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 if (!file_util::ReadFileToString(file_path, &file_contents)) { | |
43 EXPECT_TRUE(!"Could not read test data"); | |
Paweł Hajdan Jr.
2011/09/16 18:34:34
Huh? Why not EXPECT_TRUE(file_util::ReadFileToStri
dgarrett
2011/09/22 02:20:46
Honestly, because I copied that block from another
sra1
2011/09/22 02:58:17
This is an old habit of mine. Fix it if you want
Paweł Hajdan Jr.
2011/09/26 17:08:21
Please note you can EXPECT_TRUE(ReadFileToString(.
| |
44 } | |
45 return file_contents; | |
46 } | |
47 | |
48 void VersioningTest::TestApplyingOldPatch(const char* src_file, | |
49 const char* patch_file, | |
50 const char* expected_file) const { | |
51 | |
52 std::string old_buffer = FileContents(src_file); | |
53 std::string new_buffer = FileContents(patch_file); | |
54 std::string expected_buffer = FileContents(expected_file); | |
55 | |
56 courgette::SourceStream old_stream; | |
57 courgette::SourceStream patch_stream; | |
58 old_stream.Init(old_buffer); | |
59 patch_stream.Init(new_buffer); | |
60 | |
61 courgette::SinkStream generated_stream; | |
62 | |
63 courgette::Status status = | |
64 courgette::ApplyEnsemblePatch(&old_stream, | |
65 &patch_stream, | |
66 &generated_stream); | |
67 | |
68 EXPECT_EQ(status, courgette::C_OK); | |
69 | |
70 size_t expected_length = expected_buffer.size(); | |
71 size_t generated_length = generated_stream.Length(); | |
72 | |
73 EXPECT_EQ(generated_length, expected_length); | |
74 EXPECT_EQ(0, memcmp(generated_stream.Buffer(), | |
75 expected_buffer.c_str(), | |
76 expected_length)); | |
77 } | |
78 | |
79 | |
80 TEST_F(VersioningTest, All) { | |
81 TestApplyingOldPatch("setup1.exe", "setup1-setup2.v1.patch", "setup2.exe"); | |
82 | |
83 // We also need a way to test that newly generated patches are appropriately | |
84 // applicable by older clients... not sure of the best way to do that. | |
85 } | |
OLD | NEW |