init: always allow clearing a property
An unintended consequence of property types is that it makes clearing a property, by setting it to an empty string, impossible. This change explicitly allows that case: Test: new (and old) unit tests Change-Id: I188693bfd3a71b64c194c3858544230b87d8d891
This commit is contained in:
parent
22c1eefb0d
commit
2096558837
2 changed files with 10 additions and 5 deletions
|
@ -29,6 +29,11 @@ namespace android {
|
|||
namespace init {
|
||||
|
||||
bool CheckType(const std::string& type_string, const std::string& value) {
|
||||
// Always allow clearing a property such that the default value when it is not set takes over.
|
||||
if (value.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto type_strings = Split(type_string, " ");
|
||||
if (type_strings.empty()) {
|
||||
return false;
|
||||
|
|
|
@ -32,7 +32,7 @@ TEST(property_type, CheckType_string) {
|
|||
}
|
||||
|
||||
TEST(property_type, CheckType_int) {
|
||||
EXPECT_FALSE(CheckType("int", ""));
|
||||
EXPECT_TRUE(CheckType("int", ""));
|
||||
EXPECT_FALSE(CheckType("int", "abc"));
|
||||
EXPECT_FALSE(CheckType("int", "-abc"));
|
||||
EXPECT_TRUE(CheckType("int", "0"));
|
||||
|
@ -43,7 +43,7 @@ TEST(property_type, CheckType_int) {
|
|||
}
|
||||
|
||||
TEST(property_type, CheckType_uint) {
|
||||
EXPECT_FALSE(CheckType("uint", ""));
|
||||
EXPECT_TRUE(CheckType("uint", ""));
|
||||
EXPECT_FALSE(CheckType("uint", "abc"));
|
||||
EXPECT_FALSE(CheckType("uint", "-abc"));
|
||||
EXPECT_TRUE(CheckType("uint", "0"));
|
||||
|
@ -53,7 +53,7 @@ TEST(property_type, CheckType_uint) {
|
|||
}
|
||||
|
||||
TEST(property_type, CheckType_double) {
|
||||
EXPECT_FALSE(CheckType("double", ""));
|
||||
EXPECT_TRUE(CheckType("double", ""));
|
||||
EXPECT_FALSE(CheckType("double", "abc"));
|
||||
EXPECT_FALSE(CheckType("double", "-abc"));
|
||||
EXPECT_TRUE(CheckType("double", "0.0"));
|
||||
|
@ -64,7 +64,7 @@ TEST(property_type, CheckType_double) {
|
|||
}
|
||||
|
||||
TEST(property_type, CheckType_size) {
|
||||
EXPECT_FALSE(CheckType("size", ""));
|
||||
EXPECT_TRUE(CheckType("size", ""));
|
||||
EXPECT_FALSE(CheckType("size", "ab"));
|
||||
EXPECT_FALSE(CheckType("size", "abcd"));
|
||||
EXPECT_FALSE(CheckType("size", "0"));
|
||||
|
@ -80,7 +80,7 @@ TEST(property_type, CheckType_size) {
|
|||
}
|
||||
|
||||
TEST(property_type, CheckType_enum) {
|
||||
EXPECT_FALSE(CheckType("enum abc", ""));
|
||||
EXPECT_TRUE(CheckType("enum abc", ""));
|
||||
EXPECT_FALSE(CheckType("enum abc", "ab"));
|
||||
EXPECT_FALSE(CheckType("enum abc", "abcd"));
|
||||
EXPECT_FALSE(CheckType("enum 123 456 789", "0"));
|
||||
|
|
Loading…
Reference in a new issue