summaryrefslogtreecommitdiffstats
path: root/courgette/ensemble_unittest.cc
diff options
context:
space:
mode:
authordgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-19 05:31:59 +0000
committerdgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-19 05:31:59 +0000
commitc678e65edb7774bb7696ef48fc5415d52b597cb3 (patch)
tree9a9e81b83968a108bb08d69ffd104191b2795a15 /courgette/ensemble_unittest.cc
parent679346ca2c269fff9726c7ed6e94aaed7d8b563e (diff)
downloadchromium_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
Diffstat (limited to 'courgette/ensemble_unittest.cc')
-rw-r--r--courgette/ensemble_unittest.cc72
1 files changed, 72 insertions, 0 deletions
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();
+}