PageRenderTime 29ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/carrot-garden/carrot-jnlper
JavaScript | 122 lines | 70 code | 22 blank | 30 comment | 2 complexity | 8d261041b5c48577ddcc290baf686a4d MD5 | raw file
  1. /**
  2. File Name: boolean-005.js
  3. Description:
  4. A java.lang.Boolean object field should be read as a JavaScript JavaObject.
  5. @author christine@netscape.com
  6. @version 1.00
  7. */
  8. var SECTION = "LiveConnect";
  9. var VERSION = "1_3";
  10. var TITLE = "Java Boolean Object to JavaScript Object: Test #1";
  11. var HEADER = SECTION + " " + TITLE;
  12. var tc = 0;
  13. var testcasesII = new Array();
  14. startTest();
  15. writeHeaderToLog( HEADER );
  16. // In all test cases, the expected type is "object"
  17. var E_TYPE = "object";
  18. // The JavaScrpt [[Class]] of a JavaObject should be JavaObject"
  19. var E_JSCLASS = "[object JavaObject]";
  20. // The Java class of this object is java.lang.Boolean.
  21. var E_JAVACLASS = app.Packages.java.lang.Class.forName( "java.lang.Boolean" );
  22. // Create arrays of actual results (java_array) and expected results
  23. // (test_array).
  24. var java_array = new Array();
  25. var test_array = new Array();
  26. try {
  27. var i = 0;
  28. // Test for java.lang.Boolean.FALSE, which is a Boolean object.
  29. java_array[i] = new JavaValue( app.Packages.java.lang.Boolean.FALSE );
  30. test_array[i] = new TestValue( "app.Packages.java.lang.Boolean.FALSE",
  31. false );
  32. i++;
  33. // Test for java.lang.Boolean.TRUE, which is a Boolean object.
  34. java_array[i] = new JavaValue( app.Packages.java.lang.Boolean.TRUE );
  35. test_array[i] = new TestValue( "app.Packages.java.lang.Boolean.TRUE",
  36. true );
  37. i++;
  38. for ( i = 0; i < java_array.length; i++ ) {
  39. CompareValues( java_array[i], test_array[i] );
  40. }
  41. test();
  42. } catch (e) {
  43. writeExceptionToLog(e);
  44. }
  45. function CompareValues( javaval, testval ) {
  46. // Check booleanValue()
  47. testcasesII[testcasesII.length] = new TestCase( SECTION,
  48. "("+testval.description+").booleanValue()",
  49. testval.value,
  50. javaval.value );
  51. // Check typeof, which should be E_TYPE
  52. testcasesII[testcasesII.length] = new TestCase( SECTION,
  53. "typeof (" + testval.description +")",
  54. testval.type,
  55. javaval.type );
  56. /*
  57. // Check JavaScript class, which should be E_JSCLASS
  58. testcasesII[testcasesII.length] = new TestCase( SECTION,
  59. "(" + testval.description +").getJSClass()",
  60. testval.jsclass,
  61. javaval.jsclass );
  62. */
  63. // Check Java class, which should equal() E_JAVACLASS
  64. testcasesII[testcasesII.length] = new TestCase( SECTION,
  65. "(" + testval.description +").getClass().equals( " + E_JAVACLASS +" )",
  66. true,
  67. javaval.javaclass.equals( testval.javaclass ) );
  68. }
  69. function JavaValue( value ) {
  70. // java.lang.Object.getClass() returns the Java Object's class.
  71. this.javaclass = value.getClass();
  72. // Object.prototype.toString will show its JavaScript wrapper object.
  73. // value.__proto__.getJSClass = Object.prototype.toString;
  74. // this.jsclass = value.getJSClass();
  75. this.value = value.booleanValue();
  76. this.type = typeof value;
  77. return this;
  78. }
  79. function TestValue( description, value ) {
  80. this.description = description;
  81. this.value = value;
  82. this.type = E_TYPE;
  83. this.javaclass = E_JAVACLASS;
  84. this.jsclass = E_JSCLASS;
  85. return this;
  86. }
  87. function test() {
  88. for ( tc=0; tc < testcasesII.length; tc++ ) {
  89. testcasesII[tc].passed = writeTestCaseResult(
  90. testcasesII[tc].expect,
  91. testcasesII[tc].actual,
  92. testcasesII[tc].description +" = "+
  93. testcasesII[tc].actual );
  94. testcasesII[tc].reason += ( testcasesII[tc].passed ) ? "" : "wrong value ";
  95. }
  96. stopTest();
  97. return ( testcasesII );
  98. }