1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
/*
* utf8_test.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "utf8.h"
char progname[] = "utf8_test";
int
test_utf8( void )
{
char buf[512];
unsigned int i, j;
int nc, pos, failed = 0;
for ( i=0; i<1000000; ++i ) {
nc = utf8_encode( i, buf );
buf[ nc ] = '*';
buf[ nc+1 ] = '\0';
pos = 0;
j = utf8_decode( buf, &pos );
if ( i != j ) {
printf( "%s: Error test_utf8 mismatch, "
"send %u got back %u\n", progname, i, j );
failed = 1;
}
if ( buf[pos]!='*' ) {
printf( "%s: Error test_utf8 bad ending pos, "
"expect '*', got back '%c'\n", progname,
buf[pos] );
}
}
return failed;
}
int
main( int argc, char *argv[] )
{
int failed = 0;
failed += test_utf8();
if ( !failed ) {
printf( "%s: PASSED\n", progname );
return EXIT_SUCCESS;
} else {
printf( "%s: FAILED\n", progname );
return EXIT_FAILURE;
}
}
|