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

Side by Side Diff: chrome/browser/sessions/compress_data_helper_unittest.cc

Issue 9447084: Refactor Pickle Read methods to use higher performance PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile (racing with incoming CLs) Created 8 years, 9 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
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 "chrome/browser/sessions/compress_data_helper.h" 5 #include "chrome/browser/sessions/compress_data_helper.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 typedef testing::Test CompressDataHelperTest; 10 typedef testing::Test CompressDataHelperTest;
11 11
12 TEST_F(CompressDataHelperTest, CompressAndDecompressData) { 12 TEST_F(CompressDataHelperTest, CompressAndDecompressData) {
13 std::string data = "test data for compression and decompression"; 13 std::string data = "test data for compression and decompression";
14 // Add NULL bytes. 14 // Add NULL bytes.
15 data[3] = data[8] = 0; 15 data[3] = data[8] = 0;
16 16
17 Pickle pickle; 17 Pickle pickle;
18 int bytes_written = 0; 18 int bytes_written = 0;
19 int max_bytes = 100; 19 int max_bytes = 100;
20 CompressDataHelper::CompressAndWriteStringToPickle( 20 CompressDataHelper::CompressAndWriteStringToPickle(
21 data, max_bytes, &pickle, &bytes_written); 21 data, max_bytes, &pickle, &bytes_written);
22 22
23 EXPECT_GT(bytes_written, 0); 23 EXPECT_GT(bytes_written, 0);
24 EXPECT_LT(bytes_written, max_bytes + 1); 24 EXPECT_LT(bytes_written, max_bytes + 1);
25 25
26 void* it = NULL; 26 PickleIterator it(pickle);
27 std::string data_out; 27 std::string data_out;
28 28
29 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle( 29 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle(
30 pickle, &it, &data_out)); 30 pickle, &it, &data_out));
31 31
32 ASSERT_EQ(data.size(), data_out.size()); 32 ASSERT_EQ(data.size(), data_out.size());
33 for (size_t i = 0; i < data_out.size(); ++i) 33 for (size_t i = 0; i < data_out.size(); ++i)
34 EXPECT_EQ(data_out[i], data[i]); 34 EXPECT_EQ(data_out[i], data[i]);
35 } 35 }
36 36
37 TEST_F(CompressDataHelperTest, CompressAndDecompressEmptyData) { 37 TEST_F(CompressDataHelperTest, CompressAndDecompressEmptyData) {
38 std::string empty; 38 std::string empty;
39 39
40 Pickle pickle; 40 Pickle pickle;
41 int bytes_written = 0; 41 int bytes_written = 0;
42 int max_bytes = 100; 42 int max_bytes = 100;
43 CompressDataHelper::CompressAndWriteStringToPickle( 43 CompressDataHelper::CompressAndWriteStringToPickle(
44 empty, max_bytes, &pickle, &bytes_written); 44 empty, max_bytes, &pickle, &bytes_written);
45 45
46 EXPECT_EQ(0, bytes_written); 46 EXPECT_EQ(0, bytes_written);
47 47
48 void* it = NULL; 48 PickleIterator it(pickle);
49 std::string data_out; 49 std::string data_out;
50 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle( 50 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle(
51 pickle, &it, &data_out)); 51 pickle, &it, &data_out));
52 52
53 EXPECT_EQ(0U, data_out.size()); 53 EXPECT_EQ(0U, data_out.size());
54 } 54 }
55 55
56 TEST_F(CompressDataHelperTest, TooMuchData) { 56 TEST_F(CompressDataHelperTest, TooMuchData) {
57 std::string data = "Some data that clearly cannot be compressed to 2 bytes"; 57 std::string data = "Some data that clearly cannot be compressed to 2 bytes";
58 58
59 Pickle pickle; 59 Pickle pickle;
60 int bytes_written = 0; 60 int bytes_written = 0;
61 int max_bytes = 2; 61 int max_bytes = 2;
62 CompressDataHelper::CompressAndWriteStringToPickle( 62 CompressDataHelper::CompressAndWriteStringToPickle(
63 data, max_bytes, &pickle, &bytes_written); 63 data, max_bytes, &pickle, &bytes_written);
64 64
65 EXPECT_EQ(0, bytes_written); 65 EXPECT_EQ(0, bytes_written);
66 66
67 // When the data is read, we get an empty string back. 67 // When the data is read, we get an empty string back.
68 void* it = NULL; 68 PickleIterator it(pickle);
69 std::string data_out; 69 std::string data_out;
70 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle( 70 ASSERT_TRUE(CompressDataHelper::ReadAndDecompressStringFromPickle(
71 pickle, &it, &data_out)); 71 pickle, &it, &data_out));
72 72
73 EXPECT_EQ(0U, data_out.size()); 73 EXPECT_EQ(0U, data_out.size());
74 } 74 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/compress_data_helper.cc ('k') | chrome/browser/sessions/session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698