1 // Copyright 2017 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 "components/zucchini/reference_set.h"
6
7 #include <vector>
8
9 #include "components/zucchini/image_utils.h"
10 #include "components/zucchini/target_pool.h"
11 #include "components/zucchini/test_reference_reader.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace zucchini {
15
16 namespace {
17
18 constexpr offset_t kWidth = 2U;
19
20 } // namespace
21
22 class ReferenceSetTest : public testing::Test {
23 protected:
24 // For simplicity, |target_pool_| has no type info (not needed here).
25 TargetPool target_pool_ = TargetPool{{0, 2, 3, 5}};
26 ReferenceSet reference_set_ =
27 ReferenceSet{{kWidth, TypeTag(0), PoolTag(0)}, target_pool_};
28 };
29
TEST_F(ReferenceSetTest,InitReferencesFromReader)30 TEST_F(ReferenceSetTest, InitReferencesFromReader) {
31 EXPECT_EQ(std::vector<Reference>(), reference_set_.references());
32 EXPECT_EQ(0U, reference_set_.size());
33 std::vector<Reference> references = {{10, 0}, {12, 2}, {14, 5}};
34 reference_set_.InitReferences(TestReferenceReader(references));
35 EXPECT_EQ(references, reference_set_.references());
36 }
37
TEST_F(ReferenceSetTest,At)38 TEST_F(ReferenceSetTest, At) {
39 reference_set_.InitReferences({{10, 0}, {12, 2}, {15, 5}});
40 // Each references has kWidth = 2, so check all bytes covered.
41 EXPECT_EQ(Reference({10, 0}), reference_set_.at(10));
42 EXPECT_EQ(Reference({10, 0}), reference_set_.at(11));
43 EXPECT_EQ(Reference({12, 2}), reference_set_.at(12));
44 EXPECT_EQ(Reference({12, 2}), reference_set_.at(13));
45 EXPECT_EQ(Reference({15, 5}), reference_set_.at(15));
46 EXPECT_EQ(Reference({15, 5}), reference_set_.at(16));
47 }
48
49 } // namespace zucchini
50