2018年(11)
分类: LINUX
2018-04-11 15:02:04
点击(此处)折叠或打开
Test Registry | ------------------------------ | | Suite '1' . . . . Suite 'N' | | --------------- --------------- | | | | Test '11' ... Test '1M' Test 'N1' ... Test 'NM'
void test_longjmp(void) { jmp_buf buf; int i; i = setjmp(buf); if (i == 0) { run_other_func(); CU_PASS("run_other_func() succeeded."); } else CU_FAIL("run_other_func() issued longjmp."); }断言列表
CU_ASSERT(int expression) CU_ASSERT_FATAL(int expression) CU_TEST(int expression) CU_TEST_FATAL(int expression) |
Assert that expression is TRUE (non-zero) |
CU_ASSERT_TRUE(value) CU_ASSERT_TRUE_FATAL(value) |
Assert that value is TRUE (non-zero) |
CU_ASSERT_FALSE(value) CU_ASSERT_FALSE_FATAL(value) |
Assert that value is FALSE (zero) |
CU_ASSERT_EQUAL(actual, expected) CU_ASSERT_EQUAL_FATAL(actual, expected) |
Assert that actual = = expected |
CU_ASSERT_NOT_EQUAL(actual, expected)) CU_ASSERT_NOT_EQUAL_FATAL(actual, expected) |
Assert that actual != expected |
CU_ASSERT_PTR_EQUAL(actual, expected) CU_ASSERT_PTR_EQUAL_FATAL(actual, expected) |
Assert that pointers actual = = expected |
CU_ASSERT_PTR_NOT_EQUAL(actual, expected) CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) |
Assert that pointers actual != expected |
CU_ASSERT_PTR_NULL(value) CU_ASSERT_PTR_NULL_FATAL(value) |
Assert that pointer value == NULL |
CU_ASSERT_PTR_NOT_NULL(value) CU_ASSERT_PTR_NOT_NULL_FATAL(value) |
Assert that pointer value != NULL |
CU_ASSERT_STRING_EQUAL(actual, expected) CU_ASSERT_STRING_EQUAL_FATAL(actual, expected) |
Assert that strings actual and expected are equivalent |
CU_ASSERT_STRING_NOT_EQUAL(actual, expected) CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) |
Assert that strings actual and expected differ |
CU_ASSERT_NSTRING_EQUAL(actual, expected, count) CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) |
Assert that 1st count chars of actual and expected are the same |
CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) |
Assert that 1st count chars of actual and expected differ |
CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) |
Assert that |actual - expected| <= |granularity| Math library must be linked in for this assertion. |
CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) |
Assert that |actual - expected| > |granularity| Math library must be linked in for this assertion. |
CU_PASS(message) | Register a passing assertion with the specified message. No logical test is performed. |
CU_FAIL(message) CU_FAIL_FATAL(message) |
Register a failed assertion with the specified message. No logical test is performed. |
typedef struct CU_TestRegistry typedef CU_TestRegistry* CU_pTestRegistry CU_ErrorCode CU_initialize_registry(void) void CU_cleanup_registry(void) CU_pTestRegistry CU_get_registry(void) CU_pTestRegistry CU_set_registry(CU_pTestRegistry pTestRegistry) CU_pTestRegistry CU_create_new_registry(void) void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry)内部结构
typedef struct CU_TestRegistry { unsigned int uiNumberOfSuites; unsigned int uiNumberOfTests; CU_pSuite pSuite; } CU_TestRegistry; typedef CU_TestRegistry* CU_pTestRegistry;用户通常只需在使用前初始化注册表,然后进行清理。 但是,在必要时提供其他功能来操作注册表。
CUE_SUCCESS | initialization was successful. |
CUE_NOMEMORY | memory allocation failed. |
typedef struct CU_Suite typedef CU_Suite* CU_pSuite typedef struct CU_Test typedef CU_Test* CU_pTest typedef void (*CU_TestFunc)(void) typedef int (*CU_InitializeFunc)(void) typedef int (*CU_CleanupFunc)(void) CU_pSuite CU_add_suite(const char* strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean); CU_pTest CU_add_test(CU_pSuite pSuite, const char* strName, CU_TestFunc pTestFunc); typedef struct CU_TestInfo typedef struct CU_SuiteInfo CU_ErrorCode CU_register_suites(CU_SuiteInfo suite_info[]); CU_ErrorCode CU_register_nsuites(int suite_count, ...);将套件添加到注册表中
CUE_SUCCESS | suite creation was successful. |
CUE_NOREGISTRY | the registry has not been initialized. |
CUE_NO_SUITENAME | strName was NULL. |
CUE_DUP_SUITE | the suite's name was not unique. |
CUE_NOMEMORY | memory allocation failed. |
CUE_SUCCESS | suite creation was successful. |
CUE_NOSUITE | the specified suite was NULL or invalid. |
CUE_NO_TESTNAME | strName was NULL. |
CUE_NO_TEST | pTestFunc was NULL or invalid. |
CUE_DUP_TEST | the test's name was not unique. |
CUE_NOMEMORY | memory allocation failed. |
CU_ErrorCode CU_register_suites(CU_SuiteInfo suite_info[])
CU_ErrorCode CU_register_nsuites(int suite_count, ...)
CU_TestInfo test_array1[] = { { "testname1", test_func1 }, { "testname2", test_func2 }, { "testname3", test_func3 }, CU_TEST_INFO_NULL, };
CU_SuiteInfo suites[] = { { "suitename1", suite1_init-func, suite1_cleanup_func, test_array1 }, { "suitename2", suite2_init-func, suite2_cleanup_func, test_array2 }, CU_SUITE_INFO_NULL, };
void CU_automated_run_tests(void) CU_ErrorCode CU_list_tests_to_file(void) void CU_set_output_filename(const char* szFilenameRoot)
#include <CUnit/Basic.h>
typedef enum CU_BasicRunMode CU_ErrorCode CU_basic_run_tests(void) CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite) CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest) void CU_basic_set_mode(CU_BasicRunMode mode) CU_BasicRunMode CU_basic_get_mode(void) void CU_basic_show_failures(CU_pFailureRecord pFailure)
#include <CUnit/Console.h>
void CU_console_run_tests(void)
#include <CUnit/CUCurses.h>
void CU_curses_run_tests(void)
#include <CUnit/TestRun.h> (included automatically by <CUnit/CUnit.h>)
unsigned int CU_get_number_of_suites_run(void) unsigned int CU_get_number_of_suites_failed(void) unsigned int CU_get_number_of_tests_run(void) unsigned int CU_get_number_of_tests_failed(void) unsigned int CU_get_number_of_asserts(void) unsigned int CU_get_number_of_successes(void) unsigned int CU_get_number_of_failures(void) typedef struct CU_RunSummary typedef CU_Runsummary* CU_pRunSummary const CU_pRunSummary CU_get_run_summary(void) typedef struct CU_FailureRecord typedef CU_FailureRecord* CU_pFailureRecord const CU_pFailureRecord CU_get_failure_list(void) unsigned int CU_get_number_of_failure_records(void)CUnit支持在所有注册套件中运行所有测试,但也可以运行单个测试或套件。 在每次运行期间,框架会跟踪运行,传递和失败的套件,测试和断言的数量。 请注意,每次启动测试运行时都会清除结果(即使失败)。
typedef enum CU_ErrorCode CU_ErrorCode CU_get_error(void); const char* CU_get_error_msg(void); typedef enum CU_ErrorAction void CU_set_error_action(CU_ErrorAction action); CU_ErrorAction CU_get_error_action(void);
CU_ErrorCode CU_get_error(void)
const char* CU_get_error_msg(void)
第一个返回错误代码本身,而第二个返回描述错误状态的消息。 错误代码是中定义的CU_ErrorCode类型的枚举。 定义了以下错误代码值:
Error Value | Description |
CUE_SUCCESS | No error condition. |
CUE_NOMEMORY | Memory allocation failed. |
CUE_NOREGISTRY | Test registry not initialized. |
CUE_REGISTRY_EXISTS | Attempt to CU_set_registry() without CU_cleanup_registry(). |
CUE_NOSUITE | A required CU_pSuite pointer was NULL. |
CUE_NO_SUITENAME | Required CU_Suite name not provided. |
CUE_SINIT_FAILED | Suite initialization failed. |
CUE_SCLEAN_FAILED | Suite cleanup failed. |
CUE_DUP_SUITE | Duplicate suite name not allowed. |
CUE_NOTEST | A required CU_pTest pointer was NULL. |
CUE_NO_TESTNAME | Required CU_Test name not provided. |
CUE_DUP_TEST | Duplicate test case name not allowed. |
CUE_TEST_NOT_IN_SUITE | Test is not registered in the specified suite. |
CUE_FOPEN_FAILED | An error occurred opening a file. |
CUE_FCLOSE_FAILED | An error occurred closing a file. |
CUE_BAD_FILENAME | A bad filename was requested (NULL, empty, nonexistent, etc.). |
CUE_WRITE_ERROR | An error occurred during a write to a file. |
void CU_set_error_action(CU_ErrorAction action)
CU_ErrorAction CU_get_error_action(void)
错误操作代码是中定义的CU_ErrorAction类型的枚举。 定义了以下错误操作代码:
Error Value | Description |
CUEA_IGNORE | Runs should be continued when an error condition occurs (default) |
CUEA_FAIL | Runs should be stopped when an error condition occurs |
CUEA_ABORT | The application should exit() when an error conditions occurs |