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.

335 lines
6.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: genenum.cpp
  7. //
  8. // Contents: implementation of CGenDataObject
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: dd-mmm-yy Author Comment
  15. // 24-May-94 kennethm author
  16. //
  17. //--------------------------------------------------------------------------
  18. #include "oletest.h"
  19. #include "genenum.h"
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Member: CEnumeratorTest::CEnumeratorTest
  23. //
  24. // Synopsis: Constructor
  25. //
  26. // Effects:
  27. //
  28. // Arguments: [penum] -- Enumerator Interface cast to void*
  29. // [ElementSize] -- Size of elements return from next
  30. // [ElementCount] -- Numer of elements that should be in the enumeration,
  31. // -1 if unknown.
  32. //
  33. // Requires:
  34. //
  35. // Returns:
  36. //
  37. // Signals:
  38. //
  39. // Modifies:
  40. //
  41. // Derivation:
  42. //
  43. // Algorithm:
  44. //
  45. // History: dd-mmm-yy Author Comment
  46. // 24-May-94 kennethm author
  47. //
  48. // Notes:
  49. //
  50. //--------------------------------------------------------------------------
  51. CEnumeratorTest::CEnumeratorTest(
  52. void *penum,
  53. size_t ElementSize,
  54. LONG ElementCount,
  55. HRESULT& rhr)
  56. {
  57. assert(penum);
  58. m_pEnumTest = (IGenEnum*)penum;
  59. m_ElementSize = ElementSize;
  60. m_ElementCount = ElementCount;
  61. rhr = m_pEnumTest->Reset();
  62. if (rhr != S_OK)
  63. {
  64. OutputStr(("IEnumnX: Reset failed (%lx)\r\n", rhr));
  65. }
  66. }
  67. //+-------------------------------------------------------------------------
  68. //
  69. // Function: CEnumeratorTest::GetNext
  70. //
  71. // Synopsis: Internal Next Implementation. Does some basic checks on the
  72. // return values.
  73. //
  74. // Effects:
  75. //
  76. // Arguments: [celt] -- the number of items to fetch
  77. // [pceltFetched] -- the number of items fetched
  78. // [phresult] -- the return from next
  79. //
  80. // Requires:
  81. //
  82. // Returns: True if the basic tests passed, false if they didn't
  83. // The result of the next call itself is passed in param 3.
  84. //
  85. // Signals:
  86. //
  87. // Modifies:
  88. //
  89. // Algorithm: Checks:
  90. // That if s_ok is returned celt and pceltFetched are ==
  91. // If a verify is provided it is called
  92. //
  93. // History: dd-mmm-yy Author Comment
  94. // 24-May-94 kennethm author
  95. //
  96. // Notes:
  97. //
  98. //--------------------------------------------------------------------------
  99. BOOL CEnumeratorTest::GetNext( ULONG celt,
  100. ULONG* pceltFetched,
  101. HRESULT* phresult
  102. )
  103. {
  104. void* prgelt;
  105. ULONG ul;
  106. BOOL fRet = TRUE;
  107. // Allocate memory for the return elements
  108. prgelt = new char[m_ElementSize * celt];
  109. assert(prgelt);
  110. // Call next
  111. *phresult = m_pEnumTest->Next(celt, prgelt, pceltFetched);
  112. // If the return result is S_OK make sure the numbers match
  113. if (*phresult == S_OK)
  114. {
  115. if ((pceltFetched) && (celt != *pceltFetched))
  116. {
  117. OutputStr(("IEnumX::Next return S_OK but celt"
  118. " and pceltFetch mismatch.\r\n"));
  119. return(FALSE);
  120. }
  121. }
  122. // Call verify to make sure the elements are ok.
  123. if ((*phresult == NOERROR) || (*phresult == ResultFromScode(S_FALSE)))
  124. {
  125. // loop through every returned element
  126. for (ul=0; ul < *pceltFetched ; ul++)
  127. {
  128. if (!Verify(prgelt))
  129. {
  130. OutputStr(("Data elment %d returned by IEnumX::Next is bad.\r\n",
  131. ul));
  132. fRet = FALSE;
  133. // we keep looping anyway just to
  134. // free up resources.
  135. }
  136. // If the user supplied a cleanup function there is additional
  137. // memory that needs to be freed
  138. CleanUp(prgelt);
  139. }
  140. }
  141. free (prgelt);
  142. return fRet;
  143. }
  144. //+-------------------------------------------------------------------------
  145. //
  146. // Method: CEnumeratorTest::TestNext
  147. //
  148. // Synopsis: Test the next enumerator methods
  149. //
  150. // Effects:
  151. //
  152. // Arguments: None.
  153. //
  154. // Requires:
  155. //
  156. // Returns: HRESULT
  157. //
  158. // Signals:
  159. //
  160. // Modifies:
  161. //
  162. // Algorithm:
  163. //
  164. // History: dd-mmm-yy Author Comment
  165. // 24-May-94 kennethm author
  166. //
  167. // Notes:
  168. //
  169. //--------------------------------------------------------------------------
  170. HRESULT CEnumeratorTest::TestNext(void)
  171. {
  172. ULONG celtFetched;
  173. LONG InternalCount = 0;
  174. HRESULT hresult;
  175. // First we want to count the element by doing a next on each one.
  176. do {
  177. if (!GetNext(1, &celtFetched, &hresult))
  178. {
  179. return ResultFromScode(E_FAIL);
  180. }
  181. if (hresult == S_OK)
  182. {
  183. InternalCount++;
  184. }
  185. } while ( hresult == S_OK );
  186. // If the user passed in an ammount make sure it matches what we got
  187. if ((m_ElementCount != -1) && (InternalCount != m_ElementCount))
  188. {
  189. OutputStr(("IEnumX: enumerated count and passed count do not match!\r\n"));
  190. return ResultFromScode(E_FAIL);
  191. }
  192. m_pEnumTest->Reset();
  193. // Make sure we fail on ...Next(celt>1, ...,NULL)
  194. /* BUGBUG: clipboard enumerator fails on this test
  195. if (GetNext(2, NULL, &hresult))
  196. {
  197. if ((hresult == S_OK ) || (hresult == S_FALSE))
  198. {
  199. (("IEnumX: celt>1 pceltFetched==NULL returned S_OK\r\n"));
  200. return(E_FAIL);
  201. }
  202. }
  203. else
  204. {
  205. return(E_FAIL);
  206. }
  207. */
  208. return(S_OK);
  209. }
  210. //+-------------------------------------------------------------------------
  211. //
  212. // Method: CEnumeratorTest::TestAll
  213. //
  214. // Synopsis: This function calls all the tests
  215. //
  216. // Effects:
  217. //
  218. // Arguments: None
  219. //
  220. // Requires:
  221. //
  222. // Returns: HRESULT
  223. //
  224. // Signals:
  225. //
  226. // Modifies:
  227. //
  228. // Algorithm:
  229. //
  230. // History: dd-mmm-yy Author Comment
  231. // 24-May-94 kennethm author
  232. //
  233. // Notes:
  234. //
  235. //--------------------------------------------------------------------------
  236. HRESULT CEnumeratorTest::TestAll(void)
  237. {
  238. return(TestNext());
  239. }
  240. //+-------------------------------------------------------------------------
  241. //
  242. // Method: CEnumeratorTest::VerifyAll
  243. //
  244. // Synopsis: Verify entire array of returned results.
  245. //
  246. // Arguments: None
  247. //
  248. // Returns: HRESULT
  249. //
  250. // Algorithm: Just default to saying everything is ok
  251. //
  252. // History: dd-mmm-yy Author Comment
  253. // 24-May-94 ricksa author
  254. //
  255. // Notes:
  256. //
  257. //--------------------------------------------------------------------------
  258. BOOL CEnumeratorTest::VerifyAll(void *pv, LONG cl)
  259. {
  260. return TRUE;
  261. }
  262. //+-------------------------------------------------------------------------
  263. //
  264. // Method: CEnumeratorTest::CleanUp
  265. //
  266. // Synopsis: Default implementation of cleanup
  267. //
  268. // Arguments: [pv] - pointer to entry enumerated
  269. //
  270. // Algorithm: If there is nothing special to free this implementation
  271. // can be used.
  272. //
  273. // History: dd-mmm-yy Author Comment
  274. // 24-May-94 ricksa author
  275. //
  276. //--------------------------------------------------------------------------
  277. void CEnumeratorTest::CleanUp(void *pv)
  278. {
  279. return;
  280. }