1 /*
2 * Copyright (c) 2021-2022 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 "event_handler.h"
19 #include "event_queue.h"
20 #include "event_runner.h"
21 #include "inner_event.h"
22
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::AppExecFwk;
26
27 namespace {
28 bool g_isLog = false;
29 const std::string LOG_TEST1 = "LogSystemTest1";
30 const std::string LOG_TEST2 = " ";
31 const std::string LOG_TEST3 = "@#¥#3243adsafdf_中文";
32 const std::string LOG_TEST4 = std::to_string(0);
33 const std::string LOG_TEST5 = std::to_string(0) + "@#¥#3243adsafdf_中文";
34 } // namespace
35
36 class EmsLoggerSystemTest : public testing::Test {
37 public:
38 static void SetUpTestCase(void);
39 static void TearDownTestCase(void);
40 void SetUp();
41 void TearDown();
42 };
43
SetUpTestCase(void)44 void EmsLoggerSystemTest::SetUpTestCase(void)
45 {}
46
TearDownTestCase(void)47 void EmsLoggerSystemTest::TearDownTestCase(void)
48 {}
49
SetUp(void)50 void EmsLoggerSystemTest::SetUp(void)
51 {}
52
TearDown(void)53 void EmsLoggerSystemTest::TearDown(void)
54 {}
55
56 class LogTest1 : public Logger {
57 public:
58 /**
59 * Processes the content of a specified string.
60 * @param message the content of a specified string.
61 */
Log(const std::string & line)62 void Log(const std::string &line)
63 {
64 g_isLog = true;
65 GTEST_LOG_(INFO) << line;
66 }
67 };
68
69 class LogTest2 : public Logger {
70 public:
71 /**
72 * Processes the content of a specified string.
73 * @param message the content of a specified string.
74 */
Log(const std::string & line)75 void Log(const std::string &line)
76 {
77 g_isLog = true;
78 GTEST_LOG_(INFO) << line;
79 }
80 };
81
82 class LogTest3 : public Logger {
83 public:
84 /**
85 * Processes the content of a specified string.
86 * @param message the content of a specified string.
87 */
Log(const std::string & line)88 void Log(const std::string &line)
89 {
90 g_isLog = true;
91 GTEST_LOG_(INFO) << line;
92 }
93 };
94
95 class LogTest4 : public Logger {
96 public:
97 /**
98 * Processes the content of a specified string.
99 * @param message the content of a specified string.
100 */
Log(const std::string & line)101 void Log(const std::string &line)
102 {
103 g_isLog = true;
104 GTEST_LOG_(INFO) << line;
105 }
106 };
107
108 class LogTest5 : public Logger {
109 public:
110 /**
111 * Processes the content of a specified string.
112 * @param message the content of a specified string.
113 */
Log(const std::string & line)114 void Log(const std::string &line)
115 {
116 g_isLog = true;
117 GTEST_LOG_(INFO) << line;
118 }
119 };
120
121 /*
122 * @tc.name: Log001
123 * @tc.desc: Check LogTest1 process Log success
124 * @tc.type: FUNC
125 */
126 HWTEST_F(EmsLoggerSystemTest, Log001, TestSize.Level1)
127 {
128 g_isLog = false;
129 LogTest1 logTest;
130 logTest.Log(LOG_TEST1);
131 EXPECT_TRUE(g_isLog);
132 }
133
134 /*
135 * @tc.name: Log002
136 * @tc.desc: Check LogTest2 process Log success
137 * @tc.type: FUNC
138 */
139 HWTEST_F(EmsLoggerSystemTest, Log002, TestSize.Level1)
140 {
141 g_isLog = false;
142 LogTest2 logTest;
143 logTest.Log(LOG_TEST2);
144 EXPECT_TRUE(g_isLog);
145 }
146
147 /*
148 * @tc.name: Log003
149 * @tc.desc: Check LogTest3 process Log success
150 * @tc.type: FUNC
151 */
152 HWTEST_F(EmsLoggerSystemTest, Log003, TestSize.Level1)
153 {
154 g_isLog = false;
155 LogTest3 logTest;
156 logTest.Log(LOG_TEST3);
157 EXPECT_TRUE(g_isLog);
158 }
159
160 /*
161 * @tc.name: Log004
162 * @tc.desc: Check LogTest4 process Log success
163 * @tc.type: FUNC
164 */
165 HWTEST_F(EmsLoggerSystemTest, Log004, TestSize.Level1)
166 {
167 g_isLog = false;
168 LogTest4 logTest;
169 logTest.Log(LOG_TEST4);
170 EXPECT_TRUE(g_isLog);
171 }
172
173 /*
174 * @tc.name: Log005
175 * @tc.desc: Check LogTest5 process Log success
176 * @tc.type: FUNC
177 */
178 HWTEST_F(EmsLoggerSystemTest, Log005, TestSize.Level1)
179 {
180 g_isLog = false;
181 LogTest5 logTest;
182 logTest.Log(LOG_TEST5);
183 EXPECT_TRUE(g_isLog);
184 }