Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6b83cfe authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "Only apply match if there is something to apply"

parents 1b4ab8bc f5ed661f
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -96,8 +96,12 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
    if (prefix_len > remaining_name_size) continue;

    if (!strncmp(c_string(trie_node.prefix(i)->name_offset), remaining_name, prefix_len)) {
      if (trie_node.prefix(i)->context_index != ~0u) {
        *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;
    }
  }
@@ -142,8 +146,20 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
  // Check exact matches
  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 (context_index != nullptr) *context_index = trie_node.exact_match(i)->context_index;
      if (schema_index != nullptr) *schema_index = trie_node.exact_match(i)->schema_index;
      if (context_index != nullptr) {
        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;
    }
  }
+42 −0
Original line number Diff line number Diff line
@@ -844,5 +844,47 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) {
  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 android