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 int HieventLiteTestOutputFunc(uint8 *data)
57 {
58     HiEvent *e = (HiEvent *)data;
59 
60     TEST_ASSERT_EQUAL_INT(HIEVENT_TEST_ID, e->common.eventId);
61     return 0;
62 }
63 
64 /**
65  * @tc.name      : HieventLiteFuncTest001
66  * @tc.desc      : Test HiEventCreate
67  * @tc.level     : Level 1
68  */
LITE_TEST_CASEnull69 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest001, Level1)
70 {
71     HiEvent *e = HiEventCreate(HIEVENT_FAULT, 0, 3);
72 
73     TEST_ASSERT_NOT_NULL(e);
74 
75     HiEventReport(e);
76 };
77 
78 /**
79  * @tc.name      : HieventLiteFuncTest002
80  * @tc.desc      : Test HiEventPutInteger 3 items whth async flush
81  * @tc.level     : Level 1
82  */
LITE_TEST_CASEnull83 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest002, Level1)
84 {
85     HiEvent *e = HiEventCreate(HIEVENT_FAULT, 1, 3);
86 
87     TEST_ASSERT_NOT_NULL(e);
88 
89     HiEventPutInteger(e, 1, 0);
90 
91     HiEventReport(e);
92 
93     HiEventFlush(FALSE);
94 };
95 
96 /**
97  * @tc.name      : HieventLiteFuncTest003
98  * @tc.desc      : Test HiEventCreate
99  * @tc.level     : Level 1
100  */
LITE_TEST_CASEnull101 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest003, Level1)
102 {
103     HiEvent *e = HiEventCreate(HIEVENT_FAULT, HIEVENT_TEST_ID, 3);
104 
105     HiEventRegisterProc((HieventProc)HieventLiteTestOutputFunc);
106 
107     TEST_ASSERT_NOT_NULL(e);
108 
109     HiEventPutInteger(e, 1, 0);
110     HiEventPutInteger(e, 2, 10);
111     HiEventPutInteger(e, 3, 20);
112 
113     HiEventReport(e);
114     HiEventFlush(TRUE);
115     HiEventUnRegisterProc((HieventProc)HieventLiteTestOutputFunc);
116 };
117 
118 /**
119  * @tc.name      : HieventLiteFuncTest004
120  * @tc.desc      : Test HiEventCreate
121  * @tc.level     : Level 1
122  */
LITE_TEST_CASEnull123 LITE_TEST_CASE(HieventLiteTestSuite, HieventLiteFuncTest004, Level1)
124 {
125     HIEVENT_FAULT_REPORT(8, 1, 2);
126 };
127 
128 RUN_TEST_SUITE(HieventLiteTestSuite);
129