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 /target_pool_unittest.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 'target_pool_unittest.cc')
-rw-r--r-- | target_pool_unittest.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/target_pool_unittest.cc b/target_pool_unittest.cc new file mode 100644 index 0000000..4c3efec --- /dev/null +++ b/target_pool_unittest.cc @@ -0,0 +1,64 @@ +// 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 "components/zucchini/target_pool.h" + +#include <cmath> +#include <string> +#include <utility> +#include <vector> + +#include "components/zucchini/image_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace zucchini { + +namespace { + +using OffsetVector = std::vector<offset_t>; + +} // namespace + +TEST(TargetPoolTest, InsertTargetsFromReferences) { + auto test_insert = [](std::vector<Reference>&& references) -> OffsetVector { + TargetPool target_pool; + target_pool.InsertTargets(references); + // Return copy since |target_pool| goes out of scope. + return target_pool.targets(); + }; + + EXPECT_EQ(OffsetVector(), test_insert({})); + EXPECT_EQ(OffsetVector({0, 1}), test_insert({{0, 0}, {10, 1}})); + EXPECT_EQ(OffsetVector({0, 1}), test_insert({{0, 1}, {10, 0}})); + EXPECT_EQ(OffsetVector({0, 1, 2}), test_insert({{0, 1}, {10, 0}, {20, 2}})); + EXPECT_EQ(OffsetVector({0}), test_insert({{0, 0}, {10, 0}})); + EXPECT_EQ(OffsetVector({0, 1}), test_insert({{0, 0}, {10, 0}, {20, 1}})); +} + +TEST(TargetPoolTest, KeyOffset) { + auto test_key_offset = [](const std::string& nearest_offsets_key, + OffsetVector&& targets) { + TargetPool target_pool(std::move(targets)); + for (offset_t offset : target_pool.targets()) { + offset_t key = target_pool.KeyForOffset(offset); + EXPECT_LT(key, target_pool.size()); + EXPECT_EQ(offset, target_pool.OffsetForKey(key)); + } + for (offset_t offset = 0; offset < nearest_offsets_key.size(); ++offset) { + key_t key = target_pool.KeyForNearestOffset(offset); + EXPECT_EQ(key, static_cast<key_t>(nearest_offsets_key[offset] - '0')); + } + }; + test_key_offset("0000000000000000", {}); + test_key_offset("0000000000000000", {0}); + test_key_offset("0000000000000000", {1}); + test_key_offset("0111111111111111", {0, 1}); + test_key_offset("0011111111111111", {0, 2}); + test_key_offset("0011111111111111", {1, 2}); + test_key_offset("0001111111111111", {1, 3}); + test_key_offset("0001112223334444", {1, 3, 7, 9, 13}); + test_key_offset("0000011112223333", {1, 7, 9, 13}); +} + +} // namespace zucchini |