diff options
Diffstat (limited to 'cppe/test/Common/TestCommon.cpp')
-rwxr-xr-x | cppe/test/Common/TestCommon.cpp | 151 |
1 files changed, 72 insertions, 79 deletions
diff --git a/cppe/test/Common/TestCommon.cpp b/cppe/test/Common/TestCommon.cpp index 2d1809dc91f..343a71207d5 100755 --- a/cppe/test/Common/TestCommon.cpp +++ b/cppe/test/Common/TestCommon.cpp @@ -7,24 +7,23 @@ // // ********************************************************************** -#include <TestCommon.h>
-#include <TestApplication.h>
-#include <IceE/StaticMutex.h>
+#include <TestCommon.h> +#include <TestApplication.h> + +#include <IceE/StaticMutex.h> #include <IceE/Thread.h> -#ifndef _WIN32 -# include <IceE/Time.h> -#endif +#include <IceE/Time.h> #include <stdarg.h> -using namespace Ice;
using namespace std; +using namespace Ice; class LoggerI : public Logger { public: -
- virtual void
+ + virtual void print(const string& message) { tprintf("%s\n", message.c_str()); @@ -32,16 +31,18 @@ public: virtual void trace(const string& category, const string& message) - {
+ { string s = "[ ";
-#ifdef _WIN32 - char buf[1024];
- sprintf(buf, "%ld", GetTickCount()); - s += buf;
+#ifdef _WIN32
+ {
+ char buf[1024];
+ sprintf(buf, "%ld", GetTickCount());
+ s += buf;
+ }
#else - s += IceUtil::Time::now().toMilliSeconds(); + s += IceUtil::Time::now().toMilliSeconds();
#endif - s += ' ';
+ s += ' '; if(!category.empty()) { @@ -71,7 +72,7 @@ public: } }; -static IceUtil::StaticMutex terminatedMutex = ICEE_STATIC_MUTEX_INITIALIZER;
+static IceUtil::StaticMutex terminatedMutex = ICEE_STATIC_MUTEX_INITIALIZER; static bool appTerminated= false; #ifdef _WIN32_WCE @@ -84,7 +85,7 @@ class TestSuiteFailed { public: }; -
+ static FILE* _tprintfp = 0; static HWND hEdit; static HWND mainWnd; @@ -92,20 +93,20 @@ static IceUtil::ThreadControl mainThread; void tprintf(const char* fmt, ...) -{
+{ va_list va; va_start(va, fmt); char buf[1024]; _vsnprintf(buf, sizeof(buf)-1, fmt, va); buf[sizeof(buf)-1] = '\0'; - va_end(va);
-
- if(_tprintfp)
- {
- fwrite(buf, strlen(buf), 1, _tprintfp);
- fflush(_tprintfp);
- return;
- }
+ va_end(va); + + if(_tprintfp) + { + fwrite(buf, strlen(buf), 1, _tprintfp); + fflush(_tprintfp); + return; + } char* start = buf; const char* end = start + strlen(start); @@ -125,11 +126,11 @@ tprintf(const char* fmt, ...) } *curr = '\0'; static TCHAR nlStr[] = L"\r\n"; -
- //
- // If the thread is not the main thread we have to post a message
- // to the main thread to do the EM_REPLACESEL. Calling SendMessage
- // from a thread other than main is not permitted.
+ + // + // If the thread is not the main thread we have to post a message + // to the main thread to do the EM_REPLACESEL. Calling SendMessage + // from a thread other than main is not permitted. // if(IceUtil::ThreadControl() != mainThread) { @@ -187,14 +188,11 @@ WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_CREATE: { - //HFONT hfDefault; - RECT rcClient; GetClientRect(hWnd, &rcClient); hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_VISIBLE | WS_VSCROLL /*| WS_HSCROLL*/ | ES_MULTILINE, + WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, - /*0,0,100,100,*/ hWnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL); assert(hEdit != NULL); } @@ -202,12 +200,8 @@ WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SIZE: { - HWND hEdit; RECT rcClient; - GetClientRect(hWnd, &rcClient); - - hEdit = GetDlgItem(hWnd, IDC_MAIN_EDIT); SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER); } break; @@ -217,7 +211,7 @@ WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) DestroyWindow(hWnd); break; } -
+ case WM_QUIT: case WM_DESTROY: { @@ -243,7 +237,7 @@ TestApplication::main(HINSTANCE hInstance) wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = LoadIcon(NULL, 0/*IDI_APPLICATION*/); + wc.hIcon = LoadIcon(NULL, 0); wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; @@ -251,42 +245,40 @@ TestApplication::main(HINSTANCE hInstance) if(!RegisterClass(&wc)) { - MessageBox(NULL, L"Window Registration Failed!", L"Error!", - MB_ICONEXCLAMATION | MB_OK); + MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } -
- wchar_t wName[1024] = L"Test";
- if(_name.size() > 0)
- {
- int len = _name.size();
- if(len > 1023)
- {
- len = 1023;
- }
- mbstowcs(wName, _name.c_str(), len);
- wName[len] = L'\0';
- } -
- RECT rect;
- GetClientRect(GetDesktopWindow(), &rect);
- int width = rect.right - rect.left;
- if(width > 320)
- {
- width = 320;
- }
- int height = rect.bottom - rect.top;
- if(height > 200)
- {
- height = 200;
- }
+ + wchar_t wName[1024] = L"Test"; + if(_name.size() > 0) + { + int len = _name.size(); + if(len > 1023) + { + len = 1023; + } + mbstowcs(wName, _name.c_str(), len); + wName[len] = L'\0'; + } + + RECT rect; + GetClientRect(GetDesktopWindow(), &rect); + int width = rect.right - rect.left; + if(width > 320) + { + width = 320; + } + int height = rect.bottom - rect.top; + if(height > 200) + { + height = 200; + } mainWnd = CreateWindow(windowClassName, wName, WS_VISIBLE|WS_OVERLAPPED|WS_SYSMENU|WS_SIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, hInstance, NULL); if(mainWnd == NULL) { - MessageBox(NULL, L"Window Creation Failed!", L"Error!", - MB_ICONEXCLAMATION | MB_OK); + MessageBox(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } @@ -299,6 +291,7 @@ TestApplication::main(HINSTANCE hInstance) extern int __argc; extern char **__argv; status = run(__argc, __argv); + tprintf("\ntest complete\n"); } catch(const TestSuiteFailed&) { @@ -314,7 +307,7 @@ TestApplication::main(HINSTANCE hInstance) tprintf("std::exception: %s\n", ex.what()); status = EXIT_FAILURE; } - catch(const std::string& msg) + catch(const string& msg) { tprintf("std::string: %s\n", msg.c_str()); status = EXIT_FAILURE; @@ -385,9 +378,9 @@ TestApplication::loadConfig(const PropertiesPtr& properties) } } #else -
-static IceUtil::StaticMutex tprintMutex = ICEE_STATIC_MUTEX_INITIALIZER;
-
+ +static IceUtil::StaticMutex tprintMutex = ICEE_STATIC_MUTEX_INITIALIZER; + void tprintf(const char* fmt, ...) { @@ -420,7 +413,7 @@ TestApplication::main(int ac, char* av[]) tprintf("std::exception: %s\n", ex.what()); status = EXIT_FAILURE; } - catch(const std::string& msg) + catch(const string& msg) { tprintf("std::string: %s\n", msg.c_str()); status = EXIT_FAILURE; @@ -482,12 +475,12 @@ void TestApplication::setCommunicator(const CommunicatorPtr& communicator) { _communicator = communicator; -#ifdef _WIN32_WCE
+#ifdef _WIN32_WCE if(communicator->getProperties()->getPropertyWithDefault("LogToFile", "0") != "0") { - _tprintfp = fopen(("log-" + _name + ".txt").c_str(), "w");
+ _tprintfp = fopen(("log-" + _name + ".txt").c_str(), "w"); } -#endif
+#endif _communicator->setLogger(new LoggerI); } |