Skip to content

Commit 0afbe0f

Browse files
Unit test java_type_from_string and fix doc
Unit-testing this function revealed some mistakes in the examples given in the documentation.
1 parent b7c9ea1 commit 0afbe0f

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/java_bytecode/java_types.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ size_t find_closing_semi_colon_for_reference_type(
416416
/// representation thereof.
417417
///
418418
/// Example use are object types like "Ljava/lang/Integer;", type
419-
/// variables/parameters like "TE;" which require a non-empty \p class_name
420-
/// or generic types like "Ljava/util/List<T>;" or "Ljava/util/List<Integer>;"
419+
/// variables/parameters like "TE;" which require a non-empty
420+
/// \p class_name_prefix or generic types like "Ljava/util/List<TE;>;"
421+
/// or "Ljava/util/List<Ljava/lang/Integer;>;" also requiring
422+
/// \p class_name_prefix.
421423
///
422424
/// \param src: the string representation as used in the class file
423425
/// \param class_name_prefix: name of class to append to generic type
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for java_types
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
#include <java_bytecode/java_types.h>
11+
12+
SCENARIO("java_type_from_string", "[core][java_types]")
13+
{
14+
// TODO : add more cases, the current test is not comprehensive
15+
16+
GIVEN("Ljava/lang/Integer;")
17+
{
18+
const auto integer_type = java_type_from_string("Ljava/lang/Integer;", "");
19+
REQUIRE(integer_type != nil_typet());
20+
}
21+
22+
GIVEN("TE;")
23+
{
24+
const auto generic_type_E = java_type_from_string("TE;", "MyClass");
25+
REQUIRE(generic_type_E != nil_typet());
26+
}
27+
28+
GIVEN("Ljava/util/List<TX;>;")
29+
{
30+
const auto generic_list_type =
31+
java_type_from_string("Ljava/util/List<TX;>;", "java.util.List");
32+
REQUIRE(generic_list_type != nil_typet());
33+
}
34+
35+
GIVEN("Ljava/util/List<Ljava/lang/Integer>;")
36+
{
37+
const auto integer_list_type =
38+
java_type_from_string("Ljava/util/List<Ljava/lang/Integer;>;", "");
39+
REQUIRE(integer_list_type != nil_typet());
40+
}
41+
42+
GIVEN("Ljava/util/Map<TK;TV;>;")
43+
{
44+
const auto generic_symbol_type =
45+
java_type_from_string("Ljava/util/Map<TK;TV;>;", "java.util.Map");
46+
REQUIRE(generic_symbol_type != nil_typet());
47+
}
48+
}

0 commit comments

Comments
 (0)