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

Side by Side Diff: courgette/bsdiff_memory_unittest.cc

Issue 2228003: Use an array of pages for the large arrays.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | « no previous file | courgette/courgette.gyp » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "courgette/third_party/bsdiff.h" 5 #include "courgette/third_party/bsdiff.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 12
13 #include "courgette/courgette.h" 13 #include "courgette/courgette.h"
14 #include "courgette/streams.h" 14 #include "courgette/streams.h"
15 15
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 class BSDiffMemoryTest : public testing::Test { 18 class BSDiffMemoryTest : public testing::Test {
19 public: 19 public:
20 std::string FileContents(const char* file_name) const; 20 std::string FileContents(const char* file_name) const;
21 void GenerateAndTestPatch(const std::string& a, const std::string& b) const; 21 void GenerateAndTestPatch(const std::string& a, const std::string& b) const;
22 22
23 std::string GenerateSyntheticInput(size_t length, int seed) const;
24
23 private: 25 private:
24 void SetUp() { 26 void SetUp() {
25 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_); 27 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_);
26 test_dir_ = test_dir_.AppendASCII("courgette"); 28 test_dir_ = test_dir_.AppendASCII("courgette");
27 test_dir_ = test_dir_.AppendASCII("testdata"); 29 test_dir_ = test_dir_.AppendASCII("testdata");
28 } 30 }
29 31
30 FilePath test_dir_; 32 FilePath test_dir_;
31 }; 33 };
32 34
(...skipping 24 matching lines...) Expand all
57 old2.Init(old_text.c_str(), old_text.length()); 59 old2.Init(old_text.c_str(), old_text.length());
58 patch2.Init(patch1); 60 patch2.Init(patch1);
59 61
60 courgette::SinkStream new2; 62 courgette::SinkStream new2;
61 status = ApplyBinaryPatch(&old2, &patch2, &new2); 63 status = ApplyBinaryPatch(&old2, &patch2, &new2);
62 EXPECT_EQ(courgette::OK, status); 64 EXPECT_EQ(courgette::OK, status);
63 EXPECT_EQ(new_text.length(), new2.Length()); 65 EXPECT_EQ(new_text.length(), new2.Length());
64 EXPECT_EQ(0, memcmp(new_text.c_str(), new2.Buffer(), new_text.length())); 66 EXPECT_EQ(0, memcmp(new_text.c_str(), new2.Buffer(), new_text.length()));
65 } 67 }
66 68
69 std::string BSDiffMemoryTest::GenerateSyntheticInput(size_t length, int seed)
70 const {
71 static const char* a[8] = {"O", "A", "x", "-", "y", ".", "|", ":"};
72 std::string result;
73 while (result.length() < length) {
74 seed = (seed + 17) * 1049 + (seed >> 27);
75 result.append(a[seed & 7]);
76 }
77 result.resize(length);
78 return result;
79 }
80
67 TEST_F(BSDiffMemoryTest, TestEmpty) { 81 TEST_F(BSDiffMemoryTest, TestEmpty) {
68 GenerateAndTestPatch("", ""); 82 GenerateAndTestPatch("", "");
69 } 83 }
70 84
71 TEST_F(BSDiffMemoryTest, TestEmptyVsNonempty) { 85 TEST_F(BSDiffMemoryTest, TestEmptyVsNonempty) {
72 GenerateAndTestPatch("", "xxx"); 86 GenerateAndTestPatch("", "xxx");
73 } 87 }
74 88
75 TEST_F(BSDiffMemoryTest, TestNonemptyVsEmpty) { 89 TEST_F(BSDiffMemoryTest, TestNonemptyVsEmpty) {
76 GenerateAndTestPatch("xxx", ""); 90 GenerateAndTestPatch("xxx", "");
(...skipping 15 matching lines...) Expand all
92 "I will not eat them with a MOUSE.\n" 106 "I will not eat them with a MOUSE.\n"
93 "I will not eat them in a HOUSE.\n" 107 "I will not eat them in a HOUSE.\n"
94 "I will not eat them in a HOUSE.\n" // Extra line. 108 "I will not eat them in a HOUSE.\n" // Extra line.
95 "I will not eat them here or THERE.\n" 109 "I will not eat them here or THERE.\n"
96 "I will not eat them ANYWHERE.\n" 110 "I will not eat them ANYWHERE.\n"
97 "I do not eat green eggs and HAM.\n" 111 "I do not eat green eggs and HAM.\n"
98 "I do not like them, Sam-I-am.\n"; 112 "I do not like them, Sam-I-am.\n";
99 GenerateAndTestPatch(file1, file2); 113 GenerateAndTestPatch(file1, file2);
100 } 114 }
101 115
116 TEST_F(BSDiffMemoryTest, TestNearPageArrayPageSize) {
117 // This magic number is the size of one block of the PageArray in
118 // third_party/bsdiff_create.cc.
119 size_t critical_size = 1 << 18;
120
121 // Test first-inputs with sizes that straddle the magic size to test this
122 // PageArray's internal boundary condition.
123
124 std::string file1 = GenerateSyntheticInput(critical_size, 0);
125 std::string file2 = GenerateSyntheticInput(critical_size, 1);
126 GenerateAndTestPatch(file1, file2);
127
128 std::string file1a = file1.substr(0, critical_size - 1);
129 GenerateAndTestPatch(file1a, file2);
130
131 std::string file1b = file1.substr(0, critical_size - 2);
132 GenerateAndTestPatch(file1b, file2);
133
134 std::string file1c = file1 + file1.substr(0, 1);
135 GenerateAndTestPatch(file1c, file2);
136 }
137
102 TEST_F(BSDiffMemoryTest, TestIndenticalDlls) { 138 TEST_F(BSDiffMemoryTest, TestIndenticalDlls) {
103 std::string file1 = FileContents("en-US.dll"); 139 std::string file1 = FileContents("en-US.dll");
104 GenerateAndTestPatch(file1, file1); 140 GenerateAndTestPatch(file1, file1);
105 } 141 }
106 142
107 TEST_F(BSDiffMemoryTest, TestDifferentExes) { 143 TEST_F(BSDiffMemoryTest, TestDifferentExes) {
108 std::string file1 = FileContents("setup1.exe"); 144 std::string file1 = FileContents("setup1.exe");
109 std::string file2 = FileContents("setup2.exe"); 145 std::string file2 = FileContents("setup2.exe");
110 GenerateAndTestPatch(file1, file2); 146 GenerateAndTestPatch(file1, file2);
111 } 147 }
OLDNEW
« no previous file with comments | « no previous file | courgette/courgette.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698