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

Side by Side Diff: xfa/fde/cfde_txtedtbuf_unittest.cpp

Issue 2614383003: Add CFDE_TxtEdtBuf tests (Closed)
Patch Set: Created 3 years, 11 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
(Empty)
1 // Copyright 2017 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 "xfa/fde/cfde_txtedtbuf.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/test_support.h"
9 #include "third_party/base/ptr_util.h"
10
11 class CFDE_TxtEdtBufTest : public testing::Test {
12 public:
13 void SetUp() override {
14 buf = pdfium::MakeUnique<CFDE_TxtEdtBuf>();
15 buf->SetChunkSizeForTesting(5);
16 }
17 size_t ChunkCount() const { return buf->m_Chunks.GetSize(); }
18
19 std::unique_ptr<CFDE_TxtEdtBuf> buf;
Tom Sepez 2017/01/09 21:07:28 nit: buf_
dsinclair 2017/01/09 21:20:00 Done.
20 };
21
22 typedef CFDE_TxtEdtBufTest CFDE_TxtEdtBufTestDeathTest;
Tom Sepez 2017/01/09 21:07:28 nit: using CFDE_TxtEdtBufTestDeathTest = ...
dsinclair 2017/01/09 21:20:00 Done.
23
24 TEST_F(CFDE_TxtEdtBufTest, SetTextLessThenChunkSize) {
25 buf->SetText(L"Hi");
26 EXPECT_EQ(1UL, ChunkCount());
27 EXPECT_EQ(L"Hi", buf->GetText());
28 EXPECT_EQ(2, buf->GetTextLength());
Tom Sepez 2017/01/09 21:07:27 Nit: I'd check this first, then put the result of
dsinclair 2017/01/09 21:20:00 Done. You don't have to get the text to get the l
Tom Sepez 2017/01/09 21:27:10 Ok, but do we do that ever?
29 }
30
31 TEST_F(CFDE_TxtEdtBufTest, InsertAppendChunk) {
32 buf->SetText(L"Hi");
33 EXPECT_EQ(1UL, ChunkCount());
Tom Sepez 2017/01/09 21:07:27 nit: we already made this check above, probably ca
dsinclair 2017/01/09 21:20:00 Done.
34
35 CFX_WideString end = L" World";
36 buf->Insert(2, end.c_str(), end.GetLength());
37 EXPECT_EQ(3UL, ChunkCount());
38 EXPECT_EQ(L"Hi World", buf->GetText());
39 EXPECT_EQ(8, buf->GetTextLength());
40 }
41
42 TEST_F(CFDE_TxtEdtBufTest, InsertPrependChunk) {
43 buf->SetText(L"Hi");
44 EXPECT_EQ(1UL, ChunkCount());
45
46 CFX_WideString end = L"World ";
47 buf->Insert(0, end.c_str(), end.GetLength());
48 EXPECT_EQ(3UL, ChunkCount());
49 EXPECT_EQ(L"World Hi", buf->GetText());
50 EXPECT_EQ(8, buf->GetTextLength());
51 }
52
53 TEST_F(CFDE_TxtEdtBufTest, InsertBetweenChunks) {
54 buf->SetText(L"Hello World");
55 EXPECT_EQ(3UL, ChunkCount());
56
57 CFX_WideString inst = L"there ";
58 buf->Insert(6, inst.c_str(), inst.GetLength());
59 EXPECT_EQ(5UL, ChunkCount());
60 EXPECT_EQ(L"Hello there World", buf->GetText());
61 EXPECT_EQ(17, buf->GetTextLength());
62 }
63
64 TEST_F(CFDE_TxtEdtBufTestDeathTest, InsertBadIndexes) {
65 CFX_WideString inst = L"there ";
66
67 buf->SetText(L"Hi");
68 EXPECT_DEATH(buf->Insert(-4, inst.c_str(), inst.GetLength()), "Assertion");
69 EXPECT_DEATH(buf->Insert(9999, inst.c_str(), inst.GetLength()), "Assertion");
70 EXPECT_DEATH(buf->Insert(1, inst.c_str(), -6), "Assertion");
71 }
72
73 TEST_F(CFDE_TxtEdtBufTest, SetText) {
74 buf->SetText(L"Hello World");
75 EXPECT_EQ(3UL, ChunkCount());
76 EXPECT_EQ(11, buf->GetTextLength());
77
78 buf->SetText(L"Hi");
79 // Don't remove chunks on setting shorter text.
80 EXPECT_EQ(3UL, ChunkCount());
81 EXPECT_EQ(L"Hi", buf->GetText());
82 EXPECT_EQ(2, buf->GetTextLength());
83 }
84
85 TEST_F(CFDE_TxtEdtBufTest, DeleteMiddleText) {
86 buf->SetText(L"Hello there World");
87 buf->Delete(6, 6);
88 EXPECT_EQ(4UL, ChunkCount());
89 EXPECT_EQ(L"Hello World", buf->GetText());
90 EXPECT_EQ(11, buf->GetTextLength());
91 }
92
93 TEST_F(CFDE_TxtEdtBufTest, DeleteEndText) {
94 buf->SetText(L"Hello World");
95 buf->Delete(5, 6);
96 EXPECT_EQ(1UL, ChunkCount());
97 EXPECT_EQ(L"Hello", buf->GetText());
98 EXPECT_EQ(5, buf->GetTextLength());
99 }
100
101 TEST_F(CFDE_TxtEdtBufTest, DeleteStartText) {
102 buf->SetText(L"Hello World");
103 buf->Delete(0, 6);
104 EXPECT_EQ(2UL, ChunkCount());
105 EXPECT_EQ(L"World", buf->GetText());
106 EXPECT_EQ(5, buf->GetTextLength());
107 }
108
109 TEST_F(CFDE_TxtEdtBufTest, DeleteAllText) {
110 buf->SetText(L"Hello World");
111 buf->Delete(0, 11);
112 EXPECT_EQ(0UL, ChunkCount());
113 EXPECT_EQ(L"", buf->GetText());
114 EXPECT_EQ(0, buf->GetTextLength());
115 }
116
117 TEST_F(CFDE_TxtEdtBufTestDeathTest, DeleteWithBadIdx) {
118 buf->SetText(L"Hi");
119 EXPECT_DEATH(buf->Delete(-10, 4), "Assertion");
120 EXPECT_DEATH(buf->Delete(1, -5), "Assertion");
121 EXPECT_DEATH(buf->Delete(5, 1), "Assertion");
122 EXPECT_DEATH(buf->Delete(0, 10000), "Assertion");
123 }
124
125 TEST_F(CFDE_TxtEdtBufTest, ClearWithRelease) {
126 buf->SetText(L"Hello World");
127 buf->Clear(true);
128 EXPECT_EQ(0UL, ChunkCount());
129 EXPECT_EQ(L"", buf->GetText());
130 EXPECT_EQ(0, buf->GetTextLength());
131 }
132
133 TEST_F(CFDE_TxtEdtBufTest, ClearWithoutRelease) {
134 buf->SetText(L"Hello World");
135 buf->Clear(false);
136 EXPECT_EQ(3UL, ChunkCount());
137 EXPECT_EQ(L"", buf->GetText());
138 EXPECT_EQ(0, buf->GetTextLength());
139 }
140
141 TEST_F(CFDE_TxtEdtBufTest, GetCharByIndex) {
142 buf->SetText(L"Hello world");
143 EXPECT_EQ(L"e", CFX_WideString(buf->GetCharByIndex(1)));
144 EXPECT_EQ(L"o", CFX_WideString(buf->GetCharByIndex(7)));
145 }
146
147 TEST_F(CFDE_TxtEdtBufTestDeathTest, GetCharByIndex) {
148 buf->SetText(L"Hi");
149 EXPECT_DEATH(buf->GetCharByIndex(-1), "Assertion");
150 EXPECT_DEATH(buf->GetCharByIndex(100), "Assertion");
151 }
152
153 TEST_F(CFDE_TxtEdtBufTest, GetRange) {
154 buf->SetText(L"Hello World");
155 EXPECT_EQ(L"", buf->GetRange(1, 0));
156 EXPECT_EQ(L"ello", buf->GetRange(1, 4));
157 EXPECT_EQ(L"lo Wo", buf->GetRange(3, 5));
158 }
159
160 TEST_F(CFDE_TxtEdtBufTestDeathTest, GetRange) {
161 buf->SetText(L"Hi");
162 EXPECT_DEATH(buf->GetRange(1, -1), "Assertion");
163 EXPECT_DEATH(buf->GetRange(-1, 1), "Assertion");
164 EXPECT_DEATH(buf->GetRange(10, 1), "Assertion");
165 EXPECT_DEATH(buf->GetRange(1, 100), "Assertion");
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698