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.

276 lines
6.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: genforc.cpp
  7. //
  8. // Contents: implementation of CEnumeratorTestForC.
  9. // This class is a subclass of CEnumeratorTest that calls for less
  10. // Implementation work than CEnumeratorTest but is less flexible.
  11. //
  12. // Classes:
  13. //
  14. // Functions:
  15. //
  16. // History: dd-mmm-yy Author Comment
  17. // 24-May-94 kennethm author
  18. //
  19. //--------------------------------------------------------------------------
  20. #include "headers.hxx"
  21. #pragma hdrstop
  22. //+-------------------------------------------------------------------------
  23. //
  24. // Member: CEnumeratorTestForC::CEnumeratorTestForC
  25. //
  26. // Synopsis: default constructor
  27. //
  28. // Arguments:
  29. //
  30. // Returns:
  31. //
  32. // History: dd-mmm-yy Author Comment
  33. // 24-May-94 kennethm author
  34. //
  35. // Notes:
  36. //
  37. //--------------------------------------------------------------------------
  38. CEnumeratorTestForC::CEnumeratorTestForC()
  39. {
  40. m_fnVerify = NULL;
  41. m_fnVerifyAll = NULL;
  42. m_fnCleanup = NULL;
  43. }
  44. //+-------------------------------------------------------------------------
  45. //
  46. // Method: CEnumeratorTestForC::Verify
  47. //
  48. // Synopsis: Verify one element.
  49. //
  50. // Arguments: None
  51. //
  52. // Returns: BOOL
  53. //
  54. // Algorithm: call the user provided function or defer to the super-class
  55. //
  56. // History: dd-mmm-yy Author Comment
  57. // 24-May-94 kennethm author
  58. //
  59. // Notes:
  60. //
  61. //--------------------------------------------------------------------------
  62. BOOL CEnumeratorTestForC::Verify(void *pv)
  63. {
  64. if (m_fnVerify)
  65. {
  66. return(m_fnVerify(pv ));
  67. }
  68. else
  69. {
  70. return(CEnumeratorTest::Verify(pv));
  71. }
  72. }
  73. //+-------------------------------------------------------------------------
  74. //
  75. // Method: CEnumeratorTestForC::VerifyAll
  76. //
  77. // Synopsis: Verify entire array of returned results.
  78. //
  79. // Arguments: None
  80. //
  81. // Returns: BOOL
  82. //
  83. // Algorithm: call the user provided function or defer to the super-class
  84. //
  85. // History: dd-mmm-yy Author Comment
  86. // 24-May-94 kennethm author
  87. //
  88. // Notes:
  89. //
  90. //--------------------------------------------------------------------------
  91. BOOL CEnumeratorTestForC::VerifyAll(void *pv, LONG cl)
  92. {
  93. if (m_fnVerifyAll)
  94. {
  95. return(m_fnVerifyAll(pv, cl ));
  96. }
  97. else
  98. {
  99. return(CEnumeratorTest::VerifyAll(pv, cl));
  100. }
  101. }
  102. //+-------------------------------------------------------------------------
  103. //
  104. // Method: CEnumeratorTestForC::CleanUp
  105. //
  106. // Synopsis: Default implementation of cleanup
  107. //
  108. // Arguments: [pv] - pointer to entry enumerated
  109. //
  110. // Algorithm: call the user provided function or do nothing.
  111. //
  112. // History: dd-mmm-yy Author Comment
  113. // 24-May-94 kennethm author
  114. //
  115. //--------------------------------------------------------------------------
  116. void CEnumeratorTestForC::Cleanup(void *pv)
  117. {
  118. if (m_fnCleanup)
  119. {
  120. m_fnCleanup(pv);
  121. }
  122. }
  123. //+-------------------------------------------------------------------------
  124. //
  125. // Member: CEnumeratorTestForC::Create
  126. //
  127. // Synopsis: Static create function.
  128. //
  129. // Effects:
  130. //
  131. // Arguments: [ppEnumtest] -- TestEnumerator object pointer
  132. // [penum] -- Enumerator Interface cast to void*
  133. // [ElementSize] -- Size of elements return from next
  134. // [ElementCount] -- Numer of elements that should be in the enumeration,
  135. // -1 if unknown.
  136. // [verify] -- verifies one element.
  137. // [verifyall] -- verifies an array correctly contains all elements
  138. // [cleanup] -- Frees any additional memory from next call.
  139. // [pPassedDebugLog] -- The debug log object, NULL if none.
  140. //
  141. // Requires:
  142. //
  143. // Returns:
  144. //
  145. // Signals:
  146. //
  147. // Modifies:
  148. //
  149. // Derivation:
  150. //
  151. // Algorithm:
  152. //
  153. // History: dd-mmm-yy Author Comment
  154. // 24-May-94 kennethm author
  155. //
  156. // Notes: all of the functions passed in are optional and may be NULL.
  157. //
  158. //--------------------------------------------------------------------------
  159. HRESULT CEnumeratorTestForC::Create(
  160. CEnumeratorTestForC **ppEnumTest,
  161. void *penum,
  162. size_t ElementSize,
  163. LONG ElementCount,
  164. BOOL (*verify)(void*),
  165. BOOL (*verifyall)(void*,LONG),
  166. void (*cleanup)(void*))
  167. {
  168. HRESULT hresult = S_OK;
  169. CEnumeratorTestForC *pEnumTest;
  170. if ((penum == NULL) || (ppEnumTest == NULL))
  171. {
  172. return(E_INVALIDARG);
  173. }
  174. *ppEnumTest = NULL;
  175. //
  176. // Create the new enumerator object
  177. //
  178. pEnumTest = new CEnumeratorTestForC();
  179. if (pEnumTest == NULL)
  180. {
  181. return(E_OUTOFMEMORY);
  182. }
  183. //
  184. // Initialize the enumerator and reset it.
  185. //
  186. pEnumTest->m_pEnumTest = (IGenEnum*)penum;
  187. pEnumTest->m_ElementSize = ElementSize;
  188. pEnumTest->m_ElementCount = ElementCount;
  189. pEnumTest->m_fnVerify = verify;
  190. pEnumTest->m_fnVerifyAll = verifyall;
  191. pEnumTest->m_fnCleanup = cleanup;
  192. hresult = pEnumTest->m_pEnumTest->Reset();
  193. if (hresult != S_OK)
  194. {
  195. printf("IEnumnX: Reset failed (%lx)\r\n", hresult );
  196. delete pEnumTest;
  197. return(E_FAIL);
  198. }
  199. *ppEnumTest = pEnumTest;
  200. return(hresult);
  201. }
  202. //+-------------------------------------------------------------------------
  203. //
  204. // Function: TestEnumerator
  205. //
  206. // Synopsis: This is the one stop testing for C programs.
  207. //
  208. // Arguments: [pv] - pointer to entry enumerated
  209. //
  210. // Algorithm: If there is nothing special to free this implementation
  211. // can be used.
  212. //
  213. // History: dd-mmm-yy Author Comment
  214. // 24-May-94 kennethm author
  215. //
  216. //--------------------------------------------------------------------------
  217. HRESULT TestEnumerator(
  218. void *penum,
  219. size_t ElementSize,
  220. LONG ElementCount,
  221. BOOL (*verify)(void*),
  222. BOOL (*verifyall)(void*,LONG),
  223. void (*cleanup)(void*))
  224. {
  225. CEnumeratorTestForC *pEnumTest;
  226. HRESULT hresult;
  227. hresult = CEnumeratorTestForC::Create(
  228. &pEnumTest,
  229. penum,
  230. ElementSize,
  231. ElementCount,
  232. verify,
  233. verifyall,
  234. cleanup);
  235. if (SUCCEEDED(hresult))
  236. {
  237. hresult = pEnumTest->TestAll();
  238. delete pEnumTest;
  239. }
  240. return(hresult);
  241. }