|
8 | 8 | #include <util/namespace.h>
|
9 | 9 | #include <util/symbol_table.h>
|
10 | 10 |
|
| 11 | +#include <solvers/smt2_incremental/encoding/nondet_padding.h> |
11 | 12 | #include <solvers/smt2_incremental/encoding/struct_encoding.h>
|
12 | 13 | #include <testing-utils/use_catch.h>
|
13 | 14 |
|
@@ -453,3 +454,39 @@ TEST_CASE(
|
453 | 454 | REQUIRE(test.struct_encoding.encode(struct_expr) == dozen);
|
454 | 455 | }
|
455 | 456 | }
|
| 457 | + |
| 458 | +TEST_CASE("encoding of union expressions", "[core][smt2_incremental]") |
| 459 | +{ |
| 460 | + const struct_union_typet::componentst components{ |
| 461 | + {"eggs", unsignedbv_typet{8}}, {"ham", signedbv_typet{32}}}; |
| 462 | + const type_symbolt type_symbol{"foot", union_typet{components}, ID_C}; |
| 463 | + auto test = struct_encoding_test_environmentt::make(); |
| 464 | + test.symbol_table.insert(type_symbol); |
| 465 | + const union_tag_typet union_tag{type_symbol.name}; |
| 466 | + const symbolt union_value_symbol{"foo", union_tag, ID_C}; |
| 467 | + test.symbol_table.insert(union_value_symbol); |
| 468 | + const auto symbol_expr = union_value_symbol.symbol_expr(); |
| 469 | + const auto symbol_expr_as_bv = symbol_exprt{"foo", bv_typet{32}}; |
| 470 | + const auto dozen = from_integer(12, unsignedbv_typet{8}); |
| 471 | + const auto partial_union = union_exprt{"eggs", dozen, union_tag}; |
| 472 | + const auto partial_union_as_bv = concatenation_exprt{ |
| 473 | + {nondet_padding_exprt{bv_typet{24}}, dozen}, bv_typet{32}}; |
| 474 | + SECTION("Union typed symbol expression") |
| 475 | + { |
| 476 | + REQUIRE(test.struct_encoding.encode(symbol_expr) == symbol_expr_as_bv); |
| 477 | + } |
| 478 | + SECTION("Expression for a union from a component") |
| 479 | + { |
| 480 | + REQUIRE(test.struct_encoding.encode(partial_union) == partial_union_as_bv); |
| 481 | + const auto one = from_integer(1, unsignedbv_typet{32}); |
| 482 | + const auto full_union = union_exprt{"ham", one, union_tag}; |
| 483 | + const auto full_union_as_bv = typecast_exprt{one, bv_typet{32}}; |
| 484 | + REQUIRE(test.struct_encoding.encode(full_union) == full_union_as_bv); |
| 485 | + } |
| 486 | + SECTION("Union equality expression") |
| 487 | + { |
| 488 | + const auto union_equal = equal_exprt{symbol_expr, partial_union}; |
| 489 | + const auto bv_equal = equal_exprt{symbol_expr_as_bv, partial_union_as_bv}; |
| 490 | + REQUIRE(test.struct_encoding.encode(union_equal) == bv_equal); |
| 491 | + } |
| 492 | +} |
0 commit comments