diff --git a/src/developer/debug/zxdb/client/setting_schema.cc b/src/developer/debug/zxdb/client/setting_schema.cc index ed852094decf34f44e197ebf5d252aaeeaae37c9..c0a29a4e413f96fa2bc9b3fb0c0cbc8109bdd836 100644 --- a/src/developer/debug/zxdb/client/setting_schema.cc +++ b/src/developer/debug/zxdb/client/setting_schema.cc @@ -96,6 +96,20 @@ Err SettingSchema::ValidateSetting(const std::string& key, SettingTypeToString(setting.setting.value.type)); } + if (setting.setting.value.is_list() && !setting.options.empty()) { + for (auto& item : value.get_list()) { + bool found = false; + for (auto& option : setting.options) { + if (item == option) { + found = true; + break; + } + } + if (!found) + return Err("Option \"%s\" is not a valid option", item.c_str()); + } + } + return Err(); } diff --git a/src/developer/debug/zxdb/client/setting_store_unittest.cc b/src/developer/debug/zxdb/client/setting_store_unittest.cc index 61c03660a85f14fee1946aaad489980dfaf15d1b..271d203d7787e1b9afb72364e05b11ad0d19e211 100644 --- a/src/developer/debug/zxdb/client/setting_store_unittest.cc +++ b/src/developer/debug/zxdb/client/setting_store_unittest.cc @@ -27,6 +27,11 @@ fxl::RefPtr<SettingSchema> GetSchema() { FXL_NOTREACHED() << "Schema should be valid!"; return nullptr; } + if (!schema->AddList("list_with_options", "list_with_options", {}, + DefaultList())) { + FXL_NOTREACHED() << "Schema should be valid!"; + return nullptr; + } return schema; } @@ -98,6 +103,19 @@ TEST(SettingStore, Overrides) { EXPECT_EQ(store.GetInt("int"), kNewInt); } +TEST(SettingStore, ListOptions) { + Err err; + SettingStore store(GetSchema(), nullptr); + + // Attemp to add a valid item to the list with options. + err = store.SetList("list_with_options", {kDefaultString}); + EXPECT_FALSE(err.has_error()) << err.msg(); + + // Add an option that doesn't exist. + err = store.SetList("list_with_options", {"some_weird_option"}); + EXPECT_TRUE(err.has_error()); +} + TEST(SettingStore, Fallback) { SettingStore fallback2(GetSchema(), nullptr); std::vector<std::string> new_list = {"new", "list"};