1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
6 /*******************************/
7 /* GENERATED FILE, DO NOT EDIT */
8 /*******************************/
14 XBT_TEST_UNIT("controlflow",test_controlflow, "basic nested control flow") {
18 xbt_test_add0("basic nested control flow");
22 xbt_test_fail1("M1: n=%d (!= 1)", n);
26 xbt_test_fail1("M2: n=%d (!= 2)", n);
28 THROW0(unknown_error,0,"something");
31 xbt_test_fail1("M3: n=%d (!= 3)", n);
38 xbt_test_fail1("M2: n=%d (!= 5)", n);
40 THROW0(unknown_error,0,"something");
43 xbt_test_fail1("M3: n=%d (!= 6)", n);
48 xbt_test_fail1("MX: n=%d (shouldn't reach this point)", n);
52 xbt_test_fail1("M4: n=%d (!= 7)", n);
57 xbt_test_fail1("M5: n=%d (!= 8)", n);
60 XBT_TEST_UNIT("value",test_value,"exception value passing") {
64 THROW0(unknown_error, 2, "toto");
66 xbt_test_add0("exception value passing");
67 if (ex.category != unknown_error)
68 xbt_test_fail1("category=%d (!= 1)", ex.category);
70 xbt_test_fail1("value=%d (!= 2)", ex.value);
71 if (strcmp(ex.msg,"toto"))
72 xbt_test_fail1("message=%s (!= toto)", ex.msg);
77 XBT_TEST_UNIT("variables",test_variables,"variable value preservation") {
82 r1 = r2 = v1 = v2 = 1234;
86 THROW0(unknown_error, 0, "toto");
88 xbt_test_add0("variable preservation");
90 xbt_test_fail1("r1=%d (!= 1234)", r1);
92 xbt_test_fail1("v1=%d (!= 1234)", v1);
93 /* r2 is allowed to be destroyed because not volatile */
95 xbt_test_fail1("v2=%d (!= 5678)", v2);
100 XBT_TEST_UNIT("cleanup",test_cleanup,"cleanup handling") {
105 xbt_test_add0("cleanup handling");
111 THROW0(1, 2, "blah");
114 xbt_test_fail1("v1 = %d (!= 5678)", v1);
118 xbt_test_fail1("v1 = %d (!= 5678)", v1);
119 if (!(ex.category == 1 && ex.value == 2 && !strcmp(ex.msg,"blah")))
120 xbt_test_fail0("unexpected exception contents");
124 xbt_test_fail0("xbt_ex_free not executed");
129 * The following is the example included in the documentation. It's a good
130 * idea to check its syntax even if we don't try to run it.
131 * And actually, it allows to put comments in the code despite doxygen.
133 static char *mallocex(int size) {
136 #define SMALLAMOUNT 10
137 #define TOOBIG 100000000
139 #if 0 /* this contains syntax errors, actually */
140 static void bad_example(void) {
141 struct {char*first;} *globalcontext;
146 char *cp1, *cp2, *cp3;
148 cp1 = mallocex(SMALLAMOUNT);
149 globalcontext->first = cp1;
150 cp2 = mallocex(TOOBIG);
151 cp3 = mallocex(SMALLAMOUNT);
155 if (cp3 != NULL) free(cp3);
156 if (cp2 != NULL) free(cp2);
157 if (cp1 != NULL) free(cp1);
159 printf("cp3=%s", cp3);
162 /* end_of_bad_example */
165 typedef struct {char *first;} global_context_t;
167 static void good_example(void) {
168 global_context_t *global_context=malloc(sizeof(global_context_t));
173 char * volatile /*03*/ cp1 = NULL /*02*/;
174 char * volatile /*03*/ cp2 = NULL /*02*/;
175 char * volatile /*03*/ cp3 = NULL /*02*/;
177 cp1 = mallocex(SMALLAMOUNT);
178 global_context->first = cp1;
179 cp1 = NULL /*05 give away*/;
180 cp2 = mallocex(TOOBIG);
181 cp3 = mallocex(SMALLAMOUNT);
185 printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3);
190 /*05 cp1 was given away */
192 /*05 global context untouched */
196 /* end_of_good_example */
198 /*******************************/
199 /* GENERATED FILE, DO NOT EDIT */
200 /*******************************/