Merge "Only apply match if there is something to apply" am: e6b83cfe5a
am: a9ca04a17d
Change-Id: I1e1f1605fd099be09da5c579f2ce649964e3677d
This commit is contained in:
commit
333521871b
2 changed files with 62 additions and 4 deletions
|
|
@ -96,8 +96,12 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
|
||||||
if (prefix_len > remaining_name_size) continue;
|
if (prefix_len > remaining_name_size) continue;
|
||||||
|
|
||||||
if (!strncmp(c_string(trie_node.prefix(i)->name_offset), remaining_name, prefix_len)) {
|
if (!strncmp(c_string(trie_node.prefix(i)->name_offset), remaining_name, prefix_len)) {
|
||||||
*context_index = trie_node.prefix(i)->context_index;
|
if (trie_node.prefix(i)->context_index != ~0u) {
|
||||||
*schema_index = trie_node.prefix(i)->schema_index;
|
*context_index = trie_node.prefix(i)->context_index;
|
||||||
|
}
|
||||||
|
if (trie_node.prefix(i)->schema_index != ~0u) {
|
||||||
|
*schema_index = trie_node.prefix(i)->schema_index;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,8 +146,20 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
|
||||||
// Check exact matches
|
// Check exact matches
|
||||||
for (uint32_t i = 0; i < trie_node.num_exact_matches(); ++i) {
|
for (uint32_t i = 0; i < trie_node.num_exact_matches(); ++i) {
|
||||||
if (!strcmp(c_string(trie_node.exact_match(i)->name_offset), remaining_name)) {
|
if (!strcmp(c_string(trie_node.exact_match(i)->name_offset), remaining_name)) {
|
||||||
if (context_index != nullptr) *context_index = trie_node.exact_match(i)->context_index;
|
if (context_index != nullptr) {
|
||||||
if (schema_index != nullptr) *schema_index = trie_node.exact_match(i)->schema_index;
|
if (trie_node.exact_match(i)->context_index != ~0u) {
|
||||||
|
*context_index = trie_node.exact_match(i)->context_index;
|
||||||
|
} else {
|
||||||
|
*context_index = return_context_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (schema_index != nullptr) {
|
||||||
|
if (trie_node.exact_match(i)->schema_index != ~0u) {
|
||||||
|
*schema_index = trie_node.exact_match(i)->schema_index;
|
||||||
|
} else {
|
||||||
|
*schema_index = return_schema_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -844,5 +844,47 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) {
|
||||||
EXPECT_STREQ("3rd", schema);
|
EXPECT_STREQ("3rd", schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) {
|
||||||
|
auto property_info = std::vector<PropertyInfoEntry>{
|
||||||
|
{"persist.", "1st", "", false},
|
||||||
|
{"persist.dot_prefix.", "2nd", "", false},
|
||||||
|
{"persist.non_dot_prefix", "3rd", "", false},
|
||||||
|
{"persist.exact_match", "", "", true},
|
||||||
|
{"persist.dot_prefix2.", "", "4th", false},
|
||||||
|
{"persist.non_dot_prefix2", "", "5th", false},
|
||||||
|
};
|
||||||
|
|
||||||
|
auto serialized_trie = std::string();
|
||||||
|
auto build_trie_error = std::string();
|
||||||
|
ASSERT_TRUE(BuildTrie(property_info, "default", "default", &serialized_trie, &build_trie_error))
|
||||||
|
<< build_trie_error;
|
||||||
|
|
||||||
|
auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data());
|
||||||
|
|
||||||
|
const char* context;
|
||||||
|
const char* schema;
|
||||||
|
property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &schema);
|
||||||
|
EXPECT_STREQ("default", context);
|
||||||
|
EXPECT_STREQ("default", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.nomatch", &context, &schema);
|
||||||
|
EXPECT_STREQ("1st", context);
|
||||||
|
EXPECT_STREQ("default", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &schema);
|
||||||
|
EXPECT_STREQ("2nd", context);
|
||||||
|
EXPECT_STREQ("default", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &schema);
|
||||||
|
EXPECT_STREQ("3rd", context);
|
||||||
|
EXPECT_STREQ("default", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.exact_match", &context, &schema);
|
||||||
|
EXPECT_STREQ("1st", context);
|
||||||
|
EXPECT_STREQ("default", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &schema);
|
||||||
|
EXPECT_STREQ("1st", context);
|
||||||
|
EXPECT_STREQ("4th", schema);
|
||||||
|
property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &schema);
|
||||||
|
EXPECT_STREQ("1st", context);
|
||||||
|
EXPECT_STREQ("5th", schema);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace properties
|
} // namespace properties
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue