40static int global[] = { 0, 0 };
45 static std::jmp_buf jmp_env;
51 std::longjmp (jmp_env, 1);
55 static int c_comp (
const void *
x,
const void *
y)
57#ifndef _RWSTD_NO_EXCEPTIONS
60 if (
x >= global &&
x < global +
sizeof global /
sizeof *global)
72 static int cxx_comp (
const void *
x,
const void *
y)
74#ifndef _RWSTD_NO_EXCEPTIONS
77 if (
x >= global &&
x < global +
sizeof global /
sizeof *global)
101 std::qsort (xsrc,
nsrc,
sizeof *xsrc, cxx_comp);
103 std::qsort (xsrc,
nsrc,
sizeof *xsrc, c_comp);
107 "line %d: extern \"C%{?}++%{;}\" qsort (\"%s\", ...) ==> "
108 "\"%{X=*.*}\" not sorted",
109 __LINE__, cxx, src,
int (
sizeof (*xsrc)),
int (
nsrc), -1, xsrc);
118test_qsort_exception (
int line,
123#ifndef _RWSTD_NO_EXCEPTIONS
127 std::signal (
SIGABRT, handle_ABRT);
129 bool success =
false;
131 if (0 ==
setjmp (jmp_env)) {
133 std::qsort (src,
nsrc,
sizeof *src, cxx_comp);
135 std::qsort (src,
nsrc,
sizeof *src, c_comp);
141 "line %d: extern \"C%{?}++%{;}\" qsort() aborted "
142 "on exception", __LINE__, cxx);
145 catch (
const void*
x) {
146 success =
x >= src &&
x < src +
nsrc;
152 "line %d: extern \"C%{?}++%{;}\" qsort() failed to propagate "
153 "exception", __LINE__, cxx);
170test_bsearch (
int line,
182 key.data_.val_ = key_val;
184 const void*
result = cxx ?
185 std::bsearch (&key, xsrc,
nsrc,
sizeof *xsrc, cxx_comp)
186 :
std::bsearch (&key, xsrc,
nsrc, sizeof *xsrc, c_comp);
190 bool success =
result == exp_res;
192 "line %d: extern \"C%{?}++%{;}\" bsearch (\"%s\", %#c, ...) "
193 "== %p, got %p, difference is %td elements",
194 __LINE__, cxx, src, key_val,
result, exp_res,
204test_bsearch_exception (
int line,
210#ifndef _RWSTD_NO_EXCEPTIONS
214 std::signal (
SIGABRT, handle_ABRT);
216 bool success =
false;
218 if (0 ==
setjmp (jmp_env)) {
220 std::bsearch (key, src,
nsrc,
sizeof *src, cxx_comp);
222 std::bsearch (key, src,
nsrc,
sizeof *src, c_comp);
228 "line %d: extern \"C%{?}++%{;}\" bsearch() aborted "
229 "on exception", __LINE__, cxx);
232 catch (
const void*
x) {
233 success =
x >= src &&
x < src +
nsrc;
239 "line %d: extern \"C%{?}++%{;}\" bsearch() failed to propagate "
240 "exception", __LINE__, cxx);
255static int rw_opt_no_c;
256static int rw_opt_no_cxx;
257static int rw_opt_no_bsearch;
258static int rw_opt_no_qsort;
259static int rw_opt_no_exceptions;
267 "extern \"C%{?}++%{;}\" qsort (void*, size_t, size_t, "
268 "int (*compar)(const void*, const void*))", cxx);
271 test_qsort (__LINE__, src, sizeof src - 1, cxx)
307 if (rw_opt_no_exceptions) {
308 rw_note (0, 0, 0,
"extern \"C%{?}++%{;}\" qsort() exceptions tests "
312 test_qsort_exception (__LINE__, global,
313 sizeof global /
sizeof *global, cxx);
320test_bsearch (
bool cxx)
323 "extern \"C%{?}++%{;}\" bsearch (const void*, const void*, "
324 "size_t, size_t, int (*compar)(const void*, const void*))",
327#define TEST(src, key, res) \
328 test_bsearch (__LINE__, src, sizeof src - 1, key, \
329 std::size_t (res), cxx)
339 TEST (
"bc",
'a', -1);
341 TEST (
"acegi",
'i', 4);
342 TEST (
"acegi",
'b', -1);
343 TEST (
"acegi",
'g', 3);
344 TEST (
"acegi",
'f', -1);
345 TEST (
"acegi",
'e', 2);
346 TEST (
"acegi",
'j', -1);
347 TEST (
"acegi",
'c', 1);
348 TEST (
"bdfhj",
'a', -1);
350 TEST (
"abcdefghij",
'a', 0);
351 TEST (
"abcdefghij",
'c', 2);
352 TEST (
"abcdefghij",
'f', 5);
353 TEST (
"abcdefghij",
'h', 7);
354 TEST (
"abcdefghij",
'j', 9);
358 if (rw_opt_no_exceptions) {
359 rw_note (0, 0, 0,
"extern \"C%{?}++%{;}\" bsearch() exceptions "
360 "tests disabled", cxx);
363 test_bsearch_exception (__LINE__, global,
364 sizeof global /
sizeof *global, global, cxx);
374 rw_note (0, 0, 0,
"qsort test disabled");
378 if (rw_opt_no_bsearch)
379 rw_note (0, 0, 0,
"bsearch test disabled");
390 rw_note (0, 0, 0,
"tests of extern \"C\" cfunctions disabled");
395 rw_note (0, 0, 0,
"tests of extern \"C++\" functions disabled");
404int main (
int argc,
char *argv[])
406 return rw_test (argc, argv, __FILE__,
419 &rw_opt_no_exceptions);
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_STATIC_CAST(T, x)
bool is_sorted_lt(InputIterator first, InputIterator last)
_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 *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
static UserClass from_char(char c)