]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/iotest/trnstst.c
2 **********************************************************************
3 * Copyright (C) 2005-2005, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * created by: George Rhoten
11 #include "unicode/ustdio.h"
12 #include "unicode/utrans.h"
13 #include "unicode/ustring.h"
15 static void TestTranslitOps(void)
17 #if !UCONFIG_NO_TRANSLITERATION
19 UErrorCode err
= U_ZERO_ERROR
;
20 UTransliterator
*a
= NULL
, *b
= NULL
, *c
= NULL
;
22 log_verbose("opening a transliterator and UFILE for testing\n");
24 f
= u_fopen(STANDARD_TEST_FILE
, "w", "en_US_POSIX", NULL
);
27 log_err("Couldn't open test file for writing\n");
31 a
= utrans_open("Latin-Greek", UTRANS_FORWARD
, NULL
, -1, NULL
, &err
);
34 log_err("Error opening transliterator %s\n", u_errorName(err
));
40 log_verbose("setting a transliterator\n");
41 b
= u_fsettransliterator(f
, U_WRITE
, a
, &err
);
44 log_err("Error setting transliterator %s\n", u_errorName(err
));
51 log_err("Error, a transliterator was already set!\n");
54 b
= u_fsettransliterator(NULL
, U_WRITE
, a
, &err
);
55 if(err
!= U_ILLEGAL_ARGUMENT_ERROR
)
57 log_err("Error setting transliterator on NULL file err=%s\n", u_errorName(err
));
62 log_err("Error getting the same transliterator was not returned on NULL file\n");
65 err
= U_FILE_ACCESS_ERROR
;
66 b
= u_fsettransliterator(f
, U_WRITE
, a
, &err
);
67 if(err
!= U_FILE_ACCESS_ERROR
)
69 log_err("Error setting transliterator on error status err=%s\n", u_errorName(err
));
74 log_err("Error getting the same transliterator on error status\n");
79 log_verbose("un-setting transliterator (setting to null)\n");
80 c
= u_fsettransliterator(f
, U_WRITE
, NULL
, &err
);
83 log_err("Err setting transliterator %s\n", u_errorName(err
));
90 log_err("Err, transliterator that came back was not the original one.\n");
93 log_verbose("Trying to set read transliterator (should fail)\n");
94 b
= u_fsettransliterator(f
, U_READ
, NULL
, &err
);
95 if(err
!= U_UNSUPPORTED_ERROR
)
97 log_err("Should have U_UNSUPPORTED_ERROR setting Read transliterator but got %s - REVISIT AND UPDATE TEST\n", u_errorName(err
));
103 log_verbose("Got %s error (expected) setting READ transliterator.\n", u_errorName(err
));
113 static void TestTranslitFileOut(void)
115 #if !UCONFIG_NO_FORMATTING
116 #if !UCONFIG_NO_TRANSLITERATION
118 UErrorCode err
= U_ZERO_ERROR
;
119 UTransliterator
*a
= NULL
, *b
= NULL
, *c
= NULL
;
121 UChar compare
[] = { 0xfeff, 0x03a3, 0x03c4, 0x03b5, 0x03c6, 0x1f00, 0x03bd, 0x03bf, 0x03c2, 0x043C, 0x0000 };
125 log_verbose("opening a transliterator and UFILE for testing\n");
127 f
= u_fopen(STANDARD_TEST_FILE
, "w", "en_US_POSIX", "utf-16");
130 log_err("Couldn't open test file for writing\n");
134 a
= utrans_open("Latin-Greek", UTRANS_FORWARD
, NULL
, -1, NULL
, &err
);
137 log_err("Err opening transliterator %s\n", u_errorName(err
));
142 log_verbose("setting a transliterator\n");
143 b
= u_fsettransliterator(f
, U_WRITE
, a
, &err
);
146 log_err("Err setting transliterator %s\n", u_errorName(err
));
153 log_err("Err, a transliterator was already set!\n");
156 u_fprintf(f
, "Stephanos");
158 c
= utrans_open("Latin-Cyrillic", UTRANS_FORWARD
, NULL
, -1, NULL
, &err
);
161 log_err("Err opening transliterator %s\n", u_errorName(err
));
166 log_verbose("setting a transliterator\n");
167 b
= u_fsettransliterator(f
, U_WRITE
, c
, &err
);
170 log_err("Err setting transliterator %s\n", u_errorName(err
));
177 log_err("Error: a different transliterator was returned!\n");
185 log_verbose("Re reading test file to verify transliteration\n");
186 infile
= fopen(STANDARD_TEST_FILE
, "rb");
189 log_err("Couldn't reopen test file\n");
193 len
=fread(ubuf
, sizeof(UChar
), u_strlen(compare
), infile
);
194 log_verbose("Read %d UChars\n", len
);
195 if(len
!= u_strlen(compare
))
197 log_err("Wanted %d UChars from file, got %d\n", u_strlen(compare
), len
);
201 if(u_strlen(compare
) != u_strlen(ubuf
))
203 log_err("Wanted %d UChars from file, but u_strlen() returns %d\n", u_strlen(compare
), len
);
206 if(u_strcmp(compare
, ubuf
))
208 log_err("Read string doesn't match expected.\n");
212 log_verbose("Read string matches expected.\n");
220 static void TestTranslitStringOut(void)
222 #if !UCONFIG_NO_FORMATTING
223 #if !UCONFIG_NO_TRANSLITERATION
225 UErrorCode err
= U_ZERO_ERROR
;
226 UTransliterator
*a
= NULL
, *b
= NULL
, *c
= NULL
;
227 UChar compare
[] = { 0x03a3, 0x03c4, 0x03b5, 0x03c6, 0x1f00, 0x03bd, 0x03bf, 0x03c2, 0x043C, 0x0000 };
230 log_verbose("opening a transliterator and UFILE for testing\n");
232 f
= u_fstropen(ubuf
, sizeof(ubuf
)/sizeof(ubuf
[0]), "en_US_POSIX");
235 log_err("Couldn't open test file for writing\n");
239 a
= utrans_open("Latin-Greek", UTRANS_FORWARD
, NULL
, -1, NULL
, &err
);
242 log_err("Err opening transliterator %s\n", u_errorName(err
));
247 log_verbose("setting a transliterator\n");
248 b
= u_fsettransliterator(f
, U_WRITE
, a
, &err
);
251 log_err("Err setting transliterator %s\n", u_errorName(err
));
258 log_err("Err, a transliterator was already set!\n");
261 u_fprintf(f
, "Stephanos");
263 c
= utrans_open("Latin-Cyrillic", UTRANS_FORWARD
, NULL
, -1, NULL
, &err
);
266 log_err("Err opening transliterator %s\n", u_errorName(err
));
271 log_verbose("setting a transliterator\n");
272 b
= u_fsettransliterator(f
, U_WRITE
, c
, &err
);
275 log_err("Err setting transliterator %s\n", u_errorName(err
));
282 log_err("Error: a different transliterator was returned!\n");
290 if(u_strlen(compare
) != u_strlen(ubuf
))
292 log_err("Wanted %d UChars from file, but u_strlen() returns %d\n", u_strlen(compare
), u_strlen(ubuf
));
295 if(u_strcmp(compare
, ubuf
))
297 log_err("Read string doesn't match expected.\n");
301 log_verbose("Read string matches expected.\n");
308 addTranslitTest(TestNode
** root
) {
309 #if !UCONFIG_NO_TRANSLITERATION
310 addTest(root
, &TestTranslitOps
, "translit/ops");
311 #if !UCONFIG_NO_FORMATTING
312 addTest(root
, &TestTranslitFileOut
, "translit/fileOut");
313 addTest(root
, &TestTranslitStringOut
, "translit/stringOut");