131c75014Sopenharmony_ci/* 231c75014Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 331c75014Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 431c75014Sopenharmony_ci * you may not use this file except in compliance with the License. 531c75014Sopenharmony_ci * You may obtain a copy of the License at 631c75014Sopenharmony_ci * 731c75014Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 831c75014Sopenharmony_ci * 931c75014Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1031c75014Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1131c75014Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1231c75014Sopenharmony_ci * See the License for the specific language governing permissions and 1331c75014Sopenharmony_ci * limitations under the License. 1431c75014Sopenharmony_ci */ 1531c75014Sopenharmony_ci 1631c75014Sopenharmony_ci#ifndef HCTEST_H 1731c75014Sopenharmony_ci#define HCTEST_H 1831c75014Sopenharmony_ci#ifndef HCTEST_REPEAT_TIMES 1931c75014Sopenharmony_ci#define HCTEST_REPEAT_TIMES 1 2031c75014Sopenharmony_ci#endif 2131c75014Sopenharmony_ci#include <ohos_init.h> 2231c75014Sopenharmony_ci#include "unity.h" 2331c75014Sopenharmony_ci#include "hctest_internal.h" 2431c75014Sopenharmony_ci 2531c75014Sopenharmony_ci#ifdef __cplusplus 2631c75014Sopenharmony_ci#if __cplusplus 2731c75014Sopenharmony_ciextern "C" { 2831c75014Sopenharmony_ci#endif 2931c75014Sopenharmony_ci#endif 3031c75014Sopenharmony_ci 3131c75014Sopenharmony_ci#define CONST_EMPTY_STRING "" 3231c75014Sopenharmony_ci#define CONST_STRING_SPACE " " 3331c75014Sopenharmony_ci#define CONST_DOT_STRING "," 3431c75014Sopenharmony_ci 3531c75014Sopenharmony_ci#define TEST_INIT(func) LAYER_INITCALL_DEF(func, test, "test") 3631c75014Sopenharmony_ci#define TEST_INIT_PRI(func, priority) LAYER_INITCALL(func, test, "test", priority) 3731c75014Sopenharmony_citypedef struct TestSuiteManager { 3831c75014Sopenharmony_ci /** 3931c75014Sopenharmony_ci * @brief get the test suite by suite name 4031c75014Sopenharmony_ci * @param the test suite name 4131c75014Sopenharmony_ci * @return the TestSuite point 4231c75014Sopenharmony_ci * */ 4331c75014Sopenharmony_ci CTestSuite *(*GetTestSuite)(const char *test_suite); 4431c75014Sopenharmony_ci BOOL (*RegisterTestSuite)(CTestSuite *testSuite); 4531c75014Sopenharmony_ci 4631c75014Sopenharmony_ci /** 4731c75014Sopenharmony_ci * @brief remove the test suite. 4831c75014Sopenharmony_ci * @param the test case addr. 4931c75014Sopenharmony_ci * @return TRUE success 5031c75014Sopenharmony_ci * */ 5131c75014Sopenharmony_ci BOOL (*RemoveTestSuite)(CTestSuite *testSuite); 5231c75014Sopenharmony_ci 5331c75014Sopenharmony_ci /** 5431c75014Sopenharmony_ci * @brief remove the test suite. 5531c75014Sopenharmony_ci * @param the test case addr. 5631c75014Sopenharmony_ci * @return TRUE success 5731c75014Sopenharmony_ci * */ 5831c75014Sopenharmony_ci void (*AddTestCase)(CTestCase *testCase); 5931c75014Sopenharmony_ci 6031c75014Sopenharmony_ci /** 6131c75014Sopenharmony_ci * @brief remove special test suite. 6231c75014Sopenharmony_ci * @param caseName 6331c75014Sopenharmony_ci */ 6431c75014Sopenharmony_ci void (*RunSpecialTestSuite)( 6531c75014Sopenharmony_ci const char *subSystemName, const char *moduleName, const char *suiteName, const char *caseName, int caseLevel); 6631c75014Sopenharmony_ci 6731c75014Sopenharmony_ci void (*RunTestSuite)(const char *suite_name); 6831c75014Sopenharmony_ci 6931c75014Sopenharmony_ci Vector test_suites; 7031c75014Sopenharmony_ci} TestSuiteManager; 7131c75014Sopenharmony_ciTestSuiteManager *GetTestMgrInstance(void); 7231c75014Sopenharmony_ci 7331c75014Sopenharmony_ci#define LITE_TEST_SUIT(subsystem, module, test_suite) \ 7431c75014Sopenharmony_ci static CTestSuite suite_object##test_suite; \ 7531c75014Sopenharmony_ci static void initSuite##test_suite(void) \ 7631c75014Sopenharmony_ci { \ 7731c75014Sopenharmony_ci suite_object##test_suite.subsystem_name = #subsystem; \ 7831c75014Sopenharmony_ci suite_object##test_suite.module_name = #module; \ 7931c75014Sopenharmony_ci suite_object##test_suite.suite_name = #test_suite; \ 8031c75014Sopenharmony_ci suite_object##test_suite.file = __FILE__; \ 8131c75014Sopenharmony_ci suite_object##test_suite.times = HCTEST_REPEAT_TIMES; \ 8231c75014Sopenharmony_ci suite_object##test_suite.test_cases = VECTOR_Make(NULL, NULL); \ 8331c75014Sopenharmony_ci TestSuiteManager *testMgr = GetTestMgrInstance(); \ 8431c75014Sopenharmony_ci testMgr->RegisterTestSuite(&(suite_object##test_suite)); \ 8531c75014Sopenharmony_ci } \ 8631c75014Sopenharmony_ci SYS_SERVICE_INIT(initSuite##test_suite); 8731c75014Sopenharmony_ci 8831c75014Sopenharmony_ci#define LITE_TEST_CASE(test_suite, case_object, test_flag) \ 8931c75014Sopenharmony_ci static void case_object##_runTest(void); \ 9031c75014Sopenharmony_ci static CTestCase create##case_object; \ 9131c75014Sopenharmony_ci static void initCase##case_object(void) \ 9231c75014Sopenharmony_ci { \ 9331c75014Sopenharmony_ci create##case_object.suite_name = #test_suite; \ 9431c75014Sopenharmony_ci create##case_object.case_name = #case_object; \ 9531c75014Sopenharmony_ci create##case_object.flag = test_flag; \ 9631c75014Sopenharmony_ci create##case_object.line_num = __LINE__; \ 9731c75014Sopenharmony_ci create##case_object.lite_setup = test_suite##SetUp; \ 9831c75014Sopenharmony_ci create##case_object.lite_teardown = test_suite##TearDown; \ 9931c75014Sopenharmony_ci create##case_object.execute_func = case_object##_runTest; \ 10031c75014Sopenharmony_ci TestSuiteManager *testMgr = GetTestMgrInstance(); \ 10131c75014Sopenharmony_ci testMgr->AddTestCase(&(create##case_object)); \ 10231c75014Sopenharmony_ci } \ 10331c75014Sopenharmony_ci SYS_RUN(initCase##case_object); \ 10431c75014Sopenharmony_ci static void case_object##_runTest(void) 10531c75014Sopenharmony_ci 10631c75014Sopenharmony_ci#define RUN_TEST_SUITE(test_suite) \ 10731c75014Sopenharmony_ci static void runSuite##test_suite(void) \ 10831c75014Sopenharmony_ci { \ 10931c75014Sopenharmony_ci TestSuiteManager *testMgr = GetTestMgrInstance(); \ 11031c75014Sopenharmony_ci testMgr->RunTestSuite(#test_suite); \ 11131c75014Sopenharmony_ci } \ 11231c75014Sopenharmony_ci TEST_INIT(runSuite##test_suite); 11331c75014Sopenharmony_ci 11431c75014Sopenharmony_civoid LiteTestPrint(const char *fmt, ...); 11531c75014Sopenharmony_ci 11631c75014Sopenharmony_ci#ifdef __cplusplus 11731c75014Sopenharmony_ci#if __cplusplus 11831c75014Sopenharmony_ci} 11931c75014Sopenharmony_ci#endif 12031c75014Sopenharmony_ci#endif 12131c75014Sopenharmony_ci 12231c75014Sopenharmony_ci#endif /* HCTEST_H */