diff options
Diffstat (limited to 'src/java/com/e1')
-rw-r--r-- | src/java/com/e1/pdj/PDJSystem.java | 58 | ||||
-rw-r--r-- | src/java/com/e1/pdj/test/CallbackTest.java | 12 | ||||
-rw-r--r-- | src/java/com/e1/pdj/test/NetTest.java | 55 |
3 files changed, 84 insertions, 41 deletions
diff --git a/src/java/com/e1/pdj/PDJSystem.java b/src/java/com/e1/pdj/PDJSystem.java index 1fd50d2..ac3fd47 100644 --- a/src/java/com/e1/pdj/PDJSystem.java +++ b/src/java/com/e1/pdj/PDJSystem.java @@ -2,12 +2,10 @@ package com.e1.pdj; import com.cycling74.max.MaxSystem; -import java.awt.Component; -import java.awt.Frame; import java.awt.Toolkit; import java.io.*; - import java.awt.GraphicsEnvironment; + /** * Startup class for pdj. */ @@ -24,7 +22,7 @@ public class PDJSystem { public static void _init_system() { if ( loaded == 1 ) return; - linknative(); + javainit(); initIO(); } @@ -42,49 +40,29 @@ public class PDJSystem { GenericCompiler.rtJar = systemCpJar + ps + "jre" + ps + "lib" + ps + "rt.jar" + File.pathSeparator; } - /** - * Link the Java native classes - */ - static void linknative() { - String pdjHome = System.getProperty("pdj.home"); + static void javainit() { // this is a hack to be sure that statics of MaxSystem are loaded // before everything Class cls = MaxSystem.class; String osname = System.getProperty("os.name"); - - if ( osname.indexOf("Linux") != -1 ) { - // maps PD object as a JVM native library - Runtime.getRuntime().load(pdjHome + "/pdj.pd_linux"); - loaded = 1; - resolvRtJar(); - return; - } - - if ( osname.indexOf("Windows") != -1 ) { - // maps PD object as a JVM native library - Runtime.getRuntime().load(pdjHome + "/pdj.dll"); - loaded = 1; - resolvRtJar(); - return; - } - if ( osname.indexOf("OS X") != -1 ) { - // maps PD object as a JVM native library - Runtime.getRuntime().load(pdjHome + "/pdj.d_fat"); - loaded = 1; - - if ( System.getenv("PDJ_USE_AWT") != null ) { - GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); - Toolkit.getDefaultToolkit(); - } - GenericCompiler.rtJar = "/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar:"; - - return; - } - - System.err.println("pdj: operating system type not found, the native link has not been made"); + try { + if (System.getenv("PDJ_USE_AWT") != null) { + GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); + Toolkit.getDefaultToolkit(); + } + } catch (Error e) { + // on java 1.4, this will throw an error, we simply ignore AWT with 1.4 + } + GenericCompiler.rtJar = "/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar:"; + loaded = 1; + return; + } + + loaded = 1; + resolvRtJar(); } static boolean redirectIO() { diff --git a/src/java/com/e1/pdj/test/CallbackTest.java b/src/java/com/e1/pdj/test/CallbackTest.java index 4105479..526a5f4 100644 --- a/src/java/com/e1/pdj/test/CallbackTest.java +++ b/src/java/com/e1/pdj/test/CallbackTest.java @@ -1,10 +1,20 @@ package com.e1.pdj.test; +import com.cycling74.max.*; import junit.framework.TestCase; public class CallbackTest extends TestCase { - public void testSomething() { + + + public void testArgs() { + Callback callback = new Callback(this, "callme", new Object[] { new Integer[0] }); + Integer[] args = new Integer[] { new Integer(1), new Integer(2) }; + callback.setArgs((Object[]) args); + callback.execute(); + } + + public void callme(Integer args[]) { } } diff --git a/src/java/com/e1/pdj/test/NetTest.java b/src/java/com/e1/pdj/test/NetTest.java new file mode 100644 index 0000000..01b103a --- /dev/null +++ b/src/java/com/e1/pdj/test/NetTest.java @@ -0,0 +1,55 @@ +package com.e1.pdj.test; + +import com.cycling74.max.*; +import com.cycling74.net.*; +import junit.framework.TestCase; + +public class NetTest extends TestCase { + Atom value[]; + + public void testUDP() { + UdpReceiver receive = new UdpReceiver(7500); + receive.setCallback(this, "callback_test"); + receive.setActive(true); + + value = null; + + UdpSender send = new UdpSender("localhost", 7500); + send.send(7500); + + try { + Thread.sleep(1000); + } catch ( InterruptedException e ) { + } + + receive.close(); + + assertNotNull(value); + assertEquals(Integer.parseInt(value[0].toString()), 7500); + } + + public void callback_test(Atom args[]) { + value = args; + } + + public void testTCP() { + TcpReceiver receive = new TcpReceiver(7500); + receive.setCallback(this, "callback_test"); + receive.setActive(true); + + value = null; + + TcpSender send = new TcpSender("localhost", 7500); + send.send(7500); + + try { + Thread.sleep(1000); + } catch ( InterruptedException e ) { + } + + receive.close(); + + assertNotNull(value); + assertEquals(Integer.parseInt(value[0].toString()), 7500); + } +} |