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

Side by Side Diff: remoting/base/util_unittest.cc

Issue 10441131: [Chromoting] Handle CR-LF correctly when transferring text items to and from the clipboard on a Win… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a static_cast to a unit test. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « remoting/base/util.cc ('k') | remoting/host/clipboard_win.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "remoting/base/util.h" 7 #include "remoting/base/util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/core/SkRect.h" 9 #include "third_party/skia/include/core/SkRect.h"
10 #include "third_party/skia/include/core/SkSize.h" 10 #include "third_party/skia/include/core/SkSize.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 dest_rect.fTop += 1; 177 dest_rect.fTop += 1;
178 if ((i & 4) != 0) 178 if ((i & 4) != 0)
179 dest_rect.fRight += 1; 179 dest_rect.fRight += 1;
180 if ((i & 8) != 0) 180 if ((i & 8) != 0)
181 dest_rect.fBottom += 1; 181 dest_rect.fBottom += 1;
182 182
183 tester.RunTest(dest_size, dest_rect); 183 tester.RunTest(dest_size, dest_rect);
184 } 184 }
185 } 185 }
186 186
187 TEST(ReplaceLfByCrLfTest, Basic) {
188 EXPECT_EQ("ab", ReplaceLfByCrLf("ab"));
189 EXPECT_EQ("\r\nab", ReplaceLfByCrLf("\nab"));
190 EXPECT_EQ("\r\nab\r\n", ReplaceLfByCrLf("\nab\n"));
191 EXPECT_EQ("\r\nab\r\ncd", ReplaceLfByCrLf("\nab\ncd"));
192 EXPECT_EQ("\r\nab\r\ncd\r\n", ReplaceLfByCrLf("\nab\ncd\n"));
193 EXPECT_EQ("\r\n\r\nab\r\n\r\ncd\r\n\r\n",
194 ReplaceLfByCrLf("\n\nab\n\ncd\n\n"));
195 }
196
197 TEST(ReplaceLfByCrLfTest, Speed) {
198 int kLineSize = 128;
199 std::string line(kLineSize, 'a');
200 line[kLineSize - 1] = '\n';
201 // Make a 10M string.
202 int kLineNum = 10 * 1024 * 1024 / kLineSize;
203 std::string buffer;
204 buffer.resize(kLineNum * kLineSize);
205 for (int i = 0; i < kLineNum; ++i) {
206 memcpy(&buffer[i * kLineSize], &line[0], kLineSize);
207 }
208 // Convert the string.
209 buffer = ReplaceLfByCrLf(buffer);
210 // Check the converted string.
211 EXPECT_EQ(static_cast<size_t>((kLineSize + 1) * kLineNum), buffer.size());
212 const char* p = &buffer[0];
213 for (int i = 0; i < kLineNum; ++i) {
214 EXPECT_EQ(0, memcmp(&line[0], p, kLineSize - 1));
215 p += kLineSize - 1;
216 EXPECT_EQ('\r', *p++);
217 EXPECT_EQ('\n', *p++);
218 }
219 }
220
221 TEST(ReplaceCrLfByLfTest, Basic) {
222 EXPECT_EQ("ab", ReplaceCrLfByLf("ab"));
223 EXPECT_EQ("\nab", ReplaceCrLfByLf("\r\nab"));
224 EXPECT_EQ("\nab\n", ReplaceCrLfByLf("\r\nab\r\n"));
225 EXPECT_EQ("\nab\ncd", ReplaceCrLfByLf("\r\nab\r\ncd"));
226 EXPECT_EQ("\nab\ncd\n", ReplaceCrLfByLf("\r\nab\r\ncd\n"));
227 EXPECT_EQ("\n\nab\n\ncd\n\n",
228 ReplaceCrLfByLf("\r\n\r\nab\r\n\r\ncd\r\n\r\n"));
229 EXPECT_EQ("\rab\rcd\r", ReplaceCrLfByLf("\rab\rcd\r"));
230 }
231
232 TEST(ReplaceCrLfByLfTest, Speed) {
233 int kLineSize = 128;
234 std::string line(kLineSize, 'a');
235 line[kLineSize - 2] = '\r';
236 line[kLineSize - 1] = '\n';
237 // Make a 10M string.
238 int kLineNum = 10 * 1024 * 1024 / kLineSize;
239 std::string buffer;
240 buffer.resize(kLineNum * kLineSize);
241 for (int i = 0; i < kLineNum; ++i) {
242 memcpy(&buffer[i * kLineSize], &line[0], kLineSize);
243 }
244 // Convert the string.
245 buffer = ReplaceCrLfByLf(buffer);
246 // Check the converted string.
247 EXPECT_EQ(static_cast<size_t>((kLineSize - 1) * kLineNum), buffer.size());
248 const char* p = &buffer[0];
249 for (int i = 0; i < kLineNum; ++i) {
250 EXPECT_EQ(0, memcmp(&line[0], p, kLineSize - 2));
251 p += kLineSize - 2;
252 EXPECT_EQ('\n', *p++);
253 }
254 }
255
187 } // namespace remoting 256 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/util.cc ('k') | remoting/host/clipboard_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698