X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Ftest_code%2FSerialServerTest.java;h=c10a158c347c1f9e0ed64f096a33352d8a3b4556;hb=d46b7b96f94e88a776bcd2dfd756549ffb300cc9;hp=382d9a6b5a11a7b29edc1242a58fa132bc8d3165;hpb=d2219aa05bbcc5603e90aa69220fecb4a6a41f55;p=fanfix.git diff --git a/src/be/nikiroo/utils/test_code/SerialServerTest.java b/src/be/nikiroo/utils/test_code/SerialServerTest.java index 382d9a6..c10a158 100644 --- a/src/be/nikiroo/utils/test_code/SerialServerTest.java +++ b/src/be/nikiroo/utils/test_code/SerialServerTest.java @@ -2,6 +2,7 @@ package be.nikiroo.utils.test_code; import java.net.URL; +import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.server.ConnectActionClientObject; import be.nikiroo.utils.serial.server.ConnectActionClientString; import be.nikiroo.utils.serial.server.ConnectActionServerObject; @@ -43,63 +44,64 @@ class SerialServerTest extends TestLauncher { super(title + " " + skey + sbridge, args); - // addTest(new TestCase("Simple connection " + skey) { - // @Override - // public void test() throws Exception { - // final String[] rec = new String[1]; - // - // ServerString server = new ServerString(this.getName(), 0, key) { - // @Override - // protected String onRequest( - // ConnectActionServerString action, String data) - // throws Exception { - // return null; - // } - // - // @Override - // protected void onError(Exception e) { - // } - // }; - // - // int port = server.getPort(); - // assertEquals("A port should have been assigned", true, port > 0); - // - // server.start(); - // - // ServerBridge br = null; - // if (bridge) { - // br = new ServerBridge(0, key, "", port, key); - // br.setTraceHandler(null); - // - // port = br.getPort(); - // assertEquals( - // "A port should have been assigned to the bridge", - // true, port > 0); - // - // br.start(); - // } - // - // try { - // try { - // new ConnectActionClientObject(null, port, key) { - // @Override - // public void action() throws Exception { - // rec[0] = "ok"; - // } - // }.connect(); - // } finally { - // server.stop(); - // } - // } finally { - // if (br != null) { - // br.stop(); - // } - // } - // - // assertNotNull("The client action was not run", rec[0]); - // assertEquals("ok", rec[0]); - // } - // }); + addTest(new TestCase("Simple connection " + skey) { + @Override + public void test() throws Exception { + final String[] rec = new String[1]; + + ServerString server = new ServerString(this.getName(), 0, key) { + @Override + protected String onRequest( + ConnectActionServerString action, Version version, + String data, long id) throws Exception { + return null; + } + + @Override + protected void onError(Exception e) { + } + }; + + int port = server.getPort(); + assertEquals("A port should have been assigned", true, port > 0); + + server.start(); + + ServerBridge br = null; + if (bridge) { + br = new ServerBridge(0, key, "", port, key); + br.setTraceHandler(null); + + port = br.getPort(); + assertEquals( + "A port should have been assigned to the bridge", + true, port > 0); + + br.start(); + } + + try { + try { + new ConnectActionClientString(null, port, key) { + @Override + public void action(Version version) + throws Exception { + rec[0] = "ok"; + } + }.connect(); + } finally { + server.stop(); + } + } finally { + if (br != null) { + br.stop(); + } + } + + assertNotNull("The client action was not run", rec[0]); + assertEquals("ok", rec[0]); + } + }); addTest(new TestCase("Simple exchange " + skey) { final String[] sent = new String[1]; @@ -111,8 +113,8 @@ class SerialServerTest extends TestLauncher { ServerString server = new ServerString(this.getName(), 0, key) { @Override protected String onRequest( - ConnectActionServerString action, String data) - throws Exception { + ConnectActionServerString action, Version version, + String data, long id) throws Exception { sent[0] = data; return "pong"; } @@ -139,7 +141,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientString(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { recd[0] = send("ping"); } }.connect(); @@ -172,8 +175,8 @@ class SerialServerTest extends TestLauncher { ServerString server = new ServerString(this.getName(), 0, key) { @Override protected String onRequest( - ConnectActionServerString action, String data) - throws Exception { + ConnectActionServerString action, Version version, + String data, long id) throws Exception { sent[0] = data; action.send("pong"); sent[1] = action.rec(); @@ -202,7 +205,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientString(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { recd[0] = send("ping"); recd[1] = send("ping2"); } @@ -238,8 +242,8 @@ class SerialServerTest extends TestLauncher { ServerString server = new ServerString(this.getName(), 0, key) { @Override protected String onRequest( - ConnectActionServerString action, String data) - throws Exception { + ConnectActionServerString action, Version version, + String data, long id) throws Exception { sent[Integer.parseInt(data)] = data; return "" + (Integer.parseInt(data) * 2); } @@ -266,7 +270,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientString(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { for (int i = 0; i < 3; i++) { recd[i] = send("" + i); } @@ -310,8 +315,8 @@ class SerialServerTest extends TestLauncher { ServerObject server = new ServerObject(this.getName(), 0, key) { @Override protected Object onRequest( - ConnectActionServerObject action, Object data) - throws Exception { + ConnectActionServerObject action, Version version, + Object data, long id) throws Exception { return null; } @@ -337,7 +342,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientObject(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { rec[0] = true; } @@ -369,8 +375,8 @@ class SerialServerTest extends TestLauncher { ServerObject server = new ServerObject(this.getName(), 0, key) { @Override protected Object onRequest( - ConnectActionServerObject action, Object data) - throws Exception { + ConnectActionServerObject action, Version version, + Object data, long id) throws Exception { sent[0] = data; return "pong"; } @@ -397,7 +403,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientObject(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { recd[0] = send("ping"); } }.connect(); @@ -430,8 +437,8 @@ class SerialServerTest extends TestLauncher { ServerObject server = new ServerObject(this.getName(), 0, key) { @Override protected Object onRequest( - ConnectActionServerObject action, Object data) - throws Exception { + ConnectActionServerObject action, Version version, + Object data, long id) throws Exception { sent[0] = data; action.send("pong"); sent[1] = action.rec(); @@ -460,7 +467,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientObject(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { recd[0] = send("ping"); recd[1] = send("ping2"); } @@ -496,8 +504,8 @@ class SerialServerTest extends TestLauncher { ServerObject server = new ServerObject(this.getName(), 0, key) { @Override protected Object onRequest( - ConnectActionServerObject action, Object data) - throws Exception { + ConnectActionServerObject action, Version version, + Object data, long id) throws Exception { sent[0] = data; return new Object[] { "ACK" }; } @@ -524,7 +532,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientObject(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { recd[0] = send(new Object[] { "key", new URL( @@ -567,8 +576,8 @@ class SerialServerTest extends TestLauncher { ServerObject server = new ServerObject(this.getName(), 0, key) { @Override protected Object onRequest( - ConnectActionServerObject action, Object data) - throws Exception { + ConnectActionServerObject action, Version version, + Object data, long id) throws Exception { sent[(Integer) data] = data; return ((Integer) data) * 2; } @@ -595,7 +604,8 @@ class SerialServerTest extends TestLauncher { try { new ConnectActionClientObject(null, port, key) { @Override - public void action() throws Exception { + public void action(Version version) + throws Exception { for (int i = 0; i < 3; i++) { recd[i] = send(i); }