summaryrefslogtreecommitdiff
path: root/tests/test_def.c
blob: 5be06729d325ad7f5e1929fde42f68e96bfc0b44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#undef NDEBUG  /* ensure tests always assert. */
#include "upb_def.h"
#include <stdlib.h>

int main() {
  upb_symtab *s = upb_symtab_new();
  upb_symtab_add_descriptorproto(s);

  int count;
  upb_def **defs = upb_symtab_getdefs(s, &count, UPB_DEF_ANY);
  for (int i = 0; i < count; i++) {
    printf("Def with name: " UPB_STRFMT "\n", UPB_STRARG(defs[i]->fqname));
    upb_def_unref(defs[i]);
  }
  free(defs);

  printf("Size: %zd\n", sizeof(upb_ntof_ent));

  upb_string *str = upb_strdupc("google.protobuf.FileDescriptorSet");
  upb_def *fds = upb_symtab_lookup(s, str);
  assert(fds != NULL);
  assert(upb_dyncast_msgdef(fds) != NULL);
  upb_def_unref(fds);
  upb_string_unref(str);
  upb_symtab_unref(s);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback