标签:
$ ./configure $ make clean && make $ make install prefix=~/share/code/cmockery $ tree ~/share/code/cmockery install ├── include │ └── google │ └── cmockery.h ├── lib │ ├── libcmockery.a │ ├── libcmockery.la │ ├── libcmockery.so -> libcmockery.so.0.0.0 │ ├── libcmockery.so.0 -> libcmockery.so.0.0.0 │ └── libcmockery.so.0.0.0 └── share └── doc └── cmockery-0.11 ├── AUTHORS ├── ChangeLog ├── COPYING ├── index.html ├── INSTALL ├── NEWS └── README 6 directories, 13 files
安装后的目录树如上所示,包括头文件,同时提供了静态库和动态库, 和头文件,还有一些使用手册。
unit_test(f) unit_test_setup_teardown(test, setup, teardown)
使用unit_test_setup_teardown的方式可以分别添加setup函数和teardown函数,可以在test之前进行初始化,测试结束之后释放资源,可以使用NULL表示空函数。
const UnitTest tests[] = { unit_test(f), unit_test_setup_teardown(test, setup, teardown), }; run_tests(tests);
// If unit testing is enabled override assert with mock_assert(). #if UNIT_TESTING extern void mock_assert(const int result, const char* const expression,const char * const file, const int line); #undef assert #define assert(expression) \ mock_assert((int)(expression), #expression, __FILE__, __LINE__); #endif // UNIT_TESTING
assert_true(c)
assert_false(c)
assert_int_equal(a, b)
assert_int_not_equal(a, b)
assert_string_equal(a, b)
assert_string_not_equal(a, b)
assert_memory_equal(a, b, size)
assert_memory_not_equal(a, b, size)
assert_in_range(value, minimum, maximum)
assert_not_in_range(value, minimum, maximum)
assert_in_set(value, values, number_of_values)
assert_not_in_set(value, values, number_of_values)
#if UNIT_TESTING extern void* _test_malloc(const size_t size, const char* file, const int line); extern void* _test_calloc(const size_t number_of_elements, const size_t size,const char* file, const int line); extern void _test_free(void* const ptr, const char* file, const int line); #define malloc(size) _test_malloc(size, __FILE__, __LINE__) #define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) #define free(ptr) _test_free(ptr, __FILE__, __LINE__) #endif // UNIT_TESTING
int test(int value, char *string) { check_expected(value); check_expected(string); return (int)mock(); } void test_for_mock(void **state) { expect_value(test, value, 1); expect_string(test, string, "test"); will_return(test, 0x123456); assert_int_equal(test(1, "test"), 0x123456); }
标签:
原文地址:http://www.cnblogs.com/hancq/p/5410462.html