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.

695 lines
17 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. TestIWiaItem.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. //////////////////////////////////////////////////////////////////////////
  14. //
  15. //
  16. //
  17. void CWiaStressThread::TestGetItemType(CWiaItemData *pItemData)
  18. {
  19. LOG_INFO(_T("Testing GetItemType() on %ws"), pItemData->bstrFullName);
  20. // good parameter test
  21. LONG lItemType = -1;
  22. if (LOG_HR(pItemData->pWiaItem->GetItemType(&lItemType), == S_OK))
  23. {
  24. if (lItemType & ~WiaItemTypeMask)
  25. {
  26. LOG_ERROR(
  27. _T("GetItemType() returned unrecognized type bits; 0x%x"),
  28. lItemType & ~WiaItemTypeMask
  29. );
  30. }
  31. }
  32. // bad parameter test
  33. if (m_bRunBadParamTests)
  34. {
  35. LOG_HR(pItemData->pWiaItem->GetRootItem(0), != S_OK);
  36. }
  37. }
  38. //////////////////////////////////////////////////////////////////////////
  39. //
  40. //
  41. //
  42. void CWiaStressThread::TestEnumChildItems(CWiaItemData *pItemData)
  43. {
  44. if (!(pItemData->lItemType & WiaItemTypeFolder))
  45. {
  46. return;
  47. }
  48. LOG_INFO(_T("Testing EnumChildItems() on %ws"), pItemData->bstrFullName);
  49. // good parameter test
  50. CComPtr<IEnumWiaItem> pEnumWiaItem;
  51. if (LOG_HR(pItemData->pWiaItem->EnumChildItems(&pEnumWiaItem), == S_OK))
  52. {
  53. TestEnum(pEnumWiaItem, _T("EnumChildItems"));
  54. }
  55. // bad parameter test
  56. if (m_bRunBadParamTests)
  57. {
  58. LOG_HR(pItemData->pWiaItem->EnumChildItems(0), != S_OK);
  59. }
  60. }
  61. //////////////////////////////////////////////////////////////////////////
  62. //
  63. //
  64. //
  65. void CWiaStressThread::TestDeleteItem(CWiaItemData *pItemData)
  66. {
  67. LOG_INFO(_T("Testing DeleteItem() on %ws"), pItemData->bstrFullName);
  68. if (LOG_HR(pItemData->pWiaItem->DeleteItem(0), == S_OK) && !m_bBVTMode)
  69. {
  70. // enumerate the parent item's children to ensure this item is deleted
  71. IWiaItem *pParent = pItemData->ParentsList.back();
  72. CComPtr<IWiaItem> pChild;
  73. LOG_HR(pParent->FindItemByName(0, pItemData->bstrFullName, &pChild), == S_FALSE);
  74. // if there are no children left, WiaItemTypeFolder bit should be clear
  75. #if 0 //bugbug: find out why EnumChildItems fails
  76. CComPtr<IEnumWiaItem> pEnumWiaItem;
  77. CHECK_HR(pParent->EnumChildItems(&pEnumWiaItem));
  78. ULONG nChildren = -1;
  79. CHECK_HR(pEnumWiaItem->GetCount(&nChildren));
  80. if (nChildren == 0)
  81. {
  82. LONG lParentItemType = -1;
  83. CHECK_HR(pItemData->pWiaItem->GetItemType(&lParentItemType));
  84. LOG_CMP(lParentItemType & WiaItemTypeFolder, ==, 0);
  85. }
  86. #endif
  87. }
  88. }
  89. //////////////////////////////////////////////////////////////////////////
  90. //
  91. //
  92. //
  93. void CWiaStressThread::TestCreateChildItem(CWiaItemData *pItemData)
  94. {
  95. SubTestCreateChildItem(pItemData, 1);
  96. }
  97. //////////////////////////////////////////////////////////////////////////
  98. //
  99. //
  100. //
  101. void CWiaStressThread::SubTestCreateChildItem(CWiaItemData *pItemData, int nLevel)
  102. {
  103. // not meaningful to run this on root item
  104. if ((pItemData->lItemType & WiaItemTypeRoot))
  105. {
  106. return;
  107. }
  108. LOG_INFO(_T("Testing CreateChildItem() on %ws"), pItemData->bstrFullName);
  109. // good parameter test
  110. GUID guid;
  111. CHECK_HR(CoCreateGuid(&guid));
  112. CComBSTR bstrChildItemName(MAX_GUID_STRING_LEN);
  113. CHECK(StringFromGUID2(guid, bstrChildItemName, MAX_GUID_STRING_LEN));
  114. CComBSTR bstrFullChildItemName(pItemData->bstrFullName.Length() + 1 + MAX_GUID_STRING_LEN + 1);
  115. swprintf(bstrFullChildItemName, L"%s\\%s", pItemData->bstrFullName, bstrChildItemName);
  116. CComPtr<IWiaItem> pChildWiaItem;
  117. if (
  118. LOG_HR(pItemData->pWiaItem->CreateChildItem(
  119. WiaItemTypeFile,
  120. bstrChildItemName,
  121. bstrFullChildItemName,
  122. &pChildWiaItem
  123. ), == S_OK)
  124. )
  125. {
  126. CParentsList ParentsListForChild = pItemData->ParentsList;
  127. ParentsListForChild.push_back(pItemData->pWiaItem);
  128. CWiaItemData ItemData(pChildWiaItem, ParentsListForChild);
  129. if (!m_bBVTMode)
  130. {
  131. // check that the flags are modified properly
  132. // parent should have the WiaItemTypeFolder bit set
  133. LONG lParentItemType = -1;
  134. CHECK_HR(pItemData->pWiaItem->GetItemType(&lParentItemType));
  135. LOG_CMP(lParentItemType & WiaItemTypeFolder, !=, 0);
  136. // child should have the WiaItemTypeGenerated bit set
  137. LONG lChildItemType = -1;
  138. CHECK_HR(pChildWiaItem->GetItemType(&lChildItemType));
  139. LOG_CMP(lChildItemType & WiaItemTypeGenerated, !=, 0);
  140. // check that minimal properties are there
  141. //bugbug
  142. // fully test the child item
  143. TestGetData(&ItemData);
  144. TestQueryData(&ItemData);
  145. TestEnumWIA_FORMAT_INFO(&ItemData);
  146. TestGetItemType(&ItemData);
  147. TestEnumChildItems(&ItemData);
  148. TestFindItemByName(&ItemData);
  149. TestGetRootItem(&ItemData);
  150. TestPropStorage(&ItemData);
  151. TestPropGetCount(&ItemData);
  152. TestReadPropertyNames(&ItemData);
  153. TestEnumSTATPROPSTG(&ItemData);
  154. // recursively create another level of child items
  155. if (nLevel < 1)
  156. {
  157. SubTestCreateChildItem(pItemData, nLevel);
  158. SubTestCreateChildItem(&ItemData, nLevel + 1);
  159. }
  160. }
  161. // finally "test" DeleteItem
  162. TestDeleteItem(&ItemData);
  163. }
  164. // bad parameter test
  165. if (m_bRunBadParamTests)
  166. {
  167. LOG_HR(pItemData->pWiaItem->CreateChildItem(0, bstrChildItemName, bstrFullChildItemName, 0), != S_OK);
  168. CComPtr<IWiaItem> pChildWiaItem1;
  169. LOG_HR(pItemData->pWiaItem->CreateChildItem(0, bstrChildItemName, 0, &pChildWiaItem1), != S_OK);
  170. CComPtr<IWiaItem> pChildWiaItem2;
  171. LOG_HR(pItemData->pWiaItem->CreateChildItem(0, 0, bstrFullChildItemName, &pChildWiaItem2), != S_OK);
  172. LOG_HR(pItemData->pWiaItem->CreateChildItem(0, 0, 0, 0), != S_OK);
  173. }
  174. }
  175. //////////////////////////////////////////////////////////////////////////
  176. //
  177. //
  178. //
  179. void CWiaStressThread::TestEnumRegisterEventInfo(CWiaItemData *pItemData)
  180. {
  181. // good parameter test
  182. static FLAG_AND_NAME<LPCGUID> AllGuids[] =
  183. {
  184. MAKE_FLAG_AND_NAME(&WIA_EVENT_DEVICE_DISCONNECTED),
  185. MAKE_FLAG_AND_NAME(&WIA_EVENT_DEVICE_CONNECTED),
  186. MAKE_FLAG_AND_NAME(&WIA_EVENT_ITEM_DELETED),
  187. MAKE_FLAG_AND_NAME(&WIA_EVENT_ITEM_CREATED),
  188. //bugbug: MAKE_FLAG_AND_NAME(&WIA_EVENT_VOLUME_REMOVE),
  189. MAKE_FLAG_AND_NAME(&WIA_EVENT_VOLUME_INSERT)
  190. };
  191. FOR_SELECTED(nGuid, COUNTOF(AllGuids))
  192. {
  193. LOG_INFO(_T("Testing EnumRegisterEventInfo(%s) on %ws"), AllGuids[nGuid].pszName, pItemData->bstrFullName);
  194. CComPtr<IEnumWIA_DEV_CAPS> pEnumWIA_DEV_CAPS;
  195. if (LOG_HR(pItemData->pWiaItem->EnumRegisterEventInfo(0, AllGuids[nGuid].Value, &pEnumWIA_DEV_CAPS), == S_OK))
  196. {
  197. TestEnum(pEnumWIA_DEV_CAPS, _T("EnumDeviceInfo"));
  198. }
  199. }
  200. // bad parameter test
  201. if (m_bRunBadParamTests)
  202. {
  203. CComPtr<IEnumWIA_DEV_CAPS> pEnumWIA_DEV_CAPS;
  204. LOG_HR(pItemData->pWiaItem->EnumRegisterEventInfo(0, 0, &pEnumWIA_DEV_CAPS), != S_OK);
  205. LOG_HR(pItemData->pWiaItem->EnumRegisterEventInfo(0, &WIA_EVENT_DEVICE_CONNECTED, 0), != S_OK);
  206. LOG_HR(pItemData->pWiaItem->EnumRegisterEventInfo(0, 0, 0), != S_OK);
  207. }
  208. }
  209. //////////////////////////////////////////////////////////////////////////
  210. //
  211. //
  212. //
  213. void CWiaStressThread::TestFindItemByName(CWiaItemData *pItemData)
  214. {
  215. IWiaItem *pParent = pItemData->ParentsList.back();
  216. if (pParent == 0)
  217. {
  218. return;
  219. }
  220. LOG_INFO(_T("Testing FindItemByName() on %ws"), pItemData->bstrFullName);
  221. // good parameter test; initiate the search starting from each of the parents
  222. for (
  223. CParentsList::iterator itParent = pItemData->ParentsList.begin();
  224. itParent != pItemData->ParentsList.end();
  225. ++itParent
  226. )
  227. {
  228. CComPtr<IWiaItem> pFoundItem;
  229. if (LOG_HR((*itParent)->FindItemByName(0, pItemData->bstrFullName, &pFoundItem), == S_OK))
  230. {
  231. if (*pFoundItem != *pItemData->pWiaItem)
  232. {
  233. LOG_ERROR(_T("FindItemByName did not find correct item"));
  234. }
  235. }
  236. }
  237. // bad parameter tests
  238. if (m_bRunBadParamTests)
  239. {
  240. LOG_HR(pParent->FindItemByName(0, pItemData->bstrFullName, 0), != S_OK);
  241. CComPtr<IWiaItem> pFoundItem;
  242. LOG_HR(pParent->FindItemByName(0, 0, &pFoundItem), != S_OK);
  243. LOG_HR(pParent->FindItemByName(0, 0, 0), != S_OK);
  244. }
  245. }
  246. //////////////////////////////////////////////////////////////////////////
  247. //
  248. //
  249. //
  250. void CWiaStressThread::TestDeviceDlg(CWiaItemData *pItemData)
  251. {
  252. // test valid cases
  253. static FLAG_AND_NAME<LONG> AllIntents[] =
  254. {
  255. MAKE_FLAG_AND_NAME(WIA_INTENT_NONE),
  256. MAKE_FLAG_AND_NAME(WIA_INTENT_IMAGE_TYPE_COLOR),
  257. MAKE_FLAG_AND_NAME(WIA_INTENT_IMAGE_TYPE_GRAYSCALE),
  258. MAKE_FLAG_AND_NAME(WIA_INTENT_IMAGE_TYPE_TEXT)
  259. };
  260. static FLAG_AND_NAME<LONG> AllFlags[] =
  261. {
  262. MAKE_FLAG_AND_NAME(0),
  263. MAKE_FLAG_AND_NAME(WIA_DEVICE_DIALOG_SINGLE_IMAGE)
  264. };
  265. FOR_SELECTED(lIntents, COUNTOF(AllIntents))
  266. {
  267. FOR_SELECTED(lFlags, COUNTOF(AllFlags))
  268. {
  269. LOG_INFO(
  270. _T("Testing DeviceDlg(), lFlags=%s, lIntent=%s"),
  271. AllFlags[lFlags].pszName,
  272. AllIntents[lIntents].pszName
  273. );
  274. SubTestDeviceDlg(
  275. pItemData->pWiaItem,
  276. AllFlags[lFlags].Value,
  277. AllIntents[lIntents].Value
  278. );
  279. }
  280. }
  281. // test invalid cases
  282. // todo:
  283. }
  284. //////////////////////////////////////////////////////////////////////////
  285. //
  286. //
  287. //
  288. void
  289. CWiaStressThread::SubTestDeviceDlg(
  290. IWiaItem *pRootItem,
  291. LONG lFlags,
  292. LONG lIntent
  293. )
  294. {
  295. // this test only verifies that the device dialogs show up, it does not
  296. // target a through test of the dialogs. So we'll just press cancel as
  297. // soon as the dialog pops up.
  298. LONG nButtonId = IDCANCEL;
  299. // read the (localizable) dialog names from the system DLLs
  300. static TCHAR szCameraDlgTitle[256];
  301. static TCHAR szScanDlgTitle[256];
  302. static TCHAR szVideoDlgTitle[256];
  303. static TCHAR szBusy[256];
  304. static LONG bInitStrings = TRUE;
  305. if (bInitStrings)
  306. {
  307. USES_CONVERSION;
  308. CLibrary wiadefui_dll(_T("wiadefui.dll"), LOAD_LIBRARY_AS_DATAFILE);
  309. // read camera dlg title
  310. CResourceString<256> CameraDlgTitle(IDS_CAMERADLG_TITLE, wiadefui_dll);
  311. lstrcpyn(
  312. szCameraDlgTitle,
  313. CameraDlgTitle,
  314. COUNTOF(szCameraDlgTitle)
  315. );
  316. // read scanner dlg title
  317. CResourceString<256> ScanDlgTitle(IDS_DIALOG_TITLE, wiadefui_dll);
  318. lstrcpyn(
  319. szScanDlgTitle,
  320. ScanDlgTitle,
  321. COUNTOF(szScanDlgTitle)
  322. );
  323. // read video dlg title
  324. CDialogResource DlgVideo(wiadefui_dll, MAKEINTRESOURCE(IDD_CAPTURE_DIALOG));
  325. lstrcpyn(
  326. szVideoDlgTitle,
  327. W2T(DlgVideo.title),
  328. COUNTOF(szVideoDlgTitle)
  329. );
  330. // read video busy dlg title
  331. CResourceString<256> VideoBusyDlgTitle(IDS_VIDDLG_BUSY_TITLE, wiadefui_dll);
  332. lstrcpyn(
  333. szBusy,
  334. VideoBusyDlgTitle,
  335. COUNTOF(szBusy)
  336. );
  337. // set the 'we are done' switch
  338. InterlockedExchange(&bInitStrings, FALSE);
  339. }
  340. // select the title to search for according to device type
  341. CPropVariant varDevName;
  342. CHECK_HR(ReadWiaItemProperty(pRootItem, WIA_DIP_DEV_NAME, &varDevName, VT_BSTR));
  343. CPropVariant varDevType;
  344. CHECK_HR(ReadWiaItemProperty(pRootItem, WIA_DIP_DEV_TYPE, &varDevType, VT_I4));
  345. USES_CONVERSION;
  346. TCHAR szDlgTitle[4096]; //bugbug
  347. switch (GET_STIDEVICE_TYPE(varDevType.lVal))
  348. {
  349. case StiDeviceTypeScanner:
  350. _stprintf(szDlgTitle, szScanDlgTitle, W2T(varDevName.bstrVal));
  351. break;
  352. case StiDeviceTypeDigitalCamera:
  353. _stprintf(szDlgTitle, szCameraDlgTitle, varDevName.bstrVal);
  354. break;
  355. case StiDeviceTypeStreamingVideo:
  356. _tcscpy(szDlgTitle, szVideoDlgTitle);
  357. break;
  358. default:
  359. OutputDebugStringF(_T("Unknown device type %d"), GET_STIDEVICE_TYPE(varDevType.lVal));
  360. ASSERT(FALSE);
  361. break;
  362. }
  363. // start the thread that'll push the button for us
  364. CPushDlgButton PushDlgButton(
  365. GetCurrentThreadId(),
  366. szDlgTitle,
  367. nButtonId
  368. );
  369. CPushDlgButton CreateAnotherWatchForVideoBusyDialog( // bugbug
  370. GetCurrentThreadId(),
  371. szBusy,
  372. IDCANCEL
  373. );
  374. // open the select device dialog
  375. CComPtrArray<IWiaItem> ppWiaItem;
  376. HRESULT hrAPI;
  377. hrAPI = pRootItem->DeviceDlg(
  378. 0,
  379. lFlags,
  380. lIntent,
  381. &ppWiaItem.ItemCount(),
  382. &ppWiaItem
  383. );
  384. if (hrAPI == S_OK)
  385. {
  386. // for now, we are always cancelling so it won't ever return S_OK...
  387. }
  388. else
  389. {
  390. if (ppWiaItem != 0)
  391. {
  392. LOG_ERROR(
  393. _T("ppWiaItem=%p, expected NULL when hr != S_OK"),
  394. (IWiaItem **) ppWiaItem
  395. );
  396. }
  397. if (ppWiaItem.ItemCount() != 0)
  398. {
  399. LOG_ERROR(
  400. _T("lItemCount=%d, expected 0 when hr != S_OK"),
  401. ppWiaItem.ItemCount()
  402. );
  403. }
  404. }
  405. if (!PushDlgButton.m_nMatchingWindows)
  406. {
  407. LOG_ERROR(_T("Select device dialog did not show up"));
  408. }
  409. if (CreateAnotherWatchForVideoBusyDialog.m_nMatchingWindows)
  410. {
  411. LOG_ERROR(_T("Preview failed - device busy"));
  412. }
  413. if (nButtonId == IDOK)
  414. {
  415. LOG_HR(hrAPI, == S_OK);
  416. }
  417. if (nButtonId == IDCANCEL)
  418. {
  419. LOG_HR(hrAPI, == S_FALSE);
  420. }
  421. // we expect to see only one matching button
  422. if (PushDlgButton.m_nMatchingButtons < 1)
  423. {
  424. LOG_ERROR(_T("No buttons with Id=%d"), (PCTSTR) ButtonIdToStr(nButtonId));
  425. }
  426. #if 0 //***bugbug
  427. // bad parameter tests
  428. if (m_bRunBadParamTests)
  429. {
  430. ppWiaItem.Release();
  431. LOG_HR(pRootItem->DeviceDlg(0, lFlags, lIntent, 0, &ppWiaItem), != S_OK);
  432. ppWiaItem.Release();
  433. LOG_HR(pRootItem->DeviceDlg(0, lFlags, lIntent, &ppWiaItem.ItemCount(), 0), != S_OK);
  434. ppWiaItem.Release();
  435. LOG_HR(pRootItem->DeviceDlg(0, lFlags, lIntent, 0, 0), != S_OK);
  436. }
  437. #endif //***bugbug
  438. }
  439. //////////////////////////////////////////////////////////////////////////
  440. //
  441. //
  442. //
  443. void CWiaStressThread::TestGetRootItem(CWiaItemData *pItemData)
  444. {
  445. LOG_INFO(_T("Testing GetRootItem() on %ws"), pItemData->bstrFullName);
  446. // good parameter test
  447. CComPtr<IWiaItem> pRootItem;
  448. if (LOG_HR(pItemData->pWiaItem->GetRootItem(&pRootItem), == S_OK))
  449. {
  450. IWiaItem *pExpectedRootItem;
  451. if (pItemData->lItemType & WiaItemTypeRoot)
  452. {
  453. // if the item itself was the root, GetRootItem() should return self
  454. pExpectedRootItem = pItemData->pWiaItem;
  455. }
  456. else
  457. {
  458. // else, get the root item pointer from the cached parents list
  459. pExpectedRootItem = pItemData->ParentsList.front();
  460. }
  461. if (*pRootItem != *pExpectedRootItem)
  462. {
  463. LOG_ERROR(_T("GetRootItem() did not return root item"));
  464. }
  465. }
  466. // bad parameter test
  467. if (m_bRunBadParamTests)
  468. {
  469. LOG_HR(pItemData->pWiaItem->GetRootItem(0), != S_OK);
  470. }
  471. }
  472. //////////////////////////////////////////////////////////////////////////
  473. //
  474. //
  475. //
  476. void CWiaStressThread::TestEnumDeviceCapabilities(CWiaItemData *pItemData)
  477. {
  478. // good parameter test
  479. static FLAG_AND_NAME<LONG> AllFlags[] =
  480. {
  481. MAKE_FLAG_AND_NAME(WIA_DEVICE_COMMANDS),
  482. MAKE_FLAG_AND_NAME(WIA_DEVICE_EVENTS),
  483. MAKE_FLAG_AND_NAME(WIA_DEVICE_COMMANDS | WIA_DEVICE_EVENTS)
  484. };
  485. FOR_SELECTED(lFlags, COUNTOF(AllFlags))
  486. {
  487. CComPtr<IEnumWIA_DEV_CAPS> pEnumWIA_DEV_CAPS;
  488. LOG_INFO(_T("Testing TestEnumDeviceCapabilities(%s) on %ws"), AllFlags[lFlags].pszName, pItemData->bstrFullName);
  489. if (LOG_HR(pItemData->pWiaItem->EnumDeviceCapabilities(AllFlags[lFlags].Value, &pEnumWIA_DEV_CAPS), == S_OK))
  490. {
  491. TestEnum(pEnumWIA_DEV_CAPS, _T("EnumDeviceCapabilities"));
  492. }
  493. }
  494. // bad parameter test
  495. /***bugbugif (m_bRunBadParamTests)
  496. {
  497. CComPtr<IEnumWIA_DEV_CAPS> pEnumWIA_DEV_CAPS;
  498. LOG_HR(pItemData->pWiaItem->EnumDeviceCapabilities(0, &pEnumWIA_DEV_CAPS), != S_OK);
  499. LOG_HR(pItemData->pWiaItem->EnumDeviceCapabilities(WIA_DEVICE_EVENTS, 0), != S_OK);
  500. LOG_HR(pItemData->pWiaItem->EnumDeviceCapabilities(0, 0), != S_OK);
  501. }*/
  502. }