diff options
author | Tao Bao <tbao@google.com> | 2017-04-04 23:44:27 +0200 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-04-04 23:44:27 +0200 |
commit | 7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62 (patch) | |
tree | 0865aef9b52e3e0203d41e1b328ca8fb7b5ca2f9 /tests/unit | |
parent | Merge "update_verifier: correct group in rc file" (diff) | |
parent | Change the internal representation in RangeSet. (diff) | |
download | android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar.gz android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar.bz2 android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar.lz android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar.xz android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.tar.zst android_bootable_recovery-7ffa8be41dcc461dbaab7dab57a2c11d6b5a8b62.zip |
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/rangeset_test.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/unit/rangeset_test.cpp b/tests/unit/rangeset_test.cpp index e66da20e4..3c6d77ef5 100644 --- a/tests/unit/rangeset_test.cpp +++ b/tests/unit/rangeset_test.cpp @@ -25,14 +25,15 @@ TEST(RangeSetTest, Parse_smoke) { RangeSet rs = RangeSet::Parse("2,1,10"); - ASSERT_EQ(static_cast<size_t>(1), rs.count); - ASSERT_EQ((std::vector<size_t>{ 1, 10 }), rs.pos); - ASSERT_EQ(static_cast<size_t>(9), rs.size); + ASSERT_EQ(static_cast<size_t>(1), rs.size()); + ASSERT_EQ((Range{ 1, 10 }), rs[0]); + ASSERT_EQ(static_cast<size_t>(9), rs.blocks()); RangeSet rs2 = RangeSet::Parse("4,15,20,1,10"); - ASSERT_EQ(static_cast<size_t>(2), rs2.count); - ASSERT_EQ((std::vector<size_t>{ 15, 20, 1, 10 }), rs2.pos); - ASSERT_EQ(static_cast<size_t>(14), rs2.size); + ASSERT_EQ(static_cast<size_t>(2), rs2.size()); + ASSERT_EQ((Range{ 15, 20 }), rs2[0]); + ASSERT_EQ((Range{ 1, 10 }), rs2[1]); + ASSERT_EQ(static_cast<size_t>(14), rs2.blocks()); // Leading zeros are fine. But android::base::ParseUint() doesn't like trailing zeros like "10 ". ASSERT_EQ(rs, RangeSet::Parse(" 2, 1, 10")); @@ -82,3 +83,30 @@ TEST(RangeSetTest, GetBlockNumber) { // Out of bound. ASSERT_EXIT(rs.GetBlockNumber(9), ::testing::KilledBySignal(SIGABRT), ""); } + +TEST(RangeSetTest, equality) { + ASSERT_EQ(RangeSet::Parse("2,1,6"), RangeSet::Parse("2,1,6")); + + ASSERT_NE(RangeSet::Parse("2,1,6"), RangeSet::Parse("2,1,7")); + ASSERT_NE(RangeSet::Parse("2,1,6"), RangeSet::Parse("2,2,7")); + + // The orders of Range's matter. "4,1,5,8,10" != "4,8,10,1,5". + ASSERT_NE(RangeSet::Parse("4,1,5,8,10"), RangeSet::Parse("4,8,10,1,5")); +} + +TEST(RangeSetTest, iterators) { + RangeSet rs = RangeSet::Parse("4,1,5,8,10"); + std::vector<Range> ranges; + for (const auto& range : rs) { + ranges.push_back(range); + } + ASSERT_EQ((std::vector<Range>{ Range{ 1, 5 }, Range{ 8, 10 } }), ranges); + + ranges.clear(); + + // Reverse iterators. + for (auto it = rs.crbegin(); it != rs.crend(); it++) { + ranges.push_back(*it); + } + ASSERT_EQ((std::vector<Range>{ Range{ 8, 10 }, Range{ 1, 5 } }), ranges); +} |