Home | History | Annotate | Download | only in cintltst
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /********************************************************************
      4  * COPYRIGHT:
      5  * Copyright (c) 1997-2009, International Business Machines Corporation and
      6  * others. All Rights Reserved.
      7  ********************************************************************/
      8 /********************************************************************************
      9 *
     10 * File CESTST.C
     11 *
     12 * Modification History:
     13 *        Name                     Description
     14 *     Madhu Katragadda            Ported for C API
     15 *********************************************************************************/
     16 /**
     17  * CollationSpanishTest 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 "cestst.h"
     33 #include "ccolltst.h"
     34 #include "callcoll.h"
     35 #include "unicode/ustring.h"
     36 #include "string.h"
     37 
     38 static UCollator *myCollation;
     39 const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
     40     {0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
     41     {0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
     42     {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
     43     {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     44     {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
     45     {0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
     46     {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     47     {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
     48     {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
     49 };
     50 
     51 const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
     52     {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
     53     {0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
     54     {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
     55     {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     56     {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     57     {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
     58     {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     59     {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
     60     {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
     61 };
     62 
     63 const static UCollationResult results[] = {
     64     UCOL_LESS,
     65     UCOL_LESS,
     66     UCOL_GREATER,
     67     UCOL_LESS,
     68     UCOL_LESS,
     69     /* test primary > 5*/
     70     UCOL_LESS,
     71     UCOL_EQUAL,
     72     UCOL_LESS,
     73     UCOL_EQUAL
     74 };
     75 
     76 
     77 void addSpanishCollTest(TestNode** root)
     78 {
     79 
     80 
     81     addTest(root, &TestPrimary, "tscoll/cestst/TestPrimary");
     82     addTest(root, &TestTertiary, "tscoll/cestst/TestTertiary");
     83 
     84 }
     85 
     86 
     87 static void TestTertiary( )
     88 {
     89 
     90     int32_t i;
     91     UErrorCode status = U_ZERO_ERROR;
     92     myCollation = ucol_open("es_ES", &status);
     93     if(U_FAILURE(status)){
     94         log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
     95         return;
     96     }
     97     log_verbose("Testing Spanish Collation with Tertiary strength\n");
     98     ucol_setStrength(myCollation, UCOL_TERTIARY);
     99     for (i = 0; i < 5 ; i++)
    100     {
    101         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
    102     }
    103     ucol_close(myCollation);
    104 }
    105 
    106 static void TestPrimary()
    107 {
    108 
    109     int32_t i;
    110     UErrorCode status = U_ZERO_ERROR;
    111     myCollation = ucol_open("es_ES", &status);
    112     if(U_FAILURE(status)){
    113         log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
    114         return;
    115     }
    116     log_verbose("Testing Spanish Collation with Primary strength\n");
    117     ucol_setStrength(myCollation, UCOL_PRIMARY);
    118     for (i = 5; i < 9; i++)
    119     {
    120         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
    121     }
    122     ucol_close(myCollation);
    123 }
    124 
    125 #endif /* #if !UCONFIG_NO_COLLATION */
    126