Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1be4960efd1910e7ae840f03a78cb02f89b45c54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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