Rev 4075 | Rev 4350 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4075 | Rev 4332 | ||
---|---|---|---|
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 | */ |
34 | */ |
35 | 35 | ||
36 | #include "configuration.h" |
36 | #include "configuration.h" |
37 | 37 | ||
38 | #if NET_SELF_TEST |
38 | #if NET_SELF_TEST |
39 | 39 | ||
40 | #include <errno.h> |
40 | #include <errno.h> |
41 | #include <malloc.h> |
41 | #include <malloc.h> |
42 | #include <stdio.h> |
42 | #include <stdio.h> |
43 | 43 | ||
44 | #include "include/crc.h" |
44 | #include "include/crc.h" |
45 | #include "structures/int_map.h" |
45 | #include "structures/int_map.h" |
46 | #include "structures/char_map.h" |
46 | #include "structures/char_map.h" |
47 | #include "structures/generic_char_map.h" |
47 | #include "structures/generic_char_map.h" |
48 | #include "structures/measured_strings.h" |
48 | #include "structures/measured_strings.h" |
49 | 49 | ||
50 | #include "self_test.h" |
50 | #include "self_test.h" |
51 | 51 | ||
52 | #define TEST( name, function_call, result ); { \ |
52 | #define TEST( name, function_call, result ); { \ |
53 | printf( "\n\t%s", ( name )); \ |
53 | printf( "\n\t%s", ( name )); \ |
54 | if(( function_call ) != ( result )){ \ |
54 | if(( function_call ) != ( result )){ \ |
55 | printf( "\tERROR" ); \ |
55 | printf( "\tERROR" ); \ |
56 | error = 1; \ |
56 | error = 1; \ |
57 | }else{ \ |
57 | }else{ \ |
58 | printf( "\tOK" ); \ |
58 | printf( "\tOK" ); \ |
59 | } \ |
59 | } \ |
60 | } |
60 | } |
61 | 61 | ||
62 | #if NET_SELF_TEST_INT_MAP |
62 | #if NET_SELF_TEST_INT_MAP |
63 | 63 | ||
64 | INT_MAP_DECLARE( int_map, int ); |
64 | INT_MAP_DECLARE( int_map, int ); |
65 | 65 | ||
66 | INT_MAP_IMPLEMENT( int_map, int ); |
66 | INT_MAP_IMPLEMENT( int_map, int ); |
67 | 67 | ||
68 | #endif |
68 | #endif |
69 | 69 | ||
70 | #if NET_SELF_TEST_GENERIC_FIELD |
70 | #if NET_SELF_TEST_GENERIC_FIELD |
71 | 71 | ||
72 | GENERIC_FIELD_DECLARE( int_field, int ) |
72 | GENERIC_FIELD_DECLARE( int_field, int ) |
73 | 73 | ||
74 | GENERIC_FIELD_IMPLEMENT( int_field, int ) |
74 | GENERIC_FIELD_IMPLEMENT( int_field, int ) |
75 | 75 | ||
76 | #endif |
76 | #endif |
77 | 77 | ||
78 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
78 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
79 | 79 | ||
80 | GENERIC_CHAR_MAP_DECLARE( int_char_map, int ) |
80 | GENERIC_CHAR_MAP_DECLARE( int_char_map, int ) |
81 | 81 | ||
82 | GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int ) |
82 | GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int ) |
83 | 83 | ||
84 | #endif |
84 | #endif |
85 | 85 | ||
86 | int self_test( void ){ |
86 | int self_test( void ){ |
87 | int error = 0; |
87 | int error = 0; |
88 | int * x, * y, * z, * u, * v, * w; |
88 | int * x, * y, * z, * u, * v, * w; |
89 | 89 | ||
90 | #if NET_SELF_TEST_MEASURED_STRINGS |
90 | #if NET_SELF_TEST_MEASURED_STRINGS |
91 | measured_string_ref string; |
91 | measured_string_ref string; |
92 | 92 | ||
93 | printf( "\nMeasured strings test" ); |
93 | printf( "\nMeasured strings test" ); |
94 | string = measured_string_create_bulk( "I am a measured string!", 0 ); |
94 | 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 ); |
95 | printf( "\n%x, %s at %x of %d", string, string->value, string->value, string->length ); |
96 | printf( "\nOK" ); |
96 | printf( "\nOK" ); |
97 | #endif |
97 | #endif |
98 | 98 | ||
99 | #if NET_SELF_TEST_CHAR_MAP |
99 | #if NET_SELF_TEST_CHAR_MAP |
100 | char_map_t cm; |
100 | char_map_t cm; |
101 | 101 | ||
102 | printf( "\nChar map test" ); |
102 | printf( "\nChar map test" ); |
103 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
103 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
104 | TEST( "initialize", char_map_initialize( & cm ), EOK ); |
104 | TEST( "initialize", char_map_initialize( & cm ), EOK ); |
105 | TEST( "get_value", char_map_get_value( & cm ), CHAR_MAP_NULL ); |
105 | 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 ); |
106 | 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 ); |
107 | 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 ); |
108 | 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 ); |
109 | 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 ); |
110 | 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 ); |
111 | 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 ); |
112 | 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 ); |
113 | 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 ); |
114 | 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 ); |
115 | 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 ); |
116 | 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 ); |
117 | 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 ); |
118 | 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 ); |
119 | 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 ); |
120 | 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 ); |
121 | 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 ); |
122 | TEST( "find bla 6", char_map_find( & cm, "bla", 0 ), 6 ); |
123 | TEST( "exclude bla 6", char_map_exclude( & cm, "bla", 0 ), 6 ); |
123 | 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 ); |
124 | 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 ); |
125 | 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 ); |
126 | 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 ); |
127 | 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 ); |
128 | 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 ); |
129 | 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 ); |
130 | 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 ); |
131 | TEST( "find nic 9", char_map_find( & cm, "nic", 0 ), 9 ); |
132 | TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 ); |
132 | 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 ); |
|
- | 134 | TEST( "find micni 9", char_map_find( & cm, "micni", 0 ), 9 ); |
|
- | 135 | 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 ); |
|
- | 137 | TEST( "find 10.0.2.2 4 15", char_map_find( & cm, "\x10\x0\x2\x2", 4 ), 15 ); |
|
133 | printf( "\n\tdestroy" ); |
138 | printf( "\n\tdestroy" ); |
134 | char_map_destroy( & cm ); |
139 | char_map_destroy( & cm ); |
135 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
140 | TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL ); |
136 | printf( "\nOK" ); |
141 | printf( "\nOK" ); |
137 | 142 | ||
138 | if( error ) return EINVAL; |
143 | if( error ) return EINVAL; |
139 | 144 | ||
140 | #endif |
145 | #endif |
141 | 146 | ||
142 | #if NET_SELF_TEST_INT_MAP |
147 | #if NET_SELF_TEST_INT_MAP |
143 | int_map_t im; |
148 | int_map_t im; |
144 | 149 | ||
145 | x = ( int * ) malloc( sizeof( int )); |
150 | x = ( int * ) malloc( sizeof( int )); |
146 | y = ( int * ) malloc( sizeof( int )); |
151 | y = ( int * ) malloc( sizeof( int )); |
147 | z = ( int * ) malloc( sizeof( int )); |
152 | z = ( int * ) malloc( sizeof( int )); |
148 | u = ( int * ) malloc( sizeof( int )); |
153 | u = ( int * ) malloc( sizeof( int )); |
149 | v = ( int * ) malloc( sizeof( int )); |
154 | v = ( int * ) malloc( sizeof( int )); |
150 | w = ( int * ) malloc( sizeof( int )); |
155 | w = ( int * ) malloc( sizeof( int )); |
151 | 156 | ||
152 | im.magic = 0; |
157 | im.magic = 0; |
153 | printf( "\nInt map test" ); |
158 | printf( "\nInt map test" ); |
154 | TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL ); |
159 | TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL ); |
155 | TEST( "count -1", int_map_count( & im ), -1 ); |
160 | TEST( "count -1", int_map_count( & im ), -1 ); |
156 | TEST( "initialize", int_map_initialize( & im ), EOK ); |
161 | TEST( "initialize", int_map_initialize( & im ), EOK ); |
157 | TEST( "count 0", int_map_count( & im ), 0 ); |
162 | TEST( "count 0", int_map_count( & im ), 0 ); |
158 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
163 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
159 | TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 ); |
164 | TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 ); |
160 | TEST( "find 1 x", int_map_find( & im, 1 ), x ); |
165 | TEST( "find 1 x", int_map_find( & im, 1 ), x ); |
161 | int_map_exclude( & im, 1 ); |
166 | int_map_exclude( & im, 1 ); |
162 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
167 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
163 | TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 ); |
168 | TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 ); |
164 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
169 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
165 | TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 ); |
170 | TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 ); |
166 | TEST( "get 2 z", int_map_get_index( & im, 2 ), z ); |
171 | TEST( "get 2 z", int_map_get_index( & im, 2 ), z ); |
167 | TEST( "find 4 z", int_map_find( & im, 4 ), z ); |
172 | TEST( "find 4 z", int_map_find( & im, 4 ), z ); |
168 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
173 | TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
169 | TEST( "count 3", int_map_count( & im ), 3 ); |
174 | TEST( "count 3", int_map_count( & im ), 3 ); |
170 | TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 ); |
175 | TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 ); |
171 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
176 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
172 | TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 ); |
177 | TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 ); |
173 | TEST( "find 3 v", int_map_find( & im, 3 ), v ); |
178 | TEST( "find 3 v", int_map_find( & im, 3 ), v ); |
174 | TEST( "get 4 v", int_map_get_index( & im, 4 ), v ); |
179 | TEST( "get 4 v", int_map_get_index( & im, 4 ), v ); |
175 | TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 ); |
180 | TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 ); |
176 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
181 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
177 | TEST( "count 6", int_map_count( & im ), 6 ); |
182 | TEST( "count 6", int_map_count( & im ), 6 ); |
178 | int_map_exclude( & im, 1 ); |
183 | int_map_exclude( & im, 1 ); |
179 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
184 | TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
180 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
185 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
181 | int_map_exclude( & im, 7 ); |
186 | int_map_exclude( & im, 7 ); |
182 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
187 | TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
183 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
188 | TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
184 | int_map_exclude_index( & im, 4 ); |
189 | int_map_exclude_index( & im, 4 ); |
185 | TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL ); |
190 | TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL ); |
186 | TEST( "find 3 null", int_map_find( & im, 3 ), NULL ); |
191 | TEST( "find 3 null", int_map_find( & im, 3 ), NULL ); |
187 | printf( "\n\tdestroy" ); |
192 | printf( "\n\tdestroy" ); |
188 | int_map_destroy( & im ); |
193 | int_map_destroy( & im ); |
189 | TEST( "count -1", int_map_count( & im ), -1 ); |
194 | TEST( "count -1", int_map_count( & im ), -1 ); |
190 | printf( "\nOK" ); |
195 | printf( "\nOK" ); |
191 | 196 | ||
192 | if( error ) return EINVAL; |
197 | if( error ) return EINVAL; |
193 | 198 | ||
194 | #endif |
199 | #endif |
195 | 200 | ||
196 | #if NET_SELF_TEST_GENERIC_FIELD |
201 | #if NET_SELF_TEST_GENERIC_FIELD |
197 | int_field_t gf; |
202 | int_field_t gf; |
198 | 203 | ||
199 | x = ( int * ) malloc( sizeof( int )); |
204 | x = ( int * ) malloc( sizeof( int )); |
200 | y = ( int * ) malloc( sizeof( int )); |
205 | y = ( int * ) malloc( sizeof( int )); |
201 | z = ( int * ) malloc( sizeof( int )); |
206 | z = ( int * ) malloc( sizeof( int )); |
202 | u = ( int * ) malloc( sizeof( int )); |
207 | u = ( int * ) malloc( sizeof( int )); |
203 | v = ( int * ) malloc( sizeof( int )); |
208 | v = ( int * ) malloc( sizeof( int )); |
204 | w = ( int * ) malloc( sizeof( int )); |
209 | w = ( int * ) malloc( sizeof( int )); |
205 | 210 | ||
206 | gf.magic = 0; |
211 | gf.magic = 0; |
207 | printf( "\nGeneric field test" ); |
212 | printf( "\nGeneric field test" ); |
208 | TEST( "add x einval", int_field_add( & gf, x ), EINVAL ); |
213 | TEST( "add x einval", int_field_add( & gf, x ), EINVAL ); |
209 | TEST( "count -1", int_field_count( & gf ), -1 ); |
214 | TEST( "count -1", int_field_count( & gf ), -1 ); |
210 | TEST( "initialize", int_field_initialize( & gf ), EOK ); |
215 | TEST( "initialize", int_field_initialize( & gf ), EOK ); |
211 | TEST( "count 0", int_field_count( & gf ), 0 ); |
216 | TEST( "count 0", int_field_count( & gf ), 0 ); |
212 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
217 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
213 | TEST( "add x 0", int_field_add( & gf, x ), 0 ); |
218 | TEST( "add x 0", int_field_add( & gf, x ), 0 ); |
214 | TEST( "get 0 x", int_field_get_index( & gf, 0 ), x ); |
219 | TEST( "get 0 x", int_field_get_index( & gf, 0 ), x ); |
215 | int_field_exclude_index( & gf, 0 ); |
220 | int_field_exclude_index( & gf, 0 ); |
216 | TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL ); |
221 | TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL ); |
217 | TEST( "add y 1", int_field_add( & gf, y ), 1 ); |
222 | TEST( "add y 1", int_field_add( & gf, y ), 1 ); |
218 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
223 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
219 | TEST( "add z 2", int_field_add( & gf, z ), 2 ); |
224 | TEST( "add z 2", int_field_add( & gf, z ), 2 ); |
220 | TEST( "get 2 z", int_field_get_index( & gf, 2 ), z ); |
225 | TEST( "get 2 z", int_field_get_index( & gf, 2 ), z ); |
221 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
226 | TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
222 | TEST( "count 3", int_field_count( & gf ), 3 ); |
227 | TEST( "count 3", int_field_count( & gf ), 3 ); |
223 | TEST( "add u 3", int_field_add( & gf, u ), 3 ); |
228 | TEST( "add u 3", int_field_add( & gf, u ), 3 ); |
224 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
229 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
225 | TEST( "add v 4", int_field_add( & gf, v ), 4 ); |
230 | TEST( "add v 4", int_field_add( & gf, v ), 4 ); |
226 | TEST( "get 4 v", int_field_get_index( & gf, 4 ), v ); |
231 | TEST( "get 4 v", int_field_get_index( & gf, 4 ), v ); |
227 | TEST( "add w 5", int_field_add( & gf, w ), 5 ); |
232 | TEST( "add w 5", int_field_add( & gf, w ), 5 ); |
228 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
233 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
229 | TEST( "count 6", int_field_count( & gf ), 6 ); |
234 | TEST( "count 6", int_field_count( & gf ), 6 ); |
230 | int_field_exclude_index( & gf, 1 ); |
235 | int_field_exclude_index( & gf, 1 ); |
231 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
236 | TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
232 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
237 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
233 | int_field_exclude_index( & gf, 7 ); |
238 | int_field_exclude_index( & gf, 7 ); |
234 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
239 | TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
235 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
240 | TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
236 | int_field_exclude_index( & gf, 4 ); |
241 | int_field_exclude_index( & gf, 4 ); |
237 | TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL ); |
242 | TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL ); |
238 | printf( "\n\tdestroy" ); |
243 | printf( "\n\tdestroy" ); |
239 | int_field_destroy( & gf ); |
244 | int_field_destroy( & gf ); |
240 | TEST( "count -1", int_field_count( & gf ), -1 ); |
245 | TEST( "count -1", int_field_count( & gf ), -1 ); |
241 | printf( "\nOK" ); |
246 | printf( "\nOK" ); |
242 | 247 | ||
243 | if( error ) return EINVAL; |
248 | if( error ) return EINVAL; |
244 | 249 | ||
245 | #endif |
250 | #endif |
246 | 251 | ||
247 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
252 | #if NET_SELF_TEST_GENERIC_CHAR_MAP |
248 | int_char_map_t icm; |
253 | int_char_map_t icm; |
249 | 254 | ||
250 | x = ( int * ) malloc( sizeof( int )); |
255 | x = ( int * ) malloc( sizeof( int )); |
251 | y = ( int * ) malloc( sizeof( int )); |
256 | y = ( int * ) malloc( sizeof( int )); |
252 | z = ( int * ) malloc( sizeof( int )); |
257 | z = ( int * ) malloc( sizeof( int )); |
253 | u = ( int * ) malloc( sizeof( int )); |
258 | u = ( int * ) malloc( sizeof( int )); |
254 | v = ( int * ) malloc( sizeof( int )); |
259 | v = ( int * ) malloc( sizeof( int )); |
255 | w = ( int * ) malloc( sizeof( int )); |
260 | w = ( int * ) malloc( sizeof( int )); |
256 | 261 | ||
257 | icm.magic = 0; |
262 | icm.magic = 0; |
258 | printf( "\nGeneric char map test" ); |
263 | printf( "\nGeneric char map test" ); |
259 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
264 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
260 | TEST( "initialize", int_char_map_initialize( & icm ), EOK ); |
265 | TEST( "initialize", int_char_map_initialize( & icm ), EOK ); |
261 | printf( "\n\texclude bla null" ); |
266 | printf( "\n\texclude bla null" ); |
262 | int_char_map_exclude( & icm, "bla", 0 ); |
267 | int_char_map_exclude( & icm, "bla", 0 ); |
263 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
268 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
264 | TEST( "add bla x eok", int_char_map_add( & icm, "bla", 0, x ), EOK ); |
269 | TEST( "add bla x eok", int_char_map_add( & icm, "bla", 0, x ), EOK ); |
265 | TEST( "find bla x", int_char_map_find( & icm, "bla", 0 ), x ); |
270 | TEST( "find bla x", int_char_map_find( & icm, "bla", 0 ), x ); |
266 | TEST( "add bla y eexists", int_char_map_add( & icm, "bla", 0, y ), EEXISTS ); |
271 | TEST( "add bla y eexists", int_char_map_add( & icm, "bla", 0, y ), EEXISTS ); |
267 | printf( "\n\texclude bla y" ); |
272 | printf( "\n\texclude bla y" ); |
268 | int_char_map_exclude( & icm, "bla", 0 ); |
273 | int_char_map_exclude( & icm, "bla", 0 ); |
269 | printf( "\n\texclude bla null" ); |
274 | printf( "\n\texclude bla null" ); |
270 | int_char_map_exclude( & icm, "bla", 0 ); |
275 | int_char_map_exclude( & icm, "bla", 0 ); |
271 | TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", 0, v ), EOK ); |
276 | TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", 0, v ), EOK ); |
272 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
277 | TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v ); |
273 | TEST( "add bla w eok", int_char_map_add( & icm, "bla", 0, w ), EOK ); |
278 | TEST( "add bla w eok", int_char_map_add( & icm, "bla", 0, w ), EOK ); |
274 | TEST( "find bla w", int_char_map_find( & icm, "bla", 0 ), w ); |
279 | TEST( "find bla w", int_char_map_find( & icm, "bla", 0 ), w ); |
275 | printf( "\n\texclude bla" ); |
280 | printf( "\n\texclude bla" ); |
276 | int_char_map_exclude( & icm, "bla", 0 ); |
281 | int_char_map_exclude( & icm, "bla", 0 ); |
277 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
282 | TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL ); |
278 | 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 ); |
279 | TEST( "add auto u eok", int_char_map_add( & icm, "auto", 0, u ), EOK ); |
284 | TEST( "add auto u eok", int_char_map_add( & icm, "auto", 0, u ), EOK ); |
280 | TEST( "find auto u", int_char_map_find( & icm, "auto", 0 ), u ); |
285 | TEST( "find auto u", int_char_map_find( & icm, "auto", 0 ), u ); |
281 | printf( "\n\tdestroy" ); |
286 | printf( "\n\tdestroy" ); |
282 | int_char_map_destroy( & icm ); |
287 | int_char_map_destroy( & icm ); |
283 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
288 | TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL ); |
284 | printf( "\nOK" ); |
289 | printf( "\nOK" ); |
285 | 290 | ||
286 | if( error ) return EINVAL; |
291 | if( error ) return EINVAL; |
287 | 292 | ||
288 | #endif |
293 | #endif |
289 | 294 | ||
290 | #if NET_SELF_TEST_CRC |
295 | #if NET_SELF_TEST_CRC |
291 | uint32_t value; |
296 | uint32_t value; |
292 | 297 | ||
293 | printf( "\nCRC computation test" ); |
298 | printf( "\nCRC computation test" ); |
294 | value = ~ compute_crc32( ~ 0, "123456789", 8 * 9 ); |
299 | value = ~ compute_crc32( ~ 0, "123456789", 8 * 9 ); |
295 | TEST( "123456789", value, 0xCBF43926 ); |
300 | TEST( "123456789", value, 0xCBF43926 ); |
296 | printf( "\t=> %X", value ); |
301 | printf( "\t=> %X", value ); |
297 | value = ~ compute_crc32( ~ 0, "1", 8 ); |
302 | value = ~ compute_crc32( ~ 0, "1", 8 ); |
298 | TEST( "1", value, 0x83DCEFB7 ); |
303 | TEST( "1", value, 0x83DCEFB7 ); |
299 | printf( "\t=> %X", value ); |
304 | printf( "\t=> %X", value ); |
300 | value = ~ compute_crc32( ~ 0, "12", 8 * 2 ); |
305 | value = ~ compute_crc32( ~ 0, "12", 8 * 2 ); |
301 | TEST( "12", value, 0x4F5344CD ); |
306 | TEST( "12", value, 0x4F5344CD ); |
302 | printf( "\t=> %X", value ); |
307 | printf( "\t=> %X", value ); |
303 | value = ~ compute_crc32( ~ 0, "123", 8 * 3 ); |
308 | value = ~ compute_crc32( ~ 0, "123", 8 * 3 ); |
304 | TEST( "123", value, 0x884863D2 ); |
309 | TEST( "123", value, 0x884863D2 ); |
305 | printf( "\t=> %X", value ); |
310 | printf( "\t=> %X", value ); |
306 | value = ~ compute_crc32( ~ 0, "1234", 8 * 4 ); |
311 | value = ~ compute_crc32( ~ 0, "1234", 8 * 4 ); |
307 | TEST( "1234", value, 0x9BE3E0A3 ); |
312 | TEST( "1234", value, 0x9BE3E0A3 ); |
308 | printf( "\t=> %X", value ); |
313 | printf( "\t=> %X", value ); |
309 | value = ~ compute_crc32( ~ 0, "12345678", 8 * 8 ); |
314 | value = ~ compute_crc32( ~ 0, "12345678", 8 * 8 ); |
310 | TEST( "12345678", value, 0x9AE0DAAF ); |
315 | TEST( "12345678", value, 0x9AE0DAAF ); |
311 | printf( "\t=> %X", value ); |
316 | printf( "\t=> %X", value ); |
312 | value = ~ compute_crc32( ~ 0, "ahoj pane", 8 * 9 ); |
317 | value = ~ compute_crc32( ~ 0, "ahoj pane", 8 * 9 ); |
313 | TEST( "ahoj pane", value, 0x5FC3D706 ); |
318 | TEST( "ahoj pane", value, 0x5FC3D706 ); |
314 | printf( "\t=> %X", value ); |
319 | printf( "\t=> %X", value ); |
315 | 320 | ||
316 | if( error ) return EINVAL; |
321 | if( error ) return EINVAL; |
317 | 322 | ||
318 | #endif |
323 | #endif |
319 | 324 | ||
320 | return EOK; |
325 | return EOK; |
321 | } |
326 | } |
322 | 327 | ||
323 | #endif |
328 | #endif |
324 | 329 | ||
325 | /** @} |
330 | /** @} |
326 | */ |
331 | */ |
327 | 332 |