-TS_TEST(test_defer)
-{
- ex_t ex;
- volatile int i1 = 0;
- volatile int i2 = 0;
- volatile int i3 = 0;
-
- ts_test_check(TS_CTX, "exception deferring");
- if (IS_DEFERRED)
- ts_test_fail(TS_CTX, "unexpected deferring scope");
- TRY {
- DEFER {
- if (!IS_DEFERRED)
- ts_test_fail(TS_CTX, "unexpected non-deferring scope");
- DEFER {
- i1 = 1;
- THROW(4711, 0, NULL);
- i2 = 2;
- THROW(0, 0, NULL);
- i3 = 3;
- THROW(0, 0, NULL);
- }
- THROW(0, 0, 0);
- }
- ts_test_fail(TS_CTX, "unexpected not occurred deferred throwing");
- }
- CATCH(ex) {
- if (ex.category != 4711)
- ts_test_fail(TS_CTX, "caught exception with value %d, expected 4711", ex.value);
- }
- if (i1 != 1)
- ts_test_fail(TS_CTX, "v.i1 not set (expected 1, got %d)", i1);
- if (i2 != 2)
- ts_test_fail(TS_CTX, "v.i2 not set (expected 2, got %d)", i2);
- if (i3 != 3)
- ts_test_fail(TS_CTX, "v.i3 not set (expected 3, got %d)", i3);
-}
-
-TS_TEST(test_shield)
-{
- ex_t ex;
-
- ts_test_check(TS_CTX, "exception shielding");
- if (IS_SHIELDED)
- ts_test_fail(TS_CTX, "unexpected shielding scope");
- if (IS_CATCHED)
- ts_test_fail(TS_CTX, "unexpected catching scope");
- TRY {
- SHIELD {
- if (!IS_SHIELDED)
- ts_test_fail(TS_CTX, "unexpected non-shielding scope");
- THROW(0, 0, 0);
- }
- if (IS_SHIELDED)
- ts_test_fail(TS_CTX, "unexpected shielding scope");
- if (!IS_CATCHED)
- ts_test_fail(TS_CTX, "unexpected non-catching scope");
- } CATCH(ex) {
- ts_test_fail(TS_CTX, "unexpected exception catched");
- if (IS_CATCHED)
- ts_test_fail(TS_CTX, "unexpected catching scope");
- }
- if (IS_CATCHED)
- ts_test_fail(TS_CTX, "unexpected catching scope");
-}
-