Skip to content

Commit 3055754

Browse files
committed
Add tests of invariant violations in construct_value_from_smt
1 parent 446f6bb commit 3055754

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

unit/solvers/smt2_incremental/construct_value_expr_from_smt.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
#include <solvers/smt2_incremental/construct_value_expr_from_smt.h>
66

7+
#include <solvers/smt2_incremental/smt_core_theory.h>
78
#include <solvers/smt2_incremental/smt_terms.h>
89
#include <solvers/smt2_incremental/smt_to_smt2_string.h>
910

11+
#include <testing-utils/invariant.h>
12+
1013
#include <util/arith_tools.h>
1114
#include <util/bitvector_types.h>
1215
#include <util/mp_arith.h>
1316
#include <util/std_expr.h>
1417
#include <util/std_types.h>
1518

19+
#include <string>
20+
1621
static mp_integer power2(unsigned exponent)
1722
{
1823
mp_integer result;
@@ -80,3 +85,40 @@ TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
8085
*expected_result);
8186
}
8287
}
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

Comments
 (0)