Skip to content

Commit a77f066

Browse files
author
thk123
committed
Adding unit test for does_pattern_miss_descriptor
1 parent d0033d4 commit a77f066

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

jbmc/src/java_bytecode/load_method_by_regex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class load_method_by_regext : public load_extra_methodst
2929
std::regex regex;
3030

3131
static bool does_pattern_miss_descriptor(const std::string &pattern);
32+
33+
friend class load_method_by_regex_testt;
3234
};
3335

3436
#endif // CPROVER_JAVA_BYTECODE_LOAD_METHOD_BY_REGEX_H

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SRC += java_bytecode/goto-programs/class_hierarchy_output.cpp \
2121
java_bytecode/java_types/java_generic_symbol_type.cpp \
2222
java_bytecode/java_types/java_type_from_string.cpp \
2323
java_bytecode/java_utils_test.cpp \
24+
java_bytecode/load_method_by_regex.cpp \
2425
java_bytecode/inherited_static_fields/inherited_static_fields.cpp \
2526
pointer-analysis/custom_value_set_analysis.cpp \
2627
solvers/refinement/string_constraint_instantiation/instantiate_not_contains.cpp \
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for parsing generic classes
4+
5+
Author: Diffblue Limited
6+
7+
\*******************************************************************/
8+
9+
#include <java_bytecode/load_method_by_regex.h>
10+
#include <testing-utils/catch.hpp>
11+
12+
class load_method_by_regex_testt
13+
{
14+
public:
15+
static bool does_pattern_miss_descriptor(const std::string &pattern)
16+
{
17+
return load_method_by_regext::does_pattern_miss_descriptor(pattern);
18+
}
19+
};
20+
21+
SCENARIO(
22+
"load_method_by_regex::does_pattern_miss_descriptor",
23+
"[core][java_bytecode][load_method_by_regex]")
24+
{
25+
GIVEN("A string with a java prefix and no descriptor")
26+
{
27+
const std::string pattern = "java::com.diffblue.ClassName.methodName";
28+
WHEN("When calling does_pattern_miss_descriptor")
29+
{
30+
bool result =
31+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
32+
THEN("It should miss discriptor")
33+
{
34+
REQUIRE(result);
35+
}
36+
}
37+
}
38+
GIVEN("A string with a java prefix and a descriptor")
39+
{
40+
const std::string pattern = "java::com.diffblue.ClassName.methodName:()V";
41+
WHEN("When calling does_pattern_miss_descriptor")
42+
{
43+
bool result =
44+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
45+
THEN("It should have the discriptor")
46+
{
47+
REQUIRE_FALSE(result);
48+
}
49+
}
50+
}
51+
GIVEN("A string without a java prefix and without a descriptor")
52+
{
53+
const std::string pattern = "com.diffblue.ClassName.methodName";
54+
WHEN("When calling does_pattern_miss_descriptor")
55+
{
56+
bool result =
57+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
58+
THEN("It should miss discriptor")
59+
{
60+
REQUIRE(result);
61+
}
62+
}
63+
}
64+
GIVEN("A string without a java prefix and with a descriptor")
65+
{
66+
const std::string pattern = "com.diffblue.ClassName.methodName:()V";
67+
WHEN("When calling does_pattern_miss_descriptor")
68+
{
69+
bool result =
70+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
71+
THEN("It should have the discriptor")
72+
{
73+
REQUIRE_FALSE(result);
74+
}
75+
}
76+
}
77+
GIVEN("A string with an almost java prefix and no descriptor")
78+
{
79+
const std::string pattern = "java:com.diffblue.ClassName.methodName";
80+
WHEN("When calling does_pattern_miss_descriptor")
81+
{
82+
bool result =
83+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
84+
THEN("It should classify the last : as a descriptor")
85+
{
86+
REQUIRE_FALSE(result);
87+
}
88+
}
89+
}
90+
GIVEN("A string with an almost java prefix and with a descriptor")
91+
{
92+
const std::string pattern = "java:com.diffblue.ClassName.methodName:()V";
93+
WHEN("When calling does_pattern_miss_descriptor")
94+
{
95+
bool result =
96+
load_method_by_regex_testt::does_pattern_miss_descriptor(pattern);
97+
THEN("It should have the discriptor")
98+
{
99+
REQUIRE_FALSE(result);
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)