diff options
author | James Shaw <jshaw@netsurf-browser.org> | 2007-09-22 12:46:12 +0000 |
---|---|---|
committer | James Shaw <jshaw@netsurf-browser.org> | 2007-09-22 12:46:12 +0000 |
commit | b692e101ea7e1aadaf140629b3202cb7624c6d86 (patch) | |
tree | 52486bc570028341fa4760b748a969103c3c7f9b /test/testutils.h | |
parent | 17975b688c0fdc69b23d63ac286b11ef61f295b4 (diff) | |
download | libdom-b692e101ea7e1aadaf140629b3202cb7624c6d86.tar.gz libdom-b692e101ea7e1aadaf140629b3202cb7624c6d86.tar.bz2 |
Implement #defines for try/catch
svn path=/trunk/dom/; revision=3565
Diffstat (limited to 'test/testutils.h')
-rw-r--r-- | test/testutils.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/testutils.h b/test/testutils.h index e3009af..6e07660 100644 --- a/test/testutils.h +++ b/test/testutils.h @@ -6,7 +6,9 @@ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> +#include <setjmp.h> +#include "exceptions.h" #include "utils.h" #include "xmlbinding.h" #include "xmlparser.h" @@ -15,6 +17,31 @@ #define UNUSED(x) ((x) = (x)) #endif +/* Usage: + TRY + THROW(DOM_NOT_FOUND_ERR); + THROW_IF_ERR(dom_document_get_doctype(...)); + CATCH(ex) + printf("exception: %d\n", ex); + ENDTRY +*/ +#define TRY __exvalue=setjmp(__exbuf); \ + if (__exvalue==0) { +#define CATCH(x) } else { \ + int x = __exvalue; +#define ENDTRY } +#define THROW(x) longjmp(__exbuf, x) + +#define THROW_IF_ERR(x) \ + do { \ + int err = x; \ + if (err != DOM_NO_ERR) \ + THROW(err); \ + } while (0) + +jmp_buf __exbuf; +int __exvalue; + /* Redefine assert, so we can simply use the standard assert mechanism * within testcases and exit with the right output for the testrunner * to do the right thing. */ |