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