Lines 1-148
Link Here
|
1 |
https://ssl.icu-project.org/trac/ticket/12827 |
|
|
2 |
|
3 |
Index: test/intltest/apicoll.h |
4 |
=================================================================== |
5 |
--- test/intltest/apicoll.h (revision 39483) |
6 |
+++ test/intltest/apicoll.h (revision 39484) |
7 |
@@ -35,6 +35,7 @@ class CollationAPITest: public IntlTestCollator { |
8 |
* - displayable name in the desired locale |
9 |
*/ |
10 |
void TestProperty(/* char* par */); |
11 |
+ void TestKeywordValues(); |
12 |
|
13 |
/** |
14 |
* This tests the RuleBasedCollator |
15 |
Index: test/intltest/apicoll.cpp |
16 |
=================================================================== |
17 |
--- test/intltest/apicoll.cpp (revision 39483) |
18 |
+++ test/intltest/apicoll.cpp (revision 39484) |
19 |
@@ -81,17 +81,10 @@ CollationAPITest::TestProperty(/* char* par */) |
20 |
logln("Test ctors : "); |
21 |
col = Collator::createInstance(Locale::getEnglish(), success); |
22 |
if (U_FAILURE(success)){ |
23 |
- errcheckln(success, "Default Collator creation failed. - %s", u_errorName(success)); |
24 |
+ errcheckln(success, "English Collator creation failed. - %s", u_errorName(success)); |
25 |
return; |
26 |
} |
27 |
|
28 |
- StringEnumeration* kwEnum = col->getKeywordValuesForLocale("", Locale::getEnglish(),true,success); |
29 |
- if (U_FAILURE(success)){ |
30 |
- errcheckln(success, "Get Keyword Values for Locale failed. - %s", u_errorName(success)); |
31 |
- return; |
32 |
- } |
33 |
- delete kwEnum; |
34 |
- |
35 |
col->getVersion(versionArray); |
36 |
// Check for a version greater than some value rather than equality |
37 |
// so that we need not update the expected version each time. |
38 |
@@ -231,6 +224,29 @@ CollationAPITest::TestProperty(/* char* par */) |
39 |
delete junk; |
40 |
} |
41 |
|
42 |
+void CollationAPITest::TestKeywordValues() { |
43 |
+ IcuTestErrorCode errorCode(*this, "TestKeywordValues"); |
44 |
+ LocalPointer<Collator> col(Collator::createInstance(Locale::getEnglish(), errorCode)); |
45 |
+ if (errorCode.logIfFailureAndReset("English Collator creation failed")) { |
46 |
+ return; |
47 |
+ } |
48 |
+ |
49 |
+ LocalPointer<StringEnumeration> kwEnum( |
50 |
+ col->getKeywordValuesForLocale("collation", Locale::getEnglish(), TRUE, errorCode)); |
51 |
+ if (errorCode.logIfFailureAndReset("Get Keyword Values for English Collator failed")) { |
52 |
+ return; |
53 |
+ } |
54 |
+ assertTrue("expect at least one collation tailoring for English", kwEnum->count(errorCode) > 0); |
55 |
+ const char *kw; |
56 |
+ UBool hasStandard = FALSE; |
57 |
+ while ((kw = kwEnum->next(NULL, errorCode)) != NULL) { |
58 |
+ if (strcmp(kw, "standard") == 0) { |
59 |
+ hasStandard = TRUE; |
60 |
+ } |
61 |
+ } |
62 |
+ assertTrue("expect at least the 'standard' collation tailoring for English", hasStandard); |
63 |
+} |
64 |
+ |
65 |
void |
66 |
CollationAPITest::TestRuleBasedColl() |
67 |
{ |
68 |
@@ -2466,6 +2482,7 @@ void CollationAPITest::runIndexedTest( int32_t ind |
69 |
if (exec) logln("TestSuite CollationAPITest: "); |
70 |
TESTCASE_AUTO_BEGIN; |
71 |
TESTCASE_AUTO(TestProperty); |
72 |
+ TESTCASE_AUTO(TestKeywordValues); |
73 |
TESTCASE_AUTO(TestOperators); |
74 |
TESTCASE_AUTO(TestDuplicate); |
75 |
TESTCASE_AUTO(TestCompare); |
76 |
Index: i18n/ucol_res.cpp |
77 |
=================================================================== |
78 |
--- i18n/ucol_res.cpp (revision 39483) |
79 |
+++ i18n/ucol_res.cpp (revision 39484) |
80 |
@@ -680,6 +680,7 @@ ucol_getKeywordValuesForLocale(const char* /*key*/ |
81 |
return NULL; |
82 |
} |
83 |
memcpy(en, &defaultKeywordValues, sizeof(UEnumeration)); |
84 |
+ ulist_resetList(sink.values); // Initialize the iterator. |
85 |
en->context = sink.values; |
86 |
sink.values = NULL; // Avoid deletion in the sink destructor. |
87 |
return en; |
88 |
Index: common/ulist.c |
89 |
=================================================================== |
90 |
--- common/ulist.c (revision 39483) |
91 |
+++ common/ulist.c (revision 39484) |
92 |
@@ -29,7 +29,6 @@ struct UList { |
93 |
UListNode *tail; |
94 |
|
95 |
int32_t size; |
96 |
- int32_t currentIndex; |
97 |
}; |
98 |
|
99 |
static void ulist_addFirstItem(UList *list, UListNode *newItem); |
100 |
@@ -51,7 +50,6 @@ U_CAPI UList *U_EXPORT2 ulist_createEmptyList(UErr |
101 |
newList->head = NULL; |
102 |
newList->tail = NULL; |
103 |
newList->size = 0; |
104 |
- newList->currentIndex = -1; |
105 |
|
106 |
return newList; |
107 |
} |
108 |
@@ -80,8 +78,9 @@ static void ulist_removeItem(UList *list, UListNod |
109 |
} else { |
110 |
p->next->previous = p->previous; |
111 |
} |
112 |
- list->curr = NULL; |
113 |
- list->currentIndex = 0; |
114 |
+ if (p == list->curr) { |
115 |
+ list->curr = p->next; |
116 |
+ } |
117 |
--list->size; |
118 |
if (p->forceDelete) { |
119 |
uprv_free(p->data); |
120 |
@@ -150,7 +149,6 @@ U_CAPI void U_EXPORT2 ulist_addItemBeginList(UList |
121 |
newItem->next = list->head; |
122 |
list->head->previous = newItem; |
123 |
list->head = newItem; |
124 |
- list->currentIndex++; |
125 |
} |
126 |
|
127 |
list->size++; |
128 |
@@ -193,7 +191,6 @@ U_CAPI void *U_EXPORT2 ulist_getNext(UList *list) |
129 |
|
130 |
curr = list->curr; |
131 |
list->curr = curr->next; |
132 |
- list->currentIndex++; |
133 |
|
134 |
return curr->data; |
135 |
} |
136 |
@@ -209,7 +206,6 @@ U_CAPI int32_t U_EXPORT2 ulist_getListSize(const U |
137 |
U_CAPI void U_EXPORT2 ulist_resetList(UList *list) { |
138 |
if (list != NULL) { |
139 |
list->curr = list->head; |
140 |
- list->currentIndex = 0; |
141 |
} |
142 |
} |
143 |
|
144 |
@@ -272,4 +268,3 @@ U_CAPI void U_EXPORT2 ulist_reset_keyword_values_i |
145 |
U_CAPI UList * U_EXPORT2 ulist_getListFromEnum(UEnumeration *en) { |
146 |
return (UList *)(en->context); |
147 |
} |
148 |
- |