Fri, 24 Feb 2012 15:53:50 +0100
some fixes
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2011 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
26
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
32 | #include "ucx/test.h" |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
33 | |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
34 | #include "main.h" |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
35 | |
9
013c5c4b7e44
Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
36 | #include "list_tests.h" |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
37 | #include "dlist_tests.h" |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
38 | |
13 | 39 | #include "mpool_tests.h" |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
40 | #include "map_tests.h" |
9
013c5c4b7e44
Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
41 | |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
42 | int cmp_string(void* o1, void* o2, void* data) { |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
43 | return strcmp((char*)o1, (char*)o2); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
44 | } |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
45 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
46 | void* copy_string(void* e, void* data) { |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
47 | char *str = (char*) e; |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
48 | size_t n = 1+strlen(str); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
49 | char *cpy = (char*) malloc(n); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
50 | memcpy(cpy, str, n); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
51 | return cpy; |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
52 | } |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
53 | |
26
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
54 | UCX_TEST_BEGIN(testTestSuitePositive) { |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
55 | UCX_TEST_ASSERT(2*2 == 4, "the test framework fails") |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
56 | UCX_TEST_END |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
57 | } |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
58 | |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
59 | UCX_TEST_BEGIN(testTestSuiteNegative) { |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
60 | UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works") |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
61 | UCX_TEST_END |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
62 | } |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
63 | |
0 | 64 | int main(int argc, char **argv) { |
13 | 65 | printf("UCX Tests\n---------\n"); |
9
013c5c4b7e44
Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
66 | |
28 | 67 | printf("\nUcxTestSuite tests (1 failure is intended!)\n"); |
26
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
68 | UcxTestSuite* suite = ucx_test_suite_new(); |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
69 | ucx_test_register(suite, testTestSuitePositive); |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
70 | ucx_test_register(suite, testTestSuiteNegative); |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
71 | ucx_test_run(suite, stdout); |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
72 | if (suite->failure == 1 && suite->success == 1) { |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
73 | ucx_test_suite_free(suite); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
74 | |
28 | 75 | printf("\nLibrary function tests\n"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
76 | suite = ucx_test_suite_new(); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
77 | /* UcxList Tests */ |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
78 | ucx_test_register(suite, test_ucx_list_append); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
79 | ucx_test_register(suite, test_ucx_list_prepend); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
80 | ucx_test_register(suite, test_ucx_list_equals); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
81 | ucx_test_register(suite, test_ucx_list_concat); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
82 | ucx_test_register(suite, test_ucx_list_size); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
83 | ucx_test_register(suite, test_ucx_list_last); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
84 | ucx_test_register(suite, test_ucx_list_get); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
85 | ucx_test_register(suite, test_ucx_list_remove); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
86 | ucx_test_register(suite, test_ucx_list_clone); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
87 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
88 | /* UcxDlist Tests */ |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
89 | ucx_test_register(suite, test_ucx_dlist_append); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
90 | ucx_test_register(suite, test_ucx_dlist_prepend); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
91 | ucx_test_register(suite, test_ucx_dlist_equals); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
92 | ucx_test_register(suite, test_ucx_dlist_concat); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
93 | ucx_test_register(suite, test_ucx_dlist_size); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
94 | ucx_test_register(suite, test_ucx_dlist_first); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
95 | ucx_test_register(suite, test_ucx_dlist_last); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
96 | ucx_test_register(suite, test_ucx_dlist_get); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
97 | ucx_test_register(suite, test_ucx_dlist_remove); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
98 | ucx_test_register(suite, test_ucx_dlist_clone); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
99 | |
28 | 100 | /* UcxMemPool Tests */ |
101 | ucx_test_register(suite, test_ucx_mempool_new); | |
102 | ucx_test_register(suite, test_ucx_mempool_malloc); | |
103 | ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap); | |
104 | ucx_test_register(suite, test_ucx_mempool_calloc); | |
105 | ucx_test_register(suite, test_ucx_mempool_set_destr); | |
106 | ucx_test_register(suite, test_ucx_mempool_reg_destr); | |
107 | ucx_test_register(suite, test_ucx_mempool_realloc); | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
108 | |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
109 | /* UcxMap Tests */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
110 | ucx_test_register(suite, test_ucx_map_new); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
111 | ucx_test_register(suite, test_ucx_key); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
112 | ucx_test_register(suite, test_ucx_map_put); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
113 | ucx_test_register(suite, test_ucx_map_get); |
26
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
114 | |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
115 | ucx_test_run(suite, stdout); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
116 | ucx_test_suite_free(suite); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
117 | |
26
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
118 | return EXIT_SUCCESS; |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
119 | } else { |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
120 | ucx_test_suite_free(suite); |
59f147baea31
added test framework and foreach macro
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
121 | return EXIT_FAILURE; |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
122 | } |
0 | 123 | } |
124 |