|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Java string library preprocess. |
| 4 | + Test for converting an expression to a string expression. |
| 5 | +
|
| 6 | + Author: Diffblue Limited. All rights reserved. |
| 7 | +
|
| 8 | +\*******************************************************************/ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | +#include <util/c_types.h> |
| 12 | +#include <util/expr.h> |
| 13 | +#include <util/std_code.h> |
| 14 | +#include <java_bytecode/java_string_library_preprocess.h> |
| 15 | +#include <langapi/language_util.h> |
| 16 | +#include <java_bytecode/java_bytecode_language.h> |
| 17 | +#include <util/namespace.h> |
| 18 | +#include <langapi/mode.h> |
| 19 | + |
| 20 | +exprt convert_exprt_to_string_exprt_unit_test( |
| 21 | + java_string_library_preprocesst &preprocess, |
| 22 | + const exprt &deref, |
| 23 | + const source_locationt &loc, |
| 24 | + symbol_tablet &symbol_table, |
| 25 | + code_blockt &init_code) |
| 26 | +{ |
| 27 | + return preprocess.convert_exprt_to_string_exprt( |
| 28 | + deref, loc, symbol_table, init_code); |
| 29 | +} |
| 30 | + |
| 31 | +TEST_CASE("Convert exprt to string exprt") |
| 32 | +{ |
| 33 | + source_locationt loc; |
| 34 | + symbol_tablet symbol_table; |
| 35 | + namespacet ns(symbol_table); |
| 36 | + code_blockt code; |
| 37 | + java_string_library_preprocesst preprocess; |
| 38 | + preprocess.add_string_type("java.lang.String", symbol_table); |
| 39 | + symbol_typet java_string_type("java::java.lang.String"); |
| 40 | + symbol_exprt expr("a", pointer_type(java_string_type)); |
| 41 | + convert_exprt_to_string_exprt_unit_test( |
| 42 | + preprocess, expr, loc, symbol_table, code); |
| 43 | + register_language(new_java_bytecode_language); |
| 44 | + |
| 45 | + std::vector<std::string> code_string; |
| 46 | + for(auto op : code.operands()) |
| 47 | + code_string.push_back(from_expr(ns, "", op)); |
| 48 | + |
| 49 | + REQUIRE(code_string.size()==7); |
| 50 | + REQUIRE(code_string[0]=="int cprover_string_length$1;"); |
| 51 | + REQUIRE(code_string[1]=="char cprover_string_array$2[INFINITY()];"); |
| 52 | + REQUIRE(code_string[2]=="cprover_string_length$1 = a->length;"); |
| 53 | + REQUIRE(code_string[3]=="__CPROVER_assume(!(a->data == null));"); |
| 54 | + REQUIRE(code_string[4]=="cprover_string_array$2 = *a->data;"); |
| 55 | + REQUIRE(code_string[5]=="struct __CPROVER_refined_string_type { int length; " |
| 56 | + "char content[INFINITY()]; } cprover_string$3;"); |
| 57 | + REQUIRE(code_string[6]=="cprover_string$3 = { .=cprover_string_length$1, " |
| 58 | + ".=cprover_string_array$2 };"); |
| 59 | +} |
0 commit comments