From 7175edb10a51e5931efd14cdb8cf62ce3463c85e Mon Sep 17 00:00:00 2001 From: Hunter Morris Date: Fri, 9 Sep 2011 21:46:41 +0100 Subject: Add failing unit test This might actually just bring to light my misuse of the upb_fielddef functions. The test assertions are fine, but an assertion in upb/upb.h fails: ./upb/upb.h:181: upb_value_getptr: Assertion `val.type == 33' failed. --- tests/tests.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/tests.c b/tests/tests.c index 99e13cb..178254f 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -67,6 +67,30 @@ static void test_upb_symtab() { upb_def_unref(def2); } +static void test_upb_two_fielddefs() { + upb_fielddef *f1 = upb_fielddef_new(); + upb_fielddef *f2 = upb_fielddef_new(); + + ASSERT(upb_fielddef_ismutable(f1)); + upb_fielddef_setname(f1, ""); + upb_fielddef_setnumber(f1, 1937); + upb_fielddef_settype(f1, UPB_TYPE(FIXED64)); + upb_fielddef_setlabel(f1, UPB_LABEL(REPEATED)); + upb_fielddef_settypename(f1, ""); + ASSERT(upb_fielddef_number(f1) == 1937); + + ASSERT(upb_fielddef_ismutable(f2)); + upb_fielddef_setname(f2, ""); + upb_fielddef_setnumber(f2, 1572); + upb_fielddef_settype(f2, UPB_TYPE(BYTES)); + upb_fielddef_setlabel(f2, UPB_LABEL(REPEATED)); + upb_fielddef_settypename(f2, ""); + ASSERT(upb_fielddef_number(f2) == 1572); + + upb_fielddef_unref(f1); + upb_fielddef_unref(f2); +} + int main() { #define TEST(func) do { \ @@ -78,6 +102,7 @@ int main() TEST(test_upb_symtab); TEST(test_upb_jit); + TEST(test_upb_two_fielddefs); printf("All tests passed (%d assertions).\n", num_assertions); return 0; } -- cgit v1.2.3