From a95ab58e79c50b0927eae2b834d3de20a8effc36 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 28 Nov 2009 15:38:29 -0800 Subject: Overhaul defs to derive from a common base. --- tests/test_table.cc | 16 ++++++++-------- tests/test_vs_proto2.cc | 6 ++---- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/test_table.cc b/tests/test_table.cc index 1289fbc..c903fff 100644 --- a/tests/test_table.cc +++ b/tests/test_table.cc @@ -32,10 +32,10 @@ double get_usertime() } struct upb_string *get_upbstring(const string& key) { - static struct upb_string str; - str.ptr = (char*)key.c_str(); - str.byte_len = key.size(); - return &str; + struct upb_string *str = upb_string_new(); + upb_string_resize(str, key.size()); + memcpy(str->ptr, key.c_str(), key.size()); + return str; } /* num_entries must be a power of 2. */ @@ -51,7 +51,7 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) all.insert(key); struct strtable_entry e; e.value = key[0]; - e.e.key = *get_upbstring(key); + e.e.key = get_upbstring(key); upb_strtable_insert(&table, &e.e); m[key] = key[0]; } @@ -61,10 +61,10 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) const string& key = keys[i]; struct upb_string *str = get_upbstring(key); struct strtable_entry *e = - (struct strtable_entry*)upb_strtable_lookup( &table, str); + (struct strtable_entry*)upb_strtable_lookup(&table, str); if(m.find(key) != m.end()) { /* Assume map implementation is correct. */ assert(e); - assert(upb_streql(&e->e.key, get_upbstring(key))); + assert(upb_streql(e->e.key, get_upbstring(key))); assert(e->value == key[0]); assert(m[key] == key[0]); } else { @@ -75,7 +75,7 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) struct strtable_entry *e; for(e = (struct strtable_entry*)upb_strtable_begin(&table); e; e = (struct strtable_entry*)upb_strtable_next(&table, &e->e)) { - string tmp(e->e.key.ptr, e->e.key.byte_len); + string tmp(e->e.key->ptr, e->e.key->byte_len); std::set::iterator i = all.find(tmp); assert(i != all.end()); all.erase(i); diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index 57cf73c..f1db678 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -204,15 +204,13 @@ int main(int argc, char *argv[]) upb_string_unref(fds); struct upb_string *proto_name = upb_strdupc(MESSAGE_NAME); - struct upb_symtab_entry e; - bool success = upb_context_lookup(c, proto_name, &e); - if(!success || e.type != UPB_SYM_MESSAGE) { + struct upb_msgdef *def = upb_downcast_msgdef(upb_context_lookup(c, proto_name)); + if(!def) { fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n", UPB_STRARG(proto_name)); return 1; } upb_string_unref(proto_name); - struct upb_msgdef *def = e.ref.msg; // Read the message data itself. struct upb_string *str = upb_strreadfile(MESSAGE_FILE); -- cgit v1.2.3