Rev 4332 | Rev 4588 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4332 | Rev 4350 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
- | 34 | * Self tests implementation. |
|
34 | */ |
35 | */ |
35 | 36 | ||
36 | #include "configuration.h" |
37 | #include "configuration.h" |
37 | 38 | ||
38 | #if NET_SELF_TEST |
39 | #if NET_SELF_TEST |
39 | 40 | ||
40 | #include <errno.h> |
41 | #include <errno.h> |
41 | #include <malloc.h> |
42 | #include <malloc.h> |
42 | #include <stdio.h> |
43 | #include <stdio.h> |
43 | 44 | ||
44 | #include "include/crc.h" |
45 | #include "include/crc.h" |
45 | #include "structures/int_map.h" |
46 | #include "structures/int_map.h" |
46 | #include "structures/char_map.h" |
47 | #include "structures/char_map.h" |
47 | #include "structures/generic_char_map.h" |
48 | #include "structures/generic_char_map.h" |
48 | #include "structures/measured_strings.h" |
49 | #include "structures/measured_strings.h" |
49 | 50 | ||
50 | #include "self_test.h" |
51 | #include "self_test.h" |
51 | 52 | ||
- | 53 | /** Tests the function, compares the result and remembers if the result differs. |
|
- | 54 | * @param name The test name. Input parameter. |
|
- | 55 | * @param function_call The function to be called and checked. Input parameter. |
|
- | 56 | * @param result The expected result. Input parameter. |
|
- | 57 | */ |
|
52 | #define TEST( name, function_call, result ); { \ |
58 | #define TEST( name, function_call, result ); { \ |
53 | printf( "\n\t%s", ( name )); \ |
59 | printf( "\n\t%s", ( name )); \ |
54 | if(( function_call ) != ( result )){ \ |
60 | if(( function_call ) != ( result )){ \ |
55 | printf( "\tERROR" ); \ |
61 | printf( "\tERROR" ); \ |
56 | error = 1; \ |
62 | error = 1; \ |
57 | }else{ \ |
63 | }else{ \ |
58 | printf( "\tOK" ); \ |
64 | printf( "\tOK" ); \ |
59 | } \ |
65 | } \ |
60 | } |
66 | } |
61 | 67 | ||
62 | #if NET_SELF_TEST_INT_MAP |
68 | #if NET_SELF_TEST_INT_MAP |
63 | 69 | ||
64 | INT_MAP_DECLARE( int_map, int ); |
70 | INT_MAP_DECLARE( int_map, int ); |
65 | 71 | ||
66 | INT_MAP_IMPLEMENT( int_map, int ); |
72 | INT_MAP_IMPLEMENT( int_map, int ); |
67 | 73 | ||
68 | #endif |
74 | #endif |
69 | 75 | ||
70 | #if NET_SELF_TEST_GENERIC_FIELD |
76 | #if NET_SELF_TEST_GENERIC_FIELD |
71 | 77 | ||
72 | GENERIC_FIELD_DECLARE( int_field, int ) |
78 | GENERIC_FIELD_DECLARE( int_field, int ) |
73 | 79 | ||
74 | GENERIC_FIELD_IMPLEMENT( int_field, int ) |
80 | GENERIC_FIELD_IMPLEMENT( int_field, int ) |
75 | 81 | ||
76 | #endif |
82 | #endif |
77 | 83 | ||
78 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
84 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
79 | 85 | ||
80 | GENERIC_CHAR_MAP_DECLARE( int_char_map, int ) |
86 | GENERIC_CHAR_MAP_DECLARE( int_char_map, int ) |
81 | 87 | ||
82 | GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int ) |
88 | GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int ) |
83 | 89 | ||
84 | #endif |
90 | #endif |
85 | 91 | ||
86 | int self_test( void ){ |
92 | int self_test( void ){ |
87 | int error = 0; |
93 | int error = 0; |
88 | int * x, * y, * z, * u, * v, * w; |
94 | int * x, * y, * z, * u, * v, * w; |
89 | 95 | ||
90 | #if NET_SELF_TEST_MEASURED_STRINGS |
96 | #if NET_SELF_TEST_MEASURED_STRINGS |
91 | measured_string_ref string; |
97 | measured_string_ref string; |
92 | 98 | ||
93 | printf( "\nMeasured strings test" ); |
99 | printf( "\nMeasured strings test" ); |
94 | string = measured_string_create_bulk( "I am a measured string!", 0 ); |
100 | string = measured_string_create_bulk( "I am a measured string!", 0 ); |
95 | printf( "\n%x, %s at %x of %d", string, string->value, string->value, string->length ); |
101 | printf( "\n%x, %s at %x of %d", string, string->value, string->value, string->length ); |
96 | printf( "\nOK" ); |
102 | printf( "\nOK" ); |
97 | #endif |
103 | #endif |
98 | 104 | ||
99 | #if NET_SELF_TEST_CHAR_MAP |
105 | #if NET_SELF_TEST_CHAR_MAP |
100 | char_map_t cm; |
106 | char_map_t cm; |
101 | 107 | ||
102 | printf( "\nChar map test" ); |
108 | printf( "\nChar map test" ); |
103 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
109 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
104 | TEST( "initialize", char_map_initialize( & cm ), EOK ); |
110 | TEST( "initialize", char_map_initialize( & cm ), EOK ); |
105 | TEST( "get_value", char_map_get_value( & cm ), CHAR_MAP_NULL ); |
111 | TEST( "get_value", char_map_get_value( & cm ), CHAR_MAP_NULL ); |
106 | TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
112 | TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
107 | TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
113 | TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
108 | TEST( "add bla 1 eok", char_map_add( & cm, "bla", 0, 1 ), EOK ); |
114 | TEST( "add bla 1 eok", char_map_add( & cm, "bla", 0, 1 ), EOK ); |
109 | TEST( "find bla 1", char_map_find( & cm, "bla", 0 ), 1 ); |
115 | TEST( "find bla 1", char_map_find( & cm, "bla", 0 ), 1 ); |
110 | TEST( "add bla 10 eexists", char_map_add( & cm, "bla", 0, 10 ), EEXISTS ); |
116 | TEST( "add bla 10 eexists", char_map_add( & cm, "bla", 0, 10 ), EEXISTS ); |
111 | TEST( "update bla 2 eok", char_map_update( & cm, "bla", 0, 2 ), EOK ); |
117 | TEST( "update bla 2 eok", char_map_update( & cm, "bla", 0, 2 ), EOK ); |
112 | TEST( "find bla 2", char_map_find( & cm, "bla", 0 ), 2 ); |
118 | TEST( "find bla 2", char_map_find( & cm, "bla", 0 ), 2 ); |
113 | TEST( "update ucho 2 eok", char_map_update( & cm, "ucho", 0, 2 ), EOK ); |
119 | TEST( "update ucho 2 eok", char_map_update( & cm, "ucho", 0, 2 ), EOK ); |
114 | TEST( "exclude bla 2", char_map_exclude( & cm, "bla", 0 ), 2 ); |
120 | TEST( "exclude bla 2", char_map_exclude( & cm, "bla", 0 ), 2 ); |
115 | TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
121 | TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
116 | TEST( "find ucho 2", char_map_find( & cm, "ucho", 0 ), 2 ); |
122 | TEST( "find ucho 2", char_map_find( & cm, "ucho", 0 ), 2 ); |
117 | TEST( "update ucho 3 eok", char_map_update( & cm, "ucho", 0, 3 ), EOK ); |
123 | TEST( "update ucho 3 eok", char_map_update( & cm, "ucho", 0, 3 ), EOK ); |
118 | TEST( "find ucho 3", char_map_find( & cm, "ucho", 0 ), 3 ); |
124 | TEST( "find ucho 3", char_map_find( & cm, "ucho", 0 ), 3 ); |
119 | TEST( "add blabla 5 eok", char_map_add( & cm, "blabla", 0, 5 ), EOK ); |
125 | TEST( "add blabla 5 eok", char_map_add( & cm, "blabla", 0, 5 ), EOK ); |
120 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
126 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
121 | TEST( "add bla 6 eok", char_map_add( & cm, "bla", 0, 6 ), EOK ); |
127 | TEST( "add bla 6 eok", char_map_add( & cm, "bla", 0, 6 ), EOK ); |
122 | TEST( "find bla 6", char_map_find( & cm, "bla", 0 ), 6 ); |
128 | TEST( "find bla 6", char_map_find( & cm, "bla", 0 ), 6 ); |
123 | TEST( "exclude bla 6", char_map_exclude( & cm, "bla", 0 ), 6 ); |
129 | TEST( "exclude bla 6", char_map_exclude( & cm, "bla", 0 ), 6 ); |
124 | TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
130 | TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL ); |
125 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
131 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
126 | TEST( "add auto 7 eok", char_map_add( & cm, "auto", 0, 7 ), EOK ); |
132 | TEST( "add auto 7 eok", char_map_add( & cm, "auto", 0, 7 ), EOK ); |
127 | TEST( "find auto 7", char_map_find( & cm, "auto", 0 ), 7 ); |
133 | TEST( "find auto 7", char_map_find( & cm, "auto", 0 ), 7 ); |
128 | TEST( "add kara 8 eok", char_map_add( & cm, "kara", 0, 8 ), EOK ); |
134 | TEST( "add kara 8 eok", char_map_add( & cm, "kara", 0, 8 ), EOK ); |
129 | TEST( "find kara 8", char_map_find( & cm, "kara", 0 ), 8 ); |
135 | TEST( "find kara 8", char_map_find( & cm, "kara", 0 ), 8 ); |
130 | TEST( "add nic 9 eok", char_map_add( & cm, "nic", 0, 9 ), EOK ); |
136 | TEST( "add nic 9 eok", char_map_add( & cm, "nic", 0, 9 ), EOK ); |
131 | TEST( "find nic 9", char_map_find( & cm, "nic", 0 ), 9 ); |
137 | TEST( "find nic 9", char_map_find( & cm, "nic", 0 ), 9 ); |
132 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
138 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
133 | TEST( "add micnicnic 5 9 eok", char_map_add( & cm, "micnicnic", 5, 9 ), EOK ); |
139 | TEST( "add micnicnic 5 9 eok", char_map_add( & cm, "micnicnic", 5, 9 ), EOK ); |
134 | TEST( "find micni 9", char_map_find( & cm, "micni", 0 ), 9 ); |
140 | TEST( "find micni 9", char_map_find( & cm, "micni", 0 ), 9 ); |
135 | TEST( "find micnicn 5 9", char_map_find( & cm, "micnicn", 5 ), 9 ); |
141 | TEST( "find micnicn 5 9", char_map_find( & cm, "micnicn", 5 ), 9 ); |
136 | TEST( "add 10.0.2.2 4 15 eok", char_map_add( & cm, "\x10\x0\x2\x2", 4, 15 ), EOK ); |
142 | TEST( "add 10.0.2.2 4 15 eok", char_map_add( & cm, "\x10\x0\x2\x2", 4, 15 ), EOK ); |
137 | TEST( "find 10.0.2.2 4 15", char_map_find( & cm, "\x10\x0\x2\x2", 4 ), 15 ); |
143 | TEST( "find 10.0.2.2 4 15", char_map_find( & cm, "\x10\x0\x2\x2", 4 ), 15 ); |
138 | printf( "\n\tdestroy" ); |
144 | printf( "\n\tdestroy" ); |
139 | char_map_destroy( & cm ); |
145 | char_map_destroy( & cm ); |
140 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
146 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
141 | printf( "\nOK" ); |
147 | printf( "\nOK" ); |
142 | 148 | ||
143 | if( error ) return EINVAL; |
149 | if( error ) return EINVAL; |
144 | 150 | ||
145 | #endif |
151 | #endif |
146 | 152 | ||
147 | #if NET_SELF_TEST_INT_MAP |
153 | #if NET_SELF_TEST_INT_MAP |
148 | int_map_t im; |
154 | int_map_t im; |
149 | 155 | ||
150 | x = ( int * ) malloc( sizeof( int )); |
156 | x = ( int * ) malloc( sizeof( int )); |
151 | y = ( int * ) malloc( sizeof( int )); |
157 | y = ( int * ) malloc( sizeof( int )); |
152 | z = ( int * ) malloc( sizeof( int )); |
158 | z = ( int * ) malloc( sizeof( int )); |
153 | u = ( int * ) malloc( sizeof( int )); |
159 | u = ( int * ) malloc( sizeof( int )); |
154 | v = ( int * ) malloc( sizeof( int )); |
160 | v = ( int * ) malloc( sizeof( int )); |
155 | w = ( int * ) malloc( sizeof( int )); |
161 | w = ( int * ) malloc( sizeof( int )); |
156 | 162 | ||
157 | im.magic = 0; |
163 | im.magic = 0; |
158 | printf( "\nInt map test" ); |
164 | printf( "\nInt map test" ); |
159 | TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL ); |
165 | TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL ); |
160 | TEST( "count -1", int_map_count( & im ), -1 ); |
166 | TEST( "count -1", int_map_count( & im ), -1 ); |
161 | TEST( "initialize", int_map_initialize( & im ), EOK ); |
167 | TEST( "initialize", int_map_initialize( & im ), EOK ); |
162 | TEST( "count 0", int_map_count( & im ), 0 ); |
168 | TEST( "count 0", int_map_count( & im ), 0 ); |
163 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
169 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
164 | TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 ); |
170 | TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 ); |
165 | TEST( "find 1 x", int_map_find( & im, 1 ), x ); |
171 | TEST( "find 1 x", int_map_find( & im, 1 ), x ); |
166 | int_map_exclude( & im, 1 ); |
172 | int_map_exclude( & im, 1 ); |
167 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
173 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
168 | TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 ); |
174 | TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 ); |
169 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
175 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
170 | TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 ); |
176 | TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 ); |
171 | TEST( "get 2 z", int_map_get_index( & im, 2 ), z ); |
177 | TEST( "get 2 z", int_map_get_index( & im, 2 ), z ); |
172 | TEST( "find 4 z", int_map_find( & im, 4 ), z ); |
178 | TEST( "find 4 z", int_map_find( & im, 4 ), z ); |
173 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
179 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
174 | TEST( "count 3", int_map_count( & im ), 3 ); |
180 | TEST( "count 3", int_map_count( & im ), 3 ); |
175 | TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 ); |
181 | TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 ); |
176 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
182 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
177 | TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 ); |
183 | TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 ); |
178 | TEST( "find 3 v", int_map_find( & im, 3 ), v ); |
184 | TEST( "find 3 v", int_map_find( & im, 3 ), v ); |
179 | TEST( "get 4 v", int_map_get_index( & im, 4 ), v ); |
185 | TEST( "get 4 v", int_map_get_index( & im, 4 ), v ); |
180 | TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 ); |
186 | TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 ); |
181 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
187 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
182 | TEST( "count 6", int_map_count( & im ), 6 ); |
188 | TEST( "count 6", int_map_count( & im ), 6 ); |
183 | int_map_exclude( & im, 1 ); |
189 | int_map_exclude( & im, 1 ); |
184 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
190 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
185 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
191 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
186 | int_map_exclude( & im, 7 ); |
192 | int_map_exclude( & im, 7 ); |
187 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
193 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
188 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
194 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
189 | int_map_exclude_index( & im, 4 ); |
195 | int_map_exclude_index( & im, 4 ); |
190 | TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL ); |
196 | TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL ); |
191 | TEST( "find 3 null", int_map_find( & im, 3 ), NULL ); |
197 | TEST( "find 3 null", int_map_find( & im, 3 ), NULL ); |
192 | printf( "\n\tdestroy" ); |
198 | printf( "\n\tdestroy" ); |
193 | int_map_destroy( & im ); |
199 | int_map_destroy( & im ); |
194 | TEST( "count -1", int_map_count( & im ), -1 ); |
200 | TEST( "count -1", int_map_count( & im ), -1 ); |
195 | printf( "\nOK" ); |
201 | printf( "\nOK" ); |
196 | 202 | ||
197 | if( error ) return EINVAL; |
203 | if( error ) return EINVAL; |
198 | 204 | ||
199 | #endif |
205 | #endif |
200 | 206 | ||
201 | #if NET_SELF_TEST_GENERIC_FIELD |
207 | #if NET_SELF_TEST_GENERIC_FIELD |
202 | int_field_t gf; |
208 | int_field_t gf; |
203 | 209 | ||
204 | x = ( int * ) malloc( sizeof( int )); |
210 | x = ( int * ) malloc( sizeof( int )); |
205 | y = ( int * ) malloc( sizeof( int )); |
211 | y = ( int * ) malloc( sizeof( int )); |
206 | z = ( int * ) malloc( sizeof( int )); |
212 | z = ( int * ) malloc( sizeof( int )); |
207 | u = ( int * ) malloc( sizeof( int )); |
213 | u = ( int * ) malloc( sizeof( int )); |
208 | v = ( int * ) malloc( sizeof( int )); |
214 | v = ( int * ) malloc( sizeof( int )); |
209 | w = ( int * ) malloc( sizeof( int )); |
215 | w = ( int * ) malloc( sizeof( int )); |
210 | 216 | ||
211 | gf.magic = 0; |
217 | gf.magic = 0; |
212 | printf( "\nGeneric field test" ); |
218 | printf( "\nGeneric field test" ); |
213 | TEST( "add x einval", int_field_add( & gf, x ), EINVAL ); |
219 | TEST( "add x einval", int_field_add( & gf, x ), EINVAL ); |
214 | TEST( "count -1", int_field_count( & gf ), -1 ); |
220 | TEST( "count -1", int_field_count( & gf ), -1 ); |
215 | TEST( "initialize", int_field_initialize( & gf ), EOK ); |
221 | TEST( "initialize", int_field_initialize( & gf ), EOK ); |
216 | TEST( "count 0", int_field_count( & gf ), 0 ); |
222 | TEST( "count 0", int_field_count( & gf ), 0 ); |
217 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
223 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
218 | TEST( "add x 0", int_field_add( & gf, x ), 0 ); |
224 | TEST( "add x 0", int_field_add( & gf, x ), 0 ); |
219 | TEST( "get 0 x", int_field_get_index( & gf, 0 ), x ); |
225 | TEST( "get 0 x", int_field_get_index( & gf, 0 ), x ); |
220 | int_field_exclude_index( & gf, 0 ); |
226 | int_field_exclude_index( & gf, 0 ); |
221 | TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL ); |
227 | TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL ); |
222 | TEST( "add y 1", int_field_add( & gf, y ), 1 ); |
228 | TEST( "add y 1", int_field_add( & gf, y ), 1 ); |
223 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
229 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
224 | TEST( "add z 2", int_field_add( & gf, z ), 2 ); |
230 | TEST( "add z 2", int_field_add( & gf, z ), 2 ); |
225 | TEST( "get 2 z", int_field_get_index( & gf, 2 ), z ); |
231 | TEST( "get 2 z", int_field_get_index( & gf, 2 ), z ); |
226 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
232 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
227 | TEST( "count 3", int_field_count( & gf ), 3 ); |
233 | TEST( "count 3", int_field_count( & gf ), 3 ); |
228 | TEST( "add u 3", int_field_add( & gf, u ), 3 ); |
234 | TEST( "add u 3", int_field_add( & gf, u ), 3 ); |
229 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
235 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
230 | TEST( "add v 4", int_field_add( & gf, v ), 4 ); |
236 | TEST( "add v 4", int_field_add( & gf, v ), 4 ); |
231 | TEST( "get 4 v", int_field_get_index( & gf, 4 ), v ); |
237 | TEST( "get 4 v", int_field_get_index( & gf, 4 ), v ); |
232 | TEST( "add w 5", int_field_add( & gf, w ), 5 ); |
238 | TEST( "add w 5", int_field_add( & gf, w ), 5 ); |
233 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
239 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
234 | TEST( "count 6", int_field_count( & gf ), 6 ); |
240 | TEST( "count 6", int_field_count( & gf ), 6 ); |
235 | int_field_exclude_index( & gf, 1 ); |
241 | int_field_exclude_index( & gf, 1 ); |
236 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
242 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
237 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
243 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
238 | int_field_exclude_index( & gf, 7 ); |
244 | int_field_exclude_index( & gf, 7 ); |
239 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
245 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
240 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
246 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
241 | int_field_exclude_index( & gf, 4 ); |
247 | int_field_exclude_index( & gf, 4 ); |
242 | TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL ); |
248 | TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL ); |
243 | printf( "\n\tdestroy" ); |
249 | printf( "\n\tdestroy" ); |
244 | int_field_destroy( & gf ); |
250 | int_field_destroy( & gf ); |
245 | TEST( "count -1", int_field_count( & gf ), -1 ); |
251 | TEST( "count -1", int_field_count( & gf ), -1 ); |
246 | printf( "\nOK" ); |
252 | printf( "\nOK" ); |
247 | 253 | ||
248 | if( error ) return EINVAL; |
254 | if( error ) return EINVAL; |
249 | 255 | ||
250 | #endif |
256 | #endif |
251 | 257 | ||
252 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
258 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
253 | int_char_map_t icm; |
259 | int_char_map_t icm; |
254 | 260 | ||
255 | x = ( int * ) malloc( sizeof( int )); |
261 | x = ( int * ) malloc( sizeof( int )); |
256 | y = ( int * ) malloc( sizeof( int )); |
262 | y = ( int * ) malloc( sizeof( int )); |
257 | z = ( int * ) malloc( sizeof( int )); |
263 | z = ( int * ) malloc( sizeof( int )); |
258 | u = ( int * ) malloc( sizeof( int )); |
264 | u = ( int * ) malloc( sizeof( int )); |
259 | v = ( int * ) malloc( sizeof( int )); |
265 | v = ( int * ) malloc( sizeof( int )); |
260 | w = ( int * ) malloc( sizeof( int )); |
266 | w = ( int * ) malloc( sizeof( int )); |
261 | 267 | ||
262 | icm.magic = 0; |
268 | icm.magic = 0; |
263 | printf( "\nGeneric char map test" ); |
269 | printf( "\nGeneric char map test" ); |
264 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
270 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
265 | TEST( "initialize", int_char_map_initialize( & icm ), EOK ); |
271 | TEST( "initialize", int_char_map_initialize( & icm ), EOK ); |
266 | printf( "\n\texclude bla null" ); |
272 | printf( "\n\texclude bla null" ); |
267 | int_char_map_exclude( & icm, "bla", 0 ); |
273 | int_char_map_exclude( & icm, "bla", 0 ); |
268 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
274 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
269 | TEST( "add bla x eok", int_char_map_add( & icm, "bla", 0, x ), EOK ); |
275 | TEST( "add bla x eok", int_char_map_add( & icm, "bla", 0, x ), EOK ); |
270 | TEST( "find bla x", int_char_map_find( & icm, "bla", 0 ), x ); |
276 | TEST( "find bla x", int_char_map_find( & icm, "bla", 0 ), x ); |
271 | TEST( "add bla y eexists", int_char_map_add( & icm, "bla", 0, y ), EEXISTS ); |
277 | TEST( "add bla y eexists", int_char_map_add( & icm, "bla", 0, y ), EEXISTS ); |
272 | printf( "\n\texclude bla y" ); |
278 | printf( "\n\texclude bla y" ); |
273 | int_char_map_exclude( & icm, "bla", 0 ); |
279 | int_char_map_exclude( & icm, "bla", 0 ); |
274 | printf( "\n\texclude bla null" ); |
280 | printf( "\n\texclude bla null" ); |
275 | int_char_map_exclude( & icm, "bla", 0 ); |
281 | int_char_map_exclude( & icm, "bla", 0 ); |
276 | TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", 0, v ), EOK ); |
282 | TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", 0, v ), EOK ); |
277 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
283 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
278 | TEST( "add bla w eok", int_char_map_add( & icm, "bla", 0, w ), EOK ); |
284 | TEST( "add bla w eok", int_char_map_add( & icm, "bla", 0, w ), EOK ); |
279 | TEST( "find bla w", int_char_map_find( & icm, "bla", 0 ), w ); |
285 | TEST( "find bla w", int_char_map_find( & icm, "bla", 0 ), w ); |
280 | printf( "\n\texclude bla" ); |
286 | printf( "\n\texclude bla" ); |
281 | int_char_map_exclude( & icm, "bla", 0 ); |
287 | int_char_map_exclude( & icm, "bla", 0 ); |
282 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
288 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
283 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
289 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
284 | TEST( "add auto u eok", int_char_map_add( & icm, "auto", 0, u ), EOK ); |
290 | TEST( "add auto u eok", int_char_map_add( & icm, "auto", 0, u ), EOK ); |
285 | TEST( "find auto u", int_char_map_find( & icm, "auto", 0 ), u ); |
291 | TEST( "find auto u", int_char_map_find( & icm, "auto", 0 ), u ); |
286 | printf( "\n\tdestroy" ); |
292 | printf( "\n\tdestroy" ); |
287 | int_char_map_destroy( & icm ); |
293 | int_char_map_destroy( & icm ); |
288 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
294 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
289 | printf( "\nOK" ); |
295 | printf( "\nOK" ); |
290 | 296 | ||
291 | if( error ) return EINVAL; |
297 | if( error ) return EINVAL; |
292 | 298 | ||
293 | #endif |
299 | #endif |
294 | 300 | ||
295 | #if NET_SELF_TEST_CRC |
301 | #if NET_SELF_TEST_CRC |
296 | uint32_t value; |
302 | uint32_t value; |
297 | 303 | ||
298 | printf( "\nCRC computation test" ); |
304 | printf( "\nCRC computation test" ); |
299 | value = ~ compute_crc32( ~ 0, "123456789", 8 * 9 ); |
305 | value = ~ compute_crc32( ~ 0, "123456789", 8 * 9 ); |
300 | TEST( "123456789", value, 0xCBF43926 ); |
306 | TEST( "123456789", value, 0xCBF43926 ); |
301 | printf( "\t=> %X", value ); |
307 | printf( "\t=> %X", value ); |
302 | value = ~ compute_crc32( ~ 0, "1", 8 ); |
308 | value = ~ compute_crc32( ~ 0, "1", 8 ); |
303 | TEST( "1", value, 0x83DCEFB7 ); |
309 | TEST( "1", value, 0x83DCEFB7 ); |
304 | printf( "\t=> %X", value ); |
310 | printf( "\t=> %X", value ); |
305 | value = ~ compute_crc32( ~ 0, "12", 8 * 2 ); |
311 | value = ~ compute_crc32( ~ 0, "12", 8 * 2 ); |
306 | TEST( "12", value, 0x4F5344CD ); |
312 | TEST( "12", value, 0x4F5344CD ); |
307 | printf( "\t=> %X", value ); |
313 | printf( "\t=> %X", value ); |
308 | value = ~ compute_crc32( ~ 0, "123", 8 * 3 ); |
314 | value = ~ compute_crc32( ~ 0, "123", 8 * 3 ); |
309 | TEST( "123", value, 0x884863D2 ); |
315 | TEST( "123", value, 0x884863D2 ); |
310 | printf( "\t=> %X", value ); |
316 | printf( "\t=> %X", value ); |
311 | value = ~ compute_crc32( ~ 0, "1234", 8 * 4 ); |
317 | value = ~ compute_crc32( ~ 0, "1234", 8 * 4 ); |
312 | TEST( "1234", value, 0x9BE3E0A3 ); |
318 | TEST( "1234", value, 0x9BE3E0A3 ); |
313 | printf( "\t=> %X", value ); |
319 | printf( "\t=> %X", value ); |
314 | value = ~ compute_crc32( ~ 0, "12345678", 8 * 8 ); |
320 | value = ~ compute_crc32( ~ 0, "12345678", 8 * 8 ); |
315 | TEST( "12345678", value, 0x9AE0DAAF ); |
321 | TEST( "12345678", value, 0x9AE0DAAF ); |
316 | printf( "\t=> %X", value ); |
322 | printf( "\t=> %X", value ); |
317 | value = ~ compute_crc32( ~ 0, "ahoj pane", 8 * 9 ); |
323 | value = ~ compute_crc32( ~ 0, "ahoj pane", 8 * 9 ); |
318 | TEST( "ahoj pane", value, 0x5FC3D706 ); |
324 | TEST( "ahoj pane", value, 0x5FC3D706 ); |
319 | printf( "\t=> %X", value ); |
325 | printf( "\t=> %X", value ); |
320 | 326 | ||
321 | if( error ) return EINVAL; |
327 | if( error ) return EINVAL; |
322 | 328 | ||
323 | #endif |
329 | #endif |
324 | 330 | ||
325 | return EOK; |
331 | return EOK; |
326 | } |
332 | } |
327 | 333 | ||
328 | #endif |
334 | #endif |
329 | 335 | ||
330 | /** @} |
336 | /** @} |
331 | */ |
337 | */ |
332 | 338 |