1/*
2 * Copyright (C) 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#include "hilog_lite_test.h"
16
17#include <cstdlib>
18#include <malloc.h>
19
20using namespace std;
21using namespace testing::ext;
22
23namespace OHOS {
24namespace ACELite {
25constexpr int32_t RET_OK = 0;
26constexpr int32_t RET_SIZE = 0;
27constexpr int32_t VECTOR_SIZE = 1;
28constexpr size_t STRING_SIZE = 1;
29constexpr size_t ARG_NUMBER = 3;
30constexpr size_t ARG_NUMBER_ZERO = 0;
31constexpr size_t ARG_NUMBER_ONE = 1;
32constexpr size_t ARG_NUMBER_TWO = 2;
33constexpr int32_t LOG_LEVEL_INVALID = 2;
34constexpr int32_t LOG_LEVEL_DEBUG = 3;
35constexpr int32_t LOG_LEVEL_INFO = 4;
36constexpr int32_t LOG_LEVEL_WARN = 5;
37constexpr int32_t LOG_LEVEL_ERROR = 6;
38constexpr int32_t LOG_LEVEL_FATAL = 7;
39constexpr int32_t LOG_ARG_NUMBER = 0;
40constexpr size_t RELLOC_SIZE = 10;
41const char RELLOC_STRING[] = "123456789";
42const char PARSE_LOG_CASE_S[] = "TEST%{public}s";
43const char PARSE_LOG_CASE_S_FINAL_VALUE[] = "TEST1";
44const char PARSE_LOG_CASE_D[] = "TEST%{public}d";
45const char PARSE_LOG_CASE_D_FINAL_VALUE[] = "TEST1";
46const char PARSE_LOG_CASE_O1[] = "TEST%{public}O";
47const char PARSE_LOG_CASE_O1_FINAL_VALUE[] = "TEST1";
48const char PARSE_LOG_CASE_O2[] = "TEST%{public}o";
49const char PARSE_LOG_CASE_O2_FINAL_VALUE[] = "TEST1";
50const char PARSE_LOG_CASE_I[] = "TEST%{public}i";
51const char PARSE_LOG_CASE_I_FINAL_VALUE[] = "TEST1";
52const char PARSE_LOG_CASE_C[] = "TEST%{public}c";
53const char PARSE_LOG_CASE_PRIVATE[] = "TEST%{private}s";
54const char PARSE_LOG_CASE_PRIVATE_FINAL_VALUE[] = "TEST<private>";
55const char PARSE_LOG_CASE_NONE[] = "TEST%s";
56const char PARSE_LOG_CASE_NONE_FINAL_VALUE[] = "TEST<private>";
57const char FMT_STRING[] = "TEST";
58const char PARSE_LOG_CONTENT[] = "1";
59const char HILOG_THIS_VAL[] = "1";
60const char HILOG_CONTENT[] = "log";
61const char HILOG_CONTENT_LENGTH_STRING[] = "l";
62const char HILOG_CONTENT_LENGTH[] = "l";
63const char ERROR_ARG[] = "";
64const char TEST_CHAR = 'A';
65
66// SetUpTestCase
67void HilogLiteTest::SetUpTestCase(void) {}
68
69// TearDownTestCase
70void HilogLiteTest::TearDownTestCase(void) {}
71
72void HilogLiteTest::SetUp(void) {}
73
74// Tear down
75void HilogLiteTest::TearDown(void) {}
76
77/**
78 * @tc.name: Hilog_Lite_ParseLogContent_001
79 * @tc.desc: Call ParseLogContent with %{public}s to parse logs.
80 * @tc.type: FUNC
81 * @tc.require: I5NCYY
82 * @tc.author: Wutm
83 */
84HWTEST_F(HilogLiteTest, Test_ParseLogContent_001, Level1)
85{
86    const char *fmtString = PARSE_LOG_CASE_S;
87    const char *finalValue = PARSE_LOG_CASE_S_FINAL_VALUE;
88    ACELite::HilogString fmtStringBuffer;
89    ACELite::HilogVector params;
90    ACELite::HilogString logContent;
91
92    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
93    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::STRING_TYPE);
94
95    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
96    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
97}
98
99/**
100 * @tc.name: Hilog_Lite_ParseLogContent_003
101 * @tc.desc: Call ParseLogContent with %{public}d to parse logs.
102 * @tc.type: FUNC
103 * @tc.require: I5NCYY
104 * @tc.author: Wutm
105 */
106HWTEST_F(HilogLiteTest, Test_ParseLogContent_003, Level1)
107{
108    const char *fmtString = PARSE_LOG_CASE_D;
109    const char *finalValue = PARSE_LOG_CASE_D_FINAL_VALUE;
110    ACELite::HilogString fmtStringBuffer;
111    ACELite::HilogVector params;
112    ACELite::HilogString logContent;
113
114    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
115    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::INT_TYPE);
116
117    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
118    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
119}
120
121/**
122 * @tc.name: Hilog_Lite_ParseLogContent_004
123 * @tc.desc: Call ParseLogContent with %{public}O to parse logs.
124 * @tc.type: FUNC
125 * @tc.require: I5NCYY
126 * @tc.author: Wutm
127 */
128HWTEST_F(HilogLiteTest, Test_ParseLogContent_004, Level1)
129{
130    const char *fmtString = PARSE_LOG_CASE_O1;
131    const char *finalValue = PARSE_LOG_CASE_O1_FINAL_VALUE;
132    ACELite::HilogString fmtStringBuffer;
133    ACELite::HilogVector params;
134    ACELite::HilogString logContent;
135
136    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
137    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::OBJECT_TYPE);
138
139    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
140    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
141}
142
143/**
144 * @tc.name: Hilog_Lite_ParseLogContent_005
145 * @tc.desc: Call ParseLogContent with %{public}o to parse logs.
146 * @tc.type: FUNC
147 * @tc.require: I5NCYY
148 * @tc.author: Wutm
149 */
150HWTEST_F(HilogLiteTest, Test_ParseLogContent_005, Level1)
151{
152    const char *fmtString = PARSE_LOG_CASE_O2;
153    const char *finalValue = PARSE_LOG_CASE_O2_FINAL_VALUE;
154    ACELite::HilogString fmtStringBuffer;
155    ACELite::HilogVector params;
156    ACELite::HilogString logContent;
157
158    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
159    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::OBJECT_TYPE);
160
161    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
162    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
163}
164
165/**
166 * @tc.name: Hilog_Lite_ParseLogContent_006
167 * @tc.desc: Call ParseLogContent with %{public}i to parse logs.
168 * @tc.type: FUNC
169 * @tc.require: I5NCYY
170 * @tc.author: Wutm
171 */
172HWTEST_F(HilogLiteTest, Test_ParseLogContent_006, Level1)
173{
174    const char *fmtString = PARSE_LOG_CASE_I;
175    const char *finalValue = PARSE_LOG_CASE_I_FINAL_VALUE;
176    ACELite::HilogString fmtStringBuffer;
177    ACELite::HilogVector params;
178    ACELite::HilogString logContent;
179
180    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
181    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::INT_TYPE);
182
183    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
184    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
185}
186
187/**
188 * @tc.name: Hilog_Lite_ParseLogContent_007
189 * @tc.desc: Call ParseLogContent with %{private}s to parse logs.
190 * @tc.type: FUNC
191 * @tc.require: I5NCYY
192 * @tc.author: Wutm
193 */
194HWTEST_F(HilogLiteTest, Test_ParseLogContent_007, Level1)
195{
196    const char *fmtString = PARSE_LOG_CASE_PRIVATE;
197    const char *finalValue = PARSE_LOG_CASE_PRIVATE_FINAL_VALUE;
198    ACELite::HilogString fmtStringBuffer;
199    ACELite::HilogVector params;
200    ACELite::HilogString logContent;
201
202    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
203    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::STRING_TYPE);
204
205    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
206    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
207}
208
209/**
210 * @tc.name: Hilog_Lite_ParseLogContent_008
211 * @tc.desc: Call ParseLogContent with %{private}s to parse logs.
212 * @tc.type: FUNC
213 * @tc.require: I5NCYY
214 * @tc.author: Wutm
215 */
216HWTEST_F(HilogLiteTest, Test_ParseLogContent_008, Level1)
217{
218    const char *fmtString = PARSE_LOG_CASE_NONE;
219    const char *finalValue = PARSE_LOG_CASE_NONE_FINAL_VALUE;
220    ACELite::HilogString fmtStringBuffer;
221    ACELite::HilogVector params;
222    ACELite::HilogString logContent;
223
224    ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
225    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::STRING_TYPE);
226
227    ACELite::HilogModule::ParseLogContent(&fmtStringBuffer, &params, &logContent);
228    EXPECT_TRUE(strcmp(logContent.str, finalValue) == RET_OK);
229}
230
231/**
232 * @tc.name: Hilog_Lite_Debug_001
233 * @tc.desc: Call Debug.
234 * @tc.type: FUNC
235 * @tc.require: I5NCYY
236 * @tc.author: Wutm
237 */
238HWTEST_F(HilogLiteTest, Test_Debug_001, Level1)
239{
240    ACELite::JSIValue undefValue = ACELite::JSI::CreateUndefined();
241    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
242    ACELite::JSIValue args = ACELite::JSI::CreateString(HILOG_CONTENT);
243    ACELite::JSIValue resultValue = ACELite::HilogModule::Debug(thisVal, &args, LOG_ARG_NUMBER);
244    EXPECT_TRUE(resultValue == undefValue);
245}
246
247/**
248 * @tc.name: Hilog_Lite_Info_001
249 * @tc.desc: Call Info.
250 * @tc.type: FUNC
251 * @tc.require: I5NCYY
252 * @tc.author: Wutm
253 */
254HWTEST_F(HilogLiteTest, Test_Info_001, Level1)
255{
256    ACELite::JSIValue undefValue = ACELite::JSI::CreateUndefined();
257    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
258    ACELite::JSIValue args = ACELite::JSI::CreateString(HILOG_CONTENT);
259    ACELite::JSIValue resultValue = ACELite::HilogModule::Info(thisVal, &args, LOG_ARG_NUMBER);
260    EXPECT_TRUE(resultValue == undefValue);
261}
262
263/**
264 * @tc.name: Hilog_Lite_Error_001
265 * @tc.desc: Call Error.
266 * @tc.type: FUNC
267 * @tc.require: I5NCYY
268 * @tc.author: Wutm
269 */
270HWTEST_F(HilogLiteTest, Test_Error_001, Level1)
271{
272    ACELite::JSIValue undefValue = ACELite::JSI::CreateUndefined();
273    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
274    ACELite::JSIValue args = ACELite::JSI::CreateString(HILOG_CONTENT);
275    ACELite::JSIValue resultValue = ACELite::HilogModule::Error(thisVal, &args, LOG_ARG_NUMBER);
276    EXPECT_TRUE(resultValue == undefValue);
277}
278
279/**
280 * @tc.name: Hilog_Lite_Warn_001
281 * @tc.desc: Call Warn.
282 * @tc.type: FUNC
283 * @tc.require: I5NCYY
284 * @tc.author: Wutm
285 */
286HWTEST_F(HilogLiteTest, Test_Warn_001, Level1)
287{
288    ACELite::JSIValue undefValue = ACELite::JSI::CreateUndefined();
289    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
290    ACELite::JSIValue args = ACELite::JSI::CreateString(HILOG_CONTENT);
291    ACELite::JSIValue resultValue = ACELite::HilogModule::Warn(thisVal, &args, LOG_ARG_NUMBER);
292    EXPECT_TRUE(resultValue == undefValue);
293}
294
295/**
296 * @tc.name: Hilog_Lite_Fatal_001
297 * @tc.desc: Call Fatal.
298 * @tc.type: FUNC
299 * @tc.require: I5NCYY
300 * @tc.author: Wutm
301 */
302HWTEST_F(HilogLiteTest, Test_Fatal_001, Level1)
303{
304    ACELite::JSIValue undefValue = ACELite::JSI::CreateUndefined();
305    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
306    ACELite::JSIValue args = ACELite::JSI::CreateString(HILOG_CONTENT);
307    ACELite::JSIValue resultValue = ACELite::HilogModule::Fatal(thisVal, &args, LOG_ARG_NUMBER);
308    EXPECT_TRUE(resultValue == undefValue);
309}
310
311/**
312 * @tc.name: Hilog_Lite_IsLoggable_001
313 * @tc.desc: Call IsLoggable with DEBUG level.
314 * @tc.type: FUNC
315 * @tc.require: I5NCYY
316 * @tc.author: Wutm
317 */
318HWTEST_F(HilogLiteTest, Test_IsLoggable_001, Level1)
319{
320    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
321    ACELite::JSIValue args[ARG_NUMBER];
322    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
323    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
324    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_DEBUG);
325    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
326    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == true);
327}
328
329/**
330 * @tc.name: Hilog_Lite_IsLoggable_002
331 * @tc.desc: Call IsLoggable with INFO level.
332 * @tc.type: FUNC
333 * @tc.require: I5NCYY
334 * @tc.author: Wutm
335 */
336HWTEST_F(HilogLiteTest, Test_IsLoggable_002, Level1)
337{
338    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
339    ACELite::JSIValue args[ARG_NUMBER];
340    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
341    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
342    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_INFO);
343    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
344    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == true);
345}
346
347/**
348 * @tc.name: Hilog_Lite_IsLoggable_003
349 * @tc.desc: Call IsLoggable with WARN level.
350 * @tc.type: FUNC
351 * @tc.require: I5NCYY
352 * @tc.author: Wutm
353 */
354HWTEST_F(HilogLiteTest, Test_IsLoggable_003, Level1)
355{
356    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
357    ACELite::JSIValue args[ARG_NUMBER];
358    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
359    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
360    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_WARN);
361    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
362    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == true);
363}
364
365/**
366 * @tc.name: Hilog_Lite_IsLoggable_004
367 * @tc.desc: Call IsLoggable with ERROR level.
368 * @tc.type: FUNC
369 * @tc.require: I5NCYY
370 * @tc.author: Wutm
371 */
372HWTEST_F(HilogLiteTest, Test_IsLoggable_004, Level1)
373{
374    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
375    ACELite::JSIValue args[ARG_NUMBER];
376    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
377    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
378    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_ERROR);
379    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
380    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == true);
381}
382
383/**
384 * @tc.name: Hilog_Lite_IsLoggable_005
385 * @tc.desc: Call IsLoggable with FATAL level.
386 * @tc.type: FUNC
387 * @tc.require: I5NCYY
388 * @tc.author: Wutm
389 */
390HWTEST_F(HilogLiteTest, Test_IsLoggable_005, Level1)
391{
392    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
393    ACELite::JSIValue args[ARG_NUMBER];
394    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
395    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
396    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_FATAL);
397    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
398    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == true);
399}
400
401/**
402 * @tc.name: Hilog_Lite_IsLoggable_006
403 * @tc.desc: Call IsLoggable with invalid level.
404 * @tc.type: FUNC
405 * @tc.require: I5NCYY
406 * @tc.author: Wutm
407 */
408HWTEST_F(HilogLiteTest, Test_IsLoggable_006, Level1)
409{
410    ACELite::JSIValue thisVal = ACELite::JSI::CreateString(HILOG_THIS_VAL);
411    ACELite::JSIValue args[ARG_NUMBER];
412    args[ARG_NUMBER_ZERO] = ACELite::JSI::CreateNumber(STRING_SIZE);
413    args[ARG_NUMBER_ONE] = ACELite::JSI::CreateString(HILOG_CONTENT);
414    args[ARG_NUMBER_TWO] = ACELite::JSI::CreateNumber(LOG_LEVEL_INVALID);
415    ACELite::JSIValue resultValue = ACELite::HilogModule::IsLoggable(thisVal, args, ARG_NUMBER);
416    EXPECT_TRUE(ACELite::JSI::ValueToBoolean(resultValue) == false);
417}
418
419/**
420 * @tc.name: Hilog_Lite_HilogString_Puts_001
421 * @tc.desc: Call Puts with default length value.
422 * @tc.type: FUNC
423 * @tc.require: I5NCYY
424 * @tc.author: Wutm
425 */
426HWTEST_F(HilogLiteTest, Test_HilogString_Puts_001, Level1)
427{
428    const char *fmtString = PARSE_LOG_CASE_C;
429    const char *finalValue = PARSE_LOG_CASE_C;
430    ACELite::HilogString fmtStringBuffer;
431
432    size_t resultValue = ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
433    EXPECT_TRUE(strcmp(fmtStringBuffer.str, finalValue) == RET_OK);
434    EXPECT_TRUE(resultValue == strlen(fmtString));
435}
436
437/**
438 * @tc.name: Hilog_Lite_HilogString_Puts_002
439 * @tc.desc: Call Puts with a length value.
440 * @tc.type: FUNC
441 * @tc.require: I5NCYY
442 * @tc.author: Wutm
443 */
444HWTEST_F(HilogLiteTest, Test_HilogString_Puts_002, Level1)
445{
446    const char *fmtString = HILOG_CONTENT;
447    const char *finalValue = HILOG_CONTENT_LENGTH_STRING;
448    ACELite::HilogString fmtStringBuffer;
449
450    size_t resultValue = ACELite::HilogString::Puts(fmtString, &fmtStringBuffer, STRING_SIZE);
451    EXPECT_TRUE(strcmp(fmtStringBuffer.str, finalValue) == RET_OK);
452    EXPECT_TRUE(resultValue == strlen(finalValue));
453}
454
455/**
456 * @tc.name: Hilog_Lite_HilogString_Puts_003
457 * @tc.desc: Call Puts with invalid value.
458 * @tc.type: FUNC
459 * @tc.require: I5NCYY
460 * @tc.author: Wutm
461 */
462HWTEST_F(HilogLiteTest, Test_HilogString_Puts_003, Level1)
463{
464    const char *fmtString = ERROR_ARG;
465    ACELite::HilogString fmtStringBuffer;
466
467    size_t resultValue = ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
468    EXPECT_TRUE(resultValue == strlen(fmtString));
469}
470
471/**
472 * @tc.name: Hilog_Lite_HilogString_Puts_004
473 * @tc.desc: Call Puts with null.
474 * @tc.type: FUNC
475 * @tc.require: I5NCYY
476 * @tc.author: Wutm
477 */
478HWTEST_F(HilogLiteTest, Test_HilogString_Puts_004, Level1)
479{
480    char *fmtString = nullptr;
481    ACELite::HilogString fmtStringBuffer;
482
483    size_t resultValue = ACELite::HilogString::Puts(fmtString, &fmtStringBuffer);
484    EXPECT_TRUE(resultValue == RET_SIZE);
485}
486
487/**
488 * @tc.name: Hilog_Lite_HilogString_Get_001
489 * @tc.desc: Call Get.
490 * @tc.type: FUNC
491 * @tc.require: I5NCYY
492 * @tc.author: Wutm
493 */
494HWTEST_F(HilogLiteTest, Test_HilogString_Get_001, Level1)
495{
496    ACELite::HilogString fmtStringBuffer;
497
498    char *resultValue = ACELite::HilogString::Get(&fmtStringBuffer);
499    EXPECT_TRUE(resultValue == nullptr);
500}
501
502/**
503 * @tc.name: Hilog_Lite_HilogString_Get_002
504 * @tc.desc: Call Get with null.
505 * @tc.type: FUNC
506 * @tc.require: I5NCYY
507 * @tc.author: Wutm
508 */
509HWTEST_F(HilogLiteTest, Test_HilogString_Get_002, Level1)
510{
511    char *resultValue = ACELite::HilogString::Get(nullptr);
512    EXPECT_TRUE(resultValue == nullptr);
513}
514
515/**
516 * @tc.name: Hilog_Lite_HilogString_Length_001
517 * @tc.desc: Call Length.
518 * @tc.type: FUNC
519 * @tc.require: I5NCYY
520 * @tc.author: Wutm
521 */
522HWTEST_F(HilogLiteTest, Test_HilogString_Length_001, Level1)
523{
524    ACELite::HilogString fmtStringBuffer;
525
526    size_t resultValue = ACELite::HilogString::Length(&fmtStringBuffer);
527    EXPECT_TRUE(resultValue == RET_SIZE);
528}
529
530/**
531 * @tc.name: Hilog_Lite_HilogString_Length_002
532 * @tc.desc: Call Length with null.
533 * @tc.type: FUNC
534 * @tc.require: I5NCYY
535 * @tc.author: Wutm
536 */
537HWTEST_F(HilogLiteTest, Test_HilogString_Length_002, Level1)
538{
539    size_t resultValue = ACELite::HilogString::Length(nullptr);
540    EXPECT_TRUE(resultValue == RET_SIZE);
541}
542
543/**
544 * @tc.name: Hilog_Lite_HilogString_Putc_001
545 * @tc.desc: Call Putc.
546 * @tc.type: FUNC
547 * @tc.require: I5NCYY
548 * @tc.author: Wutm
549 */
550HWTEST_F(HilogLiteTest, Test_HilogString_Putc_001, Level1)
551{
552    ACELite::HilogString fmtStringBuffer;
553
554    ACELite::HilogString::Putc(TEST_CHAR, &fmtStringBuffer);
555    EXPECT_TRUE(fmtStringBuffer.str[LOG_ARG_NUMBER] == TEST_CHAR);
556}
557
558/**
559 * @tc.name: Hilog_Lite_HilogString_Putc_002
560 * @tc.desc: Call Putc.
561 * @tc.type: FUNC
562 * @tc.require: I5NCYY
563 * @tc.author: Wutm
564 */
565HWTEST_F(HilogLiteTest, Test_HilogString_Putc_002, Level1)
566{
567    ACELite::HilogString fmtStringBuffer;
568    char rChar = EOF;
569
570    char resultValue = ACELite::HilogString::Putc('0', nullptr);
571    EXPECT_TRUE(resultValue == rChar);
572}
573
574/**
575 * @tc.name: Hilog_Lite_HilogVector_Push_001
576 * @tc.desc: Call Push with valid value.
577 * @tc.type: FUNC
578 * @tc.require: I5NCYY
579 * @tc.author: Wutm
580 */
581HWTEST_F(HilogLiteTest, Test_HilogVector_Push_001, Level1)
582{
583    ACELite::HilogVector params;
584
585    ACELite::HilogVector::Push(&params, PARSE_LOG_CONTENT, ACELite::STRING_TYPE);
586    EXPECT_TRUE(params.size == VECTOR_SIZE);
587    EXPECT_TRUE(strcmp(params.str[params.size - VECTOR_SIZE], PARSE_LOG_CONTENT) == RET_OK);
588}
589
590/**
591 * @tc.name: Hilog_Lite_HilogVector_Push_002
592 * @tc.desc: Call Push with invalid value.
593 * @tc.type: FUNC
594 * @tc.require: I5NCYY
595 * @tc.author: Wutm
596 */
597HWTEST_F(HilogLiteTest, Test_HilogVector_Push_002, Level1)
598{
599    ACELite::HilogVector params;
600
601    ACELite::HilogVector::Push(&params, ERROR_ARG, ACELite::STRING_TYPE);
602    EXPECT_TRUE(params.size == VECTOR_SIZE);
603    EXPECT_TRUE(strcmp(params.str[params.size - VECTOR_SIZE], ERROR_ARG) == RET_OK);
604}
605
606/**
607 * @tc.name: Hilog_Lite_HilogVector_Push_003
608 * @tc.desc: Call Push with null value.
609 * @tc.type: FUNC
610 * @tc.require: I5NCYY
611 * @tc.author: Wutm
612 */
613HWTEST_F(HilogLiteTest, Test_HilogVector_Push_003, Level1)
614{
615    ACELite::HilogVector params;
616
617    ACELite::HilogVector::Push(&params, nullptr, ACELite::STRING_TYPE);
618    EXPECT_TRUE(params.size == RET_SIZE);
619}
620
621/**
622 * @tc.name: Hilog_Lite_HilogVector_Size_001
623 * @tc.desc: Call Size with valid value.
624 * @tc.type: FUNC
625 * @tc.require: I5NCYY
626 * @tc.author: Wutm
627 */
628HWTEST_F(HilogLiteTest, Test_HilogVectorSize_001, Level1)
629{
630    ACELite::HilogVector params;
631
632    size_t result = ACELite::HilogVector::Size(&params);
633    EXPECT_TRUE(result == RET_SIZE);
634}
635
636/**
637 * @tc.name: Hilog_Lite_HilogVector_Size_002
638 * @tc.desc: Call Size with nullptr value.
639 * @tc.type: FUNC
640 * @tc.require: I5NCYY
641 * @tc.author: Wutm
642 */
643HWTEST_F(HilogLiteTest, Test_HilogVectorSize_002, Level1)
644{
645    ACELite::HilogVector params;
646
647    size_t result = ACELite::HilogVector::Size(nullptr);
648    EXPECT_TRUE(result == RET_SIZE);
649}
650
651/**
652 * @tc.name: Hilog_Lite_HilogVector_GetStr_001
653 * @tc.desc: Call GetStr with valid value.
654 * @tc.type: FUNC
655 * @tc.require: I5NCYY
656 * @tc.author: Wutm
657 */
658HWTEST_F(HilogLiteTest, Test_HilogVectorGetStr_001, Level1)
659{
660    ACELite::HilogVector params;
661
662    char *result = ACELite::HilogVector::GetStr(&params, RET_SIZE);
663    EXPECT_TRUE(result == nullptr);
664}
665
666/**
667 * @tc.name: Hilog_Lite_HilogVector_GetStr_002
668 * @tc.desc: Call GetStr with valid value.
669 * @tc.type: FUNC
670 * @tc.require: I5NCYY
671 * @tc.author: Wutm
672 */
673HWTEST_F(HilogLiteTest, Test_HilogVectorGetStr_002, Level1)
674{
675    ACELite::HilogVector params;
676
677    char *result = ACELite::HilogVector::GetStr(&params, 0);
678    EXPECT_TRUE(result == nullptr);
679}
680
681/**
682 * @tc.name: Hilog_Lite_HilogRealloc_Realloc_001
683 * @tc.desc: Call Realloc with invalid value.
684 * @tc.type: FUNC
685 * @tc.require: I5NCYY
686 * @tc.author: Wutm
687 */
688HWTEST_F(HilogLiteTest, Test_HilogRealloc_Realloc_001, Level1)
689{
690    void *result = ACELite::HilogRealloc::Realloc(nullptr, 0, 0);
691    EXPECT_TRUE(result == nullptr);
692}
693
694/**
695 * @tc.name: Hilog_Lite_HilogRealloc_Realloc_002
696 * @tc.desc: Call Realloc with invalid value.
697 * @tc.type: FUNC
698 * @tc.require: I5NCYY
699 * @tc.author: Wutm
700 */
701HWTEST_F(HilogLiteTest, Test_HilogRealloc_Realloc_002, Level1)
702{
703    char *ptr = static_cast<char*>(malloc(1));
704    if (ptr == nullptr) {
705        return;
706    }
707    char *result = static_cast<char*>(ACELite::HilogRealloc::Realloc(ptr, 0, 0));
708    free(ptr);
709    EXPECT_TRUE(result == nullptr);
710}
711
712/**
713 * @tc.name: Hilog_Lite_HilogRealloc_Realloc_003
714 * @tc.desc: Call Realloc with valid value.
715 * @tc.type: FUNC
716 * @tc.require: I5NCYY
717 * @tc.author: Wutm
718 */
719HWTEST_F(HilogLiteTest, Test_HilogRealloc_Realloc_003, Level1)
720{
721    char *ptr = const_cast<char*>(RELLOC_STRING);
722    if (ptr == nullptr) {
723        return;
724    }
725    char *result = static_cast<char*>(ACELite::HilogRealloc::Realloc(ptr, 1, RELLOC_SIZE));
726    EXPECT_TRUE(strlen(result) == RELLOC_SIZE - 1);
727}
728
729/**
730 * @tc.name: Hilog_Lite_HilogRealloc_Realloc_004
731 * @tc.desc: Call Realloc with valid value.
732 * @tc.type: FUNC
733 * @tc.require: I5NCYY
734 * @tc.author: Wutm
735 */
736HWTEST_F(HilogLiteTest, Test_HilogRealloc_Realloc_004, Level1)
737{
738    char *ptr = static_cast<char*>(malloc(RELLOC_SIZE - 1));
739    if (ptr == nullptr) {
740        return;
741    }
742    size_t size = malloc_usable_size(ptr);
743    char *result = static_cast<char*>(ACELite::HilogRealloc::Realloc(ptr, RELLOC_SIZE, RELLOC_SIZE - 1));
744    free(result);
745    EXPECT_TRUE(malloc_usable_size(result) >= RELLOC_SIZE);
746    EXPECT_TRUE(malloc_usable_size(result) >= size);
747}
748}  // namespace ACELite
749}  // namespace OHOS
750