|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for converting annotations |
| 4 | +
|
| 5 | + Author: Diffblue Ltd. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <java-testing-utils/load_java_class.h> |
| 10 | +#include <java_bytecode/java_bytecode_convert_class.h> |
| 11 | +#include <java_bytecode/java_bytecode_parse_tree.h> |
| 12 | +#include <java_bytecode/java_types.h> |
| 13 | +#include <testing-utils/catch.hpp> |
| 14 | + |
| 15 | +SCENARIO( |
| 16 | + "java_bytecode_parse_class", |
| 17 | + "[core][java_bytecode][java_bytecode_parser]") |
| 18 | +{ |
| 19 | + GIVEN("Some class with a class hierarchy") |
| 20 | + { |
| 21 | + const symbol_tablet &new_symbol_table = |
| 22 | + load_java_class("ChildClass", "./java_bytecode/java_bytecode_parser"); |
| 23 | + WHEN("Parsing the class file structure") |
| 24 | + { |
| 25 | + THEN("We should be able to get the first super class") |
| 26 | + { |
| 27 | + const symbolt &class_symbol = |
| 28 | + new_symbol_table.lookup_ref("java::ChildClass"); |
| 29 | + const java_class_typet &java_class = |
| 30 | + to_java_class_type(class_symbol.type); |
| 31 | + REQUIRE(java_class.get_super_class() == "ParentClass"); |
| 32 | + } |
| 33 | + THEN("We should be able to get the second super class") |
| 34 | + { |
| 35 | + const symbolt &class_symbol = |
| 36 | + new_symbol_table.lookup_ref("java::ChildClass"); |
| 37 | + const java_class_typet &java_class = |
| 38 | + to_java_class_type(class_symbol.type); |
| 39 | + const symbolt &class_symbol1 = new_symbol_table.lookup_ref( |
| 40 | + "java::" + id2string(java_class.get_super_class())); |
| 41 | + const java_class_typet &java_class1 = |
| 42 | + to_java_class_type(class_symbol1.type); |
| 43 | + REQUIRE(java_class1.get_super_class() == "GrandparentClass"); |
| 44 | + } |
| 45 | + THEN("We should be able to get the third super class") |
| 46 | + { |
| 47 | + const symbolt &class_symbol = |
| 48 | + new_symbol_table.lookup_ref("java::ChildClass"); |
| 49 | + const java_class_typet &java_class = |
| 50 | + to_java_class_type(class_symbol.type); |
| 51 | + const symbolt &class_symbol1 = new_symbol_table.lookup_ref( |
| 52 | + "java::" + id2string(java_class.get_super_class())); |
| 53 | + const java_class_typet &java_class1 = |
| 54 | + to_java_class_type(class_symbol1.type); |
| 55 | + const symbolt &class_symbol2 = new_symbol_table.lookup_ref( |
| 56 | + "java::" + id2string(java_class1.get_super_class())); |
| 57 | + const java_class_typet &java_class2 = |
| 58 | + to_java_class_type(class_symbol2.type); |
| 59 | + REQUIRE(java_class2.get_super_class() == "java.lang.Object"); |
| 60 | + } |
| 61 | + THEN("We should be able to get the fourth super class") |
| 62 | + { |
| 63 | + const symbolt &class_symbol = |
| 64 | + new_symbol_table.lookup_ref("java::ChildClass"); |
| 65 | + const java_class_typet &java_class = |
| 66 | + to_java_class_type(class_symbol.type); |
| 67 | + const symbolt &class_symbol1 = new_symbol_table.lookup_ref( |
| 68 | + "java::" + id2string(java_class.get_super_class())); |
| 69 | + const java_class_typet &java_class1 = |
| 70 | + to_java_class_type(class_symbol1.type); |
| 71 | + const symbolt &class_symbol2 = new_symbol_table.lookup_ref( |
| 72 | + "java::" + id2string(java_class1.get_super_class())); |
| 73 | + const java_class_typet &java_class2 = |
| 74 | + to_java_class_type(class_symbol2.type); |
| 75 | + const symbolt &class_symbol3 = new_symbol_table.lookup_ref( |
| 76 | + "java::" + id2string(java_class2.get_super_class())); |
| 77 | + const java_class_typet &java_class3 = |
| 78 | + to_java_class_type(class_symbol3.type); |
| 79 | + REQUIRE(java_class3.get_super_class().empty()); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments