From d5566c6038845e505f7c16130b2368ef9bb3a373 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 15 Jan 2010 19:11:54 -0800 Subject: Remove struct keyword from all types, use typedef instead. --- tests/test_table.cc | 41 +++++++++++++++++++---------------------- tests/test_vs_proto2.cc | 20 ++++++++++---------- tests/tests.c | 28 ++++++++++++++-------------- 3 files changed, 43 insertions(+), 46 deletions(-) (limited to 'tests') diff --git a/tests/test_table.cc b/tests/test_table.cc index 7f8510b..47d806c 100644 --- a/tests/test_table.cc +++ b/tests/test_table.cc @@ -15,15 +15,15 @@ using std::string; using std::vector; -struct inttable_entry { - struct upb_inttable_entry e; +typedef struct { + upb_inttable_entry e; uint32_t value; /* key*2 */ -}; +} inttable_entry; -struct strtable_entry { - struct upb_strtable_entry e; +typedef struct { + upb_strtable_entry e; int32_t value; /* ASCII Value of first letter */ -}; +} strtable_entry; double get_usertime() { @@ -36,14 +36,14 @@ double get_usertime() void test_strtable(const vector& keys, uint32_t num_to_insert) { /* Initialize structures. */ - struct upb_strtable table; + upb_strtable table; std::map m; - upb_strtable_init(&table, 0, sizeof(struct strtable_entry)); + upb_strtable_init(&table, 0, sizeof(strtable_entry)); std::set all; for(size_t i = 0; i < num_to_insert; i++) { const string& key = keys[i]; all.insert(key); - struct strtable_entry e; + strtable_entry e; e.value = key[0]; upb_strptr str = upb_strduplen(key.c_str(), key.size()); e.e.key = str; @@ -56,8 +56,7 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) for(uint32_t i = 0; i < keys.size(); i++) { const string& key = keys[i]; upb_strptr str = upb_strduplen(key.c_str(), key.size()); - struct strtable_entry *e = - (struct strtable_entry*)upb_strtable_lookup(&table, str); + strtable_entry *e = (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, str)); @@ -69,9 +68,9 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) upb_string_unref(str); } - struct strtable_entry *e; - for(e = (struct strtable_entry*)upb_strtable_begin(&table); e; - e = (struct strtable_entry*)upb_strtable_next(&table, &e->e)) { + strtable_entry *e; + for(e = (strtable_entry*)upb_strtable_begin(&table); e; + e = (strtable_entry*)upb_strtable_next(&table, &e->e)) { string tmp(upb_string_getrobuf(e->e.key), upb_strlen(e->e.key)); std::set::iterator i = all.find(tmp); assert(i != all.end()); @@ -86,15 +85,15 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) void test_inttable(int32_t *keys, size_t num_entries) { /* Initialize structures. */ - struct upb_inttable table; + upb_inttable table; uint32_t largest_key = 0; std::map m; __gnu_cxx::hash_map hm; - upb_inttable_init(&table, num_entries, sizeof(struct inttable_entry)); + upb_inttable_init(&table, num_entries, sizeof(inttable_entry)); for(size_t i = 0; i < num_entries; i++) { int32_t key = keys[i]; largest_key = UPB_MAX((int32_t)largest_key, key); - struct inttable_entry e; + inttable_entry e; e.e.key = key; e.value = key*2; upb_inttable_insert(&table, &e.e); @@ -104,7 +103,7 @@ void test_inttable(int32_t *keys, size_t num_entries) /* Test correctness. */ for(uint32_t i = 1; i <= largest_key; i++) { - struct inttable_entry *e = (struct inttable_entry*)upb_inttable_lookup( + inttable_entry *e = (inttable_entry*)upb_inttable_lookup( &table, i); if(m.find(i) != m.end()) { /* Assume map implementation is correct. */ assert(e); @@ -147,8 +146,7 @@ void test_inttable(int32_t *keys, size_t num_entries) before = get_usertime(); for(unsigned int i = 0; i < iterations; i++) { int32_t key = keys[i & mask]; - struct inttable_entry *e = (struct inttable_entry*)upb_inttable_lookup( - &table, key); + inttable_entry *e = (inttable_entry*)upb_inttable_lookup(&table, key); x += (uintptr_t)e; } double total = get_usertime() - before; @@ -160,8 +158,7 @@ void test_inttable(int32_t *keys, size_t num_entries) before = get_usertime(); for(unsigned int i = 0; i < iterations; i++) { int32_t key = keys[rand() & mask]; - struct inttable_entry *e = (struct inttable_entry*)upb_inttable_lookup( - &table, key); + inttable_entry *e = (inttable_entry*)upb_inttable_lookup(&table, key); x += (uintptr_t)e; } total = get_usertime() - before; diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index 6cb37b7..736b78f 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -17,12 +17,12 @@ int num_assertions = 0; #include MESSAGE_HFILE void compare(const google::protobuf::Message& proto2_msg, - upb_msg *upb_msg, struct upb_msgdef *upb_md); + upb_msg *upb_msg, upb_msgdef *upb_md); void compare_arrays(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, const google::protobuf::FieldDescriptor *proto2_f, - upb_msg *upb_msg, struct upb_fielddef *upb_f) + upb_msg *upb_msg, upb_fielddef *upb_f) { ASSERT(upb_msg_has(upb_msg, upb_f)); upb_arrayptr arr = upb_msg_get(upb_msg, upb_f).arr; @@ -79,7 +79,7 @@ void compare_arrays(const google::protobuf::Reflection *r, void compare_values(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, const google::protobuf::FieldDescriptor *proto2_f, - upb_msg *upb_msg, struct upb_fielddef *upb_f) + upb_msg *upb_msg, upb_fielddef *upb_f) { union upb_value v = upb_msg_get(upb_msg, upb_f); switch(upb_f->type) { @@ -128,14 +128,14 @@ void compare_values(const google::protobuf::Reflection *r, } void compare(const google::protobuf::Message& proto2_msg, - upb_msg *upb_msg, struct upb_msgdef *upb_md) + upb_msg *upb_msg, upb_msgdef *upb_md) { const google::protobuf::Reflection *r = proto2_msg.GetReflection(); const google::protobuf::Descriptor *d = proto2_msg.GetDescriptor(); ASSERT((upb_field_count_t)d->field_count() == upb_md->num_fields); for(upb_field_count_t i = 0; i < upb_md->num_fields; i++) { - struct upb_fielddef *upb_f = &upb_md->fields[i]; + upb_fielddef *upb_f = &upb_md->fields[i]; const google::protobuf::FieldDescriptor *proto2_f = d->FindFieldByNumber(upb_f->number); // Make sure the definitions are equal. @@ -165,12 +165,12 @@ void compare(const google::protobuf::Message& proto2_msg, } void parse_and_compare(MESSAGE_CIDENT *proto2_msg, - upb_msg *upb_msg, struct upb_msgdef *upb_md, + upb_msg *upb_msg, upb_msgdef *upb_md, upb_strptr str) { // Parse to both proto2 and upb. ASSERT(proto2_msg->ParseFromArray(upb_string_getrobuf(str), upb_strlen(str))); - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; upb_msg_decodestr(upb_msg, upb_md, str, &status); ASSERT(upb_ok(&status)); compare(*proto2_msg, upb_msg, upb_md); @@ -193,8 +193,8 @@ int main(int argc, char *argv[]) } // Initialize upb state, parse descriptor. - struct upb_status status = UPB_STATUS_INIT; - struct upb_symtab *c = upb_symtab_new(); + upb_status status = UPB_STATUS_INIT; + upb_symtab *c = upb_symtab_new(); upb_strptr fds = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE); if(upb_string_isnull(fds)) { fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ".\n"); @@ -209,7 +209,7 @@ int main(int argc, char *argv[]) upb_string_unref(fds); upb_strptr proto_name = upb_strdupc(MESSAGE_NAME); - struct upb_msgdef *def = upb_downcast_msgdef(upb_symtab_lookup(c, proto_name)); + upb_msgdef *def = upb_downcast_msgdef(upb_symtab_lookup(c, proto_name)); if(!def) { fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n", UPB_STRARG(proto_name)); diff --git a/tests/tests.c b/tests/tests.c index 03026a6..f96b5a4 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -15,7 +15,7 @@ int num_assertions = 0; static void test_get_v_uint64_t() { #define TEST(name, bytes, val) {\ - struct upb_status status = UPB_STATUS_INIT; \ + upb_status status = UPB_STATUS_INIT; \ const uint8_t name[] = bytes; \ const uint8_t *name ## _buf = name; \ uint64_t name ## _val = 0; \ @@ -45,7 +45,7 @@ static void test_get_v_uint64_t() uint8_t twelvebyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x01}; uint64_t twelvebyte_val = 0; - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; /* A varint that terminates before hitting the end of the provided buffer, * but in too many bytes (11 instead of 10). */ upb_get_v_uint64_t(twelvebyte, twelvebyte + 12, &twelvebyte_val, &status); @@ -79,7 +79,7 @@ static void test_get_v_uint64_t() static void test_get_v_uint32_t() { #define TEST(name, bytes, val) {\ - struct upb_status status = UPB_STATUS_INIT; \ + upb_status status = UPB_STATUS_INIT; \ const uint8_t name[] = bytes; \ const uint8_t *name ## _buf = name; \ uint32_t name ## _val = 0; \ @@ -110,7 +110,7 @@ static void test_get_v_uint32_t() uint8_t twelvebyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x01}; uint32_t twelvebyte_val = 0; - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; /* A varint that terminates before hitting the end of the provided buffer, * but in too many bytes (11 instead of 10). */ upb_get_v_uint32_t(twelvebyte, twelvebyte + 12, &twelvebyte_val, &status); @@ -144,7 +144,7 @@ static void test_get_v_uint32_t() static void test_skip_v_uint64_t() { #define TEST(name, bytes) {\ - struct upb_status status = UPB_STATUS_INIT; \ + upb_status status = UPB_STATUS_INIT; \ const uint8_t name[] = bytes; \ const uint8_t *name ## _buf = name; \ name ## _buf = upb_skip_v_uint64_t(name ## _buf, name + sizeof(name), &status); \ @@ -171,7 +171,7 @@ static void test_skip_v_uint64_t() #undef TEST uint8_t twelvebyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x01}; - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; /* A varint that terminates before hitting the end of the provided buffer, * but in too many bytes (11 instead of 10). */ upb_skip_v_uint64_t(twelvebyte, twelvebyte + 12, &status); @@ -205,7 +205,7 @@ static void test_skip_v_uint64_t() static void test_get_f_uint32_t() { #define TEST(name, bytes, val) {\ - struct upb_status status = UPB_STATUS_INIT; \ + upb_status status = UPB_STATUS_INIT; \ const uint8_t name[] = bytes; \ const uint8_t *name ## _buf = name; \ uint32_t name ## _val = 0; \ @@ -220,7 +220,7 @@ static void test_get_f_uint32_t() uint8_t threeb[] = {0x00, 0x00, 0x00}; uint32_t threeb_val; - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; upb_get_f_uint32_t(threeb, threeb + sizeof(threeb), &threeb_val, &status); ASSERT(status.code == UPB_STATUS_NEED_MORE_DATA); @@ -228,14 +228,14 @@ static void test_get_f_uint32_t() } static void test_upb_symtab() { - struct upb_symtab *s = upb_symtab_new(); + upb_symtab *s = upb_symtab_new(); ASSERT(s); upb_strptr descriptor = upb_strreadfile("tests/test.proto.pb"); if(upb_string_isnull(descriptor)) { fprintf(stderr, "Couldn't read input file tests/test.proto.pb\n"); exit(1); } - struct upb_status status = UPB_STATUS_INIT; + upb_status status = UPB_STATUS_INIT; upb_symtab_add_desc(s, descriptor, &status); ASSERT(upb_ok(&status)); upb_string_unref(descriptor); @@ -243,14 +243,14 @@ static void test_upb_symtab() { // Test cycle detection by making a cyclic def's main refcount go to zero // and then be incremented to one again. upb_strptr symname = upb_strdupc("A"); - struct upb_def *def = upb_symtab_lookup(s, symname); + upb_def *def = upb_symtab_lookup(s, symname); upb_string_unref(symname); ASSERT(def); upb_symtab_unref(s); - struct upb_msgdef *m = upb_downcast_msgdef(def); - struct upb_fielddef *f = &m->fields[0]; + upb_msgdef *m = upb_downcast_msgdef(def); + upb_fielddef *f = &m->fields[0]; ASSERT(upb_hasdef(f)); - struct upb_def *def2 = f->def; + upb_def *def2 = f->def; ASSERT(upb_downcast_msgdef(def2)); upb_def_ref(def2); upb_def_unref(def); -- cgit v1.2.3