1 /* Copyright 2016-2017 Tobias Grosser
3 * Use of this software is governed by the MIT license
5 * Written by Tobias Grosser, Weststrasse 47, CH-8003, Zurich
15 #include <isl/options.h>
18 static void die_impl(const char *file
, int line
, const char *message
)
20 fprintf(stderr
, "Assertion failed in %s:%d %s\n", file
, line
, message
);
24 static void assert_impl(bool condition
, const char *file
, int line
,
30 return die_impl(file
, line
, message
);
33 #define die(msg) die_impl(__FILE__, __LINE__, msg)
34 #define assert(exp) assert_impl(exp, __FILE__, __LINE__, #exp)
36 #include "isl_test_cpp-generic.cc"
38 /* Test that isl_bool values are returned correctly.
40 * In particular, check the conversion to bool in case of true and false, and
41 * exception throwing in case of error.
43 static void test_return_bool(isl::ctx ctx
)
45 isl::set
empty(ctx
, "{ : false }");
46 isl::set
univ(ctx
, "{ : }");
49 bool b_true
= empty
.is_empty();
50 bool b_false
= univ
.is_empty();
54 die("no exception raised");
55 } catch (const isl::exception_invalid
&e
) {
64 /* Test that return values are handled correctly.
66 * Test that isl C++ objects, integers, boolean values, and strings are
69 static void test_return(isl::ctx ctx
)
73 test_return_bool(ctx
);
74 test_return_string(ctx
);
77 /* Test that foreach functions are modeled correctly.
79 * Verify that lambdas are correctly called as callback of a 'foreach'
80 * function and that variables captured by the lambda work correctly. Also
81 * check that the foreach function handles exceptions thrown from
82 * the lambda and that it propagates the exception.
84 static void test_foreach(isl::ctx ctx
)
86 isl::set
s(ctx
, "{ [0]; [1]; [2] }");
88 std::vector
<isl::basic_set
> basic_sets
;
90 auto add_to_vector
= [&] (isl::basic_set bs
) {
91 basic_sets
.push_back(bs
);
94 s
.foreach_basic_set(add_to_vector
);
96 assert(basic_sets
.size() == 3);
97 assert(isl::set(basic_sets
[0]).is_subset(s
));
98 assert(isl::set(basic_sets
[1]).is_subset(s
));
99 assert(isl::set(basic_sets
[2]).is_subset(s
));
100 assert(!basic_sets
[0].is_equal(basic_sets
[1]));
102 auto fail
= [&] (isl::basic_set bs
) {
108 s
.foreach_basic_set(fail
);
109 die("no exception raised");
110 } catch (char const *s
) {
116 /* Test that an exception is generated for an isl error and
117 * that the error message is captured by the exception.
118 * Also check that the exception can be copied and that copying
119 * does not throw any exceptions.
121 static void test_exception(isl::ctx ctx
)
123 isl::multi_union_pw_aff
mupa(ctx
, "[]");
126 static_assert(std::is_nothrow_copy_constructible
<isl::exception
>::value
,
127 "exceptions must be nothrow-copy-constructible");
128 static_assert(std::is_nothrow_assignable
<isl::exception
,
129 isl::exception
>::value
,
130 "exceptions must be nothrow-assignable");
133 auto umap
= isl::union_map::from(mupa
);
134 } catch (const isl::exception_unsupported
&error
) {
135 die("caught wrong exception");
136 } catch (const isl::exception
&error
) {
137 assert(strstr(error
.what(), "without explicit domain"));
140 assert(strstr(copy
.what(), "without explicit domain"));
143 /* Test the (unchecked) isl C++ interface
146 * - The isl C <-> C++ pointer interface
147 * - Object construction
148 * - Different parameter types
149 * - Different return types
150 * - Foreach functions
155 isl_ctx
*ctx
= isl_ctx_alloc();
157 isl_options_set_on_error(ctx
, ISL_ON_ERROR_ABORT
);
160 test_constructors(ctx
);
161 test_parameters(ctx
);