test/testiconv.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 09 May 2006 07:26:58 +0000
changeset 1790 828a17e05192
parent 1528 ff3322d66771
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3997 6a4f3a32c2e6
permissions -rw-r--r--
Date: Mon, 8 May 2006 14:19:30 -0700
From: Bob Ippolito
Subject: SDL trunk (r2346) and Mac OS X

The current state of the trunk doesn't quite compile on Mac OS X,
I've attached a series of patches that gets it to compile and kills a
few warnings.

sdl-trunk-r2346-dlcompat-warnings.diff:
The dlcompat thing is just loaded with incorrect type signatures ..
some of them have changed since 10.2 and others are just flat wrong.
This puts it in sync with the latest headers. People on 10.2 will get
the warnings instead of people with new kits.
     1 
     2 #include <stdio.h>
     3 
     4 #include "SDL.h"
     5 
     6 static size_t widelen(char *data)
     7 {
     8 	size_t len = 0;
     9 	Uint32 *p = (Uint32 *)data;
    10 	while(*p++) {
    11 		++len;
    12 	}
    13 	return len;
    14 }
    15 
    16 int main(int argc, char *argv[])
    17 {
    18 	const char * formats[] = {
    19 		"UTF8",
    20 		"UTF-8",
    21 		"UTF16BE",
    22 		"UTF-16BE",
    23 		"UTF16LE",
    24 		"UTF-16LE",
    25 		"UTF32BE",
    26 		"UTF-32BE",
    27 		"UTF32LE",
    28 		"UTF-32LE",
    29 		"UCS4",
    30 		"UCS-4",
    31 	};
    32 	char buffer[BUFSIZ];
    33 	char *ucs4;
    34 	char *test[2];
    35 	int i, index = 0;
    36 	FILE *file;
    37 	int errors = 0;
    38 
    39 	if ( !argv[1] ) {
    40 		argv[1] = "utf8.txt";
    41 	}
    42 	file = fopen(argv[1], "rb");
    43 	if ( !file ) {
    44 		fprintf(stderr, "Unable to open %s\n", argv[1]);
    45 		return (1);
    46 	}
    47 
    48 	while ( fgets(buffer, sizeof(buffer), file) ) {
    49 		/* Convert to UCS-4 */
    50 		size_t len;
    51 		ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1);
    52 		len = (widelen(ucs4)+1)*4;
    53 		for ( i = 0; i < SDL_arraysize(formats); ++i ) {
    54 			test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
    55 			test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
    56 			if ( SDL_memcmp(test[1], ucs4, len) != 0 ) {
    57 				fprintf(stderr, "FAIL: %s\n", formats[i]);
    58 				++errors;
    59 			}
    60 			SDL_free(test[0]);
    61 			SDL_free(test[1]);
    62 		}
    63 		test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
    64 		SDL_free(ucs4);
    65 		fputs(test[0], stdout);
    66 		SDL_free(test[0]);
    67 	}
    68 	return (errors ? errors + 1 : 0);
    69 }