isl_affine_hull.c: construct_column: return isl_stat
[isl.git] / isl_test_cpp-checked-conversion.cc
bloba4aeaf5a03792e18e61599c7aff90390c9e3b4c6
1 /*
2 * Copyright 2018 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
7 */
9 #include <stdlib.h>
11 #include <isl/ctx.h>
12 #include <isl/options.h>
13 #include <isl/cpp-checked-conversion.h>
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.
20 static void check_conversion_null(isl_ctx *ctx)
22 isl::checked::set checked_set;
23 isl::set set;
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;
32 if (!caught)
33 isl_die(ctx, isl_error_unknown, "no exception raised", return);
36 /* Dummy function on a set in the checked C++ bindings.
38 static void f_checked(isl::checked::set set)
42 /* Dummy function on a set in the default C++ bindings.
44 static void f_unchecked(isl::set set)
48 /* Check the conversion between C++ bindings in function calls.
49 * An incorrect call will result in a compiler error.
51 static void check_conversion_call(isl_ctx *ctx)
53 isl::set set(ctx, "{ S[i] : 0 <= i < 10 }");
54 isl::checked::set checked_set(ctx, "{ S[i] : 0 <= i < 10 }");
56 f_unchecked(set);
57 f_checked(isl::check(set));
58 f_unchecked(isl::uncheck(checked_set));
59 f_checked(checked_set);
62 /* Check that a double conversion results in the original set,
63 * or at least something that is equal to the original set.
65 static void check_conversion_equal(isl_ctx *ctx)
67 isl::set set(ctx, "{ S[i] : 0 <= i < 10 }");
68 isl::set set2;
69 isl::checked::set checked_set;
71 checked_set = isl::check(set);
72 set2 = isl::uncheck(checked_set);
74 if (!set.is_equal(set2))
75 isl_die(ctx, isl_error_unknown, "bad conversion", return);
78 /* Perform some tests on the conversion between the default C++ bindings and
79 * the checked C++ bindings.
81 static void check_conversion(isl_ctx *ctx)
83 check_conversion_null(ctx);
84 check_conversion_call(ctx);
85 check_conversion_equal(ctx);
88 int main()
90 isl_ctx *ctx = isl_ctx_alloc();
92 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
94 check_conversion(ctx);
96 isl_ctx_free(ctx);
98 return EXIT_SUCCESS;