|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for string_identifiers_resolution_from_equations in |
| 4 | + solvers/refinement/string_refinement.cpp |
| 5 | +
|
| 6 | + Author: DiffBlue Limited. All rights reserved. |
| 7 | +
|
| 8 | +\*******************************************************************/ |
| 9 | + |
| 10 | +#include <testing-utils/catch.hpp> |
| 11 | + |
| 12 | +#include <util/arith_tools.h> |
| 13 | +#include <util/c_types.h> |
| 14 | +#include <util/std_expr.h> |
| 15 | +#include <solvers/refinement/string_refinement.h> |
| 16 | +#include <util/symbol_table.h> |
| 17 | +#include <langapi/mode.h> |
| 18 | +#include <java_bytecode/java_bytecode_language.h> |
| 19 | +#include <iostream> |
| 20 | + |
| 21 | +SCENARIO("string_identifiers_resolution_from_equations", |
| 22 | +"[core][solvers][refinement][string_refinement]") |
| 23 | +{ |
| 24 | + // For printing expression |
| 25 | + register_language(new_java_bytecode_language); |
| 26 | + symbol_tablet symbol_table; |
| 27 | + namespacet ns(symbol_table); |
| 28 | + messaget::mstreamt &stream = messaget().debug(); |
| 29 | + |
| 30 | + GIVEN("Some equations") |
| 31 | + { |
| 32 | + constant_exprt a("a", string_typet()); |
| 33 | + constant_exprt b("b", string_typet()); |
| 34 | + constant_exprt c("c", string_typet()); |
| 35 | + constant_exprt d("d", string_typet()); |
| 36 | + constant_exprt e("e", string_typet()); |
| 37 | + constant_exprt f("f", string_typet()); |
| 38 | + |
| 39 | + struct_typet struct_type; |
| 40 | + struct_type.components().emplace_back("str1", string_typet()); |
| 41 | + struct_type.components().emplace_back("str2", string_typet()); |
| 42 | + struct_exprt struct_expr(struct_type); |
| 43 | + struct_expr.operands().push_back(a); |
| 44 | + struct_expr.operands().push_back(f); |
| 45 | + symbol_exprt symbol_struct("sym_struct", struct_type); |
| 46 | + |
| 47 | + std::vector<equal_exprt> equations; |
| 48 | + equations.emplace_back(a, b); |
| 49 | + equations.emplace_back(b, c); |
| 50 | + equations.emplace_back(d, e); |
| 51 | + equations.emplace_back(symbol_struct, struct_expr); |
| 52 | + |
| 53 | + WHEN("There is no function call") |
| 54 | + { |
| 55 | + union_find_replacet symbol_resolve = |
| 56 | + string_identifiers_resolution_from_equations( |
| 57 | + equations, ns, stream); |
| 58 | + |
| 59 | + THEN("The symbol resolution structure is empty") |
| 60 | + { |
| 61 | + REQUIRE(symbol_resolve.to_vector().empty()); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + WHEN("There is a function call") |
| 66 | + { |
| 67 | + symbol_exprt fun_sym("f", code_typet()); |
| 68 | + function_application_exprt fun(fun_sym, bool_typet()); |
| 69 | + fun.operands().push_back(c); |
| 70 | + symbol_exprt bool_sym("bool_b", bool_typet()); |
| 71 | + equations.emplace_back(bool_sym, fun); |
| 72 | + union_find_replacet symbol_resolve = |
| 73 | + string_identifiers_resolution_from_equations( |
| 74 | + equations, ns, stream); |
| 75 | + |
| 76 | + THEN("Equations that depend on it should be added") |
| 77 | + { |
| 78 | + REQUIRE(symbol_resolve.find(b) == symbol_resolve.find(c)); |
| 79 | + REQUIRE(symbol_resolve.find(a) == symbol_resolve.find(b)); |
| 80 | + |
| 81 | + member_exprt sym_m1(symbol_struct, "str1", string_typet()); |
| 82 | + member_exprt sym_m2(symbol_struct, "str2", string_typet()); |
| 83 | + |
| 84 | + REQUIRE(symbol_resolve.find(sym_m1) == symbol_resolve.find(c)); |
| 85 | + REQUIRE(symbol_resolve.find(sym_m2) == symbol_resolve.find(f)); |
| 86 | + } |
| 87 | + |
| 88 | + THEN("Equations that do not depend on it should not be added") |
| 89 | + { |
| 90 | + REQUIRE(symbol_resolve.find(d) != symbol_resolve.find(e)); |
| 91 | + } |
| 92 | + |
| 93 | + THEN("No other equation is added") |
| 94 | + { |
| 95 | + REQUIRE(symbol_resolve.find(a) != symbol_resolve.find(d)); |
| 96 | + REQUIRE(symbol_resolve.find(a) != symbol_resolve.find(f)); |
| 97 | + REQUIRE(symbol_resolve.find(d) != symbol_resolve.find(f)); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments