versioning_unittest.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "courgette/base_test_unittest.h"
  5. #include <stddef.h>
  6. #include <string>
  7. #include "courgette/courgette.h"
  8. #include "courgette/streams.h"
  9. #include "courgette/third_party/bsdiff/bsdiff.h"
  10. class VersioningTest : public BaseTest {
  11. public:
  12. void TestApplyingOldBsDiffPatch(const char* src_file,
  13. const char* patch_file,
  14. const char* expected_file) const;
  15. };
  16. void VersioningTest::TestApplyingOldBsDiffPatch(
  17. const char* src_file,
  18. const char* patch_file,
  19. const char* expected_file) const {
  20. std::string old_buffer = FileContents(src_file);
  21. std::string new_buffer = FileContents(patch_file);
  22. std::string expected_buffer = FileContents(expected_file);
  23. courgette::SourceStream old_stream;
  24. courgette::SourceStream patch_stream;
  25. old_stream.Init(old_buffer);
  26. patch_stream.Init(new_buffer);
  27. courgette::SinkStream generated_stream;
  28. bsdiff::BSDiffStatus status = bsdiff::ApplyBinaryPatch(
  29. &old_stream, &patch_stream, &generated_stream);
  30. EXPECT_EQ(status, bsdiff::OK);
  31. size_t expected_length = expected_buffer.size();
  32. size_t generated_length = generated_stream.Length();
  33. EXPECT_EQ(generated_length, expected_length);
  34. EXPECT_EQ(0, memcmp(generated_stream.Buffer(),
  35. expected_buffer.c_str(),
  36. expected_length));
  37. }
  38. TEST_F(VersioningTest, BsDiff) {
  39. TestApplyingOldBsDiffPatch("setup1.exe", "setup1-setup2.v1.bsdiff",
  40. "setup2.exe");
  41. TestApplyingOldBsDiffPatch("chrome64_1.exe", "chrome64-1-2.v1.bsdiff",
  42. "chrome64_2.exe");
  43. // We also need a way to test that newly generated patches are appropriately
  44. // applicable by older clients... not sure of the best way to do that.
  45. }