nashorn/test/script/basic/importpackage.js
author hannesw
Fri, 03 May 2013 22:48:53 +0200
changeset 17521 0522325da5ef
parent 16205 93fda2507e35
child 24778 2ff5d7041566
permissions -rw-r--r--
8013873: Regexp regression for escaped dash in character class Reviewed-by: jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16205
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     1
/*
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     4
 * 
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     8
 * 
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    13
 * accompanied this code).
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    14
 * 
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    18
 * 
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    21
 * questions.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    22
 */
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    23
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    24
/**
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    25
 * Test to check importPackage function.
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    26
 *
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    27
 * @test
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    28
 * @run
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    29
 */
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    30
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    31
try {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    32
    load("nashorn:mozilla_compat.js");
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    33
} catch (e) {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    34
}
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    35
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    36
importPackage(java.util);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    37
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    38
var m = new HashMap();
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    39
if (!(m instanceof java.util.HashMap)) {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    40
    fail("expected 'm' to be a java.util.HashMap instance");
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    41
}
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    42
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    43
function checkJavaClass(cls) {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    44
    if (! Java.isType(cls)) {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    45
        fail(cls + " is not a Java class");
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    46
    }
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    47
}
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    48
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    49
importPackage(java.lang.reflect, javax.script);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    50
checkJavaClass(Method);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    51
checkJavaClass(Field);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    52
checkJavaClass(Constructor);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    53
checkJavaClass(ScriptContext);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    54
checkJavaClass(ScriptEngine);
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    55
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    56
var bindings = new SimpleBindings();
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    57
if (!(bindings instanceof javax.script.SimpleBindings)) {
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    58
    fail("expected 'bindings' to be a javax.script.SimpleBindings instance");
93fda2507e35 8007286: Add JavaAdapter and importPackage to compatibility script
sundar
parents:
diff changeset
    59
}