| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'array-001.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
var SECTION = "LiveConnect"; |
| 32 |
var VERSION = "1_3"; |
| 33 |
var TITLE = "Java Array to JavaScript JavaArray object"; |
| 34 |
|
| 35 |
startTest(); |
| 36 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
var E_TYPE = "object"; |
| 42 |
var E_CLASS = "[object JavaArray]"; |
| 43 |
var test_array = new Array(); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
var java_array = new Array(); |
| 49 |
|
| 50 |
var i = 0; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
var byte_array = ( new java.lang.String("hello") ).getBytes(); |
| 55 |
|
| 56 |
java_array[i] = new JavaValue( byte_array ); |
| 57 |
test_array[i] = new TestValue( "( new java.lang.String('hello') ).getBytes()", |
| 58 |
["h".charCodeAt(0), |
| 59 |
"e".charCodeAt(0), |
| 60 |
"l".charCodeAt(0), |
| 61 |
"l".charCodeAt(0), |
| 62 |
"o".charCodeAt(0) ], |
| 63 |
"[B" |
| 64 |
); |
| 65 |
i++; |
| 66 |
|
| 67 |
|
| 68 |
var char_array = ( new java.lang.String("rhino") ).toCharArray(); |
| 69 |
|
| 70 |
java_array[i] = new JavaValue( char_array ); |
| 71 |
test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()", |
| 72 |
[ "r".charCodeAt(0), |
| 73 |
"h".charCodeAt(0), |
| 74 |
"i".charCodeAt(0), |
| 75 |
"n".charCodeAt(0), |
| 76 |
"o".charCodeAt(0)], |
| 77 |
"[C"); |
| 78 |
i++; |
| 79 |
|
| 80 |
|
| 81 |
for ( i = 0; i < java_array.length; i++ ) { |
| 82 |
CompareValues( java_array[i], test_array[i] ); |
| 83 |
} |
| 84 |
|
| 85 |
test(); |
| 86 |
|
| 87 |
function CompareValues( javaval, testval ) { |
| 88 |
|
| 89 |
|
| 90 |
for ( var i = 0; i < testval.value.length; i++ ) { |
| 91 |
new TestCase( SECTION, |
| 92 |
"("+ testval.description +")["+i+"]", |
| 93 |
testval.value[i], |
| 94 |
javaval.value[i] ); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
new TestCase( SECTION, |
| 100 |
"typeof (" + testval.description +")", |
| 101 |
testval.type, |
| 102 |
javaval.type ); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
new TestCase(SECTION, |
| 107 |
"The Java Class of ( "+ testval.description +" )", |
| 108 |
testval.lcclass +"", |
| 109 |
javaval.lcclass +""); |
| 110 |
|
| 111 |
} |
| 112 |
function JavaValue( value ) { |
| 113 |
this.value = value; |
| 114 |
this.type = typeof value; |
| 115 |
this.classname = this.value.getClass(); |
| 116 |
|
| 117 |
jlo_class = java.lang.Class.forName("java.lang.Object") |
| 118 |
jlo_getClass_method = jlo_class.getMethod("getClass", null) |
| 119 |
this.lcclass = jlo_getClass_method.invoke(value, null ); |
| 120 |
|
| 121 |
return this; |
| 122 |
} |
| 123 |
function TestValue( description, value, lcclass ) { |
| 124 |
this.lcclass = java.lang.Class.forName( lcclass ); |
| 125 |
this.description = description; |
| 126 |
this.value = value; |
| 127 |
this.type = E_TYPE; |
| 128 |
this.classname = E_CLASS; |
| 129 |
return this; |
| 130 |
} |