1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************************
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CDETST.C
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*        Name                     Description
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*     Madhu Katragadda            Ported for C API
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************************/
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * CollationGermanTest is a third level test class.  This tests the locale
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * specific primary, secondary and tertiary rules.  For example, the ignorable
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * character '-' in string "black-bird".  The en_US locale uses the default
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * collation rules as its sorting sequence.
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucol.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cdetst.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ccolltst.h"
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "callcoll.h"
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "string.h"
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UCollator *myCollation;
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testSourceCases[][MAX_TOKEN_LEN] =
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0047/*'G'*/, 0x0072/*'r'*/, 0x00F6, 0x00DF, 0x0065/*'e'*/, 0x0000},
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},                    /*doubt in primary here        */
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},                    /*doubt in primary here*/
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000},
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},                    /*doubt in primary here*/
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000}
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testTargetCases[][MAX_TOKEN_LEN] =
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0047/*'G'*/, 0x0072/*'r'*/, 0x006f/*'o'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0069/*'i'*/, 0x0073/*'s'*/, 0x0074/*'t'*/, 0x0000},
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x006f/*'o'*/, 0x006e/*'n'*/, 0x0000},
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0064/*'d'*/, 0x0000},
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0066/*'f'*/, 0x0075/*'u'*/, 0x0000},
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0041/*'A'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},                    /*doubt in primary here*/
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},            /*doubt in primary here*/
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000},
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},        /*doubt in primary here*/
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000}
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UCollationResult results[][2] =
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      /*  Primary*/            /*    Tertiary*/
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_LESS,        UCOL_LESS },        /*should be UCOL_GREATER for primary*/
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_LESS },
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_GREATER,        UCOL_GREATER },
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_GREATER,        UCOL_GREATER },
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_GREATER,        UCOL_GREATER },
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_LESS },
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_EQUAL },    /*should be UCOL_GREATER for primary*/
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_LESS,        UCOL_LESS },    /*should be UCOL_GREATER for primary*/
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_GREATER },
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_EQUAL },
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_LESS,        UCOL_LESS },   /*should be UCOL_GREATER for primary*/
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { UCOL_EQUAL,        UCOL_GREATER }
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addGermanCollTest(TestNode** root)
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestTertiary, "tscoll/cdetst/TestTertiary");
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestPrimary, "tscoll/cdetst/TestPrimary");
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestTertiary( )
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation = ucol_open("de_DE", &status);
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
10785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Testing German Collation with Tertiary strength\n");
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(myCollation, UCOL_TERTIARY);
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 0; i < 12 ; i++)
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][1]);
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(myCollation);
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestPrimary()
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation = ucol_open("de_DE", &status);
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
12785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Testing German Collation with primary strength\n");
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(myCollation, UCOL_PRIMARY);
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 0; i < 12 ; i++)
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][0]);
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(myCollation);
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */
140