summaryrefslogtreecommitdiff
path: root/tests/test_handlers.c
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2013-05-28 13:44:50 -0700
committerJosh Haberman <jhaberman@gmail.com>2013-05-28 13:44:50 -0700
commitbada1e94f472e7507a97e7565369841b3d25c9b0 (patch)
tree1fe0882b497206db03e21eb87c975d5e400fe097 /tests/test_handlers.c
parentee3a3191cda5faae5dcc9cd1526292c57f2be343 (diff)
Merge from Google-internal development.
- Better error reporting for upb::Def setters. - error reporting for upb::Handlers setters. - made the start/endmsg handlers a little less special-cased.
Diffstat (limited to 'tests/test_handlers.c')
-rw-r--r--tests/test_handlers.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_handlers.c b/tests/test_handlers.c
new file mode 100644
index 0000000..fb0564a
--- /dev/null
+++ b/tests/test_handlers.c
@@ -0,0 +1,38 @@
+/*
+ * 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) { return true; }
+
+static void test_error() {
+ upb_handlers *h = upb_handlers_new(GOOGLE_PROTOBUF_DESCRIPTORPROTO, NULL, &h);
+
+ // Attempt to set the same handler twice causes error.
+ ASSERT(upb_ok(upb_handlers_status(h)));
+ upb_handlers_setstartmsg(h, &startmsg, NULL, NULL);
+ ASSERT(upb_ok(upb_handlers_status(h)));
+ upb_handlers_setstartmsg(h, &startmsg, NULL, 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[]) {
+ test_error();
+ return 0;
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback