|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for goto_model::validate |
| 4 | +
|
| 5 | + Author: Diffblue Ltd. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <goto-programs/goto_model.h> |
| 10 | +#include <testing-utils/catch.hpp> |
| 11 | +#include <util/arith_tools.h> |
| 12 | + |
| 13 | +SCENARIO( |
| 14 | + "Validation of consistent program/table pair (function type)", |
| 15 | + "[core][goto-programs][validate]") |
| 16 | +{ |
| 17 | + GIVEN("A model with one function") |
| 18 | + { |
| 19 | + const typet type1 = signedbv_typet(32); |
| 20 | + const typet type2 = signedbv_typet(64); |
| 21 | + code_typet fun_type1({}, type1); |
| 22 | + code_typet fun_type2({}, type2); |
| 23 | + |
| 24 | + symbolt function_symbol; |
| 25 | + irep_idt function_symbol_name = "foo"; |
| 26 | + function_symbol.name = function_symbol_name; |
| 27 | + |
| 28 | + goto_modelt goto_model; |
| 29 | + goto_model.goto_functions.function_map[function_symbol.name] = |
| 30 | + goto_functiont(); |
| 31 | + goto_model.goto_functions.function_map[function_symbol.name].type = |
| 32 | + fun_type1; |
| 33 | + |
| 34 | + WHEN("Symbol table has the right type") |
| 35 | + { |
| 36 | + function_symbol.type = fun_type1; |
| 37 | + goto_model.symbol_table.insert(function_symbol); |
| 38 | + |
| 39 | + THEN("The consistency check succeeds") |
| 40 | + { |
| 41 | + goto_model.validate(validation_modet::INVARIANT); |
| 42 | + |
| 43 | + REQUIRE(true); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + WHEN("Symbol table has the wrong type") |
| 48 | + { |
| 49 | + function_symbol.type = fun_type2; |
| 50 | + goto_model.symbol_table.insert(function_symbol); |
| 51 | + |
| 52 | + THEN("The consistency check fails") |
| 53 | + { |
| 54 | + bool caught = false; |
| 55 | + try |
| 56 | + { |
| 57 | + goto_model.validate(validation_modet::EXCEPTION); |
| 58 | + } |
| 59 | + catch(incorrect_goto_program_exceptiont &e) |
| 60 | + { |
| 61 | + caught = true; |
| 62 | + } |
| 63 | + REQUIRE(caught); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments