diff options
author | Tao Bao <tbao@google.com> | 2017-04-04 23:57:57 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-04 23:57:57 +0200 |
commit | b126a2cd9a1fd91a794b8d5e18b4316730de8e22 (patch) | |
tree | f4ae1386aaf6c80cf39522126a24652c4cb7c6a0 /tests/unit | |
parent | Merge "update_verifier: correct group in rc file" into oc-dev (diff) | |
parent | Merge "Change the internal representation in RangeSet." am: 7ffa8be41d (diff) | |
download | android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar.gz android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar.bz2 android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar.lz android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar.xz android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.tar.zst android_bootable_recovery-b126a2cd9a1fd91a794b8d5e18b4316730de8e22.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); +} |