1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "input_scene_board_judgement.h"
19 #include "mmi_log.h"
20 
21 #undef MMI_LOG_TAG
22 #define MMI_LOG_TAG "SceneBoardJudgementTest"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 using namespace testing::ext;
28 } // namespace
29 
30 class SceneBoardJudgementTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {}
TearDownTestCase(void)33     static void TearDownTestCase(void) {}
34 };
35 
36 /**
37  * @tc.name: SceneBoardJudgementTest_IsSceneBoardEnabled_001
38  * @tc.desc: Verify IsSceneBoardEnabled
39  * @tc.type: FUNC
40  * @tc.require:
41  */
42 HWTEST_F(SceneBoardJudgementTest, SceneBoardJudgementTest_IsSceneBoardEnabled_001, TestSize.Level1)
43 {
44     CALL_TEST_DEBUG;
45     MMISceneBoardJudgement judgement;
46     bool ret = judgement.IsSceneBoardEnabled();
47     ASSERT_FALSE(ret);
48 }
49 
50 /**
51  * @tc.name: SceneBoardJudgementTest_IsResampleEnabled_001
52  * @tc.desc: Verify IsResampleEnabled
53  * @tc.type: FUNC
54  * @tc.require:
55  */
56 HWTEST_F(SceneBoardJudgementTest, SceneBoardJudgementTest_IsResampleEnabled_001, TestSize.Level1)
57 {
58     CALL_TEST_DEBUG;
59     MMISceneBoardJudgement judgement;
60     bool ret = judgement.IsResampleEnabled();
61     ASSERT_FALSE(ret);
62 }
63 
64 /**
65  * @tc.name: SceneBoardJudgementTest_SafeGetLine_001
66  * @tc.desc: Verify SafeGetLine
67  * @tc.type: FUNC
68  * @tc.require:
69  */
70 HWTEST_F(SceneBoardJudgementTest, SceneBoardJudgementTest_SafeGetLine_001, TestSize.Level1)
71 {
72     CALL_TEST_DEBUG;
73     MMISceneBoardJudgement judgement;
74     std::string input = "test.txt";
75     std::ofstream testFile(input);
76     testFile << "Hello\r" << std::endl;
77     testFile << "\r" << std::endl;
78     testFile << "World\r" << std::endl;
79     testFile.close();
80     std::ifstream configFile(input);
81     std::string line;
82     configFile >> std::ws;
83     judgement.SafeGetLine(configFile, line);
84     ASSERT_EQ(line, "Hello");
85     configFile >> std::ws;
86     judgement.SafeGetLine(configFile, line);
87     assert(line == "");
88     configFile >> std::ws;
89     judgement.SafeGetLine(configFile, line);
90     assert(line == "World");
91     configFile.close();
92     std::remove(input.c_str());
93 }
94 
95 /**
96  * @tc.name: SceneBoardJudgementTest_InitWithConfigFile_001
97  * @tc.desc: Verify InitWithConfigFile
98  * @tc.type: FUNC
99  * @tc.require:
100  */
101 HWTEST_F(SceneBoardJudgementTest, SceneBoardJudgementTest_InitWithConfigFile_001, TestSize.Level1)
102 {
103     CALL_TEST_DEBUG;
104     MMISceneBoardJudgement judgement;
105     bool enabled = false;
106     std::string configContent = "ENABLED";
107     std::ofstream configFile("test_config.txt");
108     configFile << configContent;
109     configFile.close();
110     judgement.InitWithConfigFile("test_config.txt", enabled);
111     ASSERT_TRUE(enabled);
112     std::remove("test_config.txt");
113 }
114 
115 /**
116  * @tc.name: SceneBoardJudgementTest_InitWithConfigFile_002
117  * @tc.desc: Verify InitWithConfigFile
118  * @tc.type: FUNC
119  * @tc.require:
120  */
121 HWTEST_F(SceneBoardJudgementTest, SceneBoardJudgementTest_InitWithConfigFile_002, TestSize.Level1)
122 {
123     CALL_TEST_DEBUG;
124     MMISceneBoardJudgement judgement;
125     bool enabled = false;
126     std::string configContent = "DISABLED";
127     std::ofstream configFile("test_config.txt");
128     configFile << configContent;
129     configFile.close();
130     judgement.InitWithConfigFile("test_config.txt", enabled);
131     ASSERT_FALSE(enabled);
132     std::remove("test_config.txt");
133 }
134 } // namespace MMI
135 } // namespace OHOS