Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
8.6 KiB

  1. /* Various tests to check if Wintab is acting as we would expect */
  2. #include <windows.h>
  3. #include "wintab.h"
  4. extern HMGR hMgr;
  5. extern HMODULE hWintab;
  6. extern char szWintab[];
  7. #ifdef WIN32
  8. #define LoadLibraryWorked(h) (h)
  9. #else
  10. #define LoadLibraryWorked(h) (h >= HINSTANCE_ERROR)
  11. #endif
  12. /* -------------------------------------------------------------------------- */
  13. BOOL BtnMarks(HMGR h, UINT c, UINT FAR *n, UINT FAR *t)
  14. {
  15. typedef BOOL (API *BM)(HMGR, UINT, DWORD, DWORD);
  16. typedef BOOL (API *BMX)(HMGR, UINT, UINT FAR *, UINT FAR *);
  17. static BM bm = NULL;
  18. static BMX bmx = NULL;
  19. /* if not got wintab handle... */
  20. if (!hWintab)
  21. /* get wintab handle. */
  22. hWintab = LoadLibrary(szWintab);
  23. /* failsafe. */
  24. if (!LoadLibraryWorked(hWintab))
  25. return FALSE;
  26. /* if not got a proc... */
  27. if (!bmx && !bm) {
  28. /* try for portable version. */
  29. bmx = (BMX)GetProcAddress(hWintab, "WTMgrCsrPressureBtnMarksEx");
  30. /* if no portable version... */
  31. if (!bmx)
  32. /* try for non-portable version. */
  33. bm = (BM)GetProcAddress(hWintab, "WTMgrCsrPressureBtnMarks");
  34. }
  35. /* failsafe. */
  36. if (!bmx && !bm)
  37. return FALSE;
  38. /* if portable version... */
  39. if (bmx) {
  40. /* call it. */
  41. return bmx(h, c, n, t);
  42. }
  43. else {
  44. /* convert arguments and call non-portable version. */
  45. DWORD dwN, dwT;
  46. if (!n)
  47. dwN = 0;
  48. else if (n == WTP_LPDEFAULT)
  49. dwN = WTP_DWDEFAULT;
  50. else
  51. dwN = *(DWORD FAR *)n;
  52. if (!t)
  53. dwT = 0;
  54. else if (t == WTP_LPDEFAULT)
  55. dwT = WTP_DWDEFAULT;
  56. else
  57. dwT = *(DWORD FAR *)t;
  58. return bm(h, c, dwN, dwT);
  59. }
  60. }
  61. /* -------------------------------------------------------------------------- */
  62. void BMSTest(HWND hWnd)
  63. {
  64. typedef BYTE MAP[32];
  65. static MAP logSave, sysSave, logTest, sysTest, logPatt, sysPatt;
  66. int i;
  67. BOOL fResult;
  68. char buf[200];
  69. /* set up funky test patterns. */
  70. for (i = 0; i < sizeof(MAP); i++) {
  71. logPatt[i] = 31;
  72. sysPatt[i] = SBN_LDRAG;
  73. }
  74. /* loop over cursors... */
  75. for (i = 0; WTInfo(WTI_CURSORS + i, CSR_NAME, NULL); i++) {
  76. /* save the current maps. */
  77. WTInfo(WTI_CURSORS + i, CSR_BUTTONMAP, logSave);
  78. WTInfo(WTI_CURSORS + i, CSR_SYSBTNMAP, sysSave);
  79. /* if the function thinks it succeeded... */
  80. if (fResult = WTMgrCsrButtonMap(hMgr, i, logPatt, sysPatt)) {
  81. /* get the resulting maps. */
  82. WTInfo(WTI_CURSORS + i, CSR_BUTTONMAP, logTest);
  83. WTInfo(WTI_CURSORS + i, CSR_SYSBTNMAP, sysTest);
  84. /* put back the originals. */
  85. WTMgrCsrButtonMap(hMgr, i, logSave, sysSave);
  86. /* compare what we sent with what we got. */
  87. fResult = (!memcmp(logTest, logPatt, sizeof(MAP)) &&
  88. !memcmp(sysTest, sysPatt, sizeof(MAP)));
  89. }
  90. /* report the results. */
  91. wsprintf(buf, "WTMgrCsrButtonMap() Test %s for Cursor %d.",
  92. (LPSTR)(fResult ? "Succeeded" : "Failed"), i);
  93. MessageBox(hWnd, buf, "MgrTest", MB_ICONINFORMATION | MB_OK);
  94. }
  95. }
  96. /* -------------------------------------------------------------------------- */
  97. void PMSTest(HWND hWnd)
  98. {
  99. UINT nSave[2], tSave[2], nTest[2], tTest[2], nPatt[2], tPatt[2];
  100. int i;
  101. BOOL fResult;
  102. BOOL fN, fT;
  103. char buf[200];
  104. /* set up funky test patterns. */
  105. nPatt[0] = tPatt[0] = 1;
  106. nPatt[1] = tPatt[1] = 2;
  107. /* loop over cursors... */
  108. for (i = 0; WTInfo(WTI_CURSORS + i, CSR_NAME, NULL); i++) {
  109. /* check which channels to test. */
  110. fN = !!WTInfo(WTI_CURSORS + i, CSR_NPBTNMARKS, NULL);
  111. fT = !!WTInfo(WTI_CURSORS + i, CSR_TPBTNMARKS, NULL);
  112. if (!fN && !fT) {
  113. fResult = !BtnMarks(hMgr, i, NULL, NULL);
  114. fResult &= !BtnMarks(hMgr, i, nPatt, NULL);
  115. fResult &= !BtnMarks(hMgr, i, NULL, tPatt);
  116. fResult &= !BtnMarks(hMgr, i, nPatt, tPatt);
  117. }
  118. else
  119. {
  120. /* save the current maps. */
  121. if (fN)
  122. WTInfo(WTI_CURSORS + i, CSR_NPBTNMARKS, nSave);
  123. if (fT)
  124. WTInfo(WTI_CURSORS + i, CSR_TPBTNMARKS, tSave);
  125. /* if the function thinks it succeeded... */
  126. if (BtnMarks(hMgr, i, (fN ? (LPVOID)nPatt : NULL),
  127. (fT ? (LPVOID)tPatt : NULL))) {
  128. /* get the resulting maps. */
  129. if (fN)
  130. WTInfo(WTI_CURSORS + i, CSR_NPBTNMARKS, nTest);
  131. if (fT)
  132. WTInfo(WTI_CURSORS + i, CSR_TPBTNMARKS, tTest);
  133. /* put back the originals. */
  134. BtnMarks(hMgr, i, (fN ? (LPVOID)nSave : NULL),
  135. (fT ? (LPVOID)tSave : NULL));
  136. /* compare what we sent with what we got. */
  137. fResult = TRUE;
  138. if (fN)
  139. fResult &= !memcmp(nTest, nPatt, sizeof(nTest));
  140. if (fT)
  141. fResult &= !memcmp(tTest, tPatt, sizeof(tTest));
  142. }
  143. else
  144. fResult = FALSE;
  145. }
  146. /* report the results. */
  147. wsprintf(buf, "WTMgrCsrPressureBtnMarks() Test %s for Cursor %d.",
  148. (LPSTR)(fResult ? "Succeeded" : "Failed"), i);
  149. MessageBox(hWnd, buf, "MgrTest", MB_ICONINFORMATION | MB_OK);
  150. }
  151. }
  152. /* -------------------------------------------------------------------------- */
  153. void PRSTest(HWND hWnd)
  154. {
  155. typedef UINT CURVE[256];
  156. static CURVE nSave, tSave, nTest, tTest, nPatt, tPatt;
  157. int nSize, tSize;
  158. int i, j;
  159. BOOL fResult;
  160. BOOL fN, fT;
  161. AXIS p;
  162. char buf[200];
  163. /* loop over devices... */
  164. for (j = 0; WTInfo(WTI_DEVICES + j, DVC_FIRSTCSR, &i); j++) {
  165. int k;
  166. /* set up funky test patterns. */
  167. if (WTInfo(WTI_DEVICES + j, DVC_NPRESSURE, &p)) {
  168. nSize = (int)(p.axMax - p.axMin);
  169. for (k = 0; k < nSize; k++)
  170. nPatt[k] = (k ? (UINT)p.axMax : (UINT)p.axMin);
  171. }
  172. if (WTInfo(WTI_DEVICES + j, DVC_TPRESSURE, &p)) {
  173. tSize = (int)(p.axMax - p.axMin);
  174. for (k = 0; k < tSize; k++)
  175. tPatt[k] = (k ? (UINT)p.axMax : (UINT)p.axMin);
  176. }
  177. /* loop over cursors... */
  178. for (; WTInfo(WTI_CURSORS + i, CSR_NAME, NULL); i++) {
  179. /* check which channels to test. */
  180. fN = !!WTInfo(WTI_CURSORS + i, CSR_NPRESPONSE, NULL);
  181. fT = !!WTInfo(WTI_CURSORS + i, CSR_TPRESPONSE, NULL);
  182. if (!fN && !fT) {
  183. fResult = !WTMgrCsrPressureResponse(hMgr, i, NULL, NULL);
  184. fResult &= !WTMgrCsrPressureResponse(hMgr, i, nPatt, NULL);
  185. fResult &= !WTMgrCsrPressureResponse(hMgr, i, NULL, tPatt);
  186. fResult &= !WTMgrCsrPressureResponse(hMgr, i, nPatt, tPatt);
  187. }
  188. else
  189. {
  190. /* save the current maps. */
  191. if (fN)
  192. WTInfo(WTI_CURSORS + i, CSR_NPRESPONSE, nSave);
  193. if (fT)
  194. WTInfo(WTI_CURSORS + i, CSR_TPRESPONSE, tSave);
  195. /* if the function thinks it succeeded... */
  196. if (WTMgrCsrPressureResponse(hMgr, i,
  197. (fN ? (LPVOID)nPatt : NULL),
  198. (fT ? (LPVOID)tPatt : NULL))) {
  199. /* get the resulting maps. */
  200. if (fN)
  201. WTInfo(WTI_CURSORS + i, CSR_NPRESPONSE, &nTest);
  202. if (fT)
  203. WTInfo(WTI_CURSORS + i, CSR_TPRESPONSE, &tTest);
  204. /* put back the originals. */
  205. WTMgrCsrPressureResponse(hMgr, i,
  206. (fN ? (LPVOID)nSave : NULL),
  207. (fT ? (LPVOID)tSave : NULL));
  208. /* compare what we sent with what we got. */
  209. fResult = TRUE;
  210. if (fN)
  211. fResult &= !memcmp(&nTest, &nPatt, sizeof(nTest));
  212. if (fT)
  213. fResult &= !memcmp(&tTest, &tPatt, sizeof(nTest));
  214. }
  215. else
  216. fResult = FALSE;
  217. }
  218. /* report the results. */
  219. wsprintf(buf, "WTMgrCsrPressureResponse() Test %s for Cursor %d.",
  220. (LPSTR)(fResult ? "Succeeded" : "Failed"), i);
  221. MessageBox(hWnd, buf, "MgrTest", MB_ICONINFORMATION | MB_OK);
  222. }
  223. }
  224. }
  225. /* -------------------------------------------------------------------------- */
  226. void HMGRTest(HWND hWnd)
  227. {
  228. BOOL success = 1;
  229. HMGR old_hMgr = hMgr;
  230. HMGR new_hMgr;
  231. new_hMgr = WTMgrOpen(hWnd, WT_DEFBASE);
  232. if( !new_hMgr ) {
  233. MessageBox(hWnd, "WTMgrOpen failed.", "MgrTest", MB_ICONHAND | MB_OK);
  234. success = 0;
  235. } else {
  236. HCTX old_hCtx = WTMgrDefContext(old_hMgr, 0);
  237. HCTX new_hCtx = WTMgrDefContext(new_hMgr, 0);
  238. LOGCONTEXT ctx;
  239. if( !old_hCtx || !new_hCtx ) {
  240. MessageBox(hWnd, "WTMgrDefContext failed.", "MgrTest", MB_ICONHAND | MB_OK);
  241. success = 0;
  242. }
  243. if( !WTGet(old_hCtx, &ctx) || !WTGet(old_hCtx, &ctx) ) {
  244. MessageBox(hWnd, "WTGet failed before WTMgrClose called.", "MgrTest", MB_ICONHAND | MB_OK);
  245. success = 0;
  246. }
  247. if( !WTMgrClose(old_hMgr) ) {
  248. MessageBox(hWnd, "WTMgrClose failed.", "MgrTest", MB_ICONHAND | MB_OK);
  249. success = 0;
  250. }
  251. if( WTGet(old_hCtx, &ctx) ) {
  252. MessageBox(hWnd, "Error! WTGet returned success on context handle from a closed manager.", "MgrTest", MB_ICONHAND | MB_OK);
  253. success = 0;
  254. }
  255. if( !WTGet(new_hCtx, &ctx) ) {
  256. MessageBox(hWnd, "WTGet failed for new_hCtx after WTMgrClose(old_hMgr).", "MgrTest", MB_ICONHAND | MB_OK);
  257. success = 0;
  258. }
  259. hMgr = new_hMgr;
  260. }
  261. if( success )
  262. MessageBox(hWnd, "Test Passed.", "MgrTest", MB_ICONINFORMATION | MB_OK);
  263. }