9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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/classLoader.hpp"
26 #include "memory/resourceArea.hpp"
27 #include "unittest.hpp"
28
29 // Tests ClassLoader::package_from_name()
30 TEST_VM(classLoader, null_class_name) {
31 ResourceMark rm;
32 bool bad_class_name = false;
33 const char* retval= ClassLoader::package_from_name(NULL, &bad_class_name);
34 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with NULL class name";
35 ASSERT_STREQ(retval, NULL) << "Wrong package for NULL class name pointer";
36 }
37
38 TEST_VM(classLoader, empty_class_name) {
39 ResourceMark rm;
40 const char* retval = ClassLoader::package_from_name("");
41 ASSERT_STREQ(retval, NULL) << "Wrong package for empty string";
42 }
43
44 TEST_VM(classLoader, no_slash) {
45 ResourceMark rm;
46 const char* retval = ClassLoader::package_from_name("L");
47 ASSERT_STREQ(retval, NULL) << "Wrong package for class with no slashes";
48 }
49
50 TEST_VM(classLoader, just_slash) {
51 ResourceMark rm;
52 bool bad_class_name = false;
53 const char* retval = ClassLoader::package_from_name("/", &bad_class_name);
54 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with package of length 0";
55 ASSERT_STREQ(retval, NULL) << "Wrong package for class with just slash";
56 }
57
58 TEST_VM(classLoader, multiple_slashes) {
59 ResourceMark rm;
60 const char* retval = ClassLoader::package_from_name("///");
61 ASSERT_STREQ(retval, "//") << "Wrong package for class with just slashes";
62 }
63
64 TEST_VM(classLoader, standard_case_1) {
65 ResourceMark rm;
66 bool bad_class_name = true;
67 const char* retval = ClassLoader::package_from_name("package/class", &bad_class_name);
68 ASSERT_FALSE(bad_class_name) << "Function did not reset bad_class_name";
69 ASSERT_STREQ(retval, "package") << "Wrong package for class with one slash";
70 }
71
72 TEST_VM(classLoader, standard_case_2) {
73 ResourceMark rm;
74 const char* retval = ClassLoader::package_from_name("package/folder/class");
75 ASSERT_STREQ(retval, "package/folder") << "Wrong package for class with multiple slashes";
76 }
77
78 TEST_VM(classLoader, class_array) {
79 ResourceMark rm;
80 bool bad_class_name = false;
81 const char* retval = ClassLoader::package_from_name("[package/class", &bad_class_name);
82 ASSERT_FALSE(bad_class_name) << "Function set bad_class_name with class array";
83 ASSERT_STREQ(retval, "package") << "Wrong package for class with leading bracket";
84 }
85
86 TEST_VM(classLoader, class_object_array) {
87 ResourceMark rm;
88 bool bad_class_name = false;
89 const char* retval = ClassLoader::package_from_name("[Lpackage/class", &bad_class_name);
90 ASSERT_TRUE(bad_class_name) << "Function did not set bad_class_name with array of class objects";
91 ASSERT_STREQ(retval, NULL) << "Wrong package for class with leading '[L'";
92 }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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/classLoader.hpp"
26 #include "memory/resourceArea.hpp"
27 #include "unittest.hpp"
28
|