OLD | NEW |
1 /*******************************************************************************
********* | 1 /*******************************************************************************
********* |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2012, International Business Machines Corporation and | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 * Modification History: | 5 * Modification History: |
6 * | 6 * |
7 * Date Name Description | 7 * Date Name Description |
8 * 05/22/2000 Madhu Added tests for testing new API for utf16 support
and more | 8 * 05/22/2000 Madhu Added tests for testing new API for utf16 support
and more |
9 *******************************************************************************
*********/ | 9 *******************************************************************************
*********/ |
10 | 10 |
11 #include <string.h> | 11 #include <string.h> |
12 #include "utypeinfo.h" // for 'typeid' to work | 12 #include "utypeinfo.h" // for 'typeid' to work |
13 | 13 |
14 #include "unicode/chariter.h" | 14 #include "unicode/chariter.h" |
15 #include "unicode/ustring.h" | 15 #include "unicode/ustring.h" |
16 #include "unicode/unistr.h" | 16 #include "unicode/unistr.h" |
17 #include "unicode/schriter.h" | 17 #include "unicode/schriter.h" |
18 #include "unicode/uchriter.h" | 18 #include "unicode/uchriter.h" |
19 #include "unicode/uiter.h" | 19 #include "unicode/uiter.h" |
20 #include "unicode/putil.h" | 20 #include "unicode/putil.h" |
21 #include "unicode/utf16.h" | 21 #include "unicode/utf16.h" |
22 #include "citrtest.h" | 22 #include "citrtest.h" |
| 23 #include "cmemory.h" |
23 | 24 |
24 | 25 |
25 class SCharacterIterator : public CharacterIterator { | 26 class SCharacterIterator : public CharacterIterator { |
26 public: | 27 public: |
27 SCharacterIterator(const UnicodeString& textStr){ | 28 SCharacterIterator(const UnicodeString& textStr){ |
28 text = textStr; | 29 text = textStr; |
29 pos=0; | 30 pos=0; |
30 textLength = textStr.length(); | 31 textLength = textStr.length(); |
31 begin = 0; | 32 begin = 0; |
32 end=textLength; | 33 end=textLength; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return *this; | 133 return *this; |
133 } | 134 } |
134 | 135 |
135 | 136 |
136 private: | 137 private: |
137 UnicodeString text; | 138 UnicodeString text; |
138 static const char fgClassID; | 139 static const char fgClassID; |
139 }; | 140 }; |
140 const char SCharacterIterator::fgClassID=0; | 141 const char SCharacterIterator::fgClassID=0; |
141 | 142 |
142 #define LENGTHOF(array) ((int32_t)(sizeof(array)/sizeof((array)[0]))) | |
143 | |
144 CharIterTest::CharIterTest() | 143 CharIterTest::CharIterTest() |
145 { | 144 { |
146 } | 145 } |
147 void CharIterTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
char* /*par*/ ) | 146 void CharIterTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
char* /*par*/ ) |
148 { | 147 { |
149 if (exec) logln("TestSuite CharIterTest: "); | 148 if (exec) logln("TestSuite CharIterTest: "); |
150 switch (index) { | 149 switch (index) { |
151 case 0: name = "TestConstructionAndEquality"; if (exec) TestConstruction
AndEquality(); break; | 150 case 0: name = "TestConstructionAndEquality"; if (exec) TestConstruction
AndEquality(); break; |
152 case 1: name = "TestConstructionAndEqualityUChariter"; if (exec) TestCon
structionAndEqualityUChariter(); break; | 151 case 1: name = "TestConstructionAndEqualityUChariter"; if (exec) TestCon
structionAndEqualityUChariter(); break; |
153 case 2: name = "TestIteration"; if (exec) TestIteration(); break; | 152 case 2: name = "TestIteration"; if (exec) TestIteration(); break; |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 errln("error: uiter_getState did not return UITER_NO_STATE on bad input"
); | 959 errln("error: uiter_getState did not return UITER_NO_STATE on bad input"
); |
961 } | 960 } |
962 } | 961 } |
963 | 962 |
964 // subclass test, and completing API coverage ------------------------------- | 963 // subclass test, and completing API coverage ------------------------------- |
965 | 964 |
966 class SubCharIter : public CharacterIterator { | 965 class SubCharIter : public CharacterIterator { |
967 public: | 966 public: |
968 // public default constructor, to get coverage of CharacterIterator() | 967 // public default constructor, to get coverage of CharacterIterator() |
969 SubCharIter() : CharacterIterator() { | 968 SubCharIter() : CharacterIterator() { |
970 textLength=end=LENGTHOF(s); | 969 textLength=end=UPRV_LENGTHOF(s); |
971 s[0]=0x61; // 'a' | 970 s[0]=0x61; // 'a' |
972 s[1]=0xd900; // U+50400 | 971 s[1]=0xd900; // U+50400 |
973 s[2]=0xdd00; | 972 s[2]=0xdd00; |
974 s[3]=0x2029; // PS | 973 s[3]=0x2029; // PS |
975 } | 974 } |
976 | 975 |
977 // useful stuff, mostly dummy but testing coverage and subclassability | 976 // useful stuff, mostly dummy but testing coverage and subclassability |
978 virtual UChar nextPostInc() { | 977 virtual UChar nextPostInc() { |
979 if(pos<LENGTHOF(s)) { | 978 if(pos<UPRV_LENGTHOF(s)) { |
980 return s[pos++]; | 979 return s[pos++]; |
981 } else { | 980 } else { |
982 return DONE; | 981 return DONE; |
983 } | 982 } |
984 } | 983 } |
985 | 984 |
986 virtual UChar32 next32PostInc() { | 985 virtual UChar32 next32PostInc() { |
987 if(pos<LENGTHOF(s)) { | 986 if(pos<UPRV_LENGTHOF(s)) { |
988 UChar32 c; | 987 UChar32 c; |
989 U16_NEXT(s, pos, LENGTHOF(s), c); | 988 U16_NEXT(s, pos, UPRV_LENGTHOF(s), c); |
990 return c; | 989 return c; |
991 } else { | 990 } else { |
992 return DONE; | 991 return DONE; |
993 } | 992 } |
994 } | 993 } |
995 | 994 |
996 virtual UBool hasNext() { | 995 virtual UBool hasNext() { |
997 return pos<LENGTHOF(s); | 996 return pos<UPRV_LENGTHOF(s); |
998 } | 997 } |
999 | 998 |
1000 virtual UChar first() { | 999 virtual UChar first() { |
1001 pos=0; | 1000 pos=0; |
1002 return s[0]; | 1001 return s[0]; |
1003 } | 1002 } |
1004 | 1003 |
1005 virtual UChar32 first32() { | 1004 virtual UChar32 first32() { |
1006 UChar32 c; | 1005 UChar32 c; |
1007 pos=0; | 1006 pos=0; |
1008 U16_NEXT(s, pos, LENGTHOF(s), c); | 1007 U16_NEXT(s, pos, UPRV_LENGTHOF(s), c); |
1009 pos=0; | 1008 pos=0; |
1010 return c; | 1009 return c; |
1011 } | 1010 } |
1012 | 1011 |
1013 virtual UChar setIndex(int32_t position) { | 1012 virtual UChar setIndex(int32_t position) { |
1014 if(0<=position && position<=LENGTHOF(s)) { | 1013 if(0<=position && position<=UPRV_LENGTHOF(s)) { |
1015 pos=position; | 1014 pos=position; |
1016 if(pos<LENGTHOF(s)) { | 1015 if(pos<UPRV_LENGTHOF(s)) { |
1017 return s[pos]; | 1016 return s[pos]; |
1018 } | 1017 } |
1019 } | 1018 } |
1020 return DONE; | 1019 return DONE; |
1021 } | 1020 } |
1022 | 1021 |
1023 virtual UChar32 setIndex32(int32_t position) { | 1022 virtual UChar32 setIndex32(int32_t position) { |
1024 if(0<=position && position<=LENGTHOF(s)) { | 1023 if(0<=position && position<=UPRV_LENGTHOF(s)) { |
1025 pos=position; | 1024 pos=position; |
1026 if(pos<LENGTHOF(s)) { | 1025 if(pos<UPRV_LENGTHOF(s)) { |
1027 UChar32 c; | 1026 UChar32 c; |
1028 U16_GET(s, 0, pos, LENGTHOF(s), c); | 1027 U16_GET(s, 0, pos, UPRV_LENGTHOF(s), c); |
1029 return c; | 1028 return c; |
1030 } | 1029 } |
1031 } | 1030 } |
1032 return DONE; | 1031 return DONE; |
1033 } | 1032 } |
1034 | 1033 |
1035 virtual UChar current() const { | 1034 virtual UChar current() const { |
1036 if(pos<LENGTHOF(s)) { | 1035 if(pos<UPRV_LENGTHOF(s)) { |
1037 return s[pos]; | 1036 return s[pos]; |
1038 } else { | 1037 } else { |
1039 return DONE; | 1038 return DONE; |
1040 } | 1039 } |
1041 } | 1040 } |
1042 | 1041 |
1043 virtual UChar32 current32() const { | 1042 virtual UChar32 current32() const { |
1044 if(pos<LENGTHOF(s)) { | 1043 if(pos<UPRV_LENGTHOF(s)) { |
1045 UChar32 c; | 1044 UChar32 c; |
1046 U16_GET(s, 0, pos, LENGTHOF(s), c); | 1045 U16_GET(s, 0, pos, UPRV_LENGTHOF(s), c); |
1047 return c; | 1046 return c; |
1048 } else { | 1047 } else { |
1049 return DONE; | 1048 return DONE; |
1050 } | 1049 } |
1051 } | 1050 } |
1052 | 1051 |
1053 virtual UChar next() { | 1052 virtual UChar next() { |
1054 if(pos<LENGTHOF(s) && ++pos<LENGTHOF(s)) { | 1053 if(pos<UPRV_LENGTHOF(s) && ++pos<UPRV_LENGTHOF(s)) { |
1055 return s[pos]; | 1054 return s[pos]; |
1056 } else { | 1055 } else { |
1057 return DONE; | 1056 return DONE; |
1058 } | 1057 } |
1059 } | 1058 } |
1060 | 1059 |
1061 virtual UChar32 next32() { | 1060 virtual UChar32 next32() { |
1062 if(pos<LENGTHOF(s)) { | 1061 if(pos<UPRV_LENGTHOF(s)) { |
1063 U16_FWD_1(s, pos, LENGTHOF(s)); | 1062 U16_FWD_1(s, pos, UPRV_LENGTHOF(s)); |
1064 } | 1063 } |
1065 if(pos<LENGTHOF(s)) { | 1064 if(pos<UPRV_LENGTHOF(s)) { |
1066 UChar32 c; | 1065 UChar32 c; |
1067 int32_t i=pos; | 1066 int32_t i=pos; |
1068 U16_NEXT(s, i, LENGTHOF(s), c); | 1067 U16_NEXT(s, i, UPRV_LENGTHOF(s), c); |
1069 return c; | 1068 return c; |
1070 } else { | 1069 } else { |
1071 return DONE; | 1070 return DONE; |
1072 } | 1071 } |
1073 } | 1072 } |
1074 | 1073 |
1075 virtual UBool hasPrevious() { | 1074 virtual UBool hasPrevious() { |
1076 return pos>0; | 1075 return pos>0; |
1077 } | 1076 } |
1078 | 1077 |
1079 virtual void getText(UnicodeString &result) { | 1078 virtual void getText(UnicodeString &result) { |
1080 result.setTo(s, LENGTHOF(s)); | 1079 result.setTo(s, UPRV_LENGTHOF(s)); |
1081 } | 1080 } |
1082 | 1081 |
1083 // dummy implementations of other pure virtual base class functions | 1082 // dummy implementations of other pure virtual base class functions |
1084 virtual UBool operator==(const ForwardCharacterIterator &that) const { | 1083 virtual UBool operator==(const ForwardCharacterIterator &that) const { |
1085 return | 1084 return |
1086 this==&that || | 1085 this==&that || |
1087 (typeid(*this)==typeid(that) && pos==((SubCharIter &)that).pos); | 1086 (typeid(*this)==typeid(that) && pos==((SubCharIter &)that).pos); |
1088 } | 1087 } |
1089 | 1088 |
1090 virtual int32_t hashCode() const { | 1089 virtual int32_t hashCode() const { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 if(sci.firstPostInc()!=0x61) { | 1178 if(sci.firstPostInc()!=0x61) { |
1180 errln("SubStringCharIter.firstPostInc() failed\n"); | 1179 errln("SubStringCharIter.firstPostInc() failed\n"); |
1181 } | 1180 } |
1182 | 1181 |
1183 // coverage: UCharCharacterIterator default constructor | 1182 // coverage: UCharCharacterIterator default constructor |
1184 SubUCharCharIter uci; | 1183 SubUCharCharIter uci; |
1185 if(uci.firstPostInc()!=0x61) { | 1184 if(uci.firstPostInc()!=0x61) { |
1186 errln("SubUCharCharIter.firstPostInc() failed\n"); | 1185 errln("SubUCharCharIter.firstPostInc() failed\n"); |
1187 } | 1186 } |
1188 } | 1187 } |
OLD | NEW |