• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4  * Copyright (c) 1997-2009,2014, International Business Machines
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*/
61     UCOL_GREATER    /* v < w per cldrbug 6615 */
62 };
63 
64 
65 
addFinnishCollTest(TestNode ** root)66 void addFinnishCollTest(TestNode** root)
67 {
68 
69 
70     addTest(root, &TestPrimary, "tscoll/cfintst/TestPrimary");
71     addTest(root, &TestTertiary, "tscoll/cfintst/TestTertiary");
72 
73 
74 
75 }
76 
77 
TestTertiary()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)){
85         log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
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 
TestPrimary()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)){
103         log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
104     }
105     log_verbose("Testing Finnish Collation with Primary strength\n");
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 */
115