blob: 4dc4460ddec10696fcf87c46982dd2bb571ba329 (
plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*******************************************************************************
* Copyright (c) 2008 Gerhard Leonhartsberger.
* 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
*******************************************************************************/
#ifndef TESTRUNNERSERVER_H_
#define TESTRUNNERSERVER_H_
#ifdef CPPUNIT_MAIN
#include "cppunit/TestResultCollector.h"
#include "cppunit/TestListener.h"
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
/*!
* Class <code>TestRunnerClient</code> handles the network connection to the
* <code>CppUnitServer</code> and executes all registered CppUnit tests.
* <p>
* The meta data of the CppUnit tests and the test results are sent to the
* <code>CppUnitServer</code> for displaying.
* </p>
* <p>
* For debugging purposes class <code>TestRunnerClient</code> displays debug
* messages on <code>std.cerr</code>. The debug modus is activated by specifying
* <code>debug</code> command line option. The command line is parsed by method
* <code>Init()</code>.
* </p>
* <p>
* Note: This class is not intended to be subclassed by clients. This class is
* based on the original <code>RemoteTestRunner</code> class provided by
* <code>org.eclipse.cdt.cppunit</code>.
* </p>
*
* @author Gerhard Leonhartsberger
*/
class TestRunnerClient: public CppUnit::TestListener
{
private:
CppUnit::TestResult *fTestResult;
CppUnit::TestResultCollector resultCollector;
int fClientSocket;
char *fHost;
int fPort;
int fDebugMode;
int fKeepAlive;
public:
TestRunnerClient();
virtual ~TestRunnerClient();
CppUnit::TestResultCollector& getResultCollector();
/*!
* Initializes the <code>TestRunnerClient</code>.
* <p>
* The given <code>args</code> are parsed. The syntax for the arguments is
* defined in EBNF as follows: <code>{-option=value}</code>
* </p>
*
* @param n The number of arguments.
* @param args The argument values. Valid options are:
* <li><code>-debug</code> When present the TestRunnerClient
* is run in debug modus and displays debug messages.</li>
* <li><code>-port=number</code> Defines the port where
* CppUnitServer is listening for client connections.</li>
*/
void Init(int n,char *args[]);
/*!
* Runs the TestRunnerClient. A trial to connect to the CppUnitServer is done.
* The test results are sent to the CppUnitServer.
*
* @return The return value is <code>0</code> when the CppUnitServer was connected successfully
* otherwise the return value is <code>-1</code>.
*/
int Run();
/*!
* Stops processing <code>CppUnit</code> from executing tests.
*/
void Stop();
/*!
* Method defined in <code>CppUnit::TestListener</code>.
*/
void startTest(CppUnit::Test *test);
/*!
* Method defined in <code>CppUnit::TestListener</code>.
*/
void addFailure(const CppUnit::TestFailure &failure);
/*!
* Method defined in <code>CppUnit::TestListener</code>.
*/
void endTest(CppUnit::Test *test);
private:
int Connect();
void RunTests();
void ShutDown();
// utility methods
void ParseCommandLine(int n, char *args[]);
void DefineHostName();
void InstallListeners();
void UninstallListeners();
/*!
* Sends the given test to the CppUnitView.
* <p>
* In case of test is of type CppUnit::Test the following protocol is sent:
* <code>TSTTREE name, false, testCaseCount</code>
* </p>
* <p>
* In case of test is of type CppUnit::TestSuite the following protocol is sent:
* TSTTREE name, true, testCount
* </p>
* @param test the CppUnit test
*/
void SendTestTree(CppUnit::Test *test);
void SendMessage(std::string msg);
// Notification methods
void NotifyTestRunStarted(int testCount);
void NotifyTestRunEnded(long elapsedTime);
void NotifyTestRunStopped(long elapsedTime);
void NotifyTestTreeEntry(std::string treeEntry);
void NotifyTestStarted(std::string testName);
void NotifyTestEnded(std::string testName);
void NotifyTestFailed(std::string status, std::string testName, std::string trace);
std::string GetTrace(const CppUnit::TestFailure &failure);
long CurrentTimeMillis();
void PrivateSleep(int millisecs);
};
#endif /*CPPUNIT_MAIN*/
#endif /*TESTRUNNERSERVER_H_*/
|