summaryrefslogtreecommitdiffstats
path: root/tests/unit/rangeset_test.cpp
diff options
context:
space:
mode:
authorxunchang <xunchang@google.com>2019-03-22 16:54:35 +0100
committerTianjie Xu <xunchang@google.com>2019-05-01 21:09:38 +0200
commit311e6ca7b609e578c0ec132440a4ad981db70a9e (patch)
tree206a8c1268e4664cb06890f9835d86e83014ae8a /tests/unit/rangeset_test.cpp
parentMerge changes I2d42f55a,Ic1b5dbf7 (diff)
downloadandroid_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar.gz
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar.bz2
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar.lz
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar.xz
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.tar.zst
android_bootable_recovery-311e6ca7b609e578c0ec132440a4ad981db70a9e.zip
Diffstat (limited to '')
-rw-r--r--tests/unit/rangeset_test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unit/rangeset_test.cpp b/tests/unit/rangeset_test.cpp
index fc72f2f6d..699f933a0 100644
--- a/tests/unit/rangeset_test.cpp
+++ b/tests/unit/rangeset_test.cpp
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <limits>
+#include <optional>
#include <vector>
#include <gtest/gtest.h>
@@ -248,6 +249,29 @@ TEST(RangeSetTest, ToString) {
ASSERT_EQ("6,1,3,4,6,15,22", RangeSet::Parse("6,1,3,4,6,15,22").ToString());
}
+TEST(RangeSetTest, GetSubRanges_invalid) {
+ RangeSet range0({ { 1, 11 }, { 20, 30 } });
+ ASSERT_FALSE(range0.GetSubRanges(0, 21)); // too many blocks
+ ASSERT_FALSE(range0.GetSubRanges(21, 1)); // start block OOB
+}
+
+TEST(RangeSetTest, GetSubRanges_empty) {
+ RangeSet range0({ { 1, 11 }, { 20, 30 } });
+ ASSERT_EQ(RangeSet{}, range0.GetSubRanges(1, 0)); // empty num_of_blocks
+}
+
+TEST(RangeSetTest, GetSubRanges_smoke) {
+ RangeSet range0({ { 10, 11 } });
+ ASSERT_EQ(RangeSet({ { 10, 11 } }), range0.GetSubRanges(0, 1));
+
+ RangeSet range1({ { 10, 11 }, { 20, 21 }, { 30, 31 } });
+ ASSERT_EQ(range1, range1.GetSubRanges(0, 3));
+ ASSERT_EQ(RangeSet({ { 20, 21 } }), range1.GetSubRanges(1, 1));
+
+ RangeSet range2({ { 1, 11 }, { 20, 25 }, { 30, 35 } });
+ ASSERT_EQ(RangeSet({ { 10, 11 }, { 20, 25 }, { 30, 31 } }), range2.GetSubRanges(9, 7));
+}
+
TEST(SortedRangeSetTest, Insert) {
SortedRangeSet rs({ { 2, 3 }, { 4, 6 }, { 8, 14 } });
rs.Insert({ 1, 2 });