|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Interpreter unit tests. |
| 4 | +
|
| 5 | + Author: Diffblue Ltd. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <testing-utils/catch.hpp> |
| 10 | + |
| 11 | +#include <goto-programs/goto_functions.h> |
| 12 | +#include <goto-programs/interpreter_class.h> |
| 13 | +#include <util/message.h> |
| 14 | +#include <util/mp_arith.h> |
| 15 | +#include <util/namespace.h> |
| 16 | + |
| 17 | +typedef interpretert::mp_vectort mp_vectort; |
| 18 | + |
| 19 | +class interpreter_testt |
| 20 | +{ |
| 21 | + symbol_tablet symbol_table; |
| 22 | + goto_functionst goto_functions; |
| 23 | + null_message_handlert null_message_handler; |
| 24 | + interpretert interpreter; |
| 25 | + |
| 26 | +public: |
| 27 | + explicit interpreter_testt() |
| 28 | + : interpreter(symbol_table, goto_functions, null_message_handler) |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + mp_vectort evaluate(const exprt &expression) |
| 33 | + { |
| 34 | + mp_vectort result; |
| 35 | + interpreter.evaluate(expression, result); |
| 36 | + return result; |
| 37 | + } |
| 38 | +}; |
| 39 | + |
| 40 | +SCENARIO("interpreter evaluation null pointer expressions") |
| 41 | +{ |
| 42 | + interpreter_testt interpreter_test; |
| 43 | + mp_vectort null_vector = {0}; |
| 44 | + |
| 45 | + THEN("null pointer without operands") |
| 46 | + { |
| 47 | + unsignedbv_typet java_char(16); |
| 48 | + pointer_typet pointer_type(java_char, 64); |
| 49 | + |
| 50 | + constant_exprt constant_expr(ID_NULL, pointer_type); |
| 51 | + |
| 52 | + mp_vectort mp_vector = interpreter_test.evaluate(constant_expr); |
| 53 | + |
| 54 | + REQUIRE_THAT(mp_vector, Catch::Equals(null_vector)); |
| 55 | + } |
| 56 | + THEN("null pointer with operands") |
| 57 | + { |
| 58 | + pointer_typet outer_pointer_type(empty_typet(), 64); |
| 59 | + constant_exprt outer_expression( |
| 60 | + "0000000000000000000000000000000000000000000000000000000000000000", |
| 61 | + outer_pointer_type); |
| 62 | + |
| 63 | + pointer_typet inner_pointer_type(empty_typet(), 64); |
| 64 | + constant_exprt inner_expression(ID_NULL, inner_pointer_type); |
| 65 | + |
| 66 | + outer_expression.move_to_operands(inner_expression); |
| 67 | + |
| 68 | + mp_vectort mp_vector = interpreter_test.evaluate(outer_expression); |
| 69 | + |
| 70 | + REQUIRE_THAT(mp_vector, Catch::Equals(null_vector)); |
| 71 | + } |
| 72 | +} |
0 commit comments