test/main.c

changeset 33
9c219a62070d
parent 31
91ac86557290
child 35
fdabd1240b69
equal deleted inserted replaced
32:c7af4ec56e19 33:9c219a62070d
49 char *cpy = (char*) malloc(n); 49 char *cpy = (char*) malloc(n);
50 memcpy(cpy, str, n); 50 memcpy(cpy, str, n);
51 return cpy; 51 return cpy;
52 } 52 }
53 53
54 UCX_TEST_BEGIN(testTestSuitePositive) { 54 UCX_TEST_IMPLEMENT(testTestSuitePositive) {
55 UCX_TEST_BEGIN
55 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails") 56 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails")
56 UCX_TEST_END 57 UCX_TEST_END
57 } 58 }
58 59
59 UCX_TEST_BEGIN(testTestSuiteNegative) { 60 UCX_TEST_IMPLEMENT(testTestSuiteNegative) {
61 UCX_TEST_BEGIN
60 UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works") 62 UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works")
63 UCX_TEST_END
64 }
65
66 UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess,field) {
67 int* i = (int*) field;
68 *i += 2;
69 UCX_TEST_ASSERT(*i==4, "the test framework fails");
70 }
71
72 UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure,field) {
73 int* i = (int*) field;
74 *i += 2;
75 UCX_TEST_ASSERT(*i==4, "the test framework works");
76 }
77
78 UCX_TEST_IMPLEMENT(testTestSuiteRoutinePositive) {
79 int i = 2;
80 UCX_TEST_BEGIN
81 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
82 UCX_TEST_ASSERT(i==4, "the test framework fails");
83 UCX_TEST_END
84 }
85
86 UCX_TEST_IMPLEMENT(testTestSuiteRoutineNegative) {
87 int i = 0;
88 UCX_TEST_BEGIN
89 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
90 UCX_TEST_ASSERT(1, "the test framework fails");
61 UCX_TEST_END 91 UCX_TEST_END
62 } 92 }
63 93
64 int main(int argc, char **argv) { 94 int main(int argc, char **argv) {
65 printf("UCX Tests\n---------\n"); 95 printf("UCX Tests\n---------\n");
66 96
67 printf("\nUcxTestSuite tests (1 failure is intended!)\n"); 97 printf("\nUcxTestSuite tests (2 failures are intended!)\n");
68 UcxTestSuite* suite = ucx_test_suite_new(); 98 UcxTestSuite* suite = ucx_test_suite_new();
69 ucx_test_register(suite, testTestSuitePositive); 99 ucx_test_register(suite, testTestSuitePositive);
70 ucx_test_register(suite, testTestSuiteNegative); 100 ucx_test_register(suite, testTestSuiteNegative);
101 ucx_test_register(suite, testTestSuiteRoutinePositive);
102 ucx_test_register(suite, testTestSuiteRoutineNegative);
71 ucx_test_run(suite, stdout); 103 ucx_test_run(suite, stdout);
72 if (suite->failure == 1 && suite->success == 1) { 104 if (suite->failure == 2 && suite->success == 2) {
73 ucx_test_suite_free(suite); 105 ucx_test_suite_free(suite);
74 106
75 printf("\nLibrary function tests\n"); 107 printf("\nLibrary function tests\n");
76 suite = ucx_test_suite_new(); 108 suite = ucx_test_suite_new();
77 /* UcxList Tests */ 109 /* UcxList Tests */
110 ucx_test_register(suite, test_ucx_map_new); 142 ucx_test_register(suite, test_ucx_map_new);
111 ucx_test_register(suite, test_ucx_key); 143 ucx_test_register(suite, test_ucx_key);
112 ucx_test_register(suite, test_ucx_map_put); 144 ucx_test_register(suite, test_ucx_map_put);
113 ucx_test_register(suite, test_ucx_map_get); 145 ucx_test_register(suite, test_ucx_map_get);
114 ucx_test_register(suite, test_ucx_map_iterator); 146 ucx_test_register(suite, test_ucx_map_iterator);
147 ucx_test_register(suite, test_ucx_map_iterator_chain);
115 148
116 ucx_test_run(suite, stdout); 149 ucx_test_run(suite, stdout);
117 ucx_test_suite_free(suite); 150 ucx_test_suite_free(suite);
118 151
119 return EXIT_SUCCESS; 152 return EXIT_SUCCESS;

mercurial