00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "PocketCoreLibraryTest.h"
00028 #include <commctrl.h>
00029
00030 #define MAX_LOADSTRING 100
00031
00032 HWND hMainWnd = NULL;
00033 Collection lines;
00034
00035 bool UpdateLinesOfText(HWND hWnd);
00036 bool DrawLinesOfText(HDC hdc);
00037
00038
00039
00040 HINSTANCE hInst;
00041 HWND hwndCB;
00042
00043
00044 ATOM MyRegisterClass (HINSTANCE, LPTSTR);
00045 BOOL InitInstance (HINSTANCE, int);
00046 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
00047 LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
00048
00049 int WINAPI WinMain( HINSTANCE hInstance,
00050 HINSTANCE hPrevInstance,
00051 LPTSTR lpCmdLine,
00052 int nCmdShow)
00053 {
00054 MSG msg;
00055 HACCEL hAccelTable;
00056
00057
00058 if (!InitInstance (hInstance, nCmdShow))
00059 {
00060 return FALSE;
00061 }
00062
00063 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_POCKETCORELIBRARYTEST);
00064
00065 JTime now;
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 lines.add(JString::format("Starting Core Test at %s", (char*) now.printTime()));
00088 lines.add("");
00089 UpdateLinesOfText(hMainWnd);
00090
00091 JString ret;
00092 Collection col;
00093 int c = 0;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 try {
00122
00123 do {
00124 ret = runTest(c);
00125 col = ret.splitIntoLines();
00126 lines.addAll(col);
00127 c++;
00128 UpdateLinesOfText(hMainWnd);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 Sleep(200);
00140 } while (ret.length() > 0);
00141
00142 lines.add("");
00143 now = JTime();
00144 lines.add(JString::format("Test Complete at %s", (char*) now.printTime()));
00145 lines.add("");
00146 UpdateLinesOfText(hMainWnd);
00147
00148
00149
00150 while (GetMessage(&msg, NULL, 0, 0))
00151 {
00152 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
00153 {
00154 TranslateMessage(&msg);
00155 DispatchMessage(&msg);
00156 }
00157 }
00158
00159 } catch(...) {
00160 lines.add("");
00161 lines.add("Error 1");
00162 lines.add("");
00163 UpdateLinesOfText(hMainWnd);
00164 }
00165
00166 return msg.wParam;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
00180 {
00181 WNDCLASS wc;
00182
00183 wc.style = CS_HREDRAW | CS_VREDRAW;
00184 wc.lpfnWndProc = (WNDPROC) WndProc;
00185 wc.cbClsExtra = 0;
00186 wc.cbWndExtra = 0;
00187 wc.hInstance = hInstance;
00188 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_POCKETCORELIBRARYTEST));
00189 wc.hCursor = 0;
00190 wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
00191 wc.lpszMenuName = 0;
00192 wc.lpszClassName = szWindowClass;
00193
00194 return RegisterClass(&wc);
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
00208 {
00209 HWND hWnd;
00210 TCHAR szTitle[MAX_LOADSTRING];
00211 TCHAR szWindowClass[MAX_LOADSTRING];
00212
00213 hInst = hInstance;
00214
00215 LoadString(hInstance, IDC_POCKETCORELIBRARYTEST, szWindowClass, MAX_LOADSTRING);
00216 MyRegisterClass(hInstance, szWindowClass);
00217
00218 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
00219 hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
00220 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
00221
00222 if (!hWnd)
00223 {
00224 return FALSE;
00225 }
00226
00227 hMainWnd = hWnd;
00228
00229 ShowWindow(hWnd, nCmdShow);
00230 UpdateWindow(hWnd);
00231 if (hwndCB)
00232 CommandBar_Show(hwndCB, TRUE);
00233
00234 return TRUE;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00248 {
00249
00250 int wmId, wmEvent;
00251 PAINTSTRUCT ps;
00252
00253
00254 JString mystr;
00255
00256 switch (message)
00257 {
00258 case WM_COMMAND:
00259 wmId = LOWORD(wParam);
00260 wmEvent = HIWORD(wParam);
00261
00262 switch (wmId)
00263 {
00264 case IDM_HELP_ABOUT:
00265 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
00266 break;
00267 case IDM_FILE_EXIT:
00268 DestroyWindow(hWnd);
00269 break;
00270 default:
00271 return DefWindowProc(hWnd, message, wParam, lParam);
00272 }
00273 break;
00274 case WM_CREATE:
00275 hwndCB = CommandBar_Create(hInst, hWnd, 1);
00276 CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
00277 CommandBar_AddAdornments(hwndCB, 0, 0);
00278 break;
00279 case WM_PAINT:
00280 DrawLinesOfText(BeginPaint(hMainWnd, &ps));
00281 EndPaint(hMainWnd, &ps);
00282 break;
00283 case WM_DESTROY:
00284 CommandBar_Destroy(hwndCB);
00285 PostQuitMessage(0);
00286 break;
00287 default:
00288 return DefWindowProc(hWnd, message, wParam, lParam);
00289 }
00290 return 0;
00291 }
00292
00293
00294 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00295 {
00296 RECT rt, rt1;
00297 int DlgWidth, DlgHeight;
00298 int NewPosX, NewPosY;
00299
00300 switch (message)
00301 {
00302 case WM_INITDIALOG:
00303
00304 if (GetWindowRect(hDlg, &rt1)) {
00305 GetClientRect(GetParent(hDlg), &rt);
00306 DlgWidth = rt1.right - rt1.left;
00307 DlgHeight = rt1.bottom - rt1.top ;
00308 NewPosX = (rt.right - rt.left - DlgWidth)/2;
00309 NewPosY = (rt.bottom - rt.top - DlgHeight)/2;
00310
00311
00312 if (NewPosX < 0) NewPosX = 0;
00313 if (NewPosY < 0) NewPosY = 0;
00314 SetWindowPos(hDlg, 0, NewPosX, NewPosY,
00315 0, 0, SWP_NOZORDER | SWP_NOSIZE);
00316 }
00317 return TRUE;
00318
00319 case WM_COMMAND:
00320 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
00321 {
00322 EndDialog(hDlg, LOWORD(wParam));
00323 return TRUE;
00324 }
00325 break;
00326 }
00327 return FALSE;
00328 }
00329
00330
00331 bool UpdateLinesOfText(HWND hWnd) {
00332
00333 HDC hdc = GetDC(hWnd);
00334 DrawLinesOfText(hdc);
00335 ReleaseDC(hMainWnd, hdc);
00336 return true;
00337 }
00338
00339 bool DrawLinesOfText(HDC hdc) {
00340
00341 RECT rt;
00342 Color bgColor = Color("White");
00343 Color fgColor = Color("Blue");
00344 Color passColor = Color("Green");
00345 Color failColor = Color("Red");
00346 JString str, pass;
00347 GetClientRect(hMainWnd, &rt);
00348 RECT crt = rt;
00349 int topMargin = 24;
00350 int lheight = 14;
00351
00352 try {
00353
00354 FillRect(hdc, &rt, bgColor);
00355 Collection tabs;
00356
00357 for (int n=0; n<lines.getCount(); n++) {
00358 crt.top = rt.bottom - (n+1)*lheight;
00359 crt.bottom = rt.bottom - n*lheight;
00360 if (crt.top < topMargin)
00361 break;
00362 str = lines.get(lines.getCount()-1-n);
00363 tabs = str.split("\t");
00364
00365 if (tabs.getCount() == 1) {
00366 SetTextColor(hdc, (COLORREF) fgColor);
00367 DrawText(hdc, str, str.length(), &crt,
00368 DT_SINGLELINE | DT_TOP | DT_LEFT);
00369 }
00370 else {
00371 SetTextColor(hdc, (COLORREF) fgColor);
00372 DrawText(hdc, tabs.getFirst(), tabs.getFirst().length(), &crt,
00373 DT_SINGLELINE | DT_TOP | DT_LEFT);
00374
00375 pass = tabs.getLast();
00376 if (pass.equalsIgnoreCase("passed"))
00377 SetTextColor(hdc, (COLORREF) passColor);
00378 else
00379 SetTextColor(hdc, (COLORREF) failColor);
00380 DrawText(hdc, pass, pass.length(), &crt,
00381 DT_SINGLELINE | DT_TOP | DT_RIGHT);
00382 }
00383 }
00384
00385 } catch(...) {
00386 FillRect(hdc, &rt, bgColor);
00387 crt.top = topMargin+10;
00388 crt.bottom = crt.top + lheight;
00389 str = "Error during paint...";
00390 DrawText(hdc, str, str.length(), &crt,
00391 DT_SINGLELINE | DT_TOP | DT_LEFT | DT_TABSTOP);
00392 }
00393
00394 return true;
00395 }