12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "classfile/symbolTable.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/instanceKlass.hpp"
29 #include "unittest.hpp"
30
31 // Tests InstanceKlass::package_from_name()
32 TEST_VM(InstanceKlass, null_symbol) {
33 ResourceMark rm;
34 TempNewSymbol package_sym = InstanceKlass::package_from_name(NULL, NULL);
35 ASSERT_TRUE(package_sym == NULL) << "Wrong package for NULL symbol";
36 }
37
38 // Tests for InstanceKlass::is_class_loader_instance_klass() function
39 TEST_VM(InstanceKlass, class_loader_class) {
40 InstanceKlass* klass = SystemDictionary::ClassLoader_klass();
41 ASSERT_TRUE(klass->is_class_loader_instance_klass());
42 }
43
44 TEST_VM(InstanceKlass, string_klass) {
45 InstanceKlass* klass = SystemDictionary::String_klass();
46 ASSERT_TRUE(!klass->is_class_loader_instance_klass());
47 }
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "classfile/symbolTable.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/instanceKlass.hpp"
29 #include "unittest.hpp"
30
31 // Tests InstanceKlass::package_from_name()
32 TEST_VM(InstanceKlass, null_class_name) {
33 bool bad_class_name = false;
34 TempNewSymbol retval = InstanceKlass::package_from_name(NULL, &bad_class_name);
35 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with NULL class name";
36 ASSERT_TRUE(retval == NULL) << "Wrong package for NULL class name pointer";
37 }
38
39 TEST_VM(InstanceKlass, empty_class_name) {
40 bool bad_class_name = false;
41 TempNewSymbol name = SymbolTable::new_symbol("");
42 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
43 ASSERT_TRUE(retval == NULL) << "Wrong package for empty string";
44 }
45
46 TEST_VM(InstanceKlass, no_slash) {
47 bool bad_class_name = false;
48 TempNewSymbol name = SymbolTable::new_symbol("L");
49 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
50 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name with empty package";
51 ASSERT_TRUE(retval == NULL) << "Wrong package for class with no slashes";
52 }
53
54 TEST_VM(InstanceKlass, just_slash) {
55 bool bad_class_name = false;
56 TempNewSymbol name = SymbolTable::new_symbol("/");
57 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
58 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with package of length 0";
59 ASSERT_TRUE(retval == NULL) << "Wrong package for class with just slash";
60 }
61
62 TEST_VM(InstanceKlass, multiple_slashes) {
63 bool bad_class_name = false;
64 TempNewSymbol name = SymbolTable::new_symbol("///");
65 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
66 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name with slashes package";
67 ASSERT_TRUE(retval->equals("//")) << "Wrong package for class with just slashes";
68 }
69
70 TEST_VM(InstanceKlass, standard_case_1) {
71 bool bad_class_name = false;
72 TempNewSymbol name = SymbolTable::new_symbol("package/class");
73 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
74 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name for valid package";
75 ASSERT_TRUE(retval->equals("package")) << "Wrong package for class with one slash";
76 }
77
78 TEST_VM(InstanceKlass, standard_case_2) {
79 bool bad_class_name = false;
80 TempNewSymbol name = SymbolTable::new_symbol("package/folder/class");
81 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
82 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name for valid package";
83 ASSERT_TRUE(retval->equals("package/folder")) << "Wrong package for class with multiple slashes";
84 }
85
86 TEST_VM(InstanceKlass, class_array) {
87 bool bad_class_name = false;
88 TempNewSymbol name = SymbolTable::new_symbol("[package/class");
89 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
90 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name with class array";
91 ASSERT_TRUE(retval->equals("package")) << "Wrong package for class with leading bracket";
92 }
93
94 TEST_VM(InstanceKlass, class_object_array) {
95 bool bad_class_name = false;
96 TempNewSymbol name = SymbolTable::new_symbol("[Lpackage/class");
97 TempNewSymbol retval = InstanceKlass::package_from_name(name, &bad_class_name);
98 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with array of class objects";
99 ASSERT_TRUE(retval == NULL) << "Wrong package for class with leading '[L'";
100 }
101
102 // Tests for InstanceKlass::is_class_loader_instance_klass() function
103 TEST_VM(InstanceKlass, class_loader_class) {
104 InstanceKlass* klass = SystemDictionary::ClassLoader_klass();
105 ASSERT_TRUE(klass->is_class_loader_instance_klass());
106 }
107
108 TEST_VM(InstanceKlass, string_klass) {
109 InstanceKlass* klass = SystemDictionary::String_klass();
110 ASSERT_TRUE(!klass->is_class_loader_instance_klass());
111 }
|