• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include <string>
8 
9 #include "base/basictypes.h"
10 #include "courgette/courgette.h"
11 #include "courgette/streams.h"
12 
13 class VersioningTest : public BaseTest {
14  public:
15   void TestApplyingOldPatch(const char* src_file,
16                             const char* patch_file,
17                             const char* expected_file) const;
18 };
19 
TestApplyingOldPatch(const char * src_file,const char * patch_file,const char * expected_file) const20 void VersioningTest::TestApplyingOldPatch(const char* src_file,
21                                           const char* patch_file,
22                                           const char* expected_file) const {
23   std::string old_buffer = FileContents(src_file);
24   std::string new_buffer = FileContents(patch_file);
25   std::string expected_buffer = FileContents(expected_file);
26 
27   courgette::SourceStream old_stream;
28   courgette::SourceStream patch_stream;
29   old_stream.Init(old_buffer);
30   patch_stream.Init(new_buffer);
31 
32   courgette::SinkStream generated_stream;
33 
34   courgette::Status status =
35       courgette::ApplyEnsemblePatch(&old_stream,
36                                     &patch_stream,
37                                     &generated_stream);
38 
39   EXPECT_EQ(status, courgette::C_OK);
40 
41   size_t expected_length = expected_buffer.size();
42   size_t generated_length = generated_stream.Length();
43 
44   EXPECT_EQ(generated_length, expected_length);
45   EXPECT_EQ(0, memcmp(generated_stream.Buffer(),
46                       expected_buffer.c_str(),
47                       expected_length));
48 }
49 
50 
TEST_F(VersioningTest,All)51 TEST_F(VersioningTest, All) {
52   TestApplyingOldPatch("setup1.exe", "setup1-setup2.v1.patch", "setup2.exe");
53   TestApplyingOldPatch("chrome64_1.exe", "chrome64-1-2.v1.patch",
54                        "chrome64_2.exe");
55 
56   // We also need a way to test that newly generated patches are appropriately
57   // applicable by older clients... not sure of the best way to do that.
58 }
59