tuple: update to make use of C++11
[chromium-blink-merge.git] / courgette / ensemble_unittest.cc
blobb255ae94c1ccc1379ccfa1d2ccce8b6d79d3bc86
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
3 // found in the LICENSE file.
5 #include "courgette/base_test_unittest.h"
6 #include "courgette/courgette.h"
7 #include "courgette/streams.h"
9 #if defined(OS_WIN) && !defined(NDEBUG)
10 // Ensemble tests still take too long on Debug Windows so disabling for now
11 // TODO(dgarrett) http://code.google.com/p/chromium/issues/detail?id=101614
12 #define MAYBE_PE DISABLED_PE
13 #define MAYBE_PE64 DISABLED_PE64
14 #define MAYBE_Elf32 DISABLED_Elf32
15 #else
16 #define MAYBE_PE PE
17 #define MAYBE_PE64 PE64
18 #define MAYBE_Elf32 Elf32
19 #endif
21 class EnsembleTest : public BaseTest {
22 public:
24 void TestEnsemble(std::string src_bytes, std::string tgt_bytes) const;
26 void PeEnsemble() const;
27 void Pe64Ensemble() const;
28 void Elf32Ensemble() const;
31 void EnsembleTest::TestEnsemble(std::string src_bytes,
32 std::string tgt_bytes) const {
34 courgette::SourceStream source;
35 courgette::SourceStream target;
37 source.Init(src_bytes);
38 target.Init(tgt_bytes);
40 courgette::SinkStream patch_sink;
42 courgette::Status status;
44 status = courgette::GenerateEnsemblePatch(&source, &target, &patch_sink);
45 EXPECT_EQ(courgette::C_OK, status);
47 courgette::SourceStream patch_source;
48 patch_source.Init(patch_sink.Buffer(), patch_sink.Length());
50 courgette::SinkStream patch_result;
52 status = courgette::ApplyEnsemblePatch(&source, &patch_source, &patch_result);
53 EXPECT_EQ(courgette::C_OK, status);
55 EXPECT_EQ(target.OriginalLength(), patch_result.Length());
56 EXPECT_FALSE(memcmp(target.Buffer(),
57 patch_result.Buffer(),
58 target.OriginalLength()));
61 void EnsembleTest::Elf32Ensemble() const {
62 std::list<std::string> src_ensemble;
63 std::list<std::string> tgt_ensemble;
65 src_ensemble.push_back("elf-32-1");
67 tgt_ensemble.push_back("elf-32-2");
69 std::string src_bytes = FilesContents(src_ensemble);
70 std::string tgt_bytes = FilesContents(tgt_ensemble);
72 src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
73 tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
75 TestEnsemble(src_bytes, tgt_bytes);
78 void EnsembleTest::PeEnsemble() const {
79 std::list<std::string> src_ensemble;
80 std::list<std::string> tgt_ensemble;
82 src_ensemble.push_back("en-US.dll");
83 src_ensemble.push_back("setup1.exe");
85 tgt_ensemble.push_back("en-US.dll");
86 tgt_ensemble.push_back("setup2.exe");
88 std::string src_bytes = FilesContents(src_ensemble);
89 std::string tgt_bytes = FilesContents(tgt_ensemble);
91 src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
92 tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
94 TestEnsemble(src_bytes, tgt_bytes);
97 void EnsembleTest::Pe64Ensemble() const {
98 std::list<std::string> src_ensemble;
99 std::list<std::string> tgt_ensemble;
101 src_ensemble.push_back("en-US-64.dll");
102 src_ensemble.push_back("chrome64_1.exe");
103 src_ensemble.push_back("pe-64.exe");
105 tgt_ensemble.push_back("en-US-64.dll");
106 tgt_ensemble.push_back("chrome64_2.exe");
107 tgt_ensemble.push_back("pe-64.exe");
109 std::string src_bytes = FilesContents(src_ensemble);
110 std::string tgt_bytes = FilesContents(tgt_ensemble);
112 src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
113 tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
115 TestEnsemble(src_bytes, tgt_bytes);
118 TEST_F(EnsembleTest, MAYBE_PE) {
119 PeEnsemble();
122 TEST_F(EnsembleTest, MAYBE_PE64) {
123 Pe64Ensemble();
126 TEST_F(EnsembleTest, MAYBE_Elf32) {
127 Elf32Ensemble();