summaryrefslogtreecommitdiff
path: root/tests/test_handlers.c
blob: ad594652c6548e5a891ed2793c36f7c7beb19911 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2011 Google Inc.  See LICENSE for details.
 *
 */

#include "upb/handlers.h"
#include "upb/descriptor/descriptor.upb.h"
#include "upb_test.h"
#include <stdlib.h>
#include <string.h>

static bool startmsg(void *c, const void *hd) {
  UPB_UNUSED(c);
  UPB_UNUSED(hd);
  return true;
}

static void test_error() {
  const upb_symtab *s = upbdefs_google_protobuf_descriptor(&s);
  upb_handlers *h =
      upb_handlers_new(upbdefs_google_protobuf_DescriptorProto(s), &h);
  upb_symtab_unref(s, &s);

  // Attempt to set the same handler twice causes error.
  ASSERT(upb_ok(upb_handlers_status(h)));
  upb_handlers_setstartmsg(h, &startmsg, NULL);
  ASSERT(upb_ok(upb_handlers_status(h)));
  upb_handlers_setstartmsg(h, &startmsg, NULL);
  ASSERT(!upb_ok(upb_handlers_status(h)));
  ASSERT(!upb_handlers_freeze(&h, 1, NULL));

  // Clearing the error will let us proceed.
  upb_handlers_clearerr(h);
  ASSERT(upb_handlers_freeze(&h, 1, NULL));
  ASSERT(upb_handlers_isfrozen(h));

  upb_handlers_unref(h, &h);
}

int run_tests(int argc, char *argv[]) {
  UPB_UNUSED(argc);
  UPB_UNUSED(argv);
  test_error();
  return 0;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback