| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 2001-2013, International Business Machines Corporation and | 3 * Copyright (c) 2001-2014, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 /*******************************************************************************
* | 6 /*******************************************************************************
* |
| 7 * | 7 * |
| 8 * File custrtrn.C | 8 * File custrtrn.C |
| 9 * | 9 * |
| 10 * Modification History: | 10 * Modification History: |
| 11 * Name Description | 11 * Name Description |
| 12 * Ram String transformations test | 12 * Ram String transformations test |
| 13 ********************************************************************************
* | 13 ********************************************************************************
* |
| 14 */ | 14 */ |
| 15 /****************************************************************************/ | 15 /****************************************************************************/ |
| 16 | 16 |
| 17 | 17 |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #include <stdio.h> | 19 #include <stdio.h> |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 #include "unicode/utypes.h" | 21 #include "unicode/utypes.h" |
| 22 #include "unicode/ustring.h" | 22 #include "unicode/ustring.h" |
| 23 #include "unicode/ures.h" | 23 #include "unicode/ures.h" |
| 24 #include "ustr_imp.h" | 24 #include "ustr_imp.h" |
| 25 #include "cintltst.h" | 25 #include "cintltst.h" |
| 26 #include "cmemory.h" | 26 #include "cmemory.h" |
| 27 #include "cstring.h" | 27 #include "cstring.h" |
| 28 #include "cwchar.h" | 28 #include "cwchar.h" |
| 29 | 29 |
| 30 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
| 31 | |
| 32 void addUCharTransformTest(TestNode** root); | 30 void addUCharTransformTest(TestNode** root); |
| 33 | 31 |
| 34 static void Test_strToUTF32(void); | 32 static void Test_strToUTF32(void); |
| 35 static void Test_strToUTF32_surrogates(void); | 33 static void Test_strToUTF32_surrogates(void); |
| 36 static void Test_strFromUTF32(void); | 34 static void Test_strFromUTF32(void); |
| 37 static void Test_strFromUTF32_surrogates(void); | 35 static void Test_strFromUTF32_surrogates(void); |
| 38 static void Test_UChar_UTF8_API(void); | 36 static void Test_UChar_UTF8_API(void); |
| 39 static void Test_FromUTF8(void); | 37 static void Test_FromUTF8(void); |
| 40 static void Test_FromUTF8Lenient(void); | 38 static void Test_FromUTF8Lenient(void); |
| 41 static void Test_UChar_WCHART_API(void); | 39 static void Test_UChar_WCHART_API(void); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 140 |
| 143 | 141 |
| 144 static void Test_strToUTF32(void){ | 142 static void Test_strToUTF32(void){ |
| 145 UErrorCode err = U_ZERO_ERROR; | 143 UErrorCode err = U_ZERO_ERROR; |
| 146 UChar32 u32Target[400]; | 144 UChar32 u32Target[400]; |
| 147 int32_t u32DestLen; | 145 int32_t u32DestLen; |
| 148 int i= 0; | 146 int i= 0; |
| 149 | 147 |
| 150 /* first with length */ | 148 /* first with length */ |
| 151 u32DestLen = -2; | 149 u32DestLen = -2; |
| 152 u_strToUTF32(u32Target, 0, &u32DestLen, src16, LENGTHOF(src16),&err); | 150 u_strToUTF32(u32Target, 0, &u32DestLen, src16, UPRV_LENGTHOF(src16),&err); |
| 153 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != LENGTHOF(src32)) { | 151 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != UPRV_LENGTHOF(src32)) { |
| 154 log_err("u_strToUTF32(preflight with length): " | 152 log_err("u_strToUTF32(preflight with length): " |
| 155 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", | 153 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", |
| 156 (long)u32DestLen, (long)LENGTHOF(src32), u_errorName(err)); | 154 (long)u32DestLen, (long)UPRV_LENGTHOF(src32), u_errorName(err)); |
| 157 return; | 155 return; |
| 158 } | 156 } |
| 159 err = U_ZERO_ERROR; | 157 err = U_ZERO_ERROR; |
| 160 u32DestLen = -2; | 158 u32DestLen = -2; |
| 161 u_strToUTF32(u32Target, LENGTHOF(src32)+1, &u32DestLen, src16, LENGTHOF(src1
6),&err); | 159 u_strToUTF32(u32Target, UPRV_LENGTHOF(src32)+1, &u32DestLen, src16, UPRV_LEN
GTHOF(src16),&err); |
| 162 if(err != U_ZERO_ERROR || u32DestLen != LENGTHOF(src32)) { | 160 if(err != U_ZERO_ERROR || u32DestLen != UPRV_LENGTHOF(src32)) { |
| 163 log_err("u_strToUTF32(with length): " | 161 log_err("u_strToUTF32(with length): " |
| 164 "length %ld != %ld and %s != U_ZERO_ERROR\n", | 162 "length %ld != %ld and %s != U_ZERO_ERROR\n", |
| 165 (long)u32DestLen, (long)LENGTHOF(src32), u_errorName(err)); | 163 (long)u32DestLen, (long)UPRV_LENGTHOF(src32), u_errorName(err)); |
| 166 return; | 164 return; |
| 167 } | 165 } |
| 168 /*for(i=0; i< u32DestLen; i++){ | 166 /*for(i=0; i< u32DestLen; i++){ |
| 169 printf("0x%08X, ",uTarget[i]); | 167 printf("0x%08X, ",uTarget[i]); |
| 170 if(i%10==0){ | 168 if(i%10==0){ |
| 171 printf("\n"); | 169 printf("\n"); |
| 172 } | 170 } |
| 173 }*/ | 171 }*/ |
| 174 for(i=0; i< LENGTHOF(src32); i++){ | 172 for(i=0; i< UPRV_LENGTHOF(src32); i++){ |
| 175 if(u32Target[i] != src32[i]){ | 173 if(u32Target[i] != src32[i]){ |
| 176 log_verbose("u_strToUTF32(with length) failed expected: %04X got: %0
4X at index: %i \n", src32[i], u32Target[i],i); | 174 log_verbose("u_strToUTF32(with length) failed expected: %04X got: %0
4X at index: %i \n", src32[i], u32Target[i],i); |
| 177 } | 175 } |
| 178 } | 176 } |
| 179 if(u32Target[i] != 0){ | 177 if(u32Target[i] != 0){ |
| 180 log_verbose("u_strToUTF32(with length) failed expected: %04X got: %04X a
t index: %i \n", 0, u32Target[i],i); | 178 log_verbose("u_strToUTF32(with length) failed expected: %04X got: %04X a
t index: %i \n", 0, u32Target[i],i); |
| 181 } | 179 } |
| 182 | 180 |
| 183 /* now NUL-terminated */ | 181 /* now NUL-terminated */ |
| 184 u32DestLen = -2; | 182 u32DestLen = -2; |
| 185 u_strToUTF32(NULL,0, &u32DestLen, src16, -1,&err); | 183 u_strToUTF32(NULL,0, &u32DestLen, src16, -1,&err); |
| 186 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != LENGTHOF(src32)-1) { | 184 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != UPRV_LENGTHOF(src32)-1) { |
| 187 log_err("u_strToUTF32(preflight with NUL-termination): " | 185 log_err("u_strToUTF32(preflight with NUL-termination): " |
| 188 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", | 186 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", |
| 189 (long)u32DestLen, (long)LENGTHOF(src32)-1, u_errorName(err)); | 187 (long)u32DestLen, (long)UPRV_LENGTHOF(src32)-1, u_errorName(err)
); |
| 190 return; | 188 return; |
| 191 } | 189 } |
| 192 err = U_ZERO_ERROR; | 190 err = U_ZERO_ERROR; |
| 193 u32DestLen = -2; | 191 u32DestLen = -2; |
| 194 u_strToUTF32(u32Target, LENGTHOF(src32), &u32DestLen, src16, -1,&err); | 192 u_strToUTF32(u32Target, UPRV_LENGTHOF(src32), &u32DestLen, src16, -1,&err); |
| 195 if(err != U_ZERO_ERROR || u32DestLen != LENGTHOF(src32)-1) { | 193 if(err != U_ZERO_ERROR || u32DestLen != UPRV_LENGTHOF(src32)-1) { |
| 196 log_err("u_strToUTF32(with NUL-termination): " | 194 log_err("u_strToUTF32(with NUL-termination): " |
| 197 "length %ld != %ld and %s != U_ZERO_ERROR\n", | 195 "length %ld != %ld and %s != U_ZERO_ERROR\n", |
| 198 (long)u32DestLen, (long)LENGTHOF(src32)-1, u_errorName(err)); | 196 (long)u32DestLen, (long)UPRV_LENGTHOF(src32)-1, u_errorName(err)
); |
| 199 return; | 197 return; |
| 200 } | 198 } |
| 201 | 199 |
| 202 for(i=0; i< LENGTHOF(src32); i++){ | 200 for(i=0; i< UPRV_LENGTHOF(src32); i++){ |
| 203 if(u32Target[i] != src32[i]){ | 201 if(u32Target[i] != src32[i]){ |
| 204 log_verbose("u_strToUTF32(NUL-termination) failed expected: %04X got
: %04X \n", src32[i], u32Target[i]); | 202 log_verbose("u_strToUTF32(NUL-termination) failed expected: %04X got
: %04X \n", src32[i], u32Target[i]); |
| 205 } | 203 } |
| 206 } | 204 } |
| 207 } | 205 } |
| 208 | 206 |
| 209 /* test unpaired surrogates */ | 207 /* test unpaired surrogates */ |
| 210 static void Test_strToUTF32_surrogates() { | 208 static void Test_strToUTF32_surrogates() { |
| 211 UErrorCode err = U_ZERO_ERROR; | 209 UErrorCode err = U_ZERO_ERROR; |
| 212 UChar32 u32Target[400]; | 210 UChar32 u32Target[400]; |
| 213 int32_t len16, u32DestLen; | 211 int32_t len16, u32DestLen; |
| 214 int32_t numSubstitutions; | 212 int32_t numSubstitutions; |
| 215 int i; | 213 int i; |
| 216 | 214 |
| 217 static const UChar surr16[] = { 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0x
dc00, 0x7a, 0 }; | 215 static const UChar surr16[] = { 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0x
dc00, 0x7a, 0 }; |
| 218 static const UChar32 expected[] = { 0x5a, 0x50000, 0x7a, 0 }; | 216 static const UChar32 expected[] = { 0x5a, 0x50000, 0x7a, 0 }; |
| 219 static const UChar32 expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0x5a, 0
x50000, 0x7a, 0 }; | 217 static const UChar32 expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0x5a, 0
x50000, 0x7a, 0 }; |
| 220 static const UChar32 expected_12345[] = { 0x41, 0x12345, 0x61, 0x12345, 0x5a
, 0x50000, 0x7a, 0 }; | 218 static const UChar32 expected_12345[] = { 0x41, 0x12345, 0x61, 0x12345, 0x5a
, 0x50000, 0x7a, 0 }; |
| 221 len16 = LENGTHOF(surr16); | 219 len16 = UPRV_LENGTHOF(surr16); |
| 222 for(i = 0; i < 4; ++i) { | 220 for(i = 0; i < 4; ++i) { |
| 223 err = U_ZERO_ERROR; | 221 err = U_ZERO_ERROR; |
| 224 u_strToUTF32(u32Target, 0, &u32DestLen, surr16+i, len16-i, &err); | 222 u_strToUTF32(u32Target, 0, &u32DestLen, surr16+i, len16-i, &err); |
| 225 if(err != U_INVALID_CHAR_FOUND) { | 223 if(err != U_INVALID_CHAR_FOUND) { |
| 226 log_err("u_strToUTF32(preflight surr16+%ld) sets %s != U_INVALID_CHA
R_FOUND\n", | 224 log_err("u_strToUTF32(preflight surr16+%ld) sets %s != U_INVALID_CHA
R_FOUND\n", |
| 227 (long)i, u_errorName(err)); | 225 (long)i, u_errorName(err)); |
| 228 return; | 226 return; |
| 229 } | 227 } |
| 230 | 228 |
| 231 err = U_ZERO_ERROR; | 229 err = U_ZERO_ERROR; |
| 232 u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+i, len1
6-i, &err); | 230 u_strToUTF32(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16+i,
len16-i, &err); |
| 233 if(err != U_INVALID_CHAR_FOUND) { | 231 if(err != U_INVALID_CHAR_FOUND) { |
| 234 log_err("u_strToUTF32(surr16+%ld) sets %s != U_INVALID_CHAR_FOUND\n"
, | 232 log_err("u_strToUTF32(surr16+%ld) sets %s != U_INVALID_CHAR_FOUND\n"
, |
| 235 (long)i, u_errorName(err)); | 233 (long)i, u_errorName(err)); |
| 236 return; | 234 return; |
| 237 } | 235 } |
| 238 | 236 |
| 239 err = U_ZERO_ERROR; | 237 err = U_ZERO_ERROR; |
| 240 u_strToUTF32(NULL, 0, &u32DestLen, surr16+i, -1, &err); | 238 u_strToUTF32(NULL, 0, &u32DestLen, surr16+i, -1, &err); |
| 241 if(err != U_INVALID_CHAR_FOUND) { | 239 if(err != U_INVALID_CHAR_FOUND) { |
| 242 log_err("u_strToUTF32(preflight surr16+%ld/NUL) sets %s != U_INVALID
_CHAR_FOUND\n", | 240 log_err("u_strToUTF32(preflight surr16+%ld/NUL) sets %s != U_INVALID
_CHAR_FOUND\n", |
| 243 (long)i, u_errorName(err)); | 241 (long)i, u_errorName(err)); |
| 244 return; | 242 return; |
| 245 } | 243 } |
| 246 | 244 |
| 247 err = U_ZERO_ERROR; | 245 err = U_ZERO_ERROR; |
| 248 u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+i, -1,
&err); | 246 u_strToUTF32(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16+i,
-1, &err); |
| 249 if(err != U_INVALID_CHAR_FOUND) { | 247 if(err != U_INVALID_CHAR_FOUND) { |
| 250 log_err("u_strToUTF32(surr16+%ld/NUL) sets %s != U_INVALID_CHAR_FOUN
D\n", | 248 log_err("u_strToUTF32(surr16+%ld/NUL) sets %s != U_INVALID_CHAR_FOUN
D\n", |
| 251 (long)i, u_errorName(err)); | 249 (long)i, u_errorName(err)); |
| 252 return; | 250 return; |
| 253 } | 251 } |
| 254 } | 252 } |
| 255 | 253 |
| 256 err = U_ZERO_ERROR; | 254 err = U_ZERO_ERROR; |
| 257 u_strToUTF32(u32Target, 0, &u32DestLen, surr16+4, len16-4-1, &err); | 255 u_strToUTF32(u32Target, 0, &u32DestLen, surr16+4, len16-4-1, &err); |
| 258 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { | 256 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { |
| 259 log_err("u_strToUTF32(preflight surr16+4) sets %s != U_BUFFER_OVERFLOW_E
RROR or an unexpected length\n", | 257 log_err("u_strToUTF32(preflight surr16+4) sets %s != U_BUFFER_OVERFLOW_E
RROR or an unexpected length\n", |
| 260 u_errorName(err)); | 258 u_errorName(err)); |
| 261 return; | 259 return; |
| 262 } | 260 } |
| 263 | 261 |
| 264 err = U_ZERO_ERROR; | 262 err = U_ZERO_ERROR; |
| 265 u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+4, len16-4-
1, &err); | 263 u_strToUTF32(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16+4, len
16-4-1, &err); |
| 266 if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected
, 4*4)) { | 264 if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected
, 4*4)) { |
| 267 log_err("u_strToUTF32(surr16+4) sets %s != U_ZERO_ERROR or does not prod
uce the expected string\n", | 265 log_err("u_strToUTF32(surr16+4) sets %s != U_ZERO_ERROR or does not prod
uce the expected string\n", |
| 268 u_errorName(err)); | 266 u_errorName(err)); |
| 269 return; | 267 return; |
| 270 } | 268 } |
| 271 | 269 |
| 272 err = U_ZERO_ERROR; | 270 err = U_ZERO_ERROR; |
| 273 u_strToUTF32(NULL, 0, &u32DestLen, surr16+4, -1, &err); | 271 u_strToUTF32(NULL, 0, &u32DestLen, surr16+4, -1, &err); |
| 274 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { | 272 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { |
| 275 log_err("u_strToUTF32(preflight surr16+4/NUL) sets %s != U_BUFFER_OVERFL
OW_ERROR or an unexpected length\n", | 273 log_err("u_strToUTF32(preflight surr16+4/NUL) sets %s != U_BUFFER_OVERFL
OW_ERROR or an unexpected length\n", |
| 276 u_errorName(err)); | 274 u_errorName(err)); |
| 277 return; | 275 return; |
| 278 } | 276 } |
| 279 | 277 |
| 280 err = U_ZERO_ERROR; | 278 err = U_ZERO_ERROR; |
| 281 u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+4, -1, &err
); | 279 u_strToUTF32(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16+4, -1,
&err); |
| 282 if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected
, 4*4)) { | 280 if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected
, 4*4)) { |
| 283 log_err("u_strToUTF32(surr16+4/NUL) sets %s != U_ZERO_ERROR or does not
produce the expected string\n", | 281 log_err("u_strToUTF32(surr16+4/NUL) sets %s != U_ZERO_ERROR or does not
produce the expected string\n", |
| 284 u_errorName(err)); | 282 u_errorName(err)); |
| 285 return; | 283 return; |
| 286 } | 284 } |
| 287 | 285 |
| 288 /* with substitution character */ | 286 /* with substitution character */ |
| 289 numSubstitutions = -1; | 287 numSubstitutions = -1; |
| 290 err = U_ZERO_ERROR; | 288 err = U_ZERO_ERROR; |
| 291 u_strToUTF32WithSub(u32Target, 0, &u32DestLen, surr16, len16-1, 0xfffd, &num
Substitutions, &err); | 289 u_strToUTF32WithSub(u32Target, 0, &u32DestLen, surr16, len16-1, 0xfffd, &num
Substitutions, &err); |
| 292 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions !=
2) { | 290 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions !=
2) { |
| 293 log_err("u_strToUTF32WithSub(preflight surr16) sets %s != U_BUFFER_OVERF
LOW_ERROR or an unexpected length\n", | 291 log_err("u_strToUTF32WithSub(preflight surr16) sets %s != U_BUFFER_OVERF
LOW_ERROR or an unexpected length\n", |
| 294 u_errorName(err)); | 292 u_errorName(err)); |
| 295 return; | 293 return; |
| 296 } | 294 } |
| 297 | 295 |
| 298 err = U_ZERO_ERROR; | 296 err = U_ZERO_ERROR; |
| 299 u_strToUTF32WithSub(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16, len
16-1, 0xfffd, &numSubstitutions, &err); | 297 u_strToUTF32WithSub(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16
, len16-1, 0xfffd, &numSubstitutions, &err); |
| 300 if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_m
emcmp(u32Target, expected_FFFD, 8*4)) { | 298 if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_m
emcmp(u32Target, expected_FFFD, 8*4)) { |
| 301 log_err("u_strToUTF32WithSub(surr16) sets %s != U_ZERO_ERROR or does not
produce the expected string\n", | 299 log_err("u_strToUTF32WithSub(surr16) sets %s != U_ZERO_ERROR or does not
produce the expected string\n", |
| 302 u_errorName(err)); | 300 u_errorName(err)); |
| 303 return; | 301 return; |
| 304 } | 302 } |
| 305 | 303 |
| 306 err = U_ZERO_ERROR; | 304 err = U_ZERO_ERROR; |
| 307 u_strToUTF32WithSub(NULL, 0, &u32DestLen, surr16, -1, 0x12345, &numSubstitut
ions, &err); | 305 u_strToUTF32WithSub(NULL, 0, &u32DestLen, surr16, -1, 0x12345, &numSubstitut
ions, &err); |
| 308 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions !=
2) { | 306 if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions !=
2) { |
| 309 log_err("u_strToUTF32WithSub(preflight surr16/NUL) sets %s != U_BUFFER_O
VERFLOW_ERROR or an unexpected length\n", | 307 log_err("u_strToUTF32WithSub(preflight surr16/NUL) sets %s != U_BUFFER_O
VERFLOW_ERROR or an unexpected length\n", |
| 310 u_errorName(err)); | 308 u_errorName(err)); |
| 311 return; | 309 return; |
| 312 } | 310 } |
| 313 | 311 |
| 314 err = U_ZERO_ERROR; | 312 err = U_ZERO_ERROR; |
| 315 u_strToUTF32WithSub(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16, -1,
0x12345, &numSubstitutions, &err); | 313 u_strToUTF32WithSub(u32Target, UPRV_LENGTHOF(u32Target), &u32DestLen, surr16
, -1, 0x12345, &numSubstitutions, &err); |
| 316 if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_m
emcmp(u32Target, expected_12345, 8*4)) { | 314 if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_m
emcmp(u32Target, expected_12345, 8*4)) { |
| 317 log_err("u_strToUTF32WithSub(surr16/NUL) sets %s != U_ZERO_ERROR or does
not produce the expected string\n", | 315 log_err("u_strToUTF32WithSub(surr16/NUL) sets %s != U_ZERO_ERROR or does
not produce the expected string\n", |
| 318 u_errorName(err)); | 316 u_errorName(err)); |
| 319 return; | 317 return; |
| 320 } | 318 } |
| 321 } | 319 } |
| 322 | 320 |
| 323 static void Test_strFromUTF32(void){ | 321 static void Test_strFromUTF32(void){ |
| 324 UErrorCode err = U_ZERO_ERROR; | 322 UErrorCode err = U_ZERO_ERROR; |
| 325 UChar uTarget[400]; | 323 UChar uTarget[400]; |
| 326 int32_t uDestLen; | 324 int32_t uDestLen; |
| 327 int i= 0; | 325 int i= 0; |
| 328 | 326 |
| 329 /* first with length */ | 327 /* first with length */ |
| 330 uDestLen = -2; | 328 uDestLen = -2; |
| 331 u_strFromUTF32(uTarget,0,&uDestLen,src32,LENGTHOF(src32),&err); | 329 u_strFromUTF32(uTarget,0,&uDestLen,src32,UPRV_LENGTHOF(src32),&err); |
| 332 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != LENGTHOF(src16)) { | 330 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != UPRV_LENGTHOF(src16)) { |
| 333 log_err("u_strFromUTF32(preflight with length): " | 331 log_err("u_strFromUTF32(preflight with length): " |
| 334 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", | 332 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", |
| 335 (long)uDestLen, (long)LENGTHOF(src16), u_errorName(err)); | 333 (long)uDestLen, (long)UPRV_LENGTHOF(src16), u_errorName(err)); |
| 336 return; | 334 return; |
| 337 } | 335 } |
| 338 err = U_ZERO_ERROR; | 336 err = U_ZERO_ERROR; |
| 339 uDestLen = -2; | 337 uDestLen = -2; |
| 340 u_strFromUTF32(uTarget, LENGTHOF(src16)+1,&uDestLen,src32,LENGTHOF(src32),&e
rr); | 338 u_strFromUTF32(uTarget, UPRV_LENGTHOF(src16)+1,&uDestLen,src32,UPRV_LENGTHOF
(src32),&err); |
| 341 if(err != U_ZERO_ERROR || uDestLen != LENGTHOF(src16)) { | 339 if(err != U_ZERO_ERROR || uDestLen != UPRV_LENGTHOF(src16)) { |
| 342 log_err("u_strFromUTF32(with length): " | 340 log_err("u_strFromUTF32(with length): " |
| 343 "length %ld != %ld and %s != U_ZERO_ERROR\n", | 341 "length %ld != %ld and %s != U_ZERO_ERROR\n", |
| 344 (long)uDestLen, (long)LENGTHOF(src16), u_errorName(err)); | 342 (long)uDestLen, (long)UPRV_LENGTHOF(src16), u_errorName(err)); |
| 345 return; | 343 return; |
| 346 } | 344 } |
| 347 /*for(i=0; i< uDestLen; i++){ | 345 /*for(i=0; i< uDestLen; i++){ |
| 348 printf("0x%04X, ",uTarget[i]); | 346 printf("0x%04X, ",uTarget[i]); |
| 349 if(i%10==0){ | 347 if(i%10==0){ |
| 350 printf("\n"); | 348 printf("\n"); |
| 351 } | 349 } |
| 352 }*/ | 350 }*/ |
| 353 | 351 |
| 354 for(i=0; i< uDestLen; i++){ | 352 for(i=0; i< uDestLen; i++){ |
| 355 if(uTarget[i] != src16[i]){ | 353 if(uTarget[i] != src16[i]){ |
| 356 log_verbose("u_strFromUTF32(with length) failed expected: %04X got:
%04X at index: %i \n", src16[i] ,uTarget[i],i); | 354 log_verbose("u_strFromUTF32(with length) failed expected: %04X got:
%04X at index: %i \n", src16[i] ,uTarget[i],i); |
| 357 } | 355 } |
| 358 } | 356 } |
| 359 if(uTarget[i] != 0){ | 357 if(uTarget[i] != 0){ |
| 360 log_verbose("u_strFromUTF32(with length) failed expected: %04X got: %04X
at index: %i \n", 0,uTarget[i],i); | 358 log_verbose("u_strFromUTF32(with length) failed expected: %04X got: %04X
at index: %i \n", 0,uTarget[i],i); |
| 361 } | 359 } |
| 362 | 360 |
| 363 /* now NUL-terminated */ | 361 /* now NUL-terminated */ |
| 364 uDestLen = -2; | 362 uDestLen = -2; |
| 365 u_strFromUTF32(NULL,0,&uDestLen,src32,-1,&err); | 363 u_strFromUTF32(NULL,0,&uDestLen,src32,-1,&err); |
| 366 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != LENGTHOF(src16)-1) { | 364 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != UPRV_LENGTHOF(src16)-1) { |
| 367 log_err("u_strFromUTF32(preflight with NUL-termination): " | 365 log_err("u_strFromUTF32(preflight with NUL-termination): " |
| 368 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", | 366 "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", |
| 369 (long)uDestLen, (long)LENGTHOF(src16)-1, u_errorName(err)); | 367 (long)uDestLen, (long)UPRV_LENGTHOF(src16)-1, u_errorName(err)); |
| 370 return; | 368 return; |
| 371 } | 369 } |
| 372 err = U_ZERO_ERROR; | 370 err = U_ZERO_ERROR; |
| 373 uDestLen = -2; | 371 uDestLen = -2; |
| 374 u_strFromUTF32(uTarget, LENGTHOF(src16),&uDestLen,src32,-1,&err); | 372 u_strFromUTF32(uTarget, UPRV_LENGTHOF(src16),&uDestLen,src32,-1,&err); |
| 375 if(err != U_ZERO_ERROR || uDestLen != LENGTHOF(src16)-1) { | 373 if(err != U_ZERO_ERROR || uDestLen != UPRV_LENGTHOF(src16)-1) { |
| 376 log_err("u_strFromUTF32(with NUL-termination): " | 374 log_err("u_strFromUTF32(with NUL-termination): " |
| 377 "length %ld != %ld and %s != U_ZERO_ERROR\n", | 375 "length %ld != %ld and %s != U_ZERO_ERROR\n", |
| 378 (long)uDestLen, (long)LENGTHOF(src16)-1, u_errorName(err)); | 376 (long)uDestLen, (long)UPRV_LENGTHOF(src16)-1, u_errorName(err)); |
| 379 return; | 377 return; |
| 380 } | 378 } |
| 381 | 379 |
| 382 for(i=0; i< uDestLen; i++){ | 380 for(i=0; i< uDestLen; i++){ |
| 383 if(uTarget[i] != src16[i]){ | 381 if(uTarget[i] != src16[i]){ |
| 384 log_verbose("u_strFromUTF32(with NUL-termination) failed expected: %
04X got: %04X \n", src16[i] ,uTarget[i]); | 382 log_verbose("u_strFromUTF32(with NUL-termination) failed expected: %
04X got: %04X \n", src16[i] ,uTarget[i]); |
| 385 } | 383 } |
| 386 } | 384 } |
| 387 } | 385 } |
| 388 | 386 |
| 389 /* test surrogate code points */ | 387 /* test surrogate code points */ |
| 390 static void Test_strFromUTF32_surrogates() { | 388 static void Test_strFromUTF32_surrogates() { |
| 391 UErrorCode err = U_ZERO_ERROR; | 389 UErrorCode err = U_ZERO_ERROR; |
| 392 UChar uTarget[400]; | 390 UChar uTarget[400]; |
| 393 int32_t len32, uDestLen; | 391 int32_t len32, uDestLen; |
| 394 int32_t numSubstitutions; | 392 int32_t numSubstitutions; |
| 395 int i; | 393 int i; |
| 396 | 394 |
| 397 static const UChar32 surr32[] = { 0x41, 0xd900, 0x61, 0xdc00, -1, 0x110000,
0x5a, 0x50000, 0x7a, 0 }; | 395 static const UChar32 surr32[] = { 0x41, 0xd900, 0x61, 0xdc00, -1, 0x110000,
0x5a, 0x50000, 0x7a, 0 }; |
| 398 static const UChar expected[] = { 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; | 396 static const UChar expected[] = { 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; |
| 399 static const UChar expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0
xfffd, 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; | 397 static const UChar expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0
xfffd, 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; |
| 400 static const UChar expected_12345[] = { 0x41, 0xd808, 0xdf45, 0x61, 0xd808,
0xdf45, 0xd808, 0xdf45, 0xd808, 0xdf45, | 398 static const UChar expected_12345[] = { 0x41, 0xd808, 0xdf45, 0x61, 0xd808,
0xdf45, 0xd808, 0xdf45, 0xd808, 0xdf45, |
| 401 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; | 399 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; |
| 402 len32 = LENGTHOF(surr32); | 400 len32 = UPRV_LENGTHOF(surr32); |
| 403 for(i = 0; i < 6; ++i) { | 401 for(i = 0; i < 6; ++i) { |
| 404 err = U_ZERO_ERROR; | 402 err = U_ZERO_ERROR; |
| 405 u_strFromUTF32(uTarget, 0, &uDestLen, surr32+i, len32-i, &err); | 403 u_strFromUTF32(uTarget, 0, &uDestLen, surr32+i, len32-i, &err); |
| 406 if(err != U_INVALID_CHAR_FOUND) { | 404 if(err != U_INVALID_CHAR_FOUND) { |
| 407 log_err("u_strFromUTF32(preflight surr32+%ld) sets %s != U_INVALID_C
HAR_FOUND\n", | 405 log_err("u_strFromUTF32(preflight surr32+%ld) sets %s != U_INVALID_C
HAR_FOUND\n", |
| 408 (long)i, u_errorName(err)); | 406 (long)i, u_errorName(err)); |
| 409 return; | 407 return; |
| 410 } | 408 } |
| 411 | 409 |
| 412 err = U_ZERO_ERROR; | 410 err = U_ZERO_ERROR; |
| 413 u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+i, len32-i,
&err); | 411 u_strFromUTF32(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32+i, len
32-i, &err); |
| 414 if(err != U_INVALID_CHAR_FOUND) { | 412 if(err != U_INVALID_CHAR_FOUND) { |
| 415 log_err("u_strFromUTF32(surr32+%ld) sets %s != U_INVALID_CHAR_FOUND\
n", | 413 log_err("u_strFromUTF32(surr32+%ld) sets %s != U_INVALID_CHAR_FOUND\
n", |
| 416 (long)i, u_errorName(err)); | 414 (long)i, u_errorName(err)); |
| 417 return; | 415 return; |
| 418 } | 416 } |
| 419 | 417 |
| 420 err = U_ZERO_ERROR; | 418 err = U_ZERO_ERROR; |
| 421 u_strFromUTF32(NULL, 0, &uDestLen, surr32+i, -1, &err); | 419 u_strFromUTF32(NULL, 0, &uDestLen, surr32+i, -1, &err); |
| 422 if(err != U_INVALID_CHAR_FOUND) { | 420 if(err != U_INVALID_CHAR_FOUND) { |
| 423 log_err("u_strFromUTF32(preflight surr32+%ld/NUL) sets %s != U_INVAL
ID_CHAR_FOUND\n", | 421 log_err("u_strFromUTF32(preflight surr32+%ld/NUL) sets %s != U_INVAL
ID_CHAR_FOUND\n", |
| 424 (long)i, u_errorName(err)); | 422 (long)i, u_errorName(err)); |
| 425 return; | 423 return; |
| 426 } | 424 } |
| 427 | 425 |
| 428 err = U_ZERO_ERROR; | 426 err = U_ZERO_ERROR; |
| 429 u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+i, -1, &err
); | 427 u_strFromUTF32(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32+i, -1,
&err); |
| 430 if(err != U_INVALID_CHAR_FOUND) { | 428 if(err != U_INVALID_CHAR_FOUND) { |
| 431 log_err("u_strFromUTF32(surr32+%ld/NUL) sets %s != U_INVALID_CHAR_FO
UND\n", | 429 log_err("u_strFromUTF32(surr32+%ld/NUL) sets %s != U_INVALID_CHAR_FO
UND\n", |
| 432 (long)i, u_errorName(err)); | 430 (long)i, u_errorName(err)); |
| 433 return; | 431 return; |
| 434 } | 432 } |
| 435 } | 433 } |
| 436 | 434 |
| 437 err = U_ZERO_ERROR; | 435 err = U_ZERO_ERROR; |
| 438 u_strFromUTF32(uTarget, 0, &uDestLen, surr32+6, len32-6-1, &err); | 436 u_strFromUTF32(uTarget, 0, &uDestLen, surr32+6, len32-6-1, &err); |
| 439 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { | 437 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { |
| 440 log_err("u_strFromUTF32(preflight surr32+6) sets %s != U_BUFFER_OVERFLOW
_ERROR or an unexpected length\n", | 438 log_err("u_strFromUTF32(preflight surr32+6) sets %s != U_BUFFER_OVERFLOW
_ERROR or an unexpected length\n", |
| 441 u_errorName(err)); | 439 u_errorName(err)); |
| 442 return; | 440 return; |
| 443 } | 441 } |
| 444 | 442 |
| 445 err = U_ZERO_ERROR; | 443 err = U_ZERO_ERROR; |
| 446 u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+6, len32-6-1, &
err); | 444 u_strFromUTF32(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32+6, len32-6
-1, &err); |
| 447 if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { | 445 if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { |
| 448 log_err("u_strFromUTF32(surr32+6) sets %s != U_ZERO_ERROR or does not pr
oduce the expected string\n", | 446 log_err("u_strFromUTF32(surr32+6) sets %s != U_ZERO_ERROR or does not pr
oduce the expected string\n", |
| 449 u_errorName(err)); | 447 u_errorName(err)); |
| 450 return; | 448 return; |
| 451 } | 449 } |
| 452 | 450 |
| 453 err = U_ZERO_ERROR; | 451 err = U_ZERO_ERROR; |
| 454 u_strFromUTF32(NULL, 0, &uDestLen, surr32+6, -1, &err); | 452 u_strFromUTF32(NULL, 0, &uDestLen, surr32+6, -1, &err); |
| 455 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { | 453 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { |
| 456 log_err("u_strFromUTF32(preflight surr32+6/NUL) sets %s != U_BUFFER_OVER
FLOW_ERROR or an unexpected length\n", | 454 log_err("u_strFromUTF32(preflight surr32+6/NUL) sets %s != U_BUFFER_OVER
FLOW_ERROR or an unexpected length\n", |
| 457 u_errorName(err)); | 455 u_errorName(err)); |
| 458 return; | 456 return; |
| 459 } | 457 } |
| 460 | 458 |
| 461 err = U_ZERO_ERROR; | 459 err = U_ZERO_ERROR; |
| 462 u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+6, -1, &err); | 460 u_strFromUTF32(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32+6, -1, &er
r); |
| 463 if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { | 461 if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { |
| 464 log_err("u_strFromUTF32(surr32+6/NUL) sets %s != U_ZERO_ERROR or does no
t produce the expected string\n", | 462 log_err("u_strFromUTF32(surr32+6/NUL) sets %s != U_ZERO_ERROR or does no
t produce the expected string\n", |
| 465 u_errorName(err)); | 463 u_errorName(err)); |
| 466 return; | 464 return; |
| 467 } | 465 } |
| 468 | 466 |
| 469 /* with substitution character */ | 467 /* with substitution character */ |
| 470 numSubstitutions = -1; | 468 numSubstitutions = -1; |
| 471 err = U_ZERO_ERROR; | 469 err = U_ZERO_ERROR; |
| 472 u_strFromUTF32WithSub(uTarget, 0, &uDestLen, surr32, len32-1, 0xfffd, &numSu
bstitutions, &err); | 470 u_strFromUTF32WithSub(uTarget, 0, &uDestLen, surr32, len32-1, 0xfffd, &numSu
bstitutions, &err); |
| 473 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 10 || numSubstitutions != 4
) { | 471 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 10 || numSubstitutions != 4
) { |
| 474 log_err("u_strFromUTF32WithSub(preflight surr32) sets %s != U_BUFFER_OVE
RFLOW_ERROR or an unexpected length\n", | 472 log_err("u_strFromUTF32WithSub(preflight surr32) sets %s != U_BUFFER_OVE
RFLOW_ERROR or an unexpected length\n", |
| 475 u_errorName(err)); | 473 u_errorName(err)); |
| 476 return; | 474 return; |
| 477 } | 475 } |
| 478 | 476 |
| 479 err = U_ZERO_ERROR; | 477 err = U_ZERO_ERROR; |
| 480 u_strFromUTF32WithSub(uTarget, LENGTHOF(uTarget), &uDestLen, surr32, len32-1
, 0xfffd, &numSubstitutions, &err); | 478 u_strFromUTF32WithSub(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32, le
n32-1, 0xfffd, &numSubstitutions, &err); |
| 481 if(err != U_ZERO_ERROR || uDestLen != 10 || numSubstitutions != 4 || u_memcm
p(uTarget, expected_FFFD, 11)) { | 479 if(err != U_ZERO_ERROR || uDestLen != 10 || numSubstitutions != 4 || u_memcm
p(uTarget, expected_FFFD, 11)) { |
| 482 log_err("u_strFromUTF32WithSub(surr32) sets %s != U_ZERO_ERROR or does n
ot produce the expected string\n", | 480 log_err("u_strFromUTF32WithSub(surr32) sets %s != U_ZERO_ERROR or does n
ot produce the expected string\n", |
| 483 u_errorName(err)); | 481 u_errorName(err)); |
| 484 return; | 482 return; |
| 485 } | 483 } |
| 486 | 484 |
| 487 err = U_ZERO_ERROR; | 485 err = U_ZERO_ERROR; |
| 488 u_strFromUTF32WithSub(NULL, 0, &uDestLen, surr32, -1, 0x12345, &numSubstitut
ions, &err); | 486 u_strFromUTF32WithSub(NULL, 0, &uDestLen, surr32, -1, 0x12345, &numSubstitut
ions, &err); |
| 489 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 14 || numSubstitutions != 4
) { | 487 if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 14 || numSubstitutions != 4
) { |
| 490 log_err("u_strFromUTF32WithSub(preflight surr32/NUL) sets %s != U_BUFFER
_OVERFLOW_ERROR or an unexpected length\n", | 488 log_err("u_strFromUTF32WithSub(preflight surr32/NUL) sets %s != U_BUFFER
_OVERFLOW_ERROR or an unexpected length\n", |
| 491 u_errorName(err)); | 489 u_errorName(err)); |
| 492 return; | 490 return; |
| 493 } | 491 } |
| 494 | 492 |
| 495 err = U_ZERO_ERROR; | 493 err = U_ZERO_ERROR; |
| 496 u_strFromUTF32WithSub(uTarget, LENGTHOF(uTarget), &uDestLen, surr32, -1, 0x1
2345, &numSubstitutions, &err); | 494 u_strFromUTF32WithSub(uTarget, UPRV_LENGTHOF(uTarget), &uDestLen, surr32, -1
, 0x12345, &numSubstitutions, &err); |
| 497 if(err != U_ZERO_ERROR || uDestLen != 14 || numSubstitutions != 4 || u_memcm
p(uTarget, expected_12345, 15)) { | 495 if(err != U_ZERO_ERROR || uDestLen != 14 || numSubstitutions != 4 || u_memcm
p(uTarget, expected_12345, 15)) { |
| 498 log_err("u_strFromUTF32WithSub(surr32/NUL) sets %s != U_ZERO_ERROR or do
es not produce the expected string\n", | 496 log_err("u_strFromUTF32WithSub(surr32/NUL) sets %s != U_ZERO_ERROR or do
es not produce the expected string\n", |
| 499 u_errorName(err)); | 497 u_errorName(err)); |
| 500 return; | 498 return; |
| 501 } | 499 } |
| 502 } | 500 } |
| 503 | 501 |
| 504 static void Test_UChar_UTF8_API(void){ | 502 static void Test_UChar_UTF8_API(void){ |
| 505 | 503 |
| 506 UErrorCode err = U_ZERO_ERROR; | 504 UErrorCode err = U_ZERO_ERROR; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 withTrail16Sub50005[]={ 0x1800, 0xd900, 0xdc05, 0x0061, 0 }; /* sub=
=U+50005 */ | 676 withTrail16Sub50005[]={ 0x1800, 0xd900, 0xdc05, 0x0061, 0 }; /* sub=
=U+50005 */ |
| 679 static const uint8_t | 677 static const uint8_t |
| 680 withLead8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xa2, 0x9a, 0x61 }, | 678 withLead8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xa2, 0x9a, 0x61 }, |
| 681 withTrail8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xb2, 0xba, 0x61, 0 }, | 679 withTrail8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xb2, 0xba, 0x61, 0 }, |
| 682 withTrail8Sub1A[]={ 0xe1, 0xa0, 0x80, 0x1a, 0x61, 0 }, /* sub==U+001
A */ | 680 withTrail8Sub1A[]={ 0xe1, 0xa0, 0x80, 0x1a, 0x61, 0 }, /* sub==U+001
A */ |
| 683 withTrail8SubFFFD[]={ 0xe1, 0xa0, 0x80, 0xef, 0xbf, 0xbd, 0x61, 0 };
/* sub==U+FFFD */ | 681 withTrail8SubFFFD[]={ 0xe1, 0xa0, 0x80, 0xef, 0xbf, 0xbd, 0x61, 0 };
/* sub==U+FFFD */ |
| 684 UChar out16[10]; | 682 UChar out16[10]; |
| 685 char out8[10]; | 683 char out8[10]; |
| 686 | 684 |
| 687 if( | 685 if( |
| 688 (err=U_ZERO_ERROR, u_strToUTF8(out8, LENGTHOF(out8), NULL, withLead1
6, LENGTHOF(withLead16), &err), err!=U_INVALID_CHAR_FOUND) || | 686 (err=U_ZERO_ERROR, u_strToUTF8(out8, UPRV_LENGTHOF(out8), NULL, with
Lead16, UPRV_LENGTHOF(withLead16), &err), err!=U_INVALID_CHAR_FOUND) || |
| 689 (err=U_ZERO_ERROR, u_strToUTF8(out8, LENGTHOF(out8), NULL, withTrail
16, -1, &err), err!=U_INVALID_CHAR_FOUND) || | 687 (err=U_ZERO_ERROR, u_strToUTF8(out8, UPRV_LENGTHOF(out8), NULL, with
Trail16, -1, &err), err!=U_INVALID_CHAR_FOUND) || |
| 690 (err=U_ZERO_ERROR, u_strFromUTF8(out16, LENGTHOF(out16), NULL, (cons
t char *)withLead8, LENGTHOF(withLead8), &err), err!=U_INVALID_CHAR_FOUND) || | 688 (err=U_ZERO_ERROR, u_strFromUTF8(out16, UPRV_LENGTHOF(out16), NULL,
(const char *)withLead8, UPRV_LENGTHOF(withLead8), &err), err!=U_INVALID_CHAR_FO
UND) || |
| 691 (err=U_ZERO_ERROR, u_strFromUTF8(out16, LENGTHOF(out16), NULL, (cons
t char *)withTrail8, -1, &err), err!=U_INVALID_CHAR_FOUND) | 689 (err=U_ZERO_ERROR, u_strFromUTF8(out16, UPRV_LENGTHOF(out16), NULL,
(const char *)withTrail8, -1, &err), err!=U_INVALID_CHAR_FOUND) |
| 692 ) { | 690 ) { |
| 693 log_err("error: u_strTo/FromUTF8(string with single surrogate) fails
to report error\n"); | 691 log_err("error: u_strTo/FromUTF8(string with single surrogate) fails
to report error\n"); |
| 694 } | 692 } |
| 695 | 693 |
| 696 /* test error handling with substitution characters */ | 694 /* test error handling with substitution characters */ |
| 697 | 695 |
| 698 /* from UTF-8 with length */ | 696 /* from UTF-8 with length */ |
| 699 err=U_ZERO_ERROR; | 697 err=U_ZERO_ERROR; |
| 700 numSubstitutions=-1; | 698 numSubstitutions=-1; |
| 701 out16[0]=0x55aa; | 699 out16[0]=0x55aa; |
| 702 uDestLen=0; | 700 uDestLen=0; |
| 703 u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, | 701 u_strFromUTF8WithSub(out16, UPRV_LENGTHOF(out16), &uDestLen, |
| 704 (const char *)withTrail8, uprv_strlen((const char *
)withTrail8), | 702 (const char *)withTrail8, uprv_strlen((const char *
)withTrail8), |
| 705 0x50005, &numSubstitutions, | 703 0x50005, &numSubstitutions, |
| 706 &err); | 704 &err); |
| 707 if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16Sub50005) || | 705 if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16Sub50005) || |
| 708 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen+1)
|| | 706 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen+1)
|| |
| 709 numSubstitutions!=1) { | 707 numSubstitutions!=1) { |
| 710 log_err("error: u_strFromUTF8WithSub(length) failed\n"); | 708 log_err("error: u_strFromUTF8WithSub(length) failed\n"); |
| 711 } | 709 } |
| 712 | 710 |
| 713 /* from UTF-8 with NUL termination */ | 711 /* from UTF-8 with NUL termination */ |
| 714 err=U_ZERO_ERROR; | 712 err=U_ZERO_ERROR; |
| 715 numSubstitutions=-1; | 713 numSubstitutions=-1; |
| 716 out16[0]=0x55aa; | 714 out16[0]=0x55aa; |
| 717 uDestLen=0; | 715 uDestLen=0; |
| 718 u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, | 716 u_strFromUTF8WithSub(out16, UPRV_LENGTHOF(out16), &uDestLen, |
| 719 (const char *)withTrail8, -1, | 717 (const char *)withTrail8, -1, |
| 720 0xfffd, &numSubstitutions, | 718 0xfffd, &numSubstitutions, |
| 721 &err); | 719 &err); |
| 722 if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16SubFFFD) || | 720 if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16SubFFFD) || |
| 723 0!=u_memcmp(withTrail16SubFFFD, out16, uDestLen+1)
|| | 721 0!=u_memcmp(withTrail16SubFFFD, out16, uDestLen+1)
|| |
| 724 numSubstitutions!=1) { | 722 numSubstitutions!=1) { |
| 725 log_err("error: u_strFromUTF8WithSub(NUL termination) failed\n"); | 723 log_err("error: u_strFromUTF8WithSub(NUL termination) failed\n"); |
| 726 } | 724 } |
| 727 | 725 |
| 728 /* preflight from UTF-8 with NUL termination */ | 726 /* preflight from UTF-8 with NUL termination */ |
| 729 err=U_ZERO_ERROR; | 727 err=U_ZERO_ERROR; |
| 730 numSubstitutions=-1; | 728 numSubstitutions=-1; |
| 731 out16[0]=0x55aa; | 729 out16[0]=0x55aa; |
| 732 uDestLen=0; | 730 uDestLen=0; |
| 733 u_strFromUTF8WithSub(out16, 1, &uDestLen, | 731 u_strFromUTF8WithSub(out16, 1, &uDestLen, |
| 734 (const char *)withTrail8, -1, | 732 (const char *)withTrail8, -1, |
| 735 0x50005, &numSubstitutions, | 733 0x50005, &numSubstitutions, |
| 736 &err); | 734 &err); |
| 737 if(err!=U_BUFFER_OVERFLOW_ERROR || uDestLen!=u_strlen(withTrail16Sub5000
5) || numSubstitutions!=1) { | 735 if(err!=U_BUFFER_OVERFLOW_ERROR || uDestLen!=u_strlen(withTrail16Sub5000
5) || numSubstitutions!=1) { |
| 738 log_err("error: u_strFromUTF8WithSub(preflight/NUL termination) fail
ed\n"); | 736 log_err("error: u_strFromUTF8WithSub(preflight/NUL termination) fail
ed\n"); |
| 739 } | 737 } |
| 740 | 738 |
| 741 /* to UTF-8 with length */ | 739 /* to UTF-8 with length */ |
| 742 err=U_ZERO_ERROR; | 740 err=U_ZERO_ERROR; |
| 743 numSubstitutions=-1; | 741 numSubstitutions=-1; |
| 744 out8[0]=(char)0xf5; | 742 out8[0]=(char)0xf5; |
| 745 u8DestLen=0; | 743 u8DestLen=0; |
| 746 u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, | 744 u_strToUTF8WithSub(out8, UPRV_LENGTHOF(out8), &u8DestLen, |
| 747 withTrail16, u_strlen(withTrail16), | 745 withTrail16, u_strlen(withTrail16), |
| 748 0xfffd, &numSubstitutions, | 746 0xfffd, &numSubstitutions, |
| 749 &err); | 747 &err); |
| 750 if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8SubF
FFD) || | 748 if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8SubF
FFD) || |
| 751 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen+1) || | 749 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen+1) || |
| 752 numSubstitutions!=1) { | 750 numSubstitutions!=1) { |
| 753 log_err("error: u_strToUTF8WithSub(length) failed\n"); | 751 log_err("error: u_strToUTF8WithSub(length) failed\n"); |
| 754 } | 752 } |
| 755 | 753 |
| 756 /* to UTF-8 with NUL termination */ | 754 /* to UTF-8 with NUL termination */ |
| 757 err=U_ZERO_ERROR; | 755 err=U_ZERO_ERROR; |
| 758 numSubstitutions=-1; | 756 numSubstitutions=-1; |
| 759 out8[0]=(char)0xf5; | 757 out8[0]=(char)0xf5; |
| 760 u8DestLen=0; | 758 u8DestLen=0; |
| 761 u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, | 759 u_strToUTF8WithSub(out8, UPRV_LENGTHOF(out8), &u8DestLen, |
| 762 withTrail16, -1, | 760 withTrail16, -1, |
| 763 0x1a, &numSubstitutions, | 761 0x1a, &numSubstitutions, |
| 764 &err); | 762 &err); |
| 765 if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8Sub1
A) || | 763 if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8Sub1
A) || |
| 766 0!=uprv_memcmp((const char *)withTrail8Sub1A, out8,
u8DestLen+1) || | 764 0!=uprv_memcmp((const char *)withTrail8Sub1A, out8,
u8DestLen+1) || |
| 767 numSubstitutions!=1) { | 765 numSubstitutions!=1) { |
| 768 log_err("error: u_strToUTF8WithSub(NUL termination) failed\n"); | 766 log_err("error: u_strToUTF8WithSub(NUL termination) failed\n"); |
| 769 } | 767 } |
| 770 | 768 |
| 771 /* preflight to UTF-8 with NUL termination */ | 769 /* preflight to UTF-8 with NUL termination */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 782 log_err("error: u_strToUTF8WithSub(preflight/NUL termination) failed
\n"); | 780 log_err("error: u_strToUTF8WithSub(preflight/NUL termination) failed
\n"); |
| 783 } | 781 } |
| 784 | 782 |
| 785 /* test that numSubstitutions==0 if there are no substitutions */ | 783 /* test that numSubstitutions==0 if there are no substitutions */ |
| 786 | 784 |
| 787 /* from UTF-8 with length (just first 3 bytes which are valid) */ | 785 /* from UTF-8 with length (just first 3 bytes which are valid) */ |
| 788 err=U_ZERO_ERROR; | 786 err=U_ZERO_ERROR; |
| 789 numSubstitutions=-1; | 787 numSubstitutions=-1; |
| 790 out16[0]=0x55aa; | 788 out16[0]=0x55aa; |
| 791 uDestLen=0; | 789 uDestLen=0; |
| 792 u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, | 790 u_strFromUTF8WithSub(out16, UPRV_LENGTHOF(out16), &uDestLen, |
| 793 (const char *)withTrail8, 3, | 791 (const char *)withTrail8, 3, |
| 794 0x50005, &numSubstitutions, | 792 0x50005, &numSubstitutions, |
| 795 &err); | 793 &err); |
| 796 if(U_FAILURE(err) || uDestLen!=1 || | 794 if(U_FAILURE(err) || uDestLen!=1 || |
| 797 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) |
| | 795 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) |
| |
| 798 numSubstitutions!=0) { | 796 numSubstitutions!=0) { |
| 799 log_err("error: u_strFromUTF8WithSub(no subs) failed\n"); | 797 log_err("error: u_strFromUTF8WithSub(no subs) failed\n"); |
| 800 } | 798 } |
| 801 | 799 |
| 802 /* to UTF-8 with length (just first UChar which is valid) */ | 800 /* to UTF-8 with length (just first UChar which is valid) */ |
| 803 err=U_ZERO_ERROR; | 801 err=U_ZERO_ERROR; |
| 804 numSubstitutions=-1; | 802 numSubstitutions=-1; |
| 805 out8[0]=(char)0xf5; | 803 out8[0]=(char)0xf5; |
| 806 u8DestLen=0; | 804 u8DestLen=0; |
| 807 u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, | 805 u_strToUTF8WithSub(out8, UPRV_LENGTHOF(out8), &u8DestLen, |
| 808 withTrail16, 1, | 806 withTrail16, 1, |
| 809 0xfffd, &numSubstitutions, | 807 0xfffd, &numSubstitutions, |
| 810 &err); | 808 &err); |
| 811 if(U_FAILURE(err) || u8DestLen!=3 || | 809 if(U_FAILURE(err) || u8DestLen!=3 || |
| 812 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen) || | 810 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen) || |
| 813 numSubstitutions!=0) { | 811 numSubstitutions!=0) { |
| 814 log_err("error: u_strToUTF8WithSub(no subs) failed\n"); | 812 log_err("error: u_strToUTF8WithSub(no subs) failed\n"); |
| 815 } | 813 } |
| 816 | 814 |
| 817 /* test that numSubstitutions==0 if subchar==U_SENTINEL (no subchar) */ | 815 /* test that numSubstitutions==0 if subchar==U_SENTINEL (no subchar) */ |
| 818 | 816 |
| 819 /* from UTF-8 with length (just first 3 bytes which are valid) */ | 817 /* from UTF-8 with length (just first 3 bytes which are valid) */ |
| 820 err=U_ZERO_ERROR; | 818 err=U_ZERO_ERROR; |
| 821 numSubstitutions=-1; | 819 numSubstitutions=-1; |
| 822 out16[0]=0x55aa; | 820 out16[0]=0x55aa; |
| 823 uDestLen=0; | 821 uDestLen=0; |
| 824 u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, | 822 u_strFromUTF8WithSub(out16, UPRV_LENGTHOF(out16), &uDestLen, |
| 825 (const char *)withTrail8, 3, | 823 (const char *)withTrail8, 3, |
| 826 U_SENTINEL, &numSubstitutions, | 824 U_SENTINEL, &numSubstitutions, |
| 827 &err); | 825 &err); |
| 828 if(U_FAILURE(err) || uDestLen!=1 || | 826 if(U_FAILURE(err) || uDestLen!=1 || |
| 829 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) |
| | 827 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) |
| |
| 830 numSubstitutions!=0) { | 828 numSubstitutions!=0) { |
| 831 log_err("error: u_strFromUTF8WithSub(no subchar) failed\n"); | 829 log_err("error: u_strFromUTF8WithSub(no subchar) failed\n"); |
| 832 } | 830 } |
| 833 | 831 |
| 834 /* to UTF-8 with length (just first UChar which is valid) */ | 832 /* to UTF-8 with length (just first UChar which is valid) */ |
| 835 err=U_ZERO_ERROR; | 833 err=U_ZERO_ERROR; |
| 836 numSubstitutions=-1; | 834 numSubstitutions=-1; |
| 837 out8[0]=(char)0xf5; | 835 out8[0]=(char)0xf5; |
| 838 u8DestLen=0; | 836 u8DestLen=0; |
| 839 u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, | 837 u_strToUTF8WithSub(out8, UPRV_LENGTHOF(out8), &u8DestLen, |
| 840 withTrail16, 1, | 838 withTrail16, 1, |
| 841 U_SENTINEL, &numSubstitutions, | 839 U_SENTINEL, &numSubstitutions, |
| 842 &err); | 840 &err); |
| 843 if(U_FAILURE(err) || u8DestLen!=3 || | 841 if(U_FAILURE(err) || u8DestLen!=3 || |
| 844 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen) || | 842 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out
8, u8DestLen) || |
| 845 numSubstitutions!=0) { | 843 numSubstitutions!=0) { |
| 846 log_err("error: u_strToUTF8WithSub(no subchar) failed\n"); | 844 log_err("error: u_strToUTF8WithSub(no subchar) failed\n"); |
| 847 } | 845 } |
| 848 } | 846 } |
| 849 { | 847 { |
| 850 /* | 848 /* |
| 851 * Test with an illegal lead byte that would be followed by more than 3
trail bytes. | 849 * Test with an illegal lead byte that would be followed by more than 3
trail bytes. |
| 852 * See ticket #10371. | 850 * See ticket #10371. |
| 853 */ | 851 */ |
| 854 static const char src[1]={ 0xf8 }; | 852 static const char src[1]={ (char)0xf8 }; |
| 855 UChar out16[10]; | 853 UChar out16[10]; |
| 856 err=U_ZERO_ERROR; | 854 err=U_ZERO_ERROR; |
| 857 u_strFromUTF8(out16, LENGTHOF(out16), NULL, src, 1, &err); | 855 u_strFromUTF8(out16, UPRV_LENGTHOF(out16), NULL, src, 1, &err); |
| 858 if(err!=U_INVALID_CHAR_FOUND) { | 856 if(err!=U_INVALID_CHAR_FOUND) { |
| 859 log_err("error: u_strFromUTF8(5-byte lead byte) failed\n"); | 857 log_err("error: u_strFromUTF8(5-byte lead byte) failed\n"); |
| 860 } | 858 } |
| 861 } | 859 } |
| 862 } | 860 } |
| 863 | 861 |
| 864 /* compare if two strings are equal, but match 0xfffd in the second string with
anything in the first */ | 862 /* compare if two strings are equal, but match 0xfffd in the second string with
anything in the first */ |
| 865 static UBool | 863 static UBool |
| 866 equalAnyFFFD(const UChar *s, const UChar *t, int32_t length) { | 864 equalAnyFFFD(const UChar *s, const UChar *t, int32_t length) { |
| 867 UChar c1, c2; | 865 UChar c1, c2; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 destPointer=u_strFromUTF8(NULL, 0, &destLength, (const char *)bytes, -1, &er
rorCode); | 911 destPointer=u_strFromUTF8(NULL, 0, &destLength, (const char *)bytes, -1, &er
rorCode); |
| 914 if(errorCode!=U_BUFFER_OVERFLOW_ERROR || destPointer!=NULL || destLength!=1)
{ | 912 if(errorCode!=U_BUFFER_OVERFLOW_ERROR || destPointer!=NULL || destLength!=1)
{ |
| 915 log_err("error: u_strFromUTF8(preflight srcLength=-1) fails: destLength=
%ld - %s\n", | 913 log_err("error: u_strFromUTF8(preflight srcLength=-1) fails: destLength=
%ld - %s\n", |
| 916 (long)destLength, u_errorName(errorCode)); | 914 (long)destLength, u_errorName(errorCode)); |
| 917 } | 915 } |
| 918 | 916 |
| 919 /* 3 bytes input, one UChar output (U+095C), transform not just preflight */ | 917 /* 3 bytes input, one UChar output (U+095C), transform not just preflight */ |
| 920 errorCode=U_ZERO_ERROR; | 918 errorCode=U_ZERO_ERROR; |
| 921 dest[0]=dest[1]=99; | 919 dest[0]=dest[1]=99; |
| 922 destLength=-99; | 920 destLength=-99; |
| 923 destPointer=u_strFromUTF8(dest, LENGTHOF(dest), &destLength, (const char *)b
ytes, 3, &errorCode); | 921 destPointer=u_strFromUTF8(dest, UPRV_LENGTHOF(dest), &destLength, (const cha
r *)bytes, 3, &errorCode); |
| 924 if(U_FAILURE(errorCode) || destPointer!=dest || destLength!=1 || dest[0]!=0x
95c || dest[1]!=0) { | 922 if(U_FAILURE(errorCode) || destPointer!=dest || destLength!=1 || dest[0]!=0x
95c || dest[1]!=0) { |
| 925 log_err("error: u_strFromUTF8(transform srcLength=3) fails: destLength=%
ld - %s\n", | 923 log_err("error: u_strFromUTF8(transform srcLength=3) fails: destLength=%
ld - %s\n", |
| 926 (long)destLength, u_errorName(errorCode)); | 924 (long)destLength, u_errorName(errorCode)); |
| 927 } | 925 } |
| 928 } | 926 } |
| 929 | 927 |
| 930 /* test u_strFromUTF8Lenient() */ | 928 /* test u_strFromUTF8Lenient() */ |
| 931 static void | 929 static void |
| 932 Test_FromUTF8Lenient(void) { | 930 Test_FromUTF8Lenient(void) { |
| 933 /* | 931 /* |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 dest[destLength0-1]!=0x1234 || destLength!=destLength0 | 1052 dest[destLength0-1]!=0x1234 || destLength!=destLength0 |
| 1055 ) { | 1053 ) { |
| 1056 log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with
NUL-termination) failed\n", number); | 1054 log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with
NUL-termination) failed\n", number); |
| 1057 } | 1055 } |
| 1058 } | 1056 } |
| 1059 | 1057 |
| 1060 /* conversion with NUL-termination, much capacity */ | 1058 /* conversion with NUL-termination, much capacity */ |
| 1061 dest[0]=dest[destLength0]=0x1234; | 1059 dest[0]=dest[destLength0]=0x1234; |
| 1062 destLength=-1; | 1060 destLength=-1; |
| 1063 errorCode=U_ZERO_ERROR; | 1061 errorCode=U_ZERO_ERROR; |
| 1064 pDest=u_strFromUTF8Lenient(dest, LENGTHOF(dest), &destLength, pb, -1, &e
rrorCode); | 1062 pDest=u_strFromUTF8Lenient(dest, UPRV_LENGTHOF(dest), &destLength, pb, -
1, &errorCode); |
| 1065 if (errorCode!=U_ZERO_ERROR || | 1063 if (errorCode!=U_ZERO_ERROR || |
| 1066 pDest!=dest || dest[destLength0]!=0 || | 1064 pDest!=dest || dest[destLength0]!=0 || |
| 1067 destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) | 1065 destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) |
| 1068 ) { | 1066 ) { |
| 1069 log_err("u_strFromUTF8Lenient(%d conversion with NUL-termination, mu
ch capacity) failed\n", number); | 1067 log_err("u_strFromUTF8Lenient(%d conversion with NUL-termination, mu
ch capacity) failed\n", number); |
| 1070 } | 1068 } |
| 1071 | 1069 |
| 1072 /* conversion with NUL-termination, exact capacity */ | 1070 /* conversion with NUL-termination, exact capacity */ |
| 1073 dest[0]=dest[destLength0]=0x1234; | 1071 dest[0]=dest[destLength0]=0x1234; |
| 1074 destLength=-1; | 1072 destLength=-1; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1102 dest[srcLength-1]!=0x1234 || destLength!=srcLength | 1100 dest[srcLength-1]!=0x1234 || destLength!=srcLength |
| 1103 ) { | 1101 ) { |
| 1104 log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with
length) failed\n", number); | 1102 log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with
length) failed\n", number); |
| 1105 } | 1103 } |
| 1106 } | 1104 } |
| 1107 | 1105 |
| 1108 /* conversion with length, much capacity */ | 1106 /* conversion with length, much capacity */ |
| 1109 dest[0]=dest[destLength0]=0x1234; | 1107 dest[0]=dest[destLength0]=0x1234; |
| 1110 destLength=-1; | 1108 destLength=-1; |
| 1111 errorCode=U_ZERO_ERROR; | 1109 errorCode=U_ZERO_ERROR; |
| 1112 pDest=u_strFromUTF8Lenient(dest, LENGTHOF(dest), &destLength, pb, srcLen
gth, &errorCode); | 1110 pDest=u_strFromUTF8Lenient(dest, UPRV_LENGTHOF(dest), &destLength, pb, s
rcLength, &errorCode); |
| 1113 if (errorCode!=U_ZERO_ERROR || | 1111 if (errorCode!=U_ZERO_ERROR || |
| 1114 pDest!=dest || dest[destLength0]!=0 || | 1112 pDest!=dest || dest[destLength0]!=0 || |
| 1115 destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) | 1113 destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) |
| 1116 ) { | 1114 ) { |
| 1117 log_err("u_strFromUTF8Lenient(%d conversion with length, much capaci
ty) failed\n", number); | 1115 log_err("u_strFromUTF8Lenient(%d conversion with length, much capaci
ty) failed\n", number); |
| 1118 } | 1116 } |
| 1119 | 1117 |
| 1120 /* conversion with length, srcLength capacity */ | 1118 /* conversion with length, srcLength capacity */ |
| 1121 dest[0]=dest[srcLength]=dest[destLength0]=0x1234; | 1119 dest[0]=dest[srcLength]=dest[destLength0]=0x1234; |
| 1122 destLength=-1; | 1120 destLength=-1; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 /* | 1343 /* |
| 1346 * Test u_terminateWChars(). | 1344 * Test u_terminateWChars(). |
| 1347 * All u_terminateXYZ() use the same implementation macro; | 1345 * All u_terminateXYZ() use the same implementation macro; |
| 1348 * we test this function to improve API coverage. | 1346 * we test this function to improve API coverage. |
| 1349 */ | 1347 */ |
| 1350 { | 1348 { |
| 1351 wchar_t buffer[10]; | 1349 wchar_t buffer[10]; |
| 1352 | 1350 |
| 1353 err=U_ZERO_ERROR; | 1351 err=U_ZERO_ERROR; |
| 1354 buffer[3]=0x20ac; | 1352 buffer[3]=0x20ac; |
| 1355 wDestLen=u_terminateWChars(buffer, LENGTHOF(buffer), 3, &err); | 1353 wDestLen=u_terminateWChars(buffer, UPRV_LENGTHOF(buffer), 3, &err); |
| 1356 if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { | 1354 if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { |
| 1357 log_err("u_terminateWChars(buffer, all, 3, zero) failed: %s length %
d [3]==U+%04x\n", | 1355 log_err("u_terminateWChars(buffer, all, 3, zero) failed: %s length %
d [3]==U+%04x\n", |
| 1358 u_errorName(err), wDestLen, buffer[3]); | 1356 u_errorName(err), wDestLen, buffer[3]); |
| 1359 } | 1357 } |
| 1360 | 1358 |
| 1361 err=U_ZERO_ERROR; | 1359 err=U_ZERO_ERROR; |
| 1362 buffer[3]=0x20ac; | 1360 buffer[3]=0x20ac; |
| 1363 wDestLen=u_terminateWChars(buffer, 3, 3, &err); | 1361 wDestLen=u_terminateWChars(buffer, 3, 3, &err); |
| 1364 if(err!=U_STRING_NOT_TERMINATED_WARNING || wDestLen!=3 || buffer[3]!=0x2
0ac) { | 1362 if(err!=U_STRING_NOT_TERMINATED_WARNING || wDestLen!=3 || buffer[3]!=0x2
0ac) { |
| 1365 log_err("u_terminateWChars(buffer, 3, 3, zero) failed: %s length %d
[3]==U+%04x\n", | 1363 log_err("u_terminateWChars(buffer, 3, 3, zero) failed: %s length %d
[3]==U+%04x\n", |
| 1366 u_errorName(err), wDestLen, buffer[3]); | 1364 u_errorName(err), wDestLen, buffer[3]); |
| 1367 } | 1365 } |
| 1368 | 1366 |
| 1369 err=U_STRING_NOT_TERMINATED_WARNING; | 1367 err=U_STRING_NOT_TERMINATED_WARNING; |
| 1370 buffer[3]=0x20ac; | 1368 buffer[3]=0x20ac; |
| 1371 wDestLen=u_terminateWChars(buffer, LENGTHOF(buffer), 3, &err); | 1369 wDestLen=u_terminateWChars(buffer, UPRV_LENGTHOF(buffer), 3, &err); |
| 1372 if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { | 1370 if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { |
| 1373 log_err("u_terminateWChars(buffer, all, 3, not-terminated) failed: %
s length %d [3]==U+%04x\n", | 1371 log_err("u_terminateWChars(buffer, all, 3, not-terminated) failed: %
s length %d [3]==U+%04x\n", |
| 1374 u_errorName(err), wDestLen, buffer[3]); | 1372 u_errorName(err), wDestLen, buffer[3]); |
| 1375 } | 1373 } |
| 1376 | 1374 |
| 1377 err=U_ZERO_ERROR; | 1375 err=U_ZERO_ERROR; |
| 1378 buffer[3]=0x20ac; | 1376 buffer[3]=0x20ac; |
| 1379 wDestLen=u_terminateWChars(buffer, 2, 3, &err); | 1377 wDestLen=u_terminateWChars(buffer, 2, 3, &err); |
| 1380 if(err!=U_BUFFER_OVERFLOW_ERROR || wDestLen!=3 || buffer[3]!=0x20ac) { | 1378 if(err!=U_BUFFER_OVERFLOW_ERROR || wDestLen!=3 || buffer[3]!=0x20ac) { |
| 1381 log_err("u_terminateWChars(buffer, 2, 3, zero) failed: %s length %d
[3]==U+%04x\n", | 1379 log_err("u_terminateWChars(buffer, 2, 3, zero) failed: %s length %d
[3]==U+%04x\n", |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 char *p; | 1549 char *p; |
| 1552 int32_t length, expectedTerminatedLength; | 1550 int32_t length, expectedTerminatedLength; |
| 1553 UErrorCode errorCode; | 1551 UErrorCode errorCode; |
| 1554 | 1552 |
| 1555 expectedTerminatedLength=(int32_t)(strstr((const char *)expected, "\xc0\x80"
)- | 1553 expectedTerminatedLength=(int32_t)(strstr((const char *)expected, "\xc0\x80"
)- |
| 1556 (const char *)expected); | 1554 (const char *)expected); |
| 1557 | 1555 |
| 1558 errorCode=U_ZERO_ERROR; | 1556 errorCode=U_ZERO_ERROR; |
| 1559 length=-5; | 1557 length=-5; |
| 1560 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, | 1558 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, |
| 1561 src, LENGTHOF(src), &errorCode); | 1559 src, UPRV_LENGTHOF(src), &errorCode); |
| 1562 if( U_FAILURE(errorCode) || p!=dest || | 1560 if( U_FAILURE(errorCode) || p!=dest || |
| 1563 length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || | 1561 length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || |
| 1564 dest[length]!=0 | 1562 dest[length]!=0 |
| 1565 ) { | 1563 ) { |
| 1566 log_err("u_strToJavaModifiedUTF8(normal) failed - %s\n", u_errorName(err
orCode)); | 1564 log_err("u_strToJavaModifiedUTF8(normal) failed - %s\n", u_errorName(err
orCode)); |
| 1567 } | 1565 } |
| 1568 memset(dest, 0xff, sizeof(dest)); | 1566 memset(dest, 0xff, sizeof(dest)); |
| 1569 errorCode=U_ZERO_ERROR; | 1567 errorCode=U_ZERO_ERROR; |
| 1570 length=-5; | 1568 length=-5; |
| 1571 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, | 1569 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, |
| 1572 src, LENGTHOF(src), &errorCode); | 1570 src, UPRV_LENGTHOF(src), &errorCode); |
| 1573 if( U_FAILURE(errorCode) || p!=dest || | 1571 if( U_FAILURE(errorCode) || p!=dest || |
| 1574 0!=memcmp(dest, expected, LENGTHOF(expected)) || | 1572 0!=memcmp(dest, expected, UPRV_LENGTHOF(expected)) || |
| 1575 dest[LENGTHOF(expected)]!=0 | 1573 dest[UPRV_LENGTHOF(expected)]!=0 |
| 1576 ) { | 1574 ) { |
| 1577 log_err("u_strToJavaModifiedUTF8(normal, pLength=NULL) failed - %s\n", u
_errorName(errorCode)); | 1575 log_err("u_strToJavaModifiedUTF8(normal, pLength=NULL) failed - %s\n", u
_errorName(errorCode)); |
| 1578 } | 1576 } |
| 1579 memset(dest, 0xff, sizeof(dest)); | 1577 memset(dest, 0xff, sizeof(dest)); |
| 1580 errorCode=U_ZERO_ERROR; | 1578 errorCode=U_ZERO_ERROR; |
| 1581 length=-5; | 1579 length=-5; |
| 1582 p=u_strToJavaModifiedUTF8(dest, LENGTHOF(expected), &length, | 1580 p=u_strToJavaModifiedUTF8(dest, UPRV_LENGTHOF(expected), &length, |
| 1583 src, LENGTHOF(src), &errorCode); | 1581 src, UPRV_LENGTHOF(src), &errorCode); |
| 1584 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || | 1582 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || |
| 1585 length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || | 1583 length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || |
| 1586 dest[length]!=(char)0xff | 1584 dest[length]!=(char)0xff |
| 1587 ) { | 1585 ) { |
| 1588 log_err("u_strToJavaModifiedUTF8(tight) failed - %s\n", u_errorName(erro
rCode)); | 1586 log_err("u_strToJavaModifiedUTF8(tight) failed - %s\n", u_errorName(erro
rCode)); |
| 1589 } | 1587 } |
| 1590 memset(dest, 0xff, sizeof(dest)); | 1588 memset(dest, 0xff, sizeof(dest)); |
| 1591 errorCode=U_ZERO_ERROR; | 1589 errorCode=U_ZERO_ERROR; |
| 1592 length=-5; | 1590 length=-5; |
| 1593 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, src, -1, &er
rorCode); | 1591 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, src, -1, &er
rorCode); |
| 1594 if( U_FAILURE(errorCode) || p!=dest || | 1592 if( U_FAILURE(errorCode) || p!=dest || |
| 1595 length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || | 1593 length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || |
| 1596 dest[length]!=0 | 1594 dest[length]!=0 |
| 1597 ) { | 1595 ) { |
| 1598 log_err("u_strToJavaModifiedUTF8(NUL-terminated) failed - %s\n", u_error
Name(errorCode)); | 1596 log_err("u_strToJavaModifiedUTF8(NUL-terminated) failed - %s\n", u_error
Name(errorCode)); |
| 1599 } | 1597 } |
| 1600 memset(dest, 0xff, sizeof(dest)); | 1598 memset(dest, 0xff, sizeof(dest)); |
| 1601 errorCode=U_ZERO_ERROR; | 1599 errorCode=U_ZERO_ERROR; |
| 1602 length=-5; | 1600 length=-5; |
| 1603 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, src, -1, &error
Code); | 1601 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, src, -1, &error
Code); |
| 1604 if( U_FAILURE(errorCode) || p!=dest || | 1602 if( U_FAILURE(errorCode) || p!=dest || |
| 1605 0!=memcmp(dest, expected, expectedTerminatedLength) || | 1603 0!=memcmp(dest, expected, expectedTerminatedLength) || |
| 1606 dest[expectedTerminatedLength]!=0 | 1604 dest[expectedTerminatedLength]!=0 |
| 1607 ) { | 1605 ) { |
| 1608 log_err("u_strToJavaModifiedUTF8(NUL-terminated, pLength=NULL) failed -
%s\n", u_errorName(errorCode)); | 1606 log_err("u_strToJavaModifiedUTF8(NUL-terminated, pLength=NULL) failed -
%s\n", u_errorName(errorCode)); |
| 1609 } | 1607 } |
| 1610 memset(dest, 0xff, sizeof(dest)); | 1608 memset(dest, 0xff, sizeof(dest)); |
| 1611 errorCode=U_ZERO_ERROR; | 1609 errorCode=U_ZERO_ERROR; |
| 1612 length=-5; | 1610 length=-5; |
| 1613 p=u_strToJavaModifiedUTF8(dest, LENGTHOF(expected)/2, &length, | 1611 p=u_strToJavaModifiedUTF8(dest, UPRV_LENGTHOF(expected)/2, &length, |
| 1614 src, LENGTHOF(src), &errorCode); | 1612 src, UPRV_LENGTHOF(src), &errorCode); |
| 1615 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || | 1613 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || |
| 1616 length!=LENGTHOF(expected) || dest[LENGTHOF(expected)/2]!=(char)0xff | 1614 length!=UPRV_LENGTHOF(expected) || dest[UPRV_LENGTHOF(expected)/2]!=(cha
r)0xff |
| 1617 ) { | 1615 ) { |
| 1618 log_err("u_strToJavaModifiedUTF8(overflow) failed - %s\n", u_errorName(e
rrorCode)); | 1616 log_err("u_strToJavaModifiedUTF8(overflow) failed - %s\n", u_errorName(e
rrorCode)); |
| 1619 } | 1617 } |
| 1620 memset(dest, 0xff, sizeof(dest)); | 1618 memset(dest, 0xff, sizeof(dest)); |
| 1621 errorCode=U_ZERO_ERROR; | 1619 errorCode=U_ZERO_ERROR; |
| 1622 length=-5; | 1620 length=-5; |
| 1623 p=u_strToJavaModifiedUTF8(NULL, 0, &length, | 1621 p=u_strToJavaModifiedUTF8(NULL, 0, &length, |
| 1624 src, LENGTHOF(src), &errorCode); | 1622 src, UPRV_LENGTHOF(src), &errorCode); |
| 1625 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || | 1623 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || |
| 1626 length!=LENGTHOF(expected) || dest[0]!=(char)0xff | 1624 length!=UPRV_LENGTHOF(expected) || dest[0]!=(char)0xff |
| 1627 ) { | 1625 ) { |
| 1628 log_err("u_strToJavaModifiedUTF8(pure preflighting) failed - %s\n", u_er
rorName(errorCode)); | 1626 log_err("u_strToJavaModifiedUTF8(pure preflighting) failed - %s\n", u_er
rorName(errorCode)); |
| 1629 } | 1627 } |
| 1630 memset(dest, 0xff, sizeof(dest)); | 1628 memset(dest, 0xff, sizeof(dest)); |
| 1631 errorCode=U_ZERO_ERROR; | 1629 errorCode=U_ZERO_ERROR; |
| 1632 length=-5; | 1630 length=-5; |
| 1633 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, | 1631 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, |
| 1634 shortSrc, LENGTHOF(shortSrc), &errorCode); | 1632 shortSrc, UPRV_LENGTHOF(shortSrc), &errorCode); |
| 1635 if( U_FAILURE(errorCode) || p!=dest || | 1633 if( U_FAILURE(errorCode) || p!=dest || |
| 1636 length!=LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, length
) || | 1634 length!=UPRV_LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, l
ength) || |
| 1637 dest[length]!=0 | 1635 dest[length]!=0 |
| 1638 ) { | 1636 ) { |
| 1639 log_err("u_strToJavaModifiedUTF8(short) failed - %s\n", u_errorName(erro
rCode)); | 1637 log_err("u_strToJavaModifiedUTF8(short) failed - %s\n", u_errorName(erro
rCode)); |
| 1640 } | 1638 } |
| 1641 memset(dest, 0xff, sizeof(dest)); | 1639 memset(dest, 0xff, sizeof(dest)); |
| 1642 errorCode=U_ZERO_ERROR; | 1640 errorCode=U_ZERO_ERROR; |
| 1643 length=-5; | 1641 length=-5; |
| 1644 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, | 1642 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, |
| 1645 asciiNul, -1, &errorCode); | 1643 asciiNul, -1, &errorCode); |
| 1646 if( U_FAILURE(errorCode) || p!=dest || | 1644 if( U_FAILURE(errorCode) || p!=dest || |
| 1647 length!=LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpected,
length) || | 1645 length!=UPRV_LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpec
ted, length) || |
| 1648 dest[length]!=0 | 1646 dest[length]!=0 |
| 1649 ) { | 1647 ) { |
| 1650 log_err("u_strToJavaModifiedUTF8(asciiNul) failed - %s\n", u_errorName(e
rrorCode)); | 1648 log_err("u_strToJavaModifiedUTF8(asciiNul) failed - %s\n", u_errorName(e
rrorCode)); |
| 1651 } | 1649 } |
| 1652 memset(dest, 0xff, sizeof(dest)); | 1650 memset(dest, 0xff, sizeof(dest)); |
| 1653 errorCode=U_ZERO_ERROR; | 1651 errorCode=U_ZERO_ERROR; |
| 1654 length=-5; | 1652 length=-5; |
| 1655 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, | 1653 p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, |
| 1656 NULL, 0, &errorCode); | 1654 NULL, 0, &errorCode); |
| 1657 if( U_FAILURE(errorCode) || p!=dest || | 1655 if( U_FAILURE(errorCode) || p!=dest || |
| 1658 length!=0 || dest[0]!=0 | 1656 length!=0 || dest[0]!=0 |
| 1659 ) { | 1657 ) { |
| 1660 log_err("u_strToJavaModifiedUTF8(empty) failed - %s\n", u_errorName(erro
rCode)); | 1658 log_err("u_strToJavaModifiedUTF8(empty) failed - %s\n", u_errorName(erro
rCode)); |
| 1661 } | 1659 } |
| 1662 | 1660 |
| 1663 /* illegal arguments */ | 1661 /* illegal arguments */ |
| 1664 memset(dest, 0xff, sizeof(dest)); | 1662 memset(dest, 0xff, sizeof(dest)); |
| 1665 errorCode=U_ZERO_ERROR; | 1663 errorCode=U_ZERO_ERROR; |
| 1666 length=-5; | 1664 length=-5; |
| 1667 p=u_strToJavaModifiedUTF8(NULL, sizeof(dest), &length, | 1665 p=u_strToJavaModifiedUTF8(NULL, sizeof(dest), &length, |
| 1668 src, LENGTHOF(src), &errorCode); | 1666 src, UPRV_LENGTHOF(src), &errorCode); |
| 1669 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { | 1667 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { |
| 1670 log_err("u_strToJavaModifiedUTF8(dest=NULL) failed - %s\n", u_errorName(
errorCode)); | 1668 log_err("u_strToJavaModifiedUTF8(dest=NULL) failed - %s\n", u_errorName(
errorCode)); |
| 1671 } | 1669 } |
| 1672 memset(dest, 0xff, sizeof(dest)); | 1670 memset(dest, 0xff, sizeof(dest)); |
| 1673 errorCode=U_ZERO_ERROR; | 1671 errorCode=U_ZERO_ERROR; |
| 1674 length=-5; | 1672 length=-5; |
| 1675 p=u_strToJavaModifiedUTF8(dest, -1, &length, | 1673 p=u_strToJavaModifiedUTF8(dest, -1, &length, |
| 1676 src, LENGTHOF(src), &errorCode); | 1674 src, UPRV_LENGTHOF(src), &errorCode); |
| 1677 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { | 1675 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { |
| 1678 log_err("u_strToJavaModifiedUTF8(destCapacity<0) failed - %s\n", u_error
Name(errorCode)); | 1676 log_err("u_strToJavaModifiedUTF8(destCapacity<0) failed - %s\n", u_error
Name(errorCode)); |
| 1679 } | 1677 } |
| 1680 memset(dest, 0xff, sizeof(dest)); | 1678 memset(dest, 0xff, sizeof(dest)); |
| 1681 errorCode=U_ZERO_ERROR; | 1679 errorCode=U_ZERO_ERROR; |
| 1682 length=-5; | 1680 length=-5; |
| 1683 p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, | 1681 p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, |
| 1684 NULL, LENGTHOF(src), &errorCode); | 1682 NULL, UPRV_LENGTHOF(src), &errorCode); |
| 1685 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { | 1683 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { |
| 1686 log_err("u_strToJavaModifiedUTF8(src=NULL) failed - %s\n", u_errorName(e
rrorCode)); | 1684 log_err("u_strToJavaModifiedUTF8(src=NULL) failed - %s\n", u_errorName(e
rrorCode)); |
| 1687 } | 1685 } |
| 1688 memset(dest, 0xff, sizeof(dest)); | 1686 memset(dest, 0xff, sizeof(dest)); |
| 1689 errorCode=U_ZERO_ERROR; | 1687 errorCode=U_ZERO_ERROR; |
| 1690 length=-5; | 1688 length=-5; |
| 1691 p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, | 1689 p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, |
| 1692 NULL, -1, &errorCode); | 1690 NULL, -1, &errorCode); |
| 1693 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { | 1691 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { |
| 1694 log_err("u_strToJavaModifiedUTF8(src=NULL, srcLength<0) failed - %s\n",
u_errorName(errorCode)); | 1692 log_err("u_strToJavaModifiedUTF8(src=NULL, srcLength<0) failed - %s\n",
u_errorName(errorCode)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 UChar *p; | 1740 UChar *p; |
| 1743 int32_t length, expectedTerminatedLength; | 1741 int32_t length, expectedTerminatedLength; |
| 1744 int32_t numSubstitutions; | 1742 int32_t numSubstitutions; |
| 1745 UErrorCode errorCode; | 1743 UErrorCode errorCode; |
| 1746 | 1744 |
| 1747 expectedTerminatedLength=(int32_t)(u_strchr(expected, 0)-expected); | 1745 expectedTerminatedLength=(int32_t)(u_strchr(expected, 0)-expected); |
| 1748 | 1746 |
| 1749 errorCode=U_ZERO_ERROR; | 1747 errorCode=U_ZERO_ERROR; |
| 1750 length=numSubstitutions=-5; | 1748 length=numSubstitutions=-5; |
| 1751 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1749 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1752 (const char *)src, LENGTHOF(src), | 1750 (const char *)src, UPRV_LENGTHOF(src), |
| 1753 0xfffd, &numSubstitutions, &errorCode); | 1751 0xfffd, &numSubstitutions, &errorCode); |
| 1754 if( U_FAILURE(errorCode) || p!=dest || | 1752 if( U_FAILURE(errorCode) || p!=dest || |
| 1755 length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || | 1753 length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || |
| 1756 dest[length]!=0 || | 1754 dest[length]!=0 || |
| 1757 numSubstitutions!=LENGTHOF(invalidExpectedFFFD) | 1755 numSubstitutions!=UPRV_LENGTHOF(invalidExpectedFFFD) |
| 1758 ) { | 1756 ) { |
| 1759 log_err("u_strFromJavaModifiedUTF8WithSub(normal) failed - %s\n", u_erro
rName(errorCode)); | 1757 log_err("u_strFromJavaModifiedUTF8WithSub(normal) failed - %s\n", u_erro
rName(errorCode)); |
| 1760 } | 1758 } |
| 1761 memset(dest, 0xff, sizeof(dest)); | 1759 memset(dest, 0xff, sizeof(dest)); |
| 1762 errorCode=U_ZERO_ERROR; | 1760 errorCode=U_ZERO_ERROR; |
| 1763 length=numSubstitutions=-5; | 1761 length=numSubstitutions=-5; |
| 1764 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), NULL, | 1762 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), NULL, |
| 1765 (const char *)src, LENGTHOF(src), | 1763 (const char *)src, UPRV_LENGTHOF(src), |
| 1766 0xfffd, &numSubstitutions, &errorCode); | 1764 0xfffd, &numSubstitutions, &errorCode); |
| 1767 if( U_FAILURE(errorCode) || p!=dest || | 1765 if( U_FAILURE(errorCode) || p!=dest || |
| 1768 0!=memcmp(dest, expected, LENGTHOF(expected)) || | 1766 0!=memcmp(dest, expected, UPRV_LENGTHOF(expected)) || |
| 1769 dest[LENGTHOF(expected)]!=0 || | 1767 dest[UPRV_LENGTHOF(expected)]!=0 || |
| 1770 numSubstitutions!=LENGTHOF(invalidExpectedFFFD) | 1768 numSubstitutions!=UPRV_LENGTHOF(invalidExpectedFFFD) |
| 1771 ) { | 1769 ) { |
| 1772 log_err("u_strFromJavaModifiedUTF8WithSub(normal, pLength=NULL) failed -
%s\n", u_errorName(errorCode)); | 1770 log_err("u_strFromJavaModifiedUTF8WithSub(normal, pLength=NULL) failed -
%s\n", u_errorName(errorCode)); |
| 1773 } | 1771 } |
| 1774 memset(dest, 0xff, sizeof(dest)); | 1772 memset(dest, 0xff, sizeof(dest)); |
| 1775 errorCode=U_ZERO_ERROR; | 1773 errorCode=U_ZERO_ERROR; |
| 1776 length=numSubstitutions=-5; | 1774 length=numSubstitutions=-5; |
| 1777 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1775 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1778 (const char *)src, LENGTHOF(src), | 1776 (const char *)src, UPRV_LENGTHOF(src), |
| 1779 0xfffd, NULL, &errorCode); | 1777 0xfffd, NULL, &errorCode); |
| 1780 if( U_FAILURE(errorCode) || p!=dest || | 1778 if( U_FAILURE(errorCode) || p!=dest || |
| 1781 length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || | 1779 length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || |
| 1782 dest[length]!=0 | 1780 dest[length]!=0 |
| 1783 ) { | 1781 ) { |
| 1784 log_err("u_strFromJavaModifiedUTF8WithSub(normal, pNumSubstitutions=NULL
) failed - %s\n", u_errorName(errorCode)); | 1782 log_err("u_strFromJavaModifiedUTF8WithSub(normal, pNumSubstitutions=NULL
) failed - %s\n", u_errorName(errorCode)); |
| 1785 } | 1783 } |
| 1786 memset(dest, 0xff, sizeof(dest)); | 1784 memset(dest, 0xff, sizeof(dest)); |
| 1787 errorCode=U_ZERO_ERROR; | 1785 errorCode=U_ZERO_ERROR; |
| 1788 length=numSubstitutions=-5; | 1786 length=numSubstitutions=-5; |
| 1789 p=u_strFromJavaModifiedUTF8WithSub(dest, LENGTHOF(expected), &length, | 1787 p=u_strFromJavaModifiedUTF8WithSub(dest, UPRV_LENGTHOF(expected), &length, |
| 1790 (const char *)src, LENGTHOF(src), | 1788 (const char *)src, UPRV_LENGTHOF(src), |
| 1791 0xfffd, &numSubstitutions, &errorCode); | 1789 0xfffd, &numSubstitutions, &errorCode); |
| 1792 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || | 1790 if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || |
| 1793 length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || | 1791 length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || |
| 1794 dest[length]!=0xffff || | 1792 dest[length]!=0xffff || |
| 1795 numSubstitutions!=LENGTHOF(invalidExpectedFFFD) | 1793 numSubstitutions!=UPRV_LENGTHOF(invalidExpectedFFFD) |
| 1796 ) { | 1794 ) { |
| 1797 log_err("u_strFromJavaModifiedUTF8WithSub(tight) failed - %s\n", u_error
Name(errorCode)); | 1795 log_err("u_strFromJavaModifiedUTF8WithSub(tight) failed - %s\n", u_error
Name(errorCode)); |
| 1798 } | 1796 } |
| 1799 memset(dest, 0xff, sizeof(dest)); | 1797 memset(dest, 0xff, sizeof(dest)); |
| 1800 errorCode=U_ZERO_ERROR; | 1798 errorCode=U_ZERO_ERROR; |
| 1801 length=numSubstitutions=-5; | 1799 length=numSubstitutions=-5; |
| 1802 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1800 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1803 (const char *)src, -1, | 1801 (const char *)src, -1, |
| 1804 0xfffd, &numSubstitutions, &errorCode); | 1802 0xfffd, &numSubstitutions, &errorCode); |
| 1805 if( U_FAILURE(errorCode) || p!=dest || | 1803 if( U_FAILURE(errorCode) || p!=dest || |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1830 0xfffd, NULL, &errorCode); | 1828 0xfffd, NULL, &errorCode); |
| 1831 if( U_FAILURE(errorCode) || p!=dest || | 1829 if( U_FAILURE(errorCode) || p!=dest || |
| 1832 length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || | 1830 length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || |
| 1833 dest[length]!=0 | 1831 dest[length]!=0 |
| 1834 ) { | 1832 ) { |
| 1835 log_err("u_strFromJavaModifiedUTF8WithSub(NUL-terminated, pNumSubstituti
ons=NULL) failed - %s\n", u_errorName(errorCode)); | 1833 log_err("u_strFromJavaModifiedUTF8WithSub(NUL-terminated, pNumSubstituti
ons=NULL) failed - %s\n", u_errorName(errorCode)); |
| 1836 } | 1834 } |
| 1837 memset(dest, 0xff, sizeof(dest)); | 1835 memset(dest, 0xff, sizeof(dest)); |
| 1838 errorCode=U_ZERO_ERROR; | 1836 errorCode=U_ZERO_ERROR; |
| 1839 length=numSubstitutions=-5; | 1837 length=numSubstitutions=-5; |
| 1840 p=u_strFromJavaModifiedUTF8WithSub(dest, LENGTHOF(expected)/2, &length, | 1838 p=u_strFromJavaModifiedUTF8WithSub(dest, UPRV_LENGTHOF(expected)/2, &length, |
| 1841 (const char *)src, LENGTHOF(src), | 1839 (const char *)src, UPRV_LENGTHOF(src), |
| 1842 0xfffd, &numSubstitutions, &errorCode); | 1840 0xfffd, &numSubstitutions, &errorCode); |
| 1843 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || | 1841 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || |
| 1844 length!=LENGTHOF(expected) || dest[LENGTHOF(expected)/2]!=0xffff | 1842 length!=UPRV_LENGTHOF(expected) || dest[UPRV_LENGTHOF(expected)/2]!=0xff
ff |
| 1845 ) { | 1843 ) { |
| 1846 log_err("u_strFromJavaModifiedUTF8WithSub(overflow) failed - %s\n", u_er
rorName(errorCode)); | 1844 log_err("u_strFromJavaModifiedUTF8WithSub(overflow) failed - %s\n", u_er
rorName(errorCode)); |
| 1847 } | 1845 } |
| 1848 memset(dest, 0xff, sizeof(dest)); | 1846 memset(dest, 0xff, sizeof(dest)); |
| 1849 errorCode=U_ZERO_ERROR; | 1847 errorCode=U_ZERO_ERROR; |
| 1850 length=numSubstitutions=-5; | 1848 length=numSubstitutions=-5; |
| 1851 p=u_strFromJavaModifiedUTF8WithSub(NULL, 0, &length, | 1849 p=u_strFromJavaModifiedUTF8WithSub(NULL, 0, &length, |
| 1852 (const char *)src, LENGTHOF(src), | 1850 (const char *)src, UPRV_LENGTHOF(src), |
| 1853 0xfffd, &numSubstitutions, &errorCode); | 1851 0xfffd, &numSubstitutions, &errorCode); |
| 1854 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || | 1852 if( errorCode!=U_BUFFER_OVERFLOW_ERROR || |
| 1855 length!=LENGTHOF(expected) || dest[0]!=0xffff | 1853 length!=UPRV_LENGTHOF(expected) || dest[0]!=0xffff |
| 1856 ) { | 1854 ) { |
| 1857 log_err("u_strFromJavaModifiedUTF8WithSub(pure preflighting) failed - %s
\n", u_errorName(errorCode)); | 1855 log_err("u_strFromJavaModifiedUTF8WithSub(pure preflighting) failed - %s
\n", u_errorName(errorCode)); |
| 1858 } | 1856 } |
| 1859 memset(dest, 0xff, sizeof(dest)); | 1857 memset(dest, 0xff, sizeof(dest)); |
| 1860 errorCode=U_ZERO_ERROR; | 1858 errorCode=U_ZERO_ERROR; |
| 1861 length=numSubstitutions=-5; | 1859 length=numSubstitutions=-5; |
| 1862 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1860 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1863 (const char *)shortSrc, LENGTHOF(shortSrc
), | 1861 (const char *)shortSrc, UPRV_LENGTHOF(sho
rtSrc), |
| 1864 0xfffd, &numSubstitutions, &errorCode); | 1862 0xfffd, &numSubstitutions, &errorCode); |
| 1865 if( U_FAILURE(errorCode) || p!=dest || | 1863 if( U_FAILURE(errorCode) || p!=dest || |
| 1866 length!=LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, length
) || | 1864 length!=UPRV_LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, l
ength) || |
| 1867 dest[length]!=0 || | 1865 dest[length]!=0 || |
| 1868 numSubstitutions!=0 | 1866 numSubstitutions!=0 |
| 1869 ) { | 1867 ) { |
| 1870 log_err("u_strFromJavaModifiedUTF8WithSub(short) failed - %s\n", u_error
Name(errorCode)); | 1868 log_err("u_strFromJavaModifiedUTF8WithSub(short) failed - %s\n", u_error
Name(errorCode)); |
| 1871 } | 1869 } |
| 1872 memset(dest, 0xff, sizeof(dest)); | 1870 memset(dest, 0xff, sizeof(dest)); |
| 1873 errorCode=U_ZERO_ERROR; | 1871 errorCode=U_ZERO_ERROR; |
| 1874 length=numSubstitutions=-5; | 1872 length=numSubstitutions=-5; |
| 1875 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1873 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1876 (const char *)asciiNul, -1, | 1874 (const char *)asciiNul, -1, |
| 1877 0xfffd, &numSubstitutions, &errorCode); | 1875 0xfffd, &numSubstitutions, &errorCode); |
| 1878 if( U_FAILURE(errorCode) || p!=dest || | 1876 if( U_FAILURE(errorCode) || p!=dest || |
| 1879 length!=LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpected,
length) || | 1877 length!=UPRV_LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpec
ted, length) || |
| 1880 dest[length]!=0 || | 1878 dest[length]!=0 || |
| 1881 numSubstitutions!=0 | 1879 numSubstitutions!=0 |
| 1882 ) { | 1880 ) { |
| 1883 log_err("u_strFromJavaModifiedUTF8WithSub(asciiNul) failed - %s\n", u_er
rorName(errorCode)); | 1881 log_err("u_strFromJavaModifiedUTF8WithSub(asciiNul) failed - %s\n", u_er
rorName(errorCode)); |
| 1884 } | 1882 } |
| 1885 memset(dest, 0xff, sizeof(dest)); | 1883 memset(dest, 0xff, sizeof(dest)); |
| 1886 errorCode=U_ZERO_ERROR; | 1884 errorCode=U_ZERO_ERROR; |
| 1887 length=numSubstitutions=-5; | 1885 length=numSubstitutions=-5; |
| 1888 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1886 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1889 NULL, 0, 0xfffd, &numSubstitutions, &erro
rCode); | 1887 NULL, 0, 0xfffd, &numSubstitutions, &erro
rCode); |
| 1890 if( U_FAILURE(errorCode) || p!=dest || | 1888 if( U_FAILURE(errorCode) || p!=dest || |
| 1891 length!=0 || dest[0]!=0 || | 1889 length!=0 || dest[0]!=0 || |
| 1892 numSubstitutions!=0 | 1890 numSubstitutions!=0 |
| 1893 ) { | 1891 ) { |
| 1894 log_err("u_strFromJavaModifiedUTF8WithSub(empty) failed - %s\n", u_error
Name(errorCode)); | 1892 log_err("u_strFromJavaModifiedUTF8WithSub(empty) failed - %s\n", u_error
Name(errorCode)); |
| 1895 } | 1893 } |
| 1896 memset(dest, 0xff, sizeof(dest)); | 1894 memset(dest, 0xff, sizeof(dest)); |
| 1897 errorCode=U_ZERO_ERROR; | 1895 errorCode=U_ZERO_ERROR; |
| 1898 length=numSubstitutions=-5; | 1896 length=numSubstitutions=-5; |
| 1899 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1897 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1900 (const char *)invalid, LENGTHOF(invalid), | 1898 (const char *)invalid, UPRV_LENGTHOF(inva
lid), |
| 1901 0xfffd, &numSubstitutions, &errorCode); | 1899 0xfffd, &numSubstitutions, &errorCode); |
| 1902 if( U_FAILURE(errorCode) || p!=dest || | 1900 if( U_FAILURE(errorCode) || p!=dest || |
| 1903 length!=LENGTHOF(invalidExpectedFFFD) || 0!=memcmp(dest, invalidExpected
FFFD, length) || | 1901 length!=UPRV_LENGTHOF(invalidExpectedFFFD) || 0!=memcmp(dest, invalidExp
ectedFFFD, length) || |
| 1904 dest[length]!=0 || | 1902 dest[length]!=0 || |
| 1905 numSubstitutions!=LENGTHOF(invalidExpectedFFFD) | 1903 numSubstitutions!=UPRV_LENGTHOF(invalidExpectedFFFD) |
| 1906 ) { | 1904 ) { |
| 1907 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->fffd) failed - %s\n",
u_errorName(errorCode)); | 1905 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->fffd) failed - %s\n",
u_errorName(errorCode)); |
| 1908 } | 1906 } |
| 1909 memset(dest, 0xff, sizeof(dest)); | 1907 memset(dest, 0xff, sizeof(dest)); |
| 1910 errorCode=U_ZERO_ERROR; | 1908 errorCode=U_ZERO_ERROR; |
| 1911 length=numSubstitutions=-5; | 1909 length=numSubstitutions=-5; |
| 1912 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1910 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1913 (const char *)invalid, LENGTHOF(invalid), | 1911 (const char *)invalid, UPRV_LENGTHOF(inva
lid), |
| 1914 0x50000, &numSubstitutions, &errorCode); | 1912 0x50000, &numSubstitutions, &errorCode); |
| 1915 if( U_FAILURE(errorCode) || p!=dest || | 1913 if( U_FAILURE(errorCode) || p!=dest || |
| 1916 length!=LENGTHOF(invalidExpected50000) || 0!=memcmp(dest, invalidExpecte
d50000, length) || | 1914 length!=UPRV_LENGTHOF(invalidExpected50000) || 0!=memcmp(dest, invalidEx
pected50000, length) || |
| 1917 dest[length]!=0 || | 1915 dest[length]!=0 || |
| 1918 numSubstitutions!=LENGTHOF(invalidExpectedFFFD) /* not ...50000 */ | 1916 numSubstitutions!=UPRV_LENGTHOF(invalidExpectedFFFD) /* not ...50000 */ |
| 1919 ) { | 1917 ) { |
| 1920 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->50000) failed - %s\n"
, u_errorName(errorCode)); | 1918 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->50000) failed - %s\n"
, u_errorName(errorCode)); |
| 1921 } | 1919 } |
| 1922 memset(dest, 0xff, sizeof(dest)); | 1920 memset(dest, 0xff, sizeof(dest)); |
| 1923 errorCode=U_ZERO_ERROR; | 1921 errorCode=U_ZERO_ERROR; |
| 1924 length=numSubstitutions=-5; | 1922 length=numSubstitutions=-5; |
| 1925 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1923 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1926 (const char *)invalid, LENGTHOF(invalid), | 1924 (const char *)invalid, UPRV_LENGTHOF(inva
lid), |
| 1927 U_SENTINEL, &numSubstitutions, &errorCode
); | 1925 U_SENTINEL, &numSubstitutions, &errorCode
); |
| 1928 if(errorCode!=U_INVALID_CHAR_FOUND || dest[0]!=0xffff || numSubstitutions!=0
) { | 1926 if(errorCode!=U_INVALID_CHAR_FOUND || dest[0]!=0xffff || numSubstitutions!=0
) { |
| 1929 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->error) failed - %s\n"
, u_errorName(errorCode)); | 1927 log_err("u_strFromJavaModifiedUTF8WithSub(invalid->error) failed - %s\n"
, u_errorName(errorCode)); |
| 1930 } | 1928 } |
| 1931 memset(dest, 0xff, sizeof(dest)); | 1929 memset(dest, 0xff, sizeof(dest)); |
| 1932 errorCode=U_ZERO_ERROR; | 1930 errorCode=U_ZERO_ERROR; |
| 1933 length=numSubstitutions=-5; | 1931 length=numSubstitutions=-5; |
| 1934 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, | 1932 p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, |
| 1935 (const char *)src, LENGTHOF(src), | 1933 (const char *)src, UPRV_LENGTHOF(src), |
| 1936 U_SENTINEL, &numSubstitutions, &errorCode
); | 1934 U_SENTINEL, &numSubstitutions, &errorCode
); |
| 1937 if( errorCode!=U_INVALID_CHAR_FOUND || | 1935 if( errorCode!=U_INVALID_CHAR_FOUND || |
| 1938 length>=LENGTHOF(expected) || dest[LENGTHOF(expected)-1]!=0xffff || | 1936 length>=UPRV_LENGTHOF(expected) || dest[UPRV_LENGTHOF(expected)-1]!=0xff
ff || |
| 1939 numSubstitutions!=0 | 1937 numSubstitutions!=0 |
| 1940 ) { | 1938 ) { |
| 1941 log_err("u_strFromJavaModifiedUTF8WithSub(normal->error) failed - %s\n",
u_errorName(errorCode)); | 1939 log_err("u_strFromJavaModifiedUTF8WithSub(normal->error) failed - %s\n",
u_errorName(errorCode)); |
| 1942 } | 1940 } |
| 1943 | 1941 |
| 1944 /* illegal arguments */ | 1942 /* illegal arguments */ |
| 1945 memset(dest, 0xff, sizeof(dest)); | 1943 memset(dest, 0xff, sizeof(dest)); |
| 1946 errorCode=U_ZERO_ERROR; | 1944 errorCode=U_ZERO_ERROR; |
| 1947 length=numSubstitutions=-5; | 1945 length=numSubstitutions=-5; |
| 1948 p=u_strFromJavaModifiedUTF8WithSub(NULL, sizeof(dest), &length, | 1946 p=u_strFromJavaModifiedUTF8WithSub(NULL, sizeof(dest), &length, |
| 1949 (const char *)src, LENGTHOF(src), | 1947 (const char *)src, UPRV_LENGTHOF(src), |
| 1950 0xfffd, &numSubstitutions, &errorCode); | 1948 0xfffd, &numSubstitutions, &errorCode); |
| 1951 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1949 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1952 log_err("u_strFromJavaModifiedUTF8WithSub(dest=NULL) failed - %s\n", u_e
rrorName(errorCode)); | 1950 log_err("u_strFromJavaModifiedUTF8WithSub(dest=NULL) failed - %s\n", u_e
rrorName(errorCode)); |
| 1953 } | 1951 } |
| 1954 memset(dest, 0xff, sizeof(dest)); | 1952 memset(dest, 0xff, sizeof(dest)); |
| 1955 errorCode=U_ZERO_ERROR; | 1953 errorCode=U_ZERO_ERROR; |
| 1956 length=numSubstitutions=-5; | 1954 length=numSubstitutions=-5; |
| 1957 p=u_strFromJavaModifiedUTF8WithSub(dest, -1, &length, | 1955 p=u_strFromJavaModifiedUTF8WithSub(dest, -1, &length, |
| 1958 (const char *)src, LENGTHOF(src), | 1956 (const char *)src, UPRV_LENGTHOF(src), |
| 1959 0xfffd, &numSubstitutions, &errorCode); | 1957 0xfffd, &numSubstitutions, &errorCode); |
| 1960 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1958 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1961 log_err("u_strFromJavaModifiedUTF8WithSub(destCapacity<0) failed - %s\n"
, u_errorName(errorCode)); | 1959 log_err("u_strFromJavaModifiedUTF8WithSub(destCapacity<0) failed - %s\n"
, u_errorName(errorCode)); |
| 1962 } | 1960 } |
| 1963 memset(dest, 0xff, sizeof(dest)); | 1961 memset(dest, 0xff, sizeof(dest)); |
| 1964 errorCode=U_ZERO_ERROR; | 1962 errorCode=U_ZERO_ERROR; |
| 1965 length=numSubstitutions=-5; | 1963 length=numSubstitutions=-5; |
| 1966 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, | 1964 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, |
| 1967 NULL, LENGTHOF(src), | 1965 NULL, UPRV_LENGTHOF(src), |
| 1968 0xfffd, &numSubstitutions, &errorCode); | 1966 0xfffd, &numSubstitutions, &errorCode); |
| 1969 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1967 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1970 log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL) failed - %s\n", u_er
rorName(errorCode)); | 1968 log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL) failed - %s\n", u_er
rorName(errorCode)); |
| 1971 } | 1969 } |
| 1972 memset(dest, 0xff, sizeof(dest)); | 1970 memset(dest, 0xff, sizeof(dest)); |
| 1973 errorCode=U_ZERO_ERROR; | 1971 errorCode=U_ZERO_ERROR; |
| 1974 length=numSubstitutions=-5; | 1972 length=numSubstitutions=-5; |
| 1975 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, | 1973 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, |
| 1976 NULL, -1, 0xfffd, &numSubstitutions, &err
orCode); | 1974 NULL, -1, 0xfffd, &numSubstitutions, &err
orCode); |
| 1977 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1975 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1978 log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL, srcLength<0) failed
- %s\n", u_errorName(errorCode)); | 1976 log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL, srcLength<0) failed
- %s\n", u_errorName(errorCode)); |
| 1979 } | 1977 } |
| 1980 memset(dest, 0xff, sizeof(dest)); | 1978 memset(dest, 0xff, sizeof(dest)); |
| 1981 errorCode=U_ZERO_ERROR; | 1979 errorCode=U_ZERO_ERROR; |
| 1982 length=numSubstitutions=-5; | 1980 length=numSubstitutions=-5; |
| 1983 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, | 1981 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, |
| 1984 (const char *)src, LENGTHOF(src), | 1982 (const char *)src, UPRV_LENGTHOF(src), |
| 1985 0x110000, &numSubstitutions, &errorCode); | 1983 0x110000, &numSubstitutions, &errorCode); |
| 1986 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1984 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1987 log_err("u_strFromJavaModifiedUTF8WithSub(subchar=U_SENTINEL) failed - %
s\n", u_errorName(errorCode)); | 1985 log_err("u_strFromJavaModifiedUTF8WithSub(subchar=U_SENTINEL) failed - %
s\n", u_errorName(errorCode)); |
| 1988 } | 1986 } |
| 1989 memset(dest, 0xff, sizeof(dest)); | 1987 memset(dest, 0xff, sizeof(dest)); |
| 1990 errorCode=U_ZERO_ERROR; | 1988 errorCode=U_ZERO_ERROR; |
| 1991 length=numSubstitutions=-5; | 1989 length=numSubstitutions=-5; |
| 1992 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, | 1990 p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, |
| 1993 (const char *)src, LENGTHOF(src), | 1991 (const char *)src, UPRV_LENGTHOF(src), |
| 1994 0xdfff, &numSubstitutions, &errorCode); | 1992 0xdfff, &numSubstitutions, &errorCode); |
| 1995 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { | 1993 if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { |
| 1996 log_err("u_strFromJavaModifiedUTF8WithSub(subchar is surrogate) failed -
%s\n", u_errorName(errorCode)); | 1994 log_err("u_strFromJavaModifiedUTF8WithSub(subchar is surrogate) failed -
%s\n", u_errorName(errorCode)); |
| 1997 } | 1995 } |
| 1998 } | 1996 } |
| 1999 | 1997 |
| 2000 /* test that string transformation functions permit NULL source pointer when sou
rce length==0 */ | 1998 /* test that string transformation functions permit NULL source pointer when sou
rce length==0 */ |
| 2001 static void TestNullEmptySource() { | 1999 static void TestNullEmptySource() { |
| 2002 char dest8[4]={ 3, 3, 3, 3 }; | 2000 char dest8[4]={ 3, 3, 3, 3 }; |
| 2003 UChar dest16[4]={ 3, 3, 3, 3 }; | 2001 UChar dest16[4]={ 3, 3, 3, 3 }; |
| 2004 UChar32 dest32[4]={ 3, 3, 3, 3 }; | 2002 UChar32 dest32[4]={ 3, 3, 3, 3 }; |
| 2005 #if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CON
VERSION && !UCONFIG_NO_LEGACY_CONVERSION) | 2003 #if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CON
VERSION && !UCONFIG_NO_LEGACY_CONVERSION) |
| 2006 wchar_t destW[4]={ 3, 3, 3, 3 }; | 2004 wchar_t destW[4]={ 3, 3, 3, 3 }; |
| 2007 #endif | 2005 #endif |
| 2008 | 2006 |
| 2009 int32_t length; | 2007 int32_t length; |
| 2010 UErrorCode errorCode; | 2008 UErrorCode errorCode; |
| 2011 | 2009 |
| 2012 /* u_strFromXyz() */ | 2010 /* u_strFromXyz() */ |
| 2013 | 2011 |
| 2014 dest16[0]=3; | 2012 dest16[0]=3; |
| 2015 length=3; | 2013 length=3; |
| 2016 errorCode=U_ZERO_ERROR; | 2014 errorCode=U_ZERO_ERROR; |
| 2017 u_strFromUTF8(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); | 2015 u_strFromUTF8(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, &errorCode); |
| 2018 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2016 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2019 log_err("u_strFromUTF8(source=NULL, sourceLength=0) failed\n"); | 2017 log_err("u_strFromUTF8(source=NULL, sourceLength=0) failed\n"); |
| 2020 } | 2018 } |
| 2021 | 2019 |
| 2022 dest16[0]=3; | 2020 dest16[0]=3; |
| 2023 length=3; | 2021 length=3; |
| 2024 errorCode=U_ZERO_ERROR; | 2022 errorCode=U_ZERO_ERROR; |
| 2025 u_strFromUTF8WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0, 0xfffd, NUL
L, &errorCode); | 2023 u_strFromUTF8WithSub(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, 0xfffd
, NULL, &errorCode); |
| 2026 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2024 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2027 log_err("u_strFromUTF8WithSub(source=NULL, sourceLength=0) failed\n"); | 2025 log_err("u_strFromUTF8WithSub(source=NULL, sourceLength=0) failed\n"); |
| 2028 } | 2026 } |
| 2029 | 2027 |
| 2030 dest16[0]=3; | 2028 dest16[0]=3; |
| 2031 length=3; | 2029 length=3; |
| 2032 errorCode=U_ZERO_ERROR; | 2030 errorCode=U_ZERO_ERROR; |
| 2033 u_strFromUTF8Lenient(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode)
; | 2031 u_strFromUTF8Lenient(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, &error
Code); |
| 2034 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2032 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2035 log_err("u_strFromUTF8Lenient(source=NULL, sourceLength=0) failed\n"); | 2033 log_err("u_strFromUTF8Lenient(source=NULL, sourceLength=0) failed\n"); |
| 2036 } | 2034 } |
| 2037 | 2035 |
| 2038 dest16[0]=3; | 2036 dest16[0]=3; |
| 2039 length=3; | 2037 length=3; |
| 2040 errorCode=U_ZERO_ERROR; | 2038 errorCode=U_ZERO_ERROR; |
| 2041 u_strFromUTF32(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); | 2039 u_strFromUTF32(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, &errorCode); |
| 2042 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2040 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2043 log_err("u_strFromUTF32(source=NULL, sourceLength=0) failed\n"); | 2041 log_err("u_strFromUTF32(source=NULL, sourceLength=0) failed\n"); |
| 2044 } | 2042 } |
| 2045 | 2043 |
| 2046 dest16[0]=3; | 2044 dest16[0]=3; |
| 2047 length=3; | 2045 length=3; |
| 2048 errorCode=U_ZERO_ERROR; | 2046 errorCode=U_ZERO_ERROR; |
| 2049 u_strFromUTF32WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0, 0xfffd, NU
LL, &errorCode); | 2047 u_strFromUTF32WithSub(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, 0xfff
d, NULL, &errorCode); |
| 2050 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2048 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2051 log_err("u_strFromUTF32WithSub(source=NULL, sourceLength=0) failed\n"); | 2049 log_err("u_strFromUTF32WithSub(source=NULL, sourceLength=0) failed\n"); |
| 2052 } | 2050 } |
| 2053 | 2051 |
| 2054 dest16[0]=3; | 2052 dest16[0]=3; |
| 2055 length=3; | 2053 length=3; |
| 2056 errorCode=U_ZERO_ERROR; | 2054 errorCode=U_ZERO_ERROR; |
| 2057 u_strFromJavaModifiedUTF8WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0,
0xfffd, NULL, &errorCode); | 2055 u_strFromJavaModifiedUTF8WithSub(dest16, UPRV_LENGTHOF(dest16), &length, NUL
L, 0, 0xfffd, NULL, &errorCode); |
| 2058 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2056 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2059 log_err("u_strFromJavaModifiedUTF8WithSub(source=NULL, sourceLength=0) f
ailed\n"); | 2057 log_err("u_strFromJavaModifiedUTF8WithSub(source=NULL, sourceLength=0) f
ailed\n"); |
| 2060 } | 2058 } |
| 2061 | 2059 |
| 2062 /* u_strToXyz() */ | 2060 /* u_strToXyz() */ |
| 2063 | 2061 |
| 2064 dest8[0]=3; | 2062 dest8[0]=3; |
| 2065 length=3; | 2063 length=3; |
| 2066 errorCode=U_ZERO_ERROR; | 2064 errorCode=U_ZERO_ERROR; |
| 2067 u_strToUTF8(dest8, LENGTHOF(dest8), &length, NULL, 0, &errorCode); | 2065 u_strToUTF8(dest8, UPRV_LENGTHOF(dest8), &length, NULL, 0, &errorCode); |
| 2068 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { | 2066 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { |
| 2069 log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); | 2067 log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); |
| 2070 } | 2068 } |
| 2071 | 2069 |
| 2072 dest8[0]=3; | 2070 dest8[0]=3; |
| 2073 length=3; | 2071 length=3; |
| 2074 errorCode=U_ZERO_ERROR; | 2072 errorCode=U_ZERO_ERROR; |
| 2075 u_strToUTF8WithSub(dest8, LENGTHOF(dest8), &length, NULL, 0, 0xfffd, NULL, &
errorCode); | 2073 u_strToUTF8WithSub(dest8, UPRV_LENGTHOF(dest8), &length, NULL, 0, 0xfffd, NU
LL, &errorCode); |
| 2076 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { | 2074 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { |
| 2077 log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); | 2075 log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); |
| 2078 } | 2076 } |
| 2079 | 2077 |
| 2080 dest32[0]=3; | 2078 dest32[0]=3; |
| 2081 length=3; | 2079 length=3; |
| 2082 errorCode=U_ZERO_ERROR; | 2080 errorCode=U_ZERO_ERROR; |
| 2083 u_strToUTF32(dest32, LENGTHOF(dest32), &length, NULL, 0, &errorCode); | 2081 u_strToUTF32(dest32, UPRV_LENGTHOF(dest32), &length, NULL, 0, &errorCode); |
| 2084 if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { | 2082 if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { |
| 2085 log_err("u_strToUTF32(source=NULL, sourceLength=0) failed\n"); | 2083 log_err("u_strToUTF32(source=NULL, sourceLength=0) failed\n"); |
| 2086 } | 2084 } |
| 2087 | 2085 |
| 2088 dest32[0]=3; | 2086 dest32[0]=3; |
| 2089 length=3; | 2087 length=3; |
| 2090 errorCode=U_ZERO_ERROR; | 2088 errorCode=U_ZERO_ERROR; |
| 2091 u_strToUTF32WithSub(dest32, LENGTHOF(dest32), &length, NULL, 0, 0xfffd, NULL
, &errorCode); | 2089 u_strToUTF32WithSub(dest32, UPRV_LENGTHOF(dest32), &length, NULL, 0, 0xfffd,
NULL, &errorCode); |
| 2092 if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { | 2090 if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { |
| 2093 log_err("u_strToUTF32WithSub(source=NULL, sourceLength=0) failed\n"); | 2091 log_err("u_strToUTF32WithSub(source=NULL, sourceLength=0) failed\n"); |
| 2094 } | 2092 } |
| 2095 | 2093 |
| 2096 dest8[0]=3; | 2094 dest8[0]=3; |
| 2097 length=3; | 2095 length=3; |
| 2098 errorCode=U_ZERO_ERROR; | 2096 errorCode=U_ZERO_ERROR; |
| 2099 u_strToJavaModifiedUTF8(dest8, LENGTHOF(dest8), &length, NULL, 0, &errorCode
); | 2097 u_strToJavaModifiedUTF8(dest8, UPRV_LENGTHOF(dest8), &length, NULL, 0, &erro
rCode); |
| 2100 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { | 2098 if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { |
| 2101 log_err("u_strToJavaModifiedUTF8(source=NULL, sourceLength=0) failed\n")
; | 2099 log_err("u_strToJavaModifiedUTF8(source=NULL, sourceLength=0) failed\n")
; |
| 2102 } | 2100 } |
| 2103 | 2101 |
| 2104 #if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CON
VERSION && !UCONFIG_NO_LEGACY_CONVERSION) | 2102 #if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CON
VERSION && !UCONFIG_NO_LEGACY_CONVERSION) |
| 2105 | 2103 |
| 2106 dest16[0]=3; | 2104 dest16[0]=3; |
| 2107 length=3; | 2105 length=3; |
| 2108 errorCode=U_ZERO_ERROR; | 2106 errorCode=U_ZERO_ERROR; |
| 2109 u_strFromWCS(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); | 2107 u_strFromWCS(dest16, UPRV_LENGTHOF(dest16), &length, NULL, 0, &errorCode); |
| 2110 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { | 2108 if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { |
| 2111 log_err("u_strFromWCS(source=NULL, sourceLength=0) failed\n"); | 2109 log_err("u_strFromWCS(source=NULL, sourceLength=0) failed\n"); |
| 2112 } | 2110 } |
| 2113 | 2111 |
| 2114 destW[0]=3; | 2112 destW[0]=3; |
| 2115 length=3; | 2113 length=3; |
| 2116 errorCode=U_ZERO_ERROR; | 2114 errorCode=U_ZERO_ERROR; |
| 2117 u_strToWCS(destW, LENGTHOF(destW), &length, NULL, 0, &errorCode); | 2115 u_strToWCS(destW, UPRV_LENGTHOF(destW), &length, NULL, 0, &errorCode); |
| 2118 if(errorCode!=U_ZERO_ERROR || length!=0 || destW[0]!=0 || destW[1]!=3) { | 2116 if(errorCode!=U_ZERO_ERROR || length!=0 || destW[0]!=0 || destW[1]!=3) { |
| 2119 log_err("u_strToWCS(source=NULL, sourceLength=0) failed\n"); | 2117 log_err("u_strToWCS(source=NULL, sourceLength=0) failed\n"); |
| 2120 } | 2118 } |
| 2121 | 2119 |
| 2122 #endif | 2120 #endif |
| 2123 } | 2121 } |
| OLD | NEW |