| [41e8e2] | 1 | /*******************************************************************************
 | 
|---|
 | 2 |  * Copyright (c) 2008 Gerhard Leonhartsberger.
 | 
|---|
 | 3 |  * All rights reserved. This program and the accompanying materials
 | 
|---|
 | 4 |  * are made available under the terms of the Eclipse Public License v1.0
 | 
|---|
 | 5 |  * which accompanies this distribution, and is available at
 | 
|---|
 | 6 |  * http://www.eclipse.org/legal/epl-v10.html
 | 
|---|
 | 7 |  *******************************************************************************/
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #ifndef TESTRUNNERSERVER_H_
 | 
|---|
 | 10 | #define TESTRUNNERSERVER_H_
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | #ifdef CPPUNIT_MAIN
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | #include "cppunit/TestListener.h"
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <vector>
 | 
|---|
 | 17 | #include <string>
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | /*!
 | 
|---|
 | 20 |  * Class <code>TestRunnerClient</code> handles the network connection to the
 | 
|---|
 | 21 |  * <code>CppUnitServer</code> and executes all registered CppUnit tests.
 | 
|---|
 | 22 |  * <p>
 | 
|---|
 | 23 |  * The meta data of the CppUnit tests and the test results are sent to the
 | 
|---|
 | 24 |  * <code>CppUnitServer</code> for displaying.
 | 
|---|
 | 25 |  * </p>
 | 
|---|
 | 26 |  * <p>
 | 
|---|
 | 27 |  * For debugging purposes class <code>TestRunnerClient</code> displays debug
 | 
|---|
 | 28 |  * messages on <code>std.cerr</code>. The debug modus is activated by specifying
 | 
|---|
 | 29 |  * <code>debug</code> command line option. The command line is parsed by method
 | 
|---|
 | 30 |  * <code>Init()</code>.
 | 
|---|
 | 31 |  * </p>
 | 
|---|
 | 32 |  * <p>
 | 
|---|
 | 33 |  * Note: This class is not intended to be subclassed by clients. This class is
 | 
|---|
 | 34 |  * based on the original <code>RemoteTestRunner</code> class provided by
 | 
|---|
 | 35 |  * <code>org.eclipse.cdt.cppunit</code>.
 | 
|---|
 | 36 |  * </p>
 | 
|---|
 | 37 |  *
 | 
|---|
 | 38 |  * @author Gerhard Leonhartsberger
 | 
|---|
 | 39 |  */
 | 
|---|
 | 40 | class TestRunnerClient: public CppUnit::TestListener
 | 
