1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
16 XBT_TEST_UNIT("controlflow",test_controlflow, "basic nested control flow") {
20 xbt_test_add0("basic nested control flow");
24 xbt_test_fail1("M1: n=%d (!= 1)", n);
28 xbt_test_fail1("M2: n=%d (!= 2)", n);
30 THROW0(unknown_error,0,"something");
33 xbt_test_fail1("M3: n=%d (!= 3)", n);
40 xbt_test_fail1("M2: n=%d (!= 5)", n);
42 THROW0(unknown_error,0,"something");
45 xbt_test_fail1("M3: n=%d (!= 6)", n);
50 xbt_test_fail1("MX: n=%d (shouldn't reach this point)", n);
54 xbt_test_fail1("M4: n=%d (!= 7)", n);
59 xbt_test_fail1("M5: n=%d (!= 8)", n);
62 XBT_TEST_UNIT("value",test_value,"exception value passing") {
66 THROW0(unknown_error, 2, "toto");
68 xbt_test_add0("exception value passing");
69 if (ex.category != unknown_error)
70 xbt_test_fail1("category=%d (!= 1)", ex.category);
72 xbt_test_fail1("value=%d (!= 2)", ex.value);
73 if (strcmp(ex.msg,"toto"))
74 xbt_test_fail1("message=%s (!= toto)", ex.msg);
79 XBT_TEST_UNIT("variables",test_variables,"variable value preservation") {
84 r1 = r2 = v1 = v2 = 1234;
88 THROW0(unknown_error, 0, "toto");
90 xbt_test_add0("variable preservation");
92 xbt_test_fail1("r1=%d (!= 1234)", r1);
94 xbt_test_fail1("v1=%d (!= 1234)", v1);
95 /* r2 is allowed to be destroyed because not volatile */
97 xbt_test_fail1("v2=%d (!= 5678)", v2);
102 XBT_TEST_UNIT("cleanup",test_cleanup,"cleanup handling") {
107 xbt_test_add0("cleanup handling");
113 THROW0(1, 2, "blah");
116 xbt_test_fail1("v1 = %d (!= 5678)", v1);
120 xbt_test_fail1("v1 = %d (!= 5678)", v1);
121 if (!(ex.category == 1 && ex.value == 2 && !strcmp(ex.msg,"blah")))
122 xbt_test_fail0("unexpected exception contents");
126 xbt_test_fail0("xbt_ex_free not executed");
131 * The following is the example included in the documentation. It's a good
132 * idea to check its syntax even if we don't try to run it.
133 * And actually, it allows to put comments in the code despite doxygen.
135 static char *mallocex(int size) {
138 #define SMALLAMOUNT 10
139 #define TOOBIG 100000000
141 #if 0 /* this contains syntax errors, actually */
142 static void bad_example(void) {
143 struct {char*first;} *globalcontext;
148 char *cp1, *cp2, *cp3;
150 cp1 = mallocex(SMALLAMOUNT);
151 globalcontext->first = cp1;
152 cp2 = mallocex(TOOBIG);
153 cp3 = mallocex(SMALLAMOUNT);
157 if (cp3 != NULL) free(cp3);
158 if (cp2 != NULL) free(cp2);
159 if (cp1 != NULL) free(cp1);
161 printf("cp3=%s", cp3);
164 /* end_of_bad_example */
167 typedef struct {char *first;} global_context_t;
169 static void good_example(void) {
170 global_context_t *global_context=malloc(sizeof(global_context_t));
175 char * volatile /*03*/ cp1 = NULL /*02*/;
176 char * volatile /*03*/ cp2 = NULL /*02*/;
177 char * volatile /*03*/ cp3 = NULL /*02*/;
179 cp1 = mallocex(SMALLAMOUNT);
180 global_context->first = cp1;
181 cp1 = NULL /*05 give away*/;
182 cp2 = mallocex(TOOBIG);
183 cp3 = mallocex(SMALLAMOUNT);
187 printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3);
192 /*05 cp1 was given away */
194 /*05 global context untouched */
198 /* end_of_good_example */
200 /*******************************/
201 /* GENERATED FILE, DO NOT EDIT */
202 /*******************************/