Disable audio device when silent profile is selected.
[SDL.s60v3.git] / test / testiconv.c
blob53415d00594180b9bb2a33b73ef05646729a481e
2 #include <stdio.h>
4 #include "SDL.h"
6 static size_t widelen(char *data)
8 size_t len = 0;
9 Uint32 *p = (Uint32 *)data;
10 while(*p++) {
11 ++len;
13 return len;
16 int main(int argc, char *argv[])
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",
32 char buffer[BUFSIZ];
33 char *ucs4;
34 char *test[2];
35 int i, index = 0;
36 FILE *file;
37 int errors = 0;
39 if ( !argv[1] ) {
40 argv[1] = "utf8.txt";
42 file = fopen(argv[1], "rb");
43 if ( !file ) {
44 fprintf(stderr, "Unable to open %s\n", argv[1]);
45 return (1);
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 ( !test[1] || SDL_memcmp(test[1], ucs4, len) != 0 ) {
57 fprintf(stderr, "FAIL: %s\n", formats[i]);
58 ++errors;
60 if ( test[0] ) {
61 SDL_free(test[0]);
63 if ( test[1] ) {
64 SDL_free(test[1]);
67 test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
68 SDL_free(ucs4);
69 fputs(test[0], stdout);
70 SDL_free(test[0]);
72 return (errors ? errors + 1 : 0);