|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for concretize_array_expression in |
| 4 | + solvers/refinement/string_refinement.cpp |
| 5 | +
|
| 6 | + Author: DiffBlue Limited. All rights reserved. |
| 7 | +
|
| 8 | +\*******************************************************************/ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | + |
| 12 | +#include <util/arith_tools.h> |
| 13 | +#include <util/std_types.h> |
| 14 | +#include <util/std_expr.h> |
| 15 | +#include <solvers/refinement/string_refinement.h> |
| 16 | + |
| 17 | +SCENARIO("concretize_array_expression", |
| 18 | + "[core][solvers][refinement][string_refinement]") |
| 19 | +{ |
| 20 | + const typet char_type=unsignedbv_typet(16); |
| 21 | + const typet int_type=signedbv_typet(32); |
| 22 | + const exprt index1=from_integer(1, int_type); |
| 23 | + const exprt charx=from_integer('x', char_type); |
| 24 | + const exprt index4=from_integer(4, int_type); |
| 25 | + const exprt chary=from_integer('y', char_type); |
| 26 | + const exprt index100=from_integer(100, int_type); |
| 27 | + const exprt char0=from_integer('0', char_type); |
| 28 | + const exprt index2=from_integer(2, int_type); |
| 29 | + array_typet array_type(char_type, infinity_exprt(int_type)); |
| 30 | + |
| 31 | + // input_expr is |
| 32 | + // `'0' + (ARRAY_OF(0) WITH [1:=x] WITH [4:=y] WITH [100:=z])[2]` |
| 33 | + const plus_exprt input_expr( |
| 34 | + from_integer('0', char_type), |
| 35 | + index_exprt( |
| 36 | + with_exprt( |
| 37 | + with_exprt( |
| 38 | + with_exprt( |
| 39 | + array_of_exprt(from_integer(0, char_type), array_type), |
| 40 | + index1, |
| 41 | + charx), |
| 42 | + index4, |
| 43 | + chary), |
| 44 | + index100, |
| 45 | + from_integer('z', char_type)), |
| 46 | + index2)); |
| 47 | + |
| 48 | + // String max length is 50, so index 100 should get ignored. |
| 49 | + const exprt concrete=concretize_arrays_in_expression(input_expr, 50); |
| 50 | + |
| 51 | + // The expected result is `'0' + { 'x', 'x', 'y', 'y', 'y' }` |
| 52 | + array_exprt array(array_type); |
| 53 | + array.operands()={charx, charx, chary, chary, chary}; |
| 54 | + const plus_exprt expected(char0, index_exprt(array, index2)); |
| 55 | + REQUIRE(concrete==expected); |
| 56 | +} |
0 commit comments