| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/** |
| 4 |
* Copyright (c) 1999-2012, International Business Machines Corporation and |
| 5 |
* others. All Rights Reserved. |
| 6 |
* |
| 7 |
* Test for source/i18n/collunsafe.h |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include "unicode/ucol.h" |
| 12 |
#include "unicode/uniset.h" |
| 13 |
#include "unicode/coll.h" |
| 14 |
#include "collation.h" |
| 15 |
|
| 16 |
#include "collunsafe.h" |
| 17 |
|
| 18 |
using icu::Collator; |
| 19 |
using icu::Locale; |
| 20 |
using icu::UnicodeSet; |
| 21 |
|
| 22 |
int main(int argc, const char *argv[]) { |
| 23 |
puts("verify"); |
| 24 |
UErrorCode errorCode = U_ZERO_ERROR; |
| 25 |
#if defined (COLLUNSAFE_PATTERN) |
| 26 |
puts("verify pattern"); |
| 27 |
const UnicodeString unsafeBackwardPattern(false, collunsafe_pattern, collunsafe_len); |
| 28 |
fprintf(stderr, "\n -- pat '%c%c%c%c%c'\n", |
| 29 |
collunsafe_pattern[0], |
| 30 |
collunsafe_pattern[1], |
| 31 |
collunsafe_pattern[2], |
| 32 |
collunsafe_pattern[3], |
| 33 |
collunsafe_pattern[4]); |
| 34 |
if(U_SUCCESS(errorCode)) { |
| 35 |
UnicodeSet us(unsafeBackwardPattern, errorCode); |
| 36 |
fprintf(stderr, "\n%s:%d: err creating set %s\n", __FILE__, __LINE__, u_errorName(errorCode)); |
| 37 |
} |
| 38 |
#endif |
| 39 |
|
| 40 |
#if defined (COLLUNSAFE_RANGE) |
| 41 |
{ |
| 42 |
puts("verify range"); |
| 43 |
UnicodeSet u; |
| 44 |
for(int32_t i=0;i<unsafe_rangeCount*2;i+=2) { |
| 45 |
u.add(unsafe_ranges[i+0],unsafe_ranges[i+1]); |
| 46 |
} |
| 47 |
printf("Finished with %d ranges\n", u.getRangeCount()); |
| 48 |
} |
| 49 |
#endif |
| 50 |
|
| 51 |
#if defined (COLLUNSAFE_SERIALIZE) |
| 52 |
{ |
| 53 |
puts("verify serialize"); |
| 54 |
UnicodeSet u(unsafe_serializedData, unsafe_serializedCount, UnicodeSet::kSerialized, errorCode); |
| 55 |
fprintf(stderr, "\n%s:%d: err creating set %s\n", __FILE__, __LINE__, u_errorName(errorCode)); |
| 56 |
printf("Finished deserialize with %d ranges\n", u.getRangeCount()); |
| 57 |
} |
| 58 |
#endif |
| 59 |
// if(tailoring.unsafeBackwardSet == nullptr) { |
| 60 |
// errorCode = U_MEMORY_ALLOCATION_ERROR; |
| 61 |
// fprintf(stderr, "\n%s:%d: err %s\n", __FILE__, __LINE__, u_errorName(errorCode)); |
| 62 |
// } |
| 63 |
puts("verify col UCA"); |
| 64 |
if(U_SUCCESS(errorCode)) { |
| 65 |
Collator *col = Collator::createInstance(Locale::getEnglish(), errorCode); |
| 66 |
fprintf(stderr, "\n%s:%d: err %s creating collator\n", __FILE__, __LINE__, u_errorName(errorCode)); |
| 67 |
} |
| 68 |
|
| 69 |
if(U_FAILURE(errorCode)) { |
| 70 |
return 1; |
| 71 |
} else { |
| 72 |
return 0; |
| 73 |
} |
| 74 |
} |