home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / plugins / javatest / JavaTestPlugin.java next >
Encoding:
Java Source  |  1998-04-08  |  4.9 KB  |  132 lines

  1. /* -*- Mode: Java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. import netscape.plugin.Plugin;
  19.  
  20. class JavaTestPlugin extends Plugin {
  21.  
  22.     public static int fact(int n) {
  23.         if (n == 1)
  24.             return 1;
  25.         else
  26.             return n * fact(n-1);
  27.     }
  28.  
  29.     int foo;
  30.     int foo_slot;
  31.  
  32.     public void test_ID() {
  33.     }
  34.  
  35.     public void testPluginCalls() {
  36.         try {
  37.             System.out.println("java: foo = "+foo);
  38.             foo = 234;
  39.             System.out.println("java: setting foo to "+foo);
  40.  
  41.             System.out.print("java: calling plugin stuff");
  42.             char k = doPluginStuff("fwoop", 65535);
  43.             System.out.print(" => "+k);
  44.             System.out.println(k == 'f'
  45.                                ? " ok" : " error");
  46.  
  47.             System.out.println("java: calling void native1()");
  48.             native1();
  49.  
  50.             System.out.print("java: calling byte native2((byte)0xff)");
  51.             byte b = native2((byte)0xff);
  52.             System.out.print(" => "+b);
  53.             System.out.println(b == ((byte)0xff + 4)
  54.                                ? " ok" : " error");
  55.  
  56.             System.out.print("java: calling char native3('a')");
  57.             char c = native3('a');
  58.             System.out.print(" => "+c);
  59.             System.out.println(c == 'b'
  60.                                ? " ok" : " error");
  61.  
  62.             System.out.print("java: calling short native4((short)-65000)");
  63.             short s = native4((short)-65000);
  64.             System.out.print(" => "+s);
  65.             System.out.println(s == ((short)-65000 + 1)
  66.                                ? " ok" : " error");
  67.  
  68.             System.out.print("java: calling int native5(1000000)");
  69.             int i = native5(1000000);
  70.             System.out.print(" => "+i);
  71.             System.out.println(i == (1000000 + 1)
  72.                                ? " ok" : " error");
  73.  
  74.             System.out.print("java: calling long native6(-989898989898)");
  75.             long l = native6(-989898989898);
  76.             System.out.print(" => "+l);
  77.             System.out.println(l == (-989898989898 + 65536)
  78.                                ? " ok" : " error");
  79.  
  80.             System.out.print("java: calling float native7(3.1415f)");
  81.             float f = native7(3.1415f);
  82.             System.out.print(" => "+f);
  83.             System.out.println(f == (3.1415f + 1.0)
  84.                                ? " ok" : " error");
  85.  
  86.             System.out.print("java: calling double native8(1e200)");
  87.             double d = native8(1e200);
  88.             System.out.print(" => "+d);
  89.             System.out.println(d == (1e200 + 1e10)
  90.                                ? " ok" : " error");
  91.  
  92.             float[] floats = new float[4];
  93.             floats[0] = 1.1f;
  94.             floats[1] = 2.2f;
  95.             floats[2] = 3.3f;
  96.             floats[3] = 4.4f;
  97.             boolean[] bools = new boolean[2];
  98.             bools[0] = true;
  99.             bools[1] = false;
  100.             System.out.print("java: calling String native9(\"hello\", 1, "
  101.                              +l+", "+floats+")");
  102.             String r = native9("hello", 1, l, floats, bools);
  103.             System.out.print(" => "+r);
  104.             System.out.println(r.equals("ello")
  105.                                ? " ok" : " error");
  106.             float j = 1.1f * 2.2f;
  107.             for (i = 0; i < 4; i++, j *= 2.2f) {
  108.                 System.out.print("floats["+i+"] = "+floats[i]);
  109.                 System.out.println(floats[i] == j
  110.                                    ? " ok" : " error");
  111.             }
  112.  
  113.         } catch (Throwable e) {
  114.             System.err.println("!!! Exception: "+e);
  115.             e.printStackTrace(System.err);
  116.         }
  117.     }
  118.  
  119.     public native char doPluginStuff(String s, int i);
  120.  
  121.     public native void native1();
  122.     public native byte native2(byte x);
  123.     public native char native3(char x);
  124.     public native short native4(short x);
  125.     public native int native5(int x);
  126.     public native long native6(long x);
  127.     public native float native7(float x);
  128.     public native double native8(double x);
  129.     public native String native9(String x, int i, long l,
  130.                                  float[] floats, boolean[] bools);
  131. }
  132.