Source code of Windows XP (NT5)
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.

485 lines
12 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. TestIWiaDevMgr.cpp
  5. Abstract:
  6. Author:
  7. Hakki T. Bostanci (hakkib) 06-Apr-2000
  8. Revision History:
  9. --*/
  10. #include "stdafx.h"
  11. #include "WiaStress.h"
  12. #include "StolenIds.h"
  13. #include "EventCallback.h"
  14. //////////////////////////////////////////////////////////////////////////
  15. //
  16. //
  17. //
  18. void CWiaStressThread::TestEnumDeviceInfo()
  19. {
  20. LOG_INFO(_T("Testing EnumDeviceInfo()"));
  21. // test valid cases
  22. CComPtr<IEnumWIA_DEV_INFO> pEnumWIA_DEV_INFO;
  23. if (LOG_HR(m_pWiaDevMgr->EnumDeviceInfo(0, &pEnumWIA_DEV_INFO), == S_OK))
  24. {
  25. TestEnum(pEnumWIA_DEV_INFO, _T("EnumDeviceInfo"));
  26. }
  27. // test invalid cases
  28. if (m_bRunBadParamTests)
  29. {
  30. LOG_HR(m_pWiaDevMgr->EnumDeviceInfo(0, 0), != S_OK);
  31. }
  32. }
  33. //////////////////////////////////////////////////////////////////////////
  34. //
  35. //
  36. //
  37. void CWiaStressThread::TestCreateDevice()
  38. {
  39. CComPtr<IEnumWIA_DEV_INFO> pEnumWIA_DEV_INFO;
  40. CHECK_HR(m_pWiaDevMgr->EnumDeviceInfo(0, &pEnumWIA_DEV_INFO));
  41. ULONG nDevices;
  42. CHECK_HR(pEnumWIA_DEV_INFO->GetCount(&nDevices));
  43. FOR_SELECTED(i, nDevices)
  44. {
  45. CComPtr<CMyWiaPropertyStorage> pProp;
  46. CHECK_HR(pEnumWIA_DEV_INFO->Next(1, (IWiaPropertyStorage **) &pProp, 0));
  47. CPropVariant varDeviceID;
  48. CHECK_HR(pProp->ReadSingle(WIA_DIP_DEV_ID, &varDeviceID, VT_BSTR));
  49. LOG_INFO(_T("Testing CreateDevice() DeviceID=%ws"), varDeviceID.bstrVal);
  50. // test with valid parameters
  51. CComPtr<IWiaItem> pWiaRootItem;
  52. LOG_HR(m_pWiaDevMgr->CreateDevice(varDeviceID.bstrVal, &pWiaRootItem), == S_OK);
  53. // test with invalid parameters
  54. if (m_bRunBadParamTests)
  55. {
  56. LOG_HR(m_pWiaDevMgr->CreateDevice(varDeviceID.bstrVal, 0), != S_OK);
  57. }
  58. }
  59. // test with invalid parameters
  60. if (m_bRunBadParamTests)
  61. {
  62. CComPtr<IWiaItem> pWiaRootItem;
  63. LOG_HR(m_pWiaDevMgr->CreateDevice(0, &pWiaRootItem), != S_OK);
  64. LOG_HR(m_pWiaDevMgr->CreateDevice(0, 0), != S_OK);
  65. }
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. //
  69. //
  70. //
  71. void CWiaStressThread::TestSelectDeviceDlg()
  72. {
  73. static FLAG_AND_NAME<LONG> AllDeviceTypes[] =
  74. {
  75. MAKE_FLAG_AND_NAME(StiDeviceTypeDefault),
  76. MAKE_FLAG_AND_NAME(StiDeviceTypeScanner),
  77. MAKE_FLAG_AND_NAME(StiDeviceTypeDigitalCamera),
  78. MAKE_FLAG_AND_NAME(StiDeviceTypeStreamingVideo)
  79. };
  80. static FLAG_AND_NAME<LONG> AllFlags[] =
  81. {
  82. MAKE_FLAG_AND_NAME(0),
  83. MAKE_FLAG_AND_NAME(WIA_SELECT_DEVICE_NODEFAULT)
  84. };
  85. static FLAG_AND_NAME<LONG> AllButtonIds[] =
  86. {
  87. MAKE_FLAG_AND_NAME(IDOK),
  88. MAKE_FLAG_AND_NAME(IDCANCEL)
  89. };
  90. static FLAG_AND_NAME<LONG> AllAPIs[] =
  91. {
  92. { 0, _T("SelectDeviceDlg") },
  93. { 1, _T("SelectDeviceDlgID") },
  94. };
  95. FOR_SELECTED(lDeviceType, COUNTOF(AllDeviceTypes))
  96. {
  97. FOR_SELECTED(lFlags, COUNTOF(AllFlags))
  98. {
  99. FOR_SELECTED(nButtonId, COUNTOF(AllButtonIds))
  100. {
  101. FOR_SELECTED(nAPI, COUNTOF(AllAPIs))
  102. {
  103. LOG_INFO(
  104. _T("Testing %s(), lDeviceType=%s, lFlags=%s, Push %s"),
  105. AllAPIs[nAPI].pszName,
  106. AllDeviceTypes[lDeviceType].pszName,
  107. AllFlags[lFlags].pszName,
  108. AllButtonIds[nButtonId].pszName
  109. );
  110. SubTestSelectDeviceDlg(
  111. AllDeviceTypes[lDeviceType].Value,
  112. AllFlags[lFlags].Value,
  113. AllButtonIds[nButtonId].Value,
  114. AllAPIs[nButtonId].Value
  115. );
  116. }
  117. }
  118. }
  119. }
  120. }
  121. //////////////////////////////////////////////////////////////////////////
  122. //
  123. //
  124. //
  125. void
  126. CWiaStressThread::SubTestSelectDeviceDlg(
  127. LONG lDeviceType,
  128. LONG lFlags,
  129. LONG nButtonId,
  130. BOOL bGetIDOnly
  131. )
  132. {
  133. // read the (localizable) dialog name from the system DLL
  134. static TCHAR szSelectDeviceTitle[256];
  135. static LONG bInitStrings = TRUE;
  136. if (bInitStrings)
  137. {
  138. CLibrary wiadefui_dll(_T("wiadefui.dll"), LOAD_LIBRARY_AS_DATAFILE);
  139. CDialogResource DlgFileProgress(
  140. wiadefui_dll,
  141. MAKEINTRESOURCE(IDD_CHOOSEWIADEVICE)
  142. );
  143. USES_CONVERSION;
  144. lstrcpyn(
  145. szSelectDeviceTitle,
  146. W2T(DlgFileProgress.title),
  147. COUNTOF(szSelectDeviceTitle)
  148. );
  149. InterlockedExchange(&bInitStrings, FALSE);
  150. }
  151. // get the number of devices from the device manager
  152. CComPtr<IEnumWIA_DEV_INFO> pEnumWIA_DEV_INFO;
  153. CHECK_HR(m_pWiaDevMgr->EnumDeviceInfo(0, &pEnumWIA_DEV_INFO));
  154. ULONG nDevices = 0;
  155. CPropVariant varFirstDeviceID;
  156. if (lDeviceType == StiDeviceTypeDefault)
  157. {
  158. CHECK_HR(pEnumWIA_DEV_INFO->GetCount(&nDevices));
  159. if (nDevices > 0)
  160. {
  161. CComPtr<CMyWiaPropertyStorage> pProp;
  162. CHECK_HR(pEnumWIA_DEV_INFO->Next(1, (IWiaPropertyStorage **) &pProp, 0));
  163. CHECK_HR(pProp->ReadSingle(WIA_DIP_DEV_ID, &varFirstDeviceID, VT_BSTR));
  164. }
  165. }
  166. else
  167. {
  168. while (1)
  169. {
  170. CComPtr<CMyWiaPropertyStorage> pProp;
  171. HRESULT hr = pEnumWIA_DEV_INFO->Next(1, (IWiaPropertyStorage **) &pProp, 0);
  172. if (hr != S_OK)
  173. {
  174. break;
  175. }
  176. CPropVariant varDeviceType;
  177. CHECK_HR(pProp->ReadSingle(WIA_DIP_DEV_TYPE, &varDeviceType, VT_I4));
  178. if (GET_STIDEVICE_TYPE(varDeviceType.lVal) == lDeviceType)
  179. {
  180. ++nDevices;
  181. CHECK_HR(pProp->ReadSingle(WIA_DIP_DEV_ID, &varFirstDeviceID, VT_BSTR));
  182. }
  183. }
  184. }
  185. // we expect to see the dialog if there are more than one devices or
  186. // WIA_SELECT_DEVICE_NODEFAULT switch is set
  187. int nExpectedNumWindows =
  188. nDevices > 1 ||
  189. ((nDevices == 1) && (lFlags & WIA_SELECT_DEVICE_NODEFAULT)) ? 1 : 0;
  190. // start the thread that'll push the button for us
  191. CPushDlgButton PushDlgButton(
  192. GetCurrentThreadId(),
  193. szSelectDeviceTitle,
  194. nButtonId
  195. );
  196. // open the select device dialog
  197. CComBSTR bstrDeviceID;
  198. CComPtr<IWiaItem> pWiaItem;
  199. HRESULT hrAPI;
  200. if (bGetIDOnly)
  201. {
  202. hrAPI = m_pWiaDevMgr->SelectDeviceDlgID(
  203. 0,
  204. lDeviceType,
  205. lFlags,
  206. &bstrDeviceID
  207. );
  208. }
  209. else
  210. {
  211. hrAPI = m_pWiaDevMgr->SelectDeviceDlg(
  212. 0,
  213. lDeviceType,
  214. lFlags,
  215. &bstrDeviceID,
  216. &pWiaItem
  217. );
  218. }
  219. if (hrAPI == S_OK)
  220. {
  221. // when we press the <OK> button, the UI should select the first item
  222. if (wcssafecmp(bstrDeviceID, varFirstDeviceID.bstrVal) != 0)
  223. {
  224. LOG_ERROR(
  225. _T("bstrDeviceID=%ws, expected %ws"),
  226. bstrDeviceID,
  227. varFirstDeviceID.bstrVal
  228. );
  229. }
  230. if (!bGetIDOnly && pWiaItem == 0)
  231. {
  232. LOG_ERROR(_T("pWiaItem == 0, expected non-NULL when hr == S_OK"));
  233. }
  234. }
  235. else
  236. {
  237. if (bstrDeviceID.Length() != 0)
  238. {
  239. LOG_ERROR(
  240. _T("bstrDeviceID == %ws, expected NULL when hr != S_OK"),
  241. bstrDeviceID
  242. );
  243. }
  244. if (!bGetIDOnly && pWiaItem != 0)
  245. {
  246. LOG_ERROR(
  247. _T("pWiaItem == %p, expected NULL when hr != S_OK"),
  248. (IWiaItem *) pWiaItem
  249. );
  250. }
  251. }
  252. if (PushDlgButton.m_nMatchingWindows < nExpectedNumWindows)
  253. {
  254. LOG_ERROR(_T("Select device dialog did not show up"));
  255. }
  256. if (nDevices == 0)
  257. {
  258. LOG_HR(hrAPI, == WIA_S_NO_DEVICE_AVAILABLE);
  259. }
  260. if (nExpectedNumWindows > 0)
  261. {
  262. if (nButtonId == IDOK)
  263. {
  264. LOG_HR(hrAPI, == S_OK);
  265. }
  266. if (nButtonId == IDCANCEL)
  267. {
  268. LOG_HR(hrAPI, == S_FALSE);
  269. }
  270. // we expect to see only one matching button
  271. if (PushDlgButton.m_nMatchingButtons < 1)
  272. {
  273. LOG_ERROR(_T("No buttons with Id=%d"), (PCTSTR) ButtonIdToStr(nButtonId));
  274. }
  275. // number of listed items should equal the number of devices
  276. if (PushDlgButton.m_nListItems != nDevices)
  277. {
  278. LOG_ERROR(
  279. _T("ListedItems=%d, expected %d (from EnumDeviceInfo)"),
  280. PushDlgButton.m_nListItems,
  281. nDevices
  282. );
  283. }
  284. }
  285. // bad param testing
  286. if (m_bRunBadParamTests)
  287. {
  288. if (bGetIDOnly)
  289. {
  290. LOG_HR(m_pWiaDevMgr->SelectDeviceDlgID(0, lDeviceType, lFlags, 0), != S_OK);
  291. }
  292. else
  293. {
  294. bstrDeviceID.Empty();
  295. LOG_HR(m_pWiaDevMgr->SelectDeviceDlg(0, lDeviceType, lFlags, &bstrDeviceID, 0), != S_OK);
  296. LOG_HR(m_pWiaDevMgr->SelectDeviceDlg(0, lDeviceType, lFlags, 0, 0), != S_OK);
  297. }
  298. }
  299. }
  300. //////////////////////////////////////////////////////////////////////////
  301. //
  302. //
  303. //
  304. void CWiaStressThread::TestGetImageDlg()
  305. {
  306. static FLAG_AND_NAME<LONG> AllDeviceTypes[] =
  307. {
  308. MAKE_FLAG_AND_NAME(StiDeviceTypeDefault),
  309. MAKE_FLAG_AND_NAME(StiDeviceTypeScanner),
  310. MAKE_FLAG_AND_NAME(StiDeviceTypeDigitalCamera),
  311. MAKE_FLAG_AND_NAME(StiDeviceTypeStreamingVideo)
  312. };
  313. static FLAG_AND_NAME<LONG> AllFlags[] =
  314. {
  315. MAKE_FLAG_AND_NAME(0),
  316. MAKE_FLAG_AND_NAME(WIA_SELECT_DEVICE_NODEFAULT)
  317. };
  318. FOR_SELECTED(lDeviceType, COUNTOF(AllDeviceTypes))
  319. {
  320. FOR_SELECTED(lFlags, COUNTOF(AllFlags))
  321. {
  322. #if 0
  323. FOR_SELECTED(nButtonId, COUNTOF(AllButtonIds))
  324. {
  325. FOR_SELECTED(nAPI, COUNTOF(AllAPIs))
  326. {
  327. LOG_INFO(
  328. _T("Testing %s(), lDeviceType=%s, lFlags=%s, Push %s"),
  329. AllAPIs[nAPI].pszName,
  330. AllDeviceTypes[lDeviceType].pszName,
  331. AllFlags[lFlags].pszName,
  332. AllButtonIds[nButtonId].pszName
  333. );
  334. virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetImageDlg(
  335. /* [in] */ HWND hwndParent,
  336. /* [in] */ LONG lDeviceType,
  337. /* [in] */ LONG lFlags,
  338. /* [in] */ LONG lIntent,
  339. /* [in] */ IWiaItem __RPC_FAR *pItemRoot,
  340. /* [in] */ BSTR bstrFilename,
  341. /* [out][in] */ GUID __RPC_FAR *pguidFormat) = 0;
  342. }
  343. }
  344. #endif 0
  345. }
  346. }
  347. }
  348. //////////////////////////////////////////////////////////////////////////
  349. //
  350. //
  351. //
  352. void CWiaStressThread::TestRegisterEventCallbackInterface()
  353. {
  354. LOG_INFO(_T("Testing RegisterEventCallbackInterface()"));
  355. CEventCallback *pEventCallback = new CEventCallback;
  356. CHECK(pEventCallback != 0);
  357. CComQIPtr<IWiaEventCallback> pWiaEventCallback(pEventCallback);
  358. CComPtr<IUnknown> pEventObject;
  359. LOG_HR(m_pWiaDevMgr->RegisterEventCallbackInterface(
  360. WIA_REGISTER_EVENT_CALLBACK,
  361. 0,
  362. &WIA_EVENT_DEVICE_CONNECTED,
  363. pWiaEventCallback,
  364. &pEventObject
  365. ), == S_OK);
  366. CComBSTR bstrDeviceId;
  367. // bugbug:
  368. InstallTestDevice(
  369. m_pWiaDevMgr,
  370. _T("\\\\hakkib2183\\cam\\testcam.inf"),
  371. &bstrDeviceId
  372. );
  373. //bugbug: ****
  374. }