• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 #ifndef HCTEST_H
17 #define HCTEST_H
18 #ifndef HCTEST_REPEAT_TIMES
19 #define HCTEST_REPEAT_TIMES 1
20 #endif
21 #include <ohos_init.h>
22 #include "unity.h"
23 #include "hctest_internal.h"
24 
25 #define CONST_EMPTY_STRING    ""
26 #define CONST_STRING_SPACE    " "
27 #define CONST_DOT_STRING      ","
28 
29 #define TEST_INIT(func) LAYER_INITCALL_DEF(func, test, "test")
30 #define TEST_INIT_PRI(func, priority) LAYER_INITCALL(func, test, "test", priority)
31 typedef struct TestSuiteManager {
32     /**
33     * @brief get the test suite by suite name
34     * @param the test suite name
35     * @return the TestSuite point
36     * */
37     CTestSuite* (*GetTestSuite)(const char *test_suite);
38     BOOL (*RegisterTestSuite)(CTestSuite *testSuite);
39 
40     /**
41     * @brief remove the test suite.
42     * @param the test case addr.
43     * @return TRUE success
44     * */
45     BOOL (*RemoveTestSuite)(CTestSuite *testSuite);
46 
47     /**
48     * @brief remove the test suite.
49     * @param the test case addr.
50     * @return TRUE success
51     * */
52     void (*AddTestCase)(CTestCase *testCase);
53 
54     /**
55      * @brief remove special test suite.
56      * @param caseName
57      */
58     void (*RunSpecialTestSuite)(const char *subSystemName,
59                                const char *moduleName,
60                                const char *suiteName,
61                                const char *caseName,
62                                int caseLevel);
63 
64     void  (*RunTestSuite)(const char* suite_name);
65 
66     Vector test_suites;
67 }TestSuiteManager;
68 TestSuiteManager *GetTestMgrInstance(void);
69 
70 #define LITE_TEST_SUIT(subsystem, module, test_suite) \
71 static CTestSuite suite_object##test_suite;\
72 static void initSuite##test_suite(void) {\
73     suite_object##test_suite.subsystem_name = #subsystem;\
74     suite_object##test_suite.module_name = #module;\
75     suite_object##test_suite.suite_name = #test_suite;\
76     suite_object##test_suite.file = __FILE__;\
77     suite_object##test_suite.times = HCTEST_REPEAT_TIMES;\
78     suite_object##test_suite.test_cases = VECTOR_Make(NULL, NULL);\
79     TestSuiteManager* testMgr = GetTestMgrInstance();\
80     testMgr->RegisterTestSuite(&(suite_object##test_suite));\
81 }\
82 SYS_SERVICE_INIT(initSuite##test_suite);
83 
84 #define LITE_TEST_CASE(test_suite, case_object, test_flag) \
85 static void case_object##_runTest(void);\
86 static CTestCase create##case_object;\
87 static void initCase##case_object(void) {\
88     create##case_object.suite_name = #test_suite;\
89     create##case_object.case_name = #case_object;\
90     create##case_object.flag = test_flag; \
91     create##case_object.line_num = __LINE__; \
92     create##case_object.lite_setup = test_suite##SetUp; \
93     create##case_object.lite_teardown = test_suite##TearDown;\
94     create##case_object.execute_func = case_object##_runTest;\
95     TestSuiteManager* testMgr = GetTestMgrInstance();\
96     testMgr->AddTestCase(&(create##case_object));\
97 }\
98 SYS_RUN(initCase##case_object);\
99 static void case_object##_runTest(void)
100 
101 
102 #define RUN_TEST_SUITE(test_suite) \
103 static void runSuite##test_suite(void) {\
104     TestSuiteManager* testMgr = GetTestMgrInstance(); \
105     testMgr->RunTestSuite(#test_suite); \
106 }\
107 TEST_INIT(runSuite##test_suite);
108 
109 void LiteTestPrint(const char *fmt, ...);
110 
111 #ifdef __cplusplus
112 #if __cplusplus
113 }
114 #endif
115 #endif
116 
117 #endif /* HCTEST_H */