Subversion Repositories HelenOS

Rev

Rev 3666 | Rev 4075 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3666 mejdrech 1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup net
30
 * @{
31
 */
32
 
33
/** @file
34
 */
35
 
36
#include "configuration.h"
37
 
38
#if NET_SELF_TEST
39
 
40
#include <errno.h>
41
#include <malloc.h>
42
#include <stdio.h>
43
 
44
#include "int_map.h"
45
#include "char_map.h"
46
#include "generic_char_map.h"
47
#include "measured_strings.h"
48
 
49
#include "self_test.h"
50
 
3846 mejdrech 51
#define TEST( name, function_call, result );    {   \
3666 mejdrech 52
    printf( "\n\t%s", ( name ));                    \
3846 mejdrech 53
    if(( function_call ) != ( result )){            \
54
        printf( "\tERROR" );                        \
55
    }else{                                          \
56
        printf( "\tOK" );                           \
57
    }                                               \
3666 mejdrech 58
}
59
 
60
#if NET_SELF_TEST_INT_MAP
61
 
62
    INT_MAP_DECLARE( int_map, int );
63
 
64
    INT_MAP_IMPLEMENT( int_map, int );
65
 
66
#endif
67
 
68
#if NET_SELF_TEST_GENERIC_FIELD
69
 
70
    GENERIC_FIELD_DECLARE( int_field, int )
71
 
72
    GENERIC_FIELD_IMPLEMENT( int_field, int )
73
 
74
#endif
75
 
76
#if NET_SELF_TEST_GENERIC_CHAR_MAP
77
 
78
    GENERIC_CHAR_MAP_DECLARE( int_char_map, int )
79
 
80
    GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int )
81
 
82
#endif
83
 
84
int self_test( void ){
85
    int * x, * y, * z, * u, * v, * w;
86
 
87
#if NET_SELF_TEST_MEASURED_STRINGS
88
    measured_string_ref string;
89
 
90
    printf( "\nMeasured strings test" );
91
    string = measured_string_create_bulk( "I am a measured string!", -1 );
92
    printf( "\n%x, %s at %x of %d", string, string->value, string->value, string->length );
93
    printf( "\nOK" );
94
#endif
95
 
96
#if NET_SELF_TEST_CHAR_MAP
97
    char_map_t  cm;
98
 
99
    printf( "\nChar map test" );
3846 mejdrech 100
    TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL );
3666 mejdrech 101
    TEST( "initialize", char_map_initialize( & cm ), EOK );
102
    TEST( "get_value", char_map_get_value( & cm ), CHAR_MAP_NULL );
3846 mejdrech 103
    TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL );
104
    TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL );
105
    TEST( "add bla 1 eok", char_map_add( & cm, "bla", 0, 1 ), EOK );
106
    TEST( "find bla 1", char_map_find( & cm, "bla", 0 ), 1 );
107
    TEST( "add bla 10 eexists", char_map_add( & cm, "bla", 0, 10 ), EEXISTS );
108
    TEST( "update bla 2 eok", char_map_update( & cm, "bla", 0, 2 ), EOK );
109
    TEST( "find bla 2", char_map_find( & cm, "bla", 0 ), 2 );
110
    TEST( "update ucho 2 eok", char_map_update( & cm, "ucho", 0, 2 ), EOK );
111
    TEST( "exclude bla 2", char_map_exclude( & cm, "bla", 0 ), 2 );
112
    TEST( "exclude bla null", char_map_exclude( & cm, "bla", 0 ), CHAR_MAP_NULL );
113
    TEST( "find ucho 2", char_map_find( & cm, "ucho", 0 ), 2 );
114
    TEST( "update ucho 3 eok", char_map_update( & cm, "ucho", 0, 3 ), EOK );
115
    TEST( "find ucho 3", char_map_find( & cm, "ucho", 0 ), 3 );
116
    TEST( "add blabla 5 eok", char_map_add( & cm, "blabla", 0, 5 ), EOK );
117
    TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 );
118
    TEST( "add bla 6 eok", char_map_add( & cm, "bla", 0, 6 ), EOK );
119
    TEST( "find bla 6", char_map_find( & cm, "bla", 0 ), 6 );
120
    TEST( "exclude bla 6", char_map_exclude( & cm, "bla", 0 ), 6 );
121
    TEST( "find bla null", char_map_find( & cm, "bla", 0 ), CHAR_MAP_NULL );
122
    TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 );
123
    TEST( "add auto 7 eok", char_map_add( & cm, "auto", 0, 7 ), EOK );
