1e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch/*
2e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * Copyright (C) 2010 The Android Open Source Project
3e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch *
4e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * Licensed under the Apache License, Version 2.0 (the "License");
5e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * you may not use this file except in compliance with the License.
6e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * You may obtain a copy of the License at
7e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch *
8e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch *      http://www.apache.org/licenses/LICENSE-2.0
9e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch *
10e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * Unless required by applicable law or agreed to in writing, software
11e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * distributed under the License is distributed on an "AS IS" BASIS,
12e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * See the License for the specific language governing permissions and
14e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch * limitations under the License.
15e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch */
16e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
17e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochpackage com.android.browser;
18e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
19e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochimport android.test.AndroidTestCase;
20e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochimport android.util.Log;
21e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
22e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochimport java.util.Arrays;
23e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochimport junit.framework.AssertionFailedError;
24e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
25e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdochpublic class JNIBindingsTest extends AndroidTestCase {
26e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
27e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    private final static String LOGTAG = "JNIBindingsTest";
28e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    private JNIBindingsTestApp mTestApp;
29e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
30e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public int mInt = 123;
31e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public String mString = "Hello World";
32e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
33e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public JNIBindingsTest(JNIBindingsTestApp testApp) {
34e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        mTestApp = testApp;
35e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
36e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
37e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public void testComplete() {
38e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Log.v(LOGTAG, "Completing the test.");
39e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        mTestApp.testComplete();
40e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
41e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
42e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public void printAssertionFailed(AssertionFailedError e) {
43e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Log.e(LOGTAG, "");
44e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Log.e(LOGTAG, "*** ASSERTION FAILED: " + e.getMessage());
45e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Log.e(LOGTAG, "*** Stack trace:");
46e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        StackTraceElement[] trace = e.getStackTrace();
47e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        for(StackTraceElement elem : trace) {
48e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            Log.e(LOGTAG, "***\t" + elem.toString());
49e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
50e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Log.e(LOGTAG, "");
51e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
52e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
53e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testPrimitiveTypes(byte byteParam, char charParam, double doubleParam,
54e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            float floatParam, int intParam, long longParam, short shortParam,
55e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            boolean booleanParam) {
56e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        byte expectedByteParam = 100;
57e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        char expectedCharParam = 'c';
58e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        double expectedDoubleParam = 123.34567890;
59e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        float expectedFloatParam = 456.789f;
60e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        int expectedIntParam = 1234567;
61e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        long expectedLongParam = 1234567890L;
62e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        short expectedShortParam = 6000;
63e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        boolean expectedBooleanParam = true;
64e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
65e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
66e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedByteParam, byteParam);
67e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
68e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS: JSC does not pass chars correctly
69e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // assertEquals(expectedCharParam, charParam);
70e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
71e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedDoubleParam, doubleParam);
72e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedFloatParam, floatParam);
73e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedIntParam, intParam);
74e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedLongParam, longParam);
75e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedShortParam, shortParam);
76e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedBooleanParam, booleanParam);
77e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
78e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
79e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch           return false;
80e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
81e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
82e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
83e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
84e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testObjectTypes(String stringParam, String emptyString, Object objectParam,
85e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            Object emptyObject) {
86e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedString = "Foo";
87e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedEmptyString = "";
88e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
89e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
90e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(stringParam);
91e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(emptyString);
92e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedString, stringParam);
93e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedEmptyString, emptyString);
94e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(objectParam);
95e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(emptyObject);
96e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
97e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
98e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            return false;
99e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
100e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
101e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
102e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
103e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testArray(byte[] byteArray, char[] charArray, double[] doubleArray,
104e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            float[] floatArray, int[] intArray, long[] longArray, short[] shortArray,
105e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            boolean[] booleanArray) {
106e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        byte[] expectedByteArray = { 1,2,3};
107e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        char[] expectedCharArray = {'d', 'o', 'g'};
108e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        double[] expectedDoubleArray = {1.2,2.3,3.4};
109e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        float[] expectedFloatArray = {4.5F,5.6F,6.7F};
110e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        int[] expectedIntArray = {1,2,3};
111e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        long[] expectedLongArray = {4L,5L,6L};
112e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        short[] expectedShortArray = {7,8,9};
113e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        boolean[] expectedBooleanArray = {true, false};
114e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
115e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
116e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(byteArray);
117e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(charArray);
118e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(doubleArray);
119e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(floatArray);
120e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(intArray);
121e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(longArray);
122e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(shortArray);
123e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(booleanArray);
124e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedByteArray), Arrays.toString(byteArray));
125e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedCharArray), Arrays.toString(charArray));
126e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedDoubleArray), Arrays.toString(doubleArray));
127e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedFloatArray), Arrays.toString(floatArray));
128e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedIntArray), Arrays.toString(intArray));
129e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedLongArray), Arrays.toString(longArray));
130e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedShortArray), Arrays.toString(shortArray));
131e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedBooleanArray), Arrays.toString(booleanArray));
132e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
133e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
134e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            return false;
135e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
136e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
137e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
138e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
139e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testObjectArray(String[] stringArray, Object[] emptyArray,
140e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            Object[] objectArray) {
141e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String[] expectedStringArray = {"Hello", "World", "!"};
142940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        String expectedStringArrayClassName = "[Ljava.lang.String;";
143e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        Object[] expectedObjectArray = {};
144e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
145e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
146e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(stringArray);
147e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
148e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS JSC pass null for object arrays that are not strings.
149e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // Should be an empty array?
150e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(emptyArray);
151e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(objectArray);
152e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
153e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedStringArray), Arrays.toString(stringArray));
154940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            assertEquals(expectedStringArrayClassName, stringArray.getClass().getName());
155e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
156e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS
157e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // assertEquals(Arrays.toString(expectedObjectArray), Arrays.toString(emptyArray));
158940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            // assertEquals(expectedObjectArrayClassName, emptyArray.getClass().getName());
159e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // assertEquals(Arrays.toString(expectedObjectArray), Arrays.toString(objectArray));
160940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            // assertEquals(expectedStringObjectClassName, objectArray.getClass().getName());
161e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
162e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
163e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
164e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            return false;
165e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
166e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
167e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
168e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
169e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testObjectMembers(boolean boolParam, byte byteParam, char charParam,
170e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            double doubleParam, float floatParam, int intParam, long longParam, short shortParam,
171e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            String stringParam, int[] intArrayParam, String[] stringArrayParam,
172e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            Object objectParam) {
173e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        boolean expectedBoolParam = true;
174e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        byte expectedByteParam = 101;
175e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        char expectedCharParam = 'd';
176e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        double expectedDoubleParam = 123.456;
177e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        float expectedFloatParam = 456.789F;
178e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        int expectedIntParam = 102;
179e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        long expectedLongParam = 103L;
180e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        short expectedShortParam = 104;
181e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedStringParam = "Hello World";
182e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        int[] expectedIntArray = {1,2,3};
183e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String[] expectedStringArrayParam = {"foo", "bar", "baz"};
184940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        String expectedStringArrayClassName = "[Ljava.lang.String;";
185e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
186e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
187e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedBoolParam, boolParam);
188e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedByteParam, byteParam);
189e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
190e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS: JSC does not pass chars correctly. (chars are strings in JS)
191e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // assertEquals(expectedCharParam, charParam);
192e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
193e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedDoubleParam, doubleParam);
194e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedFloatParam, floatParam);
195e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedIntParam, intParam);
196e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedLongParam, longParam);
197e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedShortParam, shortParam);
198e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedStringParam, stringParam);
199e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedIntArray), Arrays.toString(intArrayParam));
200e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(Arrays.toString(expectedStringArrayParam),
201e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch                    Arrays.toString(stringArrayParam));
202940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            assertEquals(expectedStringArrayClassName, stringArrayParam.getClass().getName());
203e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(objectParam);
204e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
205e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
206e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            return false;
207e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
208e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
209e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
210e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
211e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean testJSPrimitivesToStringsInJava(String intParam, String nullParam,
212e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            String doubleParam, String booleanParam, String charParam,
213e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            String undefinedParam) {
214e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedIntParam = "123";
215e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedDoubleParam = "456.789";
216e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedBooleanParam = "true";
217e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedCharParam = "d";
218e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
219e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        // EMULATE_JSC_BINDINGS JSC passes "undefined" for undefined types. Should be null?
220e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        String expectedUndefinedParam = "undefined";
221e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
222e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        try {
223e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(intParam);
224e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNull(nullParam);
225e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(doubleParam);
226e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(booleanParam);
227e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(charParam);
228e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
229e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS JSC passes "undefined" for undefined types.
230e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertNotNull(undefinedParam);
231e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
232e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedIntParam, intParam);
233e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedDoubleParam, doubleParam);
234e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedBooleanParam, booleanParam);
235e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedCharParam, charParam);;
236e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
237e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            // EMULATE_JSC_BINDINGS  JSC passes "undefined" for undefined types.
238e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            assertEquals(expectedUndefinedParam, undefinedParam);
239e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
240e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        } catch (AssertionFailedError e) {
241e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            printAssertionFailed(e);
242e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch            return false;
243e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        }
244e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return true;
245e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
246e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
247940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch    public boolean testParameterTypeMismatch(String[] stringArrayParam) {
248940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        // The JS test will pass a string, not an array to this test.
249940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        try {
250940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            assertNull(stringArrayParam);
251940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        } catch (AssertionFailedError e) {
252940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            printAssertionFailed(e);
253940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch            return false;
254940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        }
255940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch
256940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch        return true;
257940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch    }
258940e57fdd2fc09398c84fd3b8f3e993bc6fee4a0Ben Murdoch
259e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public boolean returnBool() { return true; }
260e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public byte returnByte() { return 1; }
261e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public char returnChar() { return 'b'; }
262e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public double returnDouble() { return 123.456; }
263e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public float returnFloat() { return 456.789F; }
264e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public int returnInt() { return 123; }
265e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public long returnLong() { return 1234L; }
266e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public short returnShort() { return 12345; }
267e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public String returnString() { return "Hello World!"; }
268e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
269e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public class TestObject {
270e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        public int x = 123;
271e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        public String s = "Hello World!";
272e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
273e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        public boolean aMethod() { return true; }
274e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        public String anotherMethod() { return "Hello World"; }
275e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
276e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
277e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public TestObject returnObject() { return new TestObject(); }
278e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
279e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public int[] returnArray() {
280e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        int[] array = {1,2,3,4,5};
281e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch        return array;
282e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    }
283e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch
284e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch    public void returnVoid() { }
285e902e1a71a4bb31b9db665a7ecdb853d1538eb39Ben Murdoch}
286