Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2010-12-17 18:39:44 -0500
committerHenrik Rentz-Reichert2010-12-17 18:39:44 -0500
commita18223dad8781158e889261776110780c401525d (patch)
tree8550318ab83de220e8e5be978d3d0501e5651fa0 /tests/org.eclipse.etrice.runtime.java.tests
downloadorg.eclipse.etrice-a18223dad8781158e889261776110780c401525d.tar.gz
org.eclipse.etrice-a18223dad8781158e889261776110780c401525d.tar.xz
org.eclipse.etrice-a18223dad8781158e889261776110780c401525d.zip
initial contribution (cf. http://dev.eclipse.org/ipzilla/show_bug.cgi?id=4670)
Diffstat (limited to 'tests/org.eclipse.etrice.runtime.java.tests')
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/.gitignore1
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.ocl.modelregistry2
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/about.html28
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/debugging/MSCLoggerTest.java37
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/AddressTest.java28
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/DummyMessageReceiver.java49
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcherTest.java69
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueueTest.java129
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceTest.java148
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageTest.java33
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBaseTest.java63
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventMessageTest.java34
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventWithDataMessageTest.java36
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java110
15 files changed, 779 insertions, 0 deletions
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/.gitignore b/tests/org.eclipse.etrice.runtime.java.tests/.gitignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/.gitignore
@@ -0,0 +1 @@
+bin
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..912f280ba
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Fri Dec 03 09:11:14 CET 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.ocl.modelregistry b/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.ocl.modelregistry
new file mode 100644
index 000000000..f350ed35e
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/.settings/org.eclipse.ocl.modelregistry
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="ASCII"?>
+<mreg:ModelRegistrySettings xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:mreg="http://www.eclipse.org/ocl/1.0/ModelRegistry"/>
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/about.html b/tests/org.eclipse.etrice.runtime.java.tests/about.html
new file mode 100644
index 000000000..f47dbddbb
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/debugging/MSCLoggerTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/debugging/MSCLoggerTest.java
new file mode 100644
index 000000000..8e6524ce8
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/debugging/MSCLoggerTest.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.debugging;
+
+import org.eclipse.etrice.runtime.java.debugging.MSCLogger;
+
+import junit.framework.TestCase;
+
+public class MSCLoggerTest extends TestCase {
+
+ public void testMSCLogger() {
+ MSCLogger logger = new MSCLogger();
+ logger.setMSC("MSC1", ".\\");
+ logger.open();
+ logger.addMessageAsyncOut("Inst1", "Inst2", "msg1");
+ logger.addMessageAsyncIn("Inst1", "Inst2", "msg1");
+ logger.addMessageSyncCall("Inst1", "Inst2", "msg1");
+ logger.addMessageSyncReturn("Inst1", "Inst2", "msg1");
+ logger.addActorState("Actor1", "State1");
+ logger.close();
+
+ assertEquals("\tInst1 >-- Inst2 msg1", logger.getCommandList().get(0));
+ assertEquals("\tInst1 --> Inst2 msg1", logger.getCommandList().get(1));
+ assertEquals("\tInst1 ==> Inst2 msg1", logger.getCommandList().get(2));
+ assertEquals("\tInst1 <== Inst2 msg1", logger.getCommandList().get(3));
+ assertEquals("\tActor1 >>> State1", logger.getCommandList().get(4));
+
+ //TODO: how should we check generated files?
+
+ }
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/AddressTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/AddressTest.java
new file mode 100644
index 000000000..7375e2a64
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/AddressTest.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+
+import junit.framework.TestCase;
+
+public class AddressTest extends TestCase {
+
+ public void testAddress() {
+ Address addr = new Address(1,2,3);
+ assertEquals(1, addr.nodeID);
+ assertEquals(2, addr.threadID);
+ assertEquals(3, addr.objectID);
+ }
+ public void testToString() {
+ Address addr = new Address(1,2,3);
+ assertEquals("Address(nodeID=1,threadID=2,objectID=3)", addr.toString());
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/DummyMessageReceiver.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/DummyMessageReceiver.java
new file mode 100644
index 000000000..fdf28bf90
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/DummyMessageReceiver.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+
+// this class is purely for testing purposes
+// it remembers the last receive message
+public class DummyMessageReceiver implements IMessageReceiver {
+
+ DummyMessageReceiver (Address address){
+ this.address = address;
+ }
+
+ public void receive(Message msg) {
+ last_received_message = msg;
+ }
+
+ public Address getAddress() {
+ // TODO Auto-generated method stub
+ return this.address;
+ }
+
+ public Message getLastReceivedMessage(){
+ return last_received_message;
+ }
+
+ private Message last_received_message = null;
+ private Address address = null;
+
+ public String getInstancePath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getInstancePathName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcherTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcherTest.java
new file mode 100644
index 000000000..dbe7f4c8c
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcherTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.messaging.MessageDispatcher;
+
+import junit.framework.TestCase;
+
+public class MessageDispatcherTest extends TestCase {
+
+ public void testAddMessageReceiver() {
+ Address dispatcher_address = new Address(0,0,0);
+
+ // Create Receivers to check if the messages are delivered
+ DummyMessageReceiver receiver1 = new DummyMessageReceiver(new Address(0,0,1));
+ DummyMessageReceiver receiver2 = new DummyMessageReceiver(new Address(0,1,1));
+ DummyMessageReceiver receiver3 = new DummyMessageReceiver(new Address(1,1,1));
+ DummyMessageReceiver receiver4 = new DummyMessageReceiver(new Address(0,0,2));
+ DummyMessageReceiver receiver5 = new DummyMessageReceiver(new Address(0,1,2));
+ DummyMessageReceiver receiver6 = new DummyMessageReceiver(new Address(1,1,2));
+
+
+ // Add all Receivers to the Dispatcher
+ MessageDispatcher dispatcher = new MessageDispatcher(null, dispatcher_address, "Dispatcher1");
+ dispatcher.addMessageReceiver(receiver1);
+ dispatcher.addMessageReceiver(receiver2);
+ dispatcher.addMessageReceiver(receiver3);
+ dispatcher.addMessageReceiver(receiver4);
+ dispatcher.addMessageReceiver(receiver5);
+ dispatcher.addMessageReceiver(receiver6);
+
+
+ Message msg1 = new Message(new Address(0,0,1));
+ Message msg2 = new Message(new Address(0,1,1));
+ Message msg3 = new Message(new Address(1,1,1));
+ Message msg4 = new Message(new Address(0,0,2));
+ Message msg5 = new Message(new Address(0,1,2));
+ Message msg6 = new Message(new Address(1,1,2));
+
+ dispatcher.receive(msg1);
+ assertEquals(msg1, receiver1.getLastReceivedMessage());
+ dispatcher.receive(msg2);
+ assertEquals(msg2, receiver2.getLastReceivedMessage());
+ dispatcher.receive(msg3);
+ assertEquals(msg3, receiver3.getLastReceivedMessage());
+ dispatcher.receive(msg4);
+ assertEquals(msg4, receiver4.getLastReceivedMessage());
+ dispatcher.receive(msg5);
+ assertEquals(msg5, receiver5.getLastReceivedMessage());
+ dispatcher.receive(msg6);
+ assertEquals(msg6, receiver6.getLastReceivedMessage());
+
+ }
+
+ public void testInstanceId() {
+ Address dispatcher_address = new Address(0,0,0);
+ MessageDispatcher dispatcher = new MessageDispatcher(null, dispatcher_address, "Dispatcher1");
+ assertEquals("/Dispatcher1", dispatcher.getInstancePath());
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueueTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueueTest.java
new file mode 100644
index 000000000..440c46c2f
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueueTest.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.messaging.MessageSeQueue;
+
+import junit.framework.TestCase;
+
+public class MessageSeQueueTest extends TestCase {
+
+ public void testPushPop() {
+ MessageSeQueue queue = new MessageSeQueue(null, "QueueName");
+ Message msg1 = new Message(new Address(0, 0, 0));
+ Message msg2 = new Message(new Address(0, 0, 0));
+ Message msg3 = new Message(new Address(0, 0, 0));
+
+ Message msg_received = null;
+
+ // check fresh queue
+ assertEquals(null, queue.getFirst());
+ assertEquals(null, queue.getLast());
+
+ // push first message
+ queue.push(msg1);
+ assertEquals(null, msg1.getNext());
+
+ assertEquals(msg1, queue.getFirst());
+ assertEquals(msg1, queue.getLast());
+
+ // push second message
+ queue.push(msg2);
+ assertEquals(msg2, msg1.getNext());
+ assertEquals(null, msg2.getNext());
+
+ assertEquals(msg1, queue.getFirst());
+ assertEquals(msg2, queue.getLast());
+
+ // push third message
+ queue.push(msg3);
+ assertEquals(msg2, msg1.getNext());
+ assertEquals(msg3, msg2.getNext());
+ assertEquals(null, msg3.getNext());
+
+ assertEquals(msg1, queue.getFirst());
+ assertEquals(msg3, queue.getLast());
+
+ // pop msg1
+ msg_received = queue.pop();
+ assertEquals(msg1, msg_received);
+ assertEquals(null, msg1.getNext());
+ assertEquals(msg3, msg2.getNext());
+ assertEquals(null, msg3.getNext());
+
+ assertEquals(msg2, queue.getFirst());
+ assertEquals(msg3, queue.getLast());
+
+
+ // pop msg2
+ msg_received = queue.pop();
+ assertEquals(msg2, msg_received);
+ assertEquals(null, msg2.getNext());
+ assertEquals(null, msg3.getNext());
+
+ assertEquals(msg3, queue.getFirst());
+ assertEquals(msg3, queue.getLast());
+
+ // pop msg3
+ msg_received = queue.pop();
+ assertEquals(msg3, msg_received);
+ assertEquals(null, msg3.getNext());
+
+ assertEquals(null, queue.getFirst());
+ assertEquals(null, queue.getLast());
+
+ msg_received = queue.pop();
+ assertEquals(null, msg_received);
+
+ }
+
+
+ public void testSizeAndHighwatermark() {
+ MessageSeQueue queue = new MessageSeQueue(null, "QueueName");
+ Message msg1 = new Message(new Address(0, 0, 0));
+ Message msg2 = new Message(new Address(0, 0, 0));
+ Message msg3 = new Message(new Address(0, 0, 0));
+
+ Message msg_received = null;
+
+ assertEquals(0, queue.getSize());
+ assertEquals(0, queue.getHightWaterMark());
+
+ queue.push(msg1);
+ assertEquals(1, queue.getSize());
+ assertEquals(1, queue.getHightWaterMark());
+
+ queue.push(msg2);
+ assertEquals(2, queue.getSize());
+ assertEquals(2, queue.getHightWaterMark());
+
+ queue.push(msg3);
+ assertEquals(3, queue.getSize());
+ assertEquals(3, queue.getHightWaterMark());
+
+ msg_received = queue.pop();
+ assertEquals(msg1, msg_received);
+ assertEquals(2, queue.getSize());
+ assertEquals(3, queue.getHightWaterMark());
+
+ msg_received = queue.pop();
+ assertEquals(msg2, msg_received);
+ assertEquals(1, queue.getSize());
+ assertEquals(3, queue.getHightWaterMark());
+
+ msg_received = queue.pop();
+ assertEquals(msg3, msg_received);
+ assertEquals(0, queue.getSize());
+ assertEquals(3, queue.getHightWaterMark());
+
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceTest.java
new file mode 100644
index 000000000..2c03d7051
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceTest.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.messaging.MessageService;
+
+import junit.framework.TestCase;
+
+public class MessageServiceTest extends TestCase {
+
+
+ public void testRun() {
+
+ // testing basic functionality of MessageService and Dispatcher
+ Address addr = new Address(0,0,0);
+ MessageService msg_service = new MessageService(null, addr, "MessageService1");
+
+ DummyMessageReceiver receiver1 = new DummyMessageReceiver(new Address(0,0,1));
+ DummyMessageReceiver receiver2 = new DummyMessageReceiver(new Address(0,1,1));
+ DummyMessageReceiver receiver3 = new DummyMessageReceiver(new Address(1,1,1));
+ DummyMessageReceiver receiver4 = new DummyMessageReceiver(new Address(0,0,2));
+ DummyMessageReceiver receiver5 = new DummyMessageReceiver(new Address(0,1,2));
+ DummyMessageReceiver receiver6 = new DummyMessageReceiver(new Address(1,1,2));
+
+
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver1);
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver2);
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver3);
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver4);
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver5);
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver6);
+
+ Message msg1 = new Message(new Address(0,0,1));
+ Message msg2 = new Message(new Address(0,1,1));
+ Message msg3 = new Message(new Address(1,1,1));
+ Message msg4 = new Message(new Address(0,0,2));
+ Message msg5 = new Message(new Address(0,1,2));
+ Message msg6 = new Message(new Address(1,1,2));
+
+ msg_service.start();
+
+ msg_service.receive(msg1);
+ msg_service.receive(msg2);
+ msg_service.receive(msg3);
+ msg_service.receive(msg4);
+ msg_service.receive(msg5);
+ msg_service.receive(msg6);
+
+
+ try {
+ // give the other thread in MessageService a bit time to compute the queue
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ assertEquals(msg1, receiver1.getLastReceivedMessage());
+ assertEquals(msg2, receiver2.getLastReceivedMessage());
+ assertEquals(msg3, receiver3.getLastReceivedMessage());
+ assertEquals(msg4, receiver4.getLastReceivedMessage());
+ assertEquals(msg5, receiver5.getLastReceivedMessage());
+ assertEquals(msg6, receiver6.getLastReceivedMessage());
+
+
+ }
+
+ public void testMassiveMessaging(){
+ // testing massive use of messaging between two threads
+ // current thread sends, MessageService has its own thread to dispatch the received messages
+ // implicit test of race conditions -> test breaks if you take out the synchronized keywords from the MessageService
+
+ Address addr = new Address(0,0,0);
+ MessageService msg_service = new MessageService(null, addr, "MessageService1");
+
+ int max=3000;
+ int max_iter=10;
+
+ // create and register message receivers
+ DummyMessageReceiver receiver[]=new DummyMessageReceiver[max];
+ for (int i=0; i<max; i++){
+ receiver[i] = new DummyMessageReceiver(new Address(0,0,1+i));
+ msg_service.getMessageDispatcher().addMessageReceiver(receiver[i]);
+ }
+
+
+ // Create all Messages
+ Message msg[][]=new Message[max][max_iter];
+ for (int j=0; j<max_iter; j++){
+ for (int i=0; i<max; i++){
+ msg[i][j] = new Message(new Address(0,0,i+1));
+ }
+ }
+
+ // Start Message Service before sending the Messages to test the synchronization
+ // This test fails without the synchronized keywords in the MessageService
+ msg_service.start();
+
+ // send all messages
+ for (int j=0; j<max_iter; j++){
+ for (int i=0; i<max; i++){
+ msg_service.receive(msg[i][j]);
+ }
+ }
+
+
+ try {
+ // give the other thread in MessageService a bit time to compute the queue
+ // TODO: maybe not a good choice to make a sleep in a test, a better strategy for multi threaded unit tests is needed
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ for (int i=0; i<max; i++){
+ assertEquals(msg[i][max_iter-1], receiver[i].getLastReceivedMessage());
+ }
+
+ }
+
+ public void testMessageService() {
+ Address addr = new Address(0,0,0);
+ MessageService msg_service = new MessageService(null, addr, "MessageService1");
+ assertEquals(addr, msg_service.getAddress());
+ assertEquals(msg_service.getMessageDispatcher().getAddress().objectID, msg_service.getAddress().objectID+1);
+ }
+
+ public void testInstanceId() {
+ Address addr = new Address(0,0,0);
+
+ // setInstanceId via Constructor
+ MessageService msg_service = new MessageService(null, addr, "MessageService1");
+ assertEquals("/MessageService1", msg_service.getInstancePath());
+ assertEquals("/MessageService1/Queue", msg_service.getMessageQueue().getInstancePath());
+ assertEquals("/MessageService1/Dispatcher", msg_service.getMessageDispatcher().getInstancePath());
+ }
+
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageTest.java
new file mode 100644
index 000000000..0c89fb07f
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/messaging/MessageTest.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+
+import junit.framework.TestCase;
+
+public class MessageTest extends TestCase {
+
+ public void testSetGetNext() {
+ Message msg1 = new Message(new Address(0, 0, 0));
+ Message msg2 = new Message(new Address(0, 0, 0));
+ msg1.setNext(msg2);
+ msg2.setNext(msg1);
+ assertEquals(msg1.getNext(), msg2);
+ assertEquals(msg2.getNext(), msg1);
+ }
+
+ public void testToString() {
+ Message msg = new Message(new Address(1,2,3));
+ assertEquals("Message(Address(nodeID=1,threadID=2,objectID=3))", msg.toString());
+ }
+
+
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBaseTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBaseTest.java
new file mode 100644
index 000000000..8253f20c0
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBaseTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
+import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
+
+import junit.framework.TestCase;
+
+
+
+public class ActorClassBaseTest extends TestCase {
+
+ public class TestActor extends ActorClassBase {
+ public TestActor(IRTObject parent, String name) {
+ super(parent, name, null);
+ }
+ public void receive(Message msg) {
+
+ }
+ public Address getAddress() {
+ return null;
+ }
+ public void receiveEvent(InterfaceItemBase ifitem, int evt, Object... data) {
+ }
+
+ @Override
+ public void init() {}
+ @Override
+ public void start() {}
+ @Override
+ public void stop() {}
+ @Override
+ public void destroy() {}
+ }
+
+
+ public void testActorClassBase() {
+ ActorClassBase actor = new TestActor(null, "Actor1");
+ assertEquals("/Actor1", actor.getInstancePath());
+ }
+
+ public void testToString() {
+ ActorClassBase actor = new TestActor(null, "Actor1");
+ actor.setClassName("ActorClassBase");
+ assertEquals("ActorClass(className=ActorClassBase, instancePath=/Actor1)", actor.toString());
+ }
+
+ public void testSetGetClassName() {
+ ActorClassBase actor = new TestActor(null, "Actor1");
+ actor.setClassName("ActorClassBase");
+ assertEquals("ActorClassBase", actor.getClassName());
+ }
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventMessageTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventMessageTest.java
new file mode 100644
index 000000000..13b29f616
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventMessageTest.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.modelbase.EventMessage;
+
+import junit.framework.TestCase;
+
+public class EventMessageTest extends TestCase {
+
+ public void testSetGetNext() {
+ EventMessage msg1 = new EventMessage(new Address(0, 0, 0), 123);
+ EventMessage msg2 = new EventMessage(new Address(0, 0, 0), 456);
+ msg1.setNext(msg2);
+ msg2.setNext(msg1);
+ assertEquals(msg1.getNext(), msg2);
+ assertEquals(msg2.getNext(), msg1);
+
+ assertEquals(123, msg1.getEvtId());
+ assertEquals(456, msg2.getEvtId());
+ }
+
+ public void testToString() {
+ EventMessage msg = new EventMessage(new Address(1,2,3), 789);
+ assertEquals("EventMessage(Address(nodeID=1,threadID=2,objectID=3), evt=789)", msg.toString());
+ }
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventWithDataMessageTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventWithDataMessageTest.java
new file mode 100644
index 000000000..41f228d23
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/EventWithDataMessageTest.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.modelbase.EventWithDataMessage;
+
+import junit.framework.TestCase;
+
+public class EventWithDataMessageTest extends TestCase {
+
+ public void testSetGetNext() {
+ EventWithDataMessage msg1 = new EventWithDataMessage(new Address(0, 0, 0), 123, "abc");
+ EventWithDataMessage msg2 = new EventWithDataMessage(new Address(0, 0, 0), 456, "def");
+ msg1.setNext(msg2);
+ msg2.setNext(msg1);
+ assertEquals(msg1.getNext(), msg2);
+ assertEquals(msg2.getNext(), msg1);
+
+ assertEquals(123, msg1.getEvtId());
+ assertEquals(456, msg2.getEvtId());
+ assertEquals("abc", msg1.getData()[0]);
+ assertEquals("def", msg2.getData()[0]);
+ }
+
+ public void testToString() {
+ EventWithDataMessage msg = new EventWithDataMessage(new Address(1,2,3), 789, "eTrice");
+ assertEquals("EventWithDataMessage(Address(nodeID=1,threadID=2,objectID=3), evt=789, data=eTrice)", msg.toString());
+ }
+}
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java
new file mode 100644
index 000000000..7b91b934f
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.messaging.MessageService;
+import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
+import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver;
+import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
+import org.eclipse.etrice.runtime.java.modelbase.PortBase;
+
+import junit.framework.TestCase;
+
+public class PortBaseTest extends TestCase {
+
+ public class TestActor extends ActorClassBase {
+ public TestActor(IRTObject parent, String name) {
+ super(parent, name, null);
+ }
+ public void receive(Message msg) {
+
+ }
+ public Address getAddress() {
+ return null;
+ }
+ public void receiveEvent(InterfaceItemBase ifitem, int evt, Object... data) {
+ }
+ @Override
+ public void init() {}
+ @Override
+ public void start() {}
+ @Override
+ public void stop() {}
+ @Override
+ public void destroy() {}
+ }
+
+ class MyPortBase extends PortBase {
+ public MyPortBase(IEventReceiver parent, String name, int localId, int idx, Address address,
+ Address peerAddress, IMessageReceiver msgReceiver) {
+ super(parent, name, localId, idx, address, peerAddress, msgReceiver);
+ }
+
+ public void receive(Message msg) {
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testPortBase() {
+ MessageService msgService = new MessageService(null, new Address(4, 5, 6), "MessageService1");
+ Address portAddress = new Address(1, 2, 3);
+ Address peerAddress = new Address(3, 2, 1);
+ PortBase port = new MyPortBase(null, "Port1", 0, 0, portAddress, peerAddress, msgService);
+ assertEquals(msgService, port.getMsgReceiver());
+ assertEquals(portAddress, port.getAddress());
+ assertEquals(peerAddress, port.getPeerAddress());
+ }
+
+ public void testSetGetPeerAddress() {
+ Address peerAddress = new Address(3, 2, 1);
+ PortBase port = new MyPortBase(null, "", 0, 0, null, peerAddress, null);
+ assertEquals(peerAddress, port.getPeerAddress());
+ }
+
+ public void testSetGetMsgService() {
+ MessageService msgService = new MessageService(null, new Address(4, 5, 6), "MessageService1");
+ Address portAddress = new Address(1, 2, 3);
+ PortBase port = new MyPortBase(null, "", 0, 0, portAddress, null, msgService);
+ assertEquals(msgService, port.getMsgReceiver());
+ }
+
+ public void testSetInstanceId() {
+ PortBase port = new MyPortBase(null, "Port1", 0, 0, null, null, null);
+ assertEquals("/Port1", port.getInstancePath());
+ }
+
+ public void testGetLocalId() {
+ PortBase port = new MyPortBase(null, "Port1", 123, 0, null, null, null);
+ assertEquals(123, port.getLocalId());
+ }
+
+ public void testGetIdx() {
+ PortBase port = new MyPortBase(null, "Port1", 0, 456, null, null, null);
+ assertEquals(456, port.getIdx());
+ }
+
+ public void testSetGetParentObject(){
+ ActorClassBase actor = new TestActor(null, "Actor1");
+ PortBase port = new MyPortBase(actor, "Port1", 0, 0, null, null, null);
+
+ assertEquals("/Actor1/Port1", port.getInstancePath());
+ assertEquals(actor, port.getActor());
+ }
+}

Back to the top