From 17b117e73df71925d73ee026b4f54aa1867ce0a5 Mon Sep 17 00:00:00 2001 From: Jesse Gilles Date: Mon, 20 Apr 2015 16:49:52 -0500 Subject: initial commit --- test/TestRunnerClient.h | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 test/TestRunnerClient.h (limited to 'test/TestRunnerClient.h') diff --git a/test/TestRunnerClient.h b/test/TestRunnerClient.h new file mode 100644 index 0000000..4dc4460 --- /dev/null +++ b/test/TestRunnerClient.h @@ -0,0 +1,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 +#include +#include +#include + + +/*! + * Class TestRunnerClient handles the network connection to the + * CppUnitServer and executes all registered CppUnit tests. + *

+ * The meta data of the CppUnit tests and the test results are sent to the + * CppUnitServer for displaying. + *

+ *

+ * For debugging purposes class TestRunnerClient displays debug + * messages on std.cerr. The debug modus is activated by specifying + * debug command line option. The command line is parsed by method + * Init(). + *

+ *

+ * Note: This class is not intended to be subclassed by clients. This class is + * based on the original RemoteTestRunner class provided by + * org.eclipse.cdt.cppunit. + *

+ * + * @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 TestRunnerClient. + *

+ * The given args are parsed. The syntax for the arguments is + * defined in EBNF as follows: {-option=value} + *

+ * + * @param n The number of arguments. + * @param args The argument values. Valid options are: + *
  • -debug When present the TestRunnerClient + * is run in debug modus and displays debug messages.
  • + *
  • -port=number Defines the port where + * CppUnitServer is listening for client connections.
  • + */ + 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 0 when the CppUnitServer was connected successfully + * otherwise the return value is -1. + */ + int Run(); + + /*! + * Stops processing CppUnit from executing tests. + */ + void Stop(); + + /*! + * Method defined in CppUnit::TestListener. + */ + void startTest(CppUnit::Test *test); + + /*! + * Method defined in CppUnit::TestListener. + */ + void addFailure(const CppUnit::TestFailure &failure); + + /*! + * Method defined in CppUnit::TestListener. + */ + 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. + *

    + * In case of test is of type CppUnit::Test the following protocol is sent: + * TSTTREE name, false, testCaseCount + *

    + *

    + * In case of test is of type CppUnit::TestSuite the following protocol is sent: + * TSTTREE name, true, testCount + *

    + * @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_*/ -- cgit v1.2.3