boot_control_android_unittest: ExpectStoreMetadata
Factor out common code.
Test: update_engine_unittests
Change-Id: I1faba28197e2a5731c0243730f4b1bfca0d7f046
diff --git a/boot_control_android_unittest.cc b/boot_control_android_unittest.cc
index 3e01be2..d62c3a6 100644
--- a/boot_control_android_unittest.cc
+++ b/boot_control_android_unittest.cc
@@ -245,6 +245,17 @@
}
}
+ void ExpectStoreMetadata(const PartitionSizes& partition_sizes) {
+ ExpectStoreMetadataMatch(MetadataMatches(partition_sizes));
+ }
+
+ virtual void ExpectStoreMetadataMatch(
+ const Matcher<MetadataBuilder*>& matcher) {
+ EXPECT_CALL(dynamicControl(),
+ StoreMetadata(GetSuperDevice(), matcher, target()))
+ .WillOnce(Return(true));
+ }
+
uint32_t source() { return slots_.source; }
uint32_t target() { return slots_.target; }
@@ -400,14 +411,10 @@
{T("vendor"), 1_GiB}};
SetMetadata(source(), initial);
SetMetadata(target(), initial);
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 3_GiB},
- {T("vendor"), 1_GiB}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{S("system"), 2_GiB},
+ {S("vendor"), 1_GiB},
+ {T("system"), 3_GiB},
+ {T("vendor"), 1_GiB}});
ExpectRemap({T("system"), T("vendor")});
EXPECT_TRUE(bootctl_.InitPartitionMetadata(
@@ -424,14 +431,10 @@
{T("vendor"), 1_GiB}};
SetMetadata(source(), initial);
SetMetadata(target(), initial);
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 150_MiB}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{S("system"), 2_GiB},
+ {S("vendor"), 1_GiB},
+ {T("system"), 2_GiB},
+ {T("vendor"), 150_MiB}});
ExpectRemap({T("system"), T("vendor")});
EXPECT_TRUE(bootctl_.InitPartitionMetadata(
@@ -443,12 +446,7 @@
TEST_P(BootControlAndroidTestP, AddPartitionToEmptyMetadata) {
SetMetadata(source(), {});
SetMetadata(target(), {});
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(
- GetSuperDevice(),
- MetadataMatches({{T("system"), 2_GiB}, {T("vendor"), 1_GiB}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{T("system"), 2_GiB}, {T("vendor"), 1_GiB}});
ExpectRemap({T("system"), T("vendor")});
EXPECT_TRUE(bootctl_.InitPartitionMetadata(
@@ -460,13 +458,8 @@
TEST_P(BootControlAndroidTestP, AddAdditionalPartition) {
SetMetadata(source(), {{S("system"), 2_GiB}, {T("system"), 2_GiB}});
SetMetadata(target(), {{S("system"), 2_GiB}, {T("system"), 2_GiB}});
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 1_GiB}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata(
+ {{S("system"), 2_GiB}, {T("system"), 2_GiB}, {T("vendor"), 1_GiB}});
ExpectRemap({T("system"), T("vendor")});
EXPECT_TRUE(bootctl_.InitPartitionMetadata(
@@ -482,14 +475,10 @@
{T("vendor"), 1_GiB}};
SetMetadata(source(), initial);
SetMetadata(target(), initial);
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 0}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{S("system"), 2_GiB},
+ {S("vendor"), 1_GiB},
+ {T("system"), 2_GiB},
+ {T("vendor"), 0}});
ExpectUnmap({T("system"), T("vendor")});
ExpectMap({T("system")});
@@ -506,14 +495,10 @@
{T("vendor"), 1_GiB}};
SetMetadata(source(), initial);
SetMetadata(target(), initial);
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 0},
- {T("vendor"), 0}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{S("system"), 2_GiB},
+ {S("vendor"), 1_GiB},
+ {T("system"), 0},
+ {T("vendor"), 0}});
ExpectUnmap({T("system"), T("vendor")});
ExpectMap({});
@@ -542,14 +527,10 @@
{T("vendor"), 0}});
EXPECT_CALL(dynamicControl(), LoadMetadataBuilder(GetSuperDevice(), target()))
.WillOnce(Invoke([](auto, auto) { return nullptr; }));
- EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(),
- MetadataMatches({{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 3_GiB},
- {T("vendor"), 150_MiB}}),
- target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata({{S("system"), 2_GiB},
+ {S("vendor"), 1_GiB},
+ {T("system"), 3_GiB},
+ {T("vendor"), 150_MiB}});
ExpectRemap({T("system"), T("vendor")});
EXPECT_TRUE(bootctl_.InitPartitionMetadata(
target(), {{"system", 3_GiB}, {"vendor", 150_MiB}}));
@@ -619,11 +600,7 @@
SetMetadata(source(), update_sizes_0());
SetMetadata(target(), update_sizes_0());
- EXPECT_CALL(
- dynamicControl(),
- StoreMetadata(
- GetSuperDevice(), MetadataMatches(update_sizes_1()), target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata(update_sizes_1());
ExpectUnmap({"grown_b", "shrunk_b", "same_b", "added_b", "deleted_b"});
ExpectMap({"grown_b", "shrunk_b", "same_b", "added_b"});
@@ -644,11 +621,7 @@
SetMetadata(source(), update_sizes_1());
SetMetadata(target(), update_sizes_0());
- EXPECT_CALL(
- dynamicControl(),
- StoreMetadata(
- GetSuperDevice(), MetadataMatches(update_sizes_2()), target()))
- .WillOnce(Return(true));
+ ExpectStoreMetadata(update_sizes_2());
ExpectUnmap({"grown_a", "shrunk_a", "same_a", "added_a", "deleted_a"});
ExpectMap({"grown_a", "shrunk_a", "same_a", "deleted_a"});