OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "../../../testing/fx_string_testhelpers.h" | 6 #include "../../../testing/fx_string_testhelpers.h" |
7 #include "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
8 | 8 |
9 TEST(fxcrt, WideStringOperatorSubscript) { | |
10 // CFX_WideString includes the NUL terminator for non-empty strings. | |
11 CFX_WideString abc(L"abc"); | |
12 EXPECT_EQ('a', abc[0]); | |
Lei Zhang
2015/04/21 22:12:33
Also concerned whether this actually compiles.
| |
13 EXPECT_EQ('b', abc[1]); | |
14 EXPECT_EQ('c', abc[2]); | |
15 EXPECT_EQ(0, abc[3]); | |
16 } | |
17 | |
18 TEST(fxcrt, WideStringOperatorLT) { | |
19 CFX_WideString empty; | |
20 CFX_WideString a(L"a"); | |
21 CFX_WideString abc(L"\x0110qq"); // Comes before despite endianness. | |
22 CFX_WideString def(L"\x1001qq"); // Comes after despite endianness. | |
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 | |
9 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str)) | 48 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str)) |
10 | 49 |
11 TEST(fxcrt, WideStringUTF16LE_Encode) { | 50 TEST(fxcrt, WideStringUTF16LE_Encode) { |
12 struct UTF16LEEncodeCase { | 51 struct UTF16LEEncodeCase { |
13 CFX_WideString ws; | 52 CFX_WideString ws; |
14 CFX_ByteString bs; | 53 CFX_ByteString bs; |
15 } utf16le_encode_cases[] = { | 54 } utf16le_encode_cases[] = { |
16 { L"", ByteStringLiteral("\0\0") }, | 55 { L"", ByteStringLiteral("\0\0") }, |
17 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") }, | 56 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") }, |
18 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") }, | 57 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") }, |
19 { L"abc\0def", ByteStringLiteral("a\0b\0c\0\0\0") }, | 58 { L"abc\0def", ByteStringLiteral("a\0b\0c\0\0\0") }, |
20 { L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc\0\0") }, | 59 { L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc\0\0") }, |
21 { L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61\0\0") }, | 60 { L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61\0\0") }, |
22 }; | 61 }; |
23 | 62 |
24 for (size_t i = 0; i < FX_ArraySize(utf16le_encode_cases); ++i) { | 63 for (size_t i = 0; i < FX_ArraySize(utf16le_encode_cases); ++i) { |
25 EXPECT_EQ(utf16le_encode_cases[i].bs, | 64 EXPECT_EQ(utf16le_encode_cases[i].bs, |
26 utf16le_encode_cases[i].ws.UTF16LE_Encode()) | 65 utf16le_encode_cases[i].ws.UTF16LE_Encode()) |
27 << " for case number " << i; | 66 << " for case number " << i; |
28 } | 67 } |
29 } | 68 } |
OLD | NEW |