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.

442 lines
12 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1998
  5. //
  6. // File: flattsts.cxx
  7. //
  8. // Contents: miscellaneous tests for flatfile storage
  9. //
  10. // Functions:
  11. //
  12. // History: 22-Jan-1998 BogdanT created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <dfheader.hxx>
  16. #pragma hdrstop
  17. #include "init.hxx"
  18. // for non _OLE_NSS_, funcs are stubbed out below
  19. #ifdef _OLE_NSS_
  20. //----------------------------------------------------------------------------
  21. //
  22. // Test: FLATTEST_100
  23. //
  24. // Synopsis: Check if STGM_CREATE flag is NOT returned by IStorage::Stat
  25. //
  26. // Arguments:[argc]
  27. // [argv]
  28. //
  29. // Returns: HRESULT
  30. //
  31. // History: 22-Jan-1998 BogdanT created
  32. //
  33. // Notes: To run the test, do the following at command prompt:
  34. // stgbase /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:MISCTEST-100
  35. // /dfRootMode:dirReadWriteShEx /createas:flatfile
  36. //
  37. //-----------------------------------------------------------------------------
  38. HRESULT FLATTEST_100(int argc, char *argv[])
  39. {
  40. HRESULT hr = S_OK;
  41. ChanceDF *pTestChanceDF = NULL;
  42. VirtualDF *pTestVirtualDF = NULL;
  43. VirtualCtrNode *pVirtualDFRoot = NULL;
  44. DWORD dwRootMode = 0;
  45. STATSTG statStg;
  46. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("FLATTEST_100"));
  47. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  48. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation FLATTEST_100 started.")) );
  49. DH_TRACE((
  50. DH_LVL_TRACE1,
  51. TEXT("Check if IStorage::Stat does NOT return STGM_CREATE flag")));
  52. // Create our ChanceDF and VirtualDF
  53. hr = CreateTestDocfile (argc,
  54. argv,
  55. &pVirtualDFRoot,
  56. &pTestVirtualDF,
  57. &pTestChanceDF);
  58. // if creating the docfile - bail here
  59. if (NULL != pTestChanceDF && DoingCreate ())
  60. {
  61. UINT ulSeed = pTestChanceDF->GetSeed ();
  62. CleanupTestDocfile (&pVirtualDFRoot,
  63. &pTestVirtualDF,
  64. &pTestChanceDF,
  65. FALSE);
  66. return (HRESULT)ulSeed;
  67. }
  68. if (S_OK == hr)
  69. {
  70. dwRootMode = pTestChanceDF->GetRootMode();
  71. DH_TRACE((
  72. DH_LVL_TRACE1,
  73. TEXT("Run Mode for FLATTEST_100, Access mode: %lx"),
  74. dwRootMode));
  75. }
  76. if (S_OK == hr)
  77. {
  78. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  79. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  80. }
  81. if(statStg.grfMode & STGM_CREATE)
  82. {
  83. hr = E_FAIL;
  84. DH_TRACE((
  85. DH_LVL_ERROR,
  86. TEXT("Stat returned STGM_CREATE"),
  87. hr));
  88. }
  89. // Release root
  90. if (S_OK == hr)
  91. {
  92. hr = pVirtualDFRoot->Close();
  93. }
  94. if (S_OK == hr)
  95. {
  96. DH_TRACE((
  97. DH_LVL_TRACE1,
  98. TEXT("VirtualCtrNode::Close completed successfully.")));
  99. }
  100. else
  101. {
  102. DH_TRACE((
  103. DH_LVL_TRACE1,
  104. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  105. hr));
  106. }
  107. // if everything goes well, log test as passed else failed.
  108. if (S_OK == hr)
  109. {
  110. DH_LOG((LOG_PASS, TEXT("Test variation FLATTEST_100 passed.")) );
  111. }
  112. else
  113. {
  114. DH_LOG((LOG_FAIL,
  115. TEXT("Test variation FLATTEST_100 failed, hr = 0x%lx."),
  116. hr) );
  117. }
  118. // Cleanup
  119. CleanupTestDocfile (&pVirtualDFRoot,
  120. &pTestVirtualDF,
  121. &pTestChanceDF,
  122. S_OK == hr);
  123. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation FLATTEST_100 finished")) );
  124. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  125. return hr;
  126. }
  127. #else
  128. HRESULT FLATTEST_100(int argc, char *argv[]) { return E_NOTIMPL; }
  129. #endif //_OLE_NSS_
  130. // for non _OLE_NSS_, funcs are stubbed out below
  131. #ifdef _OLE_NSS_
  132. //----------------------------------------------------------------------------
  133. //
  134. // Test: FLATTEST_101
  135. //
  136. // Synopsis: Check that a real docfile (created with STGFMT_DOCFILE can't be
  137. // opened as a flatfile with STGFMT_FILE).
  138. //
  139. // Arguments:[argc]
  140. // [argv]
  141. //
  142. // Returns: HRESULT
  143. //
  144. // History: 19/3/98 Narindk created
  145. //
  146. // Notes: To run the test, do the following at command prompt:
  147. // stgbase /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:FLATTEST-101
  148. // /dfRootMode:dirReadWriteShEx /dfname:FLATTEST101
  149. //
  150. // This test tries to open a docfile as a flatfile. In test DFTEST106
  151. // vice versa of this is tested already. It is allowed to open a
  152. // flatfile as a docfile, but not vice versa.
  153. //
  154. //-----------------------------------------------------------------------------
  155. HRESULT FLATTEST_101(int argc, char *argv[])
  156. {
  157. HRESULT hr = S_OK;
  158. HRESULT hr2 = S_OK;
  159. ChanceDF *pTestChanceDF = NULL;
  160. LPTSTR pRootDocFileName = NULL;
  161. DWORD dwRootMode = 0;
  162. LPSTORAGE pIStorageOpen = NULL;
  163. LPOLESTR poszFileName = NULL;
  164. DWORD reserved = 0;
  165. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("FLATTEST_101"));
  166. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  167. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation FLATTEST_101 started.")) );
  168. DH_TRACE((
  169. DH_LVL_TRACE1,
  170. TEXT("Check a docfile (STGFMT_DOCFILE) cant be opened as flatfile")));
  171. if (S_OK == hr)
  172. {
  173. pTestChanceDF = new ChanceDF();
  174. if(NULL == pTestChanceDF)
  175. {
  176. hr = E_OUTOFMEMORY;
  177. }
  178. }
  179. if (S_OK == hr)
  180. {
  181. hr = pTestChanceDF->CreateFromParams(argc, argv);
  182. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  183. }
  184. // GetRootDocFile mode
  185. if (S_OK == hr)
  186. {
  187. dwRootMode = pTestChanceDF->GetRootMode();
  188. DH_TRACE((
  189. DH_LVL_TRACE1,
  190. TEXT("Run Mode for DFTEST_106, Access mode: %lx"),
  191. pTestChanceDF->GetRootMode()));
  192. }
  193. // Get RootDocFile name
  194. if (S_OK == hr)
  195. {
  196. if(NULL != pTestChanceDF->GetDocFileName())
  197. {
  198. pRootDocFileName =
  199. new TCHAR[_tcslen(pTestChanceDF->GetDocFileName())+1];
  200. if (pRootDocFileName == NULL)
  201. {
  202. hr = E_OUTOFMEMORY;
  203. }
  204. else
  205. {
  206. _tcscpy(pRootDocFileName, pTestChanceDF->GetDocFileName());
  207. }
  208. }
  209. else
  210. {
  211. DH_ASSERT(!"No DocFile name passed from cmd line!") ;
  212. }
  213. DH_HRCHECK(hr, TEXT("pTestChanceDF->GetDocFileName()")) ;
  214. }
  215. if(S_OK == hr)
  216. {
  217. // Convert DocFile name to OLECHAR
  218. hr = TStringToOleString(pRootDocFileName,&poszFileName);
  219. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  220. DH_TRACE((
  221. DH_LVL_TRACE1,
  222. TEXT("Root docfile name %s."), poszFileName));
  223. }
  224. if(S_OK == hr)
  225. {
  226. hr = StgCreateStorageEx (
  227. poszFileName,
  228. dwRootMode | STGM_CREATE,
  229. STGFMT_DOCFILE, //force it to be a docfile
  230. 0,
  231. NULL,
  232. NULL,
  233. IID_IStorage,
  234. (void**)&pIStorageOpen);
  235. DH_TRACE((DH_LVL_TRACE1,
  236. TEXT("StgCreateStorageEx (df); mode=%#lx; hr=%#lx"), dwRootMode,hr));
  237. if(NULL != pIStorageOpen)
  238. {
  239. pIStorageOpen->Release();
  240. pIStorageOpen = NULL;
  241. }
  242. }
  243. // Open the above doc file as docfile, should succeed
  244. if(S_OK == hr)
  245. {
  246. hr = StgOpenStorageEx (
  247. poszFileName,
  248. dwRootMode,
  249. STGFMT_DOCFILE, //open as docfile
  250. 0,
  251. NULL,
  252. NULL,
  253. IID_IStorage,
  254. (void**)&pIStorageOpen);
  255. DH_TRACE((
  256. DH_LVL_TRACE1,
  257. TEXT("StgOpenStorageEx on docfile as docfile;mode=%#lx; hr=%#lx"),
  258. dwRootMode, hr));
  259. if(S_OK != hr)
  260. {
  261. DH_TRACE((
  262. DH_LVL_TRACE1,
  263. TEXT("StgOpenStorageEx failed unexp, hr=0x%lx ."),
  264. hr));
  265. }
  266. else
  267. {
  268. DH_TRACE((
  269. DH_LVL_TRACE1,
  270. TEXT("StgOpenStorageEx passed as exp, hr=0x%lx ."),
  271. hr));
  272. }
  273. if(NULL != pIStorageOpen)
  274. {
  275. pIStorageOpen->Release();
  276. pIStorageOpen = NULL;
  277. }
  278. }
  279. // Now open above docfile as a flatfile
  280. if(S_OK == hr)
  281. {
  282. hr = StgOpenStorageEx (
  283. poszFileName,
  284. dwRootMode,
  285. STGFMT_FILE, //force it to be a flatfile
  286. 0,
  287. NULL,
  288. NULL,
  289. IID_IStorage,
  290. (void**)&pIStorageOpen);
  291. DH_TRACE((
  292. DH_LVL_TRACE1,
  293. TEXT("StgOpenStorageEx as flatfile on docfile;mode=%#lx; hr=%#lx"),
  294. dwRootMode, hr));
  295. // BUGBUG: Check what expected error code from this? We are getting
  296. // invalid argument as of present. Have raided bug to come with a
  297. // uniform error for handling of mismatched format rejection -
  298. // e.g a docfile being opened as NSS file returns file already exists
  299. // error and a docfile being opene as flatfile returns invalid arg
  300. // Change this with what the outcome of the bug is
  301. if(S_OK != hr)
  302. {
  303. DH_TRACE((
  304. DH_LVL_TRACE1,
  305. TEXT("StgOpenStorageEx as NFF on DF failed as exp, hr=0x%lx ."),
  306. hr));
  307. hr = S_OK;
  308. }
  309. else
  310. {
  311. DH_TRACE((
  312. DH_LVL_TRACE1,
  313. TEXT("StgOpenStorageEx as NFF on DF passed unexp, hr=0x%lx ."),
  314. hr));
  315. hr = E_FAIL;
  316. }
  317. if(NULL != pIStorageOpen)
  318. {
  319. pIStorageOpen->Release();
  320. pIStorageOpen = NULL;
  321. }
  322. }
  323. // if everything goes well, log test as passed else failed.
  324. if (S_OK == hr)
  325. {
  326. DH_LOG((LOG_PASS, TEXT("Test variation FLATTEST_101 passed.")) );
  327. }
  328. else
  329. {
  330. DH_LOG((LOG_FAIL,
  331. TEXT("Test variation FLATTEST_101 failed, hr = 0x%lx."),
  332. hr) );
  333. }
  334. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation FLATTEST_101 finished")) );
  335. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  336. // Delete temp string
  337. if(NULL != poszFileName)
  338. {
  339. delete poszFileName;
  340. poszFileName = NULL;
  341. }
  342. // Delete the docfile on disk
  343. if((S_OK == hr) && (NULL != pRootDocFileName))
  344. {
  345. if(FALSE == DeleteFile(pRootDocFileName))
  346. {
  347. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  348. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  349. }
  350. }
  351. // Delete Chance docfile tree
  352. if(NULL != pTestChanceDF)
  353. {
  354. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  355. pTestChanceDF->GetChanceDFRoot());
  356. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  357. delete pTestChanceDF;
  358. pTestChanceDF = NULL;
  359. }
  360. // Delete temp string
  361. if(NULL != pRootDocFileName)
  362. {
  363. delete pRootDocFileName;
  364. pRootDocFileName = NULL;
  365. }
  366. return hr;
  367. }
  368. #else
  369. HRESULT FLATTEST_101(int argc, char *argv[]) { return E_NOTIMPL; }
  370. #endif //_OLE_NSS_