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 | c50df9dc7397029903360e215e6763ca57d9a545 (patch) | |
tree | 52486bc570028341fa4760b748a969103c3c7f9b | |
parent | 5d869cdffd2aad63209156935ea01c82fd7f7a69 (diff) | |
download | libdom-c50df9dc7397029903360e215e6763ca57d9a545.tar.gz libdom-c50df9dc7397029903360e215e6763ca57d9a545.tar.bz2 |
Implement #defines for try/catch
svn path=/trunk/dom/; revision=3565
-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. */ |