Bump docserver to 3-48-0.
[chromium-blink-merge.git] / courgette / versioning_unittest.cc
blob91154d82aae6de5f1206413215c0ca9caead6e41
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"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "courgette/courgette.h"
11 #include "courgette/streams.h"
12 #include "courgette/third_party/bsdiff.h"
14 class VersioningTest : public BaseTest {
15 public:
16 void TestApplyingOldBsDiffPatch(const char* src_file,
17 const char* patch_file,
18 const char* expected_file) const;
21 void VersioningTest::TestApplyingOldBsDiffPatch(
22 const char* src_file,
23 const char* patch_file,
24 const char* expected_file) const {
25 std::string old_buffer = FileContents(src_file);
26 std::string new_buffer = FileContents(patch_file);
27 std::string expected_buffer = FileContents(expected_file);
29 courgette::SourceStream old_stream;
30 courgette::SourceStream patch_stream;
31 old_stream.Init(old_buffer);
32 patch_stream.Init(new_buffer);
34 courgette::SinkStream generated_stream;
36 courgette::BSDiffStatus status = courgette::ApplyBinaryPatch(
37 &old_stream, &patch_stream, &generated_stream);
39 EXPECT_EQ(status, courgette::OK);
41 size_t expected_length = expected_buffer.size();
42 size_t generated_length = generated_stream.Length();
44 EXPECT_EQ(generated_length, expected_length);
45 EXPECT_EQ(0, memcmp(generated_stream.Buffer(),
46 expected_buffer.c_str(),
47 expected_length));
50 TEST_F(VersioningTest, BsDiff) {
51 TestApplyingOldBsDiffPatch("setup1.exe", "setup1-setup2.v1.bsdiff",
52 "setup2.exe");
53 TestApplyingOldBsDiffPatch("chrome64_1.exe", "chrome64-1-2.v1.bsdiff",
54 "chrome64_2.exe");
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.