OLD | NEW |
1 // Copyright (c) 2009 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.h" | 5 #include "courgette/third_party/bsdiff.h" |
6 | 6 |
7 #include <string> | 7 #include "courgette/base_test_unittest.h" |
8 | |
9 #include "base/file_util.h" | |
10 #include "base/path_service.h" | |
11 #include "base/string_util.h" | |
12 | |
13 #include "courgette/courgette.h" | 8 #include "courgette/courgette.h" |
14 #include "courgette/streams.h" | 9 #include "courgette/streams.h" |
15 | 10 |
16 #include "testing/gtest/include/gtest/gtest.h" | 11 class BSDiffMemoryTest : public BaseTest { |
17 | |
18 class BSDiffMemoryTest : public testing::Test { | |
19 public: | 12 public: |
20 std::string FileContents(const char* file_name) const; | |
21 void GenerateAndTestPatch(const std::string& a, const std::string& b) const; | 13 void GenerateAndTestPatch(const std::string& a, const std::string& b) const; |
22 | 14 |
23 std::string GenerateSyntheticInput(size_t length, int seed) const; | 15 std::string GenerateSyntheticInput(size_t length, int seed) const; |
24 | |
25 private: | |
26 void SetUp() { | |
27 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_); | |
28 test_dir_ = test_dir_.AppendASCII("courgette"); | |
29 test_dir_ = test_dir_.AppendASCII("testdata"); | |
30 } | |
31 | |
32 FilePath test_dir_; | |
33 }; | 16 }; |
34 | 17 |
35 // Reads a test file into a string. | |
36 std::string BSDiffMemoryTest::FileContents(const char* file_name) const { | |
37 FilePath file_path = test_dir_; | |
38 file_path = file_path.AppendASCII(file_name); | |
39 std::string file_bytes; | |
40 if (!file_util::ReadFileToString(file_path, &file_bytes)) { | |
41 EXPECT_TRUE(!"Could not read test data"); | |
42 } | |
43 return file_bytes; | |
44 } | |
45 | |
46 void BSDiffMemoryTest::GenerateAndTestPatch(const std::string& old_text, | 18 void BSDiffMemoryTest::GenerateAndTestPatch(const std::string& old_text, |
47 const std::string& new_text) const { | 19 const std::string& new_text) const { |
48 courgette::SourceStream old1; | 20 courgette::SourceStream old1; |
49 courgette::SourceStream new1; | 21 courgette::SourceStream new1; |
50 old1.Init(old_text.c_str(), old_text.length()); | 22 old1.Init(old_text.c_str(), old_text.length()); |
51 new1.Init(new_text.c_str(), new_text.length()); | 23 new1.Init(new_text.c_str(), new_text.length()); |
52 | 24 |
53 courgette::SinkStream patch1; | 25 courgette::SinkStream patch1; |
54 courgette::BSDiffStatus status = CreateBinaryPatch(&old1, &new1, &patch1); | 26 courgette::BSDiffStatus status = CreateBinaryPatch(&old1, &new1, &patch1); |
55 EXPECT_EQ(courgette::OK, status); | 27 EXPECT_EQ(courgette::OK, status); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 TEST_F(BSDiffMemoryTest, TestIndenticalDlls) { | 110 TEST_F(BSDiffMemoryTest, TestIndenticalDlls) { |
139 std::string file1 = FileContents("en-US.dll"); | 111 std::string file1 = FileContents("en-US.dll"); |
140 GenerateAndTestPatch(file1, file1); | 112 GenerateAndTestPatch(file1, file1); |
141 } | 113 } |
142 | 114 |
143 TEST_F(BSDiffMemoryTest, TestDifferentExes) { | 115 TEST_F(BSDiffMemoryTest, TestDifferentExes) { |
144 std::string file1 = FileContents("setup1.exe"); | 116 std::string file1 = FileContents("setup1.exe"); |
145 std::string file2 = FileContents("setup2.exe"); | 117 std::string file2 = FileContents("setup2.exe"); |
146 GenerateAndTestPatch(file1, file2); | 118 GenerateAndTestPatch(file1, file2); |
147 } | 119 } |
OLD | NEW |