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

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

https://github.com/carrot-garden/carrot-jnlper
JavaScript | 134 lines | 76 code | 25 blank | 33 comment | 2 complexity | e0360e482fbc77be1d2ab458df7559f6 MD5 | raw file
  1. /**
  2. File Name: boolean-005.js
  3. Description:
  4. A java.lang.Boolean object 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 #3";
  11. var HEADER = SECTION + " " + TITLE;
  12. var tc = 0;
  13. var testcasesIV = 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 = 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( java.lang.Boolean.FALSE );
  30. test_array[i] = new TestValue( "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( java.lang.Boolean.TRUE );
  35. test_array[i] = new TestValue( "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. testcasesIV[testcasesIV.length] = new TestCase( SECTION,
  48. "("+testval.description+").booleanValue()",
  49. testval.value,
  50. javaval.value );
  51. // Check typeof, which should be E_TYPE
  52. testcasesIV[testcasesIV.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. testcasesIV[testcasesIV.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. testcasesIV[testcasesIV.length] = new TestCase( SECTION,
  65. "(" + testval.description +").getClass().equals( " + E_JAVACLASS +" )",
  66. true,
  67. javaval.javaclass.equals( testval.javaclass ) );
  68. // Check string representation
  69. testcasesIV[testcasesIV.length] = new TestCase( SECTION,
  70. "("+ testval.description+") + ''",
  71. testval.string,
  72. javaval.string );
  73. }
  74. function JavaValue( value ) {
  75. // java.lang.Object.getClass() returns the Java Object's class.
  76. this.javaclass = value.getClass();
  77. // __proto__ of Java objects is not supported in LC2.
  78. // Object.prototype.toString will show its JavaScript wrapper object.
  79. // value.__proto__.getJSClass = Object.prototype.toString;
  80. // this.jsclass = value.getJSClass();
  81. this.string = value + "";
  82. //print( this.string );
  83. this.value = value.booleanValue();
  84. this.type = typeof value;
  85. return this;
  86. }
  87. function TestValue( description, value ) {
  88. this.description = description;
  89. this.string = String( value );
  90. this.value = value;
  91. this.type = E_TYPE;
  92. this.javaclass = E_JAVACLASS;
  93. this.jsclass = E_JSCLASS;
  94. return this;
  95. }
  96. function test() {
  97. for ( tc=0; tc < testcasesIV.length; tc++ ) {
  98. testcasesIV[tc].passed = writeTestCaseResult(
  99. testcasesIV[tc].expect,
  100. testcasesIV[tc].actual,
  101. testcasesIV[tc].description +" = "+
  102. testcasesIV[tc].actual );
  103. testcasesIV[tc].reason += ( testcasesIV[tc].passed ) ? "" : "wrong value ";
  104. }
  105. stopTest();
  106. return ( testcasesIV );
  107. }