Home | History | Annotate | Download | only in assets
      1 <html>
      2 <head>
      3 <script type="text/javascript">
      4 
      5 function testPrimitiveTypes() {
      6   return JNIBindingsTest.testPrimitiveTypes(100, 'c', 123.34567890, 456.789, 1234567, 1234567890, 6000, true);
      7 }
      8 
      9 function testObjectTypes() {
     10   return JNIBindingsTest.testObjectTypes("Foo", "", {"foo":"bar"}, {});
     11 }
     12 
     13 function testArray() {
     14   return JNIBindingsTest.testArray([1,2,3], ['d', 'o', 'g'], [1.2, 2.3, 3.4], [4.5,5.6,6.7], [1,2,3], [4,5,6], [7,8,9], [true, false]);
     15 }
     16 
     17 function testObjectArray() {
     18   return JNIBindingsTest.testObjectArray(['Hello', 'World', '!'], [], [{"foo":"bar"}]);
     19 }
     20 
     21 function testObjectMembers() {
     22   var foo = {"bool":true,
     23              "byte":101,
     24              "char":'d',
     25              "double":123.456,
     26              "float":456.789,
     27              "int":102,
     28              "long":103,
     29              "short":104,
     30              "string":"Hello World",
     31              "array": [1,2,3],
     32              "objArray":["foo", "bar", "baz"],
     33              "object": {"foo":1}
     34   };
     35   return JNIBindingsTest.testObjectMembers(foo.bool, foo.byte, foo.char, foo.double, foo.float, foo.int, foo.long, foo.short, foo.string, foo.array, foo.objArray, foo.object);
     36 }
     37 
     38 function testJSPrimitivesToStringsInJava() {
     39     return JNIBindingsTest.testJSPrimitivesToStringsInJava(123, null, 456.789, true, 'd', undefined);
     40 }
     41 
     42 function testJavaReturnTypes() {
     43   var expectedBoolReturn = true;
     44   var expectedByteReturn = 1;
     45   var expectedCharReturn = 98; // 'b'; Currently bindings in JSC and V8 return chars as their ASCII equivalent.
     46   var expectedDoubleReturn = 123.456;
     47   var expectedFloatReturn = 456.789;
     48   var expectedIntReturn = 123;
     49   var expectedLongReturn = 1234;
     50   var expectedShortReturn = 12345;
     51   var expectedStringReturn = "Hello World!";
     52 
     53   var returned = JNIBindingsTest.returnBool();
     54   if (returned != expectedBoolReturn) {
     55     appendLog("returnBool() failed: expected "+ expectedBoolReturn +", got " + returned);
     56     return false;
     57   }
     58 
     59   returned = JNIBindingsTest.returnByte();
     60   if (returned != expectedByteReturn) {
     61     appendLog("returnByte() failed: expected "+ expectedByteReturn +", got " + returned);
     62     return false;
     63   }
     64 
     65   returned = JNIBindingsTest.returnChar();
     66   if (returned != expectedCharReturn) {
     67     appendLog("returnChar() failed: expected "+ expectedCharReturn +", got " + returned);
     68     return false;
     69   }
     70 
     71   returned = JNIBindingsTest.returnDouble();
     72   if (returned != expectedDoubleReturn) {
     73     appendLog("returnDouble() failed: expected "+ expectedDoubleReturn +", got " + returned);
     74     return false;
     75   }
     76 
     77   returned = JNIBindingsTest.returnFloat();
     78   if (Math.abs(returned - expectedFloatReturn) > 0.001) {
     79     appendLog("returnFloat() failed: expected "+ expectedFloatReturn +", got " + returned);
     80     return false;
     81   }
     82 
     83   returned = JNIBindingsTest.returnInt();
     84   if (returned != expectedIntReturn) {
     85     appendLog("returnInt() failed: expected "+ expectedIntReturn +", got " + returned);
     86     return false;
     87   }
     88 
     89   returned = JNIBindingsTest.returnLong();
     90   if (returned != expectedLongReturn) {
     91     appendLog("returnLong() failed: expected "+ expectedLongReturn +", got " + returned);
     92     return false;
     93   }
     94 
     95   returned = JNIBindingsTest.returnShort();
     96   if (returned != expectedShortReturn) {
     97     appendLog("returnShort() failed: expected "+ expectedShortReturn +", got " + returned);
     98     return false;
     99   }
    100 
    101   returned = JNIBindingsTest.returnString();
    102   if (returned != expectedStringReturn) {
    103     appendLog("returnString() failed: expected "+ expectedStringReturn +", got " + returned);
    104     return false;
    105   }
    106 
    107   returned = JNIBindingsTest.returnObject();
    108   if (returned == null) {
    109     appendLog("returnObject() failed: expected non-null, got " + returned);
    110     return false;
    111   } else if (returned.x != 0) {
    112     // EMULATE_JSC_BINDINGS
    113     // Note: the Java sets the x property to 123. JSC and V8 do not support object
    114     // members in the bindings though.
    115     appendLog("returnObject() failed: expected 'x' property 0, got " + returned.x)
    116     return false;
    117   } else if (returned.s != undefined) {
    118     // EMULATE_JSC_BINDINGS
    119     // Note that the java class returned has s set to Hello World. JSC and V8 do not support
    120     // getting properties.
    121     appendLog("returnObject() failed: expected 's' property undefined, got " + returned.s);
    122     return false;
    123   } else if (!returned.aMethod()) {
    124     appendLog("returnObject() failed: expected 'aMethod' method to return true, got " + returned.aMethod());
    125     return false;
    126   } else if (returned.anotherMethod() != "Hello World") {
    127     appendLog("returnObject() failed: expected 'anotherMethod' to return 'Hello World' got "+ returned.anotherMethod());
    128     return false;
    129   }
    130 
    131   returned = JNIBindingsTest.returnArray();
    132   if (returned != null) {
    133     appendLog("returnArray() failed: expected null, got " + returned);
    134     return false;
    135   }
    136 
    137   returned = JNIBindingsTest.returnVoid();
    138   if (returned != null) {
    139     appendLog("returnVoid() failed: expected null, got " + returned);
    140     return false;
    141   }
    142 
    143   return true;
    144 }
    145 
    146 function getIfaceProperties() {
    147   if (JNIBindingsTest.mInt != 0) {
    148     // EMULATE_JSC_BINDINGS
    149     // Note: the Java sets the mInt property to 123. JSC and V8 do not support object
    150     // members in the bindings though.
    151     appendLog("getIfaceProperties() failed: expected mInt = 0, got " + JNIBindingsTest.mInt);
    152     return false;
    153   }
    154 
    155   if (JNIBindingsTest.mString != undefined) {
    156     // EMULATE_JSC_BINDINGS
    157     // Note that the java class returned has s set to Hello World. JSC and V8 do not support
    158     // getting properties.
    159     appendLog("getIfaceProperties() failed: expected mString = 'Hello World', got " + JNIBindingsTest.mString);
    160     return false;
    161   }
    162 
    163   return true;
    164 }
    165 
    166 function testParameterTypeMismatch() {
    167   return JNIBindingsTest.testParameterTypeMismatch("dog");
    168 }
    169 
    170 function appendLog(msg) {
    171   var log = document.getElementById("status");
    172   log.innerHTML += "<br/>" + msg;
    173 }
    174 
    175 function runTests() {
    176 
    177   // Assume that if the test isn't done after 10s that we failed.
    178   window.setTimeout(function() { JNIBindingsTest.notifyComplete(); }, 10000);
    179 
    180   if (testPrimitiveTypes()) {
    181     appendLog("testPrimitiveTypes passed!");
    182   } else {
    183     appendLog("testPrimtiveTypes failed!");
    184   }
    185 
    186   if (testObjectTypes()) {
    187     appendLog("testObjectTypes passed!");
    188   } else {
    189     appendLog("testObjectTypes failed!");
    190   }
    191 
    192   if (testArray()) {
    193     appendLog("testArray passed!");
    194   } else {
    195     appendLog("testArray failed!");
    196   }
    197 
    198   if (testObjectArray()) {
    199     appendLog("testObjectArray passed!");
    200   } else {
    201     appendLog("testObjectArray failed!");
    202   }
    203 
    204   if (testObjectMembers()) {
    205     appendLog("testObjectMembers passed!");
    206   } else {
    207     appendLog("<br/>testObjectMembers failed!");
    208   }
    209 
    210   if (testJSPrimitivesToStringsInJava()) {
    211     appendLog("testJSPrimitivesToStringsInJava passed!");
    212   } else {
    213     appendLog("testJSPrimitivesToStringsInJava failed!");
    214   }
    215 
    216   if (testJavaReturnTypes()) {
    217     appendLog("testJavaReturnTypes passed!");
    218   } else {
    219     appendLog("testJavaReturnTypes failed!");
    220   }
    221 
    222   if (getIfaceProperties()) {
    223     appendLog("getIfaceProperties passed!");
    224   } else {
    225     appendLog("getIfaceProperties failed!");
    226   }
    227 
    228   if (testParameterTypeMismatch()) {
    229     appendLog("testParameterTypeMismatch passed!");
    230   } else {
    231     appendLog("testParameterTypeMismatch failed!");
    232   }
    233 
    234   JNIBindingsTest.notifyComplete();
    235 }
    236 </script>
    237 
    238 <body onload="runTests();">
    239 <p id="status">Running JNI Bindings test...</p>
    240 </body>
    241 </html>
    242