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.

294 lines
9.7 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft OLE
  3. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  4. // All rights reserved.
  5. //
  6. // File: chancedf.hxx
  7. //
  8. // Contents: Random docfile generation helper functions
  9. //
  10. // Classes: ChanceNode
  11. // ChanceDF
  12. //
  13. // History: DeanE 11-Mar-96 Created
  14. //--------------------------------------------------------------------------
  15. #ifndef __CHANCEDF_HXX__
  16. #define __CHANCEDF_HXX__
  17. #include <virtdf.hxx>
  18. // forward declarations
  19. class ChanceDF;
  20. typedef ChanceDF *PCHANCEDF;
  21. class ChanceNode;
  22. typedef ChanceNode *PCHANCENODE;
  23. // Standard Chance Docfile size descriptions
  24. //
  25. typedef enum tagDFSIZE
  26. {
  27. DF_TINY,
  28. DF_SMALL,
  29. DF_MEDIUM,
  30. DF_LARGE,
  31. DF_HUGE,
  32. DF_DIF,
  33. DF_ERROR
  34. } DFSIZE;
  35. #define TSZ_DFSIZE_TINY _TEXT("tiny")
  36. #define TSZ_DFSIZE_SMALL _TEXT("small")
  37. #define TSZ_DFSIZE_MEDIUM _TEXT("medium")
  38. #define TSZ_DFSIZE_LARGE _TEXT("large")
  39. #define TSZ_DFSIZE_HUGE _TEXT("huge")
  40. #define TSZ_DFSIZE_DIF _TEXT("dif")
  41. // Creation and Access modes
  42. #define TSZ_DIRREADSHEX _TEXT("dirReadShEx")
  43. #define TSZ_DIRWRITESHEX _TEXT("dirWriteShEx")
  44. #define TSZ_DIRREADSHDENYW _TEXT("dirReadShDenyW")
  45. #define TSZ_DIRREADWRITESHEX _TEXT("dirReadWriteShEx")
  46. #define TSZ_DIRREADWRITESHDENYN _TEXT("dirReadWriteShDenyN")
  47. #define TSZ_XACTREADWRITESHEX _TEXT("xactReadWriteShEx")
  48. #define TSZ_XACTREADWRITESHDENYW _TEXT("xactReadWriteShDenyW")
  49. #define TSZ_XACTREADWRITESHDENYN _TEXT("xactReadWriteShDenyN")
  50. #define TSZ_XACTREADWRITESHDENYR _TEXT("xactReadWriteShDenyR")
  51. #define TSZ_XACTREADSHEX _TEXT("xactReadShEx")
  52. #define TSZ_XACTREADSHDENYW _TEXT("xactReadShDenyW")
  53. #define TSZ_XACTREADSHDENYN _TEXT("xactReadShDenyN")
  54. #define TSZ_XACTREADSHDENYR _TEXT("xactReadShDenyR")
  55. #define TSZ_XACTWRITESHEX _TEXT("xactWriteShEx")
  56. #define TSZ_XACTWRITESHDENYW _TEXT("xactWriteShDenyW")
  57. #define TSZ_XACTWRITESHDENYN _TEXT("xactWriteShDenyN")
  58. #define TSZ_XACTWRITESHDENYR _TEXT("xactWriteShDenyR")
  59. // Creation time defines
  60. #define SISTERNODE 0
  61. #define CHILDNODE 1
  62. // Distributed, two phase running of tests
  63. #define FL_DISTRIB_NONE 0x0000
  64. #define FL_DISTRIB_OPEN 0x0001
  65. #define FL_DISTRIB_CREATE 0x0002
  66. #define SZ_DISTRIB_CREATE "Create"
  67. #define SZ_DISTRIB_OPEN "Open"
  68. #define SZ_DISTRIB_OPENNODELETE "OpenNoDelete"
  69. // Structure to describe a Chance Docfile in a general sense; to specify
  70. // a docfile in node-by-node terms, you need to use a template file and
  71. // describe it with the template ChanceLanguage
  72. //
  73. // BUGBUG: DeanE - template files are NYI
  74. //
  75. typedef struct tagChanceDocFileDescriptor
  76. {
  77. ULONG cDepthMin;
  78. ULONG cDepthMax;
  79. ULONG cStgMin;
  80. ULONG cStgMax;
  81. ULONG cStmMin;
  82. ULONG cStmMax;
  83. ULONG cbStmMin;
  84. ULONG cbStmMax;
  85. ULONG ulSeed;
  86. DWORD dwRootMode;
  87. DWORD dwStgMode;
  88. DWORD dwStmMode;
  89. } CDFD;
  90. //+-------------------------------------------------------------------------
  91. // Class: ChanceNode
  92. //
  93. // Synopsis: Basic building node of random docfile trees.
  94. //
  95. // Methods: AppendChildStorage
  96. // AppendSisterStorage
  97. // ChanceNode
  98. // ~ChanceNode
  99. // GetFirstChildChanceNode()
  100. // GetFirstSisterChanceNode()
  101. // GetParentChanceNode()
  102. // GetChanceNodeStgCount()
  103. // GetChanceNodeStmCount()
  104. // GetChanceNodeStmMinSize()
  105. // GetChanceNodeStmMaxSize()
  106. //
  107. // Data: [_cStorages] - Number of direct child storages
  108. // [_cStreams] - Number of streams to create in this
  109. // storage
  110. // [_cbMinStreams] - Minimum number of bytes in each stream
  111. // [_cbMaxStreams] - Maximum number of bytes in each stream
  112. // [_pcnChild] - First child of this storage
  113. // [_pcnSister] - Next sister of this storage
  114. // [_pcnParent] - Storage that contains this storage
  115. //
  116. // History: 12-Mar-96 DeanE Created
  117. //--------------------------------------------------------------------------
  118. class ChanceNode
  119. {
  120. public:
  121. // Constructor/Destructor
  122. ChanceNode(ULONG cStg, ULONG cStm, ULONG cbStmMin, ULONG cbStmMax);
  123. ~ChanceNode(VOID);
  124. // Class methods
  125. HRESULT AppendChildStorage(ChanceNode *pcnNew);
  126. HRESULT AppendSisterStorage(ChanceNode *pcnNew);
  127. // friend classes
  128. friend VirtualDF;
  129. friend ChanceDF;
  130. // inline functions
  131. inline ChanceNode *GetFirstChildChanceNode() {return _pcnChild;}
  132. inline ChanceNode *GetFirstSisterChanceNode() {return _pcnSister;}
  133. inline ChanceNode *GetParentChanceNode() {return _pcnParent;}
  134. inline ULONG GetChanceNodeStgCount() {return _cStorages;}
  135. inline ULONG GetChanceNodeStmCount() {return _cStreams;}
  136. inline ULONG GetChanceNodeStmMinSize() {return _cbMinStream;}
  137. inline ULONG GetChanceNodeStmMaxSize() {return _cbMaxStream;}
  138. private:
  139. ULONG _cStorages;
  140. ULONG _cStreams;
  141. ULONG _cbMinStream;
  142. ULONG _cbMaxStream;
  143. ChanceNode *_pcnChild;
  144. ChanceNode *_pcnSister;
  145. ChanceNode *_pcnParent;
  146. };
  147. //+-------------------------------------------------------------------------
  148. // Class: ChanceDF
  149. //
  150. // Synopsis: Random docfile tree object. Parses input in various
  151. // formats and builds a random docfile outline. Outline
  152. // consists of nodes of storages (see ChanceNode class).
  153. //
  154. // Root
  155. // |
  156. // v
  157. // First Child --> Sibling --> Sibling
  158. // |
  159. // v
  160. // Next Child --> Sibling
  161. // |
  162. // v
  163. // Last Child
  164. //
  165. // Each sibling points back to the common parent, not the
  166. // older sibling as it's previous pointer. Each node also
  167. // has info about the number and size of streams they
  168. // contain.
  169. //
  170. // Methods: AppendChildNode
  171. // AppendSisterNode
  172. // ChanceDF
  173. // ~ChanceDF
  174. // CreateFromParams
  175. // CreateFromSize, multiple
  176. // CreateFromFile
  177. // Create
  178. // DeleteChanceDocFileTree
  179. // DeleteChanceDocFileSubTree
  180. // GetSeed
  181. // Generate, protected
  182. // GenerateRoot, protected
  183. // GetModes
  184. // GetDocFileNameFromCmdline
  185. // GetChanceDFRoot
  186. // GetRootMode
  187. // GetStgMode
  188. // GetStmMode
  189. // GetDocFileName
  190. // GetDepthOfNode
  191. // GetRandomChanceNode
  192. // Init, multiple public
  193. // ParseRange, protected
  194. //
  195. // Data: [_pdgi] - DataGen object to create tree
  196. // [_pcnRoot] - Root ChanceNode in the tree
  197. // [_pcdfd] - Structure that contains creation parameters
  198. //
  199. // History: 12-Mar-96 DeanE Created
  200. //--------------------------------------------------------------------------
  201. class ChanceDF
  202. {
  203. public:
  204. // Constructor/Destructor
  205. ChanceDF();
  206. ~ChanceDF();
  207. // Class Methods
  208. HRESULT Init(void);
  209. HRESULT Init(CDFD *pcdfd);
  210. HRESULT CreateFromParams(int argc, char **argv, LPTSTR ptName=NULL);
  211. HRESULT CreateFromSize (LPCTSTR tszSize,
  212. ULONG ulSeed,
  213. DWORD dwRootMode,
  214. DWORD dwStgMode,
  215. DWORD dwStmMode,
  216. LPTSTR ptszDocName);
  217. HRESULT CreateFromSize (DFSIZE dfs,
  218. ULONG ulSeed,
  219. DWORD dwRootMode,
  220. DWORD dwStgMode,
  221. DWORD dwStmMode,
  222. LPTSTR ptszDocName);
  223. HRESULT CreateFromFile (LPCTSTR tszIni, ULONG ulSeed);
  224. HRESULT Create (CDFD *pcdfd, LPTSTR ptszDocName);
  225. ULONG GetSeed(VOID);
  226. HRESULT DeleteChanceDocFileTree(ChanceNode *pcnTrav);
  227. HRESULT GetModes(DWORD *pDFMode, LPCTSTR ptcsModeFlags);
  228. // inline functions
  229. inline ChanceNode *GetChanceDFRoot() {return _pcnRoot;}
  230. inline DWORD GetRootMode() {return _pcdfd->dwRootMode;}
  231. inline DWORD GetStgMode() {return _pcdfd->dwStgMode;}
  232. inline DWORD GetStmMode() {return _pcdfd->dwStmMode;}
  233. inline LPTSTR GetDocFileName() {return _ptszName;}
  234. inline UINT GetOpenCreateDF() {return _uOpenCreateDF;}
  235. // friend class
  236. friend VirtualDF;
  237. protected:
  238. HRESULT Generate(VOID);
  239. HRESULT GenerateRoot(VOID);
  240. HRESULT ParseRange(LPCTSTR tszSwitch, ULONG *pulMin, ULONG *pulMax);
  241. HRESULT GetRandomChanceNode(ULONG cNumOfNodes, ChanceNode **ppcn);
  242. HRESULT AppendChildNode(ChanceNode **ppcnNew, ChanceNode *pcnParent);
  243. HRESULT AppendSisterNode(ChanceNode **ppcnNew, ChanceNode *pcnSister);
  244. HRESULT DeleteChanceDocFileSubTree(ChanceNode **pcnTrav);
  245. private:
  246. UINT _uOpenCreateDF;
  247. DG_INTEGER *_pdgi;
  248. ChanceNode *_pcnRoot;
  249. CDFD *_pcdfd;
  250. LPTSTR _ptszName;
  251. HRESULT GetDocFileNameFromCmdline(LPCTSTR pName);
  252. ULONG GetDepthOfNode(ChanceNode *pcn);
  253. };
  254. #endif