124
    TEST( "find auto 7", char_map_find( & cm, "auto", 0 ), 7 );
125
    TEST( "add kara 8 eok", char_map_add( & cm, "kara", 0, 8 ), EOK );
126
    TEST( "find kara 8", char_map_find( & cm, "kara", 0 ), 8 );
127
    TEST( "add nic 9 eok", char_map_add( & cm, "nic", 0, 9 ), EOK );
128
    TEST( "find nic 9", char_map_find( & cm, "nic", 0 ), 9 );
129
    TEST( "find blabla 5", char_map_find( & cm, "blabla", 0 ), 5 );
3666 mejdrech 130
    printf( "\n\tdestroy" );
131
    char_map_destroy( & cm );
3846 mejdrech 132
    TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL );
3666 mejdrech 133
    printf( "\nOK" );
134
 
135
#endif
136
 
137
#if NET_SELF_TEST_INT_MAP
138
 
139
    int_map_t   im;
140
 
141
    x = ( int * ) malloc( sizeof( int ));
142
    y = ( int * ) malloc( sizeof( int ));
143
    z = ( int * ) malloc( sizeof( int ));
144
    u = ( int * ) malloc( sizeof( int ));
145
    v = ( int * ) malloc( sizeof( int ));
146
    w = ( int * ) malloc( sizeof( int ));
147
 
148
    im.magic = 0;
149
    printf( "\nInt map test" );
150
    TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL );
151
    TEST( "count -1", int_map_count( & im ), -1 );
152
    TEST( "initialize", int_map_initialize( & im ), EOK );
153
    TEST( "count 0", int_map_count( & im ), 0 );
154
    TEST( "find 1 null", int_map_find( & im, 1 ), NULL );
155
    TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 );
156
    TEST( "find 1 x", int_map_find( & im, 1 ), x );
157
    int_map_exclude( & im, 1 );
158
    TEST( "find 1 null", int_map_find( & im, 1 ), NULL );
159
    TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 );
160
    TEST( "find 1 y", int_map_find( & im, 1 ), y );
161
    TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 );
162
    TEST( "get 2 z", int_map_get_index( & im, 2 ), z );
163
    TEST( "find 4 z", int_map_find( & im, 4 ), z );
164
    TEST( "find 1 y", int_map_find( & im, 1 ), y );
165
    TEST( "count 3", int_map_count( & im ), 3 );
166
    TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 );
167
    TEST( "find 2 u", int_map_find( & im, 2 ), u );
168
    TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 );
169
    TEST( "find 3 v", int_map_find( & im, 3 ), v );
170
    TEST( "get 4 v", int_map_get_index( & im, 4 ), v );
171
    TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 );
172
    TEST( "find 6 w", int_map_find( & im, 6 ), w );
173
    TEST( "count 6", int_map_count( & im ), 6 );
174
    int_map_exclude( & im, 1 );
175
    TEST( "find 1 null", int_map_find( & im, 1 ), NULL );
176
    TEST( "find 2 u", int_map_find( & im, 2 ), u );
177
    int_map_exclude( & im, 7 );
178
    TEST( "find 2 u", int_map_find( & im, 2 ), u );
179
    TEST( "find 6 w", int_map_find( & im, 6 ), w );
180
    int_map_exclude_index( & im, 4 );
181
    TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL );
182
    TEST( "find 3 null", int_map_find( & im, 3 ), NULL );
183
    printf( "\n\tdestroy" );
184
    int_map_destroy( & im );
185
    TEST( "count -1", int_map_count( & im ), -1 );
186
    printf( "\nOK" );
187
 
188
#endif
189
 
190
#if NET_SELF_TEST_GENERIC_FIELD
191
 
192
    int_field_t gf;
193
 
194
    x = ( int * ) malloc( sizeof( int ));
195
    y = ( int * ) malloc( sizeof( int ));
196
    z = ( int * ) malloc( sizeof( int ));
197
    u = ( int * ) malloc( sizeof( int ));
198
    v = ( int * ) malloc( sizeof( int ));
199
    w = ( int * ) malloc( sizeof( int ));
200
 
201
    gf.magic = 0;
202
    printf( "\nGeneric field test" );
203
    TEST( "add x einval", int_field_add( & gf, x ), EINVAL );
204
    TEST( "count -1", int_field_count( & gf ), -1 );
205
    TEST( "initialize", int_field_initialize( & gf ), EOK );
206
    TEST( "count 0", int_field_count( & gf ), 0 );
207
    TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL );
208
    TEST( "add x 0", int_field_add( & gf, x ), 0 );
