summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--courgette/base_test_unittest.cc27
-rw-r--r--courgette/base_test_unittest.h26
-rw-r--r--courgette/bsdiff_memory_unittest.cc34
-rw-r--r--courgette/courgette.gyp7
-rw-r--r--courgette/encode_decode_unittest.cc36
-rw-r--r--courgette/encoded_program_fuzz_unittest.cc36
-rw-r--r--courgette/image_info_unittest.cc34
-rw-r--r--courgette/versioning_unittest.cc57
8 files changed, 126 insertions, 131 deletions
diff --git a/courgette/base_test_unittest.cc b/courgette/base_test_unittest.cc
new file mode 100644
index 0000000..6da56fb
--- /dev/null
+++ b/courgette/base_test_unittest.cc
@@ -0,0 +1,27 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "courgette/base_test_unittest.h"
+
+#include "base/path_service.h"
+
+void BaseTest::SetUp() {
+ PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_);
+ test_dir_ = test_dir_.AppendASCII("courgette");
+ test_dir_ = test_dir_.AppendASCII("testdata");
+}
+
+void BaseTest::TearDown() {
+}
+
+// Reads a test file into a string.
+std::string BaseTest::FileContents(const char* file_name) const {
+ FilePath file_path = test_dir_;
+ file_path = file_path.AppendASCII(file_name);
+ std::string file_bytes;
+
+ EXPECT_TRUE(file_util::ReadFileToString(file_path, &file_bytes));
+
+ return file_bytes;
+}
diff --git a/courgette/base_test_unittest.h b/courgette/base_test_unittest.h
new file mode 100644
index 0000000..777495a
--- /dev/null
+++ b/courgette/base_test_unittest.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#ifndef COURGETTE_BASE_TEST_UNITTEST_H_
+#define COURGETTE_BASE_TEST_UNITTEST_H_
+
+#include <string>
+
+#include "base/file_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class BaseTest : public testing::Test {
+ public:
+ std::string FileContents(const char* file_name) const;
+
+ private:
+ virtual void SetUp();
+ virtual void TearDown();
+
+ FilePath test_dir_;
+};
+
+#endif // COURGETTE_BASE_TEST_UNITTEST_H_
diff --git a/courgette/bsdiff_memory_unittest.cc b/courgette/bsdiff_memory_unittest.cc
index 75de082..ce80eb7 100644
--- a/courgette/bsdiff_memory_unittest.cc
+++ b/courgette/bsdiff_memory_unittest.cc
@@ -1,48 +1,20 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "courgette/third_party/bsdiff.h"
-#include <string>
-
-#include "base/file_util.h"
-#include "base/path_service.h"
-#include "base/string_util.h"
-
+#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class BSDiffMemoryTest : public testing::Test {
+class BSDiffMemoryTest : public BaseTest {
public:
- std::string FileContents(const char* file_name) const;
void GenerateAndTestPatch(const std::string& a, const std::string& b) const;
std::string GenerateSyntheticInput(size_t length, int seed) const;
-
- private:
- void SetUp() {
- PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_);
- test_dir_ = test_dir_.AppendASCII("courgette");
- test_dir_ = test_dir_.AppendASCII("testdata");
- }
-
- FilePath test_dir_;
};
-// Reads a test file into a string.
-std::string BSDiffMemoryTest::FileContents(const char* file_name) const {
- FilePath file_path = test_dir_;
- file_path = file_path.AppendASCII(file_name);
- std::string file_bytes;
- if (!file_util::ReadFileToString(file_path, &file_bytes)) {
- EXPECT_TRUE(!"Could not read test data");
- }
- return file_bytes;
-}
-
void BSDiffMemoryTest::GenerateAndTestPatch(const std::string& old_text,
const std::string& new_text) const {
courgette::SourceStream old1;
diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp
index e9fa170..41c8d0a 100644
--- a/courgette/courgette.gyp
+++ b/courgette/courgette.gyp
@@ -1,4 +1,4 @@
-# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -86,12 +86,15 @@
'sources': [
'adjustment_method_unittest.cc',
'bsdiff_memory_unittest.cc',
+ 'base_test_unittest.cc',
+ 'base_test_unittest.h',
'difference_estimator_unittest.cc',
'encoded_program_unittest.cc',
'encode_decode_unittest.cc',
'image_info_unittest.cc',
'run_all_unittests.cc',
'streams_unittest.cc',
+ 'versioning_unittest.cc',
'third_party/paged_array_unittest.cc'
],
'dependencies': [
@@ -117,6 +120,8 @@
'target_name': 'courgette_fuzz',
'type': 'executable',
'sources': [
+ 'base_test_unittest.cc',
+ 'base_test_unittest.h',
'encoded_program_fuzz_unittest.cc',
],
'dependencies': [
diff --git a/courgette/encode_decode_unittest.cc b/courgette/encode_decode_unittest.cc
index c14dc9f..4155c56 100644
--- a/courgette/encode_decode_unittest.cc
+++ b/courgette/encode_decode_unittest.cc
@@ -2,47 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <string>
-
-#include "base/path_service.h"
-#include "base/file_util.h"
-#include "base/string_util.h"
-
+#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class EncodeDecodeTest : public testing::Test {
+class EncodeDecodeTest : public BaseTest {
public:
void TestExe(const char *) const;
-
- private:
- void SetUp() {
- PathService::Get(base::DIR_SOURCE_ROOT, &testdata_dir_);
- testdata_dir_ = testdata_dir_.AppendASCII("courgette");
- testdata_dir_ = testdata_dir_.AppendASCII("testdata");
- }
-
- void TearDown() { }
-
- // Returns contents of |file_name| as uninterprested bytes stored in a string.
- std::string FileContents(const char* file_name) const;
-
- FilePath testdata_dir_; // Full path name of testdata directory
};
-// Reads a test file into a string.
-std::string EncodeDecodeTest::FileContents(const char* file_name) const {
- FilePath file_path = testdata_dir_;
- file_path = file_path.AppendASCII(file_name);
- std::string file_contents;
- if (!file_util::ReadFileToString(file_path, &file_contents)) {
- EXPECT_TRUE(!"Could not read test data");
- }
- return file_contents;
-}
-
void EncodeDecodeTest::TestExe(const char* file_name) const {
// Test top-level Courgette API for converting an a file to a binary
// assembly representation and back.
diff --git a/courgette/encoded_program_fuzz_unittest.cc b/courgette/encoded_program_fuzz_unittest.cc
index a869bc2..1330510 100644
--- a/courgette/encoded_program_fuzz_unittest.cc
+++ b/courgette/encoded_program_fuzz_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,31 +11,17 @@
// We try a lot of arbitrary modifications to the serialized form and make sure
// that the outcome is not a crash.
-#include <string>
-
-#include "base/path_service.h"
-#include "base/file_util.h"
-#include "base/string_util.h"
#include "base/test/test_suite.h"
+#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class DecodeFuzzTest : public testing::Test {
+class DecodeFuzzTest : public BaseTest {
public:
void FuzzExe(const char *) const;
private:
- virtual void SetUp() {
- PathService::Get(base::DIR_SOURCE_ROOT, &testdata_dir_);
- testdata_dir_ = testdata_dir_.AppendASCII("courgette");
- testdata_dir_ = testdata_dir_.AppendASCII("testdata");
- }
-
- virtual void TearDown() { }
-
void FuzzByte(const std::string& buffer, const std::string& output,
size_t index) const;
void FuzzBits(const std::string& buffer, const std::string& output,
@@ -43,24 +29,8 @@ class DecodeFuzzTest : public testing::Test {
// Returns true if could assemble, false if rejected.
bool TryAssemble(const std::string& buffer, std::string* output) const;
-
- // Returns contents of |file_name| as uninterprested bytes stored in a string.
- std::string FileContents(const char* file_name) const;
-
- // Full path name of testdata directory
- FilePath testdata_dir_;
};
-// Reads a test file into a string.
-std::string DecodeFuzzTest::FileContents(const char* file_name) const {
- FilePath file_path = testdata_dir_.AppendASCII(file_name);
- std::string file_contents;
- if (!file_util::ReadFileToString(file_path, &file_contents)) {
- EXPECT_TRUE(!"Could not read test data");
- }
- return file_contents;
-}
-
// Loads an executable and does fuzz testing in the serialized format.
void DecodeFuzzTest::FuzzExe(const char* file_name) const {
std::string file1 = FileContents(file_name);
diff --git a/courgette/image_info_unittest.cc b/courgette/image_info_unittest.cc
index 6bb14da..7c08473 100644
--- a/courgette/image_info_unittest.cc
+++ b/courgette/image_info_unittest.cc
@@ -2,50 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "courgette/base_test_unittest.h"
#include "courgette/image_info.h"
-#include <string>
-
-#include "base/path_service.h"
-#include "base/file_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/string_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class ImageInfoTest : public testing::Test {
+class ImageInfoTest : public BaseTest {
public:
void TestExe() const;
void TestResourceDll() const;
private:
- void SetUp() {
- PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_);
- test_dir_ = test_dir_.AppendASCII("courgette");
- test_dir_ = test_dir_.AppendASCII("testdata");
- }
-
- void TearDown() {
- }
-
void ExpectExecutable(courgette::PEInfo* info) const;
- std::string FileContents(const char* file_name) const;
-
- FilePath test_dir_;
};
-// Reads a test file into a string.
-std::string ImageInfoTest::FileContents(const char* file_name) const {
- FilePath file_path = test_dir_;
- file_path = file_path.AppendASCII(file_name);
- std::string file_bytes;
- if (!file_util::ReadFileToString(file_path, &file_bytes)) {
- EXPECT_TRUE(!"Could not read test data");
- }
- return file_bytes;
-}
-
void ImageInfoTest::ExpectExecutable(courgette::PEInfo* info) const {
EXPECT_TRUE(info->ok());
EXPECT_TRUE(info->has_text_section());
diff --git a/courgette/versioning_unittest.cc b/courgette/versioning_unittest.cc
new file mode 100644
index 0000000..8e2bdfe
--- /dev/null
+++ b/courgette/versioning_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "courgette/base_test_unittest.h"
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "courgette/courgette.h"
+#include "courgette/streams.h"
+
+class VersioningTest : public BaseTest {
+ public:
+ void TestApplyingOldPatch(const char* src_file,
+ const char* patch_file,
+ const char* expected_file) const;
+};
+
+void VersioningTest::TestApplyingOldPatch(const char* src_file,
+ const char* patch_file,
+ const char* expected_file) const {
+
+ std::string old_buffer = FileContents(src_file);
+ std::string new_buffer = FileContents(patch_file);
+ std::string expected_buffer = FileContents(expected_file);
+
+ courgette::SourceStream old_stream;
+ courgette::SourceStream patch_stream;
+ old_stream.Init(old_buffer);
+ patch_stream.Init(new_buffer);
+
+ courgette::SinkStream generated_stream;
+
+ courgette::Status status =
+ courgette::ApplyEnsemblePatch(&old_stream,
+ &patch_stream,
+ &generated_stream);
+
+ EXPECT_EQ(status, courgette::C_OK);
+
+ size_t expected_length = expected_buffer.size();
+ size_t generated_length = generated_stream.Length();
+
+ EXPECT_EQ(generated_length, expected_length);
+ EXPECT_EQ(0, memcmp(generated_stream.Buffer(),
+ expected_buffer.c_str(),
+ expected_length));
+}
+
+
+TEST_F(VersioningTest, All) {
+ TestApplyingOldPatch("setup1.exe", "setup1-setup2.v1.patch", "setup2.exe");
+
+ // We also need a way to test that newly generated patches are appropriately
+ // applicable by older clients... not sure of the best way to do that.
+}