[32] | 1 | // replay.cpp : Defines the entry point for the console application.
|
---|
| 2 | //
|
---|
| 3 |
|
---|
| 4 | #include "stdafx.h"
|
---|
| 5 |
|
---|
| 6 | #include "LogParser.h"
|
---|
| 7 | #include "SAXContentHandlerImpl.h"
|
---|
| 8 | #include <iostream>
|
---|
| 9 |
|
---|
[161] | 10 | #include "options.h"
|
---|
| 11 |
|
---|
| 12 | const char * optv[] = {
|
---|
| 13 | "r:resultfile <string>",
|
---|
| 14 | "d:msgdelay <number>",
|
---|
| 15 | "w:wait <number>",
|
---|
| 16 | "s:startdelay <number>",
|
---|
| 17 | "p:path <string>"
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | void convertTCharToChar(const TCHAR * source, char ** dest) {
|
---|
| 21 | #ifdef UNICODE
|
---|
| 22 | std::wstring wstr(source);
|
---|
| 23 | int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
---|
| 24 | std::string strTo( size_needed, 0 );
|
---|
| 25 | WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
---|
| 26 | *dest = new char[strTo.size()+1];
|
---|
| 27 | memcpy((void*)*dest, strTo.c_str(), strTo.size()+1);
|
---|
| 28 | #else
|
---|
| 29 | std::string str(source);
|
---|
| 30 | *dest = new char[strTo.size()+1];
|
---|
| 31 | memcpy(*dest, strTo.c_str(), strTo.size()+1);
|
---|
| 32 | #endif
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | void convertCharToTChar(const char * source, TCHAR ** dest) {
|
---|
| 36 | #ifdef UNICODE
|
---|
| 37 | std::string str(source);
|
---|
| 38 | int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
|
---|
| 39 | std::wstring wstrTo( size_needed, 0 );
|
---|
| 40 | MultiByteToWideChar (CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
|
---|
| 41 | *dest = new TCHAR[wstrTo.size()+1];
|
---|
| 42 | memcpy((void*)*dest, wstrTo.c_str(), (wstrTo.size()+1)*sizeof(TCHAR));
|
---|
| 43 | #else
|
---|
| 44 | std::string str(source);
|
---|
| 45 | *dest = new char[strTo.size()+1];
|
---|
| 46 | memcpy(*dest, strTo.c_str(), strTo.size()+1);
|
---|
| 47 | #endif
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[32] | 50 | int _tmain(int argc, _TCHAR* argv[])
|
---|
| 51 | {
|
---|
[161] | 52 | int optchar;
|
---|
| 53 | const char * optarg;
|
---|
| 54 |
|
---|
| 55 | // set default values
|
---|
| 56 | TCHAR * resultfile = NULL;
|
---|
| 57 | int msgdelay = 0;
|
---|
| 58 | int startdelay = 5000;
|
---|
| 59 | int wait = 1;
|
---|
| 60 | TCHAR * workingPath = NULL;
|
---|
| 61 |
|
---|
| 62 | int argc_char = argc-2;
|
---|
| 63 | char ** argv_char = new char*[argc_char];
|
---|
| 64 |
|
---|
| 65 | // convert argv to char*[]
|
---|
| 66 | convertTCharToChar(argv[0], &argv_char[0]);
|
---|
| 67 | for( int i=3; i<argc; i++ ) {
|
---|
| 68 | convertTCharToChar(argv[i], &argv_char[i-2]);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | // parse options
|
---|
| 72 | Options opts(*argv_char, optv);
|
---|
| 73 | OptArgvIter iter(--argc_char, ++argv_char);
|
---|
| 74 | while( optchar = opts(iter, optarg) ) {
|
---|
| 75 | switch(optchar) {
|
---|
| 76 | case 'r':
|
---|
| 77 | convertCharToTChar(optarg, &resultfile);
|
---|
| 78 | break;
|
---|
| 79 | case 'd':
|
---|
| 80 | msgdelay = atoi(optarg);
|
---|
| 81 | break;
|
---|
| 82 | case 'w':
|
---|
| 83 | wait = atoi(optarg);
|
---|
| 84 | break;
|
---|
| 85 | case 'p':
|
---|
| 86 | convertCharToTChar(optarg, &workingPath);
|
---|
| 87 | break;
|
---|
| 88 | case 's':
|
---|
| 89 | startdelay = atoi(optarg);
|
---|
| 90 | break;
|
---|
| 91 | default:
|
---|
| 92 | break;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | for( int i=0; i<argc_char; i++ ) {
|
---|
| 96 | delete[] argv_char[i];
|
---|
| 97 | }
|
---|
| 98 | //delete[] argv_char; //TODO does not work?!
|
---|
| 99 |
|
---|
[160] | 100 | if (argc<4)
|
---|
[32] | 101 | {
|
---|
[161] | 102 | std::wcout << L"Usage: " << argv[0] << L"<replayfile> <applicationundertest> [-r <resultfile>] [-d <useDefaultDelay>] [-w <waitAfterFinish>] [-p <workingPath>] [-s <startupDelay>]" << std::endl;
|
---|
[32] | 103 | return 0;
|
---|
| 104 | }
|
---|
[160] | 105 | TCHAR * replayfile = argv[1];
|
---|
| 106 | TCHAR * appUnderTest = argv[2];
|
---|
[32] | 107 |
|
---|
| 108 | // initialize COM library for the current thread
|
---|
| 109 | CoInitialize(NULL);
|
---|
| 110 | MSXML2::ISAXXMLReader* pXMLReader = NULL;
|
---|
| 111 |
|
---|
| 112 | // create an instance of the XML reader
|
---|
| 113 | HRESULT hr = CoCreateInstance(
|
---|
| 114 | __uuidof(MSXML2::SAXXMLReader),
|
---|
| 115 | NULL,
|
---|
| 116 | CLSCTX_ALL,
|
---|
| 117 | __uuidof(MSXML2::ISAXXMLReader),
|
---|
| 118 | (void **)&pXMLReader);
|
---|
| 119 |
|
---|
| 120 | if( !FAILED(hr) ) {
|
---|
[160] | 121 | TestResults results(replayfile);
|
---|
[104] | 122 | std::wcout << L"replaying sessions in " << argv[1] << std::endl;
|
---|
[161] | 123 | LogParser * parser = new LogParser(appUnderTest, startdelay, &results, (bool) msgdelay);
|
---|
[32] | 124 | pXMLReader->putContentHandler(parser);
|
---|
[160] | 125 | hr = pXMLReader->parseURL(replayfile);
|
---|
[32] | 126 | pXMLReader->Release();
|
---|
[104] | 127 | std::wcout << L"================================================" << std::endl;
|
---|
| 128 | std::wcout << L"replay completed" << std::endl;
|
---|
[160] | 129 | if( resultfile!=NULL ) {
|
---|
| 130 | results.write(resultfile);
|
---|
| 131 | std::wcout << L"results written to " << resultfile << std::endl;
|
---|
[105] | 132 | }
|
---|
[32] | 133 | }
|
---|
| 134 |
|
---|
| 135 | CoUninitialize();
|
---|
[160] | 136 |
|
---|
| 137 | if( wait!=0 ) {
|
---|
| 138 | std::wcout << L"press enter to exit ...";
|
---|
| 139 | getchar();
|
---|
| 140 | }
|
---|
[32] | 141 |
|
---|
[161] | 142 | delete resultfile;
|
---|
| 143 |
|
---|
[32] | 144 | return 0;
|
---|
| 145 | }
|
---|
| 146 |
|
---|