- r1 = r2 = v1 = v2 = 1234;
- TRY {
- r2 = 5678;
- v2 = 5678;
- THROW0(unknown_error, 0, "toto");
- } CATCH(ex) {
- xbt_test_add0("variable preservation");
- if (r1 != 1234)
- xbt_test_fail1("r1=%d (!= 1234)", r1);
- if (v1 != 1234)
- xbt_test_fail1("v1=%d (!= 1234)", v1);
- /* r2 is allowed to be destroyed because not volatile */
- if (v2 != 5678)
- xbt_test_fail1("v2=%d (!= 5678)", v2);
- xbt_ex_free(ex);
- }
+ r1 = r2 = v1 = v2 = 1234;
+ TRY {
+ r2 = 5678;
+ v2 = 5678;
+ THROWF(unknown_error, 0, "toto");
+ } CATCH(ex) {
+ xbt_test_add("variable preservation");
+ if (r1 != 1234)
+ xbt_test_fail("r1=%d (!= 1234)", r1);
+ if (v1 != 1234)
+ xbt_test_fail("v1=%d (!= 1234)", v1);
+ /* r2 is allowed to be destroyed because not volatile */
+ if (v2 != 5678)
+ xbt_test_fail("v2=%d (!= 5678)", v2);
+ xbt_ex_free(ex);
+ }
+}
+
+XBT_TEST_UNIT("cleanup", test_cleanup, "cleanup handling")
+{
+ xbt_ex_t ex;
+ volatile int v1;
+ int c;
+
+ xbt_test_add("cleanup handling");
+
+ v1 = 1234;
+ c = 0;
+ TRY {
+ v1 = 5678;
+ THROWF(1, 2, "blah");
+ } TRY_CLEANUP {
+ if (v1 != 5678)
+ xbt_test_fail("v1 = %d (!= 5678)", v1);
+ c = 1;
+ }
+ CATCH(ex) {
+ if (v1 != 5678)
+ xbt_test_fail("v1 = %d (!= 5678)", v1);
+ if (!(ex.category == 1 && ex.value == 2 && !strcmp(ex.msg, "blah")))
+ xbt_test_fail("unexpected exception contents");
+ xbt_ex_free(ex);
+ }
+ if (!c)
+ xbt_test_fail("xbt_ex_free not executed");