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

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

Issue 1099193002: Add missing operators for CFX_WideStringC. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
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
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 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str)) 9 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str))
10 10
11 TEST(fxcrt, WideStringUTF16LE_Encode) { 11 TEST(fxcrt, WideStringUTF16LE_Encode) {
12 struct UTF16LEEncodeCase { 12 struct UTF16LEEncodeCase {
13 CFX_WideString ws; 13 CFX_WideString ws;
14 CFX_ByteString bs; 14 CFX_ByteString bs;
15 } utf16le_encode_cases[] = { 15 } utf16le_encode_cases[] = {
16 { L"", ByteStringLiteral("\0\0") }, 16 { L"", ByteStringLiteral("\0\0") },
17 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") }, 17 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") },
18 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") }, 18 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") },
19 { L"abc\0def", ByteStringLiteral("a\0b\0c\0\0\0") }, 19 { L"abc\0def", ByteStringLiteral("a\0b\0c\0\0\0") },
20 { L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc\0\0") }, 20 { L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc\0\0") },
21 { L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61\0\0") }, 21 { L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61\0\0") },
22 }; 22 };
23 23
24 for (size_t i = 0; i < FX_ArraySize(utf16le_encode_cases); ++i) { 24 for (size_t i = 0; i < FX_ArraySize(utf16le_encode_cases); ++i) {
25 EXPECT_EQ(utf16le_encode_cases[i].bs, 25 EXPECT_EQ(utf16le_encode_cases[i].bs,
26 utf16le_encode_cases[i].ws.UTF16LE_Encode()) 26 utf16le_encode_cases[i].ws.UTF16LE_Encode())
27 << " for case number " << i; 27 << " for case number " << i;
28 } 28 }
29 } 29 }
30
31 TEST(fxcrt, WideStringCOperatorSubscript) {
32 // CFX_WideStringC includes the NUL terminator for non-empty strings.
33 CFX_WideStringC abc(L"abc");
34 EXPECT_EQ('a', abc[0]);
Lei Zhang 2015/04/21 22:07:56 I'm surprised this compiles given that operator[]
Tom Sepez 2015/04/22 17:06:45 Done.
35 EXPECT_EQ('b', abc[1]);
36 EXPECT_EQ('c', abc[2]);
37 EXPECT_EQ(0, abc[3]);
38 }
39
40 TEST(fxcrt, WideStringCOperatorLT) {
41 CFX_WideStringC empty;
42 CFX_WideStringC a(L"a");
43 CFX_WideStringC abc(L"\x0110qq"); // Comes before despite endianness.
44 CFX_WideStringC def(L"\x1001qq"); // Comes after despite endianness.
45
46 EXPECT_FALSE(empty < empty);
47 EXPECT_FALSE(a < a);
48 EXPECT_FALSE(abc < abc);
49 EXPECT_FALSE(def < def);
50
51 EXPECT_TRUE(empty < a);
52 EXPECT_FALSE(a < empty);
53
54 EXPECT_TRUE(empty < abc);
55 EXPECT_FALSE(abc < empty);
56
57 EXPECT_TRUE(empty < def);
58 EXPECT_FALSE(def < empty);
59
60 EXPECT_TRUE(a < abc);
61 EXPECT_FALSE(abc < a);
62
63 EXPECT_TRUE(a < def);
64 EXPECT_FALSE(def < a);
65
66 EXPECT_TRUE(abc < def);
67 EXPECT_FALSE(def < abc);
68 }
OLDNEW
« core/include/fxcrt/fx_string.h ('K') | « core/include/fxcrt/fx_string.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698