209
    TEST( "get 0 x", int_field_get_index( & gf, 0 ), x );
210
    int_field_exclude_index( & gf, 0 );
211
    TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL );
212
    TEST( "add y 1", int_field_add( & gf, y ), 1 );
213
    TEST( "get 1 y", int_field_get_index( & gf, 1 ), y );
214
    TEST( "add z 2", int_field_add( & gf, z ), 2 );
215
    TEST( "get 2 z", int_field_get_index( & gf, 2 ), z );
216
    TEST( "get 1 y", int_field_get_index( & gf, 1 ), y );
217
    TEST( "count 3", int_field_count( & gf ), 3 );
218
    TEST( "add u 3", int_field_add( & gf, u ), 3 );
219
    TEST( "get 3 u", int_field_get_index( & gf, 3 ), u );
220
    TEST( "add v 4", int_field_add( & gf, v ), 4 );
221
    TEST( "get 4 v", int_field_get_index( & gf, 4 ), v );
222
    TEST( "add w 5", int_field_add( & gf, w ), 5 );
223
    TEST( "get 5 w", int_field_get_index( & gf, 5 ), w );
224
    TEST( "count 6", int_field_count( & gf ), 6 );
225
    int_field_exclude_index( & gf, 1 );
226
    TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL );
227
    TEST( "get 3 u", int_field_get_index( & gf, 3 ), u );
228
    int_field_exclude_index( & gf, 7 );
229
    TEST( "get 3 u", int_field_get_index( & gf, 3 ), u );
230
    TEST( "get 5 w", int_field_get_index( & gf, 5 ), w );
231
    int_field_exclude_index( & gf, 4 );
232
    TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL );
233
    printf( "\n\tdestroy" );
234
    int_field_destroy( & gf );
235
    TEST( "count -1", int_field_count( & gf ), -1 );
236
    printf( "\nOK" );
237
 
238
#endif
239
 
240
#if NET_SELF_TEST_GENERIC_CHAR_MAP
241
 
242
    int_char_map_t  icm;
243
 
244
    x = ( int * ) malloc( sizeof( int ));
245
    y = ( int * ) malloc( sizeof( int ));
246
    z = ( int * ) malloc( sizeof( int ));
247
    u = ( int * ) malloc( sizeof( int ));
248
    v = ( int * ) malloc( sizeof( int ));
249
    w = ( int * ) malloc( sizeof( int ));
250
 
251
    icm.magic = 0;
252
    printf( "\nGeneric char map test" );
3846 mejdrech 253
    TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL );
3666 mejdrech 254
    TEST( "initialize", int_char_map_initialize( & icm ), EOK );
255
    printf( "\n\texclude bla null" );
3846 mejdrech 256
    int_char_map_exclude( & icm, "bla", 0 );
257
    TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL );
258
    TEST( "add bla x eok", int_char_map_add( & icm, "bla", 0, x ), EOK );
259
    TEST( "find bla x", int_char_map_find( & icm, "bla", 0 ), x );
260
    TEST( "add bla y eexists", int_char_map_add( & icm, "bla", 0, y ), EEXISTS );
3666 mejdrech 261
    printf( "\n\texclude bla y" );
3846 mejdrech 262
    int_char_map_exclude( & icm, "bla", 0 );
3666 mejdrech 263
    printf( "\n\texclude bla null" );
3846 mejdrech 264
    int_char_map_exclude( & icm, "bla", 0 );
265
    TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", 0, v ), EOK );
266
    TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v );
267
    TEST( "add bla w eok", int_char_map_add( & icm, "bla", 0, w ), EOK );
268
    TEST( "find bla w", int_char_map_find( & icm, "bla", 0 ), w );
3666 mejdrech 269
    printf( "\n\texclude bla" );
3846 mejdrech 270
    int_char_map_exclude( & icm, "bla", 0 );
271
    TEST( "find bla null", int_char_map_find( & icm, "bla", 0 ), NULL );
272
    TEST( "find blabla v", int_char_map_find( & icm, "blabla", 0 ), v );
273
    TEST( "add auto u eok", int_char_map_add( & icm, "auto", 0, u ), EOK );
274
    TEST( "find auto u", int_char_map_find( & icm, "auto", 0 ), u );
3666 mejdrech 275
    printf( "\n\tdestroy" );
276
    int_char_map_destroy( & icm );
3846 mejdrech 277
    TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL );
3666 mejdrech 278
    printf( "\nOK" );
279
 
280
#endif
281
 
282
    return EOK;
283
}
284
 
285
#endif
286
 
287
/** @}
288
 */