diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.proto | 10 | ||||
-rw-r--r-- | tests/test_varint.c | 19 | ||||
-rw-r--r-- | tests/tests.c | 35 |
3 files changed, 54 insertions, 10 deletions
diff --git a/tests/test.proto b/tests/test.proto index b51bd6b..f3dde24 100644 --- a/tests/test.proto +++ b/tests/test.proto @@ -29,3 +29,13 @@ message D { optional A a = 1; optional D d = 2; } + +// A proto with a bunch of simple primitives. +message SimplePrimitives { + optional fixed64 a = 1; + optional fixed32 b = 2; + optional double c = 3; + optional float d = 5; + //optional sint64 e = 6; + //optional sint32 f = 7; +} diff --git a/tests/test_varint.c b/tests/test_varint.c index efe9418..f0a8993 100644 --- a/tests/test_varint.c +++ b/tests/test_varint.c @@ -33,7 +33,7 @@ static void test_varint_decoder(upb_decoderet (*decoder)(const char*)) { const char *twelvebyte_buf = twelvebyte; // A varint that terminates before hitting the end of the provided buffer, // but in too many bytes (11 instead of 10). - upb_decoderet r = upb_decode_varint_fast(twelvebyte_buf); + upb_decoderet r = decoder(twelvebyte_buf); ASSERT(r.p == NULL); } @@ -41,23 +41,26 @@ static void test_varint_decoder(upb_decoderet (*decoder)(const char*)) { #define TEST_VARINT_DECODER(decoder) \ /* Create non-inline versions for convenient inspection of assembly language \ * output. */ \ - upb_decoderet _upb_decode_varint_ ## decoder(const char *p) { \ - return upb_decode_varint_ ## decoder(p); \ + upb_decoderet _upb_vdecode_ ## decoder(const char *p) { \ + return upb_vdecode_ ## decoder(p); \ } \ void test_ ## decoder() { \ - test_varint_decoder(&_upb_decode_varint_ ## decoder); \ + printf("Testing varint decoder: " #decoder "..."); \ + fflush(stdout); \ + test_varint_decoder(&_upb_vdecode_ ## decoder); \ + printf("ok.\n"); \ } \ TEST_VARINT_DECODER(branch32); TEST_VARINT_DECODER(branch64); -TEST_VARINT_DECODER(nobranch1); -TEST_VARINT_DECODER(nobranch2); +TEST_VARINT_DECODER(check2_wright); +TEST_VARINT_DECODER(check2_massimino); int main() { test_branch32(); test_branch64(); - test_nobranch1(); - test_nobranch2(); + test_check2_wright(); + test_check2_massimino(); } #if 0 diff --git a/tests/tests.c b/tests/tests.c index a04b1da..2fe8b8d 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -5,8 +5,10 @@ #include "upb_def.h" #include "upb_glue.h" #include "upb_test.h" +#include "upb_stream.h" +#include "upb_decoder.h" -static void test_upb_symtab() { +static upb_symtab *load_test_proto() { upb_symtab *s = upb_symtab_new(); ASSERT(s); upb_string *descriptor = upb_strreadfile("tests/test.proto.pb"); @@ -16,10 +18,38 @@ static void test_upb_symtab() { } upb_status status = UPB_STATUS_INIT; upb_parsedesc(s, descriptor, &status); - upb_printerr(&status); ASSERT(upb_ok(&status)); upb_status_uninit(&status); upb_string_unref(descriptor); + return s; +} + +static upb_flow_t upb_test_onvalue(void *closure, upb_value fval, upb_value val) { + (void)closure; + (void)fval; + (void)val; + return UPB_CONTINUE; +} + +static void test_upb_jit() { + upb_symtab *s = load_test_proto(); + upb_string *symname = upb_strdupc("SimplePrimitives"); + upb_def *def = upb_symtab_lookup(s, symname); + upb_string_unref(symname); + ASSERT(def); + + upb_handlers h; + upb_handlers_init(&h, upb_downcast_msgdef(def)); + upb_register_all(&h, NULL, NULL, &upb_test_onvalue, NULL, NULL, NULL); + upb_decoder d; + upb_decoder_init(&d, &h); + upb_decoder_uninit(&d); + upb_symtab_unref(s); + upb_def_unref(def); +} + +static void test_upb_symtab() { + upb_symtab *s = load_test_proto(); // Test cycle detection by making a cyclic def's main refcount go to zero // and then be incremented to one again. @@ -53,6 +83,7 @@ int main() } while (0) TEST(test_upb_symtab); + TEST(test_upb_jit); printf("All tests passed (%d assertions).\n", num_assertions); return 0; } |