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.

360 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. TestWiaDataTransfer.cpp
  5. Abstract:
  6. Test routines for the WIA IWiaDataTransfer interface
  7. Author:
  8. Hakki T. Bostanci (hakkib) 17-Dec-1999
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "WiaStress.h"
  13. #include "DataCallback.h"
  14. #include "CheckBmp.h"
  15. //////////////////////////////////////////////////////////////////////////
  16. //
  17. // CWiaStressThread::TestGetData
  18. //
  19. // Routine Description:
  20. // tests IWiaDataTransfer::idtGetData and IWiaDataTransfer::idtGetBandedData
  21. //
  22. // Arguments:
  23. //
  24. // Return Value:
  25. //
  26. void CWiaStressThread::TestGetData(CWiaItemData *pItemData)
  27. {
  28. if (!(pItemData->lItemType & (WiaItemTypeFile | WiaItemTypeImage)))
  29. {
  30. return;
  31. }
  32. // get the interface pointers
  33. CComQIPtr<IWiaDataTransfer> pWiaDataTransfer(pItemData->pWiaItem);
  34. CHECK(pWiaDataTransfer != 0);
  35. CComQIPtr<CMyWiaPropertyStorage, &IID_IWiaPropertyStorage> pProp(pItemData->pWiaItem);
  36. CHECK(pProp != 0);
  37. // transfer the data in basic formats
  38. CWiaFormatInfo MemoryBmp(&WiaImgFmt_MEMORYBMP, TYMED_CALLBACK);
  39. CWiaFormatInfo FileBmp(&WiaImgFmt_BMP, TYMED_FILE);
  40. SubTestGetData(MemoryBmp, pProp, pWiaDataTransfer, pItemData->bstrFullName);
  41. SubTestGetData(FileBmp, pProp, pWiaDataTransfer, pItemData->bstrFullName);
  42. if (!m_bBVTMode)
  43. {
  44. // get all available transfer formats
  45. CComPtr<IEnumWIA_FORMAT_INFO> pEnumWIA_FORMAT_INFO;
  46. CHECK_HR(pWiaDataTransfer->idtEnumWIA_FORMAT_INFO(&pEnumWIA_FORMAT_INFO));
  47. ULONG nFormats = -1;
  48. CHECK_HR(pEnumWIA_FORMAT_INFO->GetCount(&nFormats));
  49. FOR_SELECTED(i, nFormats)
  50. {
  51. CWiaFormatInfo WiaFormatInfo;
  52. CHECK_HR(pEnumWIA_FORMAT_INFO->Next(1, &WiaFormatInfo, 0));
  53. if (WiaFormatInfo != MemoryBmp && WiaFormatInfo != FileBmp)
  54. {
  55. SubTestGetData(WiaFormatInfo, pProp, pWiaDataTransfer, pItemData->bstrFullName);
  56. }
  57. }
  58. }
  59. // test invalid cases
  60. // todo:
  61. }
  62. //////////////////////////////////////////////////////////////////////////
  63. //
  64. // CWiaStressThread::SubTestGetData
  65. //
  66. // Routine Description:
  67. //
  68. // Arguments:
  69. //
  70. // Return Value:
  71. //
  72. void
  73. CWiaStressThread::SubTestGetData(
  74. CWiaFormatInfo &WiaFormatInfo,
  75. CMyWiaPropertyStorage *pProp,
  76. IWiaDataTransfer *pWiaDataTransfer,
  77. BSTR bstrFullName
  78. )
  79. {
  80. // we don't want any other thread to mess with the image trasfer properties
  81. s_PropWriteCritSect.Enter();
  82. // set the image transfer properties
  83. CHECK_HR(pProp->WriteVerifySingle(WIA_IPA_FORMAT, WiaFormatInfo.guidFormatID));
  84. CHECK_HR(pProp->WriteVerifySingle(WIA_IPA_TYMED, WiaFormatInfo.lTymed));
  85. // transfer the item
  86. switch (WiaFormatInfo.lTymed)
  87. {
  88. case TYMED_CALLBACK:
  89. {
  90. FOR_SELECTED(bCreateSharedSection, 2)
  91. {
  92. FOR_SELECTED(bDoubleBuffered, 2)
  93. {
  94. LOG_INFO(
  95. _T("Testing idtGetBandedData() on %ws, Format=%s, Tymed=%s, %s created section, %s buffered"),
  96. bstrFullName,
  97. (PCTSTR) GuidToStr(WiaFormatInfo.guidFormatID),
  98. (PCTSTR) TymedToStr((TYMED) WiaFormatInfo.lTymed),
  99. bCreateSharedSection ? _T("client") : _T("WIA"),
  100. bDoubleBuffered ? _T("double") : _T("single")
  101. );
  102. // determine the transfer buffer size
  103. CPropVariant varBufferSize;
  104. HRESULT hr = pProp->ReadSingle(WIA_IPA_MIN_BUFFER_SIZE, &varBufferSize, VT_UI4);
  105. ULONG ulBufferSize = hr == S_OK ? varBufferSize.ulVal : 64*1024;
  106. // create the section
  107. CFileMapping Section(
  108. INVALID_HANDLE_VALUE,
  109. 0,
  110. PAGE_READWRITE,
  111. 0,
  112. (bDoubleBuffered ? 2 * ulBufferSize : ulBufferSize)
  113. );
  114. ULONG ulSection = PtrToUlong((HANDLE)Section);
  115. // initiate the transfer
  116. CWiaDataTransferInfo WiaDataTransferInfo(
  117. bCreateSharedSection ? ulSection : 0,
  118. ulBufferSize,
  119. bDoubleBuffered
  120. );
  121. CComPtr<CDataCallback> pDataCallback(new CDataCallback);
  122. CHECK(pDataCallback != 0);
  123. if (LOG_HR(pWiaDataTransfer->idtGetBandedData(&WiaDataTransferInfo, pDataCallback), == S_OK))
  124. {
  125. // check the results if we understand the format
  126. if (WiaFormatInfo.guidFormatID == WiaImgFmt_MEMORYBMP)
  127. {
  128. CheckBmp(
  129. pDataCallback->m_pBuffer,
  130. pDataCallback->m_lBufferSize,
  131. TRUE
  132. );
  133. }
  134. else if (WiaFormatInfo.guidFormatID == WiaImgFmt_BMP)
  135. {
  136. CheckBmp(
  137. pDataCallback->m_pBuffer,
  138. pDataCallback->m_lBufferSize,
  139. TRUE //FALSE bug 123640
  140. );
  141. }
  142. else if (WiaFormatInfo.guidFormatID == WiaImgFmt_JPEG)
  143. {
  144. // todo: write a jpeg checker
  145. }
  146. else if (WiaFormatInfo.guidFormatID == WiaImgFmt_TIFF)
  147. {
  148. // todo: write a tiff checker
  149. }
  150. }
  151. LOG_CMP(pDataCallback->m_cRef, ==, 1);
  152. }
  153. }
  154. break;
  155. }
  156. case TYMED_FILE:
  157. {
  158. LOG_INFO(
  159. _T("Testing idtGetData() on %ws, Format=%s, Tymed=%s"),
  160. bstrFullName,
  161. (PCTSTR) GuidToStr(WiaFormatInfo.guidFormatID),
  162. (PCTSTR) TymedToStr((TYMED) WiaFormatInfo.lTymed)
  163. );
  164. CStgMedium StgMedium;
  165. StgMedium.tymed = TYMED_FILE;
  166. CComPtr<CDataCallback> pDataCallback(new CDataCallback);
  167. CHECK(pDataCallback != 0);
  168. if (LOG_HR(pWiaDataTransfer->idtGetData(&StgMedium, pDataCallback), == S_OK))
  169. {
  170. USES_CONVERSION;
  171. PCTSTR pszFileName = W2T(StgMedium.lpszFileName);
  172. // check the results if we understand the format
  173. if (WiaFormatInfo.guidFormatID == WiaImgFmt_BMP)
  174. {
  175. CheckBmp(pszFileName);
  176. }
  177. else if (WiaFormatInfo.guidFormatID == WiaImgFmt_JPEG)
  178. {
  179. // todo: write a jpeg checker
  180. }
  181. else if (WiaFormatInfo.guidFormatID == WiaImgFmt_TIFF)
  182. {
  183. // todo: write a tiff checker
  184. }
  185. DeleteFile(pszFileName);
  186. }
  187. LOG_CMP(pDataCallback->m_cRef, ==, 1);
  188. break;
  189. }
  190. default:
  191. OutputDebugStringF(_T("Unhandled tymed %s"), (PCTSTR) TymedToStr((TYMED) WiaFormatInfo.lTymed));
  192. ASSERT(FALSE);
  193. break;
  194. }
  195. s_PropWriteCritSect.Leave();
  196. }
  197. //////////////////////////////////////////////////////////////////////////
  198. //
  199. //
  200. //
  201. void CWiaStressThread::TestQueryData(CWiaItemData *pItemData)
  202. {
  203. if (!(pItemData->lItemType & (WiaItemTypeImage | WiaItemTypeFile)))
  204. {
  205. return;
  206. }
  207. LOG_INFO(_T("Testing idtQueryData() on %ws"), pItemData->bstrFullName);
  208. CComQIPtr<IWiaDataTransfer> pWiaDataTransfer(pItemData->pWiaItem);
  209. CHECK(pWiaDataTransfer != 0);
  210. // these two should be supported by all devices
  211. LOG_HR(pWiaDataTransfer->idtQueryGetData(&CWiaFormatInfo(&WiaImgFmt_MEMORYBMP, TYMED_CALLBACK)), == S_OK);
  212. LOG_HR(pWiaDataTransfer->idtQueryGetData(&CWiaFormatInfo(&WiaImgFmt_BMP, TYMED_FILE)), == S_OK);
  213. // ask the device for the formats it supports and verify each format
  214. CComPtr<IEnumWIA_FORMAT_INFO> pEnumWIA_FORMAT_INFO;
  215. CHECK_HR(pWiaDataTransfer->idtEnumWIA_FORMAT_INFO(&pEnumWIA_FORMAT_INFO));
  216. ULONG nFormats;
  217. CHECK_HR(pEnumWIA_FORMAT_INFO->GetCount(&nFormats));
  218. for (int i = 0; i < nFormats; ++i)
  219. {
  220. CWiaFormatInfo WiaFormatInfo;
  221. CHECK_HR(pEnumWIA_FORMAT_INFO->Next(1, &WiaFormatInfo, 0));
  222. LOG_HR(pWiaDataTransfer->idtQueryGetData(&WiaFormatInfo), == S_OK);
  223. }
  224. // test invalid cases
  225. if (m_bRunBadParamTests)
  226. {
  227. LOG_HR(pWiaDataTransfer->idtQueryGetData(&CWiaFormatInfo(&GUID_NULL, TYMED_FILE)), == E_INVALIDARG);
  228. LOG_HR(pWiaDataTransfer->idtQueryGetData(&CWiaFormatInfo(&WiaImgFmt_BMP, 0)), == DV_E_TYMED);
  229. LOG_HR(pWiaDataTransfer->idtQueryGetData(&CWiaFormatInfo(&GUID_NULL, 0)), == DV_E_TYMED);
  230. LOG_HR(pWiaDataTransfer->idtQueryGetData(0), != S_OK);
  231. }
  232. }
  233. //////////////////////////////////////////////////////////////////////////
  234. //
  235. //
  236. //
  237. void CWiaStressThread::TestEnumWIA_FORMAT_INFO(CWiaItemData *pItemData)
  238. {
  239. if (!(pItemData->lItemType & (WiaItemTypeImage | WiaItemTypeFile)))
  240. {
  241. return;
  242. }
  243. LOG_INFO(_T("Testing idtEnumWIA_FORMAT_INFO() on %ws"), pItemData->bstrFullName);
  244. CComQIPtr<IWiaDataTransfer> pWiaDataTransfer(pItemData->pWiaItem);
  245. CHECK(pWiaDataTransfer != 0);
  246. // test valid cases
  247. CComPtr<IEnumWIA_FORMAT_INFO> pEnumWIA_FORMAT_INFO;
  248. if (LOG_HR(pWiaDataTransfer->idtEnumWIA_FORMAT_INFO(&pEnumWIA_FORMAT_INFO), == S_OK))
  249. {
  250. TestEnum(pEnumWIA_FORMAT_INFO, _T("idtEnumWIA_FORMAT_INFO"));
  251. }
  252. // test invalid cases
  253. if (m_bRunBadParamTests)
  254. {
  255. LOG_HR(pWiaDataTransfer->idtEnumWIA_FORMAT_INFO(0), != S_OK);
  256. }
  257. }