Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: core/src/fxcrt/fx_basic_wstring_unittest.cpp

Issue 1095893005: Merge to XFA: Add missing operators for CFX_xxxString combo patch. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_maps.cpp ('k') | xfa/src/fxfa/src/parser/xfa_object_imp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(L'a', abc[0]);
13 EXPECT_EQ(L'b', abc[1]);
14 EXPECT_EQ(L'c', abc[2]);
15 EXPECT_EQ(L'\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 }
69
70 TEST(fxcrt, WideStringCOperatorSubscript) {
71 // CFX_WideStringC includes the NUL terminator for non-empty strings.
72 CFX_WideStringC abc(L"abc");
73 EXPECT_EQ(L'a', abc[0]);
74 EXPECT_EQ(L'b', abc[1]);
75 EXPECT_EQ(L'c', abc[2]);
76 EXPECT_EQ(L'\0', abc[3]);
77 }
78
79 TEST(fxcrt, WideStringCOperatorLT) {
80 CFX_WideStringC empty;
81 CFX_WideStringC a(L"a");
82 CFX_WideStringC abc(L"\x0110qq"); // Comes before despite endianness.
83 CFX_WideStringC def(L"\x1001qq"); // Comes after despite endianness.
84
85 EXPECT_FALSE(empty < empty);
86 EXPECT_FALSE(a < a);
87 EXPECT_FALSE(abc < abc);
88 EXPECT_FALSE(def < def);
89
90 EXPECT_TRUE(empty < a);
91 EXPECT_FALSE(a < empty);
92
93 EXPECT_TRUE(empty < abc);
94 EXPECT_FALSE(abc < empty);
95
96 EXPECT_TRUE(empty < def);
97 EXPECT_FALSE(def < empty);
98
99 EXPECT_TRUE(a < abc);
100 EXPECT_FALSE(abc < a);
101
102 EXPECT_TRUE(a < def);
103 EXPECT_FALSE(def < a);
104
105 EXPECT_TRUE(abc < def);
106 EXPECT_FALSE(def < abc);
107 }
108
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_maps.cpp ('k') | xfa/src/fxfa/src/parser/xfa_object_imp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698