Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
18.setjmp.cpp
Go to the documentation of this file.
1
29#include <setjmp.h>
30
31#include <rw_driver.h>
32
33
35jmp_buf env;
36
37void test_longjmp (int arg)
38{
39 longjmp (env, arg);
40
41 rw_assert (0, 0, __LINE__,
42 "call to longjmp(..., %d) returned", arg);
43}
44
45
47static int
48run_test (int, char**)
49{
50#ifdef longjmp
51
52 // longjmp must not be #defined as a macro
53 rw_assert (0, 0, __LINE__, "longjmp #defined as a macro");
54
55#endif // longjmp
56
57#ifdef jmp_buf
58
59 //jmp_buf must not be #defined as a macro
60 rw_assert (0, 0, __LINE__, "jmp_buf #defined as a macro");
61
62#endif // jmp_buf
63
64#ifndef setjmp
65
66 //setjmp must be #defined as a macro
67 rw_assert (0, 0, __LINE__, "macro setjmp not #defined");
68
69#endif // setjmp
70
71 // verify that setjmp works
72
73 // using volatile to work around a gcc optimizer bug:
74 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34024
75 volatile int arg = 1;
76
77 int result;
78
79 result = setjmp (env);
80
81 if (0 == result) {
82
84
85 rw_assert (0, 0, __LINE__,
86 "call to longjmp(..., %d) returned", arg);
87 }
88 else {
89 rw_assert (arg == result, 0, __LINE__,
90 "longjmp(..., %d) returned %d from setjmp()",
91 arg, result);
92
93 // repeat a couple more times
94 if (arg < 3)
95 test_longjmp (++arg);
96 }
97
98 return 0;
99}
100
101
103int main (int argc, char *argv[])
104{
105 return rw_test (argc, argv, __FILE__,
106 "support.runtime",
107 "header <setjmp.h>",
108 run_test,
109 "",
110 (void*)0);
111}
volatile int result
void test_longjmp(int arg)
Definition 18.setjmp.cpp:37
jmp_buf env
Definition 18.setjmp.cpp:35
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define setjmp
Definition _csetjmp.h:52
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
int arg
Definition locale.cpp:2806