1 /*
2 * Copyright (c) 2021 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 <ctype.h>
17 #include <stdint.h>
18 #include "event.h"
19 #include "hctest.h"
20
21 #define HIEVENT_TEST_ID 0x1234
22
23 /**
24 * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
25 * @param : subsystem name is hiviewdfx
26 * @param : module name is hievet_lite
27 * @param : test suit name is HieventLiteTest
28 */
29 LITE_TEST_SUIT(hiviewdfx, hievent_lite, HieventLiteTestSuite);
30
31 /**
32 * @tc.setup : setup for all testcases
33 * @return : setup result, TRUE is success, FALSE is fail
34 */
HieventLiteTestSuiteSetUp(void)35 static BOOL HieventLiteTestSuiteSetUp(void)
36 {
37 return TRUE;
38 }
39
40 /**
41 * @tc.teardown : teardown for all testcases
42 * @return : teardown result, TRUE is success, FALSE is fail
43 */
HieventLiteTestSuiteTearDown(void)44 static BOOL HieventLiteTestSuiteTearDown(void)
45 {
46 printf("+-------------------------------------------+\n");
47 return TRUE;
48 }
49
50 /**
51 * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
52 * @param : subsystem name is hiviewdfx
53 * @param : module name is hievet_lite
54 * @param : test suit name is HieventLiteTest
55 */
HieventLiteTestOutputFunc(uint8 * data)56 static HieventProc HieventLiteTestOutputFunc(uint8 *data)
57 {
58 HiEvent *e = (HiEvent *)data;
59
60 TEST_ASSERT_EQUAL_INT(HIEVENT_TEST_ID, e->common.eventId);
61 }
62
63 /**
64 * @tc.name : HieventLiteFuncTest001
65 * @tc.desc : Test HiEventCreate
66 * @tc.level : Level 1
67 */
LITE_TEST_CASE(HieventLiteTestSuite,HieventLiteFuncTest001,Level1)68 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest001, Level1)
69 {
70 HiEvent *e = HiEventCreate(HIEVENT_FAULT, 0, 3);
71
72 TEST_ASSERT_NOT_NULL(e);
73
74 HiEventReport(e);
75 };
76
77 /**
78 * @tc.name : HieventLiteFuncTest002
79 * @tc.desc : Test HiEventPutInteger 3 items whth async flush
80 * @tc.level : Level 1
81 */
LITE_TEST_CASE(HieventLiteTestSuite,HieventLiteFuncTest002,Level1)82 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest002, Level1)
83 {
84 HiEvent *e = HiEventCreate(HIEVENT_FAULT, 1, 3);
85
86 TEST_ASSERT_NOT_NULL(e);
87
88 HiEventPutInteger(e, 1, 0);
89
90 HiEventReport(e);
91
92 HiEventFlush(FALSE);
93 };
94
95 /**
96 * @tc.name : HieventLiteFuncTest003
97 * @tc.desc : Test HiEventCreate
98 * @tc.level : Level 1
99 */
LITE_TEST_CASE(HieventLiteTestSuite,HieventLiteFuncTest003,Level1)100 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest003, Level1)
101 {
102 HiEvent *e = HiEventCreate(HIEVENT_FAULT, HIEVENT_TEST_ID, 3);
103
104 HiEventRegisterProc(HieventLiteTestOutputFunc);
105
106 TEST_ASSERT_NOT_NULL(e);
107
108 HiEventPutInteger(e, 1, 0);
109 HiEventPutInteger(e, 2, 10);
110 HiEventPutInteger(e, 3, 20);
111
112 HiEventReport(e);
113 HiEventFlush(TRUE);
114 HiEventUnRegisterProc(HieventLiteTestOutputFunc);
115 };
116
117 /**
118 * @tc.name : HieventLiteFuncTest004
119 * @tc.desc : Test HiEventCreate
120 * @tc.level : Level 1
121 */
LITE_TEST_CASE(HieventLiteTestSuite,HieventLiteFuncTest004,Level1)122 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest004, Level1)
123 {
124 HIEVENT_FAULT_REPORT(8, 1, 2);
125 };
126
127 RUN_TEST_SUITE(HieventLiteTestSuite);
128