|---|
 | 41 | {
 | 
|---|
 | 42 | private:
 | 
|---|
 | 43 |         CppUnit::TestResult *fTestResult;
 | 
|---|
 | 44 |         int fClientSocket;
 | 
|---|
 | 45 |         char *fHost;
 | 
|---|
 | 46 |         int fPort;
 | 
|---|
 | 47 |         int fDebugMode;
 | 
|---|
 | 48 |         int fKeepAlive;
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | public:
 | 
|---|
 | 51 |         TestRunnerClient();
 | 
|---|
 | 52 |         virtual ~TestRunnerClient();
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |         /*!
 | 
|---|
 | 55 |          * Initializes the <code>TestRunnerClient</code>.
 | 
|---|
 | 56 |          * <p>
 | 
|---|
 | 57 |          * The given <code>args</code> are parsed. The syntax for the arguments is
 | 
|---|
 | 58 |          * defined in EBNF as follows: <code>{-option=value}</code>
 | 
|---|
 | 59 |          * </p>
 | 
|---|
 | 60 |          *
 | 
|---|
 | 61 |          * @param n The number of arguments.
 | 
|---|
 | 62 |          * @param args The argument values. Valid options are:
 | 
|---|
 | 63 |          *                         <li><code>-debug</code> When present the TestRunnerClient
 | 
|---|
 | 64 |          *                              is run in debug modus and displays debug messages.</li>
 | 
|---|
 | 65 |          *                         <li><code>-port=number</code> Defines the port where
 | 
|---|
 | 66 |          *                         CppUnitServer is listening for client connections.</li>
 | 
|---|
 | 67 |          */
 | 
|---|
 | 68 |         void Init(int n,char *args[]);
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 |         /*!
 | 
|---|
 | 71 |          * Runs the TestRunnerClient. A trial to connect to the CppUnitServer is done.
 | 
|---|
 | 72 |          * The test results are sent to the CppUnitServer.
 | 
|---|
 | 73 |          *
 | 
|---|
 | 74 |          * @return The return value is <code>0</code> when the CppUnitServer was connected successfully
 | 
|---|
 | 75 |          * otherwise the return value is <code>-1</code>.
 | 
|---|
 | 76 |          */
 | 
|---|
 | 77 |         int Run();
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |         /*!
 | 
|---|
 | 80 |          * Stops processing <code>CppUnit</code> from executing tests.
 | 
|---|
 | 81 |          */
 | 
|---|
 | 82 |         void Stop();
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |         /*!
 | 
|---|
 | 85 |          * Method defined in <code>CppUnit::TestListener</code>.
 | 
|---|
 | 86 |          */
 | 
|---|
 | 87 |         void startTest(CppUnit::Test *test);
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 |         /*!
 | 
|---|
 | 90 |          * Method defined in <code>CppUnit::TestListener</code>.
 | 
|---|
 | 91 |          */
 | 
|---|
 | 92 |         void addFailure(const CppUnit::TestFailure &failure);
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 |         /*!
 | 
|---|
 | 95 |          * Method defined in <code>CppUnit::TestListener</code>.
 | 
|---|
 | 96 |          */
 | 
|---|
 | 97 |         void endTest(CppUnit::Test *test);
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | private:
 | 
|---|
 | 100 |         int Connect();
 | 
|---|
 | 101 |         void RunTests();
 | 
|---|
 | 102 |         void ShutDown();
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 |         // utility methods
 | 
|---|
 | 105 |         void ParseCommandLine(int n, char *args[]);
 | 
|---|
 | 106 |         void DefineHostName();
 | 
|---|
 | 107 |         void InstallListeners();
 | 
|---|
 | 108 |         void UninstallListeners();
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 |         /*!
 | 
|---|
 | 111 |          * Sends the given test to the CppUnitView.
 | 
|---|
 | 112 |          * <p>
 | 
|---|
 | 113 |          * In case of test is of type CppUnit::Test the following protocol is sent:
 | 
|---|
 | 114 |          * <code>TSTTREE name, false, testCaseCount</code>
 | 
|---|
 | 115 |          * </p>
 | 
|---|
 | 116 |          * <p>
 | 
|---|
 | 117 |          * In case of test is of type CppUnit::TestSuite the following protocol is sent:
 | 
|---|
 | 118 |          * TSTTREE name, true, testCount
 | 
|---|
 | 119 |          * </p>
 | 
|---|
 | 120 |          * @param test the CppUnit test
 | 
|---|
 | 121 |          */
 | 
|---|
 | 122 |         void SendTestTree(CppUnit::Test *test);
 | 
|---|
 | 123 |         void SendMessage(std::string msg);
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 |         // Notification methods
 | 
|---|
 | 126 |         void NotifyTestRunStarted(int testCount);
 | 
|---|
 | 127 |         void NotifyTestRunEnded(long elapsedTime);
 | 
|---|
 | 128 |         void NotifyTestRunStopped(long elapsedTime);
 | 
|---|
 | 129 |         void NotifyTestTreeEntry(std::string treeEntry);
 | 
|---|
 | 130 |         void NotifyTestStarted(std::string testName);
 | 
|---|
 | 131 |         void NotifyTestEnded(std::string testName);
 | 
|---|
 | 132 |         void NotifyTestFailed(std::string status, std::string testName, std::string trace);
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 |         std::string GetTrace(const CppUnit::TestFailure &failure);
 | 
|---|
 | 135 |         long CurrentTimeMillis();
 | 
|---|
 | 136 |         void PrivateSleep(int millisecs);
 | 
|---|
 | 137 | };
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | #endif /*CPPUNIT_MAIN*/
 | 
|---|
 | 140 | #endif /*TESTRUNNERSERVER_H_*/
 | 
|---|