|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Unit tests for java_bytecode_language. |
| 4 | +
|
| 5 | +Author: Diffblue Limited. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <testing-utils/use_catch.h> |
| 10 | + |
| 11 | +#include <util/symbol_table.h> |
| 12 | + |
| 13 | +#include <java-testing-utils/load_java_class.h> |
| 14 | +#include <java-testing-utils/require_type.h> |
| 15 | + |
| 16 | +SCENARIO( |
| 17 | + "Exclude a method using context-include/exclude", |
| 18 | + "[core][java_bytecode][java_bytecode_language]") |
| 19 | +{ |
| 20 | + GIVEN("A class with all methods excluded except for main") |
| 21 | + { |
| 22 | + const symbol_tablet symbol_table = |
| 23 | + load_goto_model_from_java_class( |
| 24 | + "ClassWithDifferentModifiers", |
| 25 | + "./java_bytecode/java_bytecode_language", |
| 26 | + {}, |
| 27 | + {{"context-include", "ClassWithDifferentModifiers.main"}}) |
| 28 | + .get_symbol_table(); |
| 29 | + |
| 30 | + WHEN("Converting the methods of this class") |
| 31 | + { |
| 32 | + const auto public_instance_symbol = symbol_table.lookup( |
| 33 | + "java::ClassWithDifferentModifiers.testPublicInstance:()I"); |
| 34 | + REQUIRE(public_instance_symbol); |
| 35 | + const auto public_instance_type = |
| 36 | + type_try_dynamic_cast<java_method_typet>(public_instance_symbol->type); |
| 37 | + |
| 38 | + const auto private_static_symbol = symbol_table.lookup( |
| 39 | + "java::ClassWithDifferentModifiers.testPrivateStatic:()I"); |
| 40 | + REQUIRE(private_static_symbol); |
| 41 | + const auto private_static_type = |
| 42 | + type_try_dynamic_cast<java_method_typet>(private_static_symbol->type); |
| 43 | + |
| 44 | + const auto protected_final_instance_symbol = symbol_table.lookup( |
| 45 | + "java::ClassWithDifferentModifiers.testProtectedFinalInstance:()I"); |
| 46 | + REQUIRE(protected_final_instance_symbol); |
| 47 | + const auto protected_final_instance_type = |
| 48 | + type_try_dynamic_cast<java_method_typet>( |
| 49 | + protected_final_instance_symbol->type); |
| 50 | + |
| 51 | + const auto default_final_static_symbol = symbol_table.lookup( |
| 52 | + "java::ClassWithDifferentModifiers.testDefaultFinalStatic:()I"); |
| 53 | + REQUIRE(default_final_static_symbol); |
| 54 | + const auto default_final_static_type = |
| 55 | + type_try_dynamic_cast<java_method_typet>( |
| 56 | + default_final_static_symbol->type); |
| 57 | + THEN( |
| 58 | + "Symbol values for excluded methods are nil as the lazy_goto_modelt " |
| 59 | + "for unit tests does not generate stub/exclude bodies.") |
| 60 | + { |
| 61 | + REQUIRE(public_instance_symbol->value.is_nil()); |
| 62 | + REQUIRE(private_static_symbol->value.is_nil()); |
| 63 | + REQUIRE(protected_final_instance_symbol->value.is_nil()); |
| 64 | + REQUIRE(default_final_static_symbol->value.is_nil()); |
| 65 | + } |
| 66 | + THEN( |
| 67 | + "Types of excluded methods are stored as java_method_typets in the " |
| 68 | + "symbol table.") |
| 69 | + { |
| 70 | + REQUIRE(public_instance_type); |
| 71 | + REQUIRE(private_static_type); |
| 72 | + REQUIRE(protected_final_instance_type); |
| 73 | + REQUIRE(default_final_static_type); |
| 74 | + } |
| 75 | + THEN("Access modifiers of excluded methods are preserved.") |
| 76 | + { |
| 77 | + REQUIRE(public_instance_type->get_access() == ID_public); |
| 78 | + REQUIRE(private_static_type->get_access() == ID_private); |
| 79 | + REQUIRE(protected_final_instance_type->get_access() == ID_protected); |
| 80 | + REQUIRE(default_final_static_type->get_access() == ID_default); |
| 81 | + } |
| 82 | + THEN("Static/Instance meta-information of excluded methods is preserved.") |
| 83 | + { |
| 84 | + REQUIRE_FALSE(public_instance_type->get_bool(ID_is_static)); |
| 85 | + REQUIRE(private_static_type->get_bool(ID_is_static)); |
| 86 | + REQUIRE_FALSE(protected_final_instance_type->get_bool(ID_is_static)); |
| 87 | + REQUIRE(default_final_static_type->get_bool(ID_is_static)); |
| 88 | + } |
| 89 | + THEN("Final/Non-final meta-information of excluded methods is preserved.") |
| 90 | + { |
| 91 | + REQUIRE_FALSE(public_instance_type->get_is_final()); |
| 92 | + REQUIRE_FALSE(private_static_type->get_is_final()); |
| 93 | + REQUIRE(protected_final_instance_type->get_is_final()); |
| 94 | + REQUIRE(default_final_static_type->get_is_final()); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments