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.

272 lines
6.5 KiB

  1. /*
  2. April 2000
  3. xiaoyu
  4. define XMLParserTestFactory and XMLParserTestFileStream
  5. */
  6. #ifndef _XMLPARSERTEST_HXX
  7. #define _XMLPARSERTEST_HXX
  8. #pragma once
  9. #include <windows.h>
  10. #include <ole2.h>
  11. #include <xmlparser.h>
  12. #include "_unknown.hxx"
  13. #include "core.hxx"
  14. #include "sxsxmltree.h"
  15. #include "xmlns.h"
  16. HRESULT XMLParserTest(PCWSTR filename);
  17. class XMLParserTestFactory : public _unknown<IXMLNodeFactory, &IID_IXMLNodeFactory>
  18. {
  19. public:
  20. XMLParserTestFactory() : m_Tree(NULL), m_pNamespaceManager(NULL)
  21. {
  22. }
  23. ~XMLParserTestFactory(){
  24. if (m_Tree)
  25. {
  26. FUSION_DELETE_SINGLETON(m_Tree);
  27. m_Tree = NULL;
  28. }
  29. if (m_pNamespaceManager)
  30. {
  31. FUSION_DELETE_SINGLETON(m_pNamespaceManager);
  32. m_pNamespaceManager = NULL;
  33. }
  34. }
  35. HRESULT Initialize();
  36. SXS_XMLTreeNode * GetTreeRoot()
  37. {
  38. return m_Tree->GetRoot();
  39. }
  40. HRESULT STDMETHODCALLTYPE NotifyEvent(
  41. /* [in] */ IXMLNodeSource __RPC_FAR *pSource,
  42. /* [in] */ XML_NODEFACTORY_EVENT iEvt);
  43. HRESULT STDMETHODCALLTYPE BeginChildren(
  44. /* [in] */ IXMLNodeSource __RPC_FAR *pSource,
  45. /* [in] */ XML_NODE_INFO* __RPC_FAR pNodeInfo);
  46. HRESULT STDMETHODCALLTYPE EndChildren(
  47. /* [in] */ IXMLNodeSource __RPC_FAR *pSource,
  48. /* [in] */ BOOL fEmptyNode,
  49. /* [in] */ XML_NODE_INFO* __RPC_FAR pNodeInfo);
  50. HRESULT STDMETHODCALLTYPE Error(
  51. /* [in] */ IXMLNodeSource __RPC_FAR *pSource,
  52. /* [in] */ HRESULT hrErrorCode,
  53. /* [in] */ USHORT cNumRecs,
  54. /* [in] */ XML_NODE_INFO* __RPC_FAR * __RPC_FAR apNodeInfo)
  55. {
  56. UNUSED(pSource);
  57. UNUSED(hrErrorCode);
  58. UNUSED(cNumRecs);
  59. UNUSED(apNodeInfo);
  60. return hrErrorCode;
  61. }
  62. HRESULT STDMETHODCALLTYPE CreateNode(
  63. /* [in] */ IXMLNodeSource __RPC_FAR *pSource,
  64. /* [in] */ PVOID pNodeParent,
  65. /* [in] */ USHORT cNumRecs,
  66. /* [in] */ XML_NODE_INFO* __RPC_FAR * __RPC_FAR apNodeInfo);
  67. SXS_XMLDOMTree* m_Tree;
  68. CXMLNamespaceManager* m_pNamespaceManager;
  69. };
  70. class XMLParserTestFileStream : public _unknown<IStream, &IID_IStream>
  71. {
  72. public:
  73. XMLParserTestFileStream() : hFile(INVALID_HANDLE_VALUE), read(true)
  74. {
  75. }
  76. ~XMLParserTestFileStream()
  77. {
  78. if (hFile != INVALID_HANDLE_VALUE)
  79. {
  80. ::CloseHandle(hFile);
  81. hFile = INVALID_HANDLE_VALUE;
  82. }
  83. }
  84. bool close()
  85. {
  86. if ( hFile != INVALID_HANDLE_VALUE)
  87. {
  88. ::CloseHandle(hFile);
  89. hFile = INVALID_HANDLE_VALUE;
  90. }
  91. return true;
  92. }
  93. bool open(PCWSTR name, bool read = true)
  94. {
  95. if ( ! name ) {
  96. return false;
  97. }
  98. if (read)
  99. {
  100. hFile = ::CreateFileW(
  101. name,
  102. GENERIC_READ,
  103. FILE_SHARE_READ,
  104. NULL,
  105. OPEN_EXISTING,
  106. FILE_ATTRIBUTE_NORMAL,
  107. NULL);
  108. }
  109. else
  110. {
  111. hFile = ::CreateFileW(
  112. name,
  113. GENERIC_WRITE,
  114. FILE_SHARE_READ,
  115. NULL,
  116. CREATE_ALWAYS,
  117. FILE_ATTRIBUTE_NORMAL,
  118. NULL);
  119. }
  120. return (hFile == INVALID_HANDLE_VALUE) ? false : true;
  121. }
  122. virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read(
  123. /* [out] */ void __RPC_FAR *pv,
  124. /* [in] */ ULONG cb,
  125. /* [out] */ ULONG __RPC_FAR *pcbRead)
  126. {
  127. if (!read) return E_FAIL;
  128. if (cb > MAXDWORD) return E_INVALIDARG;
  129. DWORD len;
  130. BOOL rc = ReadFile(
  131. hFile, // handle of file to read
  132. pv, // address of buffer that receives data
  133. cb, // number of bytes to read
  134. &len, // address of number of bytes read
  135. NULL // address of structure for data
  136. );
  137. if (pcbRead)
  138. *pcbRead = len;
  139. return (rc) ? S_OK : E_FAIL;
  140. }
  141. virtual /* [local] */ HRESULT STDMETHODCALLTYPE Write(
  142. /* [size_is][in] */ const void __RPC_FAR *pv,
  143. /* [in] */ ULONG cb,
  144. /* [out] */ ULONG __RPC_FAR *pcbWritten)
  145. {
  146. if (read) return E_FAIL;
  147. if (cb > MAXDWORD) return E_INVALIDARG;
  148. DWORD dwWritten = 0;
  149. BOOL rc = WriteFile(
  150. hFile, // handle of file to write
  151. pv, // address of buffer that contains data
  152. cb, // number of bytes to write
  153. &dwWritten, // address of number of bytes written
  154. NULL // address of structure for overlapped I/O
  155. );
  156. *pcbWritten = dwWritten;
  157. return (rc) ? S_OK : E_FAIL;
  158. }
  159. virtual /* [local] */ HRESULT STDMETHODCALLTYPE Seek(
  160. /* [in] */ LARGE_INTEGER dlibMove,
  161. /* [in] */ DWORD dwOrigin,
  162. /* [out] */ ULARGE_INTEGER __RPC_FAR *plibNewPosition) {
  163. UNUSED(dlibMove);
  164. UNUSED(dwOrigin);
  165. UNUSED(plibNewPosition);
  166. return E_NOTIMPL;
  167. }
  168. virtual HRESULT STDMETHODCALLTYPE SetSize(
  169. /* [in] */ ULARGE_INTEGER libNewSize) {
  170. UNUSED(libNewSize);
  171. return E_NOTIMPL; }
  172. virtual /* [local] */ HRESULT STDMETHODCALLTYPE CopyTo(
  173. /* [unique][in] */ IStream __RPC_FAR *pstm,
  174. /* [in] */ ULARGE_INTEGER cb,
  175. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbRead,
  176. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbWritten) {
  177. UNUSED(pstm);
  178. UNUSED(cb);
  179. UNUSED(pcbRead);
  180. UNUSED(pcbWritten);
  181. return E_NOTIMPL;
  182. }
  183. virtual HRESULT STDMETHODCALLTYPE Commit(
  184. /* [in] */ DWORD grfCommitFlags) {
  185. UNUSED(grfCommitFlags);
  186. return E_NOTIMPL;
  187. }
  188. virtual HRESULT STDMETHODCALLTYPE Revert( void) { return E_NOTIMPL; }
  189. virtual HRESULT STDMETHODCALLTYPE LockRegion(
  190. /* [in] */ ULARGE_INTEGER libOffset,
  191. /* [in] */ ULARGE_INTEGER cb,
  192. /* [in] */ DWORD dwLockType) {
  193. UNUSED(libOffset);
  194. UNUSED(cb);
  195. UNUSED(dwLockType);
  196. return E_NOTIMPL;
  197. }
  198. virtual HRESULT STDMETHODCALLTYPE UnlockRegion(
  199. /* [in] */ ULARGE_INTEGER libOffset,
  200. /* [in] */ ULARGE_INTEGER cb,
  201. /* [in] */ DWORD dwLockType) {
  202. UNUSED(libOffset);
  203. UNUSED(cb);
  204. UNUSED(dwLockType);
  205. return E_NOTIMPL;
  206. }
  207. virtual HRESULT STDMETHODCALLTYPE Stat(
  208. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  209. /* [in] */ DWORD grfStatFlag) {
  210. UNUSED(pstatstg);
  211. UNUSED(grfStatFlag);
  212. return E_NOTIMPL;
  213. }
  214. virtual HRESULT STDMETHODCALLTYPE Clone(
  215. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm) {
  216. UNUSED(ppstm);
  217. return E_NOTIMPL;
  218. }
  219. private:
  220. HANDLE hFile;
  221. bool read;
  222. };
  223. #endif