下面程序用于测试C语言的一些诡异特性, 今天我自己写了一个测试框架,以后连载只提供测试函数.
测试函数编写方法:
测试函数调用方法:
测试框架源代码(包含一个测试样例)
测试函数编写方法:
- TEST_FUN(
- fun_name,
- fun_description_str
- )
- {
- ...
- }
- RUN_TEST(fun_name);
测试框架源代码(包含一个测试样例)
- /*
- Author : Anders Ma
- Function : To show C language tricky feature
- Since 2008_1008
- */
- #include <stdio.h>
- #define TEST_FUN(name, function) /
- char* name##_fun_str = function; /
- void name()
- #define RUN_TEST(name) /
- printf("Test : %s/nFunction : %s/n", #name, name##_fun_str); /
- printf("--------------/n"); /
- name();
- TEST_FUN(
- test_1,
- "auto type conversion -- int variable is converted to 'unsigned int'"
- )
- {
- int i = -2;
- unsigned int j = 5;
- if (i < j)
- printf("int i=%d;/nunsigned int j=%d;/ni < j/n", i, j);
- else if (i > j)
- printf("int i=%d;/nunsigned int j=%d;/ni > j/n", i, j);
- }
- int main ()
- {
- RUN_TEST(test_1);
- return 0;
- }
- --------------
- test_1测试结果:
- --------------
- Test : test_1
- Function : auto type conversion -- int variable is converted to 'unsigned int'
- --------------
- int i=-2;
- unsigned int j=5;
- i > j