PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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