//***************************************************************************** // (C) Automotive Lighting Reutlingen GmbH // Tuebinger Strasse 123, 72762 Reutlingen, Germany // // Automotive Lighting Reutlingen GmbH owns all the rights to this work. // This work shall not be copied, reproduced, used, modified, transferred // or its information shall not be disclosed without the prior written // authorization of Automotive Lighting Reutlingen GmbH. //***************************************************************************** //============================================================================= // Includes //============================================================================= #include #if defined(TYP_TEST_CUnit) #include //============================================================================= // Private Variables //============================================================================= namespace { auto ALUnitTest_WrapperCUnit_tyTestSuitePtr = CU_pSuite{ nullptr }; } //============================================================================= // Public functions declarations //============================================================================= extern "C" auto ALUnitTest_Init(int argc, char** argv) -> boolean { auto ALUnitTest_WrapperCUnit_tyInitResult = CUE_SUCCESS; const char* const pcTestSuiteName = ((argc > 0) ? argv[0U] : nullptr); /* Initialize the CUnit test registry. */ if (CUE_SUCCESS != CU_initialize_registry()) { ALUnitTest_WrapperCUnit_tyInitResult = CU_get_error(); } /* Add the test suite to the registry. */ ALUnitTest_WrapperCUnit_tyTestSuitePtr = CU_add_suite((pcTestSuiteName == nullptr) ? "ALUnitTest" : pcTestSuiteName, nullptr, nullptr); if (nullptr == ALUnitTest_WrapperCUnit_tyTestSuitePtr) { CU_cleanup_registry(); ALUnitTest_WrapperCUnit_tyInitResult = CU_get_error(); } CU_basic_set_mode(CU_BRM_VERBOSE); const auto ALUnitTest_WrapperCUnit_tyInitResultIsOk = static_cast ( (ALUnitTest_WrapperCUnit_tyInitResult == CUE_SUCCESS) ? TRUE : FALSE ); return ALUnitTest_WrapperCUnit_tyInitResultIsOk; } extern "C" auto ALUnitTest_AddFunction(const char* const pcTestName, const ALUnitTest_TestFunctionType pfnTestFunction) -> boolean { const auto ptyAddTestResultPtr = CU_add_test(ALUnitTest_WrapperCUnit_tyTestSuitePtr, pcTestName, pfnTestFunction); const auto boAddTestResultIsOk = (ptyAddTestResultPtr == nullptr); return static_cast(boAddTestResultIsOk ? TRUE : FALSE); } extern "C" auto ALUnitTest_RunTests(void) -> boolean { /* Run all tests using the CUnit Basic interface. */ const auto tyRunTestsResultOfRun = CU_basic_run_tests(); const auto number_of_failed_tests = CU_get_number_of_tests_failed(); const auto number_of_failed_asserts = CU_get_number_of_failures(); std::cout << "number_of_failed_tests: " << number_of_failed_tests << std::endl; std::cout << "number_of_failed_asserts: " << number_of_failed_asserts << std::endl; CU_cleanup_registry(); const auto tyRunTestsResultOfCleanup = CU_get_error(); const auto result_tests_and_asserts_all_ok = ((number_of_failed_tests == (unsigned)0U) && (number_of_failed_asserts == (unsigned)0U)); const auto boRunTestsIsOk = ( (tyRunTestsResultOfRun == CUE_SUCCESS) && (tyRunTestsResultOfCleanup == CUE_SUCCESS) && result_tests_and_asserts_all_ok ); ALUnitTest_WrapperCUnit_tyTestSuitePtr = nullptr; return static_cast(boRunTestsIsOk ? TRUE : FALSE); } #endif