diff options
author | Samuel Huang <huangs@chromium.org> | 2018-03-13 18:19:34 +0000 |
---|---|---|
committer | Edward Lesmes <ehmaldonado@google.com> | 2021-07-23 21:50:59 +0000 |
commit | 06f1ae9aaca969ee95ef840f22b6b461c304542d (patch) | |
tree | f1e5c6624e70628e81fbf38d6cd14b974abe5d93 /integration_test.cc | |
download | zucchini-06f1ae9aaca969ee95ef840f22b6b461c304542d.tar.gz |
[Zucchini] Move Zucchini from /chrome/installer/ to /components/.
(Use "git log --follow" to see older revisions of files).
/components/ is the most logical place to put Zucchini, which only
depends on /base and /testing/gtest. This move also enables Zucchini to
be used by the Component Updater. Details:
- Move all files; run the following to change deps and guards:
sed 's/chrome\/installer/components/' *.cc *.h -i
sed 's/CHROME_INSTALLER/COMPONENTS/' *.cc *.h -i
- Sorting works out pretty well!
- Change all 'chrome/installer/zucchini' to 'components/zucchini'
throughout other parts of the repo; sort if necessary.
- Fix 6 'git cl lint' errors.
- Change 1 Bind() usage to BindRepeated().
- Update OWNER.
Bug: 729154
Change-Id: I50c5a7d411ea85f707b5994ab319dfb2a1acccf7
Reviewed-on: https://chromium-review.googlesource.com/954923
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Samuel Huang <huangs@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542857}
NOKEYCHECK=True
GitOrigin-RevId: 577ef6c435e8d43be6e3e60ccbcbd1881780f4ec
Diffstat (limited to 'integration_test.cc')
-rw-r--r-- | integration_test.cc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/integration_test.cc b/integration_test.cc new file mode 100644 index 0000000..b0ec864 --- /dev/null +++ b/integration_test.cc @@ -0,0 +1,104 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdint.h> + +#include <algorithm> +#include <string> +#include <vector> + +#include "base/files/file_path.h" +#include "base/files/memory_mapped_file.h" +#include "base/optional.h" +#include "base/path_service.h" +#include "components/zucchini/buffer_view.h" +#include "components/zucchini/patch_reader.h" +#include "components/zucchini/patch_writer.h" +#include "components/zucchini/zucchini.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace zucchini { + +base::FilePath MakeTestPath(const std::string& filename) { + base::FilePath path; + DCHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); + return path.AppendASCII("chrome") + .AppendASCII("installer") + .AppendASCII("zucchini") + .AppendASCII("testdata") + .AppendASCII(filename); +} + +void TestGenApply(const std::string& old_filename, + const std::string& new_filename, + bool raw) { + base::FilePath old_path = MakeTestPath(old_filename); + base::FilePath new_path = MakeTestPath(new_filename); + + base::MemoryMappedFile old_file; + ASSERT_TRUE(old_file.Initialize(old_path)); + + base::MemoryMappedFile new_file; + ASSERT_TRUE(new_file.Initialize(new_path)); + + ConstBufferView old_region(old_file.data(), old_file.length()); + ConstBufferView new_region(new_file.data(), new_file.length()); + + EnsemblePatchWriter patch_writer(old_region, new_region); + + // Generate patch from "old" to "new". + ASSERT_EQ(status::kStatusSuccess, + raw ? GenerateRaw(old_region, new_region, &patch_writer) + : GenerateEnsemble(old_region, new_region, &patch_writer)); + + size_t patch_size = patch_writer.SerializedSize(); + EXPECT_GE(patch_size, 80U); // Minimum size is empty patch. + // TODO(etiennep): Add check on maximum expected size. + + std::vector<uint8_t> patch_buffer(patch_writer.SerializedSize()); + patch_writer.SerializeInto({patch_buffer.data(), patch_buffer.size()}); + + // Read back generated patch. + base::Optional<EnsemblePatchReader> patch_reader = + EnsemblePatchReader::Create({patch_buffer.data(), patch_buffer.size()}); + ASSERT_TRUE(patch_reader.has_value()); + + // Check basic properties. + EXPECT_TRUE(patch_reader->CheckOldFile(old_region)); + EXPECT_TRUE(patch_reader->CheckNewFile(new_region)); + EXPECT_EQ(old_file.length(), patch_reader->header().old_size); + // If new_size doesn't match expectation, the function is aborted. + ASSERT_EQ(new_file.length(), patch_reader->header().new_size); + + // Apply patch to "old" to get "patched new", ensure it's identical to "new". + std::vector<uint8_t> patched_new_buffer(new_region.size()); + ASSERT_EQ(status::kStatusSuccess, + Apply(old_region, *patch_reader, + {patched_new_buffer.data(), patched_new_buffer.size()})); + + // Note that |new_region| and |patched_new_buffer| are the same size. + EXPECT_TRUE(std::equal(new_region.begin(), new_region.end(), + patched_new_buffer.begin())); +} + +TEST(EndToEndTest, GenApplyRaw) { + TestGenApply("setup1.exe", "setup2.exe", true); + TestGenApply("chrome64_1.exe", "chrome64_2.exe", true); +} + +TEST(EndToEndTest, GenApplyIdentity) { + TestGenApply("setup1.exe", "setup1.exe", false); +} + +TEST(EndToEndTest, GenApplySimple) { + TestGenApply("setup1.exe", "setup2.exe", false); + TestGenApply("setup2.exe", "setup1.exe", false); + TestGenApply("chrome64_1.exe", "chrome64_2.exe", false); +} + +TEST(EndToEndTest, GenApplyCross) { + TestGenApply("setup1.exe", "chrome64_1.exe", false); +} + +} // namespace zucchini |