Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/Bug467396Test.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript.tests;
6
7 import org.mozilla.javascript.Context;
8 import org.mozilla.javascript.ContextFactory;
9 import org.mozilla.javascript.Scriptable;
10 import org.mozilla.javascript.Wrapper;
11 import junit.framework.TestCase;
12
13 /**
14 * Test for overloaded varargs/non-varargs methods.
15 * See https://bugzilla.mozilla.org/show_bug.cgi?id=467396
16 * @author Hannes Wallnoefer
17 */
18 public class Bug467396Test extends TestCase {
19
20 public void testOverloadedVarargs() {
21 Context cx = ContextFactory.getGlobal().enterContext();
22 try {
23 Scriptable scope = cx.initStandardObjects();
24 Object result = unwrap(cx.evaluateString(scope,
25 "java.lang.reflect.Array.newInstance(java.lang.Object, 1)",
26 "source", 1, null));
27 assertTrue(result instanceof Object[]);
28 assertEquals(1, ((Object[]) result).length);
29 result = unwrap(cx.evaluateString(scope,
30 "java.lang.reflect.Array.newInstance(java.lang.Object, [1])",
31 "source", 1, null));
32 assertTrue(result instanceof Object[]);
33 assertEquals(1, ((Object[]) result).length);
34 result = unwrap(cx.evaluateString(scope,
35 "java.lang.reflect.Array.newInstance(java.lang.Object, [1, 1])",
36 "source", 1, null));
37 assertTrue(result instanceof Object[][]);
38 assertEquals(1, ((Object[][]) result).length);
39 assertEquals(1, ((Object[][]) result)[0].length);
40 result = unwrap(cx.evaluateString(scope,
41 "java.lang.reflect.Array.newInstance(java.lang.Object, 1, 1)",
42 "source", 1, null));
43 assertTrue(result instanceof Object[][]);
44 assertEquals(1, ((Object[][]) result).length);
45 assertEquals(1, ((Object[][]) result)[0].length);
46 } finally {
47 Context.exit();
48 }
49 }
50
51
52 private Object unwrap(Object obj) {
53 return obj instanceof Wrapper ? ((Wrapper) obj).unwrap() : obj;
54 }
55 }