summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-04-05 00:07:51 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-04-05 00:07:51 +0200
commitc2b3d700b45310d56d3b7edf4cc9b4d2034f0085 (patch)
tree333b169d8861d4186e8d8309f0bfac52c363f33a /tests/unit
parentMerge "update_verifier: correct group in rc file" into oc-dev am: 5d9fb40ef7 (diff)
parentMerge "Change the internal representation in RangeSet." am: 7ffa8be41d am: 2e12242b7a (diff)
downloadandroid_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar.gz
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar.bz2
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar.lz
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar.xz
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.tar.zst
android_bootable_recovery-c2b3d700b45310d56d3b7edf4cc9b4d2034f0085.zip
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/rangeset_test.cpp40
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);
+}