Exemple #1
0
  private static void runEchoTests() {
    nsIEcho nativeEcho =
        (nsIEcho)
            Mozilla.getInstance()
                .getComponentManager()
                .createInstanceByContractID(
                    "@mozilla.org/javaxpcom/tests/xpc;1", null, nsIEcho.NS_IECHO_IID);

    Object[][] tests =
        new Object[][] {
          /* test DOMString */
          {
            "in2OutOneDOMString",
            new Object[] {testString},
            testString,
            "in2OutOneDOMString w/ '" + testString + "'"
          },
          {
            "in2OutOneDOMString",
            new Object[] {emptyString},
            emptyString,
            "in2OutOneDomString w/ empty string"
          },
          {"in2OutOneDOMString", new Object[] {null}, null, "in2OutOneDOMString w/ null value"},
          /* test AString */
          {
            "in2OutOneAString",
            new Object[] {testString},
            testString,
            "in2OutOneAString w/ '" + testString + "'"
          },
          {
            "in2OutOneAString",
            new Object[] {emptyString},
            emptyString,
            "in2OutOneAString w/ empty string"
          },
          {
            "in2OutOneAString",
            new Object[] {utf8String},
            utf8String,
            "in2OutOneAString w/ '" + utf8String + "'"
          },
          {"in2OutOneAString", new Object[] {null}, null, "in2OutOneAString w/ null value"},
          /* test AUTF8String */
          {
            "in2OutOneUTF8String",
            new Object[] {testString},
            testString,
            "in2OutOneUTF8String w/ '" + testString + "'"
          },
          {
            "in2OutOneUTF8String",
            new Object[] {emptyString},
            emptyString,
            "in2OutOneUTF8String w/ empty string"
          },
          {
            "in2OutOneUTF8String",
            new Object[] {utf8String},
            utf8String,
            "in2OutOneUTF8String w/ '" + utf8String + "'"
          },
          {"in2OutOneUTF8String", new Object[] {null}, null, "in2OutOneUTF8String w/ null value"},
          /* test ACString */
          {
            "in2OutOneCString",
            new Object[] {testString},
            testString,
            "in2OutOneCString w/ '" + testString + "'"
          },
          {
            "in2OutOneCString",
            new Object[] {emptyString},
            emptyString,
            "in2OutOneCString w/ empty string"
          },
          {"in2OutOneCString", new Object[] {null}, null, "in2OutOneCString w/ null value"},
          /* test normal strings */
          {
            "in2OutOneString",
            new Object[] {testString},
            testString,
            "in2OutOneString w/ '" + testString + "'"
          },
          {
            "in2OutOneString",
            new Object[] {emptyString},
            emptyString,
            "in2OutOneString w/ empty string"
          }
        };

    runTestsArray(nativeEcho, tests);

    do {
      Object result = null;
      boolean passed = false;
      String comment = "in2OutOneString w/ null value";
      try {
        result = nativeEcho.in2OutOneString(null);
        passed = (result == null);
      } catch (Exception e) {
        // Calling nativeEcho.in2OutOneString(null) should throw an
        // exception, with errorcode == NS_ERROR_FAILURE.
        if (e instanceof XPCOMException
            && ((XPCOMException) e).errorcode == Mozilla.NS_ERROR_FAILURE) {
          passed = true;
        }

        if (!passed) {
          System.err.println("*** TEST " + comment + " threw exception:");
          e.printStackTrace();
          logResult(comment, false);
          continue;
        }
      }

      logResult(comment, passed);

      if (!passed) {
        System.err.println("*** TEST " + comment + " FAILED: expected null, returned " + result);
      }
    } while (false);

    tests =
        new Object[][] {
          {"setAString", new Object[] {testString}, null, "setAString w/ '" + testString + "'"},
          {"getAString", null, testString, "getAString w/ '" + testString + "'"},
          {"setAString", new Object[] {emptyString}, null, "setAString w/ empty string"},
          {"getAString", null, emptyString, "getAString w/ empty string"},
          {"setAString", new Object[] {null}, null, "setAString w/ null value"},
          {"getAString", null, null, "getAString w/ null value"},
          /* Is the 'shared' attribute even used in scriptable functions?
          { "sharedString", null, sharedString, null } */
        };

    runTestsArray(nativeEcho, tests);
  }
Exemple #2
0
 public String echoIn2OutOneUTF8String(String input) {
   if (receiver != null) {
     return receiver.echoIn2OutOneUTF8String(input);
   }
   return in2OutOneUTF8String(input);
 }
Exemple #3
0
 public void sendOneString(String str) {
   if (receiver != null) {
     receiver.sendOneString(str);
   }
   results[0] = str;
 }