Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
18.csetjmp.cpp
Go to the documentation of this file.
1
29#include <csetjmp>
30
31#include <rw_driver.h>
32
33
35std::jmp_buf env;
36
37void test_longjmp (int arg)
38{
39 std::longjmp (env, arg);
40
41 rw_assert (0, 0, __LINE__,
42 "call to std::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 // using volatile to work around a gcc optimizer bug:
73 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34024
74 volatile int arg = 1;
75 int result;
76
77 result = setjmp (env);
78
79 if (0 == result) {
80
82
83 rw_assert (0, 0, __LINE__,
84 "call to std::longjmp(..., %d) returned", arg);
85 }
86 else {
87 rw_assert (arg == result, 0, __LINE__,
88 "std::longjmp(..., %d) returned %d from setjmp()",
89 arg, result);
90
91 // repeat a couple more times
92 if (arg < 3)
93 test_longjmp (++arg);
94 }
95
96 return 0;
97}
98
99
101int main (int argc, char *argv[])
102{
103 return rw_test (argc, argv, __FILE__,
104 "support.runtime",
105 "header <csetjmp>",
106 run_test,
107 "",
108 (void*)0);
109}
void test_longjmp(int arg)
std::jmp_buf env
volatile int result
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