isl_output.c: print_nested_tuple: rename "local_dim" argument to "local_space"
[isl.git] / isl_test_cpp-checked.cc
blob84bb01a953a36d316d8b1d11b5625ccf6e5b7a78
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
6 */
8 #include <vector>
9 #include <string>
10 #include <limits.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 #include <isl/options.h>
15 #include <isl/cpp-checked.h>
17 namespace isl { using namespace checked; }
19 static void assert_impl(bool condition, const char *file, int line,
20 const char *message)
22 if (condition)
23 return;
25 fprintf(stderr, "Assertion failed in %s:%d %s\n", file, line, message);
26 exit(EXIT_FAILURE);
29 static void assert_impl(isl::boolean condition, const char *file, int line,
30 const char *message)
32 assert_impl(bool(condition), file, line, message);
35 #define assert(exp) assert_impl(exp, __FILE__, __LINE__, #exp)
36 #define IS_TRUE(b) (b).is_true()
38 #include "isl_test_cpp-generic.cc"
40 /* Test that isl_bool values are returned correctly.
42 * We check in detail the following parts of the isl::boolean class:
43 * - The is_true, is_false, and is_error functions return true in case they
44 * are called on a true, false, or error instance of isl::boolean,
45 * respectively
46 * - Explicit conversion to 'bool'
47 * - Implicit conversion to 'bool'
48 * - The complement operator
49 * - Explicit construction from 'true' and 'false'
50 * - Explicit construction form isl_bool
52 void test_return_bool(isl::ctx ctx)
54 isl::set empty(ctx, "{ : false }");
55 isl::set univ(ctx, "{ : }");
56 isl::set null;
58 isl::boolean b_true = empty.is_empty();
59 isl::boolean b_false = univ.is_empty();
60 isl::boolean b_error = null.is_empty();
62 assert(b_true.is_true());
63 assert(!b_true.is_false());
64 assert(!b_true.is_error());
66 assert(!b_false.is_true());
67 assert(b_false.is_false());
68 assert(!b_false.is_error());
70 assert(!b_error.is_true());
71 assert(!b_error.is_false());
72 assert(b_error.is_error());
74 assert(bool(b_true) == true);
75 assert(bool(b_false) == false);
77 assert(b_true);
79 assert((!b_false).is_true());
80 assert((!b_true).is_false());
81 assert((!b_error).is_error());
83 assert(isl::boolean(true).is_true());
84 assert(!isl::boolean(true).is_false());
85 assert(!isl::boolean(true).is_error());
87 assert(isl::boolean(false).is_false());
88 assert(!isl::boolean(false).is_true());
89 assert(!isl::boolean(false).is_error());
91 assert(isl::manage(isl_bool_true).is_true());
92 assert(!isl::manage(isl_bool_true).is_false());
93 assert(!isl::manage(isl_bool_true).is_error());
95 assert(isl::manage(isl_bool_false).is_false());
96 assert(!isl::manage(isl_bool_false).is_true());
97 assert(!isl::manage(isl_bool_false).is_error());
99 assert(isl::manage(isl_bool_error).is_error());
100 assert(!isl::manage(isl_bool_error).is_true());
101 assert(!isl::manage(isl_bool_error).is_false());
104 /* Test that return values are handled correctly.
106 * Test that isl C++ objects, integers, boolean values, and strings are
107 * returned correctly.
109 void test_return(isl::ctx ctx)
111 test_return_obj(ctx);
112 test_return_int(ctx);
113 test_return_bool(ctx);
114 test_return_string(ctx);
117 /* Test that foreach functions are modeled correctly.
119 * Verify that lambdas are correctly called as callback of a 'foreach'
120 * function and that variables captured by the lambda work correctly. Also
121 * check that the foreach function takes account of the return value of the
122 * lambda and aborts in case isl::stat::error is returned and then returns
123 * isl::stat::error itself.
125 void test_foreach(isl::ctx ctx)
127 isl::set s(ctx, "{ [0]; [1]; [2] }");
129 std::vector<isl::basic_set> basic_sets;
131 auto add_to_vector = [&] (isl::basic_set bs) {
132 basic_sets.push_back(bs);
133 return isl::stat::ok();
136 isl::stat ret1 = s.foreach_basic_set(add_to_vector);
138 assert(ret1.is_ok());
139 assert(basic_sets.size() == 3);
140 assert(isl::set(basic_sets[0]).is_subset(s).is_true());
141 assert(isl::set(basic_sets[1]).is_subset(s).is_true());
142 assert(isl::set(basic_sets[2]).is_subset(s).is_true());
143 assert(!basic_sets[0].is_equal(basic_sets[1]).is_true());
145 auto fail = [&] (isl::basic_set bs) {
146 return isl::stat::error();
149 isl::stat ret2 = s.foreach_basic_set(fail);
151 assert(ret2.is_error());
154 /* Test the isl checked C++ interface
156 * This includes:
157 * - The isl C <-> C++ pointer interface
158 * - Object construction
159 * - Different parameter types
160 * - Different return types
161 * - Foreach functions
163 int main()
165 isl_ctx *ctx = isl_ctx_alloc();
167 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
169 test_pointer(ctx);
170 test_constructors(ctx);
171 test_parameters(ctx);
172 test_return(ctx);
173 test_foreach(ctx);
175 isl_ctx_free(ctx);
177 return EXIT_SUCCESS;