diff options
author | Tao Bao <tbao@google.com> | 2017-04-04 23:52:26 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-04 23:52:26 +0200 |
commit | 7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0 (patch) | |
tree | 57010d3d13bac6ddd6ec27add77b7672a78eb537 /tests/unit/rangeset_test.cpp | |
parent | Merge "update_verifier: correct group in rc file" am: 310fa65c02 (diff) | |
parent | Merge "Change the internal representation in RangeSet." (diff) | |
download | android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar.gz android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar.bz2 android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar.lz android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar.xz android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.tar.zst android_bootable_recovery-7f4e5d55f4cdde472168fa4a4d8ed3294e942bc0.zip |
Diffstat (limited to '')
-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); +} |