/[pcsx2_0.9.7]/trunk/3rdparty/SDL-1.3.0-5387/test/testiconv.c
ViewVC logotype

Contents of /trunk/3rdparty/SDL-1.3.0-5387/test/testiconv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (show annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 9 months ago) by william
File MIME type: text/plain
File size: 1778 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1
2 #include <stdio.h>
3
4 #include "SDL.h"
5
6 static size_t
7 widelen(char *data)
8 {
9 size_t len = 0;
10 Uint32 *p = (Uint32 *) data;
11 while (*p++) {
12 ++len;
13 }
14 return len;
15 }
16
17 int
18 main(int argc, char *argv[])
19 {
20 const char *formats[] = {
21 "UTF8",
22 "UTF-8",
23 "UTF16BE",
24 "UTF-16BE",
25 "UTF16LE",
26 "UTF-16LE",
27 "UTF32BE",
28 "UTF-32BE",
29 "UTF32LE",
30 "UTF-32LE",
31 "UCS4",
32 "UCS-4",
33 };
34 char buffer[BUFSIZ];
35 char *ucs4;
36 char *test[2];
37 int i, index = 0;
38 FILE *file;
39 int errors = 0;
40
41 if (!argv[1]) {
42 argv[1] = "utf8.txt";
43 }
44 file = fopen(argv[1], "rb");
45 if (!file) {
46 fprintf(stderr, "Unable to open %s\n", argv[1]);
47 return (1);
48 }
49
50 while (fgets(buffer, sizeof(buffer), file)) {
51 /* Convert to UCS-4 */
52 size_t len;
53 ucs4 =
54 SDL_iconv_string("UCS-4", "UTF-8", buffer,
55 SDL_strlen(buffer) + 1);
56 len = (widelen(ucs4) + 1) * 4;
57 for (i = 0; i < SDL_arraysize(formats); ++i) {
58 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
59 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
60 if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) {
61 fprintf(stderr, "FAIL: %s\n", formats[i]);
62 ++errors;
63 }
64 if (test[0]) {
65 SDL_free(test[0]);
66 }
67 if (test[1]) {
68 SDL_free(test[1]);
69 }
70 }
71 test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
72 SDL_free(ucs4);
73 fputs(test[0], stdout);
74 SDL_free(test[0]);
75 }
76 return (errors ? errors + 1 : 0);
77 }

  ViewVC Help
Powered by ViewVC 1.1.22