From 615df5f1f4058862342ec3171ceb78da09c40fc7 Mon Sep 17 00:00:00 2001 From: jestin Date: Tue, 7 Jan 2003 10:39:44 +0000 Subject: Je vais simplifier la constructions de tests. TestApi est brutal et efficace pour tester l'api. --- tests/Makefile | 46 +++++++++++----------- tests/TESTBENCH | 4 ++ tests/TestApi.java | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/TestNetSwing.java | 6 ++- 4 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 tests/TestApi.java (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index ac421c9..c34121b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,14 +1,14 @@ -JIKESPATH=/usr/lib/j2re1.3/lib/rt.jar:../lib/ivy-java.jar +#RTPATH=/usr/lib/j2re1.3/lib/rt.jar +RTPATH=/usr/lib/j2sdk1.4-bd/jre/lib/rt.jar +JIKESPATH=:$(RTPATH):../lib/ivy-java.jar:/usr/share/java/repository +CLASSPATH=-classpath ../lib/ivy-java.jar:. JAVAC= jikes -classpath $(JIKESPATH) .SUFFIXES: .java .class -SRC = TestNetSwing.java TestNet.java Bug.java BugTok.java BenchLocal.java +SRC = TestNetSwing.java TestNet.java Bug.java BugTok.java BenchLocal.java ProbeBench.java DieSender.java TestApi.java OBJ = $(SRC:.java=.class) -JAVAOPTS = -DIVY_PING -JAVA = java $(JAVAOPTS) -JDK118=/usr/local/jdk118_v3/bin/java -JDK13=java -JDK12= /usr/local/jdk1.2.2/bin/java -JDK14= /usr/local/j2sdk1.4.0/bin/java +#JAVAOPTS = -DIVY_PING +JAVAOPTS = +JAVA = java #LOCALNET=10.0.0.255:3456 LOCALNET=10.192.36.255:3456 @@ -17,28 +17,26 @@ MULTICAST=228.1.2.3:4567 .java.class: $(JAVAC) $< -all: $(OBJ) - @echo 'run make alltests' - -alltests: $(OBJ) unitaires test1 test2 jvm +all: $(OBJ) api unitaires test1 test2 probe +probe: + $(JAVA) $(JAVAOPTS) $(CLASSPATH) fr.dgac.ivy.Probe < /dev/null +api: + $(JAVA) $(JAVAOPTS) $(CLASSPATH) TestApi + unitaires: - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. fr.dgac.ivy.Ivy + $(JAVA) $(JAVAOPTS) $(CLASSPATH) fr.dgac.ivy.Ivy test1: $(OBJ) - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -b $(LOCALNET) - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -b $(MULTICAST) - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -d 100 - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -d 0 + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -b $(LOCALNET) + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -b $(MULTICAST) + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -d 100 + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -d 0 test2: $(OBJ) - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -t 2 -d 100 - $(JAVA) $(JAVAOPTS) -classpath ../lib/ivy-java.jar:. BenchLocal -t 2 -d 0 - -jvm: - make JAVA=$(JDK14) test1 - make JAVA=$(JDK14) test2 + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -t 2 -d 100 + $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -t 2 -d 0 clean: /bin/rm -f $(OBJ) *.class diff --git a/tests/TESTBENCH b/tests/TESTBENCH index 3cc3a5c..81fc593 100644 --- a/tests/TESTBENCH +++ b/tests/TESTBENCH @@ -12,3 +12,7 @@ How to check if it doesn't work ? client B, client C vs A, C, B ... ) - the regexps should function properly, let's build a little testbench + +- Probe: + should exit on ^D + should end when receiving a die message diff --git a/tests/TestApi.java b/tests/TestApi.java new file mode 100644 index 0000000..397208e --- /dev/null +++ b/tests/TestApi.java @@ -0,0 +1,101 @@ +/** + * Ivy java library API tester. + * + * @author Yannick Jestin + * + * (c) CENA + * + * usage: java TestApi + * + */ +import fr.dgac.ivy.*; + +class TestApi implements IvyMessageListener, IvyApplicationListener { + + public static final String TestApiReadyMsg = "TestAPI ready"; + public static final String TestMsg = "Test Message"; + + private Ivy bus; + private int test=0; + private String domain; + + public TestApi(String domain) throws IvyException { + bus = new Ivy("TestAPI",TestApiReadyMsg, null); + bus.addApplicationListener(this); + bus.bindMsg("^"+TestMsg+"$",this); + bus.start(this.domain=domain); + new Sender(domain) ; + } + + public void receive(IvyClient ic,String[] args) { + System.out.println("[X] received message"); + test++; + } + + public void connect(IvyClient ic) { + if (ic.getApplicationName().compareTo("Sender")!=0) return; + System.out.println("[X] Sender connected"); + test++; + } + + public void disconnect(IvyClient ic) { + if (ic.getApplicationName().compareTo("Sender")!=0) return; + System.out.println("[X] Sender disconnected"); + test++; + } + + public void directMessage(IvyClient ic,int id,String arg) { + if (id!=1) return; + System.out.println("[X] Direct message received, ID=1"); + test++; + } + + public void die(IvyClient ic,int reason) { + System.out.println("[X] Die received"); + test++; + System.out.println(test+ "/5 tests successful, good bye"); + bus.stop(); + } + + class Sender implements IvyMessageListener { + private Ivy sbus; + private String domain; + public Sender(String domain) { + try { + sbus = new Ivy("Sender","Sender ready", null); + sbus.bindMsg("^"+TestApiReadyMsg+"$",this); + sbus.start(this.domain=domain); + } catch (IvyException ie) { + ie.printStackTrace(); + } + } + public void receive(IvyClient c,String[] args) { + sbus.sendMsg(TestMsg); + c.sendDirectMsg(1,"bye bye"); + sbus.stop(); + new Killer(domain); + } + } + + class Killer implements IvyMessageListener { + private Ivy kbus; + public Killer(String domain) { + try { + kbus = new Ivy("Killer","Killer ready", null); + kbus.bindMsg("^"+TestApiReadyMsg+"$",this); + kbus.start(domain); + } catch (IvyException ie) { + ie.printStackTrace(); + } + } + public void receive(IvyClient c,String[] args) { + c.sendDie("bye bye"); + kbus.stop(); + } + } + + public static void main(String[] args) throws IvyException { + new TestApi(null); + } + +} diff --git a/tests/TestNetSwing.java b/tests/TestNetSwing.java index 08c9db5..3154457 100644 --- a/tests/TestNetSwing.java +++ b/tests/TestNetSwing.java @@ -1,4 +1,7 @@ -/* +/** + * TestNetSwing , a network Ivy domain checker. + * @author Yannick Jestin + * (c) CENA * A simple Swing application in order to check whether the chosen network is * OK */ @@ -251,7 +254,6 @@ class TestNetSwing implements Runnable { System.exit(0); } // getopt new TestNetSwing(domain); - } } // class TestNetSwing -- cgit v1.1