1 /*
2 * Copyright 2018 Sven Verdoolaege
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege.
7 */
8
9 #include <stdlib.h>
10
11 #include <isl/ctx.h>
12 #include <isl/options.h>
13 #include <isl/cpp-checked-conversion.h>
14
15 /* Check that converting a NULL object from the checked C++ bindings
16 * (where the user is expected to check for NULL return values)
17 * to the default C++ bindings (where exceptions are raised
18 * instead of returning a NULL object) raises an exception.
19 */
check_conversion_null(isl_ctx * ctx)20 static void check_conversion_null(isl_ctx *ctx)
21 {
22 isl::checked::set checked_set;
23 isl::set set;
24
25 bool caught = false;
26 try {
27 set = isl::uncheck(checked_set);
28 isl_die(ctx, isl_error_unknown, "no exception raised", return);
29 } catch (const isl::exception &e) {
30 caught = true;
31 }
32 if (!caught)
33 isl_die(ctx, isl_error_unknown, "no exception raised", return);
34 }
35
36 /* Dummy function on a set in the checked C++ bindings.
37 */
f_checked(isl::checked::set set)38 static void f_checked(isl::checked::set set)
39 {
40 }
41
42 /* Dummy function on a set in the default C++ bindings.
43 */
f_unchecked(isl::set set)44 static void f_unchecked(isl::set set)
45 {
46 }
47
48 /* Check the conversion between C++ bindings in function calls.
49 * An incorrect call will result in a compiler error.
50 */
check_conversion_call(isl_ctx * ctx)51 static void check_conversion_call(isl_ctx *ctx)
52 {
53 isl::set set(ctx, "{ S[i] : 0 <= i < 10 }");
54 isl::checked::set checked_set(ctx, "{ S[i] : 0 <= i < 10 }");
55
56 f_unchecked(set);
57 f_checked(isl::check(set));
58 f_unchecked(isl::uncheck(checked_set));
59 f_checked(checked_set);
60 }
61
62 /* Check that a double conversion results in the original set,
63 * or at least something that is equal to the original set.
64 */
check_conversion_equal(isl_ctx * ctx)65 static void check_conversion_equal(isl_ctx *ctx)
66 {
67 isl::set set(ctx, "{ S[i] : 0 <= i < 10 }");
68 isl::set set2;
69 isl::checked::set checked_set;
70
71 checked_set = isl::check(set);
72 set2 = isl::uncheck(checked_set);
73
74 if (!set.is_equal(set2))
75 isl_die(ctx, isl_error_unknown, "bad conversion", return);
76 }
77
78 /* Perform some tests on the conversion between the default C++ bindings and
79 * the checked C++ bindings.
80 */
check_conversion(isl_ctx * ctx)81 static void check_conversion(isl_ctx *ctx)
82 {
83 check_conversion_null(ctx);
84 check_conversion_call(ctx);
85 check_conversion_equal(ctx);
86 }
87
main()88 int main()
89 {
90 isl_ctx *ctx = isl_ctx_alloc();
91
92 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
93
94 check_conversion(ctx);
95
96 isl_ctx_free(ctx);
97
98 return EXIT_SUCCESS;
99 }
100