PageRenderTime 65ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/carrot-garden/carrot-jnlper
JavaScript | 102 lines | 61 code | 15 blank | 26 comment | 2 complexity | 191279ac616634e0188a3cf994ea5173 MD5 | raw file
  1. /**
  2. File Name: boolean-001.js
  3. Description:
  4. If a Java method returns a Java boolean primitive, JavaScript should
  5. read the value as a JavaScript boolean primitive.
  6. To test this:
  7. 1. Call a java method that returns a Java boolean primitive.
  8. 2. Check the type of the returned type, which should be "boolean"
  9. 3. Check the value of the returned type, which should be true or false.
  10. It is an error if the returned value is read as a JavaScript Boolean
  11. object.
  12. @author christine@netscape.com
  13. @version 1.00
  14. */
  15. var SECTION = "LiveConnect";
  16. var VERSION = "1_3";
  17. var TITLE = "Java Boolean Primitive to JavaScript Object";
  18. var HEADER = SECTION + " " + TITLE;
  19. var tc = 0;
  20. var testcasesI = new Array();
  21. startTest();
  22. writeHeaderToLog( HEADER );
  23. // In all test cases, the expected type is "boolean"
  24. var E_TYPE = "boolean";
  25. // Create arrays of actual results (java_array) and expected results
  26. // (test_array).
  27. var java_array = new Array();
  28. var test_array = new Array();
  29. try {
  30. var i = 0;
  31. // Call a java method that returns true
  32. java_array[i] = new JavaValue( (new app.Packages.java.lang.Boolean(true)).booleanValue() );
  33. test_array[i] = new TestValue( "(new app.Packages.java.lang.Boolean(true)).booleanValue()",
  34. true )
  35. i++;
  36. // Call a java method that returns false
  37. java_array[i] = new JavaValue( (new app.Packages.java.lang.Boolean(false)).booleanValue() );
  38. test_array[i] = new TestValue( "(new app.Packages.java.lang.Boolean(false)).booleanValue()",
  39. false )
  40. i++;
  41. for ( i = 0; i < java_array.length; i++ ) {
  42. CompareValues( java_array[i], test_array[i] );
  43. }
  44. test();
  45. } catch (e) {
  46. writeExceptionToLog(e);
  47. }
  48. function CompareValues( javaval, testval ) {
  49. // Check value
  50. testcasesI[testcasesI.length] = new TestCase( SECTION,
  51. testval.description,
  52. testval.value,
  53. javaval.value );
  54. // Check type.
  55. testcasesI[testcasesI.length] = new TestCase( SECTION,
  56. "typeof (" + testval.description +")",
  57. testval.type,
  58. javaval.type );
  59. }
  60. function JavaValue( value ) {
  61. this.value = value;
  62. this.type = typeof value;
  63. return this;
  64. }
  65. function TestValue( description, value ) {
  66. this.description = description;
  67. this.value = value;
  68. this.type = E_TYPE;
  69. return this;
  70. }
  71. function test() {
  72. for ( tc=0; tc < testcasesI.length; tc++ ) {
  73. testcasesI[tc].passed = writeTestCaseResult(
  74. testcasesI[tc].expect,
  75. testcasesI[tc].actual,
  76. testcasesI[tc].description +" = "+
  77. testcasesI[tc].actual );
  78. testcasesI[tc].reason += ( testcasesI[tc].passed ) ? "" : "wrong value ";
  79. }
  80. stopTest();
  81. return ( testcasesI );
  82. }