Add a basic backwards compatibility unittest.
This verifies we can still apply old patches, but does not verify that old clients can apply new patches. That seems important, but I'm not sure how to do it without storing old client binaries in version control. Also refactors a number of unit tests to allow code sharing for reading files into memory. This is done via a new base class. Uses test binaries submitted seperatly because of build tools problems. BUG=None TEST=New Unittest Review URL: http://codereview.chromium.org/8252011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105982 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
27
courgette/base_test_unittest.cc
Normal file
27
courgette/base_test_unittest.cc
Normal file
@ -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;
|
||||
}
|
26
courgette/base_test_unittest.h
Normal file
26
courgette/base_test_unittest.h
Normal file
@ -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_
|
@ -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;
|
||||
|
@ -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': [
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
57
courgette/versioning_unittest.cc
Normal file
57
courgette/versioning_unittest.cc
Normal file
@ -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.
|
||||
}
|
Reference in New Issue
Block a user