1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
/**
* @file llstring_tut.cpp
* @author Adroit
* @date 2006-12-24
* @brief Test cases of llstring.cpp
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include <tut/tut.h>
#include "lltut.h"
#include "linden_common.h"
#include "llstring.h"
namespace tut
{
struct string_index
{
};
typedef test_group<string_index> string_index_t;
typedef string_index_t::object string_index_object_t;
tut::string_index_t tut_string_index("string_test");
template<> template<>
void string_index_object_t::test<1>()
{
LLString llstr1;
ensure("Empty LLString", (llstr1.size() == 0) && llstr1.empty());
LLString llstr2("Hello");
ensure("LLString = Hello", (!strcmp(llstr2.c_str(), "Hello")) && (llstr2.size() == 5) && !llstr2.empty());
LLString llstr3(llstr2);
ensure("LLString = LLString(LLString)", (!strcmp(llstr3.c_str(), "Hello")) && (llstr3.size() == 5) && !llstr3.empty());
std::string str("Hello World");
LLString llstr4(str, 6);
ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (!strcmp(llstr4.c_str(), "World")) && (llstr4.size() == 5) && !llstr4.empty());
LLString llstr5(str, str.size());
ensure("LLString = LLString(s, size_type pos, size_type n = npos)", (llstr5.size() == 0) && llstr5.empty());
LLString llstr6(5, 'A');
ensure("LLString = LLString(count, c)", (!strcmp(llstr6.c_str(), "AAAAA")) && (llstr6.size() == 5) && !llstr6.empty());
LLString llstr7("Hello World", 5);
ensure("LLString(s, n)", (!strcmp(llstr7.c_str(), "Hello")) && (llstr7.size() == 5) && !llstr7.empty());
LLString llstr8("Hello World", 6, 5);
ensure("LLString(s, n, count)", (!strcmp(llstr8.c_str(), "World")) && (llstr8.size() == 5) && !llstr8.empty());
LLString llstr9("Hello World", sizeof("Hello World")-1, 5); // go past end
ensure("LLString(s, n, count) goes past end", (llstr9.size() == 0) && llstr9.empty());
}
template<> template<>
void string_index_object_t::test<2>()
{
LLString str("Len=5");
ensure("isValidIndex failed", LLString::isValidIndex(str, 0) == TRUE &&
LLString::isValidIndex(str, 5) == TRUE &&
LLString::isValidIndex(str, 6) == FALSE);
LLString str1;
ensure("isValidIndex failed fo rempty string", LLString::isValidIndex(str1, 0) == FALSE);
}
template<> template<>
void string_index_object_t::test<3>()
{
LLString str_val(" Testing the extra whitespaces ");
LLString::trimHead(str_val);
ensure_equals("1: trimHead failed", str_val, "Testing the extra whitespaces ");
LLString str_val1("\n\t\r\n Testing the extra whitespaces ");
LLString::trimHead(str_val1);
ensure_equals("2: trimHead failed", str_val1, "Testing the extra whitespaces ");
}
template<> template<>
void string_index_object_t::test<4>()
{
LLString str_val(" Testing the extra whitespaces ");
LLString::trimTail(str_val);
ensure_equals("1: trimTail failed", str_val, " Testing the extra whitespaces");
LLString str_val1("\n Testing the extra whitespaces \n\t\r\n ");
LLString::trimTail(str_val1);
ensure_equals("2: trimTail failed", str_val1, "\n Testing the extra whitespaces");
}
template<> template<>
void string_index_object_t::test<5>()
{
LLString str_val(" \t \r Testing the extra \r\n whitespaces \n \t ");
LLString::trim(str_val);
ensure_equals("1: trim failed", str_val, "Testing the extra \r\n whitespaces");
}
template<> template<>
void string_index_object_t::test<6>()
{
LLString str("Second LindenLabs");
LLString::truncate(str, 6);
ensure_equals("1: truncate", str, "Second");
// further truncate more than the length
LLString::truncate(str, 0);
ensure_equals("2: truncate", str, "");
}
template<> template<>
void string_index_object_t::test<7>()
{
LLString str_val("SecondLife Source");
LLString::toUpper(str_val);
ensure_equals("toUpper failed", str_val, "SECONDLIFE SOURCE");
}
template<> template<>
void string_index_object_t::test<8>()
{
LLString str_val("SecondLife Source");
LLString::toLower(str_val);
ensure_equals("toLower failed", str_val, "secondlife source");
}
template<> template<>
void string_index_object_t::test<9>()
{
LLString str_val("Second");
ensure("1. isHead failed", LLString::isHead(str_val, "SecondLife Source") == TRUE);
ensure("2. isHead failed", LLString::isHead(str_val, " SecondLife Source") == FALSE);
LLString str_val2("");
ensure("3. isHead failed", LLString::isHead(str_val2, "") == FALSE);
}
template<> template<>
void string_index_object_t::test<10>()
{
LLString str_val("Hello.\n\n Lindenlabs. \n This is \na simple test.\n");
LLString orig_str_val(str_val);
LLString::addCRLF(str_val);
ensure_equals("addCRLF failed", str_val, "Hello.\r\n\r\n Lindenlabs. \r\n This is \r\na simple test.\r\n");
LLString::removeCRLF(str_val);
ensure_equals("removeCRLF failed", str_val, orig_str_val);
}
template<> template<>
void string_index_object_t::test<11>()
{
LLString str_val("Hello.\n\n\t \t Lindenlabs. \t\t");
LLString orig_str_val(str_val);
LLString::replaceTabsWithSpaces(str_val, 1);
ensure_equals("replaceTabsWithSpaces failed", str_val, "Hello.\n\n Lindenlabs. ");
LLString::replaceTabsWithSpaces(orig_str_val, 0);
ensure_equals("replaceTabsWithSpaces failed for 0", orig_str_val, "Hello.\n\n Lindenlabs. ");
str_val = "\t\t\t\t";
LLString::replaceTabsWithSpaces(str_val, 0);
ensure_equals("replaceTabsWithSpaces failed for all tabs", str_val, "");
}
template<> template<>
void string_index_object_t::test<12>()
{
LLString str_val("Hello.\n\n\t\t\r\nLindenlabsX.");
LLString::replaceNonstandardASCII(str_val, 'X');
ensure_equals("replaceNonstandardASCII failed", str_val, "Hello.\n\nXXX\nLindenlabsX.");
}
template<> template<>
void string_index_object_t::test<13>()
{
LLString str_val("Hello.\n\t\r\nABCDEFGHIABABAB");
LLString::replaceChar(str_val, 'A', 'X');
ensure_equals("1: replaceChar failed", str_val, "Hello.\n\t\r\nXBCDEFGHIXBXBXB");
LLString str_val1("Hello.\n\t\r\nABCDEFGHIABABAB");
}
template<> template<>
void string_index_object_t::test<14>()
{
LLString str_val("Hello.\n\r\t");
ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == TRUE);
str_val = "ABC ";
ensure("containsNonprintable failed", LLString::containsNonprintable(str_val) == FALSE);
}
template<> template<>
void string_index_object_t::test<15>()
{
LLString str_val("Hello.\n\r\t Again!");
LLString::stripNonprintable(str_val);
ensure_equals("stripNonprintable failed", str_val, "Hello. Again!");
str_val = "\r\n\t\t";
LLString::stripNonprintable(str_val);
ensure_equals("stripNonprintable resulting in empty string failed", str_val, "");
}
template<> template<>
void string_index_object_t::test<16>()
{
BOOL value;
LLString str_val("1");
ensure("convertToBOOL 1 failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "T";
ensure("convertToBOOL T failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "t";
ensure("convertToBOOL t failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "TRUE";
ensure("convertToBOOL TRUE failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "True";
ensure("convertToBOOL True failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "true";
ensure("convertToBOOL true failed", LLString::convertToBOOL(str_val, value) && value);
str_val = "0";
ensure("convertToBOOL 0 failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "F";
ensure("convertToBOOL F failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "f";
ensure("convertToBOOL f failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "FALSE";
ensure("convertToBOOL FASLE failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "False";
ensure("convertToBOOL False failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "false";
ensure("convertToBOOL false failed", LLString::convertToBOOL(str_val, value) && !value);
str_val = "Tblah";
ensure("convertToBOOL false failed", !LLString::convertToBOOL(str_val, value));
}
template<> template<>
void string_index_object_t::test<17>()
{
U8 value;
LLString str_val("255");
ensure("1: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 255);
str_val = "0";
ensure("2: convertToU8 failed", LLString::convertToU8(str_val, value) && value == 0);
str_val = "-1";
ensure("3: convertToU8 failed", !LLString::convertToU8(str_val, value));
str_val = "256"; // bigger than MAX_U8
ensure("4: convertToU8 failed", !LLString::convertToU8(str_val, value));
}
template<> template<>
void string_index_object_t::test<18>()
{
S8 value;
LLString str_val("127");
ensure("1: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 127);
str_val = "0";
ensure("2: convertToS8 failed", LLString::convertToS8(str_val, value) && value == 0);
str_val = "-128";
ensure("3: convertToS8 failed", LLString::convertToS8(str_val, value) && value == -128);
str_val = "128"; // bigger than MAX_S8
ensure("4: convertToS8 failed", !LLString::convertToS8(str_val, value));
str_val = "-129";
ensure("5: convertToS8 failed", !LLString::convertToS8(str_val, value));
}
template<> template<>
void string_index_object_t::test<19>()
{
S16 value;
LLString str_val("32767");
ensure("1: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 32767);
str_val = "0";
ensure("2: convertToS16 failed", LLString::convertToS16(str_val, value) && value == 0);
str_val = "-32768";
ensure("3: convertToS16 failed", LLString::convertToS16(str_val, value) && value == -32768);
str_val = "32768";
ensure("4: convertToS16 failed", !LLString::convertToS16(str_val, value));
str_val = "-32769";
ensure("5: convertToS16 failed", !LLString::convertToS16(str_val, value));
}
template<> template<>
void string_index_object_t::test<20>()
{
U16 value;
LLString str_val("65535"); //0xFFFF
ensure("1: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 65535);
str_val = "0";
ensure("2: convertToU16 failed", LLString::convertToU16(str_val, value) && value == 0);
str_val = "-1";
ensure("3: convertToU16 failed", !LLString::convertToU16(str_val, value));
str_val = "65536";
ensure("4: convertToU16 failed", !LLString::convertToU16(str_val, value));
}
template<> template<>
void string_index_object_t::test<21>()
{
U32 value;
LLString str_val("4294967295"); //0xFFFFFFFF
ensure("1: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295);
str_val = "0";
ensure("2: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 0);
str_val = "-1";
ensure("3: convertToU32 failed", LLString::convertToU32(str_val, value) && value == 4294967295);
str_val = "4294967296";
ensure("4: convertToU32 failed", !LLString::convertToU32(str_val, value));
}
template<> template<>
void string_index_object_t::test<22>()
{
S32 value;
LLString str_val("2147483647"); //0x7FFFFFFF
ensure("1: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 2147483647);
str_val = "0";
ensure("2: convertToS32 failed", LLString::convertToS32(str_val, value) && value == 0);
str_val = "-2147483648";
ensure("3: convertToS32 failed", LLString::convertToS32(str_val, value) && value == -2147483648);
str_val = "2147483648";
ensure("4: convertToS32 failed", !LLString::convertToS32(str_val, value));
str_val = "-2147483649";
ensure("5: convertToS32 failed", !LLString::convertToS32(str_val, value));
}
template<> template<>
void string_index_object_t::test<23>()
{
F32 value;
LLString str_val("2147483647"); //0x7FFFFFFF
ensure("1: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 2147483647);
str_val = "0";
ensure("2: convertToF32 failed", LLString::convertToF32(str_val, value) && value == 0);
/* Need to find max/min F32 values
str_val = "-2147483648";
ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648);
str_val = "2147483648";
ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value));
str_val = "-2147483649";
ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value));
*/
}
template<> template<>
void string_index_object_t::test<24>()
{
F64 value;
LLString str_val("9223372036854775807"); //0x7FFFFFFFFFFFFFFF
ensure("1: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 9223372036854775807);
str_val = "0";
ensure("2: convertToF64 failed", LLString::convertToF64(str_val, value) && value == 0);
/* Need to find max/min F64 values
str_val = "-2147483648";
ensure("3: convertToF32 failed", LLString::convertToF32(str_val, value) && value == -2147483648);
str_val = "2147483648";
ensure("4: convertToF32 failed", !LLString::convertToF32(str_val, value));
str_val = "-2147483649";
ensure("5: convertToF32 failed", !LLString::convertToF32(str_val, value));
*/
}
template<> template<>
void string_index_object_t::test<25>()
{
char* str1 = NULL;
char* str2 = NULL;
ensure("1: compareStrings failed", LLString::compareStrings(str1, str2) == 0);
str2 = "A";
ensure("2: compareStrings failed", LLString::compareStrings(str1, str2) > 0);
ensure("3: compareStrings failed", LLString::compareStrings(str2, str1) < 0);
str1 = "A is smaller than B";
str2 = "B is greater than A";
ensure("4: compareStrings failed", LLString::compareStrings(str1, str2) < 0);
str2 = "A is smaller than B";
ensure("5: compareStrings failed", LLString::compareStrings(str1, str2) == 0);
}
template<> template<>
void string_index_object_t::test<26>()
{
char* str1 = NULL;
char* str2 = NULL;
ensure("1: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0);
str2 = "A";
ensure("2: compareInsensitive failed", LLString::compareInsensitive(str1, str2) > 0);
ensure("3: compareInsensitive failed", LLString::compareInsensitive(str2, str1) < 0);
str1 = "A is equal to a";
str2 = "a is EQUAL to A";
ensure("4: compareInsensitive failed", LLString::compareInsensitive(str1, str2) == 0);
}
template<> template<>
void string_index_object_t::test<27>()
{
LLString lhs_str("PROgraM12files");
LLString rhs_str("PROgram12Files");
ensure("compareDict 1 failed", LLString::compareDict(lhs_str, rhs_str) < 0);
ensure("precedesDict 1 failed", LLString::precedesDict(lhs_str, rhs_str) == TRUE);
lhs_str = "PROgram12Files";
rhs_str = "PROgram12Files";
ensure("compareDict 2 failed", LLString::compareDict(lhs_str, rhs_str) == 0);
ensure("precedesDict 2 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE);
lhs_str = "PROgram12Files";
rhs_str = "PROgRAM12FILES";
ensure("compareDict 3 failed", LLString::compareDict(lhs_str, rhs_str) > 0);
ensure("precedesDict 3 failed", LLString::precedesDict(lhs_str, rhs_str) == FALSE);
}
template<> template<>
void string_index_object_t::test<28>()
{
char str1[] = "First String...";
char str2[100];
LLString::copy(str2, str1, 100);
ensure("LLString::copy with enough dest lenght failed", strcmp(str2, str1) == 0);
LLString::copy(str2, str1, sizeof("First"));
ensure("LLString::copy with less dest lenght failed", strcmp(str2, "First") == 0);
}
template<> template<>
void string_index_object_t::test<29>()
{
LLString str1 = "This is the sentence...";
LLString str2 = "This is the ";
LLString str3 = "first ";
LLString str4 = "This is the first sentence...";
LLString str5 = "This is the sentence...first ";
LLString dest;
dest = str1;
LLString::copyInto(dest, str3, str2.length());
ensure("LLString::copyInto insert failed", dest == str4);
dest = str1;
LLString::copyInto(dest, str3, dest.length());
ensure("LLString::copyInto append failed", dest == str5);
}
}
|