Merge "Rename property 'schema' to 'type'"

This commit is contained in:
Tom Cherry 2018-01-12 19:13:44 +00:00 committed by Gerrit Code Review
commit ceecbfc40e
10 changed files with 222 additions and 225 deletions

View file

@ -32,8 +32,8 @@ struct PropertyEntry {
// This is the context match for this node_; ~0u if it doesn't correspond to any. // This is the context match for this node_; ~0u if it doesn't correspond to any.
uint32_t context_index; uint32_t context_index;
// This is the schema for this node_; ~0u if it doesn't correspond to any. // This is the type for this node_; ~0u if it doesn't correspond to any.
uint32_t schema_index; uint32_t type_index;
}; };
struct TrieNodeInternal { struct TrieNodeInternal {
@ -61,7 +61,7 @@ struct PropertyInfoAreaHeader {
uint32_t minimum_supported_version; uint32_t minimum_supported_version;
uint32_t size; uint32_t size;
uint32_t contexts_offset; uint32_t contexts_offset;
uint32_t schemas_offset; uint32_t types_offset;
uint32_t root_offset; uint32_t root_offset;
}; };
@ -103,7 +103,7 @@ class TrieNode {
} }
uint32_t context_index() const { return node_property_entry()->context_index; } uint32_t context_index() const { return node_property_entry()->context_index; }
uint32_t schema_index() const { return node_property_entry()->schema_index; } uint32_t type_index() const { return node_property_entry()->type_index; }
uint32_t num_child_nodes() const { return trie_node_base_->num_child_nodes; } uint32_t num_child_nodes() const { return trie_node_base_->num_child_nodes; }
TrieNode child_node(int n) const { TrieNode child_node(int n) const {
@ -143,12 +143,11 @@ class TrieNode {
class PropertyInfoArea : private SerializedData { class PropertyInfoArea : private SerializedData {
public: public:
void GetPropertyInfoIndexes(const char* name, uint32_t* context_index, void GetPropertyInfoIndexes(const char* name, uint32_t* context_index, uint32_t* type_index) const;
uint32_t* schema_index) const; void GetPropertyInfo(const char* property, const char** context, const char** type) const;
void GetPropertyInfo(const char* property, const char** context, const char** schema) const;
int FindContextIndex(const char* context) const; int FindContextIndex(const char* context) const;
int FindSchemaIndex(const char* schema) const; int FindTypeIndex(const char* type) const;
const char* context(uint32_t index) const { const char* context(uint32_t index) const {
uint32_t context_array_size_offset = contexts_offset(); uint32_t context_array_size_offset = contexts_offset();
@ -156,10 +155,10 @@ class PropertyInfoArea : private SerializedData {
return data_base() + context_array[index]; return data_base() + context_array[index];
} }
const char* schema(uint32_t index) const { const char* type(uint32_t index) const {
uint32_t schema_array_size_offset = schemas_offset(); uint32_t type_array_size_offset = types_offset();
const uint32_t* schema_array = uint32_array(schema_array_size_offset + sizeof(uint32_t)); const uint32_t* type_array = uint32_array(type_array_size_offset + sizeof(uint32_t));
return data_base() + schema_array[index]; return data_base() + type_array[index];
} }
uint32_t current_version() const { return header()->current_version; } uint32_t current_version() const { return header()->current_version; }
@ -168,21 +167,21 @@ class PropertyInfoArea : private SerializedData {
uint32_t size() const { return SerializedData::size(); } uint32_t size() const { return SerializedData::size(); }
uint32_t num_contexts() const { return uint32_array(contexts_offset())[0]; } uint32_t num_contexts() const { return uint32_array(contexts_offset())[0]; }
uint32_t num_schemas() const { return uint32_array(schemas_offset())[0]; } uint32_t num_types() const { return uint32_array(types_offset())[0]; }
TrieNode root_node() const { return trie(header()->root_offset); } TrieNode root_node() const { return trie(header()->root_offset); }
private: private:
void CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node, void CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node,
uint32_t* context_index, uint32_t* schema_index) const; uint32_t* context_index, uint32_t* type_index) const;
const PropertyInfoAreaHeader* header() const { const PropertyInfoAreaHeader* header() const {
return reinterpret_cast<const PropertyInfoAreaHeader*>(data_base()); return reinterpret_cast<const PropertyInfoAreaHeader*>(data_base());
} }
uint32_t contexts_offset() const { return header()->contexts_offset; } uint32_t contexts_offset() const { return header()->contexts_offset; }
uint32_t contexts_array_offset() const { return contexts_offset() + sizeof(uint32_t); } uint32_t contexts_array_offset() const { return contexts_offset() + sizeof(uint32_t); }
uint32_t schemas_offset() const { return header()->schemas_offset; } uint32_t types_offset() const { return header()->types_offset; }
uint32_t schemas_array_offset() const { return schemas_offset() + sizeof(uint32_t); } uint32_t types_array_offset() const { return types_offset() + sizeof(uint32_t); }
TrieNode trie(uint32_t offset) const { TrieNode trie(uint32_t offset) const {
if (offset != 0 && offset > size()) return TrieNode(); if (offset != 0 && offset > size()) return TrieNode();

View file

@ -56,12 +56,12 @@ int PropertyInfoArea::FindContextIndex(const char* context) const {
}); });
} }
// Binary search the list of schemas to find the index of a given schema string. // Binary search the list of types to find the index of a given type string.
// Only should be used for TrieSerializer to construct the Trie. // Only should be used for TrieSerializer to construct the Trie.
int PropertyInfoArea::FindSchemaIndex(const char* schema) const { int PropertyInfoArea::FindTypeIndex(const char* type) const {
return Find(num_schemas(), [this, schema](auto array_offset) { return Find(num_types(), [this, type](auto array_offset) {
auto string_offset = uint32_array(schemas_array_offset())[array_offset]; auto string_offset = uint32_array(types_array_offset())[array_offset];
return strcmp(c_string(string_offset), schema); return strcmp(c_string(string_offset), type);
}); });
} }
@ -89,7 +89,7 @@ bool TrieNode::FindChildForString(const char* name, uint32_t namelen, TrieNode*
} }
void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node, void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node,
uint32_t* context_index, uint32_t* schema_index) const { uint32_t* context_index, uint32_t* type_index) const {
const uint32_t remaining_name_size = strlen(remaining_name); const uint32_t remaining_name_size = strlen(remaining_name);
for (uint32_t i = 0; i < trie_node.num_prefixes(); ++i) { for (uint32_t i = 0; i < trie_node.num_prefixes(); ++i) {
auto prefix_len = trie_node.prefix(i)->namelen; auto prefix_len = trie_node.prefix(i)->namelen;
@ -99,8 +99,8 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
if (trie_node.prefix(i)->context_index != ~0u) { if (trie_node.prefix(i)->context_index != ~0u) {
*context_index = trie_node.prefix(i)->context_index; *context_index = trie_node.prefix(i)->context_index;
} }
if (trie_node.prefix(i)->schema_index != ~0u) { if (trie_node.prefix(i)->type_index != ~0u) {
*schema_index = trie_node.prefix(i)->schema_index; *type_index = trie_node.prefix(i)->type_index;
} }
return; return;
} }
@ -108,9 +108,9 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
} }
void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* context_index, void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* context_index,
uint32_t* schema_index) const { uint32_t* type_index) const {
uint32_t return_context_index = ~0u; uint32_t return_context_index = ~0u;
uint32_t return_schema_index = ~0u; uint32_t return_type_index = ~0u;
const char* remaining_name = name; const char* remaining_name = name;
auto trie_node = root_node(); auto trie_node = root_node();
while (true) { while (true) {
@ -120,13 +120,13 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
if (trie_node.context_index() != ~0u) { if (trie_node.context_index() != ~0u) {
return_context_index = trie_node.context_index(); return_context_index = trie_node.context_index();
} }
if (trie_node.schema_index() != ~0u) { if (trie_node.type_index() != ~0u) {
return_schema_index = trie_node.schema_index(); return_type_index = trie_node.type_index();
} }
// Check prefixes at this node. This comes after the node check since these prefixes are by // Check prefixes at this node. This comes after the node check since these prefixes are by
// definition longer than the node itself. // definition longer than the node itself.
CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index); CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index);
if (sep == nullptr) { if (sep == nullptr) {
break; break;
@ -153,29 +153,29 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
*context_index = return_context_index; *context_index = return_context_index;
} }
} }
if (schema_index != nullptr) { if (type_index != nullptr) {
if (trie_node.exact_match(i)->schema_index != ~0u) { if (trie_node.exact_match(i)->type_index != ~0u) {
*schema_index = trie_node.exact_match(i)->schema_index; *type_index = trie_node.exact_match(i)->type_index;
} else { } else {
*schema_index = return_schema_index; *type_index = return_type_index;
} }
} }
return; return;
} }
} }
// Check prefix matches for prefixes not deliminated with '.' // Check prefix matches for prefixes not deliminated with '.'
CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index); CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index);
// Return previously found prefix match. // Return previously found prefix match.
if (context_index != nullptr) *context_index = return_context_index; if (context_index != nullptr) *context_index = return_context_index;
if (schema_index != nullptr) *schema_index = return_schema_index; if (type_index != nullptr) *type_index = return_type_index;
return; return;
} }
void PropertyInfoArea::GetPropertyInfo(const char* property, const char** context, void PropertyInfoArea::GetPropertyInfo(const char* property, const char** context,
const char** schema) const { const char** type) const {
uint32_t context_index; uint32_t context_index;
uint32_t schema_index; uint32_t type_index;
GetPropertyInfoIndexes(property, &context_index, &schema_index); GetPropertyInfoIndexes(property, &context_index, &type_index);
if (context != nullptr) { if (context != nullptr) {
if (context_index == ~0u) { if (context_index == ~0u) {
*context = nullptr; *context = nullptr;
@ -183,11 +183,11 @@ void PropertyInfoArea::GetPropertyInfo(const char* property, const char** contex
*context = this->context(context_index); *context = this->context(context_index);
} }
} }
if (schema != nullptr) { if (type != nullptr) {
if (schema_index == ~0u) { if (type_index == ~0u) {
*schema = nullptr; *type = nullptr;
} else { } else {
*schema = this->schema(schema_index); *type = this->type(type_index);
} }
} }
} }

View file

@ -26,19 +26,19 @@ namespace properties {
struct PropertyInfoEntry { struct PropertyInfoEntry {
PropertyInfoEntry() {} PropertyInfoEntry() {}
template <typename T, typename U, typename V> template <typename T, typename U, typename V>
PropertyInfoEntry(T&& name, U&& context, V&& schema, bool exact_match) PropertyInfoEntry(T&& name, U&& context, V&& type, bool exact_match)
: name(std::forward<T>(name)), : name(std::forward<T>(name)),
context(std::forward<U>(context)), context(std::forward<U>(context)),
schema(std::forward<V>(schema)), type(std::forward<V>(type)),
exact_match(exact_match) {} exact_match(exact_match) {}
std::string name; std::string name;
std::string context; std::string context;
std::string schema; std::string type;
bool exact_match; bool exact_match;
}; };
bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info, bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
const std::string& default_context, const std::string& default_schema, const std::string& default_context, const std::string& default_type,
std::string* serialized_trie, std::string* error); std::string* serialized_trie, std::string* error);
void ParsePropertyInfoFile(const std::string& file_contents, void ParsePropertyInfoFile(const std::string& file_contents,

View file

@ -28,9 +28,9 @@ bool ParsePropertyInfoLine(const std::string& line, PropertyInfoEntry* out, std:
// It is not an error to not find these, as older files will not contain them. // It is not an error to not find these, as older files will not contain them.
auto exact_match = tokenizer.GetNext(); auto exact_match = tokenizer.GetNext();
auto schema = tokenizer.GetRemaining(); auto type = tokenizer.GetRemaining();
*out = {property, context, schema, exact_match == "exact"}; *out = {property, context, type, exact_match == "exact"};
return true; return true;
} }

View file

@ -27,13 +27,13 @@ namespace android {
namespace properties { namespace properties {
bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info, bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
const std::string& default_context, const std::string& default_schema, const std::string& default_context, const std::string& default_type,
std::string* serialized_trie, std::string* error) { std::string* serialized_trie, std::string* error) {
// Check that names are legal first // Check that names are legal first
auto trie_builder = TrieBuilder(default_context, default_schema); auto trie_builder = TrieBuilder(default_context, default_type);
for (const auto& [name, context, schema, is_exact] : property_info) { for (const auto& [name, context, type, is_exact] : property_info) {
if (!trie_builder.AddToTrie(name, context, schema, is_exact, error)) { if (!trie_builder.AddToTrie(name, context, type, is_exact, error)) {
return false; return false;
} }
} }

View file

@ -46,7 +46,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) {
auto root_node = property_info_area->root_node(); auto root_node = property_info_area->root_node();
EXPECT_STREQ("root", root_node.name()); EXPECT_STREQ("root", root_node.name());
EXPECT_STREQ("default", property_info_area->context(root_node.context_index())); EXPECT_STREQ("default", property_info_area->context(root_node.context_index()));
EXPECT_STREQ("default", property_info_area->schema(root_node.schema_index())); EXPECT_STREQ("default", property_info_area->type(root_node.type_index()));
EXPECT_EQ(0U, root_node.num_prefixes()); EXPECT_EQ(0U, root_node.num_prefixes());
EXPECT_EQ(0U, root_node.num_exact_matches()); EXPECT_EQ(0U, root_node.num_exact_matches());
@ -59,7 +59,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) {
EXPECT_STREQ("test", test_node.name()); EXPECT_STREQ("test", test_node.name());
EXPECT_STREQ("1st", property_info_area->context(test_node.context_index())); EXPECT_STREQ("1st", property_info_area->context(test_node.context_index()));
EXPECT_STREQ("1st", property_info_area->schema(test_node.schema_index())); EXPECT_STREQ("1st", property_info_area->type(test_node.type_index()));
EXPECT_EQ(0U, test_node.num_child_nodes()); EXPECT_EQ(0U, test_node.num_child_nodes());
@ -69,7 +69,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) {
EXPECT_STREQ("test", serialized_trie.data() + prefix->name_offset); EXPECT_STREQ("test", serialized_trie.data() + prefix->name_offset);
EXPECT_EQ(4U, prefix->namelen); EXPECT_EQ(4U, prefix->namelen);
EXPECT_STREQ("2nd", property_info_area->context(prefix->context_index)); EXPECT_STREQ("2nd", property_info_area->context(prefix->context_index));
EXPECT_STREQ("2nd", property_info_area->schema(prefix->schema_index)); EXPECT_STREQ("2nd", property_info_area->type(prefix->type_index));
} }
EXPECT_EQ(3U, test_node.num_exact_matches()); EXPECT_EQ(3U, test_node.num_exact_matches());
@ -85,9 +85,9 @@ TEST(propertyinfoserializer, TrieNodeCheck) {
EXPECT_STREQ("3rd", property_info_area->context(match2->context_index)); EXPECT_STREQ("3rd", property_info_area->context(match2->context_index));
EXPECT_STREQ("3rd", property_info_area->context(match3->context_index)); EXPECT_STREQ("3rd", property_info_area->context(match3->context_index));
EXPECT_STREQ("3rd", property_info_area->schema(match1->schema_index)); EXPECT_STREQ("3rd", property_info_area->type(match1->type_index));
EXPECT_STREQ("3rd", property_info_area->schema(match2->schema_index)); EXPECT_STREQ("3rd", property_info_area->type(match2->type_index));
EXPECT_STREQ("3rd", property_info_area->schema(match3->schema_index)); EXPECT_STREQ("3rd", property_info_area->type(match3->type_index));
} }
// Check the long string node // Check the long string node
@ -120,7 +120,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) {
auto final_match = long_string_node.exact_match(0); auto final_match = long_string_node.exact_match(0);
EXPECT_STREQ("string", serialized_trie.data() + final_match->name_offset); EXPECT_STREQ("string", serialized_trie.data() + final_match->name_offset);
EXPECT_STREQ("4th", property_info_area->context(final_match->context_index)); EXPECT_STREQ("4th", property_info_area->context(final_match->context_index));
EXPECT_STREQ("4th", property_info_area->schema(final_match->schema_index)); EXPECT_STREQ("4th", property_info_area->type(final_match->type_index));
} }
TEST(propertyinfoserializer, GetPropertyInfo) { TEST(propertyinfoserializer, GetPropertyInfo) {
@ -143,109 +143,109 @@ TEST(propertyinfoserializer, GetPropertyInfo) {
auto root_node = property_info_area->root_node(); auto root_node = property_info_area->root_node();
EXPECT_STREQ("root", root_node.name()); EXPECT_STREQ("root", root_node.name());
EXPECT_STREQ("default", property_info_area->context(root_node.context_index())); EXPECT_STREQ("default", property_info_area->context(root_node.context_index()));
EXPECT_STREQ("default", property_info_area->schema(root_node.schema_index())); EXPECT_STREQ("default", property_info_area->type(root_node.type_index()));
const char* context; const char* context;
const char* schema; const char* type;
property_info_area->GetPropertyInfo("abc", &context, &schema); property_info_area->GetPropertyInfo("abc", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("abc.abc", &context, &schema); property_info_area->GetPropertyInfo("abc.abc", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("123.abc", &context, &schema); property_info_area->GetPropertyInfo("123.abc", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("test.a", &context, &schema); property_info_area->GetPropertyInfo("test.a", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("test.b", &context, &schema); property_info_area->GetPropertyInfo("test.b", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("test.c", &context, &schema); property_info_area->GetPropertyInfo("test.c", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("test.test", &context, &schema); property_info_area->GetPropertyInfo("test.test", &context, &type);
EXPECT_STREQ("5th", context); EXPECT_STREQ("5th", context);
EXPECT_STREQ("5th", schema); EXPECT_STREQ("5th", type);
property_info_area->GetPropertyInfo("test.testa", &context, &schema); property_info_area->GetPropertyInfo("test.testa", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.testb", &context, &schema); property_info_area->GetPropertyInfo("test.testb", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.testc", &context, &schema); property_info_area->GetPropertyInfo("test.testc", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test.a", &context, &schema); property_info_area->GetPropertyInfo("test.test.a", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test.b", &context, &schema); property_info_area->GetPropertyInfo("test.test.b", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test.c", &context, &schema); property_info_area->GetPropertyInfo("test.test.c", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test1", &context, &schema); property_info_area->GetPropertyInfo("test.test1", &context, &type);
EXPECT_STREQ("3rd", context); EXPECT_STREQ("3rd", context);
EXPECT_STREQ("3rd", schema); EXPECT_STREQ("3rd", type);
property_info_area->GetPropertyInfo("test.test2", &context, &schema); property_info_area->GetPropertyInfo("test.test2", &context, &type);
EXPECT_STREQ("7th", context); EXPECT_STREQ("7th", context);
EXPECT_STREQ("7th", schema); EXPECT_STREQ("7th", type);
property_info_area->GetPropertyInfo("test.test3", &context, &schema); property_info_area->GetPropertyInfo("test.test3", &context, &type);
EXPECT_STREQ("3rd", context); EXPECT_STREQ("3rd", context);
EXPECT_STREQ("3rd", schema); EXPECT_STREQ("3rd", type);
property_info_area->GetPropertyInfo("test.test11", &context, &schema); property_info_area->GetPropertyInfo("test.test11", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test22", &context, &schema); property_info_area->GetPropertyInfo("test.test22", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("test.test33", &context, &schema); property_info_area->GetPropertyInfo("test.test33", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("this.is.a.long.string", &context, &schema); property_info_area->GetPropertyInfo("this.is.a.long.string", &context, &type);
EXPECT_STREQ("4th", context); EXPECT_STREQ("4th", context);
EXPECT_STREQ("4th", schema); EXPECT_STREQ("4th", type);
property_info_area->GetPropertyInfo("this.is.a.long", &context, &schema); property_info_area->GetPropertyInfo("this.is.a.long", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("this.is.a", &context, &schema); property_info_area->GetPropertyInfo("this.is.a", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("this.is", &context, &schema); property_info_area->GetPropertyInfo("this.is", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("this", &context, &schema); property_info_area->GetPropertyInfo("this", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("test.test2.a", &context, &schema); property_info_area->GetPropertyInfo("test.test2.a", &context, &type);
EXPECT_STREQ("6th", context); EXPECT_STREQ("6th", context);
EXPECT_STREQ("6th", schema); EXPECT_STREQ("6th", type);
property_info_area->GetPropertyInfo("testoneword", &context, &schema); property_info_area->GetPropertyInfo("testoneword", &context, &type);
EXPECT_STREQ("8th", context); EXPECT_STREQ("8th", context);
EXPECT_STREQ("8th", schema); EXPECT_STREQ("8th", type);
property_info_area->GetPropertyInfo("testwordprefix", &context, &schema); property_info_area->GetPropertyInfo("testwordprefix", &context, &type);
EXPECT_STREQ("9th", context); EXPECT_STREQ("9th", context);
EXPECT_STREQ("9th", schema); EXPECT_STREQ("9th", type);
property_info_area->GetPropertyInfo("testwordprefixblah", &context, &schema); property_info_area->GetPropertyInfo("testwordprefixblah", &context, &type);
EXPECT_STREQ("9th", context); EXPECT_STREQ("9th", context);
EXPECT_STREQ("9th", schema); EXPECT_STREQ("9th", type);
property_info_area->GetPropertyInfo("testwordprefix.blah", &context, &schema); property_info_area->GetPropertyInfo("testwordprefix.blah", &context, &type);
EXPECT_STREQ("9th", context); EXPECT_STREQ("9th", context);
EXPECT_STREQ("9th", schema); EXPECT_STREQ("9th", type);
} }
TEST(propertyinfoserializer, RealProperties) { TEST(propertyinfoserializer, RealProperties) {
@ -777,35 +777,34 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_without_dot) {
auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data()); auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data());
const char* context; const char* context;
const char* schema; const char* type;
property_info_area->GetPropertyInfo("persist.radio", &context, &schema); property_info_area->GetPropertyInfo("persist.radio", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radiowords", &context, &schema); property_info_area->GetPropertyInfo("persist.radiowords", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radio.long.long.long.sub.property", &context, property_info_area->GetPropertyInfo("persist.radio.long.long.long.sub.property", &context, &type);
&schema);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radio.something.else.here", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.something.else.here", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.something.else.here2", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.something.else.here2", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.something.else.here.after", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.something.else.here.after", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.something.else.nothere", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.something.else.nothere", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radio.something.else", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.something.else", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
} }
TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) { TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) {
@ -823,28 +822,28 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) {
auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data()); auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data());
const char* context; const char* context;
const char* schema; const char* type;
property_info_area->GetPropertyInfo("persist.notradio", &context, &schema); property_info_area->GetPropertyInfo("persist.notradio", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("1st", schema); EXPECT_STREQ("1st", type);
property_info_area->GetPropertyInfo("persist.radio", &context, &schema); property_info_area->GetPropertyInfo("persist.radio", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radiowords", &context, &schema); property_info_area->GetPropertyInfo("persist.radiowords", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.long.property.prefix.match", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.long.property.prefix.match", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("2nd", schema); EXPECT_STREQ("2nd", type);
property_info_area->GetPropertyInfo("persist.radio.long.property.exact.match", &context, &schema); property_info_area->GetPropertyInfo("persist.radio.long.property.exact.match", &context, &type);
EXPECT_STREQ("3rd", context); EXPECT_STREQ("3rd", context);
EXPECT_STREQ("3rd", schema); EXPECT_STREQ("3rd", type);
} }
TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) { TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_type) {
auto property_info = std::vector<PropertyInfoEntry>{ auto property_info = std::vector<PropertyInfoEntry>{
{"persist.", "1st", "", false}, {"persist.", "1st", "", false},
{"persist.dot_prefix.", "2nd", "", false}, {"persist.dot_prefix.", "2nd", "", false},
@ -862,28 +861,28 @@ TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) {
auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data()); auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data());
const char* context; const char* context;
const char* schema; const char* type;
property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &schema); property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &type);
EXPECT_STREQ("default", context); EXPECT_STREQ("default", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("persist.nomatch", &context, &schema); property_info_area->GetPropertyInfo("persist.nomatch", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &schema); property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &type);
EXPECT_STREQ("2nd", context); EXPECT_STREQ("2nd", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &schema); property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &type);
EXPECT_STREQ("3rd", context); EXPECT_STREQ("3rd", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("persist.exact_match", &context, &schema); property_info_area->GetPropertyInfo("persist.exact_match", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("default", schema); EXPECT_STREQ("default", type);
property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &schema); property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("4th", schema); EXPECT_STREQ("4th", type);
property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &schema); property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &type);
EXPECT_STREQ("1st", context); EXPECT_STREQ("1st", context);
EXPECT_STREQ("5th", schema); EXPECT_STREQ("5th", type);
} }
} // namespace properties } // namespace properties

View file

@ -23,23 +23,23 @@ using android::base::Split;
namespace android { namespace android {
namespace properties { namespace properties {
TrieBuilder::TrieBuilder(const std::string& default_context, const std::string& default_schema) TrieBuilder::TrieBuilder(const std::string& default_context, const std::string& default_type)
: builder_root_("root") { : builder_root_("root") {
auto* context_pointer = StringPointerFromContainer(default_context, &contexts_); auto* context_pointer = StringPointerFromContainer(default_context, &contexts_);
builder_root_.set_context(context_pointer); builder_root_.set_context(context_pointer);
auto* schema_pointer = StringPointerFromContainer(default_schema, &schemas_); auto* type_pointer = StringPointerFromContainer(default_type, &types_);
builder_root_.set_schema(schema_pointer); builder_root_.set_type(type_pointer);
} }
bool TrieBuilder::AddToTrie(const std::string& name, const std::string& context, bool TrieBuilder::AddToTrie(const std::string& name, const std::string& context,
const std::string& schema, bool exact, std::string* error) { const std::string& type, bool exact, std::string* error) {
auto* context_pointer = StringPointerFromContainer(context, &contexts_); auto* context_pointer = StringPointerFromContainer(context, &contexts_);
auto* schema_pointer = StringPointerFromContainer(schema, &schemas_); auto* type_pointer = StringPointerFromContainer(type, &types_);
return AddToTrie(name, context_pointer, schema_pointer, exact, error); return AddToTrie(name, context_pointer, type_pointer, exact, error);
} }
bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context, bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context,
const std::string* schema, bool exact, std::string* error) { const std::string* type, bool exact, std::string* error) {
TrieBuilderNode* current_node = &builder_root_; TrieBuilderNode* current_node = &builder_root_;
auto name_pieces = Split(name, "."); auto name_pieces = Split(name, ".");
@ -66,12 +66,12 @@ bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context,
// Store our context based on what type of match it is. // Store our context based on what type of match it is.
if (exact) { if (exact) {
if (!current_node->AddExactMatchContext(name_pieces.front(), context, schema)) { if (!current_node->AddExactMatchContext(name_pieces.front(), context, type)) {
*error = "Duplicate exact match detected for '" + name + "'"; *error = "Duplicate exact match detected for '" + name + "'";
return false; return false;
} }
} else if (!ends_with_dot) { } else if (!ends_with_dot) {
if (!current_node->AddPrefixContext(name_pieces.front(), context, schema)) { if (!current_node->AddPrefixContext(name_pieces.front(), context, type)) {
*error = "Duplicate prefix match detected for '" + name + "'"; *error = "Duplicate prefix match detected for '" + name + "'";
return false; return false;
} }
@ -84,12 +84,12 @@ bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context,
*error = "Unable to allocate Trie node"; *error = "Unable to allocate Trie node";
return false; return false;
} }
if (child->context() != nullptr || child->schema() != nullptr) { if (child->context() != nullptr || child->type() != nullptr) {
*error = "Duplicate prefix match detected for '" + name + "'"; *error = "Duplicate prefix match detected for '" + name + "'";
return false; return false;
} }
child->set_context(context); child->set_context(context);
child->set_schema(schema); child->set_type(type);
} }
return true; return true;
} }

View file

@ -26,13 +26,12 @@ namespace android {
namespace properties { namespace properties {
struct PropertyEntryBuilder { struct PropertyEntryBuilder {
PropertyEntryBuilder() : context(nullptr), schema(nullptr) {} PropertyEntryBuilder() : context(nullptr), type(nullptr) {}
PropertyEntryBuilder(const std::string& name, const std::string* context, PropertyEntryBuilder(const std::string& name, const std::string* context, const std::string* type)
const std::string* schema) : name(name), context(context), type(type) {}
: name(name), context(context), schema(schema) {}
std::string name; std::string name;
const std::string* context; const std::string* context;
const std::string* schema; const std::string* type;
}; };
class TrieBuilderNode { class TrieBuilderNode {
@ -56,33 +55,33 @@ class TrieBuilderNode {
TrieBuilderNode* AddChild(const std::string& name) { return &children_.emplace_back(name); } TrieBuilderNode* AddChild(const std::string& name) { return &children_.emplace_back(name); }
bool AddPrefixContext(const std::string& prefix, const std::string* context, bool AddPrefixContext(const std::string& prefix, const std::string* context,
const std::string* schema) { const std::string* type) {
if (std::find_if(prefixes_.begin(), prefixes_.end(), if (std::find_if(prefixes_.begin(), prefixes_.end(),
[&prefix](const auto& t) { return t.name == prefix; }) != prefixes_.end()) { [&prefix](const auto& t) { return t.name == prefix; }) != prefixes_.end()) {
return false; return false;
} }
prefixes_.emplace_back(prefix, context, schema); prefixes_.emplace_back(prefix, context, type);
return true; return true;
} }
bool AddExactMatchContext(const std::string& exact_match, const std::string* context, bool AddExactMatchContext(const std::string& exact_match, const std::string* context,
const std::string* schema) { const std::string* type) {
if (std::find_if(exact_matches_.begin(), exact_matches_.end(), [&exact_match](const auto& t) { if (std::find_if(exact_matches_.begin(), exact_matches_.end(), [&exact_match](const auto& t) {
return t.name == exact_match; return t.name == exact_match;
}) != exact_matches_.end()) { }) != exact_matches_.end()) {
return false; return false;
} }
exact_matches_.emplace_back(exact_match, context, schema); exact_matches_.emplace_back(exact_match, context, type);
return true; return true;
} }
const std::string& name() const { return property_entry_.name; } const std::string& name() const { return property_entry_.name; }
const std::string* context() const { return property_entry_.context; } const std::string* context() const { return property_entry_.context; }
void set_context(const std::string* context) { property_entry_.context = context; } void set_context(const std::string* context) { property_entry_.context = context; }
const std::string* schema() const { return property_entry_.schema; } const std::string* type() const { return property_entry_.type; }
void set_schema(const std::string* schema) { property_entry_.schema = schema; } void set_type(const std::string* type) { property_entry_.type = type; }
const PropertyEntryBuilder property_entry() const { return property_entry_; } const PropertyEntryBuilder property_entry() const { return property_entry_; }
@ -99,23 +98,23 @@ class TrieBuilderNode {
class TrieBuilder { class TrieBuilder {
public: public:
TrieBuilder(const std::string& default_context, const std::string& default_schema); TrieBuilder(const std::string& default_context, const std::string& default_type);
bool AddToTrie(const std::string& name, const std::string& context, const std::string& schema, bool AddToTrie(const std::string& name, const std::string& context, const std::string& type,
bool exact, std::string* error); bool exact, std::string* error);
const TrieBuilderNode builder_root() const { return builder_root_; } const TrieBuilderNode builder_root() const { return builder_root_; }
const std::set<std::string>& contexts() const { return contexts_; } const std::set<std::string>& contexts() const { return contexts_; }
const std::set<std::string>& schemas() const { return schemas_; } const std::set<std::string>& types() const { return types_; }
private: private:
bool AddToTrie(const std::string& name, const std::string* context, const std::string* schema, bool AddToTrie(const std::string& name, const std::string* context, const std::string* type,
bool exact, std::string* error); bool exact, std::string* error);
const std::string* StringPointerFromContainer(const std::string& string, const std::string* StringPointerFromContainer(const std::string& string,
std::set<std::string>* container); std::set<std::string>* container);
TrieBuilderNode builder_root_; TrieBuilderNode builder_root_;
std::set<std::string> contexts_; std::set<std::string> contexts_;
std::set<std::string> schemas_; std::set<std::string> types_;
}; };
} // namespace properties } // namespace properties

View file

@ -22,19 +22,19 @@ namespace android {
namespace properties { namespace properties {
TEST(propertyinfoserializer, BuildTrie_Simple) { TEST(propertyinfoserializer, BuildTrie_Simple) {
auto trie_builder = TrieBuilder("default", "default_schema"); auto trie_builder = TrieBuilder("default", "default_type");
// Add test data to tree // Add test data to tree
auto error = std::string(); auto error = std::string();
EXPECT_TRUE(trie_builder.AddToTrie("test.", "1st", "1st_schema", false, &error)); EXPECT_TRUE(trie_builder.AddToTrie("test.", "1st", "1st_type", false, &error));
EXPECT_TRUE(trie_builder.AddToTrie("test.test", "2nd", "2nd_schema", false, &error)); EXPECT_TRUE(trie_builder.AddToTrie("test.test", "2nd", "2nd_type", false, &error));
EXPECT_TRUE(trie_builder.AddToTrie("test.test1", "3rd", "3rd_schema", true, &error)); EXPECT_TRUE(trie_builder.AddToTrie("test.test1", "3rd", "3rd_type", true, &error));
EXPECT_TRUE(trie_builder.AddToTrie("test.test2", "3rd", "3rd_schema", true, &error)); EXPECT_TRUE(trie_builder.AddToTrie("test.test2", "3rd", "3rd_type", true, &error));
EXPECT_TRUE(trie_builder.AddToTrie("test.test3", "3rd", "3rd_schema", true, &error)); EXPECT_TRUE(trie_builder.AddToTrie("test.test3", "3rd", "3rd_type", true, &error));
EXPECT_TRUE(trie_builder.AddToTrie("this.is.a.long.string", "4th", "4th_schema", true, &error)); EXPECT_TRUE(trie_builder.AddToTrie("this.is.a.long.string", "4th", "4th_type", true, &error));
ASSERT_EQ(5U, trie_builder.contexts().size()); ASSERT_EQ(5U, trie_builder.contexts().size());
ASSERT_EQ(5U, trie_builder.schemas().size()); ASSERT_EQ(5U, trie_builder.types().size());
auto& builder_root = trie_builder.builder_root(); auto& builder_root = trie_builder.builder_root();
@ -42,8 +42,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) {
EXPECT_EQ("root", builder_root.name()); EXPECT_EQ("root", builder_root.name());
ASSERT_NE(nullptr, builder_root.context()); ASSERT_NE(nullptr, builder_root.context());
EXPECT_EQ("default", *builder_root.context()); EXPECT_EQ("default", *builder_root.context());
ASSERT_NE(nullptr, builder_root.schema()); ASSERT_NE(nullptr, builder_root.type());
EXPECT_EQ("default_schema", *builder_root.schema()); EXPECT_EQ("default_type", *builder_root.type());
EXPECT_EQ(0U, builder_root.prefixes().size()); EXPECT_EQ(0U, builder_root.prefixes().size());
EXPECT_EQ(0U, builder_root.exact_matches().size()); EXPECT_EQ(0U, builder_root.exact_matches().size());
@ -55,8 +55,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) {
EXPECT_EQ("test", test_node->name()); EXPECT_EQ("test", test_node->name());
ASSERT_NE(nullptr, test_node->context()); ASSERT_NE(nullptr, test_node->context());
EXPECT_EQ("1st", *test_node->context()); EXPECT_EQ("1st", *test_node->context());
ASSERT_NE(nullptr, test_node->schema()); ASSERT_NE(nullptr, test_node->type());
EXPECT_EQ("1st_schema", *test_node->schema()); EXPECT_EQ("1st_type", *test_node->type());
EXPECT_EQ(0U, test_node->children().size()); EXPECT_EQ(0U, test_node->children().size());
EXPECT_EQ(1U, test_node->prefixes().size()); EXPECT_EQ(1U, test_node->prefixes().size());
@ -65,8 +65,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) {
EXPECT_EQ("test", property_entry.name); EXPECT_EQ("test", property_entry.name);
ASSERT_NE(nullptr, property_entry.context); ASSERT_NE(nullptr, property_entry.context);
EXPECT_EQ("2nd", *property_entry.context); EXPECT_EQ("2nd", *property_entry.context);
ASSERT_NE(nullptr, property_entry.schema); ASSERT_NE(nullptr, property_entry.type);
EXPECT_EQ("2nd_schema", *property_entry.schema); EXPECT_EQ("2nd_type", *property_entry.type);
} }
EXPECT_EQ(3U, test_node->exact_matches().size()); EXPECT_EQ(3U, test_node->exact_matches().size());
EXPECT_EQ("test1", test_node->exact_matches()[0].name); EXPECT_EQ("test1", test_node->exact_matches()[0].name);
@ -80,18 +80,18 @@ TEST(propertyinfoserializer, BuildTrie_Simple) {
EXPECT_EQ("3rd", *test_node->exact_matches()[1].context); EXPECT_EQ("3rd", *test_node->exact_matches()[1].context);
EXPECT_EQ("3rd", *test_node->exact_matches()[2].context); EXPECT_EQ("3rd", *test_node->exact_matches()[2].context);
ASSERT_NE(nullptr, test_node->exact_matches()[0].schema); ASSERT_NE(nullptr, test_node->exact_matches()[0].type);
ASSERT_NE(nullptr, test_node->exact_matches()[1].schema); ASSERT_NE(nullptr, test_node->exact_matches()[1].type);
ASSERT_NE(nullptr, test_node->exact_matches()[2].schema); ASSERT_NE(nullptr, test_node->exact_matches()[2].type);
EXPECT_EQ("3rd_schema", *test_node->exact_matches()[0].schema); EXPECT_EQ("3rd_type", *test_node->exact_matches()[0].type);
EXPECT_EQ("3rd_schema", *test_node->exact_matches()[1].schema); EXPECT_EQ("3rd_type", *test_node->exact_matches()[1].type);
EXPECT_EQ("3rd_schema", *test_node->exact_matches()[2].schema); EXPECT_EQ("3rd_type", *test_node->exact_matches()[2].type);
// Check the long string node // Check the long string node
auto expect_empty_one_child = [](auto* node) { auto expect_empty_one_child = [](auto* node) {
ASSERT_NE(nullptr, node); ASSERT_NE(nullptr, node);
EXPECT_EQ(nullptr, node->context()); EXPECT_EQ(nullptr, node->context());
EXPECT_EQ(nullptr, node->schema()); EXPECT_EQ(nullptr, node->type());
EXPECT_EQ(0U, node->prefixes().size()); EXPECT_EQ(0U, node->prefixes().size());
EXPECT_EQ(0U, node->exact_matches().size()); EXPECT_EQ(0U, node->exact_matches().size());
EXPECT_EQ(1U, node->children().size()); EXPECT_EQ(1U, node->children().size());
@ -120,8 +120,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) {
EXPECT_EQ("string", property_entry.name); EXPECT_EQ("string", property_entry.name);
ASSERT_NE(nullptr, property_entry.context); ASSERT_NE(nullptr, property_entry.context);
EXPECT_EQ("4th", *property_entry.context); EXPECT_EQ("4th", *property_entry.context);
ASSERT_NE(nullptr, property_entry.schema); ASSERT_NE(nullptr, property_entry.type);
EXPECT_EQ("4th_schema", *property_entry.schema); EXPECT_EQ("4th_type", *property_entry.type);
} }
} }

View file

@ -43,15 +43,15 @@ uint32_t TrieSerializer::WritePropertyEntry(const PropertyEntryBuilder& property
uint32_t context_index = property_entry.context != nullptr && !property_entry.context->empty() uint32_t context_index = property_entry.context != nullptr && !property_entry.context->empty()
? serialized_info()->FindContextIndex(property_entry.context->c_str()) ? serialized_info()->FindContextIndex(property_entry.context->c_str())
: ~0u; : ~0u;
uint32_t schema_index = property_entry.schema != nullptr && !property_entry.schema->empty() uint32_t type_index = property_entry.type != nullptr && !property_entry.type->empty()
? serialized_info()->FindSchemaIndex(property_entry.schema->c_str()) ? serialized_info()->FindTypeIndex(property_entry.type->c_str())
: ~0u; : ~0u;
uint32_t offset; uint32_t offset;
auto serialized_property_entry = arena_->AllocateObject<PropertyEntry>(&offset); auto serialized_property_entry = arena_->AllocateObject<PropertyEntry>(&offset);
serialized_property_entry->name_offset = arena_->AllocateAndWriteString(property_entry.name); serialized_property_entry->name_offset = arena_->AllocateAndWriteString(property_entry.name);
serialized_property_entry->namelen = property_entry.name.size(); serialized_property_entry->namelen = property_entry.name.size();
serialized_property_entry->context_index = context_index; serialized_property_entry->context_index = context_index;
serialized_property_entry->schema_index = schema_index; serialized_property_entry->type_index = type_index;
return offset; return offset;
} }
@ -122,9 +122,9 @@ std::string TrieSerializer::SerializeTrie(const TrieBuilder& trie_builder) {
header->contexts_offset = arena_->size(); header->contexts_offset = arena_->size();
SerializeStrings(trie_builder.contexts()); SerializeStrings(trie_builder.contexts());
// Store where we're about to write the schemas. // Store where we're about to write the types.
header->schemas_offset = arena_->size(); header->types_offset = arena_->size();
SerializeStrings(trie_builder.schemas()); SerializeStrings(trie_builder.types());
// We need to store size() up to this point now for Find*Offset() to work. // We need to store size() up to this point now for Find*Offset() to work.
header->size = arena_->size(); header->size = arena_->size();