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 class EnsembleTest
: public BaseTest
{
12 void TestEnsemble(std::string src_bytes
, std::string tgt_bytes
) const;
14 void PeEnsemble() const;
15 void Pe64Ensemble() const;
16 void Elf32Ensemble() const;
19 void EnsembleTest::TestEnsemble(std::string src_bytes
,
20 std::string tgt_bytes
) const {
22 courgette::SourceStream source
;
23 courgette::SourceStream target
;
25 source
.Init(src_bytes
);
26 target
.Init(tgt_bytes
);
28 courgette::SinkStream patch_sink
;
30 courgette::Status status
;
32 status
= courgette::GenerateEnsemblePatch(&source
, &target
, &patch_sink
);
33 EXPECT_EQ(courgette::C_OK
, status
);
35 courgette::SourceStream patch_source
;
36 patch_source
.Init(patch_sink
.Buffer(), patch_sink
.Length());
38 courgette::SinkStream patch_result
;
40 status
= courgette::ApplyEnsemblePatch(&source
, &patch_source
, &patch_result
);
41 EXPECT_EQ(courgette::C_OK
, status
);
43 EXPECT_EQ(target
.OriginalLength(), patch_result
.Length());
44 EXPECT_FALSE(memcmp(target
.Buffer(),
45 patch_result
.Buffer(),
46 target
.OriginalLength()));
49 void EnsembleTest::Elf32Ensemble() const {
50 std::list
<std::string
> src_ensemble
;
51 std::list
<std::string
> tgt_ensemble
;
53 src_ensemble
.push_back("elf-32-1");
55 tgt_ensemble
.push_back("elf-32-2");
57 std::string src_bytes
= FilesContents(src_ensemble
);
58 std::string tgt_bytes
= FilesContents(tgt_ensemble
);
60 src_bytes
= "aaabbbccc" + src_bytes
+ "dddeeefff";
61 tgt_bytes
= "aaagggccc" + tgt_bytes
+ "dddeeefff";
63 TestEnsemble(src_bytes
, tgt_bytes
);
66 void EnsembleTest::PeEnsemble() const {
67 std::list
<std::string
> src_ensemble
;
68 std::list
<std::string
> tgt_ensemble
;
70 src_ensemble
.push_back("en-US.dll");
71 src_ensemble
.push_back("setup1.exe");
73 tgt_ensemble
.push_back("en-US.dll");
74 tgt_ensemble
.push_back("setup2.exe");
76 std::string src_bytes
= FilesContents(src_ensemble
);
77 std::string tgt_bytes
= FilesContents(tgt_ensemble
);
79 src_bytes
= "aaabbbccc" + src_bytes
+ "dddeeefff";
80 tgt_bytes
= "aaagggccc" + tgt_bytes
+ "dddeeefff";
82 TestEnsemble(src_bytes
, tgt_bytes
);
85 void EnsembleTest::Pe64Ensemble() const {
86 std::list
<std::string
> src_ensemble
;
87 std::list
<std::string
> tgt_ensemble
;
89 src_ensemble
.push_back("en-US-64.dll");
90 src_ensemble
.push_back("chrome64_1.exe");
91 src_ensemble
.push_back("pe-64.exe");
93 tgt_ensemble
.push_back("en-US-64.dll");
94 tgt_ensemble
.push_back("chrome64_2.exe");
95 tgt_ensemble
.push_back("pe-64.exe");
97 std::string src_bytes
= FilesContents(src_ensemble
);
98 std::string tgt_bytes
= FilesContents(tgt_ensemble
);
100 src_bytes
= "aaabbbccc" + src_bytes
+ "dddeeefff";
101 tgt_bytes
= "aaagggccc" + tgt_bytes
+ "dddeeefff";
103 TestEnsemble(src_bytes
, tgt_bytes
);
106 // Ensemble tests still take too long on Windows so disabling for now
107 // TODO(dgarrett) http://code.google.com/p/chromium/issues/detail?id=101614
109 TEST_F(EnsembleTest
, DISABLED_PE
) {
113 TEST_F(EnsembleTest
, DISABLED_PE64
) {
117 TEST_F(EnsembleTest
, DISABLED_Elf32
) {