1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/fxcrt/fx_string.h"
6 #include "testing/fx_string_testhelpers.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
TEST(fxcrt,ByteStringOperatorSubscript)9 TEST(fxcrt, ByteStringOperatorSubscript) {
10 // CFX_ByteString includes the NUL terminator for non-empty strings.
11 CFX_ByteString abc("abc");
12 EXPECT_EQ('a', abc[0]);
13 EXPECT_EQ('b', abc[1]);
14 EXPECT_EQ('c', abc[2]);
15 EXPECT_EQ(0, abc[3]);
16 }
17
TEST(fxcrt,ByteStringOperatorLT)18 TEST(fxcrt, ByteStringOperatorLT) {
19 CFX_ByteString empty;
20 CFX_ByteString a("a");
21 CFX_ByteString abc("abc");
22 CFX_ByteString def("def");
23
24 EXPECT_FALSE(empty < empty);
25 EXPECT_FALSE(a < a);
26 EXPECT_FALSE(abc < abc);
27 EXPECT_FALSE(def < def);
28
29 EXPECT_TRUE(empty < a);
30 EXPECT_FALSE(a < empty);
31
32 EXPECT_TRUE(empty < abc);
33 EXPECT_FALSE(abc < empty);
34
35 EXPECT_TRUE(empty < def);
36 EXPECT_FALSE(def < empty);
37
38 EXPECT_TRUE(a < abc);
39 EXPECT_FALSE(abc < a);
40
41 EXPECT_TRUE(a < def);
42 EXPECT_FALSE(def < a);
43
44 EXPECT_TRUE(abc < def);
45 EXPECT_FALSE(def < abc);
46 }
47
TEST(fxcrt,ByteStringOperatorEQ)48 TEST(fxcrt, ByteStringOperatorEQ) {
49 CFX_ByteString null_string;
50 EXPECT_TRUE(null_string == null_string);
51
52 CFX_ByteString empty_string("");
53 EXPECT_TRUE(empty_string == empty_string);
54 EXPECT_TRUE(empty_string == null_string);
55 EXPECT_TRUE(null_string == empty_string);
56
57 CFX_ByteString deleted_string("hello");
58 deleted_string.Delete(0, 5);
59 EXPECT_TRUE(deleted_string == deleted_string);
60 EXPECT_TRUE(deleted_string == null_string);
61 EXPECT_TRUE(deleted_string == empty_string);
62 EXPECT_TRUE(null_string == deleted_string);
63 EXPECT_TRUE(empty_string == deleted_string);
64
65 CFX_ByteString byte_string("hello");
66 EXPECT_TRUE(byte_string == byte_string);
67 EXPECT_FALSE(byte_string == null_string);
68 EXPECT_FALSE(byte_string == empty_string);
69 EXPECT_FALSE(byte_string == deleted_string);
70 EXPECT_FALSE(null_string == byte_string);
71 EXPECT_FALSE(empty_string == byte_string);
72 EXPECT_FALSE(deleted_string == byte_string);
73
74 CFX_ByteString byte_string_same1("hello");
75 EXPECT_TRUE(byte_string == byte_string_same1);
76 EXPECT_TRUE(byte_string_same1 == byte_string);
77
78 CFX_ByteString byte_string_same2(byte_string);
79 EXPECT_TRUE(byte_string == byte_string_same2);
80 EXPECT_TRUE(byte_string_same2 == byte_string);
81
82 CFX_ByteString byte_string1("he");
83 CFX_ByteString byte_string2("hellp");
84 CFX_ByteString byte_string3("hellod");
85 EXPECT_FALSE(byte_string == byte_string1);
86 EXPECT_FALSE(byte_string == byte_string2);
87 EXPECT_FALSE(byte_string == byte_string3);
88 EXPECT_FALSE(byte_string1 == byte_string);
89 EXPECT_FALSE(byte_string2 == byte_string);
90 EXPECT_FALSE(byte_string3 == byte_string);
91
92 CFX_ByteStringC null_string_c;
93 CFX_ByteStringC empty_string_c("");
94 EXPECT_TRUE(null_string == null_string_c);
95 EXPECT_TRUE(null_string == empty_string_c);
96 EXPECT_TRUE(empty_string == null_string_c);
97 EXPECT_TRUE(empty_string == empty_string_c);
98 EXPECT_TRUE(deleted_string == null_string_c);
99 EXPECT_TRUE(deleted_string == empty_string_c);
100 EXPECT_TRUE(null_string_c == null_string);
101 EXPECT_TRUE(empty_string_c == null_string);
102 EXPECT_TRUE(null_string_c == empty_string);
103 EXPECT_TRUE(empty_string_c == empty_string);
104 EXPECT_TRUE(null_string_c == deleted_string);
105 EXPECT_TRUE(empty_string_c == deleted_string);
106
107 CFX_ByteStringC byte_string_c_same1("hello");
108 EXPECT_TRUE(byte_string == byte_string_c_same1);
109 EXPECT_TRUE(byte_string_c_same1 == byte_string);
110
111 CFX_ByteStringC byte_string_c1("he");
112 CFX_ByteStringC byte_string_c2("hellp");
113 CFX_ByteStringC byte_string_c3("hellod");
114 EXPECT_FALSE(byte_string == byte_string_c1);
115 EXPECT_FALSE(byte_string == byte_string_c2);
116 EXPECT_FALSE(byte_string == byte_string_c3);
117 EXPECT_FALSE(byte_string_c1 == byte_string);
118 EXPECT_FALSE(byte_string_c2 == byte_string);
119 EXPECT_FALSE(byte_string_c3 == byte_string);
120
121 const char* c_null_string = nullptr;
122 const char* c_empty_string = "";
123 EXPECT_TRUE(null_string == c_null_string);
124 EXPECT_TRUE(null_string == c_empty_string);
125 EXPECT_TRUE(empty_string == c_null_string);
126 EXPECT_TRUE(empty_string == c_empty_string);
127 EXPECT_TRUE(deleted_string == c_null_string);
128 EXPECT_TRUE(deleted_string == c_empty_string);
129 EXPECT_TRUE(c_null_string == null_string);
130 EXPECT_TRUE(c_empty_string == null_string);
131 EXPECT_TRUE(c_null_string == empty_string);
132 EXPECT_TRUE(c_empty_string == empty_string);
133 EXPECT_TRUE(c_null_string == deleted_string);
134 EXPECT_TRUE(c_empty_string == deleted_string);
135
136 const char* c_string_same1 = "hello";
137 EXPECT_TRUE(byte_string == c_string_same1);
138 EXPECT_TRUE(c_string_same1 == byte_string);
139
140 const char* c_string1 = "he";
141 const char* c_string2 = "hellp";
142 const char* c_string3 = "hellod";
143 EXPECT_FALSE(byte_string == c_string1);
144 EXPECT_FALSE(byte_string == c_string2);
145 EXPECT_FALSE(byte_string == c_string3);
146 EXPECT_FALSE(c_string1 == byte_string);
147 EXPECT_FALSE(c_string2 == byte_string);
148 EXPECT_FALSE(c_string3 == byte_string);
149 }
150
TEST(fxcrt,ByteStringOperatorNE)151 TEST(fxcrt, ByteStringOperatorNE) {
152 CFX_ByteString null_string;
153 EXPECT_FALSE(null_string != null_string);
154
155 CFX_ByteString empty_string("");
156 EXPECT_FALSE(empty_string != empty_string);
157 EXPECT_FALSE(empty_string != null_string);
158 EXPECT_FALSE(null_string != empty_string);
159
160 CFX_ByteString deleted_string("hello");
161 deleted_string.Delete(0, 5);
162 EXPECT_FALSE(deleted_string != deleted_string);
163 EXPECT_FALSE(deleted_string != null_string);
164 EXPECT_FALSE(deleted_string != empty_string);
165 EXPECT_FALSE(deleted_string != deleted_string);
166 EXPECT_FALSE(null_string != deleted_string);
167 EXPECT_FALSE(empty_string != deleted_string);
168 EXPECT_FALSE(deleted_string != deleted_string);
169
170 CFX_ByteString byte_string("hello");
171 EXPECT_FALSE(byte_string != byte_string);
172 EXPECT_TRUE(byte_string != null_string);
173 EXPECT_TRUE(byte_string != empty_string);
174 EXPECT_TRUE(byte_string != deleted_string);
175 EXPECT_TRUE(null_string != byte_string);
176 EXPECT_TRUE(empty_string != byte_string);
177 EXPECT_TRUE(deleted_string != byte_string);
178
179 CFX_ByteString byte_string_same1("hello");
180 EXPECT_FALSE(byte_string != byte_string_same1);
181 EXPECT_FALSE(byte_string_same1 != byte_string);
182
183 CFX_ByteString byte_string_same2(byte_string);
184 EXPECT_FALSE(byte_string != byte_string_same2);
185 EXPECT_FALSE(byte_string_same2 != byte_string);
186
187 CFX_ByteString byte_string1("he");
188 CFX_ByteString byte_string2("hellp");
189 CFX_ByteString byte_string3("hellod");
190 EXPECT_TRUE(byte_string != byte_string1);
191 EXPECT_TRUE(byte_string != byte_string2);
192 EXPECT_TRUE(byte_string != byte_string3);
193 EXPECT_TRUE(byte_string1 != byte_string);
194 EXPECT_TRUE(byte_string2 != byte_string);
195 EXPECT_TRUE(byte_string3 != byte_string);
196
197 CFX_ByteStringC null_string_c;
198 CFX_ByteStringC empty_string_c("");
199 EXPECT_FALSE(null_string != null_string_c);
200 EXPECT_FALSE(null_string != empty_string_c);
201 EXPECT_FALSE(empty_string != null_string_c);
202 EXPECT_FALSE(empty_string != empty_string_c);
203 EXPECT_FALSE(null_string_c != null_string);
204 EXPECT_FALSE(empty_string_c != null_string);
205 EXPECT_FALSE(null_string_c != empty_string);
206 EXPECT_FALSE(empty_string_c != empty_string);
207
208 CFX_ByteStringC byte_string_c_same1("hello");
209 EXPECT_FALSE(byte_string != byte_string_c_same1);
210 EXPECT_FALSE(byte_string_c_same1 != byte_string);
211
212 CFX_ByteStringC byte_string_c1("he");
213 CFX_ByteStringC byte_string_c2("hellp");
214 CFX_ByteStringC byte_string_c3("hellod");
215 EXPECT_TRUE(byte_string != byte_string_c1);
216 EXPECT_TRUE(byte_string != byte_string_c2);
217 EXPECT_TRUE(byte_string != byte_string_c3);
218 EXPECT_TRUE(byte_string_c1 != byte_string);
219 EXPECT_TRUE(byte_string_c2 != byte_string);
220 EXPECT_TRUE(byte_string_c3 != byte_string);
221
222 const char* c_null_string = nullptr;
223 const char* c_empty_string = "";
224 EXPECT_FALSE(null_string != c_null_string);
225 EXPECT_FALSE(null_string != c_empty_string);
226 EXPECT_FALSE(empty_string != c_null_string);
227 EXPECT_FALSE(empty_string != c_empty_string);
228 EXPECT_FALSE(deleted_string != c_null_string);
229 EXPECT_FALSE(deleted_string != c_empty_string);
230 EXPECT_FALSE(c_null_string != null_string);
231 EXPECT_FALSE(c_empty_string != null_string);
232 EXPECT_FALSE(c_null_string != empty_string);
233 EXPECT_FALSE(c_empty_string != empty_string);
234 EXPECT_FALSE(c_null_string != deleted_string);
235 EXPECT_FALSE(c_empty_string != deleted_string);
236
237 const char* c_string_same1 = "hello";
238 EXPECT_FALSE(byte_string != c_string_same1);
239 EXPECT_FALSE(c_string_same1 != byte_string);
240
241 const char* c_string1 = "he";
242 const char* c_string2 = "hellp";
243 const char* c_string3 = "hellod";
244 EXPECT_TRUE(byte_string != c_string1);
245 EXPECT_TRUE(byte_string != c_string2);
246 EXPECT_TRUE(byte_string != c_string3);
247 EXPECT_TRUE(c_string1 != byte_string);
248 EXPECT_TRUE(c_string2 != byte_string);
249 EXPECT_TRUE(c_string3 != byte_string);
250 }
251
TEST(fxcrt,ByteStringCNull)252 TEST(fxcrt, ByteStringCNull) {
253 CFX_ByteStringC null_string;
254 EXPECT_FALSE(null_string.raw_str());
255 EXPECT_EQ(null_string.GetLength(), 0);
256 EXPECT_TRUE(null_string.IsEmpty());
257
258 CFX_ByteStringC another_null_string;
259 EXPECT_EQ(null_string, another_null_string);
260
261 CFX_ByteStringC copied_null_string(null_string);
262 EXPECT_FALSE(copied_null_string.raw_str());
263 EXPECT_EQ(copied_null_string.GetLength(), 0);
264 EXPECT_TRUE(copied_null_string.IsEmpty());
265 EXPECT_EQ(null_string, copied_null_string);
266
267 CFX_ByteStringC empty_string(""); // Pointer to NUL, not NULL pointer.
268 EXPECT_TRUE(empty_string.raw_str());
269 EXPECT_EQ(empty_string.GetLength(), 0);
270 EXPECT_TRUE(empty_string.IsEmpty());
271 EXPECT_EQ(null_string, empty_string);
272
273 CFX_ByteStringC assigned_null_string("initially not nullptr");
274 assigned_null_string = null_string;
275 EXPECT_FALSE(assigned_null_string.raw_str());
276 EXPECT_EQ(assigned_null_string.GetLength(), 0);
277 EXPECT_TRUE(assigned_null_string.IsEmpty());
278 EXPECT_EQ(null_string, assigned_null_string);
279
280 CFX_ByteStringC assigned_nullptr_string("initially not nullptr");
281 assigned_nullptr_string = (const FX_CHAR*)nullptr;
282 EXPECT_FALSE(assigned_nullptr_string.raw_str());
283 EXPECT_EQ(assigned_nullptr_string.GetLength(), 0);
284 EXPECT_TRUE(assigned_nullptr_string.IsEmpty());
285 EXPECT_EQ(null_string, assigned_nullptr_string);
286
287 CFX_ByteStringC non_null_string("a");
288 EXPECT_NE(null_string, non_null_string);
289 }
290
TEST(fxcrt,ByteStringConcat)291 TEST(fxcrt, ByteStringConcat) {
292 CFX_ByteString fred;
293 fred.Concat("FRED", 4);
294 EXPECT_EQ("FRED", fred);
295
296 fred.Concat("DY", 2);
297 EXPECT_EQ("FREDDY", fred);
298
299 fred.Delete(3, 3);
300 EXPECT_EQ("FRE", fred);
301
302 fred.Concat("D", 1);
303 EXPECT_EQ("FRED", fred);
304
305 CFX_ByteString copy = fred;
306 fred.Concat("DY", 2);
307 EXPECT_EQ("FREDDY", fred);
308 EXPECT_EQ("FRED", copy);
309
310 // Test invalid arguments.
311 copy = fred;
312 fred.Concat("freddy", -6);
313 CFX_ByteString not_aliased("xxxxxx");
314 EXPECT_EQ("FREDDY", fred);
315 EXPECT_EQ("xxxxxx", not_aliased);
316 }
317
TEST(fxcrt,ByteStringRemove)318 TEST(fxcrt, ByteStringRemove) {
319 CFX_ByteString freed("FREED");
320 freed.Remove('E');
321 EXPECT_EQ("FRD", freed);
322 freed.Remove('F');
323 EXPECT_EQ("RD", freed);
324 freed.Remove('D');
325 EXPECT_EQ("R", freed);
326 freed.Remove('X');
327 EXPECT_EQ("R", freed);
328 freed.Remove('R');
329 EXPECT_EQ("", freed);
330
331 CFX_ByteString empty;
332 empty.Remove('X');
333 EXPECT_EQ("", empty);
334 }
335
TEST(fxcrt,ByteStringRemoveCopies)336 TEST(fxcrt, ByteStringRemoveCopies) {
337 CFX_ByteString freed("FREED");
338 const FX_CHAR* old_buffer = freed.c_str();
339
340 // No change with single reference - no copy.
341 freed.Remove('Q');
342 EXPECT_EQ("FREED", freed);
343 EXPECT_EQ(old_buffer, freed.c_str());
344
345 // Change with single reference - no copy.
346 freed.Remove('E');
347 EXPECT_EQ("FRD", freed);
348 EXPECT_EQ(old_buffer, freed.c_str());
349
350 // No change with multiple references - no copy.
351 CFX_ByteString shared(freed);
352 freed.Remove('Q');
353 EXPECT_EQ("FRD", freed);
354 EXPECT_EQ(old_buffer, freed.c_str());
355 EXPECT_EQ(old_buffer, shared.c_str());
356
357 // Change with multiple references -- must copy.
358 freed.Remove('D');
359 EXPECT_EQ("FR", freed);
360 EXPECT_NE(old_buffer, freed.c_str());
361 EXPECT_EQ("FRD", shared);
362 EXPECT_EQ(old_buffer, shared.c_str());
363 }
364
TEST(fxcrt,ByteStringReplace)365 TEST(fxcrt, ByteStringReplace) {
366 CFX_ByteString fred("FRED");
367 fred.Replace("FR", "BL");
368 EXPECT_EQ("BLED", fred);
369 fred.Replace("D", "DDY");
370 EXPECT_EQ("BLEDDY", fred);
371 fred.Replace("LEDD", "");
372 EXPECT_EQ("BY", fred);
373 fred.Replace("X", "CLAMS");
374 EXPECT_EQ("BY", fred);
375 fred.Replace("BY", "HI");
376 EXPECT_EQ("HI", fred);
377 fred.Replace("", "CLAMS");
378 EXPECT_EQ("HI", fred);
379 fred.Replace("HI", "");
380 EXPECT_EQ("", fred);
381 }
382
TEST(fxcrt,ByteStringInsert)383 TEST(fxcrt, ByteStringInsert) {
384 CFX_ByteString fred("FRED");
385 fred.Insert(-1, 'X');
386 EXPECT_EQ("XFRED", fred);
387 fred.Insert(0, 'S');
388 EXPECT_EQ("SXFRED", fred);
389 fred.Insert(2, 'T');
390 EXPECT_EQ("SXTFRED", fred);
391 fred.Insert(5, 'U');
392 EXPECT_EQ("SXTFRUED", fred);
393 fred.Insert(8, 'V');
394 EXPECT_EQ("SXTFRUEDV", fred);
395 fred.Insert(12, 'P');
396 EXPECT_EQ("SXTFRUEDVP", fred);
397 {
398 CFX_ByteString empty;
399 empty.Insert(-1, 'X');
400 EXPECT_EQ("X", empty);
401 }
402 {
403 CFX_ByteString empty;
404 empty.Insert(0, 'X');
405 EXPECT_EQ("X", empty);
406 }
407 {
408 CFX_ByteString empty;
409 empty.Insert(5, 'X');
410 EXPECT_EQ("X", empty);
411 }
412 }
413
TEST(fxcrt,ByteStringDelete)414 TEST(fxcrt, ByteStringDelete) {
415 CFX_ByteString fred("FRED");
416 fred.Delete(0, 2);
417 EXPECT_EQ("ED", fred);
418 fred.Delete(1);
419 EXPECT_EQ("E", fred);
420 fred.Delete(-1);
421 EXPECT_EQ("", fred);
422 fred.Delete(1);
423 EXPECT_EQ("", fred);
424
425 CFX_ByteString empty;
426 empty.Delete(0);
427 EXPECT_EQ("", empty);
428 empty.Delete(-1);
429 EXPECT_EQ("", empty);
430 empty.Delete(1);
431 EXPECT_EQ("", empty);
432 }
433
TEST(fxcrt,ByteStringMid)434 TEST(fxcrt, ByteStringMid) {
435 CFX_ByteString fred("FRED");
436 EXPECT_EQ("", fred.Mid(0, 0));
437 EXPECT_EQ("", fred.Mid(3, 0));
438 EXPECT_EQ("FRED", fred.Mid(0));
439 EXPECT_EQ("RED", fred.Mid(1));
440 EXPECT_EQ("ED", fred.Mid(2));
441 EXPECT_EQ("D", fred.Mid(3));
442 EXPECT_EQ("F", fred.Mid(0, 1));
443 EXPECT_EQ("R", fred.Mid(1, 1));
444 EXPECT_EQ("E", fred.Mid(2, 1));
445 EXPECT_EQ("D", fred.Mid(3, 1));
446 EXPECT_EQ("FR", fred.Mid(0, 2));
447 EXPECT_EQ("FRED", fred.Mid(0, 4));
448 EXPECT_EQ("FRED", fred.Mid(0, 10));
449
450 EXPECT_EQ("FR", fred.Mid(-1, 2));
451 EXPECT_EQ("RED", fred.Mid(1, 4));
452 EXPECT_EQ("", fred.Mid(4, 1));
453
454 CFX_ByteString empty;
455 EXPECT_EQ("", empty.Mid(0, 0));
456 EXPECT_EQ("", empty.Mid(0));
457 EXPECT_EQ("", empty.Mid(1));
458 EXPECT_EQ("", empty.Mid(-1));
459 }
460
TEST(fxcrt,ByteStringLeft)461 TEST(fxcrt, ByteStringLeft) {
462 CFX_ByteString fred("FRED");
463 EXPECT_EQ("", fred.Left(0));
464 EXPECT_EQ("F", fred.Left(1));
465 EXPECT_EQ("FR", fred.Left(2));
466 EXPECT_EQ("FRE", fred.Left(3));
467 EXPECT_EQ("FRED", fred.Left(4));
468
469 EXPECT_EQ("FRED", fred.Left(5));
470 EXPECT_EQ("", fred.Left(-1));
471
472 CFX_ByteString empty;
473 EXPECT_EQ("", empty.Left(0));
474 EXPECT_EQ("", empty.Left(1));
475 EXPECT_EQ("", empty.Left(-1));
476 }
477
TEST(fxcrt,ByteStringRight)478 TEST(fxcrt, ByteStringRight) {
479 CFX_ByteString fred("FRED");
480 EXPECT_EQ("", fred.Right(0));
481 EXPECT_EQ("D", fred.Right(1));
482 EXPECT_EQ("ED", fred.Right(2));
483 EXPECT_EQ("RED", fred.Right(3));
484 EXPECT_EQ("FRED", fred.Right(4));
485
486 EXPECT_EQ("FRED", fred.Right(5));
487 EXPECT_EQ("", fred.Right(-1));
488
489 CFX_ByteString empty;
490 EXPECT_EQ("", empty.Right(0));
491 EXPECT_EQ("", empty.Right(1));
492 EXPECT_EQ("", empty.Right(-1));
493 }
494
TEST(fxcrt,ByteStringUpperLower)495 TEST(fxcrt, ByteStringUpperLower) {
496 CFX_ByteString fred("F-Re.42D");
497 fred.MakeLower();
498 EXPECT_EQ("f-re.42d", fred);
499 fred.MakeUpper();
500 EXPECT_EQ("F-RE.42D", fred);
501
502 CFX_ByteString empty;
503 empty.MakeLower();
504 EXPECT_EQ("", empty);
505 empty.MakeUpper();
506 EXPECT_EQ("", empty);
507 }
508
TEST(fxcrt,ByteStringTrimRight)509 TEST(fxcrt, ByteStringTrimRight) {
510 CFX_ByteString fred(" FRED ");
511 fred.TrimRight();
512 EXPECT_EQ(" FRED", fred);
513 fred.TrimRight('E');
514 EXPECT_EQ(" FRED", fred);
515 fred.TrimRight('D');
516 EXPECT_EQ(" FRE", fred);
517 fred.TrimRight("ERP");
518 EXPECT_EQ(" F", fred);
519
520 CFX_ByteString blank(" ");
521 blank.TrimRight("ERP");
522 EXPECT_EQ(" ", blank);
523 blank.TrimRight('E');
524 EXPECT_EQ(" ", blank);
525 blank.TrimRight();
526 EXPECT_EQ("", blank);
527
528 CFX_ByteString empty;
529 empty.TrimRight("ERP");
530 EXPECT_EQ("", empty);
531 empty.TrimRight('E');
532 EXPECT_EQ("", empty);
533 empty.TrimRight();
534 EXPECT_EQ("", empty);
535 }
536
TEST(fxcrt,ByteStringTrimRightCopies)537 TEST(fxcrt, ByteStringTrimRightCopies) {
538 {
539 // With a single reference, no copy takes place.
540 CFX_ByteString fred(" FRED ");
541 const FX_CHAR* old_buffer = fred.c_str();
542 fred.TrimRight();
543 EXPECT_EQ(" FRED", fred);
544 EXPECT_EQ(old_buffer, fred.c_str());
545 }
546 {
547 // With multiple references, we must copy.
548 CFX_ByteString fred(" FRED ");
549 CFX_ByteString other_fred = fred;
550 const FX_CHAR* old_buffer = fred.c_str();
551 fred.TrimRight();
552 EXPECT_EQ(" FRED", fred);
553 EXPECT_EQ(" FRED ", other_fred);
554 EXPECT_NE(old_buffer, fred.c_str());
555 }
556 {
557 // With multiple references, but no modifications, no copy.
558 CFX_ByteString fred("FRED");
559 CFX_ByteString other_fred = fred;
560 const FX_CHAR* old_buffer = fred.c_str();
561 fred.TrimRight();
562 EXPECT_EQ("FRED", fred);
563 EXPECT_EQ("FRED", other_fred);
564 EXPECT_EQ(old_buffer, fred.c_str());
565 }
566 }
567
TEST(fxcrt,ByteStringTrimLeft)568 TEST(fxcrt, ByteStringTrimLeft) {
569 CFX_ByteString fred(" FRED ");
570 fred.TrimLeft();
571 EXPECT_EQ("FRED ", fred);
572 fred.TrimLeft('E');
573 EXPECT_EQ("FRED ", fred);
574 fred.TrimLeft('F');
575 EXPECT_EQ("RED ", fred);
576 fred.TrimLeft("ERP");
577 EXPECT_EQ("D ", fred);
578
579 CFX_ByteString blank(" ");
580 blank.TrimLeft("ERP");
581 EXPECT_EQ(" ", blank);
582 blank.TrimLeft('E');
583 EXPECT_EQ(" ", blank);
584 blank.TrimLeft();
585 EXPECT_EQ("", blank);
586
587 CFX_ByteString empty;
588 empty.TrimLeft("ERP");
589 EXPECT_EQ("", empty);
590 empty.TrimLeft('E');
591 EXPECT_EQ("", empty);
592 empty.TrimLeft();
593 EXPECT_EQ("", empty);
594 }
595
TEST(fxcrt,ByteStringTrimLeftCopies)596 TEST(fxcrt, ByteStringTrimLeftCopies) {
597 {
598 // With a single reference, no copy takes place.
599 CFX_ByteString fred(" FRED ");
600 const FX_CHAR* old_buffer = fred.c_str();
601 fred.TrimLeft();
602 EXPECT_EQ("FRED ", fred);
603 EXPECT_EQ(old_buffer, fred.c_str());
604 }
605 {
606 // With multiple references, we must copy.
607 CFX_ByteString fred(" FRED ");
608 CFX_ByteString other_fred = fred;
609 const FX_CHAR* old_buffer = fred.c_str();
610 fred.TrimLeft();
611 EXPECT_EQ("FRED ", fred);
612 EXPECT_EQ(" FRED ", other_fred);
613 EXPECT_NE(old_buffer, fred.c_str());
614 }
615 {
616 // With multiple references, but no modifications, no copy.
617 CFX_ByteString fred("FRED");
618 CFX_ByteString other_fred = fred;
619 const FX_CHAR* old_buffer = fred.c_str();
620 fred.TrimLeft();
621 EXPECT_EQ("FRED", fred);
622 EXPECT_EQ("FRED", other_fred);
623 EXPECT_EQ(old_buffer, fred.c_str());
624 }
625 }
626
TEST(fxcrt,ByteStringReserve)627 TEST(fxcrt, ByteStringReserve) {
628 {
629 CFX_ByteString str;
630 str.Reserve(6);
631 const FX_CHAR* old_buffer = str.c_str();
632 str += "ABCDEF";
633 EXPECT_EQ(old_buffer, str.c_str());
634 str += "Blah Blah Blah Blah Blah Blah";
635 EXPECT_NE(old_buffer, str.c_str());
636 }
637 {
638 CFX_ByteString str("A");
639 str.Reserve(6);
640 const FX_CHAR* old_buffer = str.c_str();
641 str += "BCDEF";
642 EXPECT_EQ(old_buffer, str.c_str());
643 str += "Blah Blah Blah Blah Blah Blah";
644 EXPECT_NE(old_buffer, str.c_str());
645 }
646 }
647
TEST(fxcrt,ByteStringGetBuffer)648 TEST(fxcrt, ByteStringGetBuffer) {
649 {
650 CFX_ByteString str;
651 FX_CHAR* buffer = str.GetBuffer(12);
652 // NOLINTNEXTLINE(runtime/printf)
653 strcpy(buffer, "clams");
654 str.ReleaseBuffer();
655 EXPECT_EQ("clams", str);
656 }
657 {
658 CFX_ByteString str("cl");
659 FX_CHAR* buffer = str.GetBuffer(12);
660 // NOLINTNEXTLINE(runtime/printf)
661 strcpy(buffer + 2, "ams");
662 str.ReleaseBuffer();
663 EXPECT_EQ("clams", str);
664 }
665 }
666
TEST(fxcrt,ByteStringReleaseBuffer)667 TEST(fxcrt, ByteStringReleaseBuffer) {
668 {
669 CFX_ByteString str;
670 str.Reserve(12);
671 str += "clams";
672 const FX_CHAR* old_buffer = str.c_str();
673 str.ReleaseBuffer(4);
674 EXPECT_EQ(old_buffer, str.c_str());
675 EXPECT_EQ("clam", str);
676 }
677 {
678 CFX_ByteString str("c");
679 str.Reserve(12);
680 str += "lams";
681 const FX_CHAR* old_buffer = str.c_str();
682 str.ReleaseBuffer(4);
683 EXPECT_EQ(old_buffer, str.c_str());
684 EXPECT_EQ("clam", str);
685 }
686 {
687 CFX_ByteString str;
688 str.Reserve(200);
689 str += "clams";
690 const FX_CHAR* old_buffer = str.c_str();
691 str.ReleaseBuffer(4);
692 EXPECT_NE(old_buffer, str.c_str());
693 EXPECT_EQ("clam", str);
694 }
695 {
696 CFX_ByteString str("c");
697 str.Reserve(200);
698 str += "lams";
699 const FX_CHAR* old_buffer = str.c_str();
700 str.ReleaseBuffer(4);
701 EXPECT_NE(old_buffer, str.c_str());
702 EXPECT_EQ("clam", str);
703 }
704 }
705
TEST(fxcrt,ByteStringCNotNull)706 TEST(fxcrt, ByteStringCNotNull) {
707 CFX_ByteStringC string3("abc");
708 CFX_ByteStringC string6("abcdef");
709 CFX_ByteStringC alternate_string3("abcdef", 3);
710 CFX_ByteStringC embedded_nul_string7("abc\0def", 7);
711 CFX_ByteStringC illegal_string7("abcdef", 7);
712
713 EXPECT_EQ(3, string3.GetLength());
714 EXPECT_EQ(6, string6.GetLength());
715 EXPECT_EQ(3, alternate_string3.GetLength());
716 EXPECT_EQ(7, embedded_nul_string7.GetLength());
717 EXPECT_EQ(7, illegal_string7.GetLength());
718
719 EXPECT_NE(string3, string6);
720 EXPECT_EQ(string3, alternate_string3);
721 EXPECT_NE(string3, embedded_nul_string7);
722 EXPECT_NE(string3, illegal_string7);
723 EXPECT_NE(string6, alternate_string3);
724 EXPECT_NE(string6, embedded_nul_string7);
725 EXPECT_NE(string6, illegal_string7);
726 EXPECT_NE(alternate_string3, embedded_nul_string7);
727 EXPECT_NE(alternate_string3, illegal_string7);
728 EXPECT_NE(embedded_nul_string7, illegal_string7);
729
730 CFX_ByteStringC copied_string3(string3);
731 CFX_ByteStringC copied_alternate_string3(alternate_string3);
732 CFX_ByteStringC copied_embedded_nul_string7(embedded_nul_string7);
733
734 EXPECT_EQ(string3, copied_string3);
735 EXPECT_EQ(alternate_string3, copied_alternate_string3);
736 EXPECT_EQ(embedded_nul_string7, copied_embedded_nul_string7);
737
738 CFX_ByteStringC assigned_string3("intially something else");
739 CFX_ByteStringC assigned_alternate_string3("initally something else");
740 CFX_ByteStringC assigned_ptr_string3("initially something else");
741 CFX_ByteStringC assigned_embedded_nul_string7("initially something else");
742
743 assigned_string3 = string3;
744 assigned_alternate_string3 = alternate_string3;
745 assigned_ptr_string3 = "abc";
746 assigned_embedded_nul_string7 = embedded_nul_string7;
747 EXPECT_EQ(string3, assigned_string3);
748 EXPECT_EQ(alternate_string3, assigned_alternate_string3);
749 EXPECT_EQ(alternate_string3, assigned_ptr_string3);
750 EXPECT_EQ(embedded_nul_string7, assigned_embedded_nul_string7);
751 }
752
TEST(fxcrt,ByteStringCFromChar)753 TEST(fxcrt, ByteStringCFromChar) {
754 CFX_ByteStringC null_string;
755 CFX_ByteStringC lower_a_string("a");
756
757 // Must have lvalues that outlive the corresponding ByteStringC.
758 char nul = '\0';
759 char lower_a = 'a';
760 CFX_ByteStringC nul_string_from_char(nul);
761 CFX_ByteStringC lower_a_string_from_char(lower_a);
762
763 // Pointer to nul, not nullptr ptr, hence length 1 ...
764 EXPECT_EQ(1, nul_string_from_char.GetLength());
765 EXPECT_NE(null_string, nul_string_from_char);
766
767 EXPECT_EQ(1, lower_a_string_from_char.GetLength());
768 EXPECT_EQ(lower_a_string, lower_a_string_from_char);
769 EXPECT_NE(nul_string_from_char, lower_a_string_from_char);
770
771 CFX_ByteStringC longer_string("ab");
772 EXPECT_NE(longer_string, lower_a_string_from_char);
773 }
774
TEST(fxcrt,ByteStringCGetID)775 TEST(fxcrt, ByteStringCGetID) {
776 CFX_ByteStringC null_string;
777 EXPECT_EQ(0u, null_string.GetID());
778 EXPECT_EQ(0u, null_string.GetID(1));
779 EXPECT_EQ(0u, null_string.GetID(-1));
780 EXPECT_EQ(0u, null_string.GetID(-1000000));
781
782 CFX_ByteStringC empty_string("");
783 EXPECT_EQ(0u, empty_string.GetID());
784 EXPECT_EQ(0u, empty_string.GetID(1));
785 EXPECT_EQ(0u, empty_string.GetID(-1));
786 EXPECT_EQ(0u, empty_string.GetID(-1000000));
787
788 CFX_ByteStringC short_string("ab");
789 EXPECT_EQ(FXBSTR_ID('a', 'b', 0, 0), short_string.GetID());
790 EXPECT_EQ(FXBSTR_ID('b', 0, 0, 0), short_string.GetID(1));
791 EXPECT_EQ(0u, short_string.GetID(2));
792 EXPECT_EQ(0u, short_string.GetID(-1));
793 EXPECT_EQ(0u, short_string.GetID(-1000000));
794
795 CFX_ByteStringC longer_string("abcdef");
796 EXPECT_EQ(FXBSTR_ID('a', 'b', 'c', 'd'), longer_string.GetID());
797 EXPECT_EQ(FXBSTR_ID('b', 'c', 'd', 'e'), longer_string.GetID(1));
798 EXPECT_EQ(FXBSTR_ID('c', 'd', 'e', 'f'), longer_string.GetID(2));
799 EXPECT_EQ(FXBSTR_ID('d', 'e', 'f', 0), longer_string.GetID(3));
800 EXPECT_EQ(FXBSTR_ID('e', 'f', 0, 0), longer_string.GetID(4));
801 EXPECT_EQ(FXBSTR_ID('f', 0, 0, 0), longer_string.GetID(5));
802 EXPECT_EQ(0u, longer_string.GetID(6));
803 EXPECT_EQ(0u, longer_string.GetID(-1));
804 EXPECT_EQ(0u, longer_string.GetID(-1000000));
805 }
806
TEST(fxcrt,ByteStringCFind)807 TEST(fxcrt, ByteStringCFind) {
808 CFX_ByteStringC null_string;
809 EXPECT_EQ(-1, null_string.Find('a'));
810 EXPECT_EQ(-1, null_string.Find(0));
811
812 CFX_ByteStringC empty_string("");
813 EXPECT_EQ(-1, empty_string.Find('a'));
814 EXPECT_EQ(-1, empty_string.Find(0));
815
816 CFX_ByteStringC single_string("a");
817 EXPECT_EQ(0, single_string.Find('a'));
818 EXPECT_EQ(-1, single_string.Find('b'));
819 EXPECT_EQ(-1, single_string.Find(0));
820
821 CFX_ByteStringC longer_string("abccc");
822 EXPECT_EQ(0, longer_string.Find('a'));
823 EXPECT_EQ(2, longer_string.Find('c'));
824 EXPECT_EQ(-1, longer_string.Find(0));
825
826 CFX_ByteStringC hibyte_string(
827 "ab\x8c"
828 "def");
829 EXPECT_EQ(2, hibyte_string.Find('\x8c'));
830 }
831
TEST(fxcrt,ByteStringCMid)832 TEST(fxcrt, ByteStringCMid) {
833 CFX_ByteStringC null_string;
834 EXPECT_EQ(null_string, null_string.Mid(0, 1));
835 EXPECT_EQ(null_string, null_string.Mid(1, 1));
836
837 CFX_ByteStringC empty_string("");
838 EXPECT_EQ(empty_string, empty_string.Mid(0, 1));
839 EXPECT_EQ(empty_string, empty_string.Mid(1, 1));
840
841 CFX_ByteStringC single_character("a");
842 EXPECT_EQ(empty_string, single_character.Mid(0, 0));
843 EXPECT_EQ(single_character, single_character.Mid(0, 1));
844 EXPECT_EQ(empty_string, single_character.Mid(1, 0));
845 EXPECT_EQ(empty_string, single_character.Mid(1, 1));
846
847 CFX_ByteStringC longer_string("abcdef");
848 EXPECT_EQ(longer_string, longer_string.Mid(0, 6));
849 EXPECT_EQ(longer_string, longer_string.Mid(0, 187));
850 EXPECT_EQ(longer_string, longer_string.Mid(-42, 6));
851 EXPECT_EQ(longer_string, longer_string.Mid(-42, 187));
852
853 CFX_ByteStringC leading_substring("ab");
854 EXPECT_EQ(leading_substring, longer_string.Mid(0, 2));
855 EXPECT_EQ(leading_substring, longer_string.Mid(-1, 2));
856
857 CFX_ByteStringC middle_substring("bcde");
858 EXPECT_EQ(middle_substring, longer_string.Mid(1, 4));
859
860 CFX_ByteStringC trailing_substring("ef");
861 EXPECT_EQ(trailing_substring, longer_string.Mid(4, 2));
862 EXPECT_EQ(trailing_substring, longer_string.Mid(4, 3));
863 }
864
TEST(fxcrt,ByteStringCGetAt)865 TEST(fxcrt, ByteStringCGetAt) {
866 CFX_ByteString short_string("a");
867 CFX_ByteString longer_string("abc");
868 CFX_ByteString embedded_nul_string("ab\0c", 4);
869
870 EXPECT_EQ('a', short_string.GetAt(0));
871 EXPECT_EQ('c', longer_string.GetAt(2));
872 EXPECT_EQ('b', embedded_nul_string.GetAt(1));
873 EXPECT_EQ('\0', embedded_nul_string.GetAt(2));
874 EXPECT_EQ('c', embedded_nul_string.GetAt(3));
875 }
876
TEST(fxcrt,ByteStringCOperatorSubscript)877 TEST(fxcrt, ByteStringCOperatorSubscript) {
878 // CFX_ByteStringC includes the NUL terminator for non-empty strings.
879 CFX_ByteStringC abc("abc");
880 EXPECT_EQ('a', abc[0]);
881 EXPECT_EQ('b', abc[1]);
882 EXPECT_EQ('c', abc[2]);
883 EXPECT_EQ(0, abc[3]);
884 }
885
TEST(fxcrt,ByteStringCOperatorLT)886 TEST(fxcrt, ByteStringCOperatorLT) {
887 CFX_ByteStringC empty;
888 CFX_ByteStringC a("a");
889 CFX_ByteStringC abc("abc");
890 CFX_ByteStringC def("def");
891
892 EXPECT_FALSE(empty < empty);
893 EXPECT_FALSE(a < a);
894 EXPECT_FALSE(abc < abc);
895 EXPECT_FALSE(def < def);
896
897 EXPECT_TRUE(empty < a);
898 EXPECT_FALSE(a < empty);
899
900 EXPECT_TRUE(empty < abc);
901 EXPECT_FALSE(abc < empty);
902
903 EXPECT_TRUE(empty < def);
904 EXPECT_FALSE(def < empty);
905
906 EXPECT_TRUE(a < abc);
907 EXPECT_FALSE(abc < a);
908
909 EXPECT_TRUE(a < def);
910 EXPECT_FALSE(def < a);
911
912 EXPECT_TRUE(abc < def);
913 EXPECT_FALSE(def < abc);
914 }
915
TEST(fxcrt,ByteStringCOperatorEQ)916 TEST(fxcrt, ByteStringCOperatorEQ) {
917 CFX_ByteStringC byte_string_c("hello");
918 EXPECT_TRUE(byte_string_c == byte_string_c);
919
920 CFX_ByteStringC byte_string_c_same1("hello");
921 EXPECT_TRUE(byte_string_c == byte_string_c_same1);
922 EXPECT_TRUE(byte_string_c_same1 == byte_string_c);
923
924 CFX_ByteStringC byte_string_c_same2(byte_string_c);
925 EXPECT_TRUE(byte_string_c == byte_string_c_same2);
926 EXPECT_TRUE(byte_string_c_same2 == byte_string_c);
927
928 CFX_ByteStringC byte_string_c1("he");
929 CFX_ByteStringC byte_string_c2("hellp");
930 CFX_ByteStringC byte_string_c3("hellod");
931 EXPECT_FALSE(byte_string_c == byte_string_c1);
932 EXPECT_FALSE(byte_string_c == byte_string_c2);
933 EXPECT_FALSE(byte_string_c == byte_string_c3);
934 EXPECT_FALSE(byte_string_c1 == byte_string_c);
935 EXPECT_FALSE(byte_string_c2 == byte_string_c);
936 EXPECT_FALSE(byte_string_c3 == byte_string_c);
937
938 CFX_ByteString byte_string_same1("hello");
939 EXPECT_TRUE(byte_string_c == byte_string_same1);
940 EXPECT_TRUE(byte_string_same1 == byte_string_c);
941
942 CFX_ByteString byte_string1("he");
943 CFX_ByteString byte_string2("hellp");
944 CFX_ByteString byte_string3("hellod");
945 EXPECT_FALSE(byte_string_c == byte_string1);
946 EXPECT_FALSE(byte_string_c == byte_string2);
947 EXPECT_FALSE(byte_string_c == byte_string3);
948 EXPECT_FALSE(byte_string1 == byte_string_c);
949 EXPECT_FALSE(byte_string2 == byte_string_c);
950 EXPECT_FALSE(byte_string3 == byte_string_c);
951
952 const char* c_string_same1 = "hello";
953 EXPECT_TRUE(byte_string_c == c_string_same1);
954 EXPECT_TRUE(c_string_same1 == byte_string_c);
955
956 const char* c_string1 = "he";
957 const char* c_string2 = "hellp";
958 const char* c_string3 = "hellod";
959 EXPECT_FALSE(byte_string_c == c_string1);
960 EXPECT_FALSE(byte_string_c == c_string2);
961 EXPECT_FALSE(byte_string_c == c_string3);
962
963 EXPECT_FALSE(c_string1 == byte_string_c);
964 EXPECT_FALSE(c_string2 == byte_string_c);
965 EXPECT_FALSE(c_string3 == byte_string_c);
966 }
967
TEST(fxcrt,ByteStringCOperatorNE)968 TEST(fxcrt, ByteStringCOperatorNE) {
969 CFX_ByteStringC byte_string_c("hello");
970 EXPECT_FALSE(byte_string_c != byte_string_c);
971
972 CFX_ByteStringC byte_string_c_same1("hello");
973 EXPECT_FALSE(byte_string_c != byte_string_c_same1);
974 EXPECT_FALSE(byte_string_c_same1 != byte_string_c);
975
976 CFX_ByteStringC byte_string_c_same2(byte_string_c);
977 EXPECT_FALSE(byte_string_c != byte_string_c_same2);
978 EXPECT_FALSE(byte_string_c_same2 != byte_string_c);
979
980 CFX_ByteStringC byte_string_c1("he");
981 CFX_ByteStringC byte_string_c2("hellp");
982 CFX_ByteStringC byte_string_c3("hellod");
983 EXPECT_TRUE(byte_string_c != byte_string_c1);
984 EXPECT_TRUE(byte_string_c != byte_string_c2);
985 EXPECT_TRUE(byte_string_c != byte_string_c3);
986 EXPECT_TRUE(byte_string_c1 != byte_string_c);
987 EXPECT_TRUE(byte_string_c2 != byte_string_c);
988 EXPECT_TRUE(byte_string_c3 != byte_string_c);
989
990 CFX_ByteString byte_string_same1("hello");
991 EXPECT_FALSE(byte_string_c != byte_string_same1);
992 EXPECT_FALSE(byte_string_same1 != byte_string_c);
993
994 CFX_ByteString byte_string1("he");
995 CFX_ByteString byte_string2("hellp");
996 CFX_ByteString byte_string3("hellod");
997 EXPECT_TRUE(byte_string_c != byte_string1);
998 EXPECT_TRUE(byte_string_c != byte_string2);
999 EXPECT_TRUE(byte_string_c != byte_string3);
1000 EXPECT_TRUE(byte_string1 != byte_string_c);
1001 EXPECT_TRUE(byte_string2 != byte_string_c);
1002 EXPECT_TRUE(byte_string3 != byte_string_c);
1003
1004 const char* c_string_same1 = "hello";
1005 EXPECT_FALSE(byte_string_c != c_string_same1);
1006 EXPECT_FALSE(c_string_same1 != byte_string_c);
1007
1008 const char* c_string1 = "he";
1009 const char* c_string2 = "hellp";
1010 const char* c_string3 = "hellod";
1011 EXPECT_TRUE(byte_string_c != c_string1);
1012 EXPECT_TRUE(byte_string_c != c_string2);
1013 EXPECT_TRUE(byte_string_c != c_string3);
1014
1015 EXPECT_TRUE(c_string1 != byte_string_c);
1016 EXPECT_TRUE(c_string2 != byte_string_c);
1017 EXPECT_TRUE(c_string3 != byte_string_c);
1018 }
1019
TEST(fxcrt,ByteStringFormatWidth)1020 TEST(fxcrt, ByteStringFormatWidth) {
1021 {
1022 CFX_ByteString str;
1023 str.Format("%5d", 1);
1024 EXPECT_EQ(" 1", str);
1025 }
1026
1027 {
1028 CFX_ByteString str;
1029 str.Format("%d", 1);
1030 EXPECT_EQ("1", str);
1031 }
1032
1033 {
1034 CFX_ByteString str;
1035 str.Format("%*d", 5, 1);
1036 EXPECT_EQ(" 1", str);
1037 }
1038
1039 {
1040 CFX_ByteString str;
1041 str.Format("%-1d", 1);
1042 EXPECT_EQ("1", str);
1043 }
1044
1045 {
1046 CFX_ByteString str;
1047 str.Format("%0d", 1);
1048 EXPECT_EQ("1", str);
1049 }
1050
1051 {
1052 CFX_ByteString str;
1053 str.Format("%1048576d", 1);
1054 EXPECT_EQ("Bad width", str);
1055 }
1056 }
1057
TEST(fxcrt,ByteStringFormatPrecision)1058 TEST(fxcrt, ByteStringFormatPrecision) {
1059 {
1060 CFX_ByteString str;
1061 str.Format("%.2f", 1.12345);
1062 EXPECT_EQ("1.12", str);
1063 }
1064
1065 {
1066 CFX_ByteString str;
1067 str.Format("%.*f", 3, 1.12345);
1068 EXPECT_EQ("1.123", str);
1069 }
1070
1071 {
1072 CFX_ByteString str;
1073 str.Format("%f", 1.12345);
1074 EXPECT_EQ("1.123450", str);
1075 }
1076
1077 {
1078 CFX_ByteString str;
1079 str.Format("%-1f", 1.12345);
1080 EXPECT_EQ("1.123450", str);
1081 }
1082
1083 {
1084 CFX_ByteString str;
1085 str.Format("%0f", 1.12345);
1086 EXPECT_EQ("1.123450", str);
1087 }
1088
1089 {
1090 CFX_ByteString str;
1091 str.Format("%.1048576f", 1.2);
1092 EXPECT_EQ("Bad precision", str);
1093 }
1094 }
1095
TEST(fxcrt,EmptyByteString)1096 TEST(fxcrt, EmptyByteString) {
1097 CFX_ByteString empty_str;
1098 EXPECT_TRUE(empty_str.IsEmpty());
1099 EXPECT_EQ(0, empty_str.GetLength());
1100 const FX_CHAR* cstr = empty_str.c_str();
1101 EXPECT_EQ(0, FXSYS_strlen(cstr));
1102 }
1103