Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
19.cerrno.cpp
Go to the documentation of this file.
1
29// include only <cerrno> here to prevent namespace pollution
30#include <cerrno>
31
32
34const char* const errors[] = {
35
36#ifndef errno
37 "errno",
38#endif // errno
39
40#ifndef EDOM
41 "EDOM not defined",
42#elif EDOM <= 0
43 "EDOM not positive",
44#endif // EDOM
45
46#ifndef EILSEQ
47 "EILSEQ", // lwg issue 288
48#elif EILSEQ <= 0
49 "EILSEQ not positive",
50#elif EILSEQ == EDOM
51 "EILSEQ not distinct from EDOM",
52#endif // EILSEQ
53
54#ifndef ERANGE
55 "ERANGE not defined",
56#elif ERANGE <= 0
57 "ERANGE not positive",
58#elif ERANGE == EDOM
59 "ERANGE not distinct from EDOM",
60#elif ERANGE == EILSEQ
61 "ERANGE not distinct from EILSEQ",
62#endif // ERANGE
63
64 0
65};
66
67
69// include all other headers here
70#include <rw_any.h> // for rw_any_t
71#include <rw_driver.h> // for rw_test(), ...
72
73
75template <class T> void set_errno_value (T, int) { /* empty */ }
76void set_errno_value (int &errno_ref, int val) { errno_ref = val; }
77
78
80static int
81errno_at_startup;
82
83static int
84run_test (int, char**)
85{
86 rw_info (0, 0, 0, "exercising the contents of the <cerrno> header");
87
88 for (unsigned i = 0; errors [i]; ++i) {
89 rw_assert (0 == errors [i], 0, 0,
90 "macro %s", errors [i]);
91 }
92
93 // get the type of errno
94 const char* const errno_type = rw_any_t (errno).type_name ();
95
96 // 7.5, p2 of C99: the type of errno must be int
97 rw_assert ( 'i' == errno_type [0]
98 && 'n' == errno_type [1]
99 && 't' == errno_type [2]
100 && '\0' == errno_type [3],
101 0, 0,
102 "the type of errno is int, got %s", errno_type);
103
104 // 7.5, p3 of C99: errno must be 0 at program startup
105 rw_assert (0 == errno_at_startup, 0, 0,
106 "errno == 0 at program startup, got %d", errno_at_startup);
107
108#ifndef EDOM
109# define EDOM 33 /* Solaris value */
110#endif // EDOM
111
112 // 7.5, p2 of C99: errno must be a modifiable lvalue
113 set_errno_value (errno, int (EDOM));
114
115 rw_assert (EDOM == errno, 0, 0,
116 "errno == %d (%{#*m}, got %d (%{#m}) "
117 "(errno not a modifiable lvalue?)",
118 EDOM, EDOM, errno, errno);
119
120#ifndef ERANGE
121# define ERANGE 34 /* Solaris value */
122#endif // ERANGE
123
124 set_errno_value (errno, int (ERANGE));
125
126 rw_assert (ERANGE == errno, 0, 0,
127 "errno == %d (%{#*m}, got %d (%{#m}) "
128 "(errno not a modifiable lvalue?)",
129 ERANGE, ERANGE, errno, errno);
130
131#ifndef EILSEQ
132# define EILSEQ 84 /* Solaris value */
133#endif // EILSEQ
134
135 set_errno_value (errno, int (EILSEQ));
136
137 rw_assert (EILSEQ == errno, 0, 0,
138 "errno == %d (%{#*m}, got %d (%{#m}) "
139 "(errno not a modifiable lvalue?)",
140 EILSEQ, EILSEQ, errno, errno);
141
142 return 0;
143}
144
145
147int main (int argc, char *argv[])
148{
149 errno_at_startup = errno;
150
151 return rw_test (argc, argv, __FILE__,
152 "lib.errno",
153 0 /* no comment */, run_test,
154 0 /* no command line options */, 0);
155}
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define val
Definition 17.names.cpp:570
const char *const errors[]
Definition 19.cerrno.cpp:34
void set_errno_value(T, int)
Definition 19.cerrno.cpp:75
#define EDOM
#define ERANGE
#define EILSEQ
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
const char * type_name() const
Definition any.cpp:310
_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_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630