Skip to content

Commit

Permalink
Add failing unit test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hunter Morris committed Sep 9, 2011
1 parent aca8cef commit 7175edb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand All @@ -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;
}

0 comments on commit 7175edb

Please sign in to comment.