|
8 | 8 |
|
9 | 9 | #include <java-testing-utils/load_java_class.h>
|
10 | 10 | #include <java_bytecode/java_bytecode_convert_class.h>
|
| 11 | +#include <java_bytecode/java_bytecode_convert_method.h> |
11 | 12 | #include <java_bytecode/java_bytecode_parse_tree.h>
|
12 | 13 | #include <java_bytecode/java_types.h>
|
13 | 14 | #include <testing-utils/catch.hpp>
|
@@ -596,4 +597,50 @@ SCENARIO(
|
596 | 597 | }
|
597 | 598 | }
|
598 | 599 | }
|
| 600 | + |
| 601 | + GIVEN("A method that may or may not throw exceptions") |
| 602 | + { |
| 603 | + const symbol_tablet &new_symbol_table = load_java_class( |
| 604 | + "ThrowsExceptions", "./java_bytecode/java_bytecode_parser"); |
| 605 | + WHEN("Parsing the exceptions attribute for a method that throws exceptions") |
| 606 | + { |
| 607 | + THEN("We should be able to get the list of exceptions it throws") |
| 608 | + { |
| 609 | + const symbolt &class_symbol = |
| 610 | + new_symbol_table.lookup_ref("java::ThrowsExceptions"); |
| 611 | + const symbolt &method_symbol = |
| 612 | + new_symbol_table.lookup_ref("java::ThrowsExceptions.test:()V"); |
| 613 | + const code_typet method = to_code_type(method_symbol.type); |
| 614 | + const std::vector<irept> exceptions = method.throws_exceptions(); |
| 615 | + REQUIRE(exceptions.size() == 2); |
| 616 | + REQUIRE( |
| 617 | + std::find( |
| 618 | + exceptions.begin(), exceptions.end(), irept("CustomException")) != |
| 619 | + exceptions.end()); |
| 620 | + REQUIRE( |
| 621 | + std::find( |
| 622 | + exceptions.begin(), |
| 623 | + exceptions.end(), |
| 624 | + irept("java.io.IOException")) != exceptions.end()); |
| 625 | + } |
| 626 | + } |
| 627 | + } |
| 628 | + |
| 629 | + const symbol_tablet &new_symbol_table2 = load_java_class( |
| 630 | + "ThrowsExceptions", "./java_bytecode/java_bytecode_parser"); |
| 631 | + WHEN( |
| 632 | + "Parsing the exceptions attribute for a method that throws no exceptions") |
| 633 | + { |
| 634 | + THEN("We should be able to get the list of exceptions it throws") |
| 635 | + { |
| 636 | + const symbolt &class_symbol = |
| 637 | + new_symbol_table2.lookup_ref("java::ThrowsExceptions"); |
| 638 | + const symbolt &method_symbol = |
| 639 | + new_symbol_table2.lookup_ref("java::ThrowsExceptions.test:()V"); |
| 640 | + const java_method_typet method = to_java_method_type(method_symbol.type); |
| 641 | + const std::vector<irept> exceptions = method.throws_exceptions(); |
| 642 | + REQUIRE(exceptions.size() == 0); |
| 643 | + } |
| 644 | + } |
| 645 | + } |
599 | 646 | }
|
0 commit comments