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.

4474 lines
118 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: dftests.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to DocFile in general.
  9. //
  10. // Functions:
  11. //
  12. // History: 3-June-1996 NarindK Created.
  13. // 27-Mar-97 SCousens conversionified
  14. //
  15. //--------------------------------------------------------------------------
  16. //BUGBUG: BUGNOTE: All not for conversion need a second look. -scousens
  17. #include <dfheader.hxx>
  18. #pragma hdrstop
  19. #include <sys/stat.h>
  20. #include <share.h>
  21. #include <errno.h> //get errors for our runtime calls
  22. #include "init.hxx"
  23. //----------------------------------------------------------------------------
  24. //
  25. // Test: DFTEST_100
  26. //
  27. // Synopsis: Regression test to create a root docfile. Commit the root docfile.
  28. //
  29. // Arguments:[argc]
  30. // [argv]
  31. //
  32. // Returns: HRESULT
  33. //
  34. // History: 3-June-1996 NarindK Created.
  35. //
  36. // Notes: This test runs in direct, transacted, and transacted deny write
  37. // modes
  38. //
  39. // New Test Notes:
  40. // 1. Old File: DFCOMMIT.CXX
  41. // 2. Old name of test : LegitRootNormal
  42. // New Name of test : DFTEST_100
  43. // 3. To run the test, do the following at command prompt.
  44. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-100
  45. // /dfRootMode:dirReadWriteShEx /dfname:DFCOMMIT.DFL
  46. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-100
  47. // /dfRootMode:xactReadWriteShEx /dfname:DFCOMMIT.DFL
  48. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-100
  49. // /dfRootMode:xactReadWriteShDenyW /dfname:DFCOMMIT.DFL
  50. //
  51. // BUGNOTE: Conversion: DFTEST-100 NO
  52. //
  53. //-----------------------------------------------------------------------------
  54. HRESULT DFTEST_100(int argc, char *argv[])
  55. {
  56. HRESULT hr = S_OK;
  57. HRESULT hr2 = S_OK;
  58. ChanceDF *pTestChanceDF = NULL;
  59. VirtualDF *pTestVirtualDF = NULL;
  60. VirtualCtrNode *pVirtualDFRoot = NULL;
  61. LPTSTR pFileName = NULL;
  62. // Not for 2phase. Bail.
  63. if (DoingDistrib ())
  64. {
  65. return S_OK;
  66. }
  67. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_100"));
  68. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  69. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_100 started.")) );
  70. DH_TRACE((DH_LVL_TRACE1,
  71. TEXT("Regression test for Root DocFile creation/commit. ")));
  72. // Create the new ChanceDocFile tree that would consist of chance nodes.
  73. if (S_OK == hr)
  74. {
  75. pTestChanceDF = new ChanceDF();
  76. if(NULL == pTestChanceDF)
  77. {
  78. hr = E_OUTOFMEMORY;
  79. }
  80. }
  81. if (S_OK == hr)
  82. {
  83. hr = pTestChanceDF->CreateFromParams(argc, argv);
  84. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  85. }
  86. if (S_OK == hr)
  87. {
  88. DH_TRACE((
  89. DH_LVL_TRACE1,
  90. TEXT("Run Mode for DFTEST_100, Access mode: %lx"),
  91. pTestChanceDF->GetRootMode()));
  92. }
  93. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  94. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  95. // and VirtualStmNodes.
  96. if (S_OK == hr)
  97. {
  98. pTestVirtualDF = new VirtualDF();
  99. if(NULL == pTestVirtualDF)
  100. {
  101. hr = E_OUTOFMEMORY;
  102. }
  103. }
  104. if (S_OK == hr)
  105. {
  106. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  107. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  108. }
  109. if (S_OK == hr)
  110. {
  111. DH_TRACE((
  112. DH_LVL_TRACE1,
  113. TEXT("DocFile - CreateFromParams - successfully created.")));
  114. }
  115. else
  116. {
  117. DH_TRACE((
  118. DH_LVL_TRACE1,
  119. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  120. hr));
  121. }
  122. // BUGBUG: Use Random commit modes...
  123. if (S_OK == hr)
  124. {
  125. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  126. }
  127. if (S_OK == hr)
  128. {
  129. DH_TRACE((
  130. DH_LVL_TRACE1,
  131. TEXT("VirtualCtrNode::Commit completed successfully.")));
  132. }
  133. else
  134. {
  135. DH_TRACE((
  136. DH_LVL_TRACE1,
  137. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  138. hr));
  139. }
  140. // Call Release on root docfile
  141. if (S_OK == hr)
  142. {
  143. hr = pVirtualDFRoot->Close();
  144. }
  145. if (S_OK == hr)
  146. {
  147. DH_TRACE((
  148. DH_LVL_TRACE1,
  149. TEXT("VirtualCtrNode::Close completed successfully.")));
  150. }
  151. else
  152. {
  153. DH_TRACE((
  154. DH_LVL_TRACE1,
  155. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  156. hr));
  157. }
  158. // if everything goes well, log test as passed else failed.
  159. if (S_OK == hr)
  160. {
  161. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_100 passed.")) );
  162. }
  163. else
  164. {
  165. DH_LOG((
  166. LOG_FAIL,
  167. TEXT("Test variation DFTEST_100 failed, hr = 0x%lx."),
  168. hr) );
  169. }
  170. // Cleanup
  171. // Get the name of file, will be used later to delete the file
  172. if(NULL != pVirtualDFRoot)
  173. {
  174. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  175. if (pFileName != NULL)
  176. {
  177. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  178. }
  179. }
  180. // Delete the docfile on disk
  181. if((S_OK == hr) && (NULL != pFileName))
  182. {
  183. if(FALSE == DeleteFile(pFileName))
  184. {
  185. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  186. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  187. }
  188. }
  189. // Delete Chance docfile tree
  190. if(NULL != pTestChanceDF)
  191. {
  192. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  193. pTestChanceDF->GetChanceDFRoot());
  194. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  195. delete pTestChanceDF;
  196. pTestChanceDF = NULL;
  197. }
  198. // Delete Virtual docfile tree
  199. if(NULL != pTestVirtualDF)
  200. {
  201. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  202. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  203. delete pTestVirtualDF;
  204. pTestVirtualDF = NULL;
  205. }
  206. // Delete temp string
  207. if(NULL != pFileName)
  208. {
  209. delete pFileName;
  210. pFileName = NULL;
  211. }
  212. // Stop logging the test
  213. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_100 finished")) );
  214. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  215. return hr;
  216. }
  217. //----------------------------------------------------------------------------
  218. //
  219. // Test: DFTEST_101
  220. //
  221. // Synopsis: Regression test to create a root docfile, commit the root docfile,
  222. // release the toot docfile and remove the docfile.
  223. //
  224. // Arguments:[argc]
  225. // [argv]
  226. //
  227. // Returns: HRESULT
  228. //
  229. // History: 3-June-1996 NarindK Created.
  230. //
  231. // Notes: This test runs in direct, transacted, and transacted deny write
  232. // modes
  233. //
  234. // New Test Notes:
  235. // 1. Old File: DFREMOVE.CXX
  236. // 2. Old name of test :
  237. // New Name of test : DFTEST_101
  238. // 3. To run the test, do the following at command prompt.
  239. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-101
  240. // /dfRootMode:dirReadWriteShEx /dfname:DFREMOVE.DFL
  241. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-101
  242. // /dfRootMode:xactReadWriteShEx /dfname:DFREMOVE.DFL
  243. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-101
  244. // /dfRootMode:xactReadWriteShDenyW /dfname:DFREMOVE.DFL
  245. //
  246. // BUGNOTE: Conversion: DFTEST-101 NO
  247. //
  248. //-----------------------------------------------------------------------------
  249. HRESULT DFTEST_101(int argc, char *argv[])
  250. {
  251. HRESULT hr = S_OK;
  252. HRESULT hr2 = S_OK;
  253. ChanceDF *pTestChanceDF = NULL;
  254. VirtualDF *pTestVirtualDF = NULL;
  255. VirtualCtrNode *pVirtualDFRoot = NULL;
  256. LPTSTR pFileName = NULL;
  257. // Not for 2phase. Bail.
  258. if (DoingDistrib ())
  259. {
  260. return S_OK;
  261. }
  262. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_101"));
  263. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  264. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_101 started.")) );
  265. DH_TRACE((DH_LVL_TRACE1,
  266. TEXT("Regression for RootDocFile creation/commit/release/removal.")));
  267. // Create the new ChanceDocFile tree that would consist of chance nodes.
  268. if (S_OK == hr)
  269. {
  270. pTestChanceDF = new ChanceDF();
  271. if(NULL == pTestChanceDF)
  272. {
  273. hr = E_OUTOFMEMORY;
  274. }
  275. }
  276. if (S_OK == hr)
  277. {
  278. hr = pTestChanceDF->CreateFromParams(argc, argv);
  279. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  280. }
  281. if (S_OK == hr)
  282. {
  283. DH_TRACE((
  284. DH_LVL_TRACE1,
  285. TEXT("Run Mode for DFTEST_101, Access mode: %lx"),
  286. pTestChanceDF->GetRootMode()));
  287. }
  288. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  289. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  290. // and VirtualStmNodes.
  291. if (S_OK == hr)
  292. {
  293. pTestVirtualDF = new VirtualDF();
  294. if(NULL == pTestVirtualDF)
  295. {
  296. hr = E_OUTOFMEMORY;
  297. }
  298. }
  299. if (S_OK == hr)
  300. {
  301. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  302. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  303. }
  304. if (S_OK == hr)
  305. {
  306. DH_TRACE((
  307. DH_LVL_TRACE1,
  308. TEXT("DocFile - CreateFromParams - successfully created.")));
  309. }
  310. else
  311. {
  312. DH_TRACE((
  313. DH_LVL_TRACE1,
  314. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  315. hr));
  316. }
  317. // Commit the root docfile with STGC_ONLYIFCURRENT mode.
  318. if (S_OK == hr)
  319. {
  320. hr = pVirtualDFRoot->Commit(STGC_ONLYIFCURRENT);
  321. }
  322. if (S_OK == hr)
  323. {
  324. DH_TRACE((
  325. DH_LVL_TRACE1,
  326. TEXT("VirtualCtrNode::Commit completed successfully.")));
  327. }
  328. else
  329. {
  330. DH_TRACE((
  331. DH_LVL_TRACE1,
  332. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  333. hr));
  334. }
  335. // Call Release on root docfile
  336. if (S_OK == hr)
  337. {
  338. hr = pVirtualDFRoot->Close();
  339. }
  340. if (S_OK == hr)
  341. {
  342. DH_TRACE((
  343. DH_LVL_TRACE1,
  344. TEXT("VirtualCtrNode::Close completed successfully.")));
  345. }
  346. else
  347. {
  348. DH_TRACE((
  349. DH_LVL_TRACE1,
  350. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  351. hr));
  352. }
  353. // if everything goes well, log test as passed else failed.
  354. if (S_OK == hr)
  355. {
  356. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_101 passed.")) );
  357. }
  358. else
  359. {
  360. DH_LOG((
  361. LOG_FAIL,
  362. TEXT("Test variation DFTEST_101 failed, hr = 0x%lx."),
  363. hr) );
  364. }
  365. // Cleanup
  366. // Get the name of file, will be used later to delete the file
  367. if(NULL != pVirtualDFRoot)
  368. {
  369. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  370. if (pFileName != NULL)
  371. {
  372. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  373. }
  374. }
  375. // Delete the docfile on disk
  376. if((S_OK == hr) && (NULL != pFileName))
  377. {
  378. if(FALSE == DeleteFile(pFileName))
  379. {
  380. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  381. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  382. }
  383. }
  384. // Delete Chance docfile tree
  385. if(NULL != pTestChanceDF)
  386. {
  387. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  388. pTestChanceDF->GetChanceDFRoot());
  389. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  390. delete pTestChanceDF;
  391. pTestChanceDF = NULL;
  392. }
  393. // Delete Virtual docfile tree
  394. if(NULL != pTestVirtualDF)
  395. {
  396. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  397. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  398. delete pTestVirtualDF;
  399. pTestVirtualDF = NULL;
  400. }
  401. // Delete temp string
  402. if(NULL != pFileName)
  403. {
  404. delete pFileName;
  405. pFileName = NULL;
  406. }
  407. // Stop logging the test
  408. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_101 finished")) );
  409. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  410. return hr;
  411. }
  412. //----------------------------------------------------------------------------
  413. //
  414. // Test: DFTEST_102
  415. //
  416. // Synopsis: Regression test to create a root docfile, commit the root docfile,
  417. // release the root docfile. Verify using StgIsStorageFile API.
  418. //
  419. // Arguments:[argc]
  420. // [argv]
  421. //
  422. // Returns: HRESULT
  423. //
  424. // History: 3-June-1996 NarindK Created.
  425. //
  426. // Notes: This test runs in transacted mode.
  427. //
  428. // New Test Notes:
  429. // 1. Old File: DFROOT.CXX
  430. // 2. Old name of test : TransactedCommitTest
  431. // New Name of test : DFTEST_102
  432. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-102
  433. // /dfRootMode:xactReadWriteShEx /dfname:DFROOT.DFL
  434. //
  435. // BUGNOTE: Conversion: DFTEST-102 NO
  436. //
  437. // StgIsOpenStorage returns S_OK in transacted mode before Commit is done.
  438. //-----------------------------------------------------------------------------
  439. HRESULT DFTEST_102(int argc, char *argv[])
  440. {
  441. HRESULT hr = S_OK;
  442. HRESULT hr2 = S_OK;
  443. ChanceDF *pTestChanceDF = NULL;
  444. VirtualDF *pTestVirtualDF = NULL;
  445. VirtualCtrNode *pVirtualDFRoot = NULL;
  446. LPTSTR pFileName = NULL;
  447. LPOLESTR pOleStrTemp = NULL;
  448. // Not for 2phase. Bail.
  449. if (DoingDistrib ())
  450. {
  451. return S_OK;
  452. }
  453. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_102"));
  454. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  455. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_102 started.")) );
  456. DH_TRACE((DH_LVL_TRACE1,
  457. TEXT("Regression test for RootDocFile creation/commit/release")));
  458. DH_TRACE((DH_LVL_TRACE1,
  459. TEXT("in transacted mode. Use StgIsStorageFile to verify.")));
  460. // Create the new ChanceDocFile tree that would consist of chance nodes.
  461. if (S_OK == hr)
  462. {
  463. pTestChanceDF = new ChanceDF();
  464. if(NULL == pTestChanceDF)
  465. {
  466. hr = E_OUTOFMEMORY;
  467. }
  468. }
  469. if (S_OK == hr)
  470. {
  471. hr = pTestChanceDF->CreateFromParams(argc, argv);
  472. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  473. }
  474. if (S_OK == hr)
  475. {
  476. DH_TRACE((
  477. DH_LVL_TRACE1,
  478. TEXT("Run Mode for DFTEST_102, Access mode: %lx"),
  479. pTestChanceDF->GetRootMode()));
  480. }
  481. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  482. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  483. // and VirtualStmNodes.
  484. if (S_OK == hr)
  485. {
  486. pTestVirtualDF = new VirtualDF();
  487. if(NULL == pTestVirtualDF)
  488. {
  489. hr = E_OUTOFMEMORY;
  490. }
  491. }
  492. if (S_OK == hr)
  493. {
  494. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  495. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  496. }
  497. if (S_OK == hr)
  498. {
  499. DH_TRACE((
  500. DH_LVL_TRACE1,
  501. TEXT("DocFile - CreateFromParams - successfully created.")));
  502. }
  503. else
  504. {
  505. DH_TRACE((
  506. DH_LVL_TRACE1,
  507. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  508. hr));
  509. }
  510. if(S_OK == hr)
  511. {
  512. // Convert DocFile name to OLECHAR
  513. hr = TStringToOleString(pTestVirtualDF->GetDocFileName(), &pOleStrTemp);
  514. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  515. }
  516. // Use StgIsStorageFile now. This should return S_OK since even if
  517. // commit is not done till this point, signature is written into it.
  518. // This is different frol old base tests since this enhancement is
  519. // checked in by Storage team (confirmed by PhilipLa)
  520. if (S_OK == hr)
  521. {
  522. hr = StgIsStorageFile(pOleStrTemp);
  523. if(S_OK == hr)
  524. {
  525. DH_TRACE((
  526. DH_LVL_TRACE1,
  527. TEXT("StgIsStorage returned hr = 0x%lx as expected."), hr));
  528. }
  529. else
  530. {
  531. DH_TRACE((
  532. DH_LVL_TRACE1,
  533. TEXT("StgIsStorage returned hr = 0x%lx unexpectedly."), hr));
  534. }
  535. }
  536. // Commit the root docfile with STGC_ONLYIFCURRENT mode.
  537. if (S_OK == hr)
  538. {
  539. hr = pVirtualDFRoot->Commit(STGC_ONLYIFCURRENT);
  540. }
  541. if (S_OK == hr)
  542. {
  543. DH_TRACE((
  544. DH_LVL_TRACE1,
  545. TEXT("VirtualCtrNode::Commit completed successfully.")));
  546. }
  547. else
  548. {
  549. DH_TRACE((
  550. DH_LVL_TRACE1,
  551. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  552. hr));
  553. }
  554. // Use StgIsStorageFile now. This should again return S_OK since commit is
  555. // done by now.
  556. if (S_OK == hr)
  557. {
  558. hr = StgIsStorageFile(pOleStrTemp);
  559. if(S_OK == hr)
  560. {
  561. DH_TRACE((
  562. DH_LVL_TRACE1,
  563. TEXT("StgIsStorage returned hr = 0x%lx as expected."), hr));
  564. }
  565. else
  566. {
  567. DH_TRACE((
  568. DH_LVL_TRACE1,
  569. TEXT("StgIsStorage returned hr = 0x%lx unexpectedly."), hr));
  570. }
  571. }
  572. // Call Release on root docfile
  573. if (S_OK == hr)
  574. {
  575. hr = pVirtualDFRoot->Close();
  576. }
  577. if (S_OK == hr)
  578. {
  579. DH_TRACE((
  580. DH_LVL_TRACE1,
  581. TEXT("VirtualCtrNode::Close completed successfully.")));
  582. }
  583. else
  584. {
  585. DH_TRACE((
  586. DH_LVL_TRACE1,
  587. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  588. hr));
  589. }
  590. // if everything goes well, log test as passed else failed.
  591. if (S_OK == hr)
  592. {
  593. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_102 passed.")) );
  594. }
  595. else
  596. {
  597. DH_LOG((
  598. LOG_FAIL,
  599. TEXT("Test variation DFTEST_102 failed, hr = 0x%lx."),
  600. hr) );
  601. }
  602. // Cleanup
  603. // Get the name of file, will be used later to delete the file
  604. if(NULL != pVirtualDFRoot)
  605. {
  606. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  607. if (pFileName != NULL)
  608. {
  609. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  610. }
  611. }
  612. // Delete the docfile on disk
  613. if((S_OK == hr) && (NULL != pFileName))
  614. {
  615. if(FALSE == DeleteFile(pFileName))
  616. {
  617. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  618. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  619. }
  620. }
  621. // Delete Chance docfile tree
  622. if(NULL != pTestChanceDF)
  623. {
  624. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  625. pTestChanceDF->GetChanceDFRoot());
  626. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  627. delete pTestChanceDF;
  628. pTestChanceDF = NULL;
  629. }
  630. // Delete Virtual docfile tree
  631. if(NULL != pTestVirtualDF)
  632. {
  633. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  634. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  635. delete pTestVirtualDF;
  636. pTestVirtualDF = NULL;
  637. }
  638. // Delete temp string
  639. if(NULL != pFileName)
  640. {
  641. delete pFileName;
  642. pFileName = NULL;
  643. }
  644. if(NULL != pOleStrTemp)
  645. {
  646. delete pOleStrTemp;
  647. pOleStrTemp = NULL;
  648. }
  649. // Stop logging the test
  650. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_102 finished")) );
  651. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  652. return hr;
  653. }
  654. //----------------------------------------------------------------------------
  655. //
  656. // Test: DFTEST_103
  657. //
  658. // Synopsis: Regression test to create and instantiate a root docfile with path
  659. // as part of the name.
  660. //
  661. // Arguments:[argc]
  662. // [argv]
  663. //
  664. // Returns: HRESULT
  665. //
  666. // History: 3-June-1996 NarindK Created.
  667. //
  668. // Notes: This test runs in direct, transacted, and transacted deny write
  669. // modes
  670. //
  671. // New Test Notes:
  672. // 1. Old File: DFTESTN.CXX
  673. // 2. Old name of test :
  674. // New Name of test : DFTEST_103
  675. // 3. To run the test, do the following at command prompt.
  676. // stgbase /seed:0 /t:DFTEST-103
  677. //
  678. // BUGNOTE: Conversion: DFTEST-103 NO
  679. //
  680. //-----------------------------------------------------------------------------
  681. HRESULT DFTEST_103(ULONG ulSeed)
  682. {
  683. HRESULT hr = S_OK;
  684. HRESULT hr2 = S_OK;
  685. LPSTORAGE pIRootStorage = NULL;
  686. DWORD dwLen = 0;
  687. DG_STRING *pdgu = NULL;
  688. USHORT usErr = 0;
  689. LPTSTR pFileName = NULL;
  690. LPOLESTR poszFileName = NULL;
  691. TCHAR tszFileName[MAX_PATH+1];
  692. ULONG ulRef = 0;
  693. DWORD dwDirectMode = STGM_DIRECT |
  694. STGM_READWRITE |
  695. STGM_SHARE_EXCLUSIVE;
  696. DWORD dwTransactedMode = STGM_TRANSACTED |
  697. STGM_READWRITE |
  698. STGM_SHARE_EXCLUSIVE;
  699. DWORD dwTransactedDWMode = STGM_TRANSACTED |
  700. STGM_READWRITE |
  701. STGM_SHARE_DENY_WRITE;
  702. DWORD dwRootMode[3] = {dwDirectMode,
  703. dwTransactedMode,
  704. dwTransactedDWMode};
  705. INT count = 0;
  706. // Not for 2phase. Bail.
  707. if (DoingDistrib ())
  708. {
  709. return S_OK;
  710. }
  711. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_103"));
  712. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  713. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_103 started.")) );
  714. DH_TRACE((DH_LVL_TRACE1,
  715. TEXT("Regression for RootDF creation with path as part of name.")));
  716. if(S_OK == hr)
  717. {
  718. // Create a new DataGen object to create random strings.
  719. pdgu = new(NullOnFail) DG_STRING(ulSeed);
  720. if (NULL == pdgu)
  721. {
  722. hr = E_OUTOFMEMORY;
  723. }
  724. }
  725. if(S_OK == hr)
  726. {
  727. // Generate random name for root
  728. hr = GenerateRandomName(
  729. pdgu,
  730. MINLENGTH,
  731. MAXLENGTH,
  732. &pFileName);
  733. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  734. }
  735. // Determine current directory path (so that a MAX_PATH long
  736. // filename can be constructed).
  737. if (S_OK == hr)
  738. {
  739. dwLen = GetCurrentDirectory(MAX_PATH, tszFileName);
  740. if (0 == dwLen)
  741. {
  742. hr = HRESULT_FROM_WIN32(GetLastError());
  743. DH_HRCHECK(hr, TEXT("GetCurrentDirectory"));
  744. }
  745. }
  746. if (S_OK == hr)
  747. {
  748. _tcscat(tszFileName, SZ_SEP);
  749. _tcscat(tszFileName, pFileName);
  750. DH_TRACE((
  751. DH_LVL_TRACE1,
  752. TEXT("Name of root docfile %ws for DFTEST_103 "),
  753. tszFileName));
  754. }
  755. if(S_OK == hr)
  756. {
  757. // Convert RootDocFile name to OLECHAR
  758. hr = TStringToOleString(tszFileName, &poszFileName);
  759. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  760. }
  761. // First attempt test with Direct mode.
  762. while((count<3) && (S_OK == hr))
  763. {
  764. DH_TRACE((
  765. DH_LVL_TRACE1,
  766. TEXT("Run Mode for DFTEST_103, Access mode: %lx"),
  767. dwRootMode[count]));
  768. // Only direct mode is supported for flatfiles, so do accordingly
  769. // ----------- flatfile change ---------------
  770. if(StorageIsFlat() && ( dwDirectMode != dwRootMode[count]))
  771. {
  772. break;
  773. }
  774. // ----------- flatfile change ---------------
  775. // Call StgCreateDocFile with path in file name.
  776. if (S_OK == hr)
  777. {
  778. hr = StgCreateDocfile(
  779. poszFileName,
  780. STGM_CREATE | dwRootMode[count],
  781. 0,
  782. &pIRootStorage);
  783. }
  784. if (S_OK == hr)
  785. {
  786. DH_TRACE((
  787. DH_LVL_TRACE1,
  788. TEXT("StgCreateDocfile completed successfully.")));
  789. }
  790. else
  791. {
  792. DH_TRACE((
  793. DH_LVL_TRACE1,
  794. TEXT("StgCreateDocfile unsuccessful, hr = 0x%lx."),
  795. hr));
  796. }
  797. // Commit
  798. if (S_OK == hr)
  799. {
  800. hr = pIRootStorage->Commit(STGC_DEFAULT);
  801. }
  802. if (S_OK == hr)
  803. {
  804. DH_TRACE((
  805. DH_LVL_TRACE1,
  806. TEXT("IStorage::Commit completed successfully.")));
  807. }
  808. else
  809. {
  810. DH_TRACE((
  811. DH_LVL_TRACE1,
  812. TEXT("IStorage::Commit unsuccessful, hr = 0x%lx."),
  813. hr));
  814. }
  815. // Call Release on root docfile
  816. if (S_OK == hr)
  817. {
  818. ulRef = pIRootStorage->Release();
  819. DH_ASSERT(0 == ulRef);
  820. pIRootStorage = NULL;
  821. }
  822. if (S_OK == hr)
  823. {
  824. DH_TRACE((
  825. DH_LVL_TRACE1,
  826. TEXT("IStorage::Release completed successfully.")));
  827. }
  828. else
  829. {
  830. DH_TRACE((
  831. DH_LVL_TRACE1,
  832. TEXT("IStorage::Release unsuccessfull, hr = 0x%lx."),
  833. hr));
  834. }
  835. // Instantiate the RootDocFile again
  836. if (S_OK == hr)
  837. {
  838. hr = StgOpenStorage(
  839. poszFileName,
  840. NULL,
  841. dwRootMode[count],
  842. NULL,
  843. 0,
  844. &pIRootStorage);
  845. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  846. }
  847. if (S_OK == hr)
  848. {
  849. DH_TRACE((
  850. DH_LVL_TRACE1,
  851. TEXT("StgOpenStorage completed successfully.")));
  852. }
  853. else
  854. {
  855. DH_TRACE((
  856. DH_LVL_TRACE1,
  857. TEXT("StgOpenStorage unsuccessful, hr = 0x%lx."),
  858. hr));
  859. }
  860. // Call Release on root docfile
  861. if (S_OK == hr)
  862. {
  863. ulRef = pIRootStorage->Release();
  864. DH_ASSERT(0 == ulRef);
  865. pIRootStorage = NULL;
  866. }
  867. if (S_OK == hr)
  868. {
  869. DH_TRACE((
  870. DH_LVL_TRACE1,
  871. TEXT("IStorage::Release completed successfully.")));
  872. }
  873. else
  874. {
  875. DH_TRACE((
  876. DH_LVL_TRACE1,
  877. TEXT("IStorage::Release unsuccessful, hr = 0x%lx."),
  878. hr));
  879. }
  880. count++;
  881. }
  882. // if everything goes well, log test as passed else failed.
  883. if (S_OK == hr)
  884. {
  885. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_103 passed.")) );
  886. }
  887. else
  888. {
  889. DH_LOG((
  890. LOG_FAIL,
  891. TEXT("Test variation DFTEST_103 failed, hr = 0x%lx."),
  892. hr) );
  893. }
  894. // Cleanup
  895. // Delete the docfile on disk
  896. if((S_OK == hr) && (NULL != pFileName))
  897. {
  898. if(FALSE == DeleteFile(pFileName))
  899. {
  900. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  901. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  902. }
  903. }
  904. // Delete temp string
  905. if(NULL != pFileName)
  906. {
  907. delete pFileName;
  908. pFileName = NULL;
  909. }
  910. if(NULL != poszFileName)
  911. {
  912. delete poszFileName;
  913. poszFileName = NULL;
  914. }
  915. // Delete data gen object
  916. if(NULL != pdgu)
  917. {
  918. delete pdgu;
  919. pdgu = NULL;
  920. }
  921. // Stop logging the test
  922. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_103 finished")) );
  923. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  924. return hr;
  925. }
  926. //----------------------------------------------------------------------------
  927. //
  928. // Test: DFTEST_104
  929. //
  930. // Synopsis: Regression test to create, instantiate and enumerate a root
  931. // docfile hierarchy and count objects.
  932. //
  933. // Arguments:[argc]
  934. // [argv]
  935. //
  936. // Returns: HRESULT
  937. //
  938. // History: 3-June-1996 NarindK Created.
  939. //
  940. // Notes: This test runs in direct mode.
  941. //
  942. // New Test Notes:
  943. // 1. Old File: DFVERIFY.CXX
  944. // 2. Old name of test : MiscDfVerify
  945. // New Name of test : DFTEST_104
  946. // 3. To run the test, do the following at command prompt.
  947. // a. stgbase /seed:2 /dfdepth:0-5 /dfstg:0-5 /dfstm:0-10 /t:DFTEST-104
  948. // /dfRootMode:dirReadWriteShEx
  949. //
  950. // BUGNOTE: Conversion: DFTEST_104
  951. //
  952. //-----------------------------------------------------------------------------
  953. HRESULT DFTEST_104(int argc, char *argv[])
  954. {
  955. HRESULT hr = S_OK;
  956. ChanceDF *pTestChanceDF = NULL;
  957. VirtualDF *pTestVirtualDF = NULL;
  958. VirtualCtrNode *pVirtualDFRoot = NULL;
  959. LPSTORAGE pStgRoot = NULL;
  960. ULONG cStg = 0;
  961. ULONG cStm = 0;
  962. ULONG cMemStg = 0;
  963. ULONG cMemStm = 0;
  964. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_104"));
  965. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  966. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_104 started.")) );
  967. DH_TRACE((DH_LVL_TRACE1,
  968. TEXT("Regression for RootDF creation/instantiation/enumeration.")));
  969. // Create our ChanceDF and VirtualDF
  970. hr = CreateTestDocfile (argc,
  971. argv,
  972. &pVirtualDFRoot,
  973. &pTestVirtualDF,
  974. &pTestChanceDF);
  975. // if creating the docfile - bail here
  976. if (NULL != pTestChanceDF && DoingCreate ())
  977. {
  978. UINT ulSeed = pTestChanceDF->GetSeed ();
  979. CleanupTestDocfile (&pVirtualDFRoot,
  980. &pTestVirtualDF,
  981. &pTestChanceDF,
  982. FALSE);
  983. return (HRESULT)ulSeed;
  984. }
  985. if (S_OK == hr)
  986. {
  987. DH_TRACE((
  988. DH_LVL_TRACE1,
  989. TEXT("Run Mode for DFTEST_104, Access mode: %lx"),
  990. pTestChanceDF->GetRootMode()));
  991. }
  992. // Enumerate the DocFile in memory and get the number of VirtualCtrNodes
  993. // and VirtualStmNodes. Later on we could compare these statistics with
  994. // real IStorages / IStreams enumerated from the disk docfile.
  995. if (S_OK == hr)
  996. {
  997. hr = EnumerateInMemoryDocFile(pVirtualDFRoot, &cMemStg, &cMemStm);
  998. DH_HRCHECK(hr, TEXT("EnumerateInMemoryDocFile"));
  999. }
  1000. if (S_OK == hr)
  1001. {
  1002. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1003. }
  1004. if (S_OK == hr)
  1005. {
  1006. DH_TRACE((
  1007. DH_LVL_TRACE1,
  1008. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1009. }
  1010. else
  1011. {
  1012. DH_TRACE((
  1013. DH_LVL_TRACE1,
  1014. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1015. hr));
  1016. }
  1017. // Clsoe all the substorages/streams
  1018. if(S_OK == hr)
  1019. {
  1020. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1021. pVirtualDFRoot,
  1022. NODE_EXC_TOPSTG);
  1023. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1024. }
  1025. // Call Release on root docfile
  1026. if (S_OK == hr)
  1027. {
  1028. hr = pVirtualDFRoot->Close();
  1029. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  1030. }
  1031. if (S_OK == hr)
  1032. {
  1033. DH_TRACE((
  1034. DH_LVL_TRACE1,
  1035. TEXT("VirtualCtrNode::Close completed successfully.")));
  1036. }
  1037. else
  1038. {
  1039. DH_TRACE((
  1040. DH_LVL_TRACE1,
  1041. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1042. hr));
  1043. }
  1044. // Instantiate the RootDocFile again
  1045. if (S_OK == hr)
  1046. {
  1047. hr = pVirtualDFRoot->Open(
  1048. NULL,
  1049. STGM_READWRITE |
  1050. STGM_SHARE_EXCLUSIVE,
  1051. NULL,
  1052. 0);
  1053. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1054. }
  1055. if (S_OK == hr)
  1056. {
  1057. DH_TRACE((
  1058. DH_LVL_TRACE1,
  1059. TEXT("VirtualCtrNode::Open completed successfully.")));
  1060. }
  1061. else
  1062. {
  1063. DH_TRACE((
  1064. DH_LVL_TRACE1,
  1065. TEXT("VirtualCtrNode::Open unsuccessful, hr = 0x%lx."),
  1066. hr));
  1067. }
  1068. if (S_OK == hr)
  1069. {
  1070. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  1071. if(NULL == pStgRoot)
  1072. {
  1073. DH_LOG((LOG_INFO,
  1074. TEXT("pVirtualDFRoot->GetIStoragePointer failed to return IStorage")) );
  1075. hr = E_FAIL;
  1076. }
  1077. }
  1078. // Enumerate the Docfile on the disk
  1079. if (S_OK == hr)
  1080. {
  1081. hr = EnumerateDiskDocFile(pStgRoot, VERIFY_SHORT, &cStg, &cStm);
  1082. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile"));
  1083. }
  1084. // Check the disk docfile enumeration with in memory docfile enumeration.
  1085. if (S_OK == hr)
  1086. {
  1087. if((cMemStg == cStg) && (cMemStm == cStm))
  1088. {
  1089. DH_TRACE((
  1090. DH_LVL_TRACE1,
  1091. TEXT("DocFile correctly written & enumerated.")) );
  1092. }
  1093. else
  1094. {
  1095. hr = S_FALSE;
  1096. DH_TRACE((
  1097. DH_LVL_TRACE1,
  1098. TEXT("DocFile not correctly written or enumerated.")) );
  1099. }
  1100. }
  1101. // Call Release on root docfile
  1102. if (S_OK == hr)
  1103. {
  1104. hr = pVirtualDFRoot->Close();
  1105. }
  1106. if (S_OK == hr)
  1107. {
  1108. DH_TRACE((
  1109. DH_LVL_TRACE1,
  1110. TEXT("VirtualCtrNode::Close completed successfully.")));
  1111. }
  1112. else
  1113. {
  1114. DH_TRACE((
  1115. DH_LVL_TRACE1,
  1116. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1117. hr));
  1118. }
  1119. // if everything goes well, log test as passed else failed.
  1120. if (S_OK == hr)
  1121. {
  1122. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_104 passed.")) );
  1123. }
  1124. else
  1125. {
  1126. DH_LOG((
  1127. LOG_FAIL,
  1128. TEXT("Test variation DFTEST_104 failed, hr = 0x%lx."),
  1129. hr) );
  1130. }
  1131. // Cleanup
  1132. CleanupTestDocfile (&pVirtualDFRoot,
  1133. &pTestVirtualDF,
  1134. &pTestChanceDF,
  1135. S_OK == hr);
  1136. // Stop logging the test
  1137. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_104 finished")) );
  1138. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1139. return hr;
  1140. }
  1141. //----------------------------------------------------------------------------
  1142. //
  1143. // Test: DFTEST_105
  1144. //
  1145. // Synopsis: Regression test to create and instantiate a root docfile with a
  1146. // random name, a child IStorage within the root, and an additional
  1147. // child storage within the first child IStorage. The first child is
  1148. // released before its child is released, verify no error. The first
  1149. // child is reinstantiated. The root IStorage is now released before
  1150. // the child IStorage, verify no error.
  1151. //
  1152. // Arguments:[argc]
  1153. // [argv]
  1154. //
  1155. // Returns: HRESULT
  1156. //
  1157. // History: 3-June-1996 NarindK Created.
  1158. //
  1159. // Notes: This test runs in direct, transacted, and transacted deny write
  1160. // modes
  1161. //
  1162. // New Test Notes:
  1163. // 1. Old File: IIREL.CXX
  1164. // 2. Old name of test : IllegitInstEnumRelease Test
  1165. // New Name of test : DFTEST_105
  1166. // 3. To run the test, do the following at command prompt.
  1167. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-105
  1168. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1169. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-105
  1170. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1171. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-105
  1172. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1173. //
  1174. // BUGNOTE: Conversion: DFTEST-105
  1175. //
  1176. //-----------------------------------------------------------------------------
  1177. HRESULT DFTEST_105(int argc, char *argv[])
  1178. {
  1179. HRESULT hr = S_OK;
  1180. ChanceDF *pTestChanceDF = NULL;
  1181. VirtualDF *pTestVirtualDF = NULL;
  1182. VirtualCtrNode *pVirtualDFRoot = NULL;
  1183. DG_STRING *pdgu = NULL;
  1184. USHORT usErr = 0;
  1185. VirtualCtrNode *pvcnRootChildStorage = NULL;
  1186. LPTSTR pRootChildStgName = NULL;
  1187. VirtualCtrNode *pvcnChildChildStorage = NULL;
  1188. LPTSTR pChildChildStgName = NULL;
  1189. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_105"));
  1190. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1191. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_105 started.")) );
  1192. DH_TRACE((DH_LVL_TRACE1,
  1193. TEXT("Create Root DF with Child IStg which has its Child IStg.")));
  1194. DH_TRACE((DH_LVL_TRACE1,
  1195. TEXT("Release first child IStg w/o releasing its child IStg.")));
  1196. DH_TRACE((DH_LVL_TRACE1,
  1197. TEXT("Reinstantiate 1st child IStg. Release root w/o releasing")));
  1198. DH_TRACE((DH_LVL_TRACE1, TEXT("this IStg. Verify no errors.")));
  1199. // Create our ChanceDF and VirtualDF
  1200. hr = CreateTestDocfile (argc,
  1201. argv,
  1202. &pVirtualDFRoot,
  1203. &pTestVirtualDF,
  1204. &pTestChanceDF);
  1205. // if creating the docfile - bail here
  1206. if (NULL != pTestChanceDF && DoingCreate ())
  1207. {
  1208. UINT ulSeed = pTestChanceDF->GetSeed ();
  1209. CleanupTestDocfile (&pVirtualDFRoot,
  1210. &pTestVirtualDF,
  1211. &pTestChanceDF,
  1212. FALSE);
  1213. return (HRESULT)ulSeed;
  1214. }
  1215. if (S_OK == hr)
  1216. {
  1217. DH_TRACE((
  1218. DH_LVL_TRACE1,
  1219. TEXT("Run Mode for DFTEST_105, Access mode: %lx"),
  1220. pTestChanceDF->GetRootMode()));
  1221. }
  1222. // Get DG_STRING object pointer
  1223. if (S_OK == hr)
  1224. {
  1225. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1226. if(NULL == pdgu)
  1227. {
  1228. DH_LOG((LOG_INFO,
  1229. TEXT("pTestVirtualDF->GetDataGenUnicode failed")) );
  1230. hr = E_FAIL;
  1231. }
  1232. }
  1233. // Create a child IStorage in the root.
  1234. // Generate a random name for child IStorage
  1235. if(S_OK == hr)
  1236. {
  1237. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootChildStgName);
  1238. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1239. }
  1240. // Adds a new storage to the root storage.
  1241. if(S_OK == hr)
  1242. {
  1243. hr = AddStorage(
  1244. pTestVirtualDF,
  1245. pVirtualDFRoot,
  1246. pRootChildStgName,
  1247. pTestChanceDF->GetStgMode()|
  1248. STGM_CREATE |
  1249. STGM_FAILIFTHERE,
  1250. &pvcnRootChildStorage);
  1251. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1252. }
  1253. if(S_OK == hr)
  1254. {
  1255. DH_TRACE((
  1256. DH_LVL_TRACE1,
  1257. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  1258. }
  1259. else
  1260. {
  1261. DH_TRACE((
  1262. DH_LVL_TRACE1,
  1263. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  1264. hr));
  1265. }
  1266. // Create a child IStorage inside the child IStorage.
  1267. // Generate a random name for the new child IStorage
  1268. if(S_OK == hr)
  1269. {
  1270. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &pChildChildStgName);
  1271. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1272. }
  1273. // Adds a new storage to the root storage.
  1274. if(S_OK == hr)
  1275. {
  1276. hr = AddStorage(
  1277. pTestVirtualDF,
  1278. pvcnRootChildStorage,
  1279. pChildChildStgName,
  1280. pTestChanceDF->GetStgMode()|
  1281. STGM_CREATE |
  1282. STGM_FAILIFTHERE,
  1283. &pvcnChildChildStorage);
  1284. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1285. }
  1286. if(S_OK == hr)
  1287. {
  1288. DH_TRACE((
  1289. DH_LVL_TRACE1,
  1290. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  1291. }
  1292. else
  1293. {
  1294. DH_TRACE((
  1295. DH_LVL_TRACE1,
  1296. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  1297. hr));
  1298. }
  1299. // Commit the storages
  1300. // BUGBUG: Use Random commit modes...
  1301. if (S_OK == hr)
  1302. {
  1303. hr = pvcnChildChildStorage->Commit(STGC_DEFAULT);
  1304. }
  1305. if (S_OK == hr)
  1306. {
  1307. DH_TRACE((
  1308. DH_LVL_TRACE1,
  1309. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1310. }
  1311. else
  1312. {
  1313. DH_TRACE((
  1314. DH_LVL_TRACE1,
  1315. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1316. hr));
  1317. }
  1318. // BUGBUG: Use Random commit modes...
  1319. if (S_OK == hr)
  1320. {
  1321. hr = pvcnRootChildStorage->Commit(STGC_DEFAULT);
  1322. }
  1323. if (S_OK == hr)
  1324. {
  1325. DH_TRACE((
  1326. DH_LVL_TRACE1,
  1327. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1328. }
  1329. else
  1330. {
  1331. DH_TRACE((
  1332. DH_LVL_TRACE1,
  1333. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1334. hr));
  1335. }
  1336. // BUGBUG: Use Random commit modes...
  1337. if (S_OK == hr)
  1338. {
  1339. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1340. }
  1341. if (S_OK == hr)
  1342. {
  1343. DH_TRACE((
  1344. DH_LVL_TRACE1,
  1345. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1346. }
  1347. else
  1348. {
  1349. DH_TRACE((
  1350. DH_LVL_TRACE1,
  1351. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1352. hr));
  1353. }
  1354. // Release child IStorage before its child is released, should
  1355. // cause no error
  1356. if (S_OK == hr)
  1357. {
  1358. hr = pvcnRootChildStorage->Close();
  1359. }
  1360. if (S_OK == hr)
  1361. {
  1362. DH_TRACE((
  1363. DH_LVL_TRACE1,
  1364. TEXT("VirtualCtrNode::Close completed successfully.")));
  1365. }
  1366. else
  1367. {
  1368. DH_TRACE((
  1369. DH_LVL_TRACE1,
  1370. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1371. hr));
  1372. }
  1373. // Release child's child IStorage
  1374. if (S_OK == hr)
  1375. {
  1376. hr = pvcnChildChildStorage->Close();
  1377. }
  1378. if (S_OK == hr)
  1379. {
  1380. DH_TRACE((
  1381. DH_LVL_TRACE1,
  1382. TEXT("VirtualCtrNode::Close completed successfully.")));
  1383. }
  1384. else
  1385. {
  1386. DH_TRACE((
  1387. DH_LVL_TRACE1,
  1388. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1389. hr));
  1390. }
  1391. // Reinstantiate the Root's child IStorage again
  1392. if (S_OK == hr)
  1393. {
  1394. hr = pvcnRootChildStorage->Open(
  1395. NULL,
  1396. pTestChanceDF->GetStgMode(),
  1397. NULL,
  1398. 0);
  1399. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1400. }
  1401. if (S_OK == hr)
  1402. {
  1403. DH_TRACE((
  1404. DH_LVL_TRACE1,
  1405. TEXT("VirtualCtrNode::Open completed successfully.")));
  1406. }
  1407. else
  1408. {
  1409. DH_TRACE((
  1410. DH_LVL_TRACE1,
  1411. TEXT("VirtualCtrNode::Open unsuccessful, hr = 0x%lx."),
  1412. hr));
  1413. }
  1414. // Call Release on root docfile before calling Release on its child.
  1415. // Verify no error.
  1416. if (S_OK == hr)
  1417. {
  1418. hr = pVirtualDFRoot->Close();
  1419. }
  1420. if (S_OK == hr)
  1421. {
  1422. DH_TRACE((
  1423. DH_LVL_TRACE1,
  1424. TEXT("VirtualCtrNode::Close completed successfully.")));
  1425. }
  1426. else
  1427. {
  1428. DH_TRACE((
  1429. DH_LVL_TRACE1,
  1430. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1431. hr));
  1432. }
  1433. // Release Root's child IStorage now.
  1434. if (S_OK == hr)
  1435. {
  1436. hr = pvcnRootChildStorage->Close();
  1437. }
  1438. if (S_OK == hr)
  1439. {
  1440. DH_TRACE((
  1441. DH_LVL_TRACE1,
  1442. TEXT("VirtualCtrNode::Close completed successfully.")));
  1443. }
  1444. else
  1445. {
  1446. DH_TRACE((
  1447. DH_LVL_TRACE1,
  1448. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1449. hr));
  1450. }
  1451. // if everything goes well, log test as passed else failed.
  1452. if (S_OK == hr)
  1453. {
  1454. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_105 passed.")) );
  1455. }
  1456. else
  1457. {
  1458. DH_LOG((
  1459. LOG_FAIL,
  1460. TEXT("Test variation DFTEST_105 failed, hr = 0x%lx."),
  1461. hr) );
  1462. }
  1463. // Cleanup
  1464. CleanupTestDocfile (&pVirtualDFRoot,
  1465. &pTestVirtualDF,
  1466. &pTestChanceDF,
  1467. S_OK == hr);
  1468. // Delete strings
  1469. if(NULL != pRootChildStgName)
  1470. {
  1471. delete pRootChildStgName;
  1472. pRootChildStgName = NULL;
  1473. }
  1474. if(NULL != pChildChildStgName)
  1475. {
  1476. delete pChildChildStgName;
  1477. pChildChildStgName = NULL;
  1478. }
  1479. // Stop logging the test
  1480. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_105 finished")) );
  1481. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1482. return hr;
  1483. }
  1484. //----------------------------------------------------------------------------
  1485. //
  1486. // Test: DFTEST_106
  1487. //
  1488. // Synopsis: Attempts several illegitimate operations during creation of
  1489. // root docfile.
  1490. //
  1491. // Arguments:[argc]
  1492. // [argv]
  1493. //
  1494. // Returns: HRESULT
  1495. //
  1496. // History: 3-June-1996 NarindK Created.
  1497. //
  1498. // Notes: This test runs in direct, transacted, and transacted deny write
  1499. // modes
  1500. //
  1501. // New Test Notes:
  1502. // 1. Old File: IRCREATE.CXX
  1503. // 2. Old name of test : IllegitRootCreate Test
  1504. // New Name of test : DFTEST_106
  1505. // 3. To run the test, do the following at command prompt.
  1506. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-106
  1507. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1508. // /dfname:DFTEST.106
  1509. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-106
  1510. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1511. // /dfname:DFTEST.106
  1512. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:DFTEST-106
  1513. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1514. // /dfname:DFTEST.106
  1515. //
  1516. // BUGNOTE: Conversion: DFTEST-106 NO
  1517. //
  1518. //-----------------------------------------------------------------------------
  1519. HRESULT DFTEST_106(int argc, char *argv[])
  1520. {
  1521. HRESULT hr = S_OK;
  1522. HRESULT hr2 = S_OK;
  1523. ChanceDF *pTestChanceDF = NULL;
  1524. VirtualDF *pTestVirtualDF = NULL;
  1525. VirtualCtrNode *pVirtualDFRoot = NULL;
  1526. LPTSTR pRootDocFileName = NULL;
  1527. DWORD dwRootMode = NULL;
  1528. LPSTORAGE pIStorage = NULL;
  1529. LPSTORAGE pIStorageOpen = NULL;
  1530. LPOLESTR pOleStrTemp = NULL;
  1531. FILE *hFile = NULL;
  1532. ULONG ulRef = 0;
  1533. BOOL fPass = TRUE;
  1534. int iErr = 0;
  1535. // Not for 2phase. Bail.
  1536. if (DoingDistrib ())
  1537. {
  1538. return S_OK;
  1539. }
  1540. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("DFTEST_106"));
  1541. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1542. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_106 started.")) );
  1543. DH_TRACE((DH_LVL_TRACE1,
  1544. TEXT("Attempt illegitimate operations in creation of root docfile.")));
  1545. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1546. if (S_OK == hr)
  1547. {
  1548. pTestChanceDF = new ChanceDF();
  1549. if(NULL == pTestChanceDF)
  1550. {
  1551. hr = E_OUTOFMEMORY;
  1552. }
  1553. }
  1554. if (S_OK == hr)
  1555. {
  1556. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1557. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1558. }
  1559. // GetRootDocFile mode
  1560. if (S_OK == hr)
  1561. {
  1562. dwRootMode = pTestChanceDF->GetRootMode();
  1563. DH_TRACE((
  1564. DH_LVL_TRACE1,
  1565. TEXT("Run Mode for DFTEST_106, Access mode: %lx"),
  1566. pTestChanceDF->GetRootMode()));
  1567. }
  1568. // Get RootDocFile name
  1569. if (S_OK == hr)
  1570. {
  1571. if(NULL != pTestChanceDF->GetDocFileName())
  1572. {
  1573. pRootDocFileName =
  1574. new TCHAR[_tcslen(pTestChanceDF->GetDocFileName())+1];
  1575. if (pRootDocFileName == NULL)
  1576. {
  1577. hr = E_OUTOFMEMORY;
  1578. }
  1579. else
  1580. {
  1581. _tcscpy(pRootDocFileName, pTestChanceDF->GetDocFileName());
  1582. }
  1583. }
  1584. else
  1585. {
  1586. DH_ASSERT(!"No DocFile name passed from cmd line!") ;
  1587. }
  1588. DH_HRCHECK(hr, TEXT("pTestChanceDF->GetDocFileName()")) ;
  1589. }
  1590. // Make a directory with the same name DFTEST.106 that we would use to
  1591. // create the directory. Check that call to StgCreateDocFile succeeds
  1592. if (S_OK == hr)
  1593. {
  1594. iErr = _tmkdir(pRootDocFileName);
  1595. if (0 != iErr)
  1596. {
  1597. // if file already exists, try deleting it and try mkdir again
  1598. if (ENOENT != errno)
  1599. {
  1600. iErr = DeleteFile (pRootDocFileName);
  1601. if (FALSE == iErr)
  1602. {
  1603. DH_TRACE ((DH_LVL_ERROR,
  1604. TEXT("DeleteFile(%s) Failed. Error:%#lx"),
  1605. pRootDocFileName,
  1606. GetLastError ()));
  1607. }
  1608. iErr = _tmkdir(pRootDocFileName);
  1609. }
  1610. }
  1611. if (0 != iErr)
  1612. {
  1613. hr = (EACCES == errno) ? ERROR_FILE_EXISTS : ERROR_FILE_NOT_FOUND;
  1614. DH_HRCHECK (hr, TEXT("mkdir"));
  1615. }
  1616. }
  1617. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  1618. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  1619. // and VirtualStmNodes.
  1620. if (S_OK == hr)
  1621. {
  1622. pTestVirtualDF = new VirtualDF();
  1623. if(NULL == pTestVirtualDF)
  1624. {
  1625. hr = E_OUTOFMEMORY;
  1626. }
  1627. }
  1628. // This call to generate VirtualDF will call StgCreateDocFile API. This
  1629. // call is expected to fail since dir of same name exists.
  1630. if (S_OK == hr)
  1631. {
  1632. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  1633. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  1634. if (STG_E_ACCESSDENIED != hr)
  1635. {
  1636. DH_TRACE((
  1637. DH_LVL_TRACE1,
  1638. TEXT("Should fail when dir of same name exists,hr = 0x%lx "),hr));
  1639. }
  1640. else
  1641. {
  1642. DH_TRACE((
  1643. DH_LVL_TRACE1,
  1644. TEXT("Failed as exp when dir of same name exists,hr = 0x%lx"), hr));
  1645. hr = S_OK;
  1646. }
  1647. }
  1648. // Case 2: Try STGM_CONVERT as mode now. This is also expected to fail, as
  1649. // a dir of same name pre exists.
  1650. if(S_OK == hr)
  1651. {
  1652. // Convert RootDocFile name to OLECHAR
  1653. hr = TStringToOleString(pRootDocFileName, &pOleStrTemp);
  1654. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  1655. }
  1656. // Try creating with STGM_CONVERT mode.
  1657. // ----------- flatfile change ---------------
  1658. if(!StorageIsFlat())
  1659. {
  1660. // ----------- flatfile change ---------------
  1661. if (S_OK == hr)
  1662. {
  1663. pIStorage = NULL;
  1664. hr = StgCreateDocfile(
  1665. pOleStrTemp,
  1666. STGM_CONVERT | dwRootMode,
  1667. 0,
  1668. &pIStorage);
  1669. if (STG_E_ACCESSDENIED != hr)
  1670. {
  1671. DH_TRACE((
  1672. DH_LVL_TRACE1,
  1673. TEXT("Err:Pass(STGM_CONVERT) with existing same name dir,hr=0x%lx"),
  1674. hr));
  1675. // if it accidentally opened, close it
  1676. if (S_OK == hr)
  1677. {
  1678. pIStorage->Release ();
  1679. pIStorage = 0;
  1680. }
  1681. fPass = FALSE;
  1682. }
  1683. else
  1684. {
  1685. DH_TRACE((
  1686. DH_LVL_TRACE1,
  1687. TEXT("Exp:Fail(STGM_CONVERT)with existing same name dir,hr=0x%lx"),
  1688. hr));
  1689. hr = S_OK;
  1690. }
  1691. }
  1692. // ----------- flatfile change ---------------
  1693. }
  1694. // ----------- flatfile change ---------------
  1695. // Remove the direcory DFTEST.106
  1696. if (S_OK == hr)
  1697. {
  1698. iErr = _trmdir(pRootDocFileName);
  1699. if (0 != iErr)
  1700. {
  1701. hr = (ENOENT == errno) ? ERROR_FILE_NOT_FOUND : ERROR_FILE_EXISTS;
  1702. DH_HRCHECK (hr, TEXT("rmdir"));
  1703. }
  1704. }
  1705. // Case 3: Create DocFile when file exists and is being accessed in deny
  1706. // write mode.
  1707. if (S_OK == hr)
  1708. {
  1709. hFile = _tfsopen(pRootDocFileName, TEXT("w+"), _SH_DENYWR);
  1710. DH_ASSERT(NULL != hFile);
  1711. }
  1712. // Try STGM_CREATE mode to create DocFile. This call is expected to fail
  1713. // as file exists and is being accessed in deny write mode.
  1714. if (S_OK == hr)
  1715. {
  1716. pIStorage = NULL;
  1717. hr = StgCreateDocfile(
  1718. pOleStrTemp,
  1719. STGM_CREATE | dwRootMode,
  1720. 0,
  1721. &pIStorage);
  1722. if (STG_E_SHAREVIOLATION != hr)
  1723. {
  1724. DH_TRACE((
  1725. DH_LVL_TRACE1,
  1726. TEXT("Err:Pass,same name file access in deny write mode, hr=0x%lx"),
  1727. hr));
  1728. // if it accidentally opened, close it
  1729. if (S_OK == hr)
  1730. {
  1731. pIStorage->Release ();
  1732. pIStorage = 0;
  1733. }
  1734. fPass = FALSE;
  1735. }
  1736. else
  1737. {
  1738. DH_TRACE((
  1739. DH_LVL_TRACE1,
  1740. TEXT("Exp;Fail,same name file access in deny write mode, hr=0x%lx"),
  1741. hr));
  1742. hr = S_OK;
  1743. }
  1744. }
  1745. // ----------- flatfile change ---------------
  1746. if(!StorageIsFlat())
  1747. {
  1748. // ----------- flatfile change ---------------
  1749. // Try STGM_CONVERT mode to create DocFile. This call is expected to fail
  1750. // as file exists and is being accessed in deny write mode.
  1751. if (S_OK == hr)
  1752. {
  1753. pIStorage = NULL;
  1754. hr = StgCreateDocfile(
  1755. pOleStrTemp,
  1756. STGM_CONVERT | dwRootMode,
  1757. 0,
  1758. &pIStorage);
  1759. if (STG_E_SHAREVIOLATION != hr)
  1760. {
  1761. DH_TRACE((
  1762. DH_LVL_TRACE1,
  1763. TEXT("Err:Pass(STGM_CONVERT),same name file access in deny write mode")
  1764. TEXT(", hr = 0x%lx "),
  1765. hr));
  1766. // if it accidentally opened, close it
  1767. if (S_OK == hr)
  1768. {
  1769. pIStorage->Release ();
  1770. pIStorage = 0;
  1771. }
  1772. fPass = FALSE;
  1773. }
  1774. else
  1775. {
  1776. DH_TRACE((
  1777. DH_LVL_TRACE1,
  1778. TEXT("Exp:Fail(STGM_CONVERT), same name file access in deny write \
  1779. mode, hr = 0x%lx "),
  1780. hr));
  1781. hr = S_OK;
  1782. }
  1783. }
  1784. // ----------- flatfile change ---------------
  1785. }
  1786. // ----------- flatfile change ---------------
  1787. // Close handle
  1788. if(NULL != hFile)
  1789. {
  1790. fclose(hFile);
  1791. }
  1792. // Change the mode to READ_ONLY and then try.
  1793. if(S_OK == hr)
  1794. {
  1795. iErr = _tchmod(pRootDocFileName, _S_IREAD);
  1796. DH_ASSERT (0 == iErr);
  1797. }
  1798. // Try STGM_CREATE mode to create DocFile. This call is expected to fail
  1799. // as file exists and is read only.
  1800. if (S_OK == hr)
  1801. {
  1802. pIStorage = NULL;
  1803. hr = StgCreateDocfile(
  1804. pOleStrTemp,
  1805. STGM_CREATE | dwRootMode,
  1806. 0,
  1807. &pIStorage);
  1808. if (STG_E_ACCESSDENIED != hr)
  1809. {
  1810. DH_TRACE((
  1811. DH_LVL_TRACE1,
  1812. TEXT("Err:Pass,same name file exists and is read only,hr=0x%lx "),
  1813. hr));
  1814. // if it accidentally opened, close it
  1815. if (S_OK == hr)
  1816. {
  1817. pIStorage->Release ();
  1818. pIStorage = 0;
  1819. }
  1820. fPass = FALSE;
  1821. }
  1822. else
  1823. {
  1824. DH_TRACE((
  1825. DH_LVL_TRACE1,
  1826. TEXT("Exp:Fail,same name file exists and is read only,hr = 0x%lx"),
  1827. hr));
  1828. hr = S_OK;
  1829. }
  1830. }
  1831. // Try STGM_CONVERT mode to create DocFile. This call is expected to fail
  1832. // as file exists and is read only.
  1833. // ----------- flatfile change ---------------
  1834. if(!StorageIsFlat())
  1835. {
  1836. // ----------- flatfile change ---------------
  1837. if (S_OK == hr)
  1838. {
  1839. pIStorage = NULL;
  1840. hr = StgCreateDocfile(
  1841. pOleStrTemp,
  1842. STGM_CONVERT | dwRootMode,
  1843. 0,
  1844. &pIStorage);
  1845. if (STG_E_ACCESSDENIED != hr)
  1846. {
  1847. DH_TRACE((
  1848. DH_LVL_TRACE1,
  1849. TEXT("Err:Pass(STGM_CONVERT), same name file exists RO,hr=0x%lx"),
  1850. hr));
  1851. // if it accidentally opened, close it
  1852. if (S_OK == hr)
  1853. {
  1854. pIStorage->Release ();
  1855. pIStorage = 0;
  1856. }
  1857. fPass = FALSE;
  1858. }
  1859. else
  1860. {
  1861. DH_TRACE((
  1862. DH_LVL_TRACE1,
  1863. TEXT("Exp:Fail(STGM_CONVERT),same name file exists RO,hr=0x%lx"),
  1864. hr));
  1865. hr = S_OK;
  1866. }
  1867. }
  1868. // ----------- flatfile change ---------------
  1869. }
  1870. // ----------- flatfile change ---------------
  1871. // Change mode to readwrite
  1872. iErr = _tchmod(pRootDocFileName, _S_IREAD|_S_IWRITE);
  1873. DH_ASSERT (0 == iErr);
  1874. // Try to instantiate the pRootDocFileName which isn't a storage object
  1875. if (S_OK == hr)
  1876. {
  1877. hr = StgOpenStorage(
  1878. pOleStrTemp,
  1879. NULL,
  1880. dwRootMode,
  1881. NULL,
  1882. 0,
  1883. &pIStorageOpen);
  1884. // ----------- flatfile change ---------------
  1885. if(!StorageIsFlat())
  1886. {
  1887. // ----------- flatfile change ---------------
  1888. if(STG_E_FILEALREADYEXISTS == hr)
  1889. {
  1890. DH_TRACE((
  1891. DH_LVL_TRACE1,
  1892. TEXT("DocFile instantiated failed as exp with non stg obj hr=0x%lx"),
  1893. hr));
  1894. hr = S_OK;
  1895. }
  1896. else
  1897. {
  1898. DH_TRACE((
  1899. DH_LVL_TRACE1,
  1900. TEXT("DocFile instantiation passed unexp with non stg obj,hr=0x%lx"),
  1901. hr));
  1902. // if it accidentally opened, close it
  1903. if (S_OK == hr)
  1904. {
  1905. pIStorageOpen->Release ();
  1906. pIStorageOpen = NULL;
  1907. }
  1908. fPass = FALSE;
  1909. }
  1910. }
  1911. else // ----------- flatfile change ---------------
  1912. {
  1913. if(S_OK == hr)
  1914. {
  1915. DH_TRACE((
  1916. DH_LVL_TRACE1,
  1917. TEXT("Exp:Flatfile instantiation passed with non stg obj,hr=0x%lx"),
  1918. hr));
  1919. if (NULL != pIStorageOpen)
  1920. {
  1921. pIStorageOpen->Release ();
  1922. pIStorageOpen = NULL;
  1923. }
  1924. }
  1925. else
  1926. {
  1927. DH_TRACE((
  1928. DH_LVL_TRACE1,
  1929. TEXT("UnExp:Flatfile instantiation fail with nonstg obj,hr=0x%lx"),
  1930. hr));
  1931. fPass = FALSE;
  1932. hr = S_OK; // Set hr to S_OK for further conditions test
  1933. }
  1934. // ----------- flatfile change ---------------
  1935. }
  1936. // ----------- flatfile change ---------------
  1937. }
  1938. // Remove the file
  1939. iErr = _tremove(pRootDocFileName);
  1940. DH_ASSERT (0 == iErr);
  1941. // Call StgCreateDocFile with non zero data in dwReserved parameter. This
  1942. // call is expected to fail
  1943. if (S_OK == hr)
  1944. {
  1945. pIStorage = NULL;
  1946. hr = StgCreateDocfile(
  1947. pOleStrTemp,
  1948. STGM_CREATE | dwRootMode,
  1949. 999,
  1950. &pIStorage);
  1951. if (STG_E_INVALIDPARAMETER != hr)
  1952. {
  1953. DH_TRACE((
  1954. DH_LVL_TRACE1,
  1955. TEXT("Err:Pass with nonzero dwReserverd para, hr = 0x%lx "),
  1956. hr));
  1957. // if it accidentally opened, close it
  1958. if (S_OK == hr)
  1959. {
  1960. pIStorage->Release ();
  1961. pIStorage = 0;
  1962. }
  1963. fPass = FALSE;
  1964. }
  1965. else
  1966. {
  1967. DH_TRACE((
  1968. DH_LVL_TRACE1,
  1969. TEXT("Exp: Fail with nonzero dwReserved parameter, hr=0x%lx "),
  1970. hr));
  1971. hr = S_OK;
  1972. }
  1973. }
  1974. // Call StgCreateDocFile with NULL 4th parameter. This call is expected
  1975. // to fail.
  1976. if (S_OK == hr)
  1977. {
  1978. pIStorage = NULL;
  1979. hr = StgCreateDocfile(
  1980. pOleStrTemp,
  1981. STGM_CREATE | dwRootMode,
  1982. 0,
  1983. NULL);
  1984. if (STG_E_INVALIDPOINTER != hr)
  1985. {
  1986. DH_TRACE((
  1987. DH_LVL_TRACE1,
  1988. TEXT("Should fail with NULL 4th parameter, hr = 0x%lx "), hr));
  1989. // if it accidentally opened, close it
  1990. if (S_OK == hr)
  1991. {
  1992. pIStorage->Release ();
  1993. pIStorage = 0;
  1994. }
  1995. fPass = FALSE;
  1996. }
  1997. else
  1998. {
  1999. DH_TRACE((
  2000. DH_LVL_TRACE1,
  2001. TEXT("Failed as exp with NULL 4th parameter, hr = 0x%lx "),
  2002. hr));
  2003. hr = S_OK;
  2004. }
  2005. }
  2006. // Call StgCreateDocFile with mode STGM_CREATE|STGM_CONVERT. This call
  2007. // is expected to fail.
  2008. // ----------- flatfile change ---------------
  2009. if(!StorageIsFlat())
  2010. {
  2011. // ----------- flatfile change ---------------
  2012. if (S_OK == hr)
  2013. {
  2014. pIStorage = NULL;
  2015. hr = StgCreateDocfile(
  2016. pOleStrTemp,
  2017. STGM_CREATE | STGM_CONVERT,
  2018. 0,
  2019. &pIStorage);
  2020. if (STG_E_INVALIDFLAG != hr)
  2021. {
  2022. DH_TRACE((
  2023. DH_LVL_TRACE1,
  2024. TEXT("Should fail with invalid mode, hr = 0x%lx "), hr));
  2025. // if it accidentally opened, close it
  2026. if (S_OK == hr)
  2027. {
  2028. pIStorage->Release ();
  2029. pIStorage = 0;
  2030. }
  2031. fPass = FALSE;
  2032. }
  2033. else
  2034. {
  2035. DH_TRACE((
  2036. DH_LVL_TRACE1,
  2037. TEXT("Failed as expected with invalid mode., hr = 0x%lx "), hr));
  2038. hr = S_OK;
  2039. }
  2040. }
  2041. // ----------- flatfile change ---------------
  2042. }
  2043. // ----------- flatfile change ---------------
  2044. // Call StgCreateDocFile with all valid parameters. This call is
  2045. // expected to pass.
  2046. if (S_OK == hr)
  2047. {
  2048. pIStorage = NULL;
  2049. hr = StgCreateDocfile(
  2050. pOleStrTemp,
  2051. STGM_CREATE | dwRootMode,
  2052. 0,
  2053. &pIStorage);
  2054. DH_HRCHECK(hr, TEXT("StgCreateDocFile")) ;
  2055. if (S_OK == hr)
  2056. {
  2057. DH_TRACE((
  2058. DH_LVL_TRACE1,
  2059. TEXT("DocFile created successfully as expected hr = 0x%lx "),hr));
  2060. }
  2061. else
  2062. {
  2063. DH_TRACE((
  2064. DH_LVL_TRACE1,
  2065. TEXT("DocFile creation failed unexpectedly, hr = 0x%lx "),hr));
  2066. fPass = FALSE;
  2067. }
  2068. }
  2069. // Instantiate DocFile again
  2070. if (S_OK == hr)
  2071. {
  2072. hr = StgOpenStorage(
  2073. pOleStrTemp,
  2074. NULL,
  2075. dwRootMode,
  2076. NULL,
  2077. 0,
  2078. &pIStorageOpen);
  2079. if(STG_E_LOCKVIOLATION == hr)
  2080. {
  2081. DH_TRACE((
  2082. DH_LVL_TRACE1,
  2083. TEXT("DocFile reinstantiated failed as expected hr = 0x%lx "),hr));
  2084. hr = S_OK;
  2085. }
  2086. else
  2087. {
  2088. DH_TRACE((
  2089. DH_LVL_TRACE1,
  2090. TEXT("DocFile reinstantiation didn't fail unexp, hr = 0x%lx "),
  2091. hr));
  2092. // if it accidentally opened, close it
  2093. if (S_OK == hr)
  2094. {
  2095. pIStorageOpen->Release ();
  2096. pIStorageOpen = 0;
  2097. }
  2098. fPass = FALSE;
  2099. }
  2100. }
  2101. // If everything goes okay, report test as passed, else failure
  2102. if ((S_OK == hr) && (TRUE == fPass))
  2103. {
  2104. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_106 passed.")) );
  2105. }
  2106. else
  2107. {
  2108. DH_LOG((
  2109. LOG_FAIL,
  2110. TEXT("Test variation DFTEST_106 failed, hr = 0x%lx."),
  2111. hr) );
  2112. // test failed. make it look like it failed.
  2113. hr = FirstError (hr, E_FAIL);
  2114. }
  2115. // Release storage pointer(s)
  2116. if (NULL != pIStorage)
  2117. {
  2118. ulRef = pIStorage->Release();
  2119. DH_ASSERT(0 == ulRef);
  2120. }
  2121. if (NULL != pIStorageOpen)
  2122. {
  2123. ulRef = pIStorageOpen->Release();
  2124. DH_ASSERT(0 == ulRef);
  2125. }
  2126. // Delete temp string
  2127. if(NULL != pOleStrTemp)
  2128. {
  2129. delete pOleStrTemp;
  2130. pOleStrTemp = NULL;
  2131. }
  2132. // Delete the docfile on disk
  2133. if((S_OK == hr) && (NULL != pRootDocFileName))
  2134. {
  2135. if(FALSE == DeleteFile(pRootDocFileName))
  2136. {
  2137. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2138. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2139. }
  2140. }
  2141. // Delete Chance docfile tree
  2142. if(NULL != pTestChanceDF)
  2143. {
  2144. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  2145. pTestChanceDF->GetChanceDFRoot());
  2146. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  2147. delete pTestChanceDF;
  2148. pTestChanceDF = NULL;
  2149. }
  2150. // Delete Virtual docfile tree
  2151. if(NULL != pTestVirtualDF)
  2152. {
  2153. if(NULL != pVirtualDFRoot)
  2154. {
  2155. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  2156. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  2157. }
  2158. delete pTestVirtualDF;
  2159. pTestVirtualDF = NULL;
  2160. }
  2161. // Delete temp string
  2162. if(NULL != pRootDocFileName)
  2163. {
  2164. delete pRootDocFileName;
  2165. pRootDocFileName = NULL;
  2166. }
  2167. // Stop logging the test
  2168. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_106 finished")) );
  2169. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2170. return hr;
  2171. }
  2172. //----------------------------------------------------------------------------
  2173. //
  2174. // Test: DFTEST_107
  2175. //
  2176. // Synopsis: A random root DF is created with STGM_SIMPLE flag and tests done
  2177. // on it. STGM_SIMPLE mode can only be specified with STGM_CREATE,
  2178. // STGM_READWRITE, STGM_SHARE_EXCLUSIVE flags. There is no support
  2179. // for substorages. Each stream is atleast 4096 bytes in length, and
  2180. // access to streams follow a linear pattern, i.e. once a stream is
  2181. // released, it can't be opened or read/written again. The following
  2182. // IStorage methods: QueryInterface, AddRef, Release, CreateStream,
  2183. // SetClass, Commit are supported. SetElementTimes is supported with
  2184. // NULL name, allowing applications to set time on root storage in
  2185. // simple mode. Supported IStream methods are QueryInterface, AddRef,
  2186. // Release, SetSize, Read, Write, Seek. All the other methods return
  2187. // STG_E_INVALIDFUNCTION.
  2188. // The test verifies the above restrictions on DocFile if STGM_
  2189. // SIMPLE is specified in creation of a docfile.
  2190. //
  2191. // Arguments:[argc]
  2192. // [argv]
  2193. //
  2194. // Returns: HRESULT
  2195. //
  2196. // History: 9-Aug-1996 NarindK Created.
  2197. // 4-Nov-1996 BogdanT Mac porting
  2198. //
  2199. // Notes: This test runs in direct mode
  2200. //
  2201. // THIS TEST HAS A MEMORY LEAK IN OLE CODE: BUG 52975
  2202. //
  2203. // New Test Notes:
  2204. // 1. Old File: STDDOC.CXX
  2205. // 2. Old name of test : TestStdDocFile Test
  2206. // New Name of test : DFTEST_107
  2207. // 3. To run the test, do the following at command prompt.
  2208. // a. stgbase /seed:0 /t:DFTEST-107
  2209. //
  2210. // BUGNOTE: Conversion: DFTEST-107
  2211. //
  2212. //-----------------------------------------------------------------------------
  2213. HRESULT DFTEST_107(ULONG ulSeed)
  2214. {
  2215. #ifdef _MAC // Simple mode not ported yet; check with the developers
  2216. // and remove this when ready
  2217. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!Simple mode DFTEST_107 crashes.")) );
  2218. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!To be investigated")) );
  2219. return E_NOTIMPL;
  2220. #else
  2221. HRESULT hr = S_OK;
  2222. ChanceDF *pTestChanceDF = NULL;
  2223. VirtualDF *pTestVirtualDF = NULL;
  2224. VirtualCtrNode *pVirtualDFRoot = NULL;
  2225. VirtualStmNode *pvsnRootNewChildStream = NULL;
  2226. VirtualStmNode *pvsnRootMoreStream = NULL;
  2227. LPTSTR pRootDocFileName = NULL;
  2228. LPTSTR pRootNewChildStmName = NULL;
  2229. LPTSTR pRootMoreStmName = NULL;
  2230. DG_STRING *pdgu = NULL;
  2231. DG_INTEGER *pdgi = NULL;
  2232. USHORT usErr = 0;
  2233. LPSTORAGE pStgRoot = NULL;
  2234. DWORD dwChildMode = STGM_READWRITE |
  2235. STGM_SHARE_EXCLUSIVE;
  2236. LPSTORAGE pStgChild = NULL;
  2237. LPSTREAM pStmChild = NULL;
  2238. LPSTREAM pStmChildTest = NULL;
  2239. OLECHAR ocName[] = {'f', 'o', 'o'};
  2240. LPENUMSTATSTG penumWalk = NULL;
  2241. ULONG cb = 0;
  2242. ULONG culWritten = 0;
  2243. ULONG culRead = 0;
  2244. ULONG cRandomMinSize = 256;
  2245. ULONG cRandomMaxSize = 2048;
  2246. ULONG cNum = 0;
  2247. ULONG cRandomMinNumStms = 3;
  2248. ULONG cRandomMaxNumStms = 6;
  2249. LPTSTR ptcsBuffer = NULL;
  2250. LPTSTR ptcsSimpReadBuffer = NULL;
  2251. LPTSTR ptcsReadBuffer = NULL;
  2252. BOOL fRet = FALSE;
  2253. FILETIME cNewFileTime = {dwDefLowDateTime,
  2254. dwDefHighDateTime};
  2255. BOOL fPass = TRUE;
  2256. ULONG ulSizeOfStream = 0;
  2257. ULONG cMemStg = 0;
  2258. ULONG cMemStm = 0;
  2259. ULONG cActStg = 0;
  2260. ULONG cActStm = 0;
  2261. DWCRCSTM dwMemCRC;
  2262. DWCRCSTM dwActCRC;
  2263. SYSTEMTIME cCurrentSystemTime;
  2264. ULARGE_INTEGER uliTest;
  2265. STATSTG statStg;
  2266. FILETIME cFileTime;
  2267. CDFD cdfd;
  2268. LARGE_INTEGER liStreamPos;
  2269. ULARGE_INTEGER uli;
  2270. // Not for 2phase. Bail.
  2271. // Test needs STGM_CREATE bit which invalidates 2 phase test
  2272. if (DoingDistrib () || DoingConversion ())
  2273. {
  2274. return S_OK;
  2275. }
  2276. dwMemCRC.dwCRCSum = dwActCRC.dwCRCSum = 0;
  2277. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_107"));
  2278. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2279. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_107 started.")) );
  2280. DH_TRACE((
  2281. DH_LVL_TRACE1,
  2282. TEXT("Root created /w STGM_SIMPLE, chk IStorage/IStream restrict")));
  2283. if(S_OK == hr)
  2284. {
  2285. // Create a new DataGen object to create random UNICODE strings.
  2286. pdgu = new(NullOnFail) DG_STRING (ulSeed);
  2287. if (NULL == pdgu)
  2288. {
  2289. hr = E_OUTOFMEMORY;
  2290. }
  2291. else
  2292. {
  2293. //want to create only one seed. Once that has been done,
  2294. //use what we created from now on.
  2295. ulSeed = pdgu->GetSeed();
  2296. }
  2297. }
  2298. if (S_OK == hr)
  2299. {
  2300. // Generate random name for root
  2301. hr = GenerateRandomName(
  2302. pdgu,
  2303. MINLENGTH,
  2304. MAXLENGTH,
  2305. &pRootDocFileName);
  2306. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2307. }
  2308. if(S_OK == hr)
  2309. {
  2310. cdfd.cDepthMin = 0;
  2311. cdfd.cDepthMax = 0;
  2312. cdfd.cStgMin = 0;
  2313. cdfd.cStgMax = 0;
  2314. cdfd.cStmMin = 0;
  2315. cdfd.cStmMax = 0;
  2316. cdfd.cbStmMin = 0;
  2317. cdfd.cbStmMax = 0;
  2318. cdfd.ulSeed = ulSeed;
  2319. cdfd.dwRootMode = STGM_CREATE |
  2320. STGM_DIRECT |
  2321. STGM_READWRITE |
  2322. STGM_SHARE_EXCLUSIVE |
  2323. STGM_SIMPLE;
  2324. hr = CreateTestDocfile (&cdfd,
  2325. pRootDocFileName,
  2326. &pVirtualDFRoot,
  2327. &pTestVirtualDF,
  2328. &pTestChanceDF);
  2329. DH_HRCHECK (hr, TEXT("CreateTestDocfile"));
  2330. }
  2331. if(S_OK == hr)
  2332. {
  2333. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  2334. if(NULL == pStgRoot)
  2335. {
  2336. DH_TRACE((
  2337. DH_LVL_ERROR,
  2338. TEXT("VirtualCtrNode::GetIStoragePointer() failed to return IStorage"),
  2339. hr));
  2340. hr = E_FAIL;
  2341. }
  2342. }
  2343. // These interfaces must fail for IStorage interface if the root docfile
  2344. // is opened with STGM_SIMPLE flag.
  2345. if(S_OK == hr)
  2346. {
  2347. TestUnsupportedInterface(
  2348. pStgRoot,
  2349. TEXT("IStorage::CreateStorage"),
  2350. CreateStorage(ocName, dwChildMode|STGM_CREATE, 0, 0, &pStgChild),
  2351. hr);
  2352. }
  2353. if(S_OK == hr)
  2354. {
  2355. TestUnsupportedInterface(
  2356. pStgRoot,
  2357. TEXT("IStorage::OpenStream"),
  2358. OpenStream(ocName, NULL, dwChildMode, 0, &pStmChild),
  2359. hr);
  2360. }
  2361. if(S_OK == hr)
  2362. {
  2363. TestUnsupportedInterface(
  2364. pStgRoot,
  2365. TEXT("IStorage::OpenStorage"),
  2366. OpenStorage(ocName, NULL, dwChildMode, NULL, 0, &pStgChild),
  2367. hr);
  2368. }
  2369. if(S_OK == hr)
  2370. {
  2371. TestUnsupportedInterface(
  2372. pStgRoot,
  2373. TEXT("IStorage::MoveElementTo"),
  2374. MoveElementTo(ocName, pStgChild, ocName, STGMOVE_MOVE),
  2375. hr);
  2376. }
  2377. if(S_OK == hr)
  2378. {
  2379. TestUnsupportedInterface(
  2380. pStgRoot,
  2381. TEXT("IStorage::EnumElements"),
  2382. EnumElements(0, NULL, 0, &penumWalk),
  2383. hr);
  2384. }
  2385. if(S_OK == hr)
  2386. {
  2387. TestUnsupportedInterface(
  2388. pStgRoot,
  2389. TEXT("IStorage::DestroyElement"),
  2390. DestroyElement(ocName),
  2391. hr);
  2392. }
  2393. if(S_OK == hr)
  2394. {
  2395. TestUnsupportedInterface(
  2396. pStgRoot,
  2397. TEXT("IStorage::RenameElement"),
  2398. RenameElement(ocName, ocName),
  2399. hr);
  2400. }
  2401. if(S_OK == hr)
  2402. {
  2403. TestUnsupportedInterface(
  2404. pStgRoot,
  2405. TEXT("IStorage::SetStateBits"),
  2406. SetStateBits(0, 0),
  2407. hr);
  2408. }
  2409. #ifndef WINNT
  2410. // NT5 spec change. This is now supported on NT5.
  2411. if(S_OK == hr)
  2412. {
  2413. TestUnsupportedInterface(
  2414. pStgRoot,
  2415. TEXT("IStorage::Stat"),
  2416. Stat(&statStg,STATFLAG_NONAME),
  2417. hr);
  2418. }
  2419. #endif
  2420. if(S_OK == hr)
  2421. {
  2422. TestUnsupportedInterface(
  2423. pStgRoot,
  2424. TEXT("IStorage::Revert"),
  2425. Revert(),
  2426. hr);
  2427. }
  2428. if(S_OK == hr)
  2429. {
  2430. TestUnsupportedInterface(
  2431. pStgRoot,
  2432. TEXT("IStorage::SetElementTimes with Non-NULL name"),
  2433. SetElementTimes(ocName, &cFileTime, &cFileTime, &cFileTime),
  2434. hr);
  2435. }
  2436. if(S_OK == hr)
  2437. {
  2438. TestUnsupportedInterface(
  2439. pStgRoot,
  2440. TEXT("IStorage::CopyTo"),
  2441. CopyTo(NULL, NULL, NULL, pStgChild),
  2442. hr);
  2443. }
  2444. // Set Element time with NULL name which should pass for STGM_SIMPLE mode.
  2445. if(S_OK == hr)
  2446. {
  2447. GetSystemTime(&cCurrentSystemTime);
  2448. fRet = SystemTimeToFileTime(&cCurrentSystemTime, &cNewFileTime);
  2449. DH_ASSERT(TRUE == fRet);
  2450. DH_ASSERT(dwDefLowDateTime != cNewFileTime.dwLowDateTime);
  2451. DH_ASSERT(dwDefHighDateTime != cNewFileTime.dwHighDateTime);
  2452. hr = pStgRoot->SetElementTimes(
  2453. NULL,
  2454. &cNewFileTime,
  2455. &cNewFileTime,
  2456. &cNewFileTime);
  2457. DH_HRCHECK(hr, TEXT("IStorage::SetElementTimes with NULL name")) ;
  2458. }
  2459. // Now create a stream in it with size less than 4096 bytes. If fewer
  2460. // than 4096 bytes are written into the stream, by the time stream is
  2461. // released, it would have extended to 4096 bytes.
  2462. if(S_OK == hr)
  2463. {
  2464. // Generate random name for stream
  2465. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  2466. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2467. }
  2468. if(S_OK == hr)
  2469. {
  2470. // Create a new DataGen object to create random integers.
  2471. pdgi = new(NullOnFail) DG_INTEGER(ulSeed);
  2472. if (NULL == pdgi)
  2473. {
  2474. hr = E_OUTOFMEMORY;
  2475. }
  2476. DH_HRCHECK(hr, TEXT("new")) ;
  2477. }
  2478. if (S_OK == hr)
  2479. {
  2480. // Generate random size for stream.
  2481. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  2482. if (DG_RC_SUCCESS != usErr)
  2483. {
  2484. hr = E_FAIL;
  2485. }
  2486. DH_HRCHECK(hr, TEXT("pdgi->Generate")) ;
  2487. }
  2488. if(S_OK == hr)
  2489. {
  2490. hr = AddStream(
  2491. pTestVirtualDF,
  2492. pVirtualDFRoot,
  2493. pRootNewChildStmName,
  2494. cb,
  2495. STGM_READWRITE |
  2496. STGM_SHARE_EXCLUSIVE,
  2497. &pvsnRootNewChildStream);
  2498. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2499. }
  2500. // With above stream size is set to less than 4096. But as per STGM_SIMPLE,
  2501. // the size would extend to 4096 by them time stream is released.
  2502. if(S_OK == hr)
  2503. {
  2504. hr = GenerateRandomString(pdgu, cb, cb, &ptcsBuffer);
  2505. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  2506. }
  2507. if (S_OK == hr)
  2508. {
  2509. hr = pvsnRootNewChildStream->Write(
  2510. ptcsBuffer,
  2511. cb,
  2512. &culWritten);
  2513. DH_HRCHECK(hr, TEXT("VSN::Write in STGM_SIMPLE")) ;
  2514. }
  2515. // Calculate the CRC for stream data
  2516. if(S_OK == hr)
  2517. {
  2518. hr = CalculateInMemoryCRCForStm(
  2519. pvsnRootNewChildStream,
  2520. ptcsBuffer,
  2521. cb,
  2522. &dwMemCRC);
  2523. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm")) ;
  2524. }
  2525. // Check the read in STGM_SIMPLE mode.
  2526. // Allocate a buffer of required size
  2527. if (S_OK == hr)
  2528. {
  2529. ptcsSimpReadBuffer = new TCHAR [cb];
  2530. if (NULL == ptcsSimpReadBuffer)
  2531. {
  2532. hr = E_OUTOFMEMORY;
  2533. }
  2534. DH_HRCHECK(hr, TEXT("new")) ;
  2535. }
  2536. if(S_OK == hr)
  2537. {
  2538. // First seek to beginning of stream in STGM_SIMPLE mode.
  2539. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2540. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  2541. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek in STGM_SIMPLE")) ;
  2542. }
  2543. if (S_OK == hr)
  2544. {
  2545. memset(ptcsSimpReadBuffer, '\0', cb*sizeof(TCHAR));
  2546. hr = pvsnRootNewChildStream->Read(
  2547. ptcsSimpReadBuffer,
  2548. cb,
  2549. &culRead);
  2550. DH_ASSERT(culRead == cb);
  2551. DH_HRCHECK(hr, TEXT("VirtualStmNode::Read in STGM_SIMPLE")) ;
  2552. }
  2553. // Test unsupported interfaces for IStream interface.
  2554. if(S_OK == hr)
  2555. {
  2556. pStmChild = pvsnRootNewChildStream->GetIStreamPointer();
  2557. if(NULL == pStmChild)
  2558. {
  2559. DH_TRACE((
  2560. DH_LVL_ERROR,
  2561. TEXT("VirtualStmNode->GetIStreamPointer() failed to return IStream"),
  2562. hr));
  2563. hr = E_FAIL;
  2564. }
  2565. }
  2566. if(S_OK == hr)
  2567. {
  2568. TestUnsupportedInterface(
  2569. pStmChild,
  2570. TEXT("IStream::CopyTo"),
  2571. CopyTo(pStmChildTest, uliTest, NULL, NULL),
  2572. hr);
  2573. }
  2574. // Don't test IStream::Commit, since that returns STG_E_NOTIMPLEMENTED,
  2575. // rather than STG_E_INVALIDFUNCTION
  2576. if(S_OK == hr)
  2577. {
  2578. TestUnsupportedInterface(
  2579. pStmChild,
  2580. TEXT("IStream::Revert"),
  2581. Revert(),
  2582. hr);
  2583. }
  2584. #ifndef WINNT
  2585. // NT5 spec change. This is now supported on NT5.
  2586. if(S_OK == hr)
  2587. {
  2588. TestUnsupportedInterface(
  2589. pStmChild,
  2590. TEXT("IStream::Stat"),
  2591. Stat(&statStg, STATFLAG_NONAME),
  2592. hr);
  2593. }
  2594. #endif
  2595. if(S_OK == hr)
  2596. {
  2597. TestUnsupportedInterface(
  2598. pStmChild,
  2599. TEXT("IStream::Clone"),
  2600. Clone(&pStmChildTest),
  2601. hr);
  2602. }
  2603. if(S_OK == hr)
  2604. {
  2605. TestUnsupportedInterface(
  2606. pStmChild,
  2607. TEXT("IStream::LockRegion"),
  2608. LockRegion(uliTest, uliTest, 0),
  2609. hr);
  2610. }
  2611. if(S_OK == hr)
  2612. {
  2613. TestUnsupportedInterface(
  2614. pStmChild,
  2615. TEXT("IStream::UnlockRegion"),
  2616. UnlockRegion(uliTest, uliTest, 0),
  2617. hr);
  2618. }
  2619. // Close child stream.
  2620. if (S_OK == hr)
  2621. {
  2622. hr = pvsnRootNewChildStream->Close();
  2623. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  2624. }
  2625. // Check the linear pattern of stream. Make sure that the stream can't be
  2626. // opened or be read , written again now.
  2627. if (S_OK == hr)
  2628. {
  2629. hr = pvsnRootNewChildStream->Open(NULL, dwChildMode, 0);
  2630. hr = DH_HRERRORCHECK (hr, STG_E_INVALIDFUNCTION, TEXT("VirtualStmNode::Open"));
  2631. }
  2632. // Create a few more streams in root storage. This being done to test
  2633. // additonal OLE code which occurs for more number of streams
  2634. if (S_OK == hr)
  2635. {
  2636. //calulate random number of streams to be created
  2637. usErr = pdgi->Generate(&cNum, cRandomMinNumStms, cRandomMaxNumStms);
  2638. if (DG_RC_SUCCESS != usErr)
  2639. {
  2640. hr = E_FAIL;
  2641. }
  2642. DH_HRCHECK (hr, TEXT("pdgi::Generate"));
  2643. }
  2644. while((cNum > 0) && (S_OK == hr))
  2645. {
  2646. cNum--;
  2647. if(S_OK == hr)
  2648. {
  2649. // Generate random name for stream
  2650. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootMoreStmName);
  2651. DH_HRCHECK (hr, TEXT("GenerateRandomName"));
  2652. }
  2653. if(S_OK == hr)
  2654. {
  2655. hr = AddStream(
  2656. pTestVirtualDF,
  2657. pVirtualDFRoot,
  2658. pRootMoreStmName,
  2659. 0,
  2660. STGM_READWRITE |
  2661. STGM_SHARE_EXCLUSIVE,
  2662. &pvsnRootMoreStream);
  2663. DH_HRCHECK (hr, TEXT("AddStream"));
  2664. }
  2665. if (S_OK == hr)
  2666. {
  2667. hr = pvsnRootMoreStream->Close();
  2668. DH_HRCHECK (hr, TEXT("IStream::Close"));
  2669. }
  2670. if(NULL != pRootMoreStmName)
  2671. {
  2672. delete pRootMoreStmName;
  2673. pRootMoreStmName = NULL;
  2674. }
  2675. }
  2676. if(S_OK == hr)
  2677. {
  2678. DH_TRACE((
  2679. DH_LVL_TRACE1,
  2680. TEXT("VirtualStmNode::AddStream (s) completed successfully.")));
  2681. }
  2682. else
  2683. {
  2684. DH_TRACE((
  2685. DH_LVL_ERROR,
  2686. TEXT("VirtualStmNode::AddStream (s) not successful, hr=0x%lx."),
  2687. hr));
  2688. }
  2689. // Commit Root Docfile.
  2690. if (S_OK == hr)
  2691. {
  2692. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2693. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2694. }
  2695. // Enumerate In Memory DocFile to count no of stgs/stms for verification
  2696. // later
  2697. if (S_OK == hr)
  2698. {
  2699. hr = EnumerateInMemoryDocFile(pVirtualDFRoot, &cMemStg, &cMemStm);
  2700. DH_HRCHECK(hr, TEXT("EnumerateInMemoryDocFile"));
  2701. }
  2702. // Close Root Docfile.
  2703. if (S_OK == hr)
  2704. {
  2705. hr = pVirtualDFRoot->Close();
  2706. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2707. }
  2708. // Open the root docfile without STGM_SIMPLE mode, i.e open in STGM_DIRECT|
  2709. // STGM_READWRITE | STGM_SHARE_EXCLUSIVE mode.
  2710. if (S_OK == hr)
  2711. {
  2712. hr = pVirtualDFRoot->Open(
  2713. NULL,
  2714. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2715. NULL,
  2716. 0);
  2717. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2718. }
  2719. // Open the stream and Verify the CRC of the stream 1 that was calculated
  2720. // before.
  2721. if (S_OK == hr)
  2722. {
  2723. hr = pvsnRootNewChildStream->Open(NULL, dwChildMode, 0);
  2724. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  2725. }
  2726. // Calculate CRC on stream for the number of bytes that were written during
  2727. // the time the root was opened in STGM_SIMPLE mode. Since the stream size
  2728. // has got extended, the CRC on total stream would be different, since the
  2729. // fill bytes would be present in extended size. Garbage tests verify to
  2730. // see that fill bytes are all zero's not checked here.
  2731. // Allocate a buffer of required size
  2732. if (S_OK == hr)
  2733. {
  2734. ptcsReadBuffer = new TCHAR [cb];
  2735. if (NULL == ptcsReadBuffer)
  2736. {
  2737. hr = E_OUTOFMEMORY;
  2738. }
  2739. DH_HRCHECK(hr, TEXT("new")) ;
  2740. }
  2741. if (S_OK == hr)
  2742. {
  2743. memset(ptcsReadBuffer, '\0', cb*sizeof(TCHAR));
  2744. culRead = 0;
  2745. hr = pvsnRootNewChildStream->Read(
  2746. ptcsReadBuffer,
  2747. cb,
  2748. &culRead);
  2749. DH_ASSERT(culRead == cb);
  2750. DH_HRCHECK(hr, TEXT("VirtualStmNode::Read")) ;
  2751. }
  2752. if(S_OK == hr)
  2753. {
  2754. hr = CalculateInMemoryCRCForStm(
  2755. pvsnRootNewChildStream,
  2756. ptcsReadBuffer,
  2757. cb,
  2758. &dwActCRC);
  2759. DH_HRCHECK(hr, TEXT("CalculateInMmeoryCRCForStm")) ;
  2760. }
  2761. // Compare CRC's
  2762. if(S_OK == hr)
  2763. {
  2764. if(dwMemCRC.dwCRCSum == dwActCRC.dwCRCSum)
  2765. {
  2766. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's of stream match as exp.")));
  2767. }
  2768. else
  2769. {
  2770. DH_TRACE((DH_LVL_ERROR, TEXT("CRC's of stream don't match as exp.")));
  2771. fPass = FALSE;
  2772. }
  2773. }
  2774. // Verify the size of stream is 4096 bytes.
  2775. // Now seek to the current stream to end of stream
  2776. if(S_OK == hr)
  2777. {
  2778. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2779. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  2780. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2781. ulSizeOfStream = ULIGetLow(uli);
  2782. }
  2783. if(S_OK == hr)
  2784. {
  2785. if(4096 == ulSizeOfStream)
  2786. {
  2787. DH_TRACE((
  2788. DH_LVL_TRACE1,
  2789. TEXT("Size of stream extended to 4096 bytes as exp")));
  2790. }
  2791. else
  2792. {
  2793. DH_TRACE((
  2794. DH_LVL_ERROR,
  2795. TEXT("Size of stream not extended to 4096 bytes as exp")));
  2796. fPass = FALSE;
  2797. }
  2798. }
  2799. // Close the stream
  2800. if (S_OK == hr)
  2801. {
  2802. hr = pvsnRootNewChildStream->Close();
  2803. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  2804. }
  2805. // Check times set from SetElementTimes. BUGBUG: On FAT, the timestamp
  2806. // resolution is not fine enough to make dwLowDateTimeStamp meaningful,
  2807. // so verify with dwHighDataTimeStamp only.
  2808. // Stat on Root Storage
  2809. if(S_OK == hr)
  2810. {
  2811. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  2812. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  2813. }
  2814. if(S_OK == hr)
  2815. {
  2816. if(cNewFileTime.dwHighDateTime == statStg.mtime.dwHighDateTime)
  2817. {
  2818. DH_TRACE((
  2819. DH_LVL_TRACE1,
  2820. TEXT("SetElementTime and STATSTG.mtime match as exp")));
  2821. }
  2822. else
  2823. {
  2824. DH_TRACE((
  2825. DH_LVL_ERROR,
  2826. TEXT("SetElementTime and STATSTG.mtime don't match as exp")));
  2827. fPass = FALSE;
  2828. }
  2829. }
  2830. // Enumerate Actual DocFile to count no of stgs/stms for verification
  2831. // with in memory enumerated stgs and stms
  2832. if (S_OK == hr)
  2833. {
  2834. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  2835. DH_ASSERT(NULL != pStgRoot);
  2836. if (NULL == pStgRoot)
  2837. {
  2838. DH_TRACE((
  2839. DH_LVL_ERROR,
  2840. TEXT("VirtualCtrNode::GetIStoragePointer() failed to return IStorage"),
  2841. hr));
  2842. hr = E_FAIL;
  2843. }
  2844. }
  2845. if (S_OK == hr)
  2846. {
  2847. hr = EnumerateDiskDocFile(pStgRoot, VERIFY_SHORT, &cActStg, &cActStm);
  2848. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile"));
  2849. }
  2850. // Verify structure of DocFile
  2851. if(S_OK == hr)
  2852. {
  2853. if((cActStg == cMemStg) && (cActStm == cMemStm))
  2854. {
  2855. DH_TRACE((DH_LVL_TRACE1, TEXT("DocFile enumeration passed as exp")));
  2856. }
  2857. else
  2858. {
  2859. DH_TRACE((DH_LVL_ERROR, TEXT("DocFile enumeration failed unexp")));
  2860. fPass = FALSE;
  2861. }
  2862. }
  2863. // Close the root.
  2864. if (S_OK == hr)
  2865. {
  2866. hr = pVirtualDFRoot->Close();
  2867. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2868. }
  2869. // if everything goes well, log test as passed else failed.
  2870. if ((S_OK == hr) && (TRUE == fPass))
  2871. {
  2872. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_107 passed.")) );
  2873. }
  2874. else
  2875. {
  2876. DH_LOG((
  2877. LOG_FAIL,
  2878. TEXT("Test variation DFTEST_107 failed, hr=0x%lx, fPass=%d."),
  2879. hr,
  2880. fPass));
  2881. // test failed. make it look like it failed.
  2882. hr = FirstError (hr, E_FAIL);
  2883. }
  2884. // Cleanup
  2885. CleanupTestDocfile (&pVirtualDFRoot, &pTestVirtualDF, &pTestChanceDF, S_OK==hr);
  2886. // Delete strings
  2887. if(NULL != pRootDocFileName)
  2888. {
  2889. delete pRootDocFileName;
  2890. pRootDocFileName = NULL;
  2891. }
  2892. if(NULL != pRootNewChildStmName)
  2893. {
  2894. delete pRootNewChildStmName;
  2895. pRootNewChildStmName = NULL;
  2896. }
  2897. if(NULL != ptcsBuffer)
  2898. {
  2899. delete [] ptcsBuffer;
  2900. ptcsBuffer = NULL;
  2901. }
  2902. if(NULL != ptcsSimpReadBuffer)
  2903. {
  2904. delete [] ptcsSimpReadBuffer;
  2905. ptcsSimpReadBuffer = NULL;
  2906. }
  2907. if(NULL != ptcsReadBuffer)
  2908. {
  2909. delete [] ptcsReadBuffer;
  2910. ptcsReadBuffer = NULL;
  2911. }
  2912. // Delete data generators
  2913. if(NULL != pdgi)
  2914. {
  2915. delete pdgi;
  2916. pdgi = NULL;
  2917. }
  2918. if(NULL != pdgu)
  2919. {
  2920. delete pdgu;
  2921. pdgu = NULL;
  2922. }
  2923. // Stop logging the test
  2924. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_107 finished")) );
  2925. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2926. return hr;
  2927. #endif //_MAC
  2928. }
  2929. //----------------------------------------------------------------------------
  2930. //
  2931. // Test: DFTEST_108
  2932. //
  2933. // Synopsis: A random root DF is created with STGM_SIMPLE flag. Illegal
  2934. // operations are done on that DocFile permitted methods.
  2935. //
  2936. // Arguments:[argc]
  2937. // [argv]
  2938. //
  2939. // Returns: HRESULT
  2940. //
  2941. // History: 12-Aug-1996 NarindK Created.
  2942. // 04-Nov-1996 BogdanT Mac porting
  2943. //
  2944. // Notes: This test runs in direct mode
  2945. //
  2946. // THIS TEST GPF's IN OLE CODE: BUG 53142, BUG 53615 - fixed 6/97
  2947. //
  2948. // New Test Notes:
  2949. // 1. Old File: -none-
  2950. // 2. Old name of test : -none-
  2951. // New Name of test : DFTEST_108
  2952. // 3. To run the test, do the following at command prompt.
  2953. // a. stgbase /seed:0 /t:DFTEST-108
  2954. //
  2955. // BUGNOTE: Conversion: DFTEST-108 NO
  2956. //
  2957. //-----------------------------------------------------------------------------
  2958. HRESULT DFTEST_108(ULONG ulSeed)
  2959. {
  2960. #ifdef _MAC // Simple mode not ported yet; check with the developers
  2961. // and remove this when ready
  2962. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!Simple mode DFTEST_108 crashes.")) );
  2963. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!To be investigated")) );
  2964. return E_NOTIMPL;
  2965. #elif defined (_CHICAGO_) || (_WIN32_WINNT < 0x500)
  2966. DH_TRACE ((DH_LVL_ALWAYS,
  2967. TEXT("DCOM has not picked up the new bits yet. Failure hardcoded in test")));
  2968. DH_LOG ((LOG_FAIL,
  2969. TEXT("DFTEST-108 Failed. DCOM not updated in chicago. Bugs# 53142,53615")));
  2970. return E_FAIL;
  2971. #else
  2972. HRESULT hr = S_OK;
  2973. HRESULT hr2 = S_OK;
  2974. ChanceDF *pTestChanceDF = NULL;
  2975. VirtualDF *pTestVirtualDF = NULL;
  2976. VirtualCtrNode *pVirtualDFRoot = NULL;
  2977. VirtualStmNode *pvsnRootNewChildStream = NULL;
  2978. LPTSTR pRootDocFileName = NULL;
  2979. LPTSTR pRootNewChildStmName = NULL;
  2980. LPOLESTR poszRootNewChildStmName = NULL;
  2981. DG_STRING *pdgu = NULL;
  2982. USHORT usErr = 0;
  2983. LPSTORAGE pStgRoot = NULL;
  2984. LPSTREAM pStmChild = NULL;
  2985. ULONG ulRef = 0;
  2986. CDFD cdfd;
  2987. // Not for 2phase. Bail.
  2988. if (DoingDistrib ())
  2989. {
  2990. return S_OK;
  2991. }
  2992. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_108"));
  2993. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2994. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_108 started.")) );
  2995. DH_TRACE((
  2996. DH_LVL_TRACE1,
  2997. TEXT("Attempt illegal tests on STGM_SIMPLE docfile")));
  2998. if(S_OK == hr)
  2999. {
  3000. // Create a new DataGen object to create random strings.
  3001. pdgu = new(NullOnFail) DG_STRING(ulSeed);
  3002. if (NULL == pdgu)
  3003. {
  3004. hr = E_OUTOFMEMORY;
  3005. }
  3006. }
  3007. if(S_OK == hr)
  3008. {
  3009. // Generate random name for root
  3010. hr = GenerateRandomName(
  3011. pdgu,
  3012. MINLENGTH,
  3013. MAXLENGTH,
  3014. &pRootDocFileName);
  3015. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3016. }
  3017. // Create the new ChanceDocFile tree that would consist of chance nodes.
  3018. if (S_OK == hr)
  3019. {
  3020. pTestChanceDF = new ChanceDF();
  3021. if(NULL == pTestChanceDF)
  3022. {
  3023. hr = E_OUTOFMEMORY;
  3024. }
  3025. }
  3026. if(S_OK == hr)
  3027. {
  3028. cdfd.cDepthMin = 0;
  3029. cdfd.cDepthMax = 0;
  3030. cdfd.cStgMin = 0;
  3031. cdfd.cStgMax = 0;
  3032. cdfd.cStmMin = 0;
  3033. cdfd.cStmMax = 0;
  3034. cdfd.cbStmMin = 0;
  3035. cdfd.cbStmMax = 0;
  3036. cdfd.ulSeed = ulSeed;
  3037. cdfd.dwRootMode = STGM_CREATE |
  3038. STGM_DIRECT |
  3039. STGM_READWRITE |
  3040. STGM_SHARE_EXCLUSIVE |
  3041. STGM_SIMPLE;
  3042. hr = pTestChanceDF->Create(&cdfd, pRootDocFileName);
  3043. DH_HRCHECK(hr, TEXT("pTestChanceDF->Create"));
  3044. }
  3045. if (S_OK == hr)
  3046. {
  3047. pTestVirtualDF = new VirtualDF();
  3048. if(NULL == pTestVirtualDF)
  3049. {
  3050. hr = E_OUTOFMEMORY;
  3051. }
  3052. }
  3053. if (S_OK == hr)
  3054. {
  3055. hr = pTestVirtualDF->GenerateVirtualDF(
  3056. pTestChanceDF,
  3057. &pVirtualDFRoot);
  3058. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  3059. }
  3060. if (S_OK == hr)
  3061. {
  3062. DH_TRACE((
  3063. DH_LVL_TRACE1,
  3064. TEXT("DocFile - Create - successfully created.")));
  3065. }
  3066. else
  3067. {
  3068. DH_TRACE((
  3069. DH_LVL_TRACE1,
  3070. TEXT("DocFile - Create - failed, hr=0x%lx."),
  3071. hr));
  3072. }
  3073. if(S_OK == hr)
  3074. {
  3075. // Get Root Storage pointer
  3076. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  3077. if(NULL == pStgRoot)
  3078. {
  3079. DH_LOG((LOG_INFO,
  3080. TEXT("pVirtualDFRoot->GetIStoragePointer failed to return IStorage")) );
  3081. hr = E_FAIL;
  3082. }
  3083. }
  3084. if(S_OK == hr)
  3085. {
  3086. // Generate random name for stream
  3087. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  3088. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3089. }
  3090. if(S_OK == hr)
  3091. {
  3092. // Convert stream name to OLECHAR
  3093. hr = TStringToOleString(pRootNewChildStmName, &poszRootNewChildStmName);
  3094. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3095. }
  3096. // Call CSimpStorage::CreateStream with valid paramter .
  3097. if(S_OK == hr)
  3098. {
  3099. hr = pStgRoot->CreateStream(
  3100. poszRootNewChildStmName,
  3101. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3102. 0,
  3103. 0,
  3104. &pStmChild);
  3105. DH_HRCHECK(hr, TEXT("CSimpStorage::CreateStream"));
  3106. if (S_OK == hr)
  3107. {
  3108. DH_TRACE((
  3109. DH_LVL_TRACE1,
  3110. TEXT("CSimpStorage:CreateStream passed as exp")));
  3111. }
  3112. else
  3113. {
  3114. DH_TRACE((
  3115. DH_LVL_TRACE1,
  3116. TEXT("CSimpStorage:CreateStream failed unexp,hr=0x%lx"),
  3117. hr));
  3118. }
  3119. }
  3120. // Call QueryInterface on IStream with invalid out parameter.
  3121. if(S_OK == hr)
  3122. {
  3123. hr = pStmChild->QueryInterface(IID_IStream, NULL);
  3124. if (STG_E_INVALIDPOINTER == hr)
  3125. {
  3126. DH_TRACE((
  3127. DH_LVL_TRACE1,
  3128. TEXT("CSimpStream:QueryInterface failed as exp, hr =0x%lx."),
  3129. hr));
  3130. hr = S_OK;
  3131. }
  3132. else
  3133. {
  3134. DH_TRACE((
  3135. DH_LVL_TRACE1,
  3136. TEXT("CSimpStream::QueryInterface didn't fail exp,hr=0x%lx"),
  3137. hr));
  3138. hr = E_FAIL;
  3139. }
  3140. }
  3141. // Release ptr, if reqd
  3142. if(NULL != pStmChild)
  3143. {
  3144. ulRef = pStmChild->Release();
  3145. DH_ASSERT(0 == ulRef);
  3146. pStmChild = NULL;
  3147. }
  3148. // delete these strings and create new ones so we get different
  3149. // names when trying to create things in the df (avoid name collisions)
  3150. delete pRootNewChildStmName;
  3151. pRootNewChildStmName = NULL;
  3152. delete poszRootNewChildStmName;
  3153. poszRootNewChildStmName = NULL;
  3154. if(S_OK == hr)
  3155. {
  3156. // Generate random name for stream
  3157. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  3158. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3159. }
  3160. if(S_OK == hr)
  3161. {
  3162. // Convert stream name to OLECHAR
  3163. hr = TStringToOleString(pRootNewChildStmName, &poszRootNewChildStmName);
  3164. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3165. }
  3166. // Call QueryInterface on CSimpStorage with invalid out parameter.
  3167. if(S_OK == hr)
  3168. {
  3169. hr = pStgRoot->QueryInterface(IID_IStorage, NULL);
  3170. if (STG_E_INVALIDPOINTER == hr)
  3171. {
  3172. DH_TRACE((DH_LVL_TRACE1,
  3173. TEXT("CSimpStorage:QueryInterface failed as exp, hr =0x%lx."),
  3174. hr));
  3175. hr = S_OK;
  3176. }
  3177. else
  3178. {
  3179. DH_TRACE((DH_LVL_TRACE1,
  3180. TEXT("CSimpStorage::QueryInterface didn't fail exp,hr=0x%lx"),
  3181. hr));
  3182. hr = E_FAIL;
  3183. }
  3184. }
  3185. // Call CSimpStorage::CreateStream with invalid out &pStmChild paramter .
  3186. if(S_OK == hr)
  3187. {
  3188. hr = pStgRoot->CreateStream(
  3189. poszRootNewChildStmName,
  3190. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3191. 0,
  3192. 0,
  3193. NULL);
  3194. DH_HRCHECK(hr, TEXT("CSimpStorage::CreateStream"));
  3195. if (STG_E_INVALIDPOINTER == hr)
  3196. {
  3197. DH_TRACE((
  3198. DH_LVL_TRACE1,
  3199. TEXT("CSimpStorage:CreateStream failed as exp, hr =0x%lx."),
  3200. hr));
  3201. hr = S_OK;
  3202. }
  3203. else
  3204. {
  3205. DH_TRACE((
  3206. DH_LVL_TRACE1,
  3207. TEXT("CSimpStorage:CreateStream didn't fail as exp,hr=0x%lx"),
  3208. hr));
  3209. hr = E_FAIL;
  3210. }
  3211. }
  3212. // Call CSimpStorage::CreateStream with NULL name .
  3213. if(S_OK == hr)
  3214. {
  3215. hr = pStgRoot->CreateStream(
  3216. NULL,
  3217. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3218. 0,
  3219. 0,
  3220. &pStmChild);
  3221. DH_HRCHECK(hr, TEXT("CSimpStorage::CreateStream"));
  3222. if (S_OK != hr)
  3223. {
  3224. DH_TRACE((
  3225. DH_LVL_TRACE1,
  3226. TEXT("CSimpStorage:CreateStream failed as exp, hr =0x%lx."),
  3227. hr));
  3228. hr = S_OK;
  3229. }
  3230. else
  3231. {
  3232. DH_TRACE((
  3233. DH_LVL_TRACE1,
  3234. TEXT("CSimpStorage:CreateStream didn't fail as exp,hr=0x%lx"),
  3235. hr));
  3236. hr = E_FAIL;
  3237. }
  3238. }
  3239. // Release ptr, if reqd
  3240. if(NULL != pStmChild)
  3241. {
  3242. ulRef = pStmChild->Release();
  3243. DH_ASSERT(0 == ulRef);
  3244. pStmChild = NULL;
  3245. }
  3246. // Call CSimpStorage::CreateStream with invalid reserved paramter .
  3247. if(S_OK == hr)
  3248. {
  3249. hr = pStgRoot->CreateStream(
  3250. poszRootNewChildStmName,
  3251. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3252. 999,
  3253. 999,
  3254. &pStmChild);
  3255. DH_HRCHECK(hr, TEXT("CSimpStorage::CreateStream"));
  3256. if (S_OK != hr)
  3257. {
  3258. DH_TRACE((
  3259. DH_LVL_TRACE1,
  3260. TEXT("CSimpStorage:CreateStream failed as exp, hr =0x%lx."),
  3261. hr));
  3262. hr = S_OK;
  3263. }
  3264. else
  3265. {
  3266. DH_TRACE((
  3267. DH_LVL_TRACE1,
  3268. TEXT("CSimpStorage:CreateStream didn't fail as exp,hr=0x%lx"),
  3269. hr));
  3270. hr = E_FAIL;
  3271. }
  3272. }
  3273. // Release ptr, if reqd
  3274. if(NULL != pStmChild)
  3275. {
  3276. ulRef = pStmChild->Release();
  3277. DH_ASSERT(0 == ulRef);
  3278. pStmChild = NULL;
  3279. }
  3280. // if everything goes well, log test as passed else failed.
  3281. if(S_OK == hr)
  3282. {
  3283. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_108 passed.")) );
  3284. }
  3285. else
  3286. {
  3287. DH_LOG((
  3288. LOG_FAIL,
  3289. TEXT("Test variation DFTEST_108 failed, hr=0x%lx."),
  3290. hr) );
  3291. }
  3292. // Cleanup
  3293. // Delete docfile on disk
  3294. if((S_OK == hr) && (NULL != pRootDocFileName))
  3295. {
  3296. if(FALSE == DeleteFile(pRootDocFileName))
  3297. {
  3298. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  3299. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  3300. }
  3301. }
  3302. // Delete Chance docfile tree for first DocFile
  3303. if(NULL != pTestChanceDF)
  3304. {
  3305. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  3306. pTestChanceDF->GetChanceDFRoot());
  3307. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  3308. delete pTestChanceDF;
  3309. pTestChanceDF = NULL;
  3310. }
  3311. // Delete Virtual docfile tree for first docfile
  3312. if(NULL != pTestVirtualDF)
  3313. {
  3314. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  3315. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  3316. delete pTestVirtualDF;
  3317. pTestVirtualDF = NULL;
  3318. }
  3319. // Delete strings
  3320. if(NULL != pRootDocFileName)
  3321. {
  3322. delete pRootDocFileName;
  3323. pRootDocFileName = NULL;
  3324. }
  3325. if(NULL != pRootNewChildStmName)
  3326. {
  3327. delete pRootNewChildStmName;
  3328. pRootNewChildStmName = NULL;
  3329. }
  3330. if(NULL != poszRootNewChildStmName)
  3331. {
  3332. delete poszRootNewChildStmName;
  3333. poszRootNewChildStmName = NULL;
  3334. }
  3335. // Delete data generators
  3336. if(NULL != pdgu)
  3337. {
  3338. delete pdgu;
  3339. pdgu = NULL;
  3340. }
  3341. // Stop logging the test
  3342. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_108 finished")) );
  3343. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3344. return hr;
  3345. #endif //_MAC
  3346. }
  3347. //----------------------------------------------------------------------------
  3348. //
  3349. // Test: DFTEST_109
  3350. //
  3351. // Synopsis: A simple mode root docfile is created, then add a random number
  3352. // of streams under the root storage, make sure the last stream's size
  3353. // is less than 4K(ministream), then commit and release the docfile.
  3354. //
  3355. // Arguments:[ulSeed]
  3356. //
  3357. // Returns: HRESULT
  3358. //
  3359. // Notes: This test runs in direct mode only
  3360. //
  3361. // History: 29-Oct-1996 JiminLi Created.
  3362. //
  3363. // Notes:
  3364. // To run the test, do the following at command prompt.
  3365. // stgbase /seed:0 /t:DFTEST-109
  3366. //
  3367. // BUGNOTE: Conversion: DFTEST-109 NO
  3368. //
  3369. //-----------------------------------------------------------------------------
  3370. HRESULT DFTEST_109(ULONG ulSeed)
  3371. {
  3372. #ifdef _MAC // Simple mode not ported yet; check with the developers
  3373. // and remove this when ready
  3374. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!Simple mode DFTEST_109 crashes.")) );
  3375. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!To be investigated")) );
  3376. return E_NOTIMPL;
  3377. #else
  3378. HRESULT hr = S_OK;
  3379. HRESULT hr2 = S_OK;
  3380. ChanceDF *pTestChanceDF = NULL;
  3381. VirtualDF *pTestVirtualDF = NULL;
  3382. VirtualCtrNode *pVirtualDFRoot = NULL;
  3383. VirtualStmNode **pvsnRootNewChildStream = NULL;
  3384. LPTSTR *pRootNewChildStmName = NULL;
  3385. ULONG culBytesWrite = 0;
  3386. DG_INTEGER *pdgi = NULL;
  3387. LPTSTR pRootDocFileName = NULL;
  3388. LPTSTR ptcsBuffer = NULL;
  3389. DG_STRING *pdgu = NULL;
  3390. DWORD dwRootMode = 0;
  3391. ULONG ulIndex = 0;
  3392. ULONG ulStmNum = 0;
  3393. ULONG ulMinStm = 2;
  3394. ULONG ulMaxStm = 5;
  3395. ULONG culWritten = 0;
  3396. USHORT usErr = 0;
  3397. CDFD cdfd;
  3398. // Not for 2phase. Bail.
  3399. if (DoingDistrib ())
  3400. {
  3401. return S_OK;
  3402. }
  3403. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("DFTEST_109"));
  3404. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3405. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_109 started.")) );
  3406. DH_TRACE((
  3407. DH_LVL_TRACE1,
  3408. TEXT("Test on adding a ministream into the simple root storage")));
  3409. if (S_OK == hr)
  3410. {
  3411. // Create a new DataGen object to create random UNICODE strings.
  3412. pdgu = new(NullOnFail) DG_STRING(ulSeed);
  3413. if (NULL == pdgu)
  3414. {
  3415. hr = E_OUTOFMEMORY;
  3416. }
  3417. }
  3418. if (S_OK == hr)
  3419. {
  3420. // Create a new DataGen object to create random integers.
  3421. pdgi = new(NullOnFail) DG_INTEGER(ulSeed);
  3422. if (NULL == pdgi)
  3423. {
  3424. hr = E_OUTOFMEMORY;
  3425. }
  3426. }
  3427. if(S_OK == hr)
  3428. {
  3429. // Generate random name for root
  3430. hr = GenerateRandomName(
  3431. pdgu,
  3432. MINLENGTH,
  3433. MAXLENGTH,
  3434. &pRootDocFileName);
  3435. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3436. }
  3437. // Create the new ChanceDocFile tree that would consist of chance nodes.
  3438. if (S_OK == hr)
  3439. {
  3440. pTestChanceDF = new ChanceDF();
  3441. if(NULL == pTestChanceDF)
  3442. {
  3443. hr = E_OUTOFMEMORY;
  3444. }
  3445. }
  3446. if(S_OK == hr)
  3447. {
  3448. cdfd.cDepthMin = 0;
  3449. cdfd.cDepthMax = 0;
  3450. cdfd.cStgMin = 0;
  3451. cdfd.cStgMax = 0;
  3452. cdfd.cStmMin = 0;
  3453. cdfd.cStmMax = 0;
  3454. cdfd.cbStmMin = 0;
  3455. cdfd.cbStmMax = 0;
  3456. cdfd.ulSeed = ulSeed;
  3457. cdfd.dwRootMode = STGM_CREATE |
  3458. STGM_DIRECT |
  3459. STGM_READWRITE |
  3460. STGM_SHARE_EXCLUSIVE |
  3461. STGM_SIMPLE;
  3462. hr = pTestChanceDF->Create(&cdfd, pRootDocFileName);
  3463. DH_HRCHECK(hr, TEXT("pTestChanceDF->Create"));
  3464. }
  3465. if (S_OK == hr)
  3466. {
  3467. pTestVirtualDF = new VirtualDF();
  3468. if(NULL == pTestVirtualDF)
  3469. {
  3470. hr = E_OUTOFMEMORY;
  3471. }
  3472. }
  3473. if (S_OK == hr)
  3474. {
  3475. hr = pTestVirtualDF->GenerateVirtualDF(
  3476. pTestChanceDF,
  3477. &pVirtualDFRoot);
  3478. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  3479. }
  3480. if (S_OK == hr)
  3481. {
  3482. DH_TRACE((
  3483. DH_LVL_TRACE1,
  3484. TEXT("DocFile - Create - successfully created.")));
  3485. }
  3486. else
  3487. {
  3488. DH_TRACE((
  3489. DH_LVL_TRACE1,
  3490. TEXT("DocFile - Create - failed, hr=0x%lx."),
  3491. hr));
  3492. }
  3493. // Generate the number of streams to create
  3494. if (S_OK == hr)
  3495. {
  3496. usErr = pdgi->Generate(&ulStmNum, ulMinStm, ulMaxStm);
  3497. if (DG_RC_SUCCESS != usErr)
  3498. {
  3499. hr = E_FAIL;
  3500. }
  3501. }
  3502. // Initialization
  3503. if (S_OK == hr)
  3504. {
  3505. pvsnRootNewChildStream = new VirtualStmNode*[ulStmNum];
  3506. pRootNewChildStmName = new LPTSTR[ulStmNum];
  3507. if ((NULL == pvsnRootNewChildStream) || (NULL == pRootNewChildStmName))
  3508. {
  3509. hr = E_OUTOFMEMORY;
  3510. }
  3511. }
  3512. if (S_OK == hr)
  3513. {
  3514. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  3515. {
  3516. pvsnRootNewChildStream[ulIndex] = NULL;
  3517. pRootNewChildStmName[ulIndex] = NULL;
  3518. }
  3519. }
  3520. // Create ulStmNum streams under the root storage
  3521. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  3522. {
  3523. if (S_OK == hr)
  3524. {
  3525. // Generate random name for stream
  3526. hr = GenerateRandomName(
  3527. pdgu,
  3528. MINLENGTH,
  3529. MAXLENGTH,
  3530. &pRootNewChildStmName[ulIndex]);
  3531. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3532. }
  3533. if (S_OK == hr)
  3534. {
  3535. hr = AddStream(
  3536. pTestVirtualDF,
  3537. pVirtualDFRoot,
  3538. pRootNewChildStmName[ulIndex],
  3539. 0,
  3540. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3541. &pvsnRootNewChildStream[ulIndex]);
  3542. DH_HRCHECK(hr, TEXT("AddStream")) ;
  3543. }
  3544. if(S_OK == hr)
  3545. {
  3546. DH_TRACE((
  3547. DH_LVL_TRACE1,
  3548. TEXT("VirtualStmNode::AddStream completed successfully.")));
  3549. }
  3550. else
  3551. {
  3552. DH_TRACE((
  3553. DH_LVL_TRACE1,
  3554. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx"),
  3555. hr));
  3556. }
  3557. if (S_OK == hr)
  3558. {
  3559. // Generate random size for stream between MIN_STMSIZE and
  3560. // MAX_STMSIZE if it's not the last stream, otherwise generate a
  3561. // size between 0 and MAXSIZEOFMINISTM(4096L).
  3562. if (ulStmNum-1 == ulIndex)
  3563. {
  3564. usErr = pdgi->Generate(&culBytesWrite, 0L, MAXSIZEOFMINISTM);
  3565. }
  3566. else
  3567. {
  3568. usErr = pdgi->Generate(&culBytesWrite,MIN_STMSIZE,MAX_STMSIZE);
  3569. }
  3570. if (DG_RC_SUCCESS != usErr)
  3571. {
  3572. hr = E_FAIL;
  3573. }
  3574. }
  3575. if (S_OK == hr)
  3576. {
  3577. // Generate a random string of size culBytesWrite
  3578. hr = GenerateRandomString(
  3579. pdgu,
  3580. culBytesWrite,
  3581. culBytesWrite,
  3582. &ptcsBuffer);
  3583. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  3584. }
  3585. if (S_OK == hr)
  3586. {
  3587. hr = pvsnRootNewChildStream[ulIndex]->Write(
  3588. ptcsBuffer,
  3589. culBytesWrite,
  3590. &culWritten);
  3591. }
  3592. if (S_OK != hr)
  3593. {
  3594. DH_TRACE((
  3595. DH_LVL_TRACE1,
  3596. TEXT("VirtualStmNode::Write not successful, hr=0x%lx."),
  3597. hr));
  3598. }
  3599. // Release the stream
  3600. if (S_OK == hr)
  3601. {
  3602. hr = pvsnRootNewChildStream[ulIndex]->Close();
  3603. }
  3604. if (S_OK != hr)
  3605. {
  3606. DH_TRACE((
  3607. DH_LVL_TRACE1,
  3608. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3609. hr));
  3610. }
  3611. // Delete the temp buffer
  3612. if (NULL != ptcsBuffer)
  3613. {
  3614. delete ptcsBuffer;
  3615. ptcsBuffer = NULL;
  3616. }
  3617. }
  3618. // Commit the root
  3619. if (S_OK == hr)
  3620. {
  3621. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3622. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit"));
  3623. }
  3624. if (S_OK == hr)
  3625. {
  3626. DH_TRACE((
  3627. DH_LVL_TRACE1,
  3628. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3629. }
  3630. else
  3631. {
  3632. DH_TRACE((
  3633. DH_LVL_TRACE1,
  3634. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  3635. hr));
  3636. }
  3637. // Release root
  3638. if (S_OK == hr)
  3639. {
  3640. hr = pVirtualDFRoot->Close();
  3641. }
  3642. if (S_OK == hr)
  3643. {
  3644. DH_TRACE((
  3645. DH_LVL_TRACE1,
  3646. TEXT("VirtualCtrNode::Close completed successfully.")));
  3647. }
  3648. else
  3649. {
  3650. DH_TRACE((
  3651. DH_LVL_TRACE1,
  3652. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3653. hr));
  3654. }
  3655. // if everything goes well, log test as passed else failed.
  3656. if (S_OK == hr)
  3657. {
  3658. DH_LOG((LOG_PASS, TEXT("Test variation DFTEST_109 passed.")) );
  3659. }
  3660. else
  3661. {
  3662. DH_LOG((
  3663. LOG_FAIL,
  3664. TEXT("Test variation DFTEST_109 failed, hr = 0x%lx."),
  3665. hr) );
  3666. }
  3667. // Cleanup
  3668. // Delete the docfile on disk
  3669. if ((S_OK == hr) && (NULL != pRootDocFileName))
  3670. {
  3671. if(FALSE == DeleteFile(pRootDocFileName))
  3672. {
  3673. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  3674. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  3675. }
  3676. }
  3677. // Delete Chance docfile tree
  3678. if(NULL != pTestChanceDF)
  3679. {
  3680. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  3681. pTestChanceDF->GetChanceDFRoot());
  3682. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  3683. delete pTestChanceDF;
  3684. pTestChanceDF = NULL;
  3685. }
  3686. // Delete Virtual docfile tree
  3687. if(NULL != pTestVirtualDF)
  3688. {
  3689. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  3690. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  3691. delete pTestVirtualDF;
  3692. pTestVirtualDF = NULL;
  3693. }
  3694. // Delete temp space
  3695. if (NULL != pRootDocFileName)
  3696. {
  3697. delete pRootDocFileName;
  3698. pRootDocFileName = NULL;
  3699. }
  3700. if (NULL != pvsnRootNewChildStream)
  3701. {
  3702. delete []pvsnRootNewChildStream;
  3703. pvsnRootNewChildStream = NULL;
  3704. }
  3705. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  3706. {
  3707. if (NULL != pRootNewChildStmName[ulIndex])
  3708. {
  3709. delete pRootNewChildStmName[ulIndex];
  3710. pRootNewChildStmName[ulIndex] = NULL;
  3711. }
  3712. }
  3713. if (NULL != pRootNewChildStmName)
  3714. {
  3715. delete pRootNewChildStmName;
  3716. pRootNewChildStmName = NULL;
  3717. }
  3718. if (NULL != pdgi)
  3719. {
  3720. delete pdgi;
  3721. pdgi = NULL;
  3722. }
  3723. if (NULL != pdgu)
  3724. {
  3725. delete pdgu;
  3726. pdgu = NULL;
  3727. }
  3728. // Stop logging the test
  3729. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation DFTEST_109 finished")) );
  3730. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3731. return hr;
  3732. #endif //_MAC
  3733. }