[rfc][icedtea-web] a new reproducer LiveConnect "function parameters" tests

Jana Fabrikova jfabriko at redhat.com
Tue Jan 15 04:59:54 PST 2013


Hello,

I have rewritten the JSToJFuncParam reproducer according to Adam's 
comments, please see the attached patch.

Jana


2013-01-15  Jana Fabrikova  <jfabriko at redhat.com>

* 
/tests/reproducers/simple/JSToJFuncParam/testcases/JSToJFuncParamTest.java:
adding 19 testcases - 18 based on the interactive Liveconnect JS->Java 
function parameter tests, 1 additional testcase for passing parameters 
of type JSObject (from JS to Java)

* /tests/reproducers/simple/JSToJFuncParam/srcs/JSToJFuncParam.java:
the applet whose methods are invoked from JS during the tests

* /tests/reproducers/simple/JSToJFuncParam/resources/JSToJava_FuncParam.js:
the JavaScript code for calling the applet methods from JS

* /tests/reproducers/simple/JSToJFuncParam/resources/jstoj-funcparam.jnlp:
java network launch protocol file for displaying applet in the html page

* /tests/reproducers/simple/JSToJFuncParam/resources/JSToJFuncParam.html:
the html page with java applet embedded, displayed in browser during the 
tests


On 12/12/2012 09:38 PM, Adam Domurad wrote:
> On 10/08/2012 07:33 AM, Jana Fabrikova wrote:
>> 2012-10-08 Jana Fabrikova <jfabriko at redhat.com>
>>
>> * /tests/reproducers/simple/JSToJFuncParam:
>> adding a new reproducer for the third LiveConnect
>> test (Tests for function parameter conversion when
>> calling Java functions from JavaScript.)
>
> Describing the individual files here is more standard I think
>
>>
>>
>> I would like to ask for review of the attached patch,
>> thank you,
>> Jana
>>
>
> [from another email:]
>> I would like to ask, if you can have a look at the following
>> reproducers, that I have send for review earlier (patches attached).
>> It may be the case, that they have the same errors as JSToJSet, but I
>> would like to
>
> Less-than-ideal perhaps, but error is a strong word, since the tests do
> work :)
>
>
> Sorry for letting these drop down the lists :) You can always ask for a
> review on IRC, or reply to the patch so that they reappear on the list.
>
> --------------------------------
>
> General comments for:
> JSToJFuncParam
> JSToJFuncReturn
> JSToJFuncResol
> JSToJTypeConv
>
> I'd avoid any filenames with the same name in reproducers. Because of
> how the reproducer system is implemented, one copy will 'win' and the
> rest will be overridden, making it hard to correctly update.
> For the case of 'DummyObject' I think the cleanest solution, since it so
> simple, is to have this object be defined inside the same class file.
>
> This goes doubly so for OverloadTestHelper1,2,3.
>
> For the case of JS*auxiliary.js files -- although I do not like the
> approach these files take, more on this later -- if multiple copies
> exist its best to put them in their own 'test folder' that only has
> resources. Since all tests are conveniently extracted into same
> directory they can be used as before.
>
> Another special case worthy of test is JSObject (for all JS<->J tests).
> It can be used to encapsulate any javascript object. Possibly use an
> object like { "key" : "value" } and test that it is correctly passed
> around (Note: In fact passing a java JSObject to javascript will not
> work correctly until my patch goes in).
>
> --------------------------------
> First off, JSToJFuncParam:
>
>
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/resources/JSToJFuncParam.html b/tests/reproducers/simple/JSToJFuncParam/resources/JSToJFuncParam.html
>>
>> new file mode 100644
>> --- /dev/null
>> +++
>> b/tests/reproducers/simple/JSToJFuncParam/resources/JSToJFuncParam.html
>> @@ -0,0 +1,98 @@
>> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> +<html lang="en-US">
>> + <head>
>> + <title>JavaScript to Java LiveConnect - function parameter
>> conversion</title>
>> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
>> +
>> + <script language="JavaScript" src="JSToJava_FuncParam.js"></script>
>> + <script language="JavaScript" src="JSToJ_auxiliary.js"></script>
>> +
>> + </head>
>> + <body>
>> +
>> + <h2> The JSToJFuncParam html page</h2>
>> +
>> + <applet code="JSToJFuncParam" width="1000" height="100"
>> name="JSToJFuncParam" id="jstojFuncParamApplet" MAYSCRIPT>
>> + <param name="jnlp_href" value="jstoj-funcparam.jnlp">
>> + </applet>
>> +
>> + <div id="messageDiv"></div>
>> +
>> + <script type="text/javascript">
>> + var urlArgs = document.URL.split("?");
>> + var testid = urlArgs[1];
>> +
>> + if( testid != null ){
>> + document.getElementById( 'jstojFuncParamApplet'
>> ).setStatusLabel(testid);
>> + appendMessageDiv(testid+"... ");
>> + }else{
>> + document.getElementById( 'jstojFuncParamApplet'
>> ).setStatusLabel("url without ?");
>> + appendMessageDiv("no url arguments...");
>> + }
>> +
>> + switch(testid){
>> + case "int":
>> + test_funcParam_int();
>> + break;
>> + case "double":
>> + test_funcParam_double();
>> + break;
>> + case "float":
>> + test_funcParam_float();
>> + break;
>> + case "long":
>> + test_funcParam_long();
>> + break;
>> + case "boolean":
>> + test_funcParam_boolean();
>> + break;
>> + case "char":
>> + test_funcParam_char();
>> + break;
>> + case "byte":
>> + test_funcParam_byte();
>> + break;
>> + case "charArray":
>> + test_funcParam_charArray();
>> + break;
>> + case "String":
>> + test_funcParam_String();
>> + break;
>> + case "Integer":
>> + test_funcParam_Integer();
>> + break;
>> + case "Double":
>> + test_funcParam_Double();
>> + break;
>> + case "Float":
>> + test_funcParam_Float();
>> + break;
>> + case "Long":
>> + test_funcParam_Long();
>> + break;
>> + case "Boolean":
>> + test_funcParam_Boolean();
>> + break;
>> + case "Byte":
>> + test_funcParam_Byte();
>> + break;
>> + case "Character":
>> + test_funcParam_Character();
>> + break;
>> + case "StringIntMixed":
>> + test_funcParam_StringIntMixed();
>> + break;
>> + case "DummyObjectArray":
>> + test_funcParam_DummyObjectArray();
>> + break;
>
> Needs some eval :)
>
>> + default:
>> + appletStdOutLn('jstojFuncParamApplet', "No argument in URL! Should
>> be e.g. JSToJFuncParam.html?int");
>> + document.getElementById( 'jstojFuncParamApplet'
>> ).setStatusLabel("Not a valid argument in URL! Should be e.g.
>> JSToJFuncParam.html?int");
>> + break;
>> + }
>> + afterTestsMessage('jstojFuncParamApplet');
>> +
>> + </script>
>> +
>> + </body>
>> +</html>
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/resources/JSToJ_auxiliary.js
>> b/tests/reproducers/simple/JSToJFuncParam/resources/JSToJ_auxiliary.js
>> new file mode 100644
>> --- /dev/null
>> +++
>> b/tests/reproducers/simple/JSToJFuncParam/resources/JSToJ_auxiliary.js
>> @@ -0,0 +1,69 @@
>> +/*
>> +JSToJ_auxiliary.js
>> +This file contains auxiliary JavaScript functions for LiveConnect
>> tests output,
>> +the following reproducers have this file as a common resource:
>> +- JSToJGet
>> +- JSToJSet
>> +- JSToJFuncParam
>> +- JSToJFuncReturn
>> +- JSToJFuncResol
>> +- JSToJTypeConv
>> +- JToJSGet
>> +- JToJSSet
>> +- JToJSFuncParam
>> +- JToJSFuncReturn
>> +- JToJSEval
>> +*/
>> +
>> +function check(actual, expected, expectedtype, testid, appletName ) {
>> + if (actual == expected) { //the same value
>> + if (typeof(actual) == expectedtype) { //the same type
>> + passTest( testid, appletName );
>> + } else {
>> + failTypeTest( testid, appletName, actual, expectedtype );
>> + }
>> + } else {
>> + failValTest( testid, appletName, actual, expected );
>> + }
>> +}
>> +
>> +function passTest( testid, appletName ){
>> + var passStr = "Test no."+testid+" - passed.";
>> + //applet stdout
>> + appletStdOut( appletName, passStr);
>> + //html page
>> + appendMessageDiv(passStr);
>> +}
>> +
>> +function failValTest( testid, appletName, actual, expected ){
>> + var failValStr = "Test no."+testid+" - failed, value mismatch.
>> expected:["+expected+"] found:["+actual+"].";
>> + //applet stdout
>> + appletStdOut( appletName, failValStr);
>> + //html page
>> + appendMessageDiv(failValStr);
>> +}
>> +
>> +function failTypeTest( testid, appletName, actual, expectedtype ){
>> + var failTypeStr = "Test no."+testid+" - failed, type mismatch.
>> expected:["+expectedtype+"] found:["+typeof(actual)+"].";
>> + //applet stdout
>> + appletStdOutLn( appletName, failTypeStr);
>> + //html page
>> + appendMessageDiv(failTypeStr);
>> +}
>> +
>> +function appletStdOut( appletName, str ){
>> + document.getElementById( appletName ).stdOutWrite( str );
>> +}
>> +
>> +function appletStdOutLn( appletName, str ){
>> + document.getElementById( appletName ).stdOutWriteln( str );
>> +}
>> +
>> +function afterTestsMessage( appletName ){
>> + document.getElementById( appletName ).stdOutWriteln("afterTests");
>> +}
>> +
>> +function appendMessageDiv( message ){
>> + var messageDiv = document.getElementById( 'messageDiv' );
>> + messageDiv.appendChild( document.createTextNode(message) );
>> +}
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/resources/JSToJava_FuncParam.jsb/tests/reproducers/simple/JSToJFuncParam/resources/JSToJava_FuncParam.js
>>
>> new file mode 100644
>> --- /dev/null
>> +++
>> b/tests/reproducers/simple/JSToJFuncParam/resources/JSToJava_FuncParam.js
>> @@ -0,0 +1,226 @@
>> +function test_funcParam_int(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 1;
>> + document.getElementById( appletName ).functioniParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_double()
>> +{
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 1.1;
>> + document.getElementById( appletName ).functiondParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_float(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 1.11;
>> + document.getElementById( appletName ).functionfParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_long(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 4294967300;
>> + document.getElementById( appletName ).functionlParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_boolean(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = true;
>> + document.getElementById( appletName ).functionbParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_char(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 75;
>> + document.getElementById( appletName ).functioncParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_byte(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 76;
>> + document.getElementById( appletName ).functionbyParamTest(send);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_charArray(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var arr = new Array();
>> + arr[0] = 80;
>> + arr[1] = 81;
>> + document.getElementById( appletName ).functioncaParamTest(arr);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_String(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = "$〒£€��ǣ";
>> + var reply = document.getElementById( appletName
>> ).functionsParamTest(send);
>> + var expectedreply = "$〒£€��ǣ:java.lang.String";
>> + check(reply, expectedreply, "string", " 9 - (regular string)",
>> appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Integer(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = "32";
>> + var reply = document.getElementById( appletName
>> ).functionIParamTest(send);
>> + var expectedreply = send+":java.lang.Integer"
>> + check(reply, expectedreply, "string", "10 - (Integer)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Double(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 32.0;
>> + var reply = document.getElementById( appletName
>> ).functionDParamTest(send);
>> + var expectedreply = "32.0:java.lang.Double";
>> + check(reply, expectedreply, "string", "11 - (Double)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Float(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 32.01;
>> + var reply = document.getElementById( appletName
>> ).functionFParamTest(send);
>> + var expectedreply = send+":java.lang.Float"
>> + check(reply, expectedreply, "string", "12 - (Float)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Long(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 4294967301;
>> + var reply = document.getElementById( appletName
>> ).functionLParamTest(send);
>> + var expectedreply = send+":java.lang.Long";
>> + check(reply, expectedreply, "string", "13 - (Long)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Boolean(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = true;
>> + var reply = document.getElementById( appletName
>> ).functionBParamTest(send);
>> + var expectedreply = send+":java.lang.Boolean";
>> + check(reply, expectedreply, "string", "14 - (Boolean)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Character(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 80;
>> + var reply = document.getElementById( appletName
>> ).functionCParamTest(send);
>> + var expectedreply = send+":java.lang.Character";
>> + check(reply, expectedreply, "string", "15 - (Character)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_Byte(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var send = 12;
>> + var reply = document.getElementById( appletName
>> ).functionBParamTest(send);
>> + var expectedreply = send+":java.lang.Byte";
>> + check(reply, expectedreply, "string", "16 - (Byte)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>
> Expected results in general belong in the test-case (the class in
> testcases folder). It is brittle for the programs being tested to decide
> whether they are correct. (and is causing a lot of replication in this
> case)
>
> I don't think the try catches are necessary.
>
> Some eval-based refactoring should be used here, as you did in your
> previous patch. The general idea is pass whats needed to run the test
> from the testcase, have the applet print what happened, and check it in
> the testcase. For this test, since a java parameter cannot receive an
> object of an invalid type, testing for type is somewhat redundant.
> Printing the value in the applet should suffice.
>
> As well, you should pass the function name being called via the testcase
> too. The javascript should be left as a very simple test driver.
>
>> +
>> +function test_funcParam_StringIntMixed(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var arr = new Array();
>> + arr[0] = "s1";
>> + arr[1] = 42;
>
> I think "test" is a good test string, '1' is a good test integer.
> Construct this using data based from the test case, though (as you did
> in your previous patch)
>
>> + document.getElementById( appletName ).functionsiaParamTest(arr);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> +function test_funcParam_DummyObjectArray(){
>> + var appletName = 'jstojFuncParamApplet';
>> + try{
>> + var arr = new Array();
>> + arr[0] = new (document.getElementById( appletName
>> ).Packages).DummyObject("DummyObject1");
>> + //arr[0] = new JSToJFuncParam.Packages.DummyObject("DummyObject1");
>> + //arr[0] = new java.lang.String("DummyObject1");
>> + arr[1] = new (document.getElementById( appletName
>> ).Packages).DummyObject("DummyObject2");
>> + //arr[1] = new JSToJFuncParam.Packages.DummyObject("DummyObject2");
>> + //arr[1] = new java.lang.String("DummyObject2");
>> + var reply = document.getElementById( appletName
>> ).functioncomplexaParamTest(arr);
>> + check(reply, "DummyObject1:DummyObject2", "string", "18 -
>> (DummyObject[] - complex)", appletName);
>> + }catch(e){
>> + appletStdOut( appletName, e );
>> + appendMessageDiv(e);
>> + }
>> +}
>> +
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/resources/jstoj-funcparam.jnlp
>> b/tests/reproducers/simple/JSToJFuncParam/resources/jstoj-funcparam.jnlp
>> new file mode 100644
>> --- /dev/null
>> +++
>> b/tests/reproducers/simple/JSToJFuncParam/resources/jstoj-funcparam.jnlp
>> @@ -0,0 +1,23 @@
>> +
>> +<?xml version="1.0" encoding="UTF-8"?>
>> +<jnlp spec="1.0+" codebase="" href="jstoj-funcparam.jnlp">
>> + <information>
>> + <title>JavaScript to Java LiveConnect - FuncParam</title>
>> + <vendor>RedHat</vendor>
>> + <homepage
>> href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
>>
>> + <description>LiveConnect - tests for function parameter conversion
>> when calling Java from JS.</description>
>> + </information>
>> + <resources>
>> + <!-- Application Resources -->
>> + <j2se version="1.6+"
>> + href="http://java.sun.com/products/autodl/j2se"/>
>> + <jar href="JSToJFuncParam.jar" main="true" />
>> +
>> + </resources>
>> + <applet-desc
>> + name="JS to J FuncParam"
>> + main-class="JSToJFuncParam"
>> + width="1000"
>> + height="100">
>> + </applet-desc>
>> +</jnlp>
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/srcs/DummyObject.java
>> b/tests/reproducers/simple/JSToJFuncParam/srcs/DummyObject.java
>> new file mode 100644
>> --- /dev/null
>> +++ b/tests/reproducers/simple/JSToJFuncParam/srcs/DummyObject.java
>> @@ -0,0 +1,15 @@
>> +public class DummyObject {
>> + private String str;
>> +
>> + public DummyObject(String s) {
>> + this.str = s;
>> + }
>> +
>> + public void setStr(String s) {
>> + this.str = s;
>> + }
>> +
>> + public String toString() {
>> + return str;
>> + }
>> +}
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/srcs/JSToJFuncParam.java
>> b/tests/reproducers/simple/JSToJFuncParam/srcs/JSToJFuncParam.java
>> new file mode 100644
>> --- /dev/null
>> +++ b/tests/reproducers/simple/JSToJFuncParam/srcs/JSToJFuncParam.java
>> @@ -0,0 +1,176 @@
>> +import java.applet.*;
>> +import java.awt.*;
>> +
>> +public class JSToJFuncParam extends Applet {
>> +
>> + public String[] outputStrings = { "Test no. 1 - (int)",
>> + "Test no. 2 - (double)", "Test no. 3 - (float)",
>> + "Test no. 4 - (long)", "Test no. 5 - (boolean)",
>> + "Test no. 6 - (char)", "Test no. 7 - (byte)",
>> + "Test no. 8 - (char[] - simple primitive)",
>> + "Test no. 9 - (regular string)", "Test no.10 - (Integer)",
>> + "Test no.11 - (Double)", "Test no.12 - (Float)",
>> + "Test no.13 - (Long)", "Test no.14 - (Boolean)",
>> + "Test no.15 - (Character)", "Test no.16 - (Byte)",
>> + "Test no.17 - (String/Int[] - mixed)",
>> + "Test no.18 - (DummyObject[] - complex)" };
>> +
>> + private Label statusLabel;
>> +
>> + public void init() {
>> + setLayout(new BorderLayout());
>> + statusLabel = new Label();
>> + add(statusLabel);
>> + String initStr = "JSToJFuncParam applet initialized.";
>> + System.out.println(initStr);
>> + statusLabel.setText(initStr);
>> + }
>> +
>> + public void functioniParamTest(int i) {
>> + String ret = Integer.toString(i);
>> + checkAndOutput(0, i == 1, true, "1", ret);
>> + }
>> +
>> + public void functiondParamTest(double d) {
>> + String ret = Double.toHexString(d);
>> + String h = Double.toHexString(1.1);
>> + checkAndOutput(1, d == 1.1, true, h, ret);
>> + }
>> +
>> + public void functionfParamTest(float f) {
>> + String ret = Float.toHexString(f);
>> + Float F = new Float("1.11");
>> + String h = Float.toHexString(F);
>> + checkAndOutput(2, h.equals(ret), true, h, ret);
>> + }
>> +
>> + public void functionlParamTest(long l) {
>> + String ret = Long.toString(l);
>> + checkAndOutput(3, l == 4294967300L, true, "4294967300", ret);
>> + }
>> +
>> + public void functionbParamTest(boolean b) {
>> + String ret = Boolean.toString(b);
>> + checkAndOutput(4, b == true, true, "true", ret);
>> + }
>> +
>> + public void functioncParamTest(char c) {
>> + String ret = Character.toString(c);
>> + checkAndOutput(5, c == 'K', true, "K", ret);
>> + }
>> +
>> + public void functionbyParamTest(byte b) {
>> + String ret = Byte.toString(b);
>> + checkAndOutput(6, b == 76, true, "76", ret);
>> + }
>> +
>> + public void functioncaParamTest(char[] ca) {
>> +
>> + String ret = "";
>> + ret += ca[0];
>> + for (int i = 1; i < ca.length; i++) {
>> + ret += ":" + ca[i];
>> + }
>> +
>> + checkAndOutput(7, (ca[0] == 'P') && (ca[1] == 'Q'), true, "P:Q", ret);
>> + }
>> +
>> + public String functionsParamTest(String s) {
>> + return s + ":" + s.getClass().getName();
>> + }
>> +
>> + public String functionIParamTest(Integer p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionDParamTest(Double p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionFParamTest(Float p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionLParamTest(Long p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionBParamTest(Boolean p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionCParamTest(Character p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public String functionBParamTest(Byte p) {
>> + String ret = p.toString() + ":" + p.getClass().getName();
>> + return ret;
>> + }
>> +
>> + public void functionsiaParamTest(String[] s) {
>> +
>> + String ret = s[0];
>> + for (int i = 1; i < s.length; i++) {
>> + ret += ":" + s[i];
>> + }
>> + checkAndOutput(16, (s[0].equals("s1")) && (s[1].equals("42")), true,
>> + "s1:42", ret);
>> + }
>> +
>> + public String functioncomplexaParamTest(DummyObject[] ca) {
>> + String ret = ca[0].toString();
>> + for (int i = 1; i < ca.length; i++) {
>> + ret += ":" + ca[i].toString();
>> + }
>> +
>> + return ret;
>> + }
>
> These should all simply print out the value via System.out.println(..);
> In the case of arrays you can use System.out.println(Arrays.toString(..));
> I think the names could also be shorter, eg I think the resulting class
> should look like ...
>
> public class JSToJFuncParam extends Applet {
> public void intParam(int i) {
> System.out.println(i);
> }
> public void floatParam(float f) {
> System.out.println(f);
> }
> // etc...
> }
>
> All the checking code should be in testcases/
>
>> +
>> + // auxiliary methods writing fail/pass to stdout
>> + public void checkAndOutput(int index, boolean valsEq, boolean typesEq,
>> + String expected, String found) {
>> + String outStr = "";
>> + if (valsEq) {
>> + if (typesEq) {
>> + outStr = outputStrings[index] + " - passed.";
>> + } else {
>> + outStr = outputStrings[index] + " - failed, type mismatch";
>> + outStr += " expected:[" + expected + "] found:[" + found + "].";
>> + }
>> + } else {
>> + outStr = outputStrings[index] + " - failed, value mismatch";
>> + outStr += " expected:[" + expected + "] found:[" + found + "].";
>> + }
>> + System.out.println(outStr);
>> + statusLabel.setText(outStr);
>> + }
>> +
>> + // auxiliary method for setting the statusLabel text:
>> + public void setStatusLabel(String s) {
>> + statusLabel.setText(s);
>> + }
>> +
>> + // auxiliary methods for writing to stdout and stderr:
>> + public void stdOutWrite(String s) {
>> + System.out.print(s);
>> + }
>> +
>> + public void stdErrWrite(String s) {
>> + System.err.print(s);
>> + }
>> +
>> + public void stdOutWriteln(String s) {
>> + System.out.println(s);
>> + }
>> +
>> + public void stdErrWriteln(String s) {
>> + System.err.println(s);
>> + }
>> +}
>> diff --git
>> a/tests/reproducers/simple/JSToJFuncParam/testcases/JSToJFuncParamTest.javab/tests/reproducers/simple/JSToJFuncParam/testcases/JSToJFuncParamTest.java
>>
>> new file mode 100644
>> --- /dev/null
>> +++
>> b/tests/reproducers/simple/JSToJFuncParam/testcases/JSToJFuncParamTest.java
>>
>> @@ -0,0 +1,278 @@
>> +/* JSToJFuncParamTest.java
>> +Copyright (C) 2012 Red Hat, Inc.
>> +
>> +This file is part of IcedTea.
>> +
>> +IcedTea is free software; you can redistribute it and/or
>> +modify it under the terms of the GNU General Public License as
>> published by
>> +the Free Software Foundation, version 2.
>> +
>> +IcedTea is distributed in the hope that it will be useful,
>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>> +General Public License for more details.
>> +
>> +You should have received a copy of the GNU General Public License
>> +along with IcedTea; see the file COPYING. If not, write to
>> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
>> Boston, MA
>> +02110-1301 USA.
>> +
>> +Linking this library statically or dynamically with other modules is
>> +making a combined work based on this library. Thus, the terms and
>> +conditions of the GNU General Public License cover the whole
>> +combination.
>> +
>> +As a special exception, the copyright holders of this library give you
>> +permission to link this library with independent modules to produce an
>> +executable, regardless of the license terms of these independent
>> +modules, and to copy and distribute the resulting executable under
>> +terms of your choice, provided that you also meet, for each linked
>> +independent module, the terms and conditions of the license of that
>> +module. An independent module is a module which is not derived from
>> +or based on this library. If you modify this library, you may extend
>> +this exception to your version of the library, but you are not
>> +obligated to do so. If you do not wish to do so, delete this
>> +exception statement from your version.
>> + */
>> +
>> +import net.sourceforge.jnlp.ProcessResult;
>> +import net.sourceforge.jnlp.ServerAccess;
>> +import net.sourceforge.jnlp.browsertesting.BrowserTest;
>> +import net.sourceforge.jnlp.browsertesting.Browsers;
>> +import net.sourceforge.jnlp.closinglisteners.CountingClosingListener;
>> +import net.sourceforge.jnlp.annotations.NeedsDisplay;
>> +import net.sourceforge.jnlp.annotations.TestInBrowsers;
>> +import org.junit.Assert;
>> +
>> +import org.junit.Test;
>> +
>> +public class JSToJFuncParamTest extends BrowserTest {
>> +
>> + public String[] testNames = { "int", "double", "float", "long",
>> "boolean",
>> + "char", "byte", "charArray", "String", "Integer", "Double",
>> + "Float", "Long", "Boolean", "Character", "Byte", "StringIntMixed",
>> + "DummyObjectArray" };
>> +
>> + public String[] outputStrings = { "Test no. 1 - (int)",
>> + "Test no. 2 - (double)", "Test no. 3 - (float)",
>> + "Test no. 4 - (long)", "Test no. 5 - (boolean)",
>> + "Test no. 6 - (char)", "Test no. 7 - (byte)",
>> + "Test no. 8 - (char[] - simple primitive)",
>> + "Test no. 9 - (regular string)", "Test no.10 - (Integer)",
>> + "Test no.11 - (Double)", "Test no.12 - (Float)",
>> + "Test no.13 - (Long)", "Test no.14 - (Boolean)",
>> + "Test no.15 - (Character)", "Test no.16 - (Byte)",
>> + "Test no.17 - (String/Int[] - mixed)",
>> + "Test no.18 - (DummyObject[] - complex)" };
>> +
>> + public String passStr = " - passed.";
>> + public String failValStr = " - failed, value mismatch.";
>> + public String failTypeStr = " - failed, type mismatch.";
>> + public String expStr = "expected:[";
>> + public String foundStr = "] found:[";
>> + public String endStr = "].";
>> +
>> + private final String exceptionStr = "xception";
>> + private final String initStr = "JSToJFuncParam applet initialized.";
>> + private final String afterStr = "afterTests";
>> +
>> + private class CountingClosingListenerImpl extends
>> CountingClosingListener {
>> +
>> + @Override
>> + protected boolean isAlowedToFinish(String s) {
>> + if (s.contains(exceptionStr)) {
>> + return true;
>> + }
>> + return (s.contains(initStr) && s.contains(afterStr));
>> + }
>> + }
>> +
>> + private void evaluateStdoutContents(int index, ProcessResult pr) {
>> + // Assert that the applet was initialized.
>> + Assert.assertTrue("JSToJFuncParamTest stdout should contain \""
>> + + initStr + "\" but it didn't.", pr.stdout.contains(initStr));
>> +
>> + // Assert that the tests have passed.
>> + String s0 = outputStrings[index] + passStr;
>> + String s1 = outputStrings[index] + failValStr;
>> + String s2 = outputStrings[index] + failTypeStr;
>> + String s3 = "Error on Java side";
>> +
>> + int ind0 = pr.stdout.indexOf(s0);
>> + int ind1 = pr.stdout.indexOf(s1);
>> + int ind2 = pr.stdout.indexOf(s2);
>> + int ind3 = pr.stdout.indexOf(s3);
>> + int indBegin = pr.stdout.indexOf(initStr);
>> + if (indBegin != -1) {
>> + indBegin += initStr.length();
>> + } else {
>> + indBegin = 0;
>> + }
>> +
>> + String failStr = "JSToJFuncParam " + outputStrings[index]
>> + + ": \"passed\" not found in the applet stdout, which is: "
>> + + pr.stdout.substring(indBegin, pr.stdout.length());
>> +
>> + if (ind1 != -1) {
>> + // int inde = pr.stdout.indexOf(expStr);
>> + // int indf = pr.stdout.indexOf(foundStr);
>> + int indend = pr.stdout.indexOf(endStr);
>> + failStr = pr.stdout.substring(ind1, indend + endStr.length());
>> + }
>> +
>> + if (ind2 != -1) {
>> + // int inde = pr.stdout.indexOf(expStr);
>> + // int indf = pr.stdout.indexOf(foundStr);
>> + int indend = pr.stdout.indexOf(endStr);
>> + failStr = pr.stdout.substring(ind2, indend + endStr.length());
>> + }
>> +
>> + if (ind3 != -1) {
>> + failStr = "JSToJFuncParam: " + outputStrings[index]
>> + + pr.stdout.substring(ind3, pr.stdout.length());
>> + }
>> +
>> + Assert.assertTrue(failStr, (ind3 == -1));// no error on Java side
>> + Assert.assertTrue(failStr, (ind1 == -1));// no value mismatch
>> + Assert.assertTrue(failStr, (ind2 == -1));// no type mismatch
>> + Assert.assertTrue(failStr, (ind0 != -1));// test passed
>> +
>> + }
>> +
>> + private void genericJSToJavaFuncParamTestMethod(int index) throws
>> Exception {
>> +
>> + String strURL = "/JSToJFuncParam.html?" + testNames[index];
>> + ProcessResult pr = server.executeBrowser(strURL,
>> + new CountingClosingListenerImpl(),
>> + new CountingClosingListenerImpl());
>> + evaluateStdoutContents(index, pr);
>> +
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_int_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(0);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_double_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(1);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_float_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(2);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_long_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(3);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_boolean_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(4);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_char_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(5);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_byte_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(6);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_charArray_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(7);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_String_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(8);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Integer_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(9);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Double_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(10);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Float_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(11);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Long_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(12);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Boolean_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(13);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Character_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(14);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_Byte_Test() throws Exception {
>> + genericJSToJavaFuncParamTestMethod(15);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_StringIntMixed_Test() throws
>> Exception {
>> + genericJSToJavaFuncParamTestMethod(16);
>> + }
>> +
>> + @Test
>> + @TestInBrowsers(testIn = { Browsers.all })
>> + @NeedsDisplay
>> + public void AppletJSToJFuncParam_DummyObjectArray_Test() throws
>> Exception {
>> + genericJSToJavaFuncParamTestMethod(17);
>> + }
>> +
>> +}
>
> These functions should all pass strings to use with 'eval' like in your
> previous test. They should contain the method to call as well as the
> value as a string / a 'special value' indicator.
>
> Happy hacking,
> -Adam
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: JSToJFuncParam_reproducer_revisited.patch
Type: text/x-patch
Size: 15865 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20130115/d1a9f99c/JSToJFuncParam_reproducer_revisited.patch 


More information about the distro-pkg-dev mailing list