PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/carrot-jdk6-jnlp-windows/src/plugin/share/classes/sun/plugin2/test/liveconnect/mozillaTests/number-002.js

https://github.com/carrot-garden/carrot-jnlper
JavaScript | 157 lines | 86 code | 27 blank | 44 comment | 2 complexity | f447922e6a1dae7da765fe2b2580a777 MD5 | raw file
  1. /**
  2. File Name: number-002.js
  3. Description:
  4. Accessing a Java field whose value is one of the primitive Java types
  5. below, JavaScript should read this as a JavaScript Number object.
  6. byte
  7. short
  8. int
  9. long
  10. float
  11. double
  12. char
  13. To test this:
  14. 1. Instantiate a new Java object that has a field whose type one of
  15. the above primitive Java types, OR get the value of a class's static
  16. field.
  17. 2. Check the value of the returned object
  18. 3. Check the type of the returned object, which should be "object"
  19. 4. Check the class of the returned object using Object.prototype.toString,
  20. which should return "[object Number]"
  21. It is an error if the type of the JavaScript variable is "number" or if
  22. its class is JavaObject.
  23. @author christine@netscape.com
  24. @version 1.00
  25. */
  26. var SECTION = "LiveConnect";
  27. var VERSION = "1_3";
  28. var TITLE = "Java Number Primitive to JavaScript Object: Test #2";
  29. var HEADER = SECTION + " " + TITLE;
  30. var tc = 0;
  31. var testcasesI = new Array();
  32. startTest();
  33. writeHeaderToLog( HEADER );
  34. // In all test cases, the expected type is "object, and the expected
  35. // class is "Number"
  36. var E_TYPE = "number";
  37. // Create arrays of actual results (java_array) and expected results
  38. // (test_array).
  39. var java_array = new Array();
  40. var test_array = new Array();
  41. try {
  42. var i = 0;
  43. // Get a static java field whose type is byte.
  44. java_array[i] = new JavaValue( app.Packages.java.lang.Byte.MIN_VALUE );
  45. test_array[i] = new TestValue( "app.Packages.java.lang.Byte.MIN_VALUE",
  46. -128 )
  47. i++;
  48. // Get a static java field whose type is short.
  49. java_array[i] = new JavaValue( app.Packages.java.lang.Short.MIN_VALUE );
  50. test_array[i] = new TestValue( "app.Packages.java.lang.Short.MIN_VALUE",
  51. -32768 )
  52. i++;
  53. // Get a static java field whose type is int.
  54. java_array[i] = new JavaValue( app.Packages.java.lang.Integer.MIN_VALUE );
  55. test_array[i] = new TestValue( "app.Packages.java.lang.Integer.MIN_VALUE",
  56. -2147483648 )
  57. i++;
  58. // Instantiate a class, and get a field in that class whose type is int.
  59. var java_rect = new app.Packages.java.awt.Rectangle( 1,2,3,4 );
  60. java_array[i] = new JavaValue( java_rect.width );
  61. test_array[i] = new TestValue( "java_object = new app.Packages.java.awt.Rectangle( 1,2,3,4 ); java_object.width",
  62. 3 );
  63. i++;
  64. // Get a static java field whose type is long.
  65. java_array[i] = new JavaValue( app.Packages.java.lang.Long.MIN_VALUE );
  66. test_array[i] = new TestValue( "app.Packages.java.lang.Long.MIN_VALUE",
  67. -9223372036854776000 );
  68. i++;
  69. // Get a static java field whose type is float.
  70. java_array[i] = new JavaValue( app.Packages.java.lang.Float.MAX_VALUE );
  71. test_array[i] = new TestValue( "app.Packages.java.lang.Float.MAX_VALUE",
  72. 3.4028234663852886e+38 )
  73. i++;
  74. // Get a static java field whose type is double.
  75. java_array[i] = new JavaValue( app.Packages.java.lang.Double.MAX_VALUE );
  76. test_array[i] = new TestValue( "app.Packages.java.lang.Double.MAX_VALUE",
  77. 1.7976931348623157e+308 )
  78. i++;
  79. // Get a static java field whose type is char.
  80. java_array[i] = new JavaValue( app.Packages.java.lang.Character.MAX_VALUE );
  81. test_array[i] = new TestValue( "app.Packages.java.lang.Character.MAX_VALUE",
  82. 65535 );
  83. i++;
  84. for ( i = 0; i < java_array.length; i++ ) {
  85. CompareValues( java_array[i], test_array[i] );
  86. }
  87. test();
  88. } catch (e) {
  89. writeExceptionToLog(e);
  90. }
  91. function CompareValues( javaval, testval ) {
  92. // Check value
  93. testcasesI[testcasesI.length] = new TestCase( SECTION,
  94. testval.description,
  95. testval.value,
  96. javaval.value );
  97. // Check type.
  98. testcasesI[testcasesI.length] = new TestCase( SECTION,
  99. "typeof (" + testval.description +")",
  100. testval.type,
  101. javaval.type );
  102. }
  103. function JavaValue( value ) {
  104. this.value = value.valueOf();
  105. this.type = typeof value;
  106. return this;
  107. }
  108. function TestValue( description, value, type ) {
  109. this.description = description;
  110. this.value = value;
  111. this.type = E_TYPE;
  112. // this.classname = classname;
  113. return this;
  114. }
  115. function test() {
  116. for ( tc=0; tc < testcasesI.length; tc++ ) {
  117. testcasesI[tc].passed = writeTestCaseResult(
  118. testcasesI[tc].expect,
  119. testcasesI[tc].actual,
  120. testcasesI[tc].description +" = "+
  121. testcasesI[tc].actual );
  122. testcasesI[tc].reason += ( testcasesI[tc].passed ) ? "" : "wrong value ";
  123. }
  124. stopTest();
  125. return ( testcasesI );
  126. }