2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 /****************************************************************************
16 PURPOSE: system test code for osi package.
18 ****************************************************************************/
21 #include <afs/param.h>
33 /* global state for test program */
39 char main_screenText
[HW_NLINES
][80];
41 /* screen display image size */
44 /* height of a text line */
47 /****************************************************************************
49 FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
51 PURPOSE: calls initialization function, processes message loop
53 ****************************************************************************/
65 if (!InitApplication(hInstance
))
68 if (!InitInstance(hInstance
, nCmdShow
))
71 while (GetMessage(&msg
, NULL
, 0, 0)) {
72 TranslateMessage(&msg
);
73 DispatchMessage(&msg
);
79 /****************************************************************************
81 FUNCTION: InitApplication(HANDLE)
83 PURPOSE: Initializes window data and registers window class
85 ****************************************************************************/
87 BOOL
InitApplication(HANDLE hInstance
)
91 /* create window class */
92 wc
.style
= CS_DBLCLKS
; /* double-click messages */
93 wc
.lpfnWndProc
= (WNDPROC
) MainWndProc
;
96 wc
.hInstance
= hInstance
;
97 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
98 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
99 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
100 wc
.lpszMenuName
= "InputMenu";
101 wc
.lpszClassName
= "InputWClass";
103 return (RegisterClass(&wc
));
107 /****************************************************************************
109 FUNCTION: InitInstance(HANDLE, int)
111 PURPOSE: Saves instance handle and creates main window
113 ****************************************************************************/
121 TEXTMETRIC textmetric
;
128 /* create window itself */
131 "OSI Lock Test Application",
132 WS_OVERLAPPEDWINDOW
| WS_HSCROLL
| WS_VSCROLL
, /* horz & vert scroll bars */
149 GetTextMetrics(hDC
, &textmetric
);
150 lineHeight
= textmetric
.tmExternalLeading
+ textmetric
.tmHeight
;
152 rect
.left
= GetDeviceCaps(hDC
, LOGPIXELSX
) / 4; /* 1/4 inch */
153 rect
.right
= GetDeviceCaps(hDC
, HORZRES
);
154 rect
.top
= GetDeviceCaps(hDC
, LOGPIXELSY
) / 4; /* 1/4 inch */
155 ReleaseDC(hWnd
, hDC
);
156 rect
.bottom
= rect
.top
+ HW_NLINES
* lineHeight
;
159 /* init RPC system */
160 osi_LongToUID(1, &debugID
);
161 code
= osi_InitDebug(&debugID
);
163 if (code
== 0) wsprintf(main_screenText
[0], "Initialized successfully.");
164 else wsprintf(main_screenText
[0], "Failed to init debug system, code %ld", code
);
166 ShowWindow(hWnd
, nCmdShow
);
172 /****************************************************************************
174 FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
176 PURPOSE: Processes messages
178 ****************************************************************************/
180 LONG APIENTRY
MainWndProc(
188 HDC hDC
; /* display-context variable */
189 HMENU hMenu
; /* menu */
190 PAINTSTRUCT ps
; /* paint structure */
197 if (LOWORD(wParam
) == IDM_ABOUT
) {
198 lpProcAbout
= (FARPROC
) About
;
207 if (LOWORD(wParam
) == IDM_DEBUGON
) {
208 osi_LockTypeSetDefault("stat");
209 hMenu
= GetMenu(globalWnd
);
210 CheckMenuItem(hMenu
, IDM_DEBUGON
, MF_CHECKED
);
211 CheckMenuItem(hMenu
, IDM_DEBUGOFF
, MF_UNCHECKED
);
213 if (LOWORD(wParam
) == IDM_DEBUGOFF
) {
214 osi_LockTypeSetDefault((char *) 0);
215 hMenu
= GetMenu(globalWnd
);
216 CheckMenuItem(hMenu
, IDM_DEBUGON
, MF_UNCHECKED
);
217 CheckMenuItem(hMenu
, IDM_DEBUGOFF
, MF_CHECKED
);
219 if (LOWORD(wParam
) == IDM_BASICTEST
) {
221 wsprintf(main_screenText
[0], "Starting basic test run...");
222 code
= main_BasicTest(hWnd
);
223 wsprintf(main_screenText
[0], "Basic test returned code %d", code
);
224 InvalidateRect(hWnd
, &screenRect
, TRUE
);
226 else if (LOWORD(wParam
) == IDM_PERFTEST
) {
228 wsprintf(main_screenText
[0], "Starting performance test run...");
229 code
= main_PerfTest(hWnd
);
230 wsprintf(main_screenText
[0], "Performance test returned code %d", code
);
231 InvalidateRect(hWnd
, &screenRect
, TRUE
);
233 else if (LOWORD(wParam
) == IDM_TRYLOCKTEST
) {
235 wsprintf(main_screenText
[0], "Starting TryLock test run...");
236 code
= main_TryLockTest(hWnd
);
237 wsprintf(main_screenText
[0], "TryLock test returned code %d", code
);
238 InvalidateRect(hWnd
, &screenRect
, TRUE
);
241 return (DefWindowProc(hWnd
, message
, wParam
, lParam
));
245 wsprintf(main_screenText
[0], "WM_CHAR: %c, %x, %x",
246 wParam
, LOWORD(lParam
), HIWORD(lParam
));
247 InvalidateRect(hWnd
, &screenRect
, TRUE
);
251 hDC
= BeginPaint (hWnd
, &ps
);
253 if (IntersectRect(&rect
, &screenRect
, &ps
.rcPaint
)) {
254 for(i
=0; i
<HW_NLINES
; i
++) {
255 TextOut(hDC
, screenRect
.left
, screenRect
.top
+ i
*lineHeight
,
256 main_screenText
[i
], strlen(main_screenText
[i
]));
268 return (DefWindowProc(hWnd
, message
, wParam
, lParam
));
274 /****************************************************************************
276 FUNCTION: About(HWND, unsigned, WORD, LONG)
278 PURPOSE: Processes messages for "About" dialog box
282 WM_INITDIALOG - initialize dialog box
283 WM_COMMAND - Input received
285 ****************************************************************************/
298 if (LOWORD(wParam
) == IDOK
) {
299 EndDialog(hDlg
, TRUE
);
305 UNREFERENCED_PARAMETER(lParam
);
308 void main_ClearDisplay(void)
311 for(i
=0; i
<HW_NLINES
; i
++) {
312 /* make the line an empty line */
313 main_screenText
[i
][0] = 0;
317 void main_ForceDisplay(HANDLE hWnd
)
324 hBrush
= GetStockObject(WHITE_BRUSH
);
325 FillRect(hDC
, &screenRect
, hBrush
);
326 DeleteObject(hBrush
);
327 for(i
=0; i
<HW_NLINES
; i
++) {
328 TextOut(hDC
, screenRect
.left
, screenRect
.top
+ i
*lineHeight
,
329 main_screenText
[i
], strlen(main_screenText
[i
]));
331 ReleaseDC(hWnd
, hDC
);