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

Side by Side Diff: courgette/bsdiff_memory_unittest.cc

Issue 2031193002: [Courgette] Refactor BSDiff namespaces and bsdiff::search() interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 4 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
« no previous file with comments | « components/update_client/component_patcher_operation.cc ('k') | courgette/courgette_tool.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bsdiff.h" 5 #include "courgette/third_party/bsdiff/bsdiff.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "courgette/base_test_unittest.h" 9 #include "courgette/base_test_unittest.h"
10 #include "courgette/courgette.h" 10 #include "courgette/courgette.h"
11 #include "courgette/streams.h" 11 #include "courgette/streams.h"
12 12
13 class BSDiffMemoryTest : public BaseTest { 13 class BSDiffMemoryTest : public BaseTest {
14 public: 14 public:
15 void GenerateAndTestPatch(const std::string& a, const std::string& b) const; 15 void GenerateAndTestPatch(const std::string& a, const std::string& b) const;
16 16
17 std::string GenerateSyntheticInput(size_t length, int seed) const; 17 std::string GenerateSyntheticInput(size_t length, int seed) const;
18 }; 18 };
19 19
20 void BSDiffMemoryTest::GenerateAndTestPatch(const std::string& old_text, 20 void BSDiffMemoryTest::GenerateAndTestPatch(const std::string& old_text,
21 const std::string& new_text) const { 21 const std::string& new_text) const {
22 courgette::SourceStream old1; 22 courgette::SourceStream old1;
23 courgette::SourceStream new1; 23 courgette::SourceStream new1;
24 old1.Init(old_text.c_str(), old_text.length()); 24 old1.Init(old_text.c_str(), old_text.length());
25 new1.Init(new_text.c_str(), new_text.length()); 25 new1.Init(new_text.c_str(), new_text.length());
26 26
27 courgette::SinkStream patch1; 27 courgette::SinkStream patch1;
28 courgette::BSDiffStatus status = CreateBinaryPatch(&old1, &new1, &patch1); 28 bsdiff::BSDiffStatus status =
29 EXPECT_EQ(courgette::OK, status); 29 bsdiff::CreateBinaryPatch(&old1, &new1, &patch1);
30 EXPECT_EQ(bsdiff::OK, status);
30 31
31 courgette::SourceStream old2; 32 courgette::SourceStream old2;
32 courgette::SourceStream patch2; 33 courgette::SourceStream patch2;
33 old2.Init(old_text.c_str(), old_text.length()); 34 old2.Init(old_text.c_str(), old_text.length());
34 patch2.Init(patch1); 35 patch2.Init(patch1);
35 36
36 courgette::SinkStream new2; 37 courgette::SinkStream new2;
37 status = ApplyBinaryPatch(&old2, &patch2, &new2); 38 status = bsdiff::ApplyBinaryPatch(&old2, &patch2, &new2);
38 EXPECT_EQ(courgette::OK, status); 39 EXPECT_EQ(bsdiff::OK, status);
39 EXPECT_EQ(new_text.length(), new2.Length()); 40 EXPECT_EQ(new_text.length(), new2.Length());
40 EXPECT_EQ(0, memcmp(new_text.c_str(), new2.Buffer(), new_text.length())); 41 EXPECT_EQ(0, memcmp(new_text.c_str(), new2.Buffer(), new_text.length()));
41 } 42 }
42 43
43 std::string BSDiffMemoryTest::GenerateSyntheticInput(size_t length, int seed) 44 std::string BSDiffMemoryTest::GenerateSyntheticInput(size_t length, int seed)
44 const { 45 const {
45 static const char* a[8] = {"O", "A", "x", "-", "y", ".", "|", ":"}; 46 static const char* a[8] = {"O", "A", "x", "-", "y", ".", "|", ":"};
46 std::string result; 47 std::string result;
47 while (result.length() < length) { 48 while (result.length() < length) {
48 seed = (seed + 17) * 1049 + (seed >> 27); 49 seed = (seed + 17) * 1049 + (seed >> 27);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 std::string file1 = FileContents("setup1.exe"); 119 std::string file1 = FileContents("setup1.exe");
119 std::string file2 = FileContents("setup2.exe"); 120 std::string file2 = FileContents("setup2.exe");
120 GenerateAndTestPatch(file1, file2); 121 GenerateAndTestPatch(file1, file2);
121 } 122 }
122 123
123 TEST_F(BSDiffMemoryTest, TestDifferentElfs) { 124 TEST_F(BSDiffMemoryTest, TestDifferentElfs) {
124 std::string file1 = FileContents("elf-32-1"); 125 std::string file1 = FileContents("elf-32-1");
125 std::string file2 = FileContents("elf-32-2"); 126 std::string file2 = FileContents("elf-32-2");
126 GenerateAndTestPatch(file1, file2); 127 GenerateAndTestPatch(file1, file2);
127 } 128 }
OLDNEW
« no previous file with comments | « components/update_client/component_patcher_operation.cc ('k') | courgette/courgette_tool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698