Leaked source code of windows server 2003
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.

318 lines
7.0 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File:
  4. // enum.cpp
  5. //
  6. // Contents:
  7. // Enumerator test methods for the cache unit test
  8. //
  9. // History:
  10. //
  11. // 04-Sep-94 davepl Created
  12. //
  13. //-----------------------------------------------------------------------------
  14. #include "headers.hxx"
  15. #pragma hdrstop
  16. //+----------------------------------------------------------------------------
  17. //
  18. // Member: TestInstance::EnumeratorTest
  19. //
  20. // Synopsis: Performs various tests on the cache enumerator
  21. //
  22. // Arguments: (void)
  23. //
  24. // Returns: HRESULT
  25. //
  26. // Notes: General sequence of events is as follows:
  27. //
  28. // - Add cache nodes for EMF, DIB (and BMP) and MF
  29. // - Try to add BMP node (expecting failure)
  30. // - Create a cache enumerator
  31. // - Run generic enumerator tests on that cache enumerator
  32. // - Reset the enumerator
  33. // - Grab the 4 nodes added above in a single Next()
  34. // - Verify that the correct 4 nodes were returned
  35. // - Reset the enumerator
  36. // - Uncache the MF node
  37. // - Grab the 3 remaining nodes
  38. // - Verify that the correct 3 nodes were returned
  39. // - Reset the enumerator
  40. // - Skip 1 node
  41. // - Uncache the DIB (and BMP) node
  42. // - Try to uncache the BMP node (expecting failure)
  43. // - Try to skip (expecting failure, as BMP node has disappeared midflight)
  44. // - Uncache the EMF node (cache should now be empty)
  45. // - Reset and Skip (expecting failure to verify the cache is empty)
  46. // - Release the enumerator
  47. //
  48. // History: 23-Aug-94 Davepl Created
  49. //
  50. //-----------------------------------------------------------------------------
  51. HRESULT TestInstance::EnumeratorTest()
  52. {
  53. HRESULT hr;
  54. DWORD dwEMFCon, dwBMPCon, dwDIBCon, dwMFCon;
  55. TraceLog Log(this, "TestInstance::EnumeratorTest", GS_CACHE, VB_MINIMAL);
  56. Log.OnEntry ();
  57. Log.OnExit (" ( %X )\n", &hr);
  58. SetCurrentState(TESTING_ENUMERATOR);
  59. //
  60. // Cache DIB, MF, EMF, and BITMAP nodes
  61. //
  62. hr = AddEMFCacheNode(&dwEMFCon);
  63. if (S_OK == hr)
  64. {
  65. hr = AddDIBCacheNode(&dwDIBCon);
  66. }
  67. if (S_OK == hr)
  68. {
  69. hr = AddMFCacheNode(&dwMFCon);
  70. }
  71. if (S_OK == hr)
  72. {
  73. hr = AddBITMAPCacheNode(&dwBMPCon);
  74. //
  75. // We expect that caching a Bitmap node when a DIB node has
  76. // already been cached should return CACHE_S_SAMECACHE, so
  77. // we transform that into S_OK
  78. //
  79. if (CACHE_S_SAMECACHE == hr)
  80. {
  81. hr = S_OK;
  82. }
  83. }
  84. //
  85. // Get an enumerator on the cache
  86. //
  87. LPENUMSTATDATA pEsd;
  88. if (S_OK == hr)
  89. {
  90. hr = m_pOleCache->EnumCache(&pEsd);
  91. }
  92. //
  93. // Perform generic emnumerator testing
  94. //
  95. if (S_OK == hr)
  96. {
  97. hr = TestEnumerator((void *) pEsd, sizeof(STATDATA), 4, NULL, NULL,NULL);
  98. }
  99. //
  100. // Reset the enumerator before our specific tests
  101. //
  102. if (S_OK == hr)
  103. {
  104. hr = pEsd->Reset();
  105. }
  106. ULONG cFetched; // Count of elements enumd
  107. STATDATA rgStat[4]; // Array of STATDATA to enum into
  108. //
  109. // Get an enumeration of the expected 4 nodes, then check to
  110. // ensure that all four match (at a basic level) the four
  111. // we expect to find
  112. //
  113. if (S_OK == hr)
  114. {
  115. hr = pEsd->Next(4, rgStat, &cFetched);
  116. }
  117. STATDATA sdEMF, sdMF, sdBMP, sdDIB;
  118. // These are the STATDATAs we expect to find
  119. sdEMF.formatetc.cfFormat = CF_ENHMETAFILE;
  120. sdEMF.dwConnection = dwEMFCon;
  121. sdMF.formatetc.cfFormat = CF_METAFILEPICT;
  122. sdMF.dwConnection = dwMFCon;
  123. sdDIB.formatetc.cfFormat = CF_BITMAP;
  124. sdDIB.dwConnection = dwBMPCon;
  125. sdBMP.formatetc.cfFormat = CF_DIB;
  126. sdBMP.dwConnection = dwBMPCon;
  127. //
  128. // Verify that each of our STATDATAs came back
  129. // from the enumeration
  130. //
  131. if (S_OK == hr)
  132. {
  133. if (S_FALSE == EltIsInArray(sdDIB, rgStat, 4))
  134. {
  135. hr = E_FAIL;
  136. }
  137. else if (S_FALSE == EltIsInArray(sdBMP, rgStat, 4))
  138. {
  139. hr = E_FAIL;
  140. }
  141. else if (S_FALSE == EltIsInArray(sdEMF, rgStat, 4))
  142. {
  143. hr = E_FAIL;
  144. }
  145. else if (S_FALSE == EltIsInArray(sdMF, rgStat, 4))
  146. {
  147. hr = E_FAIL;
  148. }
  149. }
  150. //
  151. // Reset the enumerator
  152. //
  153. if (S_OK == hr)
  154. {
  155. hr = pEsd->Reset();
  156. }
  157. //
  158. // Remove the EMF node, leaving only MF, DIB and Bitmap
  159. //
  160. if (S_OK == hr)
  161. {
  162. hr = m_pOleCache->Uncache(dwMFCon);
  163. }
  164. //
  165. // Get an enumeration of the expected 3 nodes, then check to
  166. // ensure that the DIB and Bitmap nodes are there
  167. //
  168. if (S_OK == hr)
  169. {
  170. hr = pEsd->Next(3, rgStat, &cFetched);
  171. }
  172. //
  173. // Verify that each of our STATDATAs came back
  174. // from the enumeration.
  175. //
  176. if (S_OK == hr)
  177. {
  178. if (S_FALSE == EltIsInArray(sdDIB, rgStat, 3))
  179. {
  180. hr = E_FAIL;
  181. }
  182. else if (S_FALSE == EltIsInArray(sdBMP, rgStat, 3))
  183. {
  184. hr = E_FAIL;
  185. }
  186. else if (S_FALSE == EltIsInArray(sdEMF, rgStat, 3))
  187. {
  188. hr = E_FAIL;
  189. }
  190. }
  191. //
  192. // Reset and Skip one node. WARNING: We assume that the EMF
  193. // node is the first on to be enum'd. This is NOT valid, but
  194. // is based on knowledge of how the cache is implemented, and
  195. // is our only way of testing this...
  196. //
  197. if (S_OK == hr)
  198. {
  199. hr = pEsd->Reset();
  200. }
  201. if (S_OK == hr)
  202. {
  203. hr = pEsd->Skip(1);
  204. }
  205. //
  206. // What we expect at this point: EMF
  207. // DIB <---
  208. // BMP
  209. //
  210. //
  211. // If we kill the DIB or BMP node, both should disappear, and Next()
  212. // must fail (even though we can't assume order, we know that DIB
  213. // and BMP are never enum'd out of order, such as DIB-EMF-DIB
  214. //
  215. if (S_OK == hr)
  216. {
  217. hr = m_pOleCache->Uncache(dwDIBCon);
  218. }
  219. // Since we have uncached the DIB node, the BITMAP node should have
  220. // been automatically uncached as well. First we ensure that we are
  221. // unable to uncache the BITMAP node...
  222. if (S_OK == hr)
  223. {
  224. hr = m_pOleCache->Uncache(dwBMPCon);
  225. // This _should_ have failed, so adjust the error code
  226. hr = MassageErrorCode(OLE_E_NOCONNECTION, hr);
  227. }
  228. //
  229. // Now try to skip; the next node automatically disappeared,
  230. // so it should fail
  231. //
  232. if (S_OK == hr)
  233. {
  234. hr = pEsd->Skip(1);
  235. // The above _should_ fail
  236. hr = MassageErrorCode(S_FALSE, hr);
  237. }
  238. //
  239. // The EMF node should be the only one remaining, so uncache it
  240. // to ensure that we leave the cache as empty as we found it.
  241. //
  242. if (S_OK == hr)
  243. {
  244. hr = m_pOleCache->Uncache(dwEMFCon);
  245. }
  246. //
  247. // Verify that the cache is empty
  248. //
  249. if (S_OK == hr)
  250. {
  251. hr = pEsd->Reset();
  252. if (hr == S_OK)
  253. {
  254. hr = pEsd->Skip(1);
  255. hr = MassageErrorCode(S_FALSE, hr);
  256. }
  257. }
  258. //
  259. // Release the enumerator
  260. //
  261. pEsd->Release();
  262. return hr;
  263. }