| 1 |
// TGConsoleGui |
|---|
| 2 |
#ifndef __cxxtest__TGConsoleGui_h__ |
|---|
| 3 |
#define __cxxtest__TGConsoleGui_h__ |
|---|
| 4 |
|
|---|
| 5 |
// OSRail -- a network enabled railroad operations simulator and utilities |
|---|
| 6 |
// Copyright (C) 2007,2008 Samuel E. Henley sehenley@comcast.net |
|---|
| 7 |
// |
|---|
| 8 |
// This program is free software; you can redistribute it and/or modify |
|---|
| 9 |
// it under the terms of the GNU General Public License as published by |
|---|
| 10 |
// the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 |
// (at your option) any later version. |
|---|
| 12 |
// |
|---|
| 13 |
// This program is distributed in the hope that it will be useful, |
|---|
| 14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 |
// GNU General Public License for more details. |
|---|
| 17 |
// |
|---|
| 18 |
// You should have received a copy of the GNU General Public License along |
|---|
| 19 |
// with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 20 |
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 21 |
// |
|---|
| 22 |
// |
|---|
| 23 |
#include <cxxtest/Gui.h> |
|---|
| 24 |
#ifdef WIN32 |
|---|
| 25 |
#include <windows.h> |
|---|
| 26 |
#include <shlobj.h> //Shell folders |
|---|
| 27 |
#include <tchar.h> |
|---|
| 28 |
#include <process.h> |
|---|
| 29 |
#else //Linux |
|---|
| 30 |
#include <stdio.h> |
|---|
| 31 |
#include <stdlib.h> |
|---|
| 32 |
#include <stdarg.h> |
|---|
| 33 |
#include <string.h> |
|---|
| 34 |
#include <sys/types.h> |
|---|
| 35 |
#include <sys/ipc.h> |
|---|
| 36 |
#include <sys/shm.h> |
|---|
| 37 |
#endif |
|---|
| 38 |
|
|---|
| 39 |
#include "paths.h" |
|---|
| 40 |
#include "ipc.h" |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
#include <vector> |
|---|
| 44 |
#include <string> |
|---|
| 45 |
|
|---|
| 46 |
namespace CxxTest |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
class TGConsoleGui : public GuiListener |
|---|
| 50 |
{ |
|---|
| 51 |
public: |
|---|
| 52 |
|
|---|
| 53 |
/// virtual void runGui( int &argc, char **argv, TestListener &listener ) //runs tests |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
void enterGui( int &argc, char **argv ) |
|---|
| 57 |
{ |
|---|
| 58 |
parseCommandLine( argc, argv ); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
void leaveGui() |
|---|
| 62 |
{ |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
virtual void enterWorld( const WorldDescription& desc ) |
|---|
| 66 |
{ |
|---|
| 67 |
//numSuites(); |
|---|
| 68 |
type_name = "enterWorld"; |
|---|
| 69 |
total_tests = desc.numTotalTests(); |
|---|
| 70 |
file_name = desc.firstSuite()->file(); |
|---|
| 71 |
line_number = desc.firstSuite()->line(); |
|---|
| 72 |
suite_name = "World"; |
|---|
| 73 |
test_name = "..."; |
|---|
| 74 |
test_expression = "..."; |
|---|
| 75 |
total_tests_done = 0; |
|---|
| 76 |
message( "EnterWorld" ); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
virtual void enterSuite( const SuiteDescription& desc ) |
|---|
| 80 |
{ |
|---|
| 81 |
type_name = "enterSuite"; |
|---|
| 82 |
suite_name = desc.suiteName(); |
|---|
| 83 |
file_name = desc.file(); |
|---|
| 84 |
line_number = desc.line(); |
|---|
| 85 |
test_name = "..."; |
|---|
| 86 |
test_expression = "..."; |
|---|
| 87 |
message( "EnterSuite" ); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
virtual void enterTest( const TestDescription& desc ) |
|---|
| 91 |
{ |
|---|
| 92 |
type_name = "enterTest"; |
|---|
| 93 |
file_name = desc.file(); |
|---|
| 94 |
line_number = desc.line(); |
|---|
| 95 |
test_name = desc.testName(); |
|---|
| 96 |
test_expression = "..."; |
|---|
| 97 |
++total_tests_done; |
|---|
| 98 |
message( "EnterTest" ); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
virtual void leaveWorld( const WorldDescription& desc ) |
|---|
| 102 |
{ |
|---|
| 103 |
//numSuites(); |
|---|
| 104 |
type_name = "leaveWorld"; |
|---|
| 105 |
total_tests = desc.numTotalTests(); |
|---|
| 106 |
file_name = desc.firstSuite()->file(); |
|---|
| 107 |
line_number = desc.firstSuite()->line(); |
|---|
| 108 |
suite_name = "World"; |
|---|
| 109 |
test_name = "..."; |
|---|
| 110 |
test_expression = "..."; |
|---|
| 111 |
message( "LeaveWorld" ); |
|---|
| 112 |
total_tests_done = 0; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
virtual void leaveSuite( const SuiteDescription& desc ) |
|---|
| 116 |
{ |
|---|
| 117 |
type_name = "leaveSuite"; |
|---|
| 118 |
suite_name = desc.suiteName(); |
|---|
| 119 |
file_name = desc.file(); |
|---|
| 120 |
line_number = desc.line(); |
|---|
| 121 |
test_name = "..."; |
|---|
| 122 |
test_expression = "..."; |
|---|
| 123 |
message( "LeaveSuite" ); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
virtual void leaveTest( const TestDescription& desc ) |
|---|
| 127 |
{ |
|---|
| 128 |
type_name = "leaveTest"; |
|---|
| 129 |
file_name = desc.file(); |
|---|
| 130 |
line_number = desc.line(); |
|---|
| 131 |
test_name = desc.testName(); |
|---|
| 132 |
test_expression = "..."; |
|---|
| 133 |
++total_tests_done; |
|---|
| 134 |
message( "LeaveTest" ); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
virtual void trace( const char* file, unsigned line, const char* expression ) |
|---|
| 140 |
{ |
|---|
| 141 |
type_name = "trace"; |
|---|
| 142 |
file_name = file; |
|---|
| 143 |
line_number = line; |
|---|
| 144 |
test_expression = expression; |
|---|
| 145 |
message( "trace" ); |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
virtual void warning( const char* file, unsigned line, const char* expression ) |
|---|
| 149 |
{ |
|---|
| 150 |
type_name = "warning"; |
|---|
| 151 |
file_name = file; |
|---|
| 152 |
line_number = line; |
|---|
| 153 |
test_expression = expression; |
|---|
| 154 |
message( "warning" ); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
virtual void failedTest( const char* file, unsigned line, const char* expression ) |
|---|
| 158 |
{ |
|---|
| 159 |
type_name = "failedTest"; |
|---|
| 160 |
file_name = file; |
|---|
| 161 |
line_number = line; |
|---|
| 162 |
test_expression = expression; |
|---|
| 163 |
message( "failedTest" ); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
virtual void failedAssert( const char* file, unsigned line, const char* expression ) |
|---|
| 167 |
{ |
|---|
| 168 |
type_name = "failedAssert"; |
|---|
| 169 |
file_name = file; |
|---|
| 170 |
line_number = line; |
|---|
| 171 |
test_expression = expression; |
|---|
| 172 |
message( "failedAssert" ); |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
virtual void failedAssertEquals( const char* file, unsigned line, const char* xStr, |
|---|
| 176 |
const char* yStr, const char* x, const char* y ) |
|---|
| 177 |
{ |
|---|
| 178 |
type_name = "failedAssertEquals"; |
|---|
| 179 |
file_name = file; |
|---|
| 180 |
line_number = line; |
|---|
| 181 |
test_expression = "..."; |
|---|
| 182 |
message( "failedAssertEquals" ); |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
virtual void failedAssertSameData( const char* file, unsigned line, const char* xStr, |
|---|
| 186 |
const char* yStr, const char* sizeStr, const void * x, const void * y, unsigned size ) |
|---|
| 187 |
{ |
|---|
| 188 |
type_name = "failedAssertSameData"; |
|---|
| 189 |
file_name = file; |
|---|
| 190 |
line_number = line; |
|---|
| 191 |
test_expression = "..."; |
|---|
| 192 |
message( "failedAssertSameData" ); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
virtual void failedAssertDelta( const char* file, unsigned line, const char* xStr, const char* yStr, |
|---|
| 196 |
const char* dStr, const char* x, const char* y, const char* d ) |
|---|
| 197 |
{ |
|---|
| 198 |
type_name = "failedAssertDelta"; |
|---|
| 199 |
file_name = file; |
|---|
| 200 |
line_number = line; |
|---|
| 201 |
test_expression = "..."; |
|---|
| 202 |
message( "failedAssertDelta" ); |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
virtual void failedAssertDiffers( const char* file, unsigned line, const char* xStr, const char* yStr, const char* value ) |
|---|
| 206 |
{ |
|---|
| 207 |
type_name = "failedAssertDiffers"; |
|---|
| 208 |
file_name = file; |
|---|
| 209 |
line_number = line; |
|---|
| 210 |
test_expression = "..."; |
|---|
| 211 |
message( "failedAssertDiffers" ); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
virtual void failedAssertLessThan( const char* file, unsigned line, const char* xStr, |
|---|
| 215 |
const char* yStr, const char* x, const char* y ) |
|---|
| 216 |
{ |
|---|
| 217 |
type_name = "failedAssertLessThan"; |
|---|
| 218 |
file_name = file; |
|---|
| 219 |
line_number = line; |
|---|
| 220 |
test_expression = "..."; |
|---|
| 221 |
message( "failedAssertLessThan" ); |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
virtual void failedAssertLessThanEquals( const char* file, unsigned line, const char* xStr, |
|---|
| 225 |
const char* yStr, const char* x, const char* y ) |
|---|
| 226 |
{ |
|---|
| 227 |
type_name = "failedAssertLessThanEquals"; |
|---|
| 228 |
file_name = file; |
|---|
| 229 |
line_number = line; |
|---|
| 230 |
test_expression = "..."; |
|---|
| 231 |
message( "failedAssertLessThanEquals" ); |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
virtual void failedAssertPredicate( const char* file, unsigned line, const char* predicate, const char* xStr, const char* x ) |
|---|
| 235 |
{ |
|---|
| 236 |
type_name = "failedAssertPredicate"; |
|---|
| 237 |
file_name = file; |
|---|
| 238 |
line_number = line; |
|---|
| 239 |
test_expression = predicate; |
|---|
| 240 |
message( "failedAssertPredicate" ); |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
virtual void failedAssertRelation( const char* file, unsigned line, const char* relation, |
|---|
| 244 |
const char* xStr, const char* yStr, const char* x, const char* y ) |
|---|
| 245 |
{ |
|---|
| 246 |
type_name = "failedAssertRelation"; |
|---|
| 247 |
file_name = file; |
|---|
| 248 |
line_number = line; |
|---|
| 249 |
test_expression = relation; |
|---|
| 250 |
message( "failedAssertRelation" ); |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
virtual void failedAssertThrows( const char* file, unsigned line, const char* expression, const char* type, bool otherThrown ) |
|---|
| 254 |
{ |
|---|
| 255 |
type_name = "failedAssertThrows"; |
|---|
| 256 |
file_name = file; |
|---|
| 257 |
line_number = line; |
|---|
| 258 |
test_expression = expression; |
|---|
| 259 |
message( "failedAssertThrows" ); |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
virtual void failedAssertThrowsNot( const char* file, unsigned line, const char* expression ) |
|---|
| 263 |
{ |
|---|
| 264 |
type_name = "failedAssertThrowsNot"; |
|---|
| 265 |
file_name = file; |
|---|
| 266 |
line_number = line; |
|---|
| 267 |
test_expression = expression; |
|---|
| 268 |
message( "failedAssertThrowsNot" ); |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
private: |
|---|
| 274 |
|
|---|
| 275 |
void message( const char* message ) |
|---|
| 276 |
{ |
|---|
| 277 |
UNIT_TEST( "Unit Tests", suite_name.c_str(), type_name.c_str(), test_name.c_str(), file_name.c_str(), line_number, test_expression.c_str(), message ) |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
std::string suite_name; |
|---|
| 281 |
std::string test_name; |
|---|
| 282 |
std::string file_name; |
|---|
| 283 |
std::string type_name; |
|---|
| 284 |
std::string test_expression; |
|---|
| 285 |
unsigned int line_number; |
|---|
| 286 |
unsigned int total_tests; |
|---|
| 287 |
unsigned int total_tests_done; |
|---|
| 288 |
|
|---|
| 289 |
std::string title; |
|---|
| 290 |
bool start_minimized; |
|---|
| 291 |
bool keep; |
|---|
| 292 |
|
|---|
| 293 |
void parseCommandLine( int argc, char **argv ) |
|---|
| 294 |
{ |
|---|
| 295 |
start_minimized = false; |
|---|
| 296 |
keep = false; |
|---|
| 297 |
title.clear(); |
|---|
| 298 |
|
|---|
| 299 |
for ( int i = 1; i < argc; ++ i ) |
|---|
| 300 |
{ |
|---|
| 301 |
#ifdef WIN32 |
|---|
| 302 |
if ( !stricmp( argv[i], "-minimized" ) ) start_minimized = true; |
|---|
| 303 |
else if ( !stricmp( argv[i], "-keep" ) ) keep = true; |
|---|
| 304 |
else if ( !stricmp( argv[i], "-title" ) && (i + 1 < argc) )title = argv[++i]; |
|---|
| 305 |
#else //Linux |
|---|
| 306 |
if ( !strcasecmp( argv[i], "-minimized" ) ) start_minimized = true; |
|---|
| 307 |
else if ( !strcasecmp( argv[i], "-keep" ) ) keep = true; |
|---|
| 308 |
else if ( !strcasecmp( argv[i], "-title" ) && (i + 1 < argc) )title = argv[++i]; |
|---|
| 309 |
#endif //WIN32 |
|---|
| 310 |
} |
|---|
| 311 |
} |
|---|
| 312 |
}; |
|---|
| 313 |
|
|---|
| 314 |
} //namespace |
|---|
| 315 |
|
|---|
| 316 |
#endif // __cxxtest__TGConsoleGui_h__ |
|---|