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 #include <fstream>
18 #include <string>
19 #include "interfaces/innerkits/include/scene_board_judgement.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 
27 class SceneBoardJudgementTest : public testing::Test {
28 protected:
29     SceneBoardJudgement sceneBoardJudgement;
30     std::ifstream configFile;
31     std::string line;
32 };
33 
34 HWTEST_F(SceneBoardJudgementTest, SafeGetLine_WhenLineEndsWithCR, Function | SmallTest | Level1)
35 {
36     std::istringstream input("Test\r");
37     std::string line;
38     std::ifstream configFile;
39     configFile.basic_ios<char>::rdbuf(input.rdbuf());
40 
41     SceneBoardJudgement sceneBoardJudgement;
42     sceneBoardJudgement.SafeGetLine(configFile, line);
43     EXPECT_EQ(line, "Test");
44 }
45 
46 HWTEST_F(SceneBoardJudgementTest, SafeGetLine_WhenLineDoesNotEndWithCR, Function | SmallTest | Level1)
47 {
48     std::istringstream input("Test");
49     std::string line;
50     std::ifstream configFile;
51     configFile.basic_ios<char>::rdbuf(input.rdbuf());
52 
53     SceneBoardJudgement sceneBoardJudgement;
54     sceneBoardJudgement.SafeGetLine(configFile, line);
55     EXPECT_EQ(line, "Test");
56 }
57 
58 HWTEST_F(SceneBoardJudgementTest, SafeGetLine_WhenLineIsEmpty, Function | SmallTest | Level1)
59 {
60     std::istringstream input("");
61     std::string line;
62     std::ifstream configFile;
63     configFile.basic_ios<char>::rdbuf(input.rdbuf());
64 
65     SceneBoardJudgement sceneBoardJudgement;
66     sceneBoardJudgement.SafeGetLine(configFile, line);
67     EXPECT_EQ(line, "");
68 }
69 
70 } // Rosen
71 } // OHOS