Subversion Repositories HelenOS

Rev

Rev 3912 | Rev 4350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3912 Rev 4075
Line 39... Line 39...
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 "int_map.h"
44
#include "include/crc.h"
-
 
45
#include "structures/int_map.h"
45
#include "char_map.h"
46
#include "structures/char_map.h"
46
#include "generic_char_map.h"
47
#include "structures/generic_char_map.h"
47
#include "measured_strings.h"
48
#include "structures/measured_strings.h"
48
 
49
 
49
#include "self_test.h"
50
#include "self_test.h"
50
 
51
 
51
#define TEST( name, function_call, result );    {   \
52
#define TEST( name, function_call, result );    {   \
52
    printf( "\n\t%s", ( name ));                    \
53
    printf( "\n\t%s", ( name ));                    \
53
    if(( function_call ) != ( result )){            \
54
    if(( function_call ) != ( result )){            \
54
        printf( "\tERROR" );                        \
55
        printf( "\tERROR" );                        \
-
 
56
        error = 1;                                  \
55
    }else{                                          \
57
    }else{                                          \
56
        printf( "\tOK" );                           \
58
        printf( "\tOK" );                           \
57
    }                                               \
59
    }                                               \
58
}
60
}
59
 
61
 
Line 80... Line 82...
80
    GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int )
82
    GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int )
81
 
83
 
82
#endif
84
#endif
83
 
85
 
84
int self_test( void ){
86
int self_test( void ){
-
 
87
    int error = 0;
85
    int * x, * y, * z, * u, * v, * w;
88
    int * x, * y, * z, * u, * v, * w;
86
 
89
 
87
#if NET_SELF_TEST_MEASURED_STRINGS
90
#if NET_SELF_TEST_MEASURED_STRINGS
88
    measured_string_ref string;
91
    measured_string_ref string;
89
 
92
 
90
    printf( "\nMeasured strings test" );
93
    printf( "\nMeasured strings test" );
91
    string = measured_string_create_bulk( "I am a measured string!", -1 );
94
    string = measured_string_create_bulk( "I am a measured string!", 0 );
92
    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 );
93
    printf( "\nOK" );
96
    printf( "\nOK" );
94
#endif
97
#endif
95
 
98
 
96
#if NET_SELF_TEST_CHAR_MAP
99
#if NET_SELF_TEST_CHAR_MAP
Line 130... Line 133...
130
    printf( "\n\tdestroy" );
133
    printf( "\n\tdestroy" );
131
    char_map_destroy( & cm );
134
    char_map_destroy( & cm );
132
    TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL );
135
    TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 0, 3 ), EINVAL );
133
    printf( "\nOK" );
136
    printf( "\nOK" );
134
 
137
 
-
 
138
    if( error ) return EINVAL;
-
 
139
 
135
#endif
140
#endif
136
 
141
 
137
#if NET_SELF_TEST_INT_MAP
142
#if NET_SELF_TEST_INT_MAP
138
 
-
 
139
    int_map_t   im;
143
    int_map_t   im;
140
 
144
 
141
    x = ( int * ) malloc( sizeof( int ));
145
    x = ( int * ) malloc( sizeof( int ));
142
    y = ( int * ) malloc( sizeof( int ));
146
    y = ( int * ) malloc( sizeof( int ));
143
    z = ( int * ) malloc( sizeof( int ));
147
    z = ( int * ) malloc( sizeof( int ));
Line 183... Line 187...
183
    printf( "\n\tdestroy" );
187
    printf( "\n\tdestroy" );
184
    int_map_destroy( & im );
188
    int_map_destroy( & im );
185
    TEST( "count -1", int_map_count( & im ), -1 );
189
    TEST( "count -1", int_map_count( & im ), -1 );
186
    printf( "\nOK" );
190
    printf( "\nOK" );
187
 
191
 
-
 
192
    if( error ) return EINVAL;
-
 
193
 
188
#endif
194
#endif
189
 
195
 
190
#if NET_SELF_TEST_GENERIC_FIELD
196
#if NET_SELF_TEST_GENERIC_FIELD
191
 
