| OLD | NEW |
| (Empty) |
| 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 <string> | |
| 6 | |
| 7 #include "base/path_service.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/string_util.h" | |
| 10 | |
| 11 #include "courgette/courgette.h" | |
| 12 #include "courgette/streams.h" | |
| 13 | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 class VersioningTest : public testing::Test { | |
| 17 public: | |
| 18 void TestApplyingOldPatch(const char* src_file, | |
| 19 const char* patch_file, | |
| 20 const char* expected_file) const; | |
| 21 | |
| 22 private: | |
| 23 void SetUp() { | |
| 24 PathService::Get(base::DIR_SOURCE_ROOT, &testdata_dir_); | |
| 25 testdata_dir_ = testdata_dir_.AppendASCII("courgette"); | |
| 26 testdata_dir_ = testdata_dir_.AppendASCII("testdata"); | |
| 27 } | |
| 28 | |
| 29 void TearDown() { } | |
| 30 | |
| 31 // Returns contents of |file_name| as uninterprested bytes stored in a string. | |
| 32 std::string FileContents(const char* file_name) const; | |
| 33 | |
| 34 FilePath testdata_dir_; // Full path name of testdata directory | |
| 35 }; | |
| 36 | |
| 37 // Reads a test file into a string. | |
| 38 std::string VersioningTest::FileContents(const char* file_name) const { | |
| 39 FilePath file_path = testdata_dir_; | |
| 40 file_path = file_path.AppendASCII(file_name); | |
| 41 std::string file_contents; | |
| 42 EXPECT_TRUE(file_util::ReadFileToString(file_path, &file_contents)); | |
| 43 return file_contents; | |
| 44 } | |
| 45 | |
| 46 void VersioningTest::TestApplyingOldPatch(const char* src_file, | |
| 47 const char* patch_file, | |
| 48 const char* expected_file) const { | |
| 49 | |
| 50 std::string old_buffer = FileContents(src_file); | |
| 51 std::string new_buffer = FileContents(patch_file); | |
| 52 std::string expected_buffer = FileContents(expected_file); | |
| 53 | |
| 54 courgette::SourceStream old_stream; | |
| 55 courgette::SourceStream patch_stream; | |
| 56 old_stream.Init(old_buffer); | |
| 57 patch_stream.Init(new_buffer); | |
| 58 | |
| 59 courgette::SinkStream generated_stream; | |
| 60 | |
| 61 courgette::Status status = | |
| 62 courgette::ApplyEnsemblePatch(&old_stream, | |
| 63 &patch_stream, | |
| 64 &generated_stream); | |
| 65 | |
| 66 EXPECT_EQ(status, courgette::C_OK); | |
| 67 | |
| 68 size_t expected_length = expected_buffer.size(); | |
| 69 size_t generated_length = generated_stream.Length(); | |
| 70 | |
| 71 EXPECT_EQ(generated_length, expected_length); | |
| 72 EXPECT_EQ(0, memcmp(generated_stream.Buffer(), | |
| 73 expected_buffer.c_str(), | |
| 74 expected_length)); | |
| 75 } | |
| 76 | |
| 77 | |
| 78 TEST_F(VersioningTest, All) { | |
| 79 TestApplyingOldPatch("setup1.exe", "setup1-setup2.v1.patch", "setup2.exe"); | |
| 80 | |
| 81 // We also need a way to test that newly generated patches are appropriately | |
| 82 // applicable by older clients... not sure of the best way to do that. | |
| 83 } | |
| OLD | NEW |