Home | History | Annotate | Download | only in courgette
      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.
      4 
      5 #include "courgette/base_test_unittest.h"
      6 #include "courgette/courgette.h"
      7 #include "courgette/streams.h"
      8 
      9 class EnsembleTest : public BaseTest {
     10  public:
     11 
     12   void TestEnsemble(std::string src_bytes, std::string tgt_bytes) const;
     13 
     14   void PeEnsemble() const;
     15   void Pe64Ensemble() const;
     16   void Elf32Ensemble() const;
     17 };
     18 
     19 void EnsembleTest::TestEnsemble(std::string src_bytes,
     20                                 std::string tgt_bytes) const {
     21 
     22   courgette::SourceStream source;
     23   courgette::SourceStream target;
     24 
     25   source.Init(src_bytes);
     26   target.Init(tgt_bytes);
     27 
     28   courgette::SinkStream patch_sink;
     29 
     30   courgette::Status status;
     31 
     32   status = courgette::GenerateEnsemblePatch(&source, &target, &patch_sink);
     33   EXPECT_EQ(courgette::C_OK, status);
     34 
     35   courgette::SourceStream patch_source;
     36   patch_source.Init(patch_sink.Buffer(), patch_sink.Length());
     37 
     38   courgette::SinkStream patch_result;
     39 
     40   status = courgette::ApplyEnsemblePatch(&source, &patch_source, &patch_result);
     41   EXPECT_EQ(courgette::C_OK, status);
     42 
     43   EXPECT_EQ(target.OriginalLength(), patch_result.Length());
     44   EXPECT_FALSE(memcmp(target.Buffer(),
     45                       patch_result.Buffer(),
     46                       target.OriginalLength()));
     47 }
     48 
     49 void EnsembleTest::Elf32Ensemble() const {
     50   std::list<std::string> src_ensemble;
     51   std::list<std::string> tgt_ensemble;
     52 
     53   src_ensemble.push_back("elf-32-1");
     54 
     55   tgt_ensemble.push_back("elf-32-2");
     56 
     57   std::string src_bytes = FilesContents(src_ensemble);
     58   std::string tgt_bytes = FilesContents(tgt_ensemble);
     59 
     60   src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
     61   tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
     62 
     63   TestEnsemble(src_bytes, tgt_bytes);
     64 }
     65 
     66 void EnsembleTest::PeEnsemble() const {
     67   std::list<std::string> src_ensemble;
     68   std::list<std::string> tgt_ensemble;
     69 
     70   src_ensemble.push_back("en-US.dll");
     71   src_ensemble.push_back("setup1.exe");
     72 
     73   tgt_ensemble.push_back("en-US.dll");
     74   tgt_ensemble.push_back("setup2.exe");
     75 
     76   std::string src_bytes = FilesContents(src_ensemble);
     77   std::string tgt_bytes = FilesContents(tgt_ensemble);
     78 
     79   src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
     80   tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
     81 
     82   TestEnsemble(src_bytes, tgt_bytes);
     83 }
     84 
     85 void EnsembleTest::Pe64Ensemble() const {
     86   std::list<std::string> src_ensemble;
     87   std::list<std::string> tgt_ensemble;
     88 
     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");
     92 
     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");
     96 
     97   std::string src_bytes = FilesContents(src_ensemble);
     98   std::string tgt_bytes = FilesContents(tgt_ensemble);
     99 
    100   src_bytes = "aaabbbccc" + src_bytes + "dddeeefff";
    101   tgt_bytes = "aaagggccc" + tgt_bytes + "dddeeefff";
    102 
    103   TestEnsemble(src_bytes, tgt_bytes);
    104 }
    105 
    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
    108 
    109 TEST_F(EnsembleTest, DISABLED_PE) {
    110   PeEnsemble();
    111 }
    112 
    113 TEST_F(EnsembleTest, DISABLED_PE64) {
    114   Pe64Ensemble();
    115 }
    116 
    117 TEST_F(EnsembleTest, DISABLED_Elf32) {
    118   Elf32Ensemble();
    119 }
    120