1f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/******************************************************************** 2f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * COPYRIGHT: 3f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Copyright (c) 1997-2011, International Business Machines Corporation and 4f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * others. All Rights Reserved. 5f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ********************************************************************/ 6f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/******************************************************************************** 7f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* 8f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* File CITERTST.C 9f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* 10f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Modification History: 11f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Date Name Description 12f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Madhu Katragadda Ported for C API 13f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* 02/19/01 synwee Modified test case for new collation iterator 14f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*********************************************************************************/ 15f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/* 16f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Collation Iterator tests. 17f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * (Let me reiterate my position...) 18f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 19f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 20f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/utypes.h" 21f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 22f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#if !UCONFIG_NO_COLLATION 23f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 24f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/ucol.h" 25f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/ucoleitr.h" 26f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/uloc.h" 27f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/uchar.h" 28f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/ustring.h" 29f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "unicode/putil.h" 30f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "callcoll.h" 31f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "cmemory.h" 32f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "cintltst.h" 33f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "citertst.h" 34f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "ccolltst.h" 35f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "filestrm.h" 36f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "cstring.h" 37f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "ucol_imp.h" 38f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "ucol_tok.h" 39f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include "uparse.h" 40f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#include <stdio.h> 41f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 42f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)extern uint8_t ucol_uprv_getCaseBits(const UChar *, uint32_t, UErrorCode *); 43f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 44f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)void addCollIterTest(TestNode** root) 45f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 46f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestPrevious, "tscoll/citertst/TestPrevious"); 47f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestOffset, "tscoll/citertst/TestOffset"); 48f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestSetText, "tscoll/citertst/TestSetText"); 49f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestMaxExpansion, "tscoll/citertst/TestMaxExpansion"); 50f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestUnicodeChar, "tscoll/citertst/TestUnicodeChar"); 51f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestNormalizedUnicodeChar, 52f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "tscoll/citertst/TestNormalizedUnicodeChar"); 53f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestNormalization, "tscoll/citertst/TestNormalization"); 54f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestBug672, "tscoll/citertst/TestBug672"); 55f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestBug672Normalize, "tscoll/citertst/TestBug672Normalize"); 56f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestSmallBuffer, "tscoll/citertst/TestSmallBuffer"); 57f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestCEs, "tscoll/citertst/TestCEs"); 58f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestDiscontiguos, "tscoll/citertst/TestDiscontiguos"); 59f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestCEBufferOverflow, "tscoll/citertst/TestCEBufferOverflow"); 60f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestCEValidity, "tscoll/citertst/TestCEValidity"); 61f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestSortKeyValidity, "tscoll/citertst/TestSortKeyValidity"); 62f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) addTest(root, &TestSearchCollatorElements, "tscoll/citertst/TestSearchCollatorElements"); 63f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 64f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 65f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/* The locales we support */ 66f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 67f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static const char * LOCALES[] = {"en_AU", "en_BE", "en_CA"}; 68f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 69f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestBug672() { 70f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 71f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar pattern[20]; 72f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar text[50]; 73f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int i; 74f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int result[3][3]; 75f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 76f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(pattern, "resume"); 77f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(text, "Time to resume updating my resume."); 78f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 79f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (i = 0; i < 3; ++ i) { 80f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll = ucol_open(LOCALES[i], &status); 81f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *pitr = ucol_openElements(coll, pattern, -1, 82f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) &status); 83f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *titer = ucol_openElements(coll, text, -1, 84f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) &status); 85f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 86f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of either the collator or the collation iterator :%s\n", 87f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 88f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 89f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 90f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 91f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("locale tested %s\n", LOCALES[i]); 92f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 93f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ucol_next(pitr, &status) != UCOL_NULLORDER && 94f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U_SUCCESS(status)) { 95f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 96f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 97f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: reversing collation iterator :%s\n", 98f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 99f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 100f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 101f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_reset(pitr); 102f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 103f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(titer, u_strlen(pattern), &status); 104f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 105f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: setting offset in collator :%s\n", 106f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 107f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 108f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 109f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][0] = ucol_getOffset(titer); 110f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Text iterator set to offset %d\n", result[i][0]); 111f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 112f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Use previous() */ 113f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_previous(titer, &status); 114f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][1] = ucol_getOffset(titer); 115f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Current offset %d after previous\n", result[i][1]); 116f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 117f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Add one to index */ 118f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Adding one to current offset...\n"); 119f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(titer, ucol_getOffset(titer) + 1, &status); 120f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 121f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: setting offset in collator :%s\n", 122f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 123f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 124f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 125f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][2] = ucol_getOffset(titer); 126f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Current offset in text = %d\n", result[i][2]); 127f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(pitr); 128f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(titer); 129f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 130f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 131f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 132f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (uprv_memcmp(result[0], result[1], 3) != 0 || 133f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcmp(result[1], result[2], 3) != 0) { 134f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Different locales have different offsets at the same character\n"); 135f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 136f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 137f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 138f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 139f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 140f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/* Running this test with normalization enabled showed up a bug in the incremental 141f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) normalization code. */ 142f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestBug672Normalize() { 143f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 144f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar pattern[20]; 145f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar text[50]; 146f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int i; 147f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int result[3][3]; 148f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 149f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(pattern, "resume"); 150f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(text, "Time to resume updating my resume."); 151f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 152f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (i = 0; i < 3; ++ i) { 153f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll = ucol_open(LOCALES[i], &status); 154f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *pitr = NULL; 155f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *titer = NULL; 156f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 157f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); 158f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 159f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) pitr = ucol_openElements(coll, pattern, -1, &status); 160f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) titer = ucol_openElements(coll, text, -1, &status); 161f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 162f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of either the collator or the collation iterator :%s\n", 163f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 164f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 165f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 166f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 167f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("locale tested %s\n", LOCALES[i]); 168f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 169f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ucol_next(pitr, &status) != UCOL_NULLORDER && 170f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U_SUCCESS(status)) { 171f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 172f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 173f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: reversing collation iterator :%s\n", 174f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 175f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 176f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 177f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_reset(pitr); 178f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 179f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(titer, u_strlen(pattern), &status); 180f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 181f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: setting offset in collator :%s\n", 182f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 183f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 184f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 185f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][0] = ucol_getOffset(titer); 186f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Text iterator set to offset %d\n", result[i][0]); 187f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 188f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Use previous() */ 189f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_previous(titer, &status); 190f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][1] = ucol_getOffset(titer); 191f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Current offset %d after previous\n", result[i][1]); 192f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 193f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Add one to index */ 194f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Adding one to current offset...\n"); 195f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(titer, ucol_getOffset(titer) + 1, &status); 196f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 197f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: setting offset in collator :%s\n", 198f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 199f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 200f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 201f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result[i][2] = ucol_getOffset(titer); 202f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Current offset in text = %d\n", result[i][2]); 203f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(pitr); 204f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(titer); 205f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 206f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 207f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 208f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (uprv_memcmp(result[0], result[1], 3) != 0 || 209f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcmp(result[1], result[2], 3) != 0) { 210f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Different locales have different offsets at the same character\n"); 211f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 212f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 213f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 214f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 215f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 216f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 217f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 218f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for CollationElementIterator previous and next for the whole set of 219f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * unicode characters. 220f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 221f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestUnicodeChar() 222f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 223f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar source[0x100]; 224f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *en_us; 225f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 226f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 227f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar codepoint; 228f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 229f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *test; 230f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) en_us = ucol_open("en_US", &status); 231f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)){ 232f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of collation data using ucol_open()\n %s\n", 233f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 234f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 235f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 236f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 237f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (codepoint = 1; codepoint < 0xFFFE;) 238f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 239f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test = source; 240f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 241f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (codepoint % 0xFF != 0) 242f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 243f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(codepoint)) 244f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(test ++) = codepoint; 245f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoint ++; 246f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 247f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 248f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(codepoint)) 249f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(test ++) = codepoint; 250f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 251f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (codepoint != 0xFFFF) 252f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoint ++; 253f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 254f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *test = 0; 255f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(en_us, source, u_strlen(source), &status); 256f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 257f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 258f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 259f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 260f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 261f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 262f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* A basic test to see if it's working at all */ 263f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("codepoint testing %x\n", codepoint); 264f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 265f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 266f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 267f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* null termination test */ 268f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(en_us, source, -1, &status); 269f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 270f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 271f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 272f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 273f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 274f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 275f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* A basic test to see if it's working at all */ 276f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 277f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 278f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 279f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 280f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 281f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 282f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 283f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 284f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for CollationElementIterator previous and next for the whole set of 285f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * unicode characters with normalization on. 286f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 287f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestNormalizedUnicodeChar() 288f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 289f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar source[0x100]; 290f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *th_th; 291f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 292f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 293f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar codepoint; 294f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 295f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *test; 296f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* thai should have normalization on */ 297f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) th_th = ucol_open("th_TH", &status); 298f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)){ 299f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of thai collation using ucol_open()\n %s\n", 300f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 301f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 302f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 303f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 304f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (codepoint = 1; codepoint < 0xFFFE;) 305f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 306f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test = source; 307f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 308f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (codepoint % 0xFF != 0) 309f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 310f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(codepoint)) 311f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(test ++) = codepoint; 312f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoint ++; 313f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 314f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 315f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(codepoint)) 316f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(test ++) = codepoint; 317f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 318f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (codepoint != 0xFFFF) 319f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoint ++; 320f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 321f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *test = 0; 322f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(th_th, source, u_strlen(source), &status); 323f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 324f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 325f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 326f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(th_th); 327f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 328f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 329f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 330f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 331f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 332f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 333f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(th_th, source, -1, &status); 334f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 335f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 336f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 337f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(th_th); 338f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 339f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 340f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 341f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 342f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 343f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 344f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 345f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(th_th); 346f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 347f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 348f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 349f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Test the incremental normalization 350f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 351f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestNormalization() 352f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 353f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 354f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *str = 355f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "&a < \\u0300\\u0315 < A\\u0300\\u0315 < \\u0316\\u0315B < \\u0316\\u0300\\u0315"; 356f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll; 357f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar rule[50]; 358f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int rulelen = u_unescape(str, rule, 50); 359f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 360f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *testdata[] = 361f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) {"\\u1ED9", "o\\u0323\\u0302", 362f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "\\u0300\\u0315", "\\u0315\\u0300", 363f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "A\\u0300\\u0315B", "A\\u0315\\u0300B", 364f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "A\\u0316\\u0315B", "A\\u0315\\u0316B", 365f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "\\u0316\\u0300\\u0315", "\\u0315\\u0300\\u0316", 366f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "A\\u0316\\u0300\\u0315B", "A\\u0315\\u0300\\u0316B", 367f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "\\u0316\\u0315\\u0300", "A\\u0316\\u0315\\u0300B"}; 368f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t srclen; 369f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar source[10]; 370f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 371f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 372f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_openRules(rule, rulelen, UCOL_ON, UCOL_TERTIARY, NULL, &status); 373f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); 374f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)){ 375f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of collator using ucol_openRules()\n %s\n", 376f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 377f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 378f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 379f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 380f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) srclen = u_unescape(testdata[0], source, 10); 381f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, source, srclen, &status); 382f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 383f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 384f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 385f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) srclen = u_unescape(testdata[1], source, 10); 386f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, source, srclen, &status); 387f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 388f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 389f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 390f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < 12) { 391f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) srclen = u_unescape(testdata[count], source, 10); 392f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, source, srclen, &status); 393f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 394f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)){ 395f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collator element iterator\n %s\n", 396f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 397f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 398f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 399f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 400f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 401f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 402f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, source, -1, &status); 403f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 404f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)){ 405f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collator element iterator\n %s\n", 406f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 407f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 408f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 409f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 410f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 411f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 412f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 413f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 414f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 415f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 416f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 417f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for CollationElementIterator.previous() 418f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * 419f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * @bug 4108758 - Make sure it works with contracting characters 420f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * 421f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 422f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestPrevious() 423f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 424f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll=NULL; 425f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar rule[50]; 426f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *source; 427f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *c1, *c2, *c3; 428f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 429f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 430f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test1[50]; 431f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test2[50]; 432f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 433f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test1, "What subset of all possible test cases?"); 434f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test2, "has the highest probability of detecting"); 435f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open("en_US", &status); 436f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 437f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(coll, test1, u_strlen(test1), &status); 438f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("English locale testing back and forth\n"); 439f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 440f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 441f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 442f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 443f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 444f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 445f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* A basic test to see if it's working at all */ 446f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 447f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 448f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 449f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 450f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Test with a contracting character sequence */ 451f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(rule, "&a,A < b,B < c,C, d,D < z,Z < ch,cH,Ch,CH"); 452f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status); 453f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 454f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Contraction rule testing back and forth with no normalization\n"); 455f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 456f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (c1 == NULL || U_FAILURE(status)) 457f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 458f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Couldn't create a RuleBasedCollator with a contracting sequence\n %s\n", 459f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 460f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 461f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 462f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source=(UChar*)malloc(sizeof(UChar) * 20); 463f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(source, "abchdcba"); 464f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(c1, source, u_strlen(source), &status); 465f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 466f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 467f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 468f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 469f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 470f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 471f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 472f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(c1); 473f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 474f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Test with an expanding character sequence */ 475f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(rule, "&a < b < c/abd < d"); 476f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c2 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status); 477f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Expansion rule testing back and forth with no normalization\n"); 478f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (c2 == NULL || U_FAILURE(status)) 479f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 480f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n", 481f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 482f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 483f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 484f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(source, "abcd"); 485f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(c2, source, u_strlen(source), &status); 486f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 487f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 488f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 489f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 490f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 491f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 492f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 493f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(c2); 494f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Now try both */ 495f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(rule, "&a < b < c/aba < d < z < ch"); 496f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c3 = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH,NULL, &status); 497f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Expansion/contraction rule testing back and forth with no normalization\n"); 498f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 499f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (c3 == NULL || U_FAILURE(status)) 500f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 501f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n", 502f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 503f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 504f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 505f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(source, "abcdbchdc"); 506f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(c3, source, u_strlen(source), &status); 507f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 508f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 509f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 510f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 511f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 512f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 513f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 514f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(c3); 515f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[0] = 0x0e41; 516f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[1] = 0x0e02; 517f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[2] = 0x0e41; 518f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[3] = 0x0e02; 519f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[4] = 0x0e27; 520f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[5] = 0x61; 521f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[6] = 0x62; 522f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[7] = 0x63; 523f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[8] = 0; 524f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 525f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open("th_TH", &status); 526f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Thai locale testing back and forth with normalization\n"); 527f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(coll, source, u_strlen(source), &status); 528f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 529f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 530f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 531f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 532f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 533f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 534f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 535f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 536f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 537f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* prev test */ 538f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[0] = 0x0061; 539f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[1] = 0x30CF; 540f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[2] = 0x3099; 541f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[3] = 0x30FC; 542f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) source[4] = 0; 543f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 544f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open("ja_JP", &status); 545f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Japanese locale testing back and forth with normalization\n"); 546f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter=ucol_openElements(coll, source, u_strlen(source), &status); 547f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 548f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 549f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 550f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 551f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 552f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 553f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 554f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 555f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 556f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) free(source); 557f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 558f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 559f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 560f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for getOffset() and setOffset() 561f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 562f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestOffset() 563f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 564f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status= U_ZERO_ERROR; 565f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *en_us=NULL; 566f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter, *pristine; 567f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t offset; 568f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) OrderAndOffset *orders; 569f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t orderLength=0; 570f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 571f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test1[50]; 572f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test2[50]; 573f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 574f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test1, "What subset of all possible test cases?"); 575f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test2, "has the highest probability of detecting"); 576f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) en_us = ucol_open("en_US", &status); 577f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing getOffset and setOffset for collations\n"); 578f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(en_us, test1, u_strlen(test1), &status); 579f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 580f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 581f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 582f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 583f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 584f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 585f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 586f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing boundaries */ 587f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(iter, 0, &status); 588f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_previous(iter, &status) != UCOL_NULLORDER) { 589f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error: After setting offset to 0, we should be at the end " 590f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "of the backwards iteration"); 591f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 592f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(iter, u_strlen(test1), &status); 593f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_next(iter, &status) != UCOL_NULLORDER) { 594f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error: After setting offset to end of the string, we should " 595f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "be at the end of the backwards iteration"); 596f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 597f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 598f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Run all the way through the iterator, then get the offset */ 599f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 600f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) orders = getOrders(iter, &orderLength); 601f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 602f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) offset = ucol_getOffset(iter); 603f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 604f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (offset != u_strlen(test1)) 605f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 606f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("offset at end != length %d vs %d\n", offset, 607f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_strlen(test1) ); 608f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 609f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 610f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Now set the offset back to the beginning and see if it works */ 611f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) pristine=ucol_openElements(en_us, test1, u_strlen(test1), &status); 612f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 613f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 614f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 615f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 616f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 617f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 618f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) status = U_ZERO_ERROR; 619f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 620f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(iter, 0, &status); 621f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) 622f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 623f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("setOffset failed. %s\n", myErrorName(status)); 624f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 625f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) else 626f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 627f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) assertEqual(iter, pristine); 628f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 629f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 630f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(pristine); 631f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 632f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) free(orders); 633f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 634f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing offsets in normalization buffer */ 635f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test1[0] = 0x61; 636f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test1[1] = 0x300; 637f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test1[2] = 0x316; 638f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test1[3] = 0x62; 639f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test1[4] = 0; 640f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setAttribute(en_us, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); 641f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(en_us, test1, 4, &status); 642f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 643f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", 644f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 645f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 646f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 647f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 648f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 649f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count = 0; 650f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ucol_next(iter, &status) != UCOL_NULLORDER && 651f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U_SUCCESS(status)) { 652f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) switch (count) { 653f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) case 0: 654f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 1) { 655f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 1\n"); 656f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 657f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 658f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) case 3: 659f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 4) { 660f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 4\n"); 661f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 662f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 663f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) default: 664f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 3) { 665f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 3\n"); 666f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 667f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 668f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 669f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 670f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 671f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_reset(iter); 672f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count = 0; 673f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ucol_previous(iter, &status) != UCOL_NULLORDER && 674f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U_SUCCESS(status)) { 675f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) switch (count) { 676f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) case 0: 677f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) case 1: 678f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 3) { 679f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 3\n"); 680f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 681f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 682f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) case 2: 683f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 1) { 684f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 1\n"); 685f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 686f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 687f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) default: 688f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_getOffset(iter) != 0) { 689f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: Offset of iteration should be 0\n"); 690f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 691f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 692f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 693f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 694f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 695f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 696f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in iterating collation elements %s\n", 697f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 698f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 699f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 700f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 701f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 702f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 703f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 704f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 705f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for setText() 706f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 707f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestSetText() 708f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 709f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t c,i; 710f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 711f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *en_us=NULL; 712f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter1, *iter2; 713f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test1[50]; 714f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar test2[50]; 715f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 716f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test1, "What subset of all possible test cases?"); 717f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(test2, "has the highest probability of detecting"); 718f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) en_us = ucol_open("en_US", &status); 719f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("testing setText for Collation elements\n"); 720f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter1=ucol_openElements(en_us, test1, u_strlen(test1), &status); 721f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 722f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "ERROR: in creation of collation element iterator1 using ucol_openElements()\n %s\n", 723f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 724f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 725f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 726f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 727f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter2=ucol_openElements(en_us, test2, u_strlen(test2), &status); 728f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(status)){ 729f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("ERROR: in creation of collation element iterator2 using ucol_openElements()\n %s\n", 730f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) myErrorName(status)); 731f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 732f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 733f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 734f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 735f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Run through the second iterator just to exercise it */ 736f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c = ucol_next(iter2, &status); 737f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) i = 0; 738f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 739f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while ( ++i < 10 && (c != UCOL_NULLORDER)) 740f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 741f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) 742f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 743f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("iter2->next() returned an error. %s\n", myErrorName(status)); 744f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter2); 745f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter1); 746f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 747f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 748f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 749f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 750f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c = ucol_next(iter2, &status); 751f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 752f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 753f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Now set it to point to the same string as the first iterator */ 754f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter2, test1, u_strlen(test1), &status); 755f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) 756f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 757f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("call to iter2->setText(test1) failed. %s\n", myErrorName(status)); 758f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 759f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) else 760f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 761f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) assertEqual(iter1, iter2); 762f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 763f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 764f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Now set it to point to a null string with fake length*/ 765f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter2, NULL, 2, &status); 766f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) 767f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 768f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("call to iter2->setText(null) failed. %s\n", myErrorName(status)); 769f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 770f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) else 771f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 772f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_next(iter2, &status) != UCOL_NULLORDER) { 773f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("iter2 with null text expected to return UCOL_NULLORDER\n"); 774f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 775f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 776f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 777f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter2); 778f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter1); 779f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(en_us); 780f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 781f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 782f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** @bug 4108762 783f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Test for getMaxExpansion() 784f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 785f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestMaxExpansion() 786f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 787f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 788f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll ;/*= ucol_open("en_US", &status);*/ 789f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar ch = 0; 790f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar32 unassigned = 0xEFFFD; 791f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar supplementary[2]; 792f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t stringOffset = 0; 793f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UBool isError = FALSE; 794f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t sorder = 0; 795f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter ;/*= ucol_openElements(coll, &ch, 1, &status);*/ 796f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t temporder = 0; 797f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 798f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar rule[256]; 799f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(rule, "&a < ab < c/aba < d < z < ch"); 800f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT, 801f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_DEFAULT_STRENGTH,NULL, &status); 802f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_SUCCESS(status) && coll) { 803f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, &ch, 1, &status); 804f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 805f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ch < 0xFFFF && U_SUCCESS(status)) { 806f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 1; 807f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t order; 808f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t size = 0; 809f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 810f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch ++; 811f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 812f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, &ch, 1, &status); 813f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) order = ucol_previous(iter, &status); 814f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 815f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* thai management */ 816f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (order == 0) 817f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) order = ucol_previous(iter, &status); 818f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 819f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (U_SUCCESS(status) && 820f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_previous(iter, &status) != UCOL_NULLORDER) { 821f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 822f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 823f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 824f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) size = ucol_getMaxExpansion(iter, order); 825f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || size < count) { 826f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count < %d\n", 827f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, count); 828f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 829f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 830f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 831f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing for exact max expansion */ 832f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch = 0; 833f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ch < 0x61) { 834f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t order; 835f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t size; 836f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, &ch, 1, &status); 837f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) order = ucol_previous(iter, &status); 838f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) size = ucol_getMaxExpansion(iter, order); 839f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || size != 1) { 840f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count < %d\n", 841f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 1); 842f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 843f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch ++; 844f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 845f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 846f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch = 0x63; 847f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, &ch, 1, &status); 848f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) temporder = ucol_previous(iter, &status); 849f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 850f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 3) { 851f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count != %d\n", 852f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 3); 853f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 854f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 855f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch = 0x64; 856f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, &ch, 1, &status); 857f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) temporder = ucol_previous(iter, &status); 858f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 859f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 1) { 860f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count != %d\n", 861f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 3); 862f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 863f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 864f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U16_APPEND(supplementary, stringOffset, 2, unassigned, isError); 865f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, supplementary, 2, &status); 866f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) sorder = ucol_previous(iter, &status); 867f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 868f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_getMaxExpansion(iter, sorder) != 2) { 869f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count < %d\n", 870f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 2); 871f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 872f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 873f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing jamo */ 874f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch = 0x1165; 875f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 876f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, &ch, 1, &status); 877f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) temporder = ucol_previous(iter, &status); 878f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) > 3) { 879f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count > %d\n", 880f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 3); 881f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 882f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 883f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 884f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 885f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 886f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing special jamo &a<\u1160 */ 887f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[0] = 0x26; 888f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[1] = 0x71; 889f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[2] = 0x3c; 890f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[3] = 0x1165; 891f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[4] = 0x2f; 892f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[5] = 0x71; 893f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[6] = 0x71; 894f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[7] = 0x71; 895f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[8] = 0x71; 896f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rule[9] = 0; 897f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 898f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT, 899f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_DEFAULT_STRENGTH,NULL, &status); 900f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, &ch, 1, &status); 901f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 902f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) temporder = ucol_previous(iter, &status); 903f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 6) { 904f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failure at codepoint %d, maximum expansion count > %d\n", 905f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ch, 5); 906f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 907f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 908f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 909f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 910f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 911f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "Couldn't open collator -> %s\n", u_errorName(status)); 912f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 913f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 914f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 915f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 916f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 917f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void assertEqual(UCollationElements *i1, UCollationElements *i2) 918f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 919f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t c1, c2; 920f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t count = 0; 921f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 922f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 923f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) do 924f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 925f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c1 = ucol_next(i1, &status); 926f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) c2 = ucol_next(i2, &status); 927f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 928f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (c1 != c2) 929f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 930f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error in iteration %d assetEqual between\n %d and %d, they are not equal\n", count, c1, c2); 931f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 932f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 933f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 934f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count += 1; 935f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 936f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (c1 != UCOL_NULLORDER); 937f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 938f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 939f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 940f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Testing iterators with extremely small buffers 941f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 942f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestSmallBuffer() 943f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 944f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 945f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll; 946f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *testiter, 947f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *iter; 948f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t count = 0; 949f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) OrderAndOffset *testorders, 950f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *orders; 951f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 952f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar teststr[500]; 953f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar str[] = {0x300, 0x31A, 0}; 954f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* 955f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) creating a long string of decomposable characters, 956f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) since by default the writable buffer is of size 256 957f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 958f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < 500) { 959f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ((count & 1) == 0) { 960f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) teststr[count ++] = 0x300; 961f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 962f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) else { 963f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) teststr[count ++] = 0x31A; 964f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 965f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 966f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 967f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open("th_TH", &status); 968f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_SUCCESS(status) && coll) { 969f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) testiter = ucol_openElements(coll, teststr, 500, &status); 970f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, str, 2, &status); 971f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 972f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) orders = getOrders(iter, &count); 973f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (count != 2) { 974f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error collation elements size is not 2 for \\u0300\\u031A\n"); 975f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 976f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 977f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* 978f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) this will rearrange the string data to 250 characters of 0x300 first then 979f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 250 characters of 0x031A 980f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 981f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) testorders = getOrders(testiter, &count); 982f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 983f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (count != 500) { 984f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error decomposition does not give the right sized collation elements\n"); 985f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 986f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 987f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count != 0) { 988f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* UCA collation element for 0x0F76 */ 989f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ((count > 250 && testorders[-- count].order != orders[1].order) || 990f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) (count <= 250 && testorders[-- count].order != orders[0].order)) { 991f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error decomposition does not give the right collation element at %d count\n", count); 992f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 993f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 994f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 995f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 996f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) free(testorders); 997f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) free(orders); 998f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 999f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_reset(testiter); 1000f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1001f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* ensures closing of elements done properly to clear writable buffer */ 1002f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_next(testiter, &status); 1003f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_next(testiter, &status); 1004f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(testiter); 1005f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1006f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1007f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1008f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "Couldn't open collator -> %s\n", u_errorName(status)); 1009f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1010f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1011f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1012f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1013f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Sniplets of code from genuca 1014f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1015f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static int32_t hex2num(char hex) { 1016f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(hex>='0' && hex <='9') { 1017f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return hex-'0'; 1018f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else if(hex>='a' && hex<='f') { 1019f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return hex-'a'+10; 1020f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else if(hex>='A' && hex<='F') { 1021f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return hex-'A'+10; 1022f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1023f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return 0; 1024f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1025f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1026f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1027f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1028f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Getting codepoints from a string 1029f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @param str character string contain codepoints seperated by space and ended 1030f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* by a semicolon 1031f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @param codepoints array for storage, assuming size > 5 1032f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @return position at the end of the codepoint section 1033f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1034f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static char *getCodePoints(char *str, UChar *codepoints, UChar *contextCPs) { 1035f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode errorCode = U_ZERO_ERROR; 1036f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *semi = uprv_strchr(str, ';'); 1037f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *pipe = uprv_strchr(str, '|'); 1038f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *s; 1039f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *codepoints = 0; 1040f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *contextCPs = 0; 1041f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(semi == NULL) { 1042f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("expected semicolon after code point string in FractionalUCA.txt %s\n", str); 1043f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return str; 1044f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1045f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(pipe != NULL) { 1046f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t contextLength; 1047f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *pipe = 0; 1048f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) contextLength = u_parseString(str, contextCPs, 99, NULL, &errorCode); 1049f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *pipe = '|'; 1050f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(errorCode)) { 1051f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error parsing precontext string from FractionalUCA.txt %s\n", str); 1052f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return str; 1053f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1054f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* prepend the precontext string to the codepoints */ 1055f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_memcpy(codepoints, contextCPs, contextLength); 1056f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints += contextLength; 1057f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* start of the code point string */ 1058f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) s = pipe + 1; 1059f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1060f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) s = str; 1061f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1062f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_parseString(s, codepoints, 99, NULL, &errorCode); 1063f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(U_FAILURE(errorCode)) { 1064f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error parsing code point string from FractionalUCA.txt %s\n", str); 1065f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return str; 1066f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1067f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return semi + 1; 1068f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1069f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1070f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1071f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Sniplets of code from genuca 1072f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1073f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static int32_t 1074f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)readElement(char **from, char *to, char separator, UErrorCode *status) 1075f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1076f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_SUCCESS(*status)) { 1077f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char buffer[1024]; 1078f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t i = 0; 1079f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (**from != separator) { 1080f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (**from != ' ') { 1081f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(buffer+i++) = **from; 1082f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1083f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) (*from)++; 1084f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1085f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) (*from)++; 1086f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *(buffer + i) = 0; 1087f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strcpy(to, buffer); 1088f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return i/2; 1089f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1090f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1091f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return 0; 1092f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1093f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1094f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1095f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Sniplets of code from genuca 1096f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1097f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static uint32_t 1098f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)getSingleCEValue(char *primary, char *secondary, char *tertiary, 1099f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode *status) 1100f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1101f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_SUCCESS(*status)) { 1102f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t value = 0; 1103f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char primsave = '\0'; 1104f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char secsave = '\0'; 1105f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char tersave = '\0'; 1106f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *primend = primary+4; 1107f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *secend = secondary+2; 1108f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *terend = tertiary+2; 1109f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t primvalue; 1110f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t secvalue; 1111f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t tervalue; 1112f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1113f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (uprv_strlen(primary) > 4) { 1114f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primsave = *primend; 1115f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *primend = '\0'; 1116f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1117f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1118f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (uprv_strlen(secondary) > 2) { 1119f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secsave = *secend; 1120f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *secend = '\0'; 1121f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1122f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1123f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (uprv_strlen(tertiary) > 2) { 1124f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tersave = *terend; 1125f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *terend = '\0'; 1126f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1127f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1128f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primvalue = (*primary!='\0')?uprv_strtoul(primary, &primend, 16):0; 1129f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secvalue = (*secondary!='\0')?uprv_strtoul(secondary, &secend, 16):0; 1130f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tervalue = (*tertiary!='\0')?uprv_strtoul(tertiary, &terend, 16):0; 1131f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(primvalue <= 0xFF) { 1132f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primvalue <<= 8; 1133f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1134f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1135f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value = ((primvalue << UCOL_PRIMARYORDERSHIFT) & UCOL_PRIMARYORDERMASK) 1136f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) | ((secvalue << UCOL_SECONDARYORDERSHIFT) & UCOL_SECONDARYORDERMASK) 1137f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) | (tervalue & UCOL_TERTIARYORDERMASK); 1138f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1139f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(primsave!='\0') { 1140f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *primend = primsave; 1141f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1142f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(secsave!='\0') { 1143f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *secend = secsave; 1144f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1145f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(tersave!='\0') { 1146f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *terend = tersave; 1147f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1148f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return value; 1149f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1150f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return 0; 1151f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1152f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1153f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1154f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Getting collation elements generated from a string 1155f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @param str character string contain collation elements contained in [] and 1156f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* seperated by space 1157f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @param ce array for storage, assuming size > 20 1158f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @param status error status 1159f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* @return position at the end of the codepoint section 1160f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1161f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static char * getCEs(char *str, uint32_t *ces, UErrorCode *status) { 1162f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *pStartCP = uprv_strchr(str, '['); 1163f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1164f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *pEndCP; 1165f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char primary[100]; 1166f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char secondary[100]; 1167f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char tertiary[100]; 1168f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1169f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (*pStartCP == '[') { 1170f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t primarycount = 0; 1171f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t secondarycount = 0; 1172f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t tertiarycount = 0; 1173f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t CEi = 1; 1174f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) pEndCP = strchr(pStartCP, ']'); 1175f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(pEndCP == NULL) { 1176f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1177f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1178f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) pStartCP ++; 1179f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1180f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primarycount = readElement(&pStartCP, primary, ',', status); 1181f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secondarycount = readElement(&pStartCP, secondary, ',', status); 1182f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tertiarycount = readElement(&pStartCP, tertiary, ']', status); 1183f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1184f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* I want to get the CEs entered right here, including continuation */ 1185f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ces[count ++] = getSingleCEValue(primary, secondary, tertiary, status); 1186f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(*status)) { 1187f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1188f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1189f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1190f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (2 * CEi < primarycount || CEi < secondarycount || 1191f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) CEi < tertiarycount) { 1192f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t value = UCOL_CONTINUATION_MARKER; /* Continuation marker */ 1193f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (2 * CEi < primarycount) { 1194f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(primary + 4 * CEi)) & 0xF) << 28); 1195f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(primary + 4 * CEi + 1)) & 0xF) << 24); 1196f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1197f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1198f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (2 * CEi + 1 < primarycount) { 1199f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(primary + 4 * CEi + 2)) & 0xF) << 20); 1200f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(primary + 4 * CEi + 3)) &0xF) << 16); 1201f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1202f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1203f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (CEi < secondarycount) { 1204f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(secondary + 2 * CEi)) & 0xF) << 12); 1205f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(secondary + 2 * CEi + 1)) & 0xF) << 8); 1206f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1207f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1208f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (CEi < tertiarycount) { 1209f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= ((hex2num(*(tertiary + 2 * CEi)) & 0x3) << 4); 1210f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) value |= (hex2num(*(tertiary + 2 * CEi + 1)) & 0xF); 1211f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1212f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1213f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) CEi ++; 1214f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ces[count ++] = value; 1215f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1216f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1217f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) pStartCP = pEndCP + 1; 1218f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1219f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ces[count] = 0; 1220f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return pStartCP; 1221f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1222f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1223f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1224f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Getting the FractionalUCA.txt file stream 1225f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1226f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static FileStream * getFractionalUCA(void) 1227f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1228f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char newPath[256]; 1229f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char backupPath[256]; 1230f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) FileStream *result = NULL; 1231f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1232f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Look inside ICU_DATA first */ 1233f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_strcpy(newPath, ctest_dataSrcDir()); 1234f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_strcat(newPath, "unidata" U_FILE_SEP_STRING ); 1235f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_strcat(newPath, "FractionalUCA.txt"); 1236f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1237f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* As a fallback, try to guess where the source data was located 1238f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * at the time ICU was built, and look there. 1239f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 1240f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#if defined (U_TOPSRCDIR) 1241f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strcpy(backupPath, U_TOPSRCDIR U_FILE_SEP_STRING "data"); 1242f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#else 1243f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { 1244f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode errorCode = U_ZERO_ERROR; 1245f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strcpy(backupPath, loadTestData(&errorCode)); 1246f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strcat(backupPath, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data"); 1247f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1248f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#endif 1249f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strcat(backupPath, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "FractionalUCA.txt"); 1250f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1251f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result = T_FileStream_open(newPath, "rb"); 1252f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1253f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (result == NULL) { 1254f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result = T_FileStream_open(backupPath, "rb"); 1255f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (result == NULL) { 1256f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Failed to open either %s or %s\n", newPath, backupPath); 1257f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1258f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1259f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return result; 1260f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1261f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1262f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1263f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Testing the CEs returned by the iterator 1264f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1265f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestCEs() { 1266f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) FileStream *file = NULL; 1267f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char line[2048]; 1268f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char *str; 1269f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar codepoints[10]; 1270f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t ces[20]; 1271f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1272f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll = ucol_open("", &status); 1273f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t lineNo = 0; 1274f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar contextCPs[5]; 1275f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1276f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1277f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "Error in opening root collator -> %s\n", u_errorName(status)); 1278f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1279f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1280f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1281f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) file = getFractionalUCA(); 1282f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1283f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (file == NULL) { 1284f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("*** unable to open input FractionalUCA.txt file ***\n"); 1285f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1286f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1287f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1288f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1289f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) { 1290f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1291f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 1292f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t preContextCeLen=0; 1293f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) lineNo++; 1294f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* skip this line if it is empty or a comment or is a return value 1295f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) or start of some variable section */ 1296f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(line[0] == 0 || line[0] == '#' || line[0] == '\n' || 1297f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) line[0] == 0x000D || line[0] == '[') { 1298f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1299f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1300f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1301f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) str = getCodePoints(line, codepoints, contextCPs); 1302f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1303f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* these are 'fake' codepoints in the fractional UCA, and are used just 1304f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * for positioning of indirect values. They should not go through this 1305f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * test. 1306f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 1307f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(*codepoints == 0xFDD0) { 1308f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1309f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1310f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (*contextCPs != 0) { 1311f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, contextCPs, -1, &status); 1312f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1313f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error in opening collation elements\n"); 1314f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1315f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1316f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while((ces[preContextCeLen] = ucol_next(iter, &status)) != (uint32_t)UCOL_NULLORDER) { 1317f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) preContextCeLen++; 1318f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1319f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1320f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1321f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1322f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) getCEs(str, ces+preContextCeLen, &status); 1323f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1324f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error in parsing collation elements in FractionalUCA.txt\n"); 1325f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1326f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1327f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, codepoints, -1, &status); 1328f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1329f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error in opening collation elements\n"); 1330f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1331f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1332f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (;;) { 1333f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t ce = (uint32_t)ucol_next(iter, &status); 1334f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce == 0xFFFFFFFF) { 1335f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ce = 0; 1336f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1337f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* we now unconditionally reorder Thai/Lao prevowels, so this 1338f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * test would fail if we don't skip here. 1339f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 1340f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(UCOL_ISTHAIPREVOWEL(*codepoints) && ce == 0 && count == 0) { 1341f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1342f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1343f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce != ces[count] || U_FAILURE(status)) { 1344f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Collation elements in FractionalUCA.txt and iterators do not match!\n"); 1345f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1346f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1347f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ces[count] == 0) { 1348f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1349f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1350f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 1351f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1352f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1353f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1354f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1355f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) T_FileStream_close(file); 1356f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1357f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1358f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1359f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1360f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Testing the discontigous contractions 1361f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1362f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestDiscontiguos() { 1363f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *rulestr = 1364f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "&z < AB < X\\u0300 < ABC < X\\u0300\\u0315"; 1365f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar rule[50]; 1366f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int rulelen = u_unescape(rulestr, rule, 50); 1367f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *src[] = { 1368f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "ADB", "ADBC", "A\\u0315B", "A\\u0315BC", 1369f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* base character blocked */ 1370f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "XD\\u0300", "XD\\u0300\\u0315", 1371f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* non blocking combining character */ 1372f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0319\\u0300", "X\\u0319\\u0300\\u0315", 1373f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* blocking combining character */ 1374f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0314\\u0300", "X\\u0314\\u0300\\u0315", 1375f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* contraction prefix */ 1376f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "ABDC", "AB\\u0315C","X\\u0300D\\u0315", "X\\u0300\\u0319\\u0315", 1377f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300\\u031A\\u0315", 1378f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* ends not with a contraction character */ 1379f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0319\\u0300D", "X\\u0319\\u0300\\u0315D", "X\\u0300D\\u0315D", 1380f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300\\u0319\\u0315D", "X\\u0300\\u031A\\u0315D" 1381f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) }; 1382f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *tgt[] = { 1383f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* non blocking combining character */ 1384f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "A D B", "A D BC", "A \\u0315 B", "A \\u0315 BC", 1385f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* base character blocked */ 1386f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X D \\u0300", "X D \\u0300\\u0315", 1387f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* non blocking combining character */ 1388f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300 \\u0319", "X\\u0300\\u0315 \\u0319", 1389f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* blocking combining character */ 1390f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X \\u0314 \\u0300", "X \\u0314 \\u0300\\u0315", 1391f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* contraction prefix */ 1392f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "AB DC", "AB \\u0315 C","X\\u0300 D \\u0315", "X\\u0300\\u0315 \\u0319", 1393f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300 \\u031A \\u0315", 1394f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* ends not with a contraction character */ 1395f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300 \\u0319D", "X\\u0300\\u0315 \\u0319D", "X\\u0300 D\\u0315D", 1396f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) "X\\u0300\\u0315 \\u0319D", "X\\u0300 \\u031A\\u0315D" 1397f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) }; 1398f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int size = 20; 1399f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll; 1400f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1401f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1402f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 1403f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *resultiter; 1404f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1405f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_openRules(rule, rulelen, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status); 1406f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, rule, 1, &status); 1407f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) resultiter = ucol_openElements(coll, rule, 1, &status); 1408f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1409f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1410f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "Error opening collation rules -> %s\n", u_errorName(status)); 1411f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1412f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1413f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1414f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < size) { 1415f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar str[20]; 1416f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar tstr[20]; 1417f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int strLen = u_unescape(src[count], str, 20); 1418f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *s; 1419f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1420f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(iter, str, strLen, &status); 1421f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1422f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error opening collation iterator\n"); 1423f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1424f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1425f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1426f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_unescape(tgt[count], tstr, 20); 1427f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) s = tstr; 1428f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1429f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("count %d\n", count); 1430f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1431f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (;;) { 1432f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t ce; 1433f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *e = u_strchr(s, 0x20); 1434f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (e == 0) { 1435f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) e = u_strchr(s, 0); 1436f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1437f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setText(resultiter, s, (int32_t)(e - s), &status); 1438f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ce = ucol_next(resultiter, &status); 1439f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1440f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error manipulating collation iterator\n"); 1441f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1442f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1443f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (ce != UCOL_NULLORDER) { 1444f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce != (uint32_t)ucol_next(iter, &status) || 1445f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U_FAILURE(status)) { 1446f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Discontiguos contraction test mismatch\n"); 1447f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1448f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1449f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ce = ucol_next(resultiter, &status); 1450f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1451f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error getting next collation element\n"); 1452f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1453f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1454f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1455f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) s = e + 1; 1456f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (*e == 0) { 1457f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1458f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1459f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1460f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_reset(iter); 1461f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) backAndForth(iter); 1462f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 1463f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1464f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(resultiter); 1465f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1466f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1467f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1468f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1469f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestCEBufferOverflow() 1470f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1471f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar str[UCOL_EXPAND_CE_BUFFER_SIZE + 1]; 1472f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1473f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar rule[10]; 1474f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll; 1475f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter; 1476f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1477f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) u_uastrcpy(rule, "&z < AB"); 1478f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL,&status); 1479f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1480f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "Rule based collator not created for testing ce buffer overflow -> %s\n", u_errorName(status)); 1481f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1482f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1483f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1484f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* 0xDCDC is a trail surrogate hence deemed unsafe by the heuristic 1485f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) test. this will cause an overflow in getPrev */ 1486f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) str[0] = 0x0041; /* 'A' */ 1487f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /*uprv_memset(str + 1, 0xE0, sizeof(UChar) * UCOL_EXPAND_CE_BUFFER_SIZE);*/ 1488f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memset(str + 1, 0xDC, sizeof(UChar) * UCOL_EXPAND_CE_BUFFER_SIZE); 1489f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) str[UCOL_EXPAND_CE_BUFFER_SIZE] = 0x0042; /* 'B' */ 1490f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) iter = ucol_openElements(coll, str, UCOL_EXPAND_CE_BUFFER_SIZE + 1, 1491f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) &status); 1492f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ucol_previous(iter, &status) == UCOL_NULLORDER || 1493f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) status == U_BUFFER_OVERFLOW_ERROR) { 1494f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("CE buffer should not overflow with long string of trail surrogates\n"); 1495f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1496f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1497f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1498f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1499f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1500f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1501f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Checking collation element validity. 1502f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1503f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#define MAX_CODEPOINTS_TO_SHOW 10 1504f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void showCodepoints(const UChar *codepoints, int length, char * codepointText) { 1505f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int i, lengthToUse = length; 1506f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (lengthToUse > MAX_CODEPOINTS_TO_SHOW) { 1507f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) lengthToUse = MAX_CODEPOINTS_TO_SHOW; 1508f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1509f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (i = 0; i < lengthToUse; ++i) { 1510f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int bytesWritten = sprintf(codepointText, " %04X", *codepoints++); 1511f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (bytesWritten <= 0) { 1512f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1513f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1514f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepointText += bytesWritten; 1515f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1516f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (i < length) { 1517f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) sprintf(codepointText, " ..."); 1518f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1519f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1520f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1521f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static UBool checkCEValidity(const UCollator *coll, const UChar *codepoints, 1522f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int length) 1523f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1524f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1525f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements *iter = ucol_openElements(coll, codepoints, length, 1526f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) &status); 1527f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UBool result = FALSE; 1528f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UBool primaryDone = FALSE, secondaryDone = FALSE, tertiaryDone = FALSE; 1529f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char * collLocale; 1530f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1531f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1532f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Error creating iterator for testing validity\n"); 1533f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return FALSE; 1534f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1535f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) collLocale = ucol_getLocale(coll, ULOC_VALID_LOCALE, &status); 1536f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status) || collLocale==NULL) { 1537f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) status = U_ZERO_ERROR; 1538f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) collLocale = "?"; 1539f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1540f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1541f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (;;) { 1542f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t ce = ucol_next(iter, &status); 1543f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t primary, p1, p2, secondary, tertiary; 1544f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce == UCOL_NULLORDER) { 1545f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) result = TRUE; 1546f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1547f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1548f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce == 0) { 1549f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1550f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1551f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ce == 0x02000202) { 1552f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* special CE for merge-sort character */ 1553f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (*codepoints == 0xFFFE /* && length == 1 */) { 1554f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* 1555f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * Note: We should check for length==1 but the token parser appears 1556f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * to give us trailing NUL characters. 1557f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * TODO: Ticket #8047: Change TestCEValidity to use ucol_getTailoredSet() 1558f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) * rather than the internal collation rule parser 1559f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) */ 1560f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1561f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1562f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Special 02/02/02 weight for code point U+%04X [len %d] != U+FFFE\n", 1563f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) (int)*codepoints, (int)length); 1564f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1565f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1566f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1567f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primary = UCOL_PRIMARYORDER(ce); 1568f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) p1 = primary >> 8; 1569f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) p2 = primary & 0xFF; 1570f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secondary = UCOL_SECONDARYORDER(ce); 1571f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tertiary = UCOL_TERTIARYORDER(ce) & UCOL_REMOVE_CONTINUATION; 1572f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1573f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (!isContinuation(ce)) { 1574f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ((ce & UCOL_REMOVE_CONTINUATION) == 0) { 1575f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Empty CE %08lX except for case bits\n", (long)ce); 1576f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1577f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1578f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p1 == 0) { 1579f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 != 0) { 1580f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary 00 xx in %08lX\n", (long)ce); 1581f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1582f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1583f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primaryDone = TRUE; 1584f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1585f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p1 <= 2 || p1 >= 0xF0) { 1586f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Primary first bytes F0..FF are specials. */ 1587f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary first byte of %08lX out of range\n", (long)ce); 1588f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1589f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1590f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 == 0) { 1591f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primaryDone = TRUE; 1592f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1593f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 <= 3 || p2 >= 0xFF) { 1594f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Primary second bytes 03 and FF are sort key compression terminators. */ 1595f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary second byte of %08lX out of range\n", (long)ce); 1596f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1597f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1598f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primaryDone = FALSE; 1599f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1600f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1601f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (secondary == 0) { 1602f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (primary != 0) { 1603f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary!=0 secondary==0 in %08lX\n", (long)ce); 1604f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1605f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1606f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secondaryDone = TRUE; 1607f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1608f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (secondary <= 2 || 1609f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) (UCOL_BYTE_COMMON < secondary && secondary <= (UCOL_BYTE_COMMON + 0x80)) 1610f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ) { 1611f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Secondary first bytes common+1..+0x80 are used for sort key compression. */ 1612f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Secondary byte of %08lX out of range\n", (long)ce); 1613f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1614f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1615f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secondaryDone = FALSE; 1616f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1617f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (tertiary == 0) { 1618f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* We know that ce != 0. */ 1619f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary!=0 or secondary!=0 but tertiary==0 in %08lX\n", (long)ce); 1620f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1621f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1622f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (tertiary <= 2) { 1623f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Tertiary byte of %08lX out of range\n", (long)ce); 1624f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1625f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1626f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tertiaryDone = FALSE; 1627f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1628f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ((ce & UCOL_REMOVE_CONTINUATION) == 0) { 1629f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Empty continuation %08lX\n", (long)ce); 1630f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1631f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1632f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (primaryDone && primary != 0) { 1633f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary was done but continues in %08lX\n", (long)ce); 1634f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1635f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1636f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p1 == 0) { 1637f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 != 0) { 1638f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary 00 xx in %08lX\n", (long)ce); 1639f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1640f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1641f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primaryDone = TRUE; 1642f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1643f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p1 <= 2) { 1644f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary first byte of %08lX out of range\n", (long)ce); 1645f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1646f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1647f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 == 0) { 1648f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) primaryDone = TRUE; 1649f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1650f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (p2 <= 3) { 1651f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Primary second byte of %08lX out of range\n", (long)ce); 1652f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1653f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1654f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1655f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1656f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (secondaryDone && secondary != 0) { 1657f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Secondary was done but continues in %08lX\n", (long)ce); 1658f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1659f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1660f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (secondary == 0) { 1661f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) secondaryDone = TRUE; 1662f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1663f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (secondary <= 2) { 1664f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Secondary byte of %08lX out of range\n", (long)ce); 1665f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1666f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1667f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1668f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (tertiaryDone && tertiary != 0) { 1669f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Tertiary was done but continues in %08lX\n", (long)ce); 1670f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1671f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1672f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (tertiary == 0) { 1673f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tertiaryDone = TRUE; 1674f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else if (tertiary <= 2) { 1675f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Tertiary byte of %08lX out of range\n", (long)ce); 1676f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 1677f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1678f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1679f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1680f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (!result) { 1681f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char codepointText[5*MAX_CODEPOINTS_TO_SHOW + 5]; 1682f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) showCodepoints(codepoints, length, codepointText); 1683f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Locale: %s Code point string: %s\n", collLocale, codepointText); 1684f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1685f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(iter); 1686f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return result; 1687f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1688f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1689f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestCEValidity() 1690f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1691f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing UCA collation elements */ 1692f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1693f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* en_US has no tailorings */ 1694f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll = ucol_open("root", &status); 1695f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* tailored locales */ 1696f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char locale[][11] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN", "zh__PINYIN"}; 1697f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char *loc; 1698f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) FileStream *file = NULL; 1699f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char line[2048]; 1700f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar codepoints[11]; 1701f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1702f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int maxCount = 0; 1703f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar contextCPs[3]; 1704f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar32 c; 1705f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UParseError parseError; 1706f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1707f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "en_US collator creation failed -> %s\n", u_errorName(status)); 1708f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1709f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1710f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing UCA elements\n"); 1711f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) file = getFractionalUCA(); 1712f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (file == NULL) { 1713f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Fractional UCA data can not be opened\n"); 1714f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1715f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1716f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1717f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) { 1718f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(line[0] == 0 || line[0] == '#' || line[0] == '\n' || 1719f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) line[0] == 0x000D || line[0] == '[') { 1720f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1721f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1722f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1723f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) getCodePoints(line, codepoints, contextCPs); 1724f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkCEValidity(coll, codepoints, u_strlen(codepoints)); 1725f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1726f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1727f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing UCA elements for the whole range of unicode characters\n"); 1728f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (c = 0; c <= 0xffff; ++c) { 1729f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(c)) { 1730f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints[0] = (UChar)c; 1731f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkCEValidity(coll, codepoints, 1); 1732f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1733f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1734f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (; c <= 0x10ffff; ++c) { 1735f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined(c)) { 1736f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t i = 0; 1737f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) U16_APPEND_UNSAFE(codepoints, i, c); 1738f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkCEValidity(coll, codepoints, i); 1739f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1740f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1741f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1742f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1743f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1744f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing tailored collation elements */ 1745f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing tailored elements\n"); 1746f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(getTestOption(QUICK_OPTION)) { 1747f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) maxCount = sizeof(locale)/sizeof(locale[0]); 1748f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1749f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) maxCount = uloc_countAvailable(); 1750f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1751f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < maxCount) { 1752f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const UChar *rules = NULL, 1753f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *current = NULL; 1754f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *rulesCopy = NULL; 1755f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t ruleLen = 0; 1756f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1757f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t chOffset = 0; 1758f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t chLen = 0; 1759f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t exOffset = 0; 1760f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t exLen = 0; 1761f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t prefixOffset = 0; 1762f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t prefixLen = 0; 1763f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UBool startOfRules = TRUE; 1764f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UColOptionSet opts; 1765f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1766f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UColTokenParser src; 1767f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t strength = 0; 1768f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint16_t specs = 0; 1769f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(getTestOption(QUICK_OPTION)) { 1770f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) loc = locale[count]; 1771f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 1772f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) loc = uloc_getAvailable(count); 1773f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(!hasCollationElements(loc)) { 1774f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count++; 1775f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1776f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1777f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1778f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1779f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memset(&src, 0, sizeof(UColTokenParser)); 1780f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1781f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing CEs for %s\n", loc); 1782f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1783f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open(loc, &status); 1784f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1785f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("%s collator creation failed\n", loc); 1786f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1787f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1788f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1789f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.opts = &opts; 1790f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rules = ucol_getRules(coll, &ruleLen); 1791f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1792f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ruleLen > 0) { 1793f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rulesCopy = (UChar *)uprv_malloc((ruleLen + 1794f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar)); 1795f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar)); 1796f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.current = src.source = rulesCopy; 1797f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.end = rulesCopy + ruleLen; 1798f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.extraCurrent = src.end; 1799f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.extraEnd = src.end + UCOL_TOK_EXTRA_RULE_SPACE_SIZE; 1800f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1801f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to 1802f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ 1803f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,&status)) != NULL) { 1804f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strength = src.parsedToken.strength; 1805f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chOffset = src.parsedToken.charsOffset; 1806f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chLen = src.parsedToken.charsLen; 1807f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) exOffset = src.parsedToken.extensionOffset; 1808f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) exLen = src.parsedToken.extensionLen; 1809f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) prefixOffset = src.parsedToken.prefixOffset; 1810f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) prefixLen = src.parsedToken.prefixLen; 1811f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) specs = src.parsedToken.flags; 1812f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1813f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) startOfRules = FALSE; 1814f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcpy(codepoints, src.source + chOffset, 1815f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chLen * sizeof(UChar)); 1816f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints[chLen] = 0; 1817f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkCEValidity(coll, codepoints, chLen); 1818f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1819f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_free(src.source); 1820f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1821f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1822f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1823f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 1824f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1825f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) T_FileStream_close(file); 1826f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1827f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1828f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void printSortKeyError(const UChar *codepoints, int length, 1829f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint8_t *sortkey, int sklen) 1830f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1831f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1832f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Sortkey not valid for "); 1833f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (length > 0) { 1834f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("0x%04x ", *codepoints); 1835f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) length --; 1836f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints ++; 1837f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1838f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("\nSortkey : "); 1839f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < sklen) { 1840f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("0x%02x ", sortkey[count]); 1841f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 1842f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1843f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("\n"); 1844f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1845f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1846f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 1847f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* Checking sort key validity for all levels 1848f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 1849f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static UBool checkSortKeyValidity(UCollator *coll, 1850f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const UChar *codepoints, 1851f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int length) 1852f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1853f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1854f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationStrength strength[5] = {UCOL_PRIMARY, UCOL_SECONDARY, 1855f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_TERTIARY, UCOL_QUATERNARY, 1856f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_IDENTICAL}; 1857f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int strengthlen = 5; 1858f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int strengthIndex = 0; 1859f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int caselevel = 0; 1860f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1861f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (caselevel < 1) { 1862f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (caselevel == 0) { 1863f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &status); 1864f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1865f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) else { 1866f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &status); 1867f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1868f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1869f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (strengthIndex < strengthlen) { 1870f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count01 = 0; 1871f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t count = 0; 1872f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint8_t sortkey[128]; 1873f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t sklen; 1874f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1875f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setStrength(coll, strength[strengthIndex]); 1876f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) sklen = ucol_getSortKey(coll, codepoints, length, sortkey, 128); 1877f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (sortkey[count] != 0) { 1878f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (sortkey[count] == 2 || (sortkey[count] == 3 && count01 > 0 && strengthIndex != 4)) { 1879f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) printSortKeyError(codepoints, length, sortkey, sklen); 1880f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return FALSE; 1881f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1882f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (sortkey[count] == 1) { 1883f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count01 ++; 1884f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1885f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 1886f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1887f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1888f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (count + 1 != sklen || (count01 != strengthIndex + caselevel)) { 1889f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) printSortKeyError(codepoints, length, sortkey, sklen); 1890f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return FALSE; 1891f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1892f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strengthIndex ++; 1893f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1894f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) caselevel ++; 1895f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1896f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return TRUE; 1897f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 1898f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1899f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestSortKeyValidity(void) 1900f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 1901f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing UCA collation elements */ 1902f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 1903f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* en_US has no tailorings */ 1904f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator *coll = ucol_open("en_US", &status); 1905f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* tailored locales */ 1906f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char locale[][6] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN"}; 1907f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) FileStream *file = NULL; 1908f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) char line[2048]; 1909f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar codepoints[10]; 1910f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int count = 0; 1911f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar contextCPs[5]; 1912f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UParseError parseError; 1913f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1914f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err_status(status, "en_US collator creation failed -> %s\n", u_errorName(status)); 1915f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1916f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1917f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing UCA elements\n"); 1918f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) file = getFractionalUCA(); 1919f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (file == NULL) { 1920f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("Fractional UCA data can not be opened\n"); 1921f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1922f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1923f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1924f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) { 1925f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(line[0] == 0 || line[0] == '#' || line[0] == '\n' || 1926f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) line[0] == 0x000D || line[0] == '[') { 1927f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1928f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1929f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1930f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) getCodePoints(line, codepoints, contextCPs); 1931f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(codepoints[0] == 0xFFFE) { 1932f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Skip special merge-sort character U+FFFE which has otherwise illegal 02 weight bytes. */ 1933f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 1934f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1935f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkSortKeyValidity(coll, codepoints, u_strlen(codepoints)); 1936f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1937f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1938f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing UCA elements for the whole range of unicode characters\n"); 1939f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints[0] = 0; 1940f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1941f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (codepoints[0] < 0xFFFF) { 1942f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (u_isdefined((UChar32)codepoints[0])) { 1943f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkSortKeyValidity(coll, codepoints, 1); 1944f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1945f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints[0] ++; 1946f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1947f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1948f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 1949f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1950f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* testing tailored collation elements */ 1951f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_verbose("Testing tailored elements\n"); 1952f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while (count < 5) { 1953f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const UChar *rules = NULL, 1954f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) *current = NULL; 1955f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UChar *rulesCopy = NULL; 1956f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t ruleLen = 0; 1957f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1958f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t chOffset = 0; 1959f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t chLen = 0; 1960f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t exOffset = 0; 1961f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t exLen = 0; 1962f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t prefixOffset = 0; 1963f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t prefixLen = 0; 1964f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UBool startOfRules = TRUE; 1965f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UColOptionSet opts; 1966f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1967f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UColTokenParser src; 1968f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint32_t strength = 0; 1969f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uint16_t specs = 0; 1970f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1971f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memset(&src, 0, sizeof(UColTokenParser)); 1972f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1973f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) coll = ucol_open(locale[count], &status); 1974f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (U_FAILURE(status)) { 1975f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("%s collator creation failed\n", locale[count]); 1976f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) return; 1977f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 1978f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1979f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.opts = &opts; 1980f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rules = ucol_getRules(coll, &ruleLen); 1981f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1982f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (ruleLen > 0) { 1983f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) rulesCopy = (UChar *)uprv_malloc((ruleLen + 1984f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar)); 1985f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar)); 1986f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.current = src.source = rulesCopy; 1987f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.end = rulesCopy + ruleLen; 1988f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.extraCurrent = src.end; 1989f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) src.extraEnd = src.end + UCOL_TOK_EXTRA_RULE_SPACE_SIZE; 1990f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 1991f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to 1992f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ 1993f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) while ((current = ucol_tok_parseNextToken(&src, startOfRules,&parseError, &status)) != NULL) { 1994f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) strength = src.parsedToken.strength; 1995f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chOffset = src.parsedToken.charsOffset; 1996f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chLen = src.parsedToken.charsLen; 1997f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) exOffset = src.parsedToken.extensionOffset; 1998f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) exLen = src.parsedToken.extensionLen; 1999f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) prefixOffset = src.parsedToken.prefixOffset; 2000f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) prefixLen = src.parsedToken.prefixLen; 2001f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) specs = src.parsedToken.flags; 2002f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2003f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) startOfRules = FALSE; 2004f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_memcpy(codepoints, src.source + chOffset, 2005f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) chLen * sizeof(UChar)); 2006f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) codepoints[chLen] = 0; 2007f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if(codepoints[0] == 0xFFFE) { 2008f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) /* Skip special merge-sort character U+FFFE which has otherwise illegal 02 weight bytes. */ 2009f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) continue; 2010f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2011f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) checkSortKeyValidity(coll, codepoints, chLen); 2012f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2013f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) uprv_free(src.source); 2014f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2015f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2016f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(coll); 2017f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) count ++; 2018f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2019f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) T_FileStream_close(file); 2020f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 2021f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2022f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)/** 2023f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* TestSearchCollatorElements tests iterator behavior (forwards and backwards) with 2024f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)* normalization on AND jamo tailoring, among other things. 2025f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)*/ 2026f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static const UChar tsceText[] = { /* Nothing in here should be ignorable */ 2027f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0xAC00, /* simple LV Hangul */ 2028f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0xAC01, /* simple LVT Hangul */ 2029f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0xAC0F, /* LVTT, last jamo expands for search */ 2030f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0xAFFF, /* LLVVVTT, every jamo expands for search */ 2031f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x1100, 0x1161, 0x11A8, /* 0xAC01 as conjoining jamo */ 2032f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x3131, 0x314F, 0x3131, /* 0xAC01 as compatibility jamo */ 2033f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x1100, 0x1161, 0x11B6, /* 0xAC0F as conjoining jamo; last expands for search */ 2034f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x1101, 0x1170, 0x11B6, /* 0xAFFF as conjoining jamo; all expand for search */ 2035f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x00E6, /* small letter ae, expands */ 2036f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020, 0x1E4D, /* small letter o with tilde and acute, decomposes */ 2037f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0x0020 2038f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)}; 2039f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)enum { kLen_tsceText = sizeof(tsceText)/sizeof(tsceText[0]) }; 2040f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2041f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static const int32_t rootStandardOffsets[] = { 2042f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0, 1,2, 2043f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2, 3,4,4, 2044f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 4, 5,6,6, 2045f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 6, 7,8,8, 2046f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 8, 9,10,11, 2047f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 12, 13,14,15, 2048f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 16, 17,18,19, 2049f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 20, 21,22,23, 2050f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 24, 25,26,26,26, 2051f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 26, 27,28,28, 2052f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 28, 2053f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 29 2054f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)}; 2055f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)enum { kLen_rootStandardOffsets = sizeof(rootStandardOffsets)/sizeof(rootStandardOffsets[0]) }; 2056f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2057f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static const int32_t rootSearchOffsets[] = { 2058f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 0, 1,2, 2059f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2, 3,4,4, 2060f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 4, 5,6,6,6, 2061f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 6, 7,8,8,8,8,8,8, 2062f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 8, 9,10,11, 2063f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 12, 13,14,15, 2064f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 16, 17,18,19,20, 2065f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 20, 21,22,22,23,23,23,24, 2066f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 24, 25,26,26,26, 2067f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 26, 27,28,28, 2068f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 28, 2069f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 29 2070f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)}; 2071f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)enum { kLen_rootSearchOffsets = sizeof(rootSearchOffsets)/sizeof(rootSearchOffsets[0]) }; 2072f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2073f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)typedef struct { 2074f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const char * locale; 2075f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const int32_t * offsets; 2076f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t offsetsLen; 2077f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} TSCEItem; 2078f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2079f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static const TSCEItem tsceItems[] = { 2080f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { "root", rootStandardOffsets, kLen_rootStandardOffsets }, 2081f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { "root@collation=search", rootSearchOffsets, kLen_rootSearchOffsets }, 2082f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) { NULL, NULL, 0 } 2083f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)}; 2084f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2085f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)static void TestSearchCollatorElements(void) 2086f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles){ 2087f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const TSCEItem * tsceItemPtr; 2088f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) for (tsceItemPtr = tsceItems; tsceItemPtr->locale != NULL; tsceItemPtr++) { 2089f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UErrorCode status = U_ZERO_ERROR; 2090f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollator* ucol = ucol_open(tsceItemPtr->locale, &status); 2091f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( U_SUCCESS(status) ) { 2092f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) UCollationElements * uce = ucol_openElements(ucol, tsceText, kLen_tsceText, &status); 2093f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( U_SUCCESS(status) ) { 2094f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) int32_t offset, element; 2095f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const int32_t * nextOffsetPtr; 2096f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) const int32_t * limitOffsetPtr; 2097f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2098f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr = tsceItemPtr->offsets; 2099f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) limitOffsetPtr = tsceItemPtr->offsets + tsceItemPtr->offsetsLen; 2100f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) do { 2101f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) offset = ucol_getOffset(uce); 2102f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) element = ucol_next(uce, &status); 2103f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( element == 0 ) { 2104f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_next returned element 0\n", tsceItemPtr->locale ); 2105f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2106f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( nextOffsetPtr < limitOffsetPtr ) { 2107f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (offset != *nextOffsetPtr) { 2108f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, expected ucol_next -> ucol_getOffset %d, got %d\n", 2109f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tsceItemPtr->locale, *nextOffsetPtr, offset ); 2110f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr = limitOffsetPtr; 2111f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 2112f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2113f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr++; 2114f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 2115f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_next returned more elements than expected\n", tsceItemPtr->locale ); 2116f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2117f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } while ( U_SUCCESS(status) && element != UCOL_NULLORDER ); 2118f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( nextOffsetPtr < limitOffsetPtr ) { 2119f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_next returned fewer elements than expected\n", tsceItemPtr->locale ); 2120f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2121f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2122f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_setOffset(uce, kLen_tsceText, &status); 2123f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) status = U_ZERO_ERROR; 2124f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr = tsceItemPtr->offsets + tsceItemPtr->offsetsLen; 2125f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) limitOffsetPtr = tsceItemPtr->offsets; 2126f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) do { 2127f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) offset = ucol_getOffset(uce); 2128f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) element = ucol_previous(uce, &status); 2129f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( element == 0 ) { 2130f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_previous returned element 0\n", tsceItemPtr->locale ); 2131f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2132f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( nextOffsetPtr > limitOffsetPtr ) { 2133f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr--; 2134f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if (offset != *nextOffsetPtr) { 2135f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, expected ucol_previous -> ucol_getOffset %d, got %d\n", 2136f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) tsceItemPtr->locale, *nextOffsetPtr, offset ); 2137f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) nextOffsetPtr = limitOffsetPtr; 2138f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) break; 2139f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2140f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 2141f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_previous returned more elements than expected\n", tsceItemPtr->locale ); 2142f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2143f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } while ( U_SUCCESS(status) && element != UCOL_NULLORDER ); 2144f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) if ( nextOffsetPtr > limitOffsetPtr ) { 2145f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_previous returned fewer elements than expected\n", tsceItemPtr->locale ); 2146f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2147f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2148f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_closeElements(uce); 2149f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 2150f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_openElements failed: %s\n", tsceItemPtr->locale, u_errorName(status) ); 2151f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2152f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) ucol_close(ucol); 2153f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } else { 2154f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) log_err("error, locale %s, ucol_open failed: %s\n", tsceItemPtr->locale, u_errorName(status) ); 2155f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2156f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) } 2157f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)} 2158f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles) 2159f4ed1cf5d184064c4cf0e4359c6d5d8aadb50afaTorne (Richard Coles)#endif /* #if !UCONFIG_NO_COLLATION */ 2160