blob: d81d90c6396b6e8bd88acbca875d8583fe2dd084 [file] [log] [blame]
Fredrik Roubert0596fae2017-04-18 21:34:02 +02001// © 2016 and later: Unicode, Inc. and others.
Fredrik Roubert64339d32016-10-21 19:43:16 +02002// License & terms of use: http://www.unicode.org/copyright.html
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -07003/********************************************************************
ccorneliusf9878a22014-11-20 18:09:39 -08004 * Copyright (c) 1997-2009,2014, International Business Machines
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -07005 * 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
38static UCollator *myCollation;
39const 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
47const 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
55const static UCollationResult results[] = {
56 UCOL_GREATER,
57 UCOL_LESS,
58 UCOL_GREATER,
59 UCOL_LESS,
60 /* test primary > 4*/
ccorneliusf9878a22014-11-20 18:09:39 -080061 UCOL_GREATER /* v < w per cldrbug 6615 */
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070062};
63
64
65
66void addFinnishCollTest(TestNode** root)
67{
68
69
ccorneliusf9878a22014-11-20 18:09:39 -080070 addTest(root, &TestPrimary, "tscoll/cfintst/TestPrimary");
71 addTest(root, &TestTertiary, "tscoll/cfintst/TestTertiary");
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070072
73
74
75}
76
77
78static 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 Ho85bf2e22009-11-24 14:23:02 -080085 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070086 }
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
96static 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 Ho85bf2e22009-11-24 14:23:02 -0800103 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -0700104 }
ccorneliusf9878a22014-11-20 18:09:39 -0800105 log_verbose("Testing Finnish Collation with Primary strength\n");
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -0700106 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 */