diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/test/llstring_tut.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/llstring_tut.cpp | 544 |
1 files changed, 357 insertions, 187 deletions
diff --git a/linden/indra/test/llstring_tut.cpp b/linden/indra/test/llstring_tut.cpp index 16569ea..191b804 100644 --- a/linden/indra/test/llstring_tut.cpp +++ b/linden/indra/test/llstring_tut.cpp | |||
@@ -31,9 +31,10 @@ | |||
31 | * $/LicenseInfo$ | 31 | * $/LicenseInfo$ |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include "linden_common.h" | ||
35 | |||
34 | #include <tut/tut.h> | 36 | #include <tut/tut.h> |
35 | #include "lltut.h" | 37 | #include "lltut.h" |
36 | #include "linden_common.h" | ||
37 | #include "llstring.h" | 38 | #include "llstring.h" |
38 | 39 | ||
39 | namespace tut | 40 | namespace tut |
@@ -48,455 +49,624 @@ namespace tut | |||
48 | template<> template<> | 49 | template<> template<> |
49 | void string_index_object_t::test<1>() | 50 | void string_index_object_t::test<1>() |
50 | { | 51 | { |
51 | LLString llstr1; | 52 | std::string llstr1; |
52 | ensure("Empty LLString", (llstr1.size() == 0) && llstr1.empty()); | 53 | ensure("Empty std::string", (llstr1.size() == 0) && llstr1.empty()); |
53 | 54 | ||
54 | LLString llstr2("Hello"); | 55 | std::string llstr2("Hello"); |
55 | ensure("LLString = Hello", (!strcmp(llstr2.c_str(), "Hello")) && (llstr2.size() == 5) && !llstr2.empty()); | 56 | ensure("std::string = Hello", (!strcmp(llstr2.c_str(), "Hello")) && (llstr2.size() == 5) && !llstr2.empty()); |
56 | 57 | ||
57 | LLString llstr3(llstr2); | 58 | std::string llstr3(llstr2); |
58 | ensure("LLString = LLString(LLString)", (!strcmp(llstr3.c_str(), "Hello")) && (llstr3.size() == 5) && !llstr3.empty()); | 59 | ensure("std::string = std::string(std::string)", (!strcmp(llstr3.c_str(), "Hello")) && (llstr3.size() == 5) && !llstr3.empty()); |
59 | 60 | ||
60 | std::string str("Hello World"); | 61 | std::string str("Hello World"); |
61 | LLString llstr4(str, 6); | 62 | std::string llstr4(str, 6); |
62 | ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (!strcmp(llstr4.c_str(), "World")) && (llstr4.size() == 5) && !llstr4.empty()); | 63 | ensure("std::string = std::string(s, size_type pos, size_type n = npos)", (!strcmp(llstr4.c_str(), "World")) && (llstr4.size() == 5) && !llstr4.empty()); |
63 | 64 | ||
64 | LLString llstr5(str, str.size()); | 65 | std::string llstr5(str, str.size()); |
65 | ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (llstr5.size() == 0) && llstr5.empty()); | 66 | ensure("std::string = std::string(s, size_type pos, size_type n = npos)", (llstr5.size() == 0) && llstr5.empty()); |
66 | 67 | ||
67 | LLString llstr6(5, 'A'); | 68 | std::string llstr6(5, 'A'); |
68 | ensure("LLString = LLString(count, c)", (!strcmp(llstr6.c_str(), "AAAAA")) && (llstr6.size() == 5) && !llstr6.empty()); | 69 | ensure("std::string = std::string(count, c)", (!strcmp(llstr6.c_str(), "AAAAA")) && (llstr6.size() == 5) && !llstr6.empty()); |
69 | 70 | ||
70 | LLString llstr7("Hello World", 5); | 71 | std::string llstr7("Hello World", 5); |
71 | ensure("LLString(s, n)", (!strcmp(llstr7.c_str(), "Hello")) && (llstr7.size() == 5) && !llstr7.empty()); | 72 | ensure("std::string(s, n)", (!strcmp(llstr7.c_str(), "Hello")) && (llstr7.size() == 5) && !llstr7.empty()); |
72 | 73 | ||
73 | LLString llstr8("Hello World", 6, 5); | 74 | std::string llstr8("Hello World", 6, 5); |
74 | ensure("LLString(s, n, count)", (!strcmp(llstr8.c_str(), "World")) && (llstr8.size() == 5) && !llstr8.empty()); | 75 | ensure("std::string(s, n, count)", (!strcmp(llstr8.c_str(), "World")) && (llstr8.size() == 5) && !llstr8.empty()); |
75 | 76 | ||
76 | LLString llstr9("Hello World", sizeof("Hello World")-1, 5); // go past end | 77 | std::string llstr9("Hello World", sizeof("Hello World")-1, 5); // go past end |
77 | ensure("LLString(s, n, count) goes past end", (llstr9.size() == 0) && llstr9.empty()); | 78 | ensure("std::string(s, n, count) goes past end", (llstr9.size() == 0) && llstr9.empty()); |
78 | } | 79 | } |
79 | 80 | ||
80 | template<> template<> | 81 | template<> template<> |
81 | void string_index_object_t::test<2>() | 82 | void string_index_object_t::test<3>() |
82 | { | 83 | { |
83 | LLString str("Len=5"); | 84 | std::string str("Len=5"); |
84 | ensure("isValidIndex failed", LLString::isValidIndex(str, 0) == TRUE && | 85 | ensure("isValidIndex failed", LLStringUtil::isValidIndex(str, 0) == TRUE && |
85 | LLString::isValidIndex(str, 5) == TRUE && | 86 | LLStringUtil::isValidIndex(str, 5) == TRUE && |
86 | LLString::isValidIndex(str, 6) == FALSE); | 87 | LLStringUtil::isValidIndex(str, 6) == FALSE); |
87 | 88 | ||
88 | LLString str1; | 89 | std::string str1; |
89 | ensure("isValidIndex failed fo rempty string", LLString::isValidIndex(str1, 0) == FALSE); | 90 | ensure("isValidIndex failed fo rempty string", LLStringUtil::isValidIndex(str1, 0) == FALSE); |
90 | } | 91 | } |
91 | 92 | ||
92 | template<> template<> | 93 | template<> template<> |
93 | void string_index_object_t::test<3>() | 94 | void string_index_object_t::test<4>() |
94 | { | 95 | { |
95 | LLString str_val(" Testing the extra whitespaces "); | 96 | std::string str_val(" Testing the extra whitespaces "); |
96 | LLString::trimHead(str_val); | 97 | LLStringUtil::trimHead(str_val); |
97 | ensure_equals("1: trimHead failed", str_val, "Testing the extra whitespaces "); | 98 | ensure_equals("1: trimHead failed", str_val, "Testing the extra whitespaces "); |
98 | 99 | ||
99 | LLString str_val1("\n\t\r\n Testing the extra whitespaces "); | 100 | std::string str_val1("\n\t\r\n Testing the extra whitespaces "); |
100 | LLString::trimHead(str_val1); | 101 | LLStringUtil::trimHead(str_val1); |
101 | ensure_equals("2: trimHead failed", str_val1, "Testing the extra whitespaces "); | 102 | ensure_equals("2: trimHead failed", str_val1, "Testing the extra whitespaces "); |
102 | } | 103 | } |
103 | 104 | ||
104 | template<> template<> | 105 | template<> template<> |
105 | void string_index_object_t::test<4>() | 106 | void string_index_object_t::test<5>() |
106 | { | 107 | { |
107 | LLString str_val(" Testing the extra whitespaces "); | 108 | std::string str_val(" Testing the extra whitespaces "); |
108 | LLString::trimTail(str_val); | 109 | LLStringUtil::trimTail(str_val); |
109 | ensure_equals("1: trimTail failed", str_val, " Testing the extra whitespaces"); | 110 | ensure_equals("1: trimTail failed", str_val, " Testing the extra whitespaces"); |
110 | 111 | ||
111 | LLString str_val1("\n Testing the extra whitespaces \n\t\r\n "); | 112 | std::string str_val1("\n Testing the extra whitespaces \n\t\r\n "); |
112 | LLString::trimTail(str_val1); | 113 | LLStringUtil::trimTail(str_val1); |
113 | ensure_equals("2: trimTail failed", str_val1, "\n Testing the extra whitespaces"); | 114 | ensure_equals("2: trimTail failed", str_val1, "\n Testing the extra whitespaces"); |
114 | } | 115 | } |
115 | 116 | ||
116 | 117 | ||
117 | template<> template<> | 118 | template<> template<> |
118 | void string_index_object_t::test<5>() | 119 | void string_index_object_t::test<6>() |
119 | { | 120 | { |
120 | LLString str_val(" \t \r Testing the extra \r\n whitespaces \n \t "); | 121 | std::string str_val(" \t \r Testing the extra \r\n whitespaces \n \t "); |
121 | LLString::trim(str_val); | 122 | LLStringUtil::trim(str_val); |
122 | ensure_equals("1: trim failed", str_val, "Testing the extra \r\n whitespaces"); | 123 | ensure_equals("1: trim failed", str_val, "Testing the extra \r\n whitespaces"); |
123 | } | 124 | } |
124 | 125 | ||
125 | template<> template<> | 126 | template<> template<> |
126 | void string_index_object_t::test<6>() | 127 | void string_index_object_t::test<7>() |
127 | { | 128 | { |
128 | LLString str("Second LindenLabs"); | 129 | std::string str("Second LindenLabs"); |
129 | LLString::truncate(str, 6); | 130 | LLStringUtil::truncate(str, 6); |
130 | ensure_equals("1: truncate", str, "Second"); | 131 | ensure_equals("1: truncate", str, "Second"); |
131 | 132 | ||
132 | // further truncate more than the length | 133 | // further truncate more than the length |
133 | LLString::truncate(str, 0); | 134 | LLStringUtil::truncate(str, 0); |
134 | ensure_equals("2: truncate", str, ""); | 135 | ensure_equals("2: truncate", str, ""); |
135 | } | 136 | } |
136 | 137 | ||
137 | template<> template<> | 138 | template<> template<> |
138 | void string_index_object_t::test<7>() | 139 | void string_index_object_t::test<8>() |
139 | { | 140 | { |
140 | LLString str_val("SecondLife Source"); | 141 | std::string str_val("SecondLife Source"); |
141 | LLString::toUpper(str_val); | 142 | LLStringUtil::toUpper(str_val); |
142 | ensure_equals("toUpper failed", str_val, "SECONDLIFE SOURCE"); | 143 | ensure_equals("toUpper failed", str_val, "SECONDLIFE SOURCE"); |
143 | } | 144 | } |
144 | 145 | ||
145 | template<> template<> | 146 | template<> template<> |
146 | void string_index_object_t::test<8>() | 147 | void string_index_object_t::test<9>() |
147 | { | 148 | { |
148 | LLString str_val("SecondLife Source"); | 149 | std::string str_val("SecondLife Source"); |
149 | LLString::toLower(str_val); | 150 | LLStringUtil::toLower(str_val); |
150 | ensure_equals("toLower failed", str_val, "secondlife source"); | 151 | ensure_equals("toLower failed", str_val, "secondlife source"); |
151 | } | 152 | } |
152 | 153 | ||
153 | template<> template<> | 154 | template<> template<> |
154 | void string_index_object_t::test<9>() | 155 | void string_index_object_t::test<10>() |
155 | { | 156 | { |
156 | LLString str_val("Second"); | 157 | std::string str_val("Second"); |
157 | ensure("1. isHead failed", LLString::isHead(str_val, "SecondLife Source") == TRUE); | 158 | ensure("1. isHead failed", LLStringUtil::isHead(str_val, "SecondLife Source") == TRUE); |
158 | ensure("2. isHead failed", LLString::isHead(str_val, " SecondLife Source") == FALSE); | 159 | ensure("2. isHead failed", LLStringUtil::isHead(str_val, " SecondLife Source") == FALSE); |
159 | LLString str_val2(""); | 160 | std::string str_val2(""); |
160 | ensure("3. isHead failed", LLString::isHead(str_val2, "") == FALSE); | 161 | ensure("3. isHead failed", LLStringUtil::isHead(str_val2, "") == FALSE); |
161 | } | 162 | } |
162 | 163 | ||
163 | template<> template<> | 164 | template<> template<> |
164 | void string_index_object_t::test<10>() | 165 | void string_index_object_t::test<11>() |
165 | { | 166 | { |
166 | LLString str_val("Hello.\n\n Lindenlabs. \n This is \na simple test.\n"); | 167 | std::string str_val("Hello.\n\n Lindenlabs. \n This is \na simple test.\n"); |
167 | LLString orig_str_val(str_val); | 168 | std::string orig_str_val(str_val); |
168 | LLString::addCRLF(str_val); | 169 | LLStringUtil::addCRLF(str_val); |
169 | ensure_equals("addCRLF failed", str_val, "Hello.\r\n\r\n Lindenlabs. \r\n This is \r\na simple test.\r\n"); | 170 | ensure_equals("addCRLF failed", str_val, "Hello.\r\n\r\n Lindenlabs. \r\n This is \r\na simple test.\r\n"); |
170 | LLString::removeCRLF(str_val); | 171 | LLStringUtil::removeCRLF(str_val); |
171 | ensure_equals("removeCRLF failed", str_val, orig_str_val); | 172 | ensure_equals("removeCRLF failed", str_val, orig_str_val); |
172 | } | 173 | } |
173 | 174 | ||
174 | template<> template<> | 175 | template<> template<> |
175 | void string_index_object_t::test<11>() | 176 | void string_index_object_t::test<12>() |
176 | { | 177 | { |
177 | LLString str_val("Hello.\n\n\t \t Lindenlabs. \t\t"); | 178 | std::string str_val("Hello.\n\n\t \t Lindenlabs. \t\t"); |
178 | LLString orig_str_val(str_val); | 179 | std::string orig_str_val(str_val); |
179 | LLString::replaceTabsWithSpaces(str_val, 1); | 180 | LLStringUtil::replaceTabsWithSpaces(str_val, 1); |
180 | ensure_equals("replaceTabsWithSpaces failed", str_val, "Hello.\n\n Lindenlabs. "); | 181 | ensure_equals("replaceTabsWithSpaces failed", str_val, "Hello.\n\n Lindenlabs. "); |
181 | LLString::replaceTabsWithSpaces(orig_str_val, 0); | 182 | LLStringUtil::replaceTabsWithSpaces(orig_str_val, 0); |
182 | ensure_equals("replaceTabsWithSpaces failed for 0", orig_str_val, "Hello.\n\n Lindenlabs. "); | 183 | ensure_equals("replaceTabsWithSpaces failed for 0", orig_str_val, "Hello.\n\n Lindenlabs. "); |
183 | 184 | ||
184 | str_val = "\t\t\t\t"; | 185 | str_val = "\t\t\t\t"; |
185 | LLString::replaceTabsWithSpaces(str_val, 0); | 186 | LLStringUtil::replaceTabsWithSpaces(str_val, 0); |
186 | ensure_equals("replaceTabsWithSpaces failed for all tabs", str_val, ""); | 187 | ensure_equals("replaceTabsWithSpaces failed for all tabs", str_val, ""); |
187 | } | 188 | } |
188 | 189 | ||
189 | template<> template<> | 190 | template<> template<> |
190 | void string_index_object_t::test<12>() | 191 | void string_index_object_t::test<13>() |
191 | { | 192 | { |
192 | LLString str_val("Hello.\n\n\t\t\r\nLindenlabsX."); | 193 | std::string str_val("Hello.\n\n\t\t\r\nLindenlabsX."); |
193 | LLString::replaceNonstandardASCII(str_val, 'X'); | 194 | LLStringUtil::replaceNonstandardASCII(str_val, 'X'); |
194 | ensure_equals("replaceNonstandardASCII failed", str_val, "Hello.\n\nXXX\nLindenlabsX."); | 195 | ensure_equals("replaceNonstandardASCII failed", str_val, "Hello.\n\nXXX\nLindenlabsX."); |
195 | } | 196 | } |
196 | 197 | ||
197 | template<> template<> | 198 | template<> template<> |
198 | void string_index_object_t::test<13>() | 199 | void string_index_object_t::test<14>() |
199 | { | 200 | { |
200 | LLString str_val("Hello.\n\t\r\nABCDEFGHIABABAB"); | 201 | std::string str_val("Hello.\n\t\r\nABCDEFGHIABABAB"); |
201 | LLString::replaceChar(str_val, 'A', 'X'); | 202 | LLStringUtil::replaceChar(str_val, 'A', 'X'); |
202 | ensure_equals("1: replaceChar failed", str_val, "Hello.\n\t\r\nXBCDEFGHIXBXBXB"); | 203 | ensure_equals("1: replaceChar failed", str_val, "Hello.\n\t\r\nXBCDEFGHIXBXBXB"); |
203 | LLString str_val1("Hello.\n\t\r\nABCDEFGHIABABAB"); | 204 | std::string str_val1("Hello.\n\t\r\nABCDEFGHIABABAB"); |
204 | } | 205 | } |
205 | 206 | ||
206 | template<> template<> | 207 | template<> template<> |
207 | void string_index_object_t::test<14>() | 208 | void string_index_object_t::test<15>() |
208 | { | 209 | { |
209 | LLString str_val("Hello.\n\r\t"); | 210 | std::string str_val("Hello.\n\r\t"); |
210 | ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == TRUE); | 211 | ensure("containsNonprintable failed", LLStringUtil::containsNonprintable(str_val) == TRUE); |
211 | 212 | ||
212 | str_val = "ABC "; | 213 | str_val = "ABC "; |
213 | ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == FALSE); | 214 | ensure("containsNonprintable failed", LLStringUtil::containsNonprintable(str_val) == FALSE); |
214 | } | 215 | } |
215 | 216 | ||
216 | template<> template<> | 217 | template<> template<> |
217 | void string_index_object_t::test<15>() | 218 | void string_index_object_t::test<16>() |
218 | { | 219 | { |
219 | LLString str_val("Hello.\n\r\t Again!"); | 220 | std::string str_val("Hello.\n\r\t Again!"); |
220 | LLString::stripNonprintable(str_val); | 221 | LLStringUtil::stripNonprintable(str_val); |
221 | ensure_equals("stripNonprintable failed", str_val, "Hello. Again!"); | 222 | ensure_equals("stripNonprintable failed", str_val, "Hello. Again!"); |
222 | 223 | ||
223 | str_val = "\r\n\t\t"; | 224 | str_val = "\r\n\t\t"; |
224 | LLString::stripNonprintable(str_val); | 225 | LLStringUtil::stripNonprintable(str_val); |
225 | ensure_equals("stripNonprintable resulting in empty string failed", str_val, ""); | 226 | ensure_equals("stripNonprintable resulting in empty string failed", str_val, ""); |
226 | } | 227 | } |
227 | 228 | ||
228 | template<> template<> | 229 | template<> template<> |
229 | void string_index_object_t::test<16>() | 230 | void string_index_object_t::test<17>() |
230 | { | 231 | { |
231 | BOOL value; | 232 | BOOL value; |
232 | LLString str_val("1"); | 233 | std::string str_val("1"); |
233 | ensure("convertToBOOL 1 failed", LLString::convertToBOOL(str_val, value) && value); | 234 | ensure("convertToBOOL 1 failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
234 | str_val = "T"; | 235 | str_val = "T"; |
235 | ensure("convertToBOOL T failed", LLString::convertToBOOL(str_val, value) && value); | 236 | ensure("convertToBOOL T failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
236 | str_val = "t"; | 237 | str_val = "t"; |
237 | ensure("convertToBOOL t failed", LLString::convertToBOOL(str_val, value) && value); | 238 | ensure("convertToBOOL t failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
238 | str_val = "TRUE"; | 239 | str_val = "TRUE"; |
239 | ensure("convertToBOOL TRUE failed", LLString::convertToBOOL(str_val, value) && value); | 240 | ensure("convertToBOOL TRUE failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
240 | str_val = "True"; | 241 | str_val = "True"; |
241 | ensure("convertToBOOL True failed", LLString::convertToBOOL(str_val, value) && value); | 242 | ensure("convertToBOOL True failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
242 | str_val = "true"; | 243 | str_val = "true"; |
243 | ensure("convertToBOOL true failed", LLString::convertToBOOL(str_val, value) && value); | 244 | ensure("convertToBOOL true failed", LLStringUtil::convertToBOOL(str_val, value) && value); |
244 | 245 | ||
245 | str_val = "0"; | 246 | str_val = "0"; |
246 | ensure("convertToBOOL 0 failed", LLString::convertToBOOL(str_val, value) && !value); | 247 | ensure("convertToBOOL 0 failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
247 | str_val = "F"; | 248 | str_val = "F"; |
248 | ensure("convertToBOOL F failed", LLString::convertToBOOL(str_val, value) && !value); | 249 | ensure("convertToBOOL F failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
249 | str_val = "f"; | 250 | str_val = "f"; |
250 | ensure("convertToBOOL f failed", LLString::convertToBOOL(str_val, value) && !value); | 251 | ensure("convertToBOOL f failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
251 | str_val = "FALSE"; | 252 | str_val = "FALSE"; |
252 | ensure("convertToBOOL FASLE failed", LLString::convertToBOOL(str_val, value) && !value); | 253 | ensure("convertToBOOL FASLE failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
253 | str_val = "False"; | 254 | str_val = "False"; |
254 | ensure("convertToBOOL False failed", LLString::convertToBOOL(str_val, value) && !value); | 255 | ensure("convertToBOOL False failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
255 | str_val = "false"; | 256 | str_val = "false"; |
256 | ensure("convertToBOOL false failed", LLString::convertToBOOL(str_val, value) && !value); | 257 | ensure("convertToBOOL false failed", LLStringUtil::convertToBOOL(str_val, value) && !value); |
257 | 258 | ||
258 | str_val = "Tblah"; | 259 | str_val = "Tblah"; |
259 | ensure("convertToBOOL false failed", !LLString::convertToBOOL(str_val, value)); | 260 | ensure("convertToBOOL false failed", !LLStringUtil::convertToBOOL(str_val, value)); |
260 | } | 261 | } |
261 | 262 | ||
262 | template<> template<> | 263 | template<> template<> |
263 | void string_index_object_t::test<17>() | 264 | void string_index_object_t::test<18>() |
264 | { | 265 | { |
265 | U8 value; | 266 | U8 value; |
266 | LLString str_val("255"); | 267 | std::string str_val("255"); |
267 | ensure("1: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 255); | 268 | ensure("1: convertToU8 failed", LLStringUtil::convertToU8(str_val, value) && value == 255); |
268 | 269 | ||
269 | str_val = "0"; | 270 | str_val = "0"; |
270 | ensure("2: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 0); | 271 | ensure("2: convertToU8 failed", LLStringUtil::convertToU8(str_val, value) && value == 0); |
271 | 272 | ||
272 | str_val = "-1"; | 273 | str_val = "-1"; |
273 | ensure("3: convertToU8 failed", !LLString::convertToU8(str_val, value)); | 274 | ensure("3: convertToU8 failed", !LLStringUtil::convertToU8(str_val, value)); |
274 | 275 | ||
275 | str_val = "256"; // bigger than MAX_U8 | 276 | str_val = "256"; // bigger than MAX_U8 |
276 | ensure("4: convertToU8 failed", !LLString::convertToU8(str_val, value)); | 277 | ensure("4: convertToU8 failed", !LLStringUtil::convertToU8(str_val, value)); |
277 | } | 278 | } |
278 | 279 | ||
279 | template<> template<> | 280 | template<> template<> |
280 | void string_index_object_t::test<18>() | 281 | void string_index_object_t::test<19>() |
281 | { | 282 | { |
282 | S8 value; | 283 | S8 value; |
283 | LLString str_val("127"); | 284 | std::string str_val("127"); |
284 | ensure("1: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 127); | 285 | ensure("1: convertToS8 failed", LLStringUtil::convertToS8(str_val, value) && value == 127); |
285 | 286 | ||
286 | str_val = "0"; | 287 | str_val = "0"; |
287 | ensure("2: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 0); | 288 | ensure("2: convertToS8 failed", LLStringUtil::convertToS8(str_val, value) && value == 0); |
288 | 289 | ||
289 | str_val = "-128"; | 290 | str_val = "-128"; |
290 | ensure("3: convertToS8 failed", LLString::convertToS8(str_val, value) && value == -128); | 291 | ensure("3: convertToS8 failed", LLStringUtil::convertToS8(str_val, value) && value == -128); |
291 | 292 | ||
292 | str_val = "128"; // bigger than MAX_S8 | 293 | str_val = "128"; // bigger than MAX_S8 |
293 | ensure("4: convertToS8 failed", !LLString::convertToS8(str_val, value)); | 294 | ensure("4: convertToS8 failed", !LLStringUtil::convertToS8(str_val, value)); |
294 | 295 | ||
295 | str_val = "-129"; | 296 | str_val = "-129"; |
296 | ensure("5: convertToS8 failed", !LLString::convertToS8(str_val, value)); | 297 | ensure("5: convertToS8 failed", !LLStringUtil::convertToS8(str_val, value)); |
297 | } | 298 | } |
298 | 299 | ||
299 | template<> template<> | 300 | template<> template<> |
300 | void string_index_object_t::test<19>() | 301 | void string_index_object_t::test<20>() |
301 | { | 302 | { |
302 | S16 value; | 303 | S16 value; |
303 | LLString str_val("32767"); | 304 | std::string str_val("32767"); |
304 | ensure("1: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 32767); | 305 | ensure("1: convertToS16 failed", LLStringUtil::convertToS16(str_val, value) && value == 32767); |
305 | 306 | ||
306 | str_val = "0"; | 307 | str_val = "0"; |
307 | ensure("2: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 0); | 308 | ensure("2: convertToS16 failed", LLStringUtil::convertToS16(str_val, value) && value == 0); |
308 | 309 | ||
309 | str_val = "-32768"; | 310 | str_val = "-32768"; |
310 | ensure("3: convertToS16 failed", LLString::convertToS16(str_val, value) && value == -32768); | 311 | ensure("3: convertToS16 failed", LLStringUtil::convertToS16(str_val, value) && value == -32768); |
311 | 312 | ||
312 | str_val = "32768"; | 313 | str_val = "32768"; |
313 | ensure("4: convertToS16 failed", !LLString::convertToS16(str_val, value)); | 314 | ensure("4: convertToS16 failed", !LLStringUtil::convertToS16(str_val, value)); |
314 | 315 | ||
315 | str_val = "-32769"; | 316 | str_val = "-32769"; |
316 | ensure("5: convertToS16 failed", !LLString::convertToS16(str_val, value)); | 317 | ensure("5: convertToS16 failed", !LLStringUtil::convertToS16(str_val, value)); |
317 | } | 318 | } |
318 | 319 | ||
319 | template<> template<> | 320 | template<> template<> |
320 | void string_index_object_t::test<20>() | 321 | void string_index_object_t::test<21>() |
321 | { | 322 | { |
322 | U16 value; | 323 | U16 value; |
323 | LLString str_val("65535"); //0xFFFF | 324 | std::string str_val("65535"); //0xFFFF |
324 | ensure("1: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 65535); | 325 | ensure("1: convertToU16 failed", LLStringUtil::convertToU16(str_val, value) && value == 65535); |
325 | 326 | ||
326 | str_val = "0"; | 327 | str_val = "0"; |
327 | ensure("2: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 0); | 328 | ensure("2: convertToU16 failed", LLStringUtil::convertToU16(str_val, value) && value == 0); |
328 | 329 | ||
329 | str_val = "-1"; | 330 | str_val = "-1"; |
330 | ensure("3: convertToU16 failed", !LLString::convertToU16(str_val, value)); | 331 | ensure("3: convertToU16 failed", !LLStringUtil::convertToU16(str_val, value)); |
331 | 332 | ||
332 | str_val = "65536"; | 333 | str_val = "65536"; |
333 | ensure("4: convertToU16 failed", !LLString::convertToU16(str_val, value)); | 334 | ensure("4: convertToU16 failed", !LLStringUtil::convertToU16(str_val, value)); |
334 | } | 335 | } |
335 | 336 | ||
336 | template<> template<> | 337 | template<> template<> |
337 | void string_index_object_t::test<21>() | 338 | void string_index_object_t::test<22>() |
338 | { | 339 | { |
339 | U32 value; | 340 | U32 value; |
340 | LLString str_val("4294967295"); //0xFFFFFFFF | 341 | std::string str_val("4294967295"); //0xFFFFFFFF |
341 | ensure("1: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295); | 342 | ensure("1: convertToU32 failed", LLStringUtil::convertToU32(str_val, value) && value == 4294967295UL); |
342 | 343 | ||
343 | str_val = "0"; | 344 | str_val = "0"; |
344 | ensure("2: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 0); | 345 | ensure("2: convertToU32 failed", LLStringUtil::convertToU32(str_val, value) && value == 0); |
345 | 346 | ||
347 | #ifndef LL_DARWIN | ||
346 | str_val = "-1"; | 348 | str_val = "-1"; |
347 | ensure("3: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295); | 349 | ensure("3: convertToU32 failed", LLStringUtil::convertToU32(str_val, value) && value == 4294967295UL); |
348 | 350 | #endif | |
351 | |||
349 | str_val = "4294967296"; | 352 | str_val = "4294967296"; |
350 | ensure("4: convertToU32 failed", !LLString::convertToU32(str_val, value)); | 353 | ensure("4: convertToU32 failed", !LLStringUtil::convertToU32(str_val, value)); |
351 | } | 354 | } |
352 | 355 | ||
353 | template<> template<> | 356 | template<> template<> |
354 | void string_index_object_t::test<22>() | 357 | void string_index_object_t::test<23>() |
355 | { | 358 | { |
356 | S32 value; | 359 | S32 value; |
357 | LLString str_val("2147483647"); //0x7FFFFFFF | 360 | std::string str_val("2147483647"); //0x7FFFFFFF |
358 | ensure("1: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 2147483647); | 361 | ensure("1: convertToS32 failed", LLStringUtil::convertToS32(str_val, value) && value == 2147483647); |
359 | 362 | ||
360 | str_val = "0"; | 363 | str_val = "0"; |
361 | ensure("2: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 0); | 364 | ensure("2: convertToS32 failed", LLStringUtil::convertToS32(str_val, value) && value == 0); |
362 | 365 | ||
366 | // Avoid "unary minus operator applied to unsigned type" warning on VC++. JC | ||
367 | S32 min_val = -2147483647 - 1; | ||
363 | str_val = "-2147483648"; | 368 | str_val = "-2147483648"; |
364 | ensure("3: convertToS32 failed", LLString::convertToS32(str_val, value) && value == -2147483648); | 369 | ensure("3: convertToS32 failed", LLStringUtil::convertToS32(str_val, value) && value == min_val); |
365 | 370 | ||
366 | str_val = "2147483648"; | 371 | str_val = "2147483648"; |
367 | ensure("4: convertToS32 failed", !LLString::convertToS32(str_val, value)); | 372 | ensure("4: convertToS32 failed", !LLStringUtil::convertToS32(str_val, value)); |
368 | 373 | ||
369 | str_val = "-2147483649"; | 374 | str_val = "-2147483649"; |
370 | ensure("5: convertToS32 failed", !LLString::convertToS32(str_val, value)); | 375 | ensure("5: convertToS32 failed", !LLStringUtil::convertToS32(str_val, value)); |
371 | } | 376 | } |
372 | 377 | ||
373 | template<> template<> | 378 | template<> template<> |
374 | void string_index_object_t::test<23>() | 379 | void string_index_object_t::test<24>() |
375 | { | 380 | { |
376 | F32 value; | 381 | F32 value; |
377 | LLString str_val("2147483647"); //0x7FFFFFFF | 382 | std::string str_val("2147483647"); //0x7FFFFFFF |
378 | ensure("1: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 2147483647); | 383 | ensure("1: convertToF32 failed", LLStringUtil::convertToF32(str_val, value) && value == 2147483647); |
379 | 384 | ||
380 | str_val = "0"; | 385 | str_val = "0"; |
381 | ensure("2: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 0); | 386 | ensure("2: convertToF32 failed", LLStringUtil::convertToF32(str_val, value) && value == 0); |
382 | 387 | ||
383 | /* Need to find max/min F32 values | 388 | /* Need to find max/min F32 values |
384 | str_val = "-2147483648"; | 389 | str_val = "-2147483648"; |
385 | ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648); | 390 | ensure("3: convertToF32 failed", LLStringUtil::convertToF32(str_val, value) && value == -2147483648); |
386 | 391 | ||
387 | str_val = "2147483648"; | 392 | str_val = "2147483648"; |
388 | ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value)); | 393 | ensure("4: convertToF32 failed", !LLStringUtil::convertToF32(str_val, value)); |
389 | 394 | ||
390 | str_val = "-2147483649"; | 395 | str_val = "-2147483649"; |
391 | ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value)); | 396 | ensure("5: convertToF32 failed", !LLStringUtil::convertToF32(str_val, value)); |
392 | */ | 397 | */ |
393 | } | 398 | } |
394 | 399 | ||
395 | template<> template<> | 400 | template<> template<> |
396 | void string_index_object_t::test<24>() | 401 | void string_index_object_t::test<25>() |
397 | { | 402 | { |
398 | F64 value; | 403 | F64 value; |
399 | LLString str_val("9223372036854775807"); //0x7FFFFFFFFFFFFFFF | 404 | std::string str_val("9223372036854775807"); //0x7FFFFFFFFFFFFFFF |
400 | ensure("1: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 9223372036854775807); | 405 | ensure("1: convertToF64 failed", LLStringUtil::convertToF64(str_val, value) && value == 9223372036854775807LL); |
401 | 406 | ||
402 | str_val = "0"; | 407 | str_val = "0"; |
403 | ensure("2: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 0); | 408 | ensure("2: convertToF64 failed", LLStringUtil::convertToF64(str_val, value) && value == 0.0F); |
404 | 409 | ||
405 | /* Need to find max/min F64 values | 410 | /* Need to find max/min F64 values |
406 | str_val = "-2147483648"; | 411 | str_val = "-2147483648"; |
407 | ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648); | 412 | ensure("3: convertToF32 failed", LLStringUtil::convertToF32(str_val, value) && value == -2147483648); |
408 | 413 | ||
409 | str_val = "2147483648"; | 414 | str_val = "2147483648"; |
410 | ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value)); | 415 | ensure("4: convertToF32 failed", !LLStringUtil::convertToF32(str_val, value)); |
411 | 416 | ||
412 | str_val = "-2147483649"; | 417 | str_val = "-2147483649"; |
413 | ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value)); | 418 | ensure("5: convertToF32 failed", !LLStringUtil::convertToF32(str_val, value)); |
414 | */ | 419 | */ |
415 | } | 420 | } |
416 | 421 | ||
417 | template<> template<> | 422 | template<> template<> |
418 | void string_index_object_t::test<25>() | 423 | void string_index_object_t::test<26>() |
419 | { | 424 | { |
420 | char* str1 = NULL; | 425 | char* str1 = NULL; |
421 | char* str2 = NULL; | 426 | char* str2 = NULL; |
422 | 427 | ||
423 | ensure("1: compareStrings failed", LLString::compareStrings(str1, str2) == 0); | 428 | ensure("1: compareStrings failed", LLStringUtil::compareStrings(str1, str2) == 0); |
424 | str2 = "A"; | 429 | str2 = "A"; |
425 | ensure("2: compareStrings failed", LLString::compareStrings(str1, str2) > 0); | 430 | ensure("2: compareStrings failed", LLStringUtil::compareStrings(str1, str2) > 0); |
426 | ensure("3: compareStrings failed", LLString::compareStrings(str2, str1) < 0); | 431 | ensure("3: compareStrings failed", LLStringUtil::compareStrings(str2, str1) < 0); |
427 | 432 | ||
428 | str1 = "A is smaller than B"; | 433 | str1 = "A is smaller than B"; |
429 | str2 = "B is greater than A"; | 434 | str2 = "B is greater than A"; |
430 | ensure("4: compareStrings failed", LLString::compareStrings(str1, str2) < 0); | 435 | ensure("4: compareStrings failed", LLStringUtil::compareStrings(str1, str2) < 0); |
431 | 436 | ||
432 | str2 = "A is smaller than B"; | 437 | str2 = "A is smaller than B"; |
433 | ensure("5: compareStrings failed", LLString::compareStrings(str1, str2) == 0); | 438 | ensure("5: compareStrings failed", LLStringUtil::compareStrings(str1, str2) == 0); |
434 | } | 439 | } |
435 | 440 | ||
436 | template<> template<> | 441 | template<> template<> |
437 | void string_index_object_t::test<26>() | 442 | void string_index_object_t::test<27>() |
438 | { | 443 | { |
439 | char* str1 = NULL; | 444 | char* str1 = NULL; |
440 | char* str2 = NULL; | 445 | char* str2 = NULL; |
441 | 446 | ||
442 | ensure("1: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0); | 447 | ensure("1: compareInsensitive failed", LLStringUtil::compareInsensitive(str1, str2) == 0); |
443 | str2 = "A"; | 448 | str2 = "A"; |
444 | ensure("2: compareInsensitive failed", LLString::compareInsensitive(str1, str2) > 0); | 449 | ensure("2: compareInsensitive failed", LLStringUtil::compareInsensitive(str1, str2) > 0); |
445 | ensure("3: compareInsensitive failed", LLString::compareInsensitive(str2, str1) < 0); | 450 | ensure("3: compareInsensitive failed", LLStringUtil::compareInsensitive(str2, str1) < 0); |
446 | 451 | ||
447 | str1 = "A is equal to a"; | 452 | str1 = "A is equal to a"; |
448 | str2 = "a is EQUAL to A"; | 453 | str2 = "a is EQUAL to A"; |
449 | ensure("4: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0); | 454 | ensure("4: compareInsensitive failed", LLStringUtil::compareInsensitive(str1, str2) == 0); |
450 | } | 455 | } |
451 | 456 | ||
452 | template<> template<> | 457 | template<> template<> |
453 | void string_index_object_t::test<27>() | 458 | void string_index_object_t::test<28>() |
454 | { | 459 | { |
455 | LLString lhs_str("PROgraM12files"); | 460 | std::string lhs_str("PROgraM12files"); |
456 | LLString rhs_str("PROgram12Files"); | 461 | std::string rhs_str("PROgram12Files"); |
457 | ensure("compareDict 1 failed", LLString::compareDict(lhs_str, rhs_str) < 0); | 462 | ensure("compareDict 1 failed", LLStringUtil::compareDict(lhs_str, rhs_str) < 0); |
458 | ensure("precedesDict 1 failed", LLString::precedesDict(lhs_str, rhs_str) == TRUE); | 463 | ensure("precedesDict 1 failed", LLStringUtil::precedesDict(lhs_str, rhs_str) == TRUE); |
459 | 464 | ||
460 | lhs_str = "PROgram12Files"; | 465 | lhs_str = "PROgram12Files"; |
461 | rhs_str = "PROgram12Files"; | 466 | rhs_str = "PROgram12Files"; |
462 | ensure("compareDict 2 failed", LLString::compareDict(lhs_str, rhs_str) == 0); | 467 | ensure("compareDict 2 failed", LLStringUtil::compareDict(lhs_str, rhs_str) == 0); |
463 | ensure("precedesDict 2 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE); | 468 | ensure("precedesDict 2 failed", LLStringUtil::precedesDict(lhs_str, rhs_str) == FALSE); |
464 | 469 | ||
465 | lhs_str = "PROgram12Files"; | 470 | lhs_str = "PROgram12Files"; |
466 | rhs_str = "PROgRAM12FILES"; | 471 | rhs_str = "PROgRAM12FILES"; |
467 | ensure("compareDict 3 failed", LLString::compareDict(lhs_str, rhs_str) > 0); | 472 | ensure("compareDict 3 failed", LLStringUtil::compareDict(lhs_str, rhs_str) > 0); |
468 | ensure("precedesDict 3 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE); | 473 | ensure("precedesDict 3 failed", LLStringUtil::precedesDict(lhs_str, rhs_str) == FALSE); |
469 | } | 474 | } |
470 | 475 | ||
471 | template<> template<> | 476 | template<> template<> |
472 | void string_index_object_t::test<28>() | 477 | void string_index_object_t::test<29>() |
473 | { | 478 | { |
474 | char str1[] = "First String..."; | 479 | char str1[] = "First String..."; |
475 | char str2[100]; | 480 | char str2[100]; |
476 | 481 | ||
477 | LLString::copy(str2, str1, 100); | 482 | LLStringUtil::copy(str2, str1, 100); |
478 | ensure("LLString::copy with enough dest lenght failed", strcmp(str2, str1) == 0); | 483 | ensure("LLStringUtil::copy with enough dest length failed", strcmp(str2, str1) == 0); |
479 | LLString::copy(str2, str1, sizeof("First")); | 484 | LLStringUtil::copy(str2, str1, sizeof("First")); |
480 | ensure("LLString::copy with less dest lenght failed", strcmp(str2, "First") == 0); | 485 | ensure("LLStringUtil::copy with less dest length failed", strcmp(str2, "First") == 0); |
481 | } | 486 | } |
482 | 487 | ||
483 | template<> template<> | 488 | template<> template<> |
484 | void string_index_object_t::test<29>() | 489 | void string_index_object_t::test<30>() |
485 | { | 490 | { |
486 | LLString str1 = "This is the sentence..."; | 491 | std::string str1 = "This is the sentence..."; |
487 | LLString str2 = "This is the "; | 492 | std::string str2 = "This is the "; |
488 | LLString str3 = "first "; | 493 | std::string str3 = "first "; |
489 | LLString str4 = "This is the first sentence..."; | 494 | std::string str4 = "This is the first sentence..."; |
490 | LLString str5 = "This is the sentence...first "; | 495 | std::string str5 = "This is the sentence...first "; |
491 | LLString dest; | 496 | std::string dest; |
492 | 497 | ||
493 | dest = str1; | 498 | dest = str1; |
494 | LLString::copyInto(dest, str3, str2.length()); | 499 | LLStringUtil::copyInto(dest, str3, str2.length()); |
495 | ensure("LLString::copyInto insert failed", dest == str4); | 500 | ensure("LLStringUtil::copyInto insert failed", dest == str4); |
496 | 501 | ||
497 | dest = str1; | 502 | dest = str1; |
498 | LLString::copyInto(dest, str3, dest.length()); | 503 | LLStringUtil::copyInto(dest, str3, dest.length()); |
499 | ensure("LLString::copyInto append failed", dest == str5); | 504 | ensure("LLStringUtil::copyInto append failed", dest == str5); |
505 | } | ||
506 | |||
507 | template<> template<> | ||
508 | void string_index_object_t::test<31>() | ||
509 | { | ||
510 | std::string stripped; | ||
511 | |||
512 | // Plain US ASCII text, including spaces and punctuation, | ||
513 | // should not be altered. | ||
514 | std::string simple_text = "Hello, world!"; | ||
515 | stripped = LLStringFn::strip_invalid_xml(simple_text); | ||
516 | ensure("Simple text passed unchanged", stripped == simple_text); | ||
517 | |||
518 | // Control characters should be removed | ||
519 | // except for 0x09, 0x0a, 0x0d | ||
520 | std::string control_chars; | ||
521 | for (char c = 0x01; c < 0x20; c++) | ||
522 | { | ||
523 | control_chars.push_back(c); | ||
524 | } | ||
525 | std::string allowed_control_chars; | ||
526 | allowed_control_chars.push_back( (char)0x09 ); | ||
527 | allowed_control_chars.push_back( (char)0x0a ); | ||
528 | allowed_control_chars.push_back( (char)0x0d ); | ||
529 | |||
530 | stripped = LLStringFn::strip_invalid_xml(control_chars); | ||
531 | ensure("Only tab, LF, CR control characters allowed", | ||
532 | stripped == allowed_control_chars); | ||
533 | |||
534 | // UTF-8 should be passed intact, including high byte | ||
535 | // characters. Try Francais (with C squiggle cedilla) | ||
536 | std::string french = "Fran"; | ||
537 | french.push_back( (char)0xC3 ); | ||
538 | french.push_back( (char)0xA7 ); | ||
539 | french += "ais"; | ||
540 | stripped = LLStringFn::strip_invalid_xml( french ); | ||
541 | ensure("UTF-8 high byte text is allowed", french == stripped ); | ||
500 | } | 542 | } |
501 | } | ||
502 | 543 | ||
544 | template<> template<> | ||
545 | void string_index_object_t::test<32>() | ||
546 | { | ||
547 | // Test LLStringUtil::format() string interpolation | ||
548 | LLStringUtil::format_map_t fmt_map; | ||
549 | std::string s; | ||
550 | int subcount; | ||
551 | |||
552 | fmt_map["[TRICK1]"] = "[A]"; | ||
553 | fmt_map["[A]"] = "a"; | ||
554 | fmt_map["[B]"] = "b"; | ||
555 | fmt_map["[AAA]"] = "aaa"; | ||
556 | fmt_map["[BBB]"] = "bbb"; | ||
557 | fmt_map["[TRICK2]"] = "[A]"; | ||
558 | fmt_map["[EXPLOIT]"] = "!!!!!!!!!!!![EXPLOIT]!!!!!!!!!!!!"; | ||
559 | fmt_map["[KEYLONGER]"] = "short"; | ||
560 | fmt_map["[KEYSHORTER]"] = "Am I not a long string?"; | ||
561 | fmt_map["?"] = "!"; | ||
562 | fmt_map["[DELETE]"] = ""; | ||
563 | |||
564 | for (LLStringUtil::format_map_t::const_iterator iter = fmt_map.begin(); iter != fmt_map.end(); ++iter) | ||
565 | { | ||
566 | // Test when source string is entirely one key | ||
567 | s = iter->first; | ||
568 | subcount = LLStringUtil::format(s, fmt_map); | ||
569 | ensure_equals("LLStringUtil::format: Raw interpolation result", s, iter->second); | ||
570 | ensure_equals("LLStringUtil::format: Raw interpolation result count", 1, subcount); | ||
571 | } | ||
572 | |||
573 | for (LLStringUtil::format_map_t::const_iterator iter = fmt_map.begin(); iter != fmt_map.end(); ++iter) | ||
574 | { | ||
575 | // Test when source string is one key, duplicated | ||
576 | s = iter->first + iter->first + iter->first + iter->first; | ||
577 | subcount = LLStringUtil::format(s, fmt_map); | ||
578 | ensure_equals("LLStringUtil::format: Rawx4 interpolation result", s, iter->second + iter->second + iter->second + iter->second); | ||
579 | ensure_equals("LLStringUtil::format: Rawx4 interpolation result count", 4, subcount); | ||
580 | } | ||
581 | |||
582 | // Test when source string has no keys | ||
583 | std::string srcs = "!!!!!!!!!!!!!!!!"; | ||
584 | s = srcs; | ||
585 | subcount = LLStringUtil::format(s, fmt_map); | ||
586 | ensure_equals("LLStringUtil::format: No key test result", s, srcs); | ||
587 | ensure_equals("LLStringUtil::format: No key test result count", 0, subcount); | ||
588 | |||
589 | // Test when source string has no keys and is empty | ||
590 | std::string srcs3; | ||
591 | s = srcs3; | ||
592 | subcount = LLStringUtil::format(s, fmt_map); | ||
593 | ensure("LLStringUtil::format: No key test3 result", s.empty()); | ||
594 | ensure_equals("LLStringUtil::format: No key test3 result count", 0, subcount); | ||
595 | |||
596 | // Test a substitution where a key is substituted with blankness | ||
597 | std::string srcs2 = "[DELETE]"; | ||
598 | s = srcs2; | ||
599 | subcount = LLStringUtil::format(s, fmt_map); | ||
600 | ensure("LLStringUtil::format: Delete key test2 result", s.empty()); | ||
601 | ensure_equals("LLStringUtil::format: Delete key test2 result count", 1, subcount); | ||
602 | |||
603 | // Test an assorted substitution | ||
604 | std::string srcs4 = "[TRICK1][A][B][AAA][BBB][TRICK2][KEYLONGER][KEYSHORTER]?[DELETE]"; | ||
605 | s = srcs4; | ||
606 | subcount = LLStringUtil::format(s, fmt_map); | ||
607 | ensure_equals("LLStringUtil::format: Assorted Test1 result", s, "[A]abaaabbb[A]shortAm I not a long string?!"); | ||
608 | ensure_equals("LLStringUtil::format: Assorted Test1 result count", 10, subcount); | ||
609 | |||
610 | // Test an assorted substitution | ||
611 | std::string srcs5 = "[DELETE]?[KEYSHORTER][KEYLONGER][TRICK2][BBB][AAA][B][A][TRICK1]"; | ||
612 | s = srcs5; | ||
613 | subcount = LLStringUtil::format(s, fmt_map); | ||
614 | ensure_equals("LLStringUtil::format: Assorted Test2 result", s, "!Am I not a long string?short[A]bbbaaaba[A]"); | ||
615 | ensure_equals("LLStringUtil::format: Assorted Test2 result count", 10, subcount); | ||
616 | |||
617 | // Test an assorted substitution | ||
618 | std::string srcs8 = "foo[DELETE]bar?"; | ||
619 | s = srcs8; | ||
620 | subcount = LLStringUtil::format(s, fmt_map); | ||
621 | ensure_equals("LLStringUtil::format: Assorted Test3 result", s, "foobar!"); | ||
622 | ensure_equals("LLStringUtil::format: Assorted Test3 result count", 2, subcount); | ||
623 | } | ||
624 | |||
625 | template<> template<> | ||
626 | void string_index_object_t::test<33>() | ||
627 | { | ||
628 | // Test LLStringUtil::format() string interpolation | ||
629 | LLStringUtil::format_map_t blank_fmt_map; | ||
630 | std::string s; | ||
631 | int subcount; | ||
632 | |||
633 | // Test substituting out of a blank format_map | ||
634 | std::string srcs6 = "12345"; | ||
635 | s = srcs6; | ||
636 | subcount = LLStringUtil::format(s, blank_fmt_map); | ||
637 | ensure_equals("LLStringUtil::format: Blankfmt Test1 result", s, "12345"); | ||
638 | ensure_equals("LLStringUtil::format: Blankfmt Test1 result count", 0, subcount); | ||
639 | |||
640 | // Test substituting a blank string out of a blank format_map | ||
641 | std::string srcs7; | ||
642 | s = srcs7; | ||
643 | subcount = LLStringUtil::format(s, blank_fmt_map); | ||
644 | ensure("LLStringUtil::format: Blankfmt Test2 result", s.empty()); | ||
645 | ensure_equals("LLStringUtil::format: Blankfmt Test2 result count", 0, subcount); | ||
646 | } | ||
647 | |||
648 | template<> template<> | ||
649 | void string_index_object_t::test<34>() | ||
650 | { | ||
651 | // Test that incorrect LLStringUtil::format() use does not explode. | ||
652 | LLStringUtil::format_map_t nasty_fmt_map; | ||
653 | std::string s; | ||
654 | int subcount; | ||
655 | |||
656 | nasty_fmt_map[""] = "never used"; // see, this is nasty. | ||
657 | |||
658 | // Test substituting out of a nasty format_map | ||
659 | std::string srcs6 = "12345"; | ||
660 | s = srcs6; | ||
661 | subcount = LLStringUtil::format(s, nasty_fmt_map); | ||
662 | ensure_equals("LLStringUtil::format: Nastyfmt Test1 result", s, "12345"); | ||
663 | ensure_equals("LLStringUtil::format: Nastyfmt Test1 result count", 0, subcount); | ||
664 | |||
665 | // Test substituting a blank string out of a nasty format_map | ||
666 | std::string srcs7; | ||
667 | s = srcs7; | ||
668 | subcount = LLStringUtil::format(s, nasty_fmt_map); | ||
669 | ensure("LLStringUtil::format: Nastyfmt Test2 result", s.empty()); | ||
670 | ensure_equals("LLStringUtil::format: Nastyfmt Test2 result count", 0, subcount); | ||
671 | } | ||
672 | } | ||