-
 
192
    int_field_t gf;
197
    int_field_t gf;
193
 
198
 
194
    x = ( int * ) malloc( sizeof( int ));
199
    x = ( int * ) malloc( sizeof( int ));
195
    y = ( int * ) malloc( sizeof( int ));
200
    y = ( int * ) malloc( sizeof( int ));
196
    z = ( int * ) malloc( sizeof( int ));
201
    z = ( int * ) malloc( sizeof( int ));
Line 233... Line 238...
233
    printf( "\n\tdestroy" );
238
    printf( "\n\tdestroy" );
234
    int_field_destroy( & gf );
239
    int_field_destroy( & gf );
235
    TEST( "count -1", int_field_count( & gf ), -1 );
240
    TEST( "count -1", int_field_count( & gf ), -1 );
236
    printf( "\nOK" );
241
    printf( "\nOK" );
237
 
242
 
-
 
243
    if( error ) return EINVAL;
-
 
244
 
238
#endif
245
#endif
239
 
246
 
240
#if NET_SELF_TEST_GENERIC_CHAR_MAP
247
#if NET_SELF_TEST_GENERIC_CHAR_MAP
241
 
-
 
242
    int_char_map_t  icm;
248
    int_char_map_t  icm;
243
 
249
 
244
    x = ( int * ) malloc( sizeof( int ));
250
    x = ( int * ) malloc( sizeof( int ));
245
    y = ( int * ) malloc( sizeof( int ));
251
    y = ( int * ) malloc( sizeof( int ));
246
    z = ( int * ) malloc( sizeof( int ));
252
    z = ( int * ) malloc( sizeof( int ));
Line 275... Line 281...
275
    printf( "\n\tdestroy" );
281
    printf( "\n\tdestroy" );
276
    int_char_map_destroy( & icm );
282
    int_char_map_destroy( & icm );
277
    TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL );
283
    TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", 0, z ), EINVAL );
278
    printf( "\nOK" );
284
    printf( "\nOK" );
279
 
285
 
-
 
286
    if( error ) return EINVAL;
-
 
287
 
-
 
288
#endif
-
 
289
 
-
 
290
#if NET_SELF_TEST_CRC
-
 
291
    uint32_t    value;
-
 
292
 
-
 
293
    printf( "\nCRC computation test" );
-
 
294
    value = ~ compute_crc32( ~ 0, "123456789", 8 * 9 );
-
 
295
    TEST( "123456789", value, 0xCBF43926 );
-
 
296
    printf( "\t=> %X", value );
-
 
297
    value = ~ compute_crc32( ~ 0, "1", 8 );
-
 
298
    TEST( "1", value, 0x83DCEFB7 );
-
 
299
    printf( "\t=> %X", value );
-
 
300
    value = ~ compute_crc32( ~ 0, "12", 8 * 2 );
-
 
301
    TEST( "12", value, 0x4F5344CD );
-
 
302
    printf( "\t=> %X", value );
-
 
303
    value = ~ compute_crc32( ~ 0, "123", 8 * 3 );
-
 
304
    TEST( "123", value, 0x884863D2 );
-
 
305
    printf( "\t=> %X", value );
-
 
306
    value = ~ compute_crc32( ~ 0, "1234", 8 * 4 );
-
 
307
    TEST( "1234", value, 0x9BE3E0A3 );
-
 
308
    printf( "\t=> %X", value );
-
 
309
    value = ~ compute_crc32( ~ 0, "12345678", 8 * 8 );
-
 
310
    TEST( "12345678", value, 0x9AE0DAAF );
-
 
311
    printf( "\t=> %X", value );
-
 
312
    value = ~ compute_crc32( ~ 0, "ahoj pane", 8 * 9 );
-
 
313
    TEST( "ahoj pane", value, 0x5FC3D706 );
-
 
314
    printf( "\t=> %X", value );
-
 
315
 
-
 
316
    if( error ) return EINVAL;
-
 
317
 
280
#endif
318
#endif
281
 
319
 
282
    return EOK;
320
    return EOK;
283
}
321
}
284
 
322