diff options
author | dgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 05:31:59 +0000 |
---|---|---|
committer | dgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 05:31:59 +0000 |
commit | c678e65edb7774bb7696ef48fc5415d52b597cb3 (patch) | |
tree | 9a9e81b83968a108bb08d69ffd104191b2795a15 | |
parent | 679346ca2c269fff9726c7ed6e94aaed7d8b563e (diff) | |
download | chromium_src-c678e65edb7774bb7696ef48fc5415d52b597cb3.zip chromium_src-c678e65edb7774bb7696ef48fc5415d52b597cb3.tar.gz chromium_src-c678e65edb7774bb7696ef48fc5415d52b597cb3.tar.bz2 |
Add a unittest for ensemble diffing.
The courgette refactoring broke the ability to handle ensembles with 64 bit
PE files, or resource only DLLs. This unittest handles patching ensembles
that contain these file types to confirm my fix, and ensure I don't introduce
this regression again.
BUG=None
TEST=New Unittest
Review URL: http://codereview.chromium.org/8330006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106223 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | courgette/base_test_unittest.cc | 14 | ||||
-rw-r--r-- | courgette/base_test_unittest.h | 5 | ||||
-rw-r--r-- | courgette/courgette.gyp | 1 | ||||
-rw-r--r-- | courgette/ensemble_unittest.cc | 72 |
4 files changed, 92 insertions, 0 deletions
diff --git a/courgette/base_test_unittest.cc b/courgette/base_test_unittest.cc index 6da56fb..2a3c0c6 100644 --- a/courgette/base_test_unittest.cc +++ b/courgette/base_test_unittest.cc @@ -25,3 +25,17 @@ std::string BaseTest::FileContents(const char* file_name) const { return file_bytes; } + +std::string BaseTest::FilesContents(std::list<std::string> file_names) const { + + std::string result; + + std::list<std::string>::iterator file_name = file_names.begin(); + + while (file_name != file_names.end()) { + result += FileContents(file_name->c_str()); + file_name++; + } + + return result; +} diff --git a/courgette/base_test_unittest.h b/courgette/base_test_unittest.h index 777495a..170a0c9 100644 --- a/courgette/base_test_unittest.h +++ b/courgette/base_test_unittest.h @@ -7,6 +7,7 @@ #ifndef COURGETTE_BASE_TEST_UNITTEST_H_ #define COURGETTE_BASE_TEST_UNITTEST_H_ +#include <list> #include <string> #include "base/file_util.h" @@ -16,6 +17,10 @@ class BaseTest : public testing::Test { public: std::string FileContents(const char* file_name) const; + // Pass a list of strings, and get back the concatenated contents + // of each of the mentioned files. + std::string FilesContents(std::list<std::string> file_names) const; + private: virtual void SetUp(); virtual void TearDown(); diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp index 41c8d0a..2bda671 100644 --- a/courgette/courgette.gyp +++ b/courgette/courgette.gyp @@ -91,6 +91,7 @@ 'difference_estimator_unittest.cc', 'encoded_program_unittest.cc', 'encode_decode_unittest.cc', + 'ensemble_unittest.cc', 'image_info_unittest.cc', 'run_all_unittests.cc', 'streams_unittest.cc', diff --git a/courgette/ensemble_unittest.cc b/courgette/ensemble_unittest.cc new file mode 100644 index 0000000..5330efa --- /dev/null +++ b/courgette/ensemble_unittest.cc @@ -0,0 +1,72 @@ +// 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 "courgette/courgette.h" +#include "courgette/streams.h" + +class EnsembleTest : public BaseTest { + public: + + void TestEnsemble(std::string src_bytes, std::string tgt_bytes) const; + + void PeEnsemble() const; +}; + +void EnsembleTest::TestEnsemble(std::string src_bytes, + std::string tgt_bytes) const { + + courgette::SourceStream source; + courgette::SourceStream target; + + source.Init(src_bytes); + target.Init(tgt_bytes); + + courgette::SinkStream patch_sink; + + courgette::Status status; + + status = courgette::GenerateEnsemblePatch(&source, &target, &patch_sink); + EXPECT_EQ(courgette::C_OK, status); + + courgette::SourceStream patch_source; + patch_source.Init(patch_sink.Buffer(), patch_sink.Length()); + + courgette::SinkStream patch_result; + + status = courgette::ApplyEnsemblePatch(&source, &patch_source, &patch_result); + EXPECT_EQ(courgette::C_OK, status); + + EXPECT_EQ(target.OriginalLength(), patch_result.Length()); + EXPECT_FALSE(memcmp(target.Buffer(), + patch_result.Buffer(), + target.OriginalLength())); +} + +void EnsembleTest::PeEnsemble() const { + std::list<std::string> src_ensemble; + std::list<std::string> tgt_ensemble; + + src_ensemble.push_back("en-US.dll"); + src_ensemble.push_back("setup1.exe"); + src_ensemble.push_back("elf-32-1"); + src_ensemble.push_back("pe-64.exe"); + + tgt_ensemble.push_back("en-US.dll"); + tgt_ensemble.push_back("setup2.exe"); + tgt_ensemble.push_back("elf-32-2"); + tgt_ensemble.push_back("pe-64.exe"); + + std::string src_bytes = FilesContents(src_ensemble); + std::string tgt_bytes = FilesContents(tgt_ensemble); + + src_bytes = "aaabbbccc" + src_bytes + "dddeeefff"; + tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff"; + + TestEnsemble(src_bytes, tgt_bytes); +} + +TEST_F(EnsembleTest, All) { + PeEnsemble(); +} |