Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7a53e2fc97a81259b5c88bcda19cc0a1d976c113 (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) 2016 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
 *
 * CONTRIBUTORS:
 * 		Jan Belle (initial contribution)
 *
 *******************************************************************************/

#include "debugging/DebuggingServiceTest.h"
#include "common/debugging/DebuggingService.h"
#include "common/messaging/MessageService.h"
#include "common/messaging/RTServices.h"
#include "common/messaging/StaticMessageMemory.h"
#include "etUnit/etUnit.h"

using namespace etRuntime;

void DebuggingServiceTest::testLogging() {

	MessageService msgSvc(NULL, IMessageService::BLOCKED, 0, 0,
			"TestMessageService", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
	RTServices::getInstance().getMsgSvcCtrl().addMsgSvc(msgSvc);
	RTServices::getInstance().getMsgSvcCtrl().start();
	SubSystemClass subSystem(NULL, "TestSubSystem");
	ActorClass actor1(&subSystem, "TestActor1");
	ActorClass actor2(&subSystem, "TestActor2");
	Port port1(&actor1, "TestPort1");
	Port port2(&actor2, "TestPort2");
	DebuggingService& dbgSvc = DebuggingService::getInstance();
	dbgSvc.getAsyncLogger().setMSC("DebuggingServiceTest", "log/testlog/");
	dbgSvc.getAsyncLogger().open();

	InterfaceItemBase::connect(&subSystem, port1.getInstancePath(),
			port2.getInstancePath());
	dbgSvc.addPortInstance(port1);
	dbgSvc.addPortInstance(port2);

	dbgSvc.addMessageActorCreate(subSystem, "TestActor1");
	dbgSvc.addMessageActorCreate(subSystem, "TestActor2");
	dbgSvc.addMessageActorCreate(actor1, "SubActor");
	dbgSvc.addMessageAsyncOut(port1.getAddress(), port2.getAddress(),
			"MessageAsync");
	dbgSvc.addMessageAsyncIn(port1.getAddress(), port2.getAddress(),
			"MessageAsync");
	dbgSvc.addMessageSyncCall(port1.getAddress(), port2.getAddress(),
			"MessageSyncCall");
	dbgSvc.addMessageSyncReturn(port1.getAddress(), port2.getAddress(),
			"MessageSyncReturn");
	dbgSvc.addActorState(actor1, "TestState");
	dbgSvc.addMessageActorDestroy(actor1);
	dbgSvc.addVisibleComment("This is a comment");

	dbgSvc.removePortInstance(port1);
	dbgSvc.removePortInstance(port2);

	dbgSvc.getAsyncLogger().close();
	RTServices::getInstance().getMsgSvcCtrl().stop();

	const char* failMsg = "DebuggingServiceTest failed";
	std::list<std::string>& result = dbgSvc.getAsyncLogger().getCommandList();

	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem (!) /TestSubSystem/TestActor1 "));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem (!) /TestSubSystem/TestActor2 "));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 (!) /TestSubSystem/TestActor1/SubActor "));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 >-- /TestSubSystem/TestActor2 MessageAsync"));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 --> /TestSubSystem/TestActor2 MessageAsync"));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 ==> /TestSubSystem/TestActor2 MessageSyncCall"));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 <== /TestSubSystem/TestActor2 MessageSyncReturn"));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem/TestActor1 >>> TestState"));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare(
					"\t/TestSubSystem (X) /TestSubSystem/TestActor1 "));
	result.pop_front();
	EXPECT_TRUE(m_caseId, failMsg,
			!result.front().compare("# This is a comment"));
	result.pop_front();

}

void DebuggingServiceTest::runAllTestCases() {
	ADD_TESTCASE_CPP(testLogging)
}

Back to the top