Fredrik Roubert | 0596fae | 2017-04-18 21:34:02 +0200 | [diff] [blame] | 1 | // © 2016 and later: Unicode, Inc. and others. |
Fredrik Roubert | 64339d3 | 2016-10-21 19:43:16 +0200 | [diff] [blame] | 2 | // License & terms of use: http://www.unicode.org/copyright.html |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 3 | /******************************************************************** |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 4 | * Copyright (c) 1997-2009,2014, International Business Machines |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 5 | * Corporation and others. All Rights Reserved. |
| 6 | ******************************************************************** |
| 7 | * |
| 8 | * File CFINTST.C |
| 9 | * |
| 10 | * Modification History: |
| 11 | * Name Description |
| 12 | * Madhu Katragadda Ported for C API |
| 13 | ******************************************************************** |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * CollationFinnishTest is a third level test class. This tests the locale |
| 18 | * specific primary, secondary and tertiary rules. For example, the ignorable |
| 19 | * character '-' in string "black-bird". The en_US locale uses the default |
| 20 | * collation rules as its sorting sequence. |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | |
| 25 | #include "unicode/utypes.h" |
| 26 | |
| 27 | #if !UCONFIG_NO_COLLATION |
| 28 | |
| 29 | #include "unicode/ucol.h" |
| 30 | #include "unicode/uloc.h" |
| 31 | #include "cintltst.h" |
| 32 | #include "ccolltst.h" |
| 33 | #include "callcoll.h" |
| 34 | #include "cfintst.h" |
| 35 | #include "unicode/ustring.h" |
| 36 | #include "string.h" |
| 37 | |
| 38 | static UCollator *myCollation; |
| 39 | const static UChar testSourceCases[][MAX_TOKEN_LEN] = { |
| 40 | {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, |
| 41 | {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, |
| 42 | {0x0061/*'a'*/, 0x00FC, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000}, |
| 43 | {0x004c/*'L'*/, 0x00E5, 0x0076/*'v'*/, 0x0069/*'i'*/, 0x0000}, |
| 44 | {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000} |
| 45 | }; |
| 46 | |
| 47 | const static UChar testTargetCases[][MAX_TOKEN_LEN] = { |
| 48 | {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, |
| 49 | {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0079/*'y'*/, 0x0000}, |
| 50 | {0x0061/*'a'*/, 0x0078/*'x'*/, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000}, |
| 51 | {0x004c/*'L'*/, 0x00E4, 0x0077/*'w'*/, 0x0065/*'e'*/, 0x0000}, |
| 52 | {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000} |
| 53 | }; |
| 54 | |
| 55 | const static UCollationResult results[] = { |
| 56 | UCOL_GREATER, |
| 57 | UCOL_LESS, |
| 58 | UCOL_GREATER, |
| 59 | UCOL_LESS, |
| 60 | /* test primary > 4*/ |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 61 | UCOL_GREATER /* v < w per cldrbug 6615 */ |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | |
| 65 | |
| 66 | void addFinnishCollTest(TestNode** root) |
| 67 | { |
| 68 | |
| 69 | |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 70 | addTest(root, &TestPrimary, "tscoll/cfintst/TestPrimary"); |
| 71 | addTest(root, &TestTertiary, "tscoll/cfintst/TestTertiary"); |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 72 | |
| 73 | |
| 74 | |
| 75 | } |
| 76 | |
| 77 | |
| 78 | static void TestTertiary( ) |
| 79 | { |
| 80 | |
| 81 | int32_t i; |
| 82 | UErrorCode status = U_ZERO_ERROR; |
| 83 | myCollation = ucol_open("fi_FI@collation=standard", &status); |
| 84 | if(U_FAILURE(status)){ |
Claire Ho | 85bf2e2 | 2009-11-24 14:23:02 -0800 | [diff] [blame] | 85 | log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 86 | } |
| 87 | log_verbose("Testing Finnish Collation with Tertiary strength\n"); |
| 88 | ucol_setStrength(myCollation, UCOL_TERTIARY); |
| 89 | for (i = 0; i < 4 ; i++) |
| 90 | { |
| 91 | doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); |
| 92 | } |
| 93 | ucol_close(myCollation); |
| 94 | } |
| 95 | |
| 96 | static void TestPrimary() |
| 97 | { |
| 98 | |
| 99 | int32_t i; |
| 100 | UErrorCode status = U_ZERO_ERROR; |
| 101 | myCollation = ucol_open("fi_FI@collation=standard", &status); |
| 102 | if(U_FAILURE(status)){ |
Claire Ho | 85bf2e2 | 2009-11-24 14:23:02 -0800 | [diff] [blame] | 103 | log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 104 | } |
ccornelius | f9878a2 | 2014-11-20 18:09:39 -0800 | [diff] [blame] | 105 | log_verbose("Testing Finnish Collation with Primary strength\n"); |
Jean-Baptiste Queru | ac04d0b | 2009-07-17 17:11:19 -0700 | [diff] [blame] | 106 | ucol_setStrength(myCollation, UCOL_PRIMARY); |
| 107 | for (i = 4; i < 5; i++) |
| 108 | { |
| 109 | doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); |
| 110 | } |
| 111 | ucol_close(myCollation); |
| 112 | } |
| 113 | |
| 114 | #endif /* #if !UCONFIG_NO_COLLATION */ |