OSSP CVS Repository

ossp - Difference in ossp-pkg/ex/ex_test.c versions 1.8 and 1.9
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/ex/ex_test.c 1.8 -> 1.9

--- ex_test.c    2002/01/30 10:40:07     1.8
+++ ex_test.c    2002/03/07 21:30:10     1.9
@@ -111,6 +111,44 @@
     }
 }
 
+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 (ex_deferring)
+        ts_test_fail(TS_CTX, "unexpected deferring scope");
+    ex_try {
+        ex_defer {
+            if (!ex_deferring)
+                ts_test_fail(TS_CTX, "unexpected non-deferring scope");
+            ex_defer {
+                i1 = 1;
+                ex_throw(0, 0, 4711);
+                i2 = 2;
+                ex_throw(0, 0, 0);
+                i3 = 3;
+                ex_throw(0, 0, 0);
+            }
+            ex_throw(0, 0, 0);
+        }
+        ts_test_fail(TS_CTX, "unexpected not occurred deferred throwing");
+    }
+    ex_catch (ex) {
+        if ((long)ex.ex_value != (long)4711)
+            ts_test_fail(TS_CTX, "caught exception with value %d, expected 4711", (long)ex.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;
@@ -178,6 +216,7 @@
     ts_suite_test(ts, test_controlflow, "basic nested control flow");
     ts_suite_test(ts, test_value,       "exception value passing");
     ts_suite_test(ts, test_variables,   "variable value preservation");
+    ts_suite_test(ts, test_defer,       "exception deferring");
     ts_suite_test(ts, test_shield,      "exception shielding");
     ts_suite_test(ts, test_cleanup,     "cleanup handling");
     n = ts_suite_run(ts);

CVSTrac 2.0.1