|
4 | 4 |
|
5 | 5 | #include <solvers/smt2_incremental/construct_value_expr_from_smt.h>
|
6 | 6 |
|
| 7 | +#include <solvers/smt2_incremental/smt_core_theory.h> |
7 | 8 | #include <solvers/smt2_incremental/smt_terms.h>
|
8 | 9 | #include <solvers/smt2_incremental/smt_to_smt2_string.h>
|
9 | 10 |
|
| 11 | +#include <testing-utils/invariant.h> |
| 12 | + |
10 | 13 | #include <util/arith_tools.h>
|
11 | 14 | #include <util/bitvector_types.h>
|
12 | 15 | #include <util/mp_arith.h>
|
13 | 16 | #include <util/std_expr.h>
|
14 | 17 | #include <util/std_types.h>
|
15 | 18 |
|
| 19 | +#include <string> |
| 20 | + |
16 | 21 | static mp_integer power2(unsigned exponent)
|
17 | 22 | {
|
18 | 23 | mp_integer result;
|
@@ -80,3 +85,40 @@ TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
|
80 | 85 | *expected_result);
|
81 | 86 | }
|
82 | 87 | }
|
| 88 | + |
| 89 | +TEST_CASE( |
| 90 | + "Invariant violations in value expr construction from smt.", |
| 91 | + "[core][smt2_incremental]") |
| 92 | +{ |
| 93 | + optionalt<smt_termt> input_term; |
| 94 | + optionalt<typet> input_type; |
| 95 | + std::string invariant_reason; |
| 96 | + |
| 97 | + using rowt = std::tuple<smt_termt, typet, std::string>; |
| 98 | + std::tie(input_term, input_type, invariant_reason) = GENERATE( |
| 99 | + rowt{smt_bool_literal_termt{true}, |
| 100 | + unsignedbv_typet{16}, |
| 101 | + "Bool terms may only be used to construct bool typed expressions."}, |
| 102 | + rowt{smt_identifier_termt{"foo", smt_bit_vector_sortt{16}}, |
| 103 | + unsignedbv_typet{16}, |
| 104 | + "Unexpected conversion of identifier to value expression."}, |
| 105 | + rowt{ |
| 106 | + smt_bit_vector_constant_termt{0, 8}, |
| 107 | + unsignedbv_typet{16}, |
| 108 | + "Width of smt bit vector term must match the width of bit vector type."}, |
| 109 | + rowt{smt_bit_vector_constant_termt{0, 8}, |
| 110 | + empty_typet{}, |
| 111 | + "construct_value_expr_from_smt for bit vector should not be applied " |
| 112 | + "to unsupported type empty"}, |
| 113 | + rowt{smt_core_theoryt::make_not(smt_bool_literal_termt{true}), |
| 114 | + unsignedbv_typet{16}, |
| 115 | + "Unexpected conversion of function application to value expression."}); |
| 116 | + SECTION(invariant_reason) |
| 117 | + { |
| 118 | + const cbmc_invariants_should_throwt invariants_throw; |
| 119 | + REQUIRE_THROWS_MATCHES( |
| 120 | + construct_value_expr_from_smt(*input_term, *input_type), |
| 121 | + invariant_failedt, |
| 122 | + invariant_failure_containing(invariant_reason)); |
| 123 | + } |
| 124 | +} |
0 commit comments