164339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// Copyright (C) 2016 and later: Unicode, Inc. and others.
264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************************
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CESTST.C
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*        Name                     Description
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*     Madhu Katragadda            Ported for C API
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************************/
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * CollationSpanishTest is a third level test class.  This tests the locale
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * specific primary, secondary and tertiary rules.  For example, the ignorable
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * character '-' in string "black-bird".  The en_US locale uses the default
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * collation rules as its sorting sequence.
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucol.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cestst.h"
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ccolltst.h"
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "callcoll.h"
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "string.h"
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UCollator *myCollation;
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testSourceCases[][MAX_TOKEN_LEN] = {
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testTargetCases[][MAX_TOKEN_LEN] = {
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UCollationResult results[] = {
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_GREATER,
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test primary > 5*/
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_EQUAL,
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_LESS,
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCOL_EQUAL
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addSpanishCollTest(TestNode** root)
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestPrimary, "tscoll/cestst/TestPrimary");
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestTertiary, "tscoll/cestst/TestTertiary");
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestTertiary( )
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation = ucol_open("es_ES", &status);
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
9485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Testing Spanish Collation with Tertiary strength\n");
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(myCollation, UCOL_TERTIARY);
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 0; i < 5 ; i++)
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(myCollation);
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestPrimary()
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation = ucol_open("es_ES", &status);
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
11385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Testing Spanish Collation with Primary strength\n");
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(myCollation, UCOL_PRIMARY);
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 5; i < 9; i++)
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(myCollation);
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */
126