From 621c0cdcb5efc4f7c2382031becded018ef0b62b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 4 Sep 2011 19:29:36 -0700 Subject: Const invasion: large parts of upb made const-correct. --- tests/test_cpp.cc | 2 +- tests/test_decoder.c | 6 +++--- tests/test_def.c | 2 +- tests/test_vs_proto2.cc | 14 +++++++------- tests/tests.c | 20 ++++++++------------ 5 files changed, 20 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index ac5a3be..35526fb 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -10,7 +10,7 @@ static void TestSymbolTable() { std::cerr << "Couldn't load descriptor: " << status; exit(1); } - upb::MessageDef *md = s->LookupMessage("A"); + const upb::MessageDef *md = s->LookupMessage("A"); assert(md); s->Unref(); diff --git a/tests/test_decoder.c b/tests/test_decoder.c index 3ad9c08..1994501 100644 --- a/tests/test_decoder.c +++ b/tests/test_decoder.c @@ -20,20 +20,20 @@ int main(int argc, char *argv[]) { } upb_status status = UPB_STATUS_INIT; - upb_read_descriptor(symtab, desc, desc_len, &status); + upb_load_descriptor_into_symtab(symtab, desc, desc_len, &status); if (!upb_ok(&status)) { fprintf(stderr, "Error parsing descriptor: %s", upb_status_getstr(&status)); return 1; } free((void*)desc); - upb_def *md = upb_symtab_lookup(symtab, argv[2]); + const upb_def *md = upb_symtab_lookup(symtab, argv[2]); if (!md) { fprintf(stderr, "Descriptor did not contain message: %s\n", argv[2]); return 1; } - upb_msgdef *m = upb_dyncast_msgdef(md); + const upb_msgdef *m = upb_dyncast_msgdef_const(md); if (!m) { fprintf(stderr, "Def was not a msgdef.\n"); return 1; diff --git a/tests/test_def.c b/tests/test_def.c index 1f014f6..3ca3064 100644 --- a/tests/test_def.c +++ b/tests/test_def.c @@ -8,7 +8,7 @@ int main() { // Will be empty atm since we haven't added anything to the symtab. int count; - upb_def **defs = upb_symtab_getdefs(s, &count, UPB_DEF_ANY); + const upb_def **defs = upb_symtab_getdefs(s, &count, UPB_DEF_ANY); for (int i = 0; i < count; i++) { upb_def_unref(defs[i]); } diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index a313aa5..22aa2e2 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -21,7 +21,7 @@ size_t string_size; void compare(const google::protobuf::Message& proto2_msg, - void *upb_msg, upb_msgdef *upb_md); + void *upb_msg, const upb_msgdef *upb_md); void compare_arrays(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, @@ -143,7 +143,7 @@ void compare_values(const google::protobuf::Reflection *r, } void compare(const google::protobuf::Message& proto2_msg, - void *upb_msg, upb_msgdef *upb_md) + void *upb_msg, const upb_msgdef *upb_md) { const google::protobuf::Reflection *r = proto2_msg.GetReflection(); const google::protobuf::Descriptor *d = proto2_msg.GetDescriptor(); @@ -179,7 +179,7 @@ void compare(const google::protobuf::Message& proto2_msg, } void parse_and_compare(MESSAGE_CIDENT *proto2_msg, - void *upb_msg, upb_msgdef *upb_md, + void *upb_msg, const upb_msgdef *upb_md, const char *str, size_t len) { // Parse to both proto2 and upb. @@ -223,7 +223,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ".\n"); return 1; } - upb_read_descriptor(symtab, fds, fds_len, &status); + upb_load_descriptor_into_symtab(symtab, fds, fds_len, &status); if(!upb_ok(&status)) { fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ": %s", upb_status_getstr(&status)); @@ -231,9 +231,9 @@ int main(int argc, char *argv[]) } free((void*)fds); - upb_def *def = upb_symtab_lookup(symtab, MESSAGE_NAME); - upb_msgdef *msgdef; - if(!def || !(msgdef = upb_dyncast_msgdef(def))) { + const upb_def *def = upb_symtab_lookup(symtab, MESSAGE_NAME); + const upb_msgdef *msgdef; + if(!def || !(msgdef = upb_dyncast_msgdef_const(def))) { fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME); return 1; } diff --git a/tests/tests.c b/tests/tests.c index 64e3ef3..99e13cb 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -1,4 +1,5 @@ + #include #include #include @@ -11,17 +12,12 @@ static upb_symtab *load_test_proto() { upb_symtab *s = upb_symtab_new(); ASSERT(s); - size_t len; - char *descriptor = upb_readfile("tests/test.proto.pb", &len); - if(!descriptor) { - fprintf(stderr, "Couldn't read input file tests/test.proto.pb\n"); + upb_status status = UPB_STATUS_INIT; + if (!upb_load_descriptor_file_into_symtab(s, "tests/test.proto.pb", &status)) { + fprintf(stderr, "Error loading descriptor file: %s\n", upb_status_getstr(&status)); exit(1); } - upb_status status = UPB_STATUS_INIT; - upb_read_descriptor(s, descriptor, len, &status); - ASSERT(upb_ok(&status)); upb_status_uninit(&status); - free(descriptor); return s; } @@ -34,12 +30,12 @@ static upb_flow_t upb_test_onvalue(void *closure, upb_value fval, upb_value val) static void test_upb_jit() { upb_symtab *s = load_test_proto(); - upb_def *def = upb_symtab_lookup(s, "SimplePrimitives"); + const upb_def *def = upb_symtab_lookup(s, "SimplePrimitives"); ASSERT(def); upb_handlers *h = upb_handlers_new(); upb_handlerset hset = {NULL, NULL, &upb_test_onvalue, NULL, NULL, NULL, NULL}; - upb_handlers_reghandlerset(h, upb_downcast_msgdef(def), &hset); + upb_handlers_reghandlerset(h, upb_downcast_msgdef_const(def), &hset); upb_decoder d; upb_decoder_init(&d, h); upb_decoder_uninit(&d); @@ -53,10 +49,10 @@ 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_def *def = upb_symtab_lookup(s, "A"); + const upb_def *def = upb_symtab_lookup(s, "A"); ASSERT(def); upb_symtab_unref(s); - upb_msgdef *m = upb_downcast_msgdef(def); + const upb_msgdef *m = upb_downcast_msgdef_const(def); upb_msg_iter i = upb_msg_begin(m); upb_fielddef *f = upb_msg_iter_field(i); ASSERT(upb_hassubdef(f)); -- cgit v1.2.3