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.

2811 lines
78 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: irootstg.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to IRootStorage
  9. // interface.
  10. //
  11. // Functions:
  12. //
  13. // History: 25-July-1996 NarindK Created.
  14. // 27-Mar-97 SCousens Conversionified
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <dfheader.hxx>
  18. #pragma hdrstop
  19. #include "init.hxx"
  20. //Local Functions - Actual test functions.
  21. HRESULT IROOTSTGTEST_100a(int argc, char *argv[], LPTSTR ptAlt);
  22. HRESULT IROOTSTGTEST_101a(int argc, char *argv[], LPTSTR ptAlt);
  23. HRESULT IROOTSTGTEST_102a(int argc, char *argv[], LPTSTR ptAlt);
  24. HRESULT IROOTSTGTEST_103a(int argc, char *argv[], LPTSTR ptAlt);
  25. // These stubs call a processor function for common processing
  26. // before going on to call the actual tests.
  27. HRESULT IROOTSTGTEST_100(int argc, char *argv[])
  28. {
  29. return RunTestAltPath(argc, argv, IROOTSTGTEST_100a);
  30. }
  31. HRESULT IROOTSTGTEST_101(int argc, char *argv[])
  32. {
  33. return RunTestAltPath(argc, argv, IROOTSTGTEST_101a);
  34. }
  35. HRESULT IROOTSTGTEST_102(int argc, char *argv[])
  36. {
  37. return RunTestAltPath(argc, argv, IROOTSTGTEST_102a);
  38. }
  39. HRESULT IROOTSTGTEST_103(int argc, char *argv[])
  40. {
  41. return RunTestAltPath(argc, argv, IROOTSTGTEST_103a);
  42. }
  43. //----------------------------------------------------------------------------
  44. //
  45. // Test: IROOTSTGTEST_100a
  46. //
  47. // Synopsis: A random docfile with random number of storages/streams is
  48. // created/committed/closed. The root docfile is instantiated
  49. // and CRC'd. QueryInterface for an IRootStorage is called and then
  50. // SwitchToFile with a new file name is called. The orignal file is
  51. // released. We then modify the switched to file, commit it, and
  52. // release. The original root docfile is then instantiated and CRC'd.
  53. // The CRCs are compared to verify that original file is unchanged.
  54. //
  55. // Arguments:[argc]
  56. // [argv]
  57. //
  58. // Returns: HRESULT
  59. //
  60. // History: 25-July-1996 NarindK Created.
  61. //
  62. // Notes: This test runs in direct, transacted, and transacted deny write
  63. // modes
  64. //
  65. // New Test Notes:
  66. // 1. Old File: LTSAVEAS.CXX
  67. // 2. Old name of test : LegitTransactedSaveAs
  68. // New Name of test : IROOTSTGTEST_100
  69. // 3. To run the test, do the following at command prompt.
  70. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  71. // /t:IROOTSTGTEST-100 /dfRootMode:dirReadWriteShEx
  72. // /dfStgMode:dirReadWriteShEx
  73. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  74. // /t:IROOTSTGTEST-100 /dfRootMode:xactReadWriteShEx
  75. // /dfStgMode:xactReadWriteShEx
  76. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  77. // /t:IROOTSTGTEST-100 /dfRootMode:xactReadWriteShDenyW
  78. // /dfStgMode:xactReadWriteShEx
  79. //
  80. // BUGNOTE: Conversion: IROOTSTGTEST-100 NO - root stgs not suppd in nss
  81. //
  82. // Note: The IRootStorage interface is used to switch the underlying disk file
  83. // that IStorage Objects are being saved to. SwitchToFile makes a new
  84. // copy of the file underlying this Istorage and associated IStorage
  85. // object with this new file, rather than its current file, including
  86. // uncommitted changes.
  87. //-----------------------------------------------------------------------------
  88. HRESULT IROOTSTGTEST_100a(int argc, char *argv[], LPTSTR ptAlt)
  89. {
  90. HRESULT hr = S_OK;
  91. HRESULT hr2 = S_OK;
  92. ChanceDF *pTestChanceDF = NULL;
  93. VirtualDF *pTestVirtualDF = NULL;
  94. VirtualCtrNode *pVirtualDFRoot = NULL;
  95. LPTSTR pFileName = NULL;
  96. LPTSTR pNewRootDocFileName = NULL;
  97. LPOLESTR poszNewRootDocFileName = NULL;
  98. DWORD dwCRCOrg = 0;
  99. DWORD dwCRCNew = 0;
  100. DWORD dwRootMode = 0;
  101. DWORD dwStgMode = 0;
  102. LPSTORAGE pStgRootOrg = NULL;
  103. LPSTORAGE pStgRootNew = NULL;
  104. LPROOTSTORAGE pStgIRootStg = NULL;
  105. DG_STRING *pdgu = NULL;
  106. DG_INTEGER *pdgi = NULL;
  107. USHORT usErr = 0;
  108. ULONG ulRef = 0;
  109. BOOL fPass = TRUE;
  110. // Not for 2phase. Bail.
  111. if (DoingDistrib ())
  112. {
  113. return S_OK;
  114. }
  115. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("IROOTSTGTEST_100"));
  116. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  117. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_100 started.")) );
  118. DH_TRACE((DH_LVL_TRACE1,
  119. TEXT("IRootStorage-SwitchToFile, Save as. Modify DF, comp org DF.")));
  120. // Create the new ChanceDocFile tree that would consist of chance nodes.
  121. if (S_OK == hr)
  122. {
  123. pTestChanceDF = new ChanceDF();
  124. if(NULL == pTestChanceDF)
  125. {
  126. hr = E_OUTOFMEMORY;
  127. }
  128. }
  129. if (S_OK == hr)
  130. {
  131. hr = pTestChanceDF->CreateFromParams(argc, argv);
  132. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  133. }
  134. if (S_OK == hr)
  135. {
  136. dwRootMode = pTestChanceDF->GetRootMode();
  137. dwStgMode = pTestChanceDF->GetStgMode();
  138. DH_TRACE((
  139. DH_LVL_TRACE1,
  140. TEXT("Run Mode for IROOTSTGTEST_100, Access mode: %lx"),
  141. dwRootMode));
  142. }
  143. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  144. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  145. // and VirtualStmNodes.
  146. if (S_OK == hr)
  147. {
  148. pTestVirtualDF = new VirtualDF();
  149. if(NULL == pTestVirtualDF)
  150. {
  151. hr = E_OUTOFMEMORY;
  152. }
  153. }
  154. if (S_OK == hr)
  155. {
  156. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  157. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  158. }
  159. if (S_OK == hr)
  160. {
  161. DH_TRACE((
  162. DH_LVL_TRACE1,
  163. TEXT("DocFile - CreateFromParams - successfully created.")));
  164. }
  165. else
  166. {
  167. DH_TRACE((
  168. DH_LVL_TRACE1,
  169. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  170. hr));
  171. }
  172. if(S_OK == hr)
  173. {
  174. hr = ParseVirtualDFAndCommitAllOpenStgs(
  175. pVirtualDFRoot,
  176. STGC_DEFAULT,
  177. NODE_EXC_TOPSTG);
  178. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  179. }
  180. // Commit root.
  181. if(S_OK == hr)
  182. {
  183. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  184. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  185. }
  186. if (S_OK == hr)
  187. {
  188. DH_TRACE((
  189. DH_LVL_TRACE1,
  190. TEXT("VirtualCtrNode::Commit completed successfully.")));
  191. }
  192. else
  193. {
  194. DH_TRACE((
  195. DH_LVL_TRACE1,
  196. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  197. hr));
  198. }
  199. if(S_OK == hr)
  200. {
  201. hr = ParseVirtualDFAndCloseOpenStgsStms(
  202. pVirtualDFRoot,
  203. NODE_EXC_TOPSTG);
  204. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  205. }
  206. // Calculate CRC for entire DocFile without the RootDocfile name
  207. if(S_OK == hr)
  208. {
  209. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  210. DH_ASSERT(NULL != pStgRootOrg);
  211. hr = CalculateCRCForDocFile(
  212. pStgRootOrg,
  213. VERIFY_INC_TOPSTG_NAME,
  214. &dwCRCOrg);
  215. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  216. }
  217. // Get the IRootStorage interface pointer by doing QueryInterface.
  218. if(S_OK == hr)
  219. {
  220. hr = pVirtualDFRoot->QueryInterface(
  221. IID_IRootStorage,
  222. (LPVOID *) &pStgIRootStg);
  223. DH_HRCHECK(hr, TEXT("VirtualCtrNode::QueryInterface")) ;
  224. }
  225. if (S_OK == hr)
  226. {
  227. DH_TRACE((
  228. DH_LVL_TRACE1,
  229. TEXT("VirtualCtrNode::QueryInterface completed successfully.")));
  230. }
  231. else
  232. {
  233. DH_TRACE((
  234. DH_LVL_TRACE1,
  235. TEXT("VirtualCtrNode::QueryInterface unsuccessful, hr=0x%lx."),
  236. hr));
  237. }
  238. // Get DG_STRING object pointer
  239. if (S_OK == hr)
  240. {
  241. pdgu = pTestVirtualDF->GetDataGenUnicode();
  242. DH_ASSERT(NULL != pdgu) ;
  243. }
  244. // Generates a new name for DocFile that we would switch to using the
  245. // IRootStorage::SwitchToFile
  246. if(S_OK == hr)
  247. {
  248. // Generate random name for new docfile that we would switch to
  249. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pNewRootDocFileName);
  250. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  251. }
  252. //prepend drive so IRootStorage::SwitchToFile goes onto a different drive.
  253. if(S_OK == hr && NULL != ptAlt)
  254. {
  255. LPTSTR ptszNewName = new TCHAR[_tcslen ((LPTSTR)pNewRootDocFileName)+4];
  256. if (NULL != ptszNewName)
  257. {
  258. _stprintf (ptszNewName, TEXT("%s%s"), ptAlt, pNewRootDocFileName);
  259. delete []pNewRootDocFileName;
  260. pNewRootDocFileName = ptszNewName;
  261. }
  262. }
  263. if(S_OK == hr)
  264. {
  265. // Convert the new name to OLECHAR
  266. hr = TStringToOleString(pNewRootDocFileName, &poszNewRootDocFileName);
  267. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  268. }
  269. // Call IRootStorage::SwitchToFile
  270. if(S_OK == hr)
  271. {
  272. // Call DeleteFile just to make sure that pNewRootDocFileName doesn't
  273. // exist, before calling SwitchToFile
  274. DeleteFile(pNewRootDocFileName);
  275. DH_TRACE ((DH_LVL_TRACE1, TEXT("SwitchToFile: %s"), pNewRootDocFileName));
  276. hr = pStgIRootStg->SwitchToFile(poszNewRootDocFileName);
  277. DH_HRCHECK(hr, TEXT("IRootStorage::SwitchToFile")) ;
  278. }
  279. if (S_OK == hr)
  280. {
  281. DH_TRACE((
  282. DH_LVL_TRACE1,
  283. TEXT("IRootStorage::SwitchToFile completed successfully.")));
  284. }
  285. else
  286. {
  287. DH_TRACE((
  288. DH_LVL_TRACE1,
  289. TEXT("IRootStorage::SwitchToFile unsuccessful, hr=0x%lx."),
  290. hr));
  291. }
  292. // Release the pStgIRootStg pointer
  293. if(S_OK == hr)
  294. {
  295. // Release the Reference count that was added by QueryInterface call.
  296. ulRef = pStgIRootStg->Release();
  297. DH_ASSERT(1 == ulRef);
  298. }
  299. // Get DG_INTEGER object pointer
  300. if (S_OK == hr)
  301. {
  302. pdgi = pTestVirtualDF->GetDataGenInteger();
  303. DH_ASSERT(NULL != pdgi) ;
  304. }
  305. // ModifyDocFile call. All the changes should be reflected to new docfile
  306. // (the one switched to) rather than original, since SwitchToFile asso
  307. // -ciated the ISotrage object with switchedto file rather than original
  308. // file.
  309. if (S_OK == hr)
  310. {
  311. hr = ModifyDocFile(
  312. pTestVirtualDF,
  313. pVirtualDFRoot,
  314. pdgi,
  315. pdgu,
  316. dwStgMode,
  317. TRUE);
  318. DH_HRCHECK(hr, TEXT("ModifyDocFile")) ;
  319. }
  320. if (S_OK == hr)
  321. {
  322. DH_TRACE((
  323. DH_LVL_TRACE1,
  324. TEXT("ModifyDF-Rename/Destroy/Open/Close elem- passed as exp.")));
  325. }
  326. else
  327. {
  328. DH_TRACE((
  329. DH_LVL_TRACE1,
  330. TEXT("ModifyDF-Rename/Destry/Open/Close elem- failed, hr=0x%lx"),
  331. hr));
  332. }
  333. // Try to open second time when flags are STGM_DENY_WRITE. This should
  334. // fail with STG_E_LOCKVIOLATION error.
  335. if (S_OK == hr)
  336. {
  337. if(dwRootMode & STGM_SHARE_DENY_WRITE)
  338. {
  339. if(S_OK == hr)
  340. {
  341. hr = StgOpenStorage(
  342. poszNewRootDocFileName,
  343. NULL,
  344. dwRootMode,
  345. NULL,
  346. 0,
  347. &pStgRootNew);
  348. }
  349. if(STG_E_LOCKVIOLATION == hr)
  350. {
  351. DH_TRACE((
  352. DH_LVL_TRACE1,
  353. TEXT("STGM_SHARE_DENY_WRITE: StgOpenStg hr = 0x%lx exp"),
  354. hr));
  355. hr = S_OK;
  356. }
  357. else
  358. {
  359. DH_TRACE((
  360. DH_LVL_TRACE1,
  361. TEXT("STGM_SHARE_DENY_WRITE:StgOpenStg hr = 0x%lx unexp"),
  362. hr));
  363. fPass = FALSE;
  364. }
  365. }
  366. }
  367. // Close the Original DocFile
  368. if(S_OK == hr)
  369. {
  370. hr = pVirtualDFRoot->Close();
  371. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  372. }
  373. if (S_OK == hr)
  374. {
  375. DH_TRACE((
  376. DH_LVL_TRACE1,
  377. TEXT("VirtualCtrNode::Close completed successfully.")));
  378. }
  379. else
  380. {
  381. DH_TRACE((
  382. DH_LVL_TRACE1,
  383. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  384. hr));
  385. }
  386. // Open the original Root DocFile again
  387. if(S_OK == hr)
  388. {
  389. hr = pVirtualDFRoot->Open(NULL, dwRootMode, NULL, 0);
  390. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  391. }
  392. if (S_OK == hr)
  393. {
  394. DH_TRACE((
  395. DH_LVL_TRACE1,
  396. TEXT("VirtualCtrNode::Open completed successfully.")));
  397. }
  398. else
  399. {
  400. DH_TRACE((
  401. DH_LVL_TRACE1,
  402. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  403. hr));
  404. }
  405. // Calculate CRC for entire original DocFile without the RootDocfile name.
  406. // This CRC should match with CRC calculated for original DocFile since
  407. // all the changes being made after first CRC calculation should have been
  408. // to switched to file.
  409. if(S_OK == hr)
  410. {
  411. pStgRootOrg = NULL;
  412. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  413. DH_ASSERT(NULL != pStgRootOrg);
  414. hr = CalculateCRCForDocFile(
  415. pStgRootOrg,
  416. VERIFY_INC_TOPSTG_NAME,
  417. &dwCRCNew);
  418. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  419. }
  420. // Compare CRC's
  421. if(S_OK == hr)
  422. {
  423. if(dwCRCOrg == dwCRCNew)
  424. {
  425. DH_TRACE((
  426. DH_LVL_TRACE1,
  427. TEXT("CRC's match, original file unchanged as expected.")));
  428. }
  429. else
  430. {
  431. fPass = FALSE;
  432. DH_TRACE((
  433. DH_LVL_TRACE1,
  434. TEXT("CRC's don't match, original file got changed unexp.")));
  435. }
  436. }
  437. // Close original file.
  438. if(S_OK == hr)
  439. {
  440. hr = pVirtualDFRoot->Close();
  441. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  442. }
  443. if (S_OK == hr)
  444. {
  445. DH_TRACE((
  446. DH_LVL_TRACE1,
  447. TEXT("VirtualCtrNode::Close completed successfully.")));
  448. }
  449. else
  450. {
  451. DH_TRACE((
  452. DH_LVL_TRACE1,
  453. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  454. hr));
  455. }
  456. // Get some info about the test
  457. TCHAR szFileSystemInfoBuffer[10] = {TEXT(" :(")};
  458. GetVolumeInformation (ptAlt,
  459. NULL, //lpVolumeNameBuffer
  460. 0, //nVolumeNameSize
  461. NULL,
  462. NULL,
  463. NULL, //lpFileSystemFlags
  464. &szFileSystemInfoBuffer[3],
  465. sizeof (szFileSystemInfoBuffer)-4);
  466. _tcscat (szFileSystemInfoBuffer, TEXT(")"));
  467. if (NULL != ptAlt)
  468. {
  469. *szFileSystemInfoBuffer = *ptAlt;
  470. }
  471. // if everything goes well, log test as passed else failed.
  472. if ((S_OK == hr) && (TRUE == fPass))
  473. {
  474. DH_LOG((LOG_PASS,
  475. TEXT("Test IROOTSTGTEST_100 passed. %s"),
  476. szFileSystemInfoBuffer));
  477. }
  478. else
  479. {
  480. DH_LOG((LOG_FAIL,
  481. TEXT("Test IROOTSTGTEST_100 failed, hr = 0x%lx. %s"),
  482. hr,
  483. szFileSystemInfoBuffer));
  484. DH_DUMPCMD((LOG_FAIL, TEXT(" /seed:%u %s%c"),
  485. pTestChanceDF->GetSeed(),
  486. NULL == ptAlt ? TEXT("") : TEXT("/altpath:"),
  487. NULL == ptAlt ? TCHAR('\0') : TCHAR(*ptAlt)));
  488. // test failed. make it look like it failed.
  489. hr = FirstError (hr, E_FAIL);
  490. }
  491. // Cleanup
  492. // Get the name of file, will be used later to delete the file
  493. if(NULL != pVirtualDFRoot)
  494. {
  495. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  496. if (pFileName != NULL)
  497. {
  498. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  499. }
  500. }
  501. // Delete Chance docfile tree
  502. if(NULL != pTestChanceDF)
  503. {
  504. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  505. pTestChanceDF->GetChanceDFRoot());
  506. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  507. delete pTestChanceDF;
  508. pTestChanceDF = NULL;
  509. }
  510. // Delete Virtual docfile tree
  511. if(NULL != pTestVirtualDF)
  512. {
  513. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  514. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  515. delete pTestVirtualDF;
  516. pTestVirtualDF = NULL;
  517. }
  518. // Delete the original docfile on disk
  519. if((S_OK == hr) && (NULL != pFileName))
  520. {
  521. if(FALSE == DeleteFile(pFileName))
  522. {
  523. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  524. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  525. }
  526. }
  527. // Delete the new docfile on disk
  528. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  529. {
  530. if(FALSE == DeleteFile(pNewRootDocFileName))
  531. {
  532. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  533. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  534. }
  535. }
  536. // Delete temp string
  537. if(NULL != pFileName)
  538. {
  539. delete pFileName;
  540. pFileName = NULL;
  541. }
  542. if(NULL != poszNewRootDocFileName)
  543. {
  544. delete poszNewRootDocFileName;
  545. poszNewRootDocFileName = NULL;
  546. }
  547. if(NULL != pNewRootDocFileName)
  548. {
  549. delete pNewRootDocFileName;
  550. pNewRootDocFileName = NULL;
  551. }
  552. // Stop logging the test
  553. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_100 finished")) );
  554. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  555. return hr;
  556. }
  557. //----------------------------------------------------------------------------
  558. //
  559. // Test: IROOTSTGTEST_101a
  560. //
  561. // Synopsis: A random docfile with random number of storages/streams is
  562. // created/committed/closed. The root docfile is instantiated,
  563. // modified, and then CRC' is calculated for that. We then do
  564. // do QueryInterface for an IRootStorage and SwitchToFile to
  565. // a new root docfile. The new docfile is CRC'd and compared to
  566. // the original, they should match at this point. This docfile is
  567. // then modified, CRC'd, and released. This docfile is then
  568. // re-instantiated, CRC'd, and the previous two CRCs are compared.
  569. // The original root docfile is then instantiated and CRC'd and
  570. // the CRC is compared against the orignal CRC.
  571. //
  572. // Arguments:[argc]
  573. // [argv]
  574. //
  575. // Returns: HRESULT
  576. //
  577. // History: 25-July-1996 NarindK Created.
  578. //
  579. // Notes: This test runs in direct, transacted, and transacted deny write
  580. // modes
  581. //
  582. // New Test Notes:
  583. // 1. Old File: LTSVBOTH.CXX
  584. // 2. Old name of test : LegitTransactedSaveAsBoth
  585. // New Name of test : IROOTSTGTEST_101
  586. // 3. To run the test, do the following at command prompt.
  587. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  588. // /t:IROOTSTGTEST-101 /dfRootMode:dirReadWriteShEx
  589. // /dfStgMode:dirReadWriteShEx
  590. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  591. // /t:IROOTSTGTEST-101 /dfRootMode:xactReadWriteShEx
  592. // /dfStgMode:xactReadWriteShEx
  593. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  594. // /t:IROOTSTGTEST-101 /dfRootMode:xactReadWriteShDenyW
  595. // /dfStgMode:xactReadWriteShEx
  596. //
  597. // BUGNOTE: Conversion: IROOTSTGTEST-101 NO - root stgs not suppd in nss
  598. //
  599. // Note: The IRootStorage interface is used to switch the underlying disk file
  600. // that IStorage Objects are being saved to. SwitchToFile makes a new
  601. // copy of the file underlying this Istorage and associated IStorage
  602. // object with this new file, rather than its current file, including
  603. // uncommitted changes.
  604. //-----------------------------------------------------------------------------
  605. HRESULT IROOTSTGTEST_101a(int argc, char *argv[], LPTSTR ptAlt)
  606. {
  607. HRESULT hr = S_OK;
  608. HRESULT hr2 = S_OK;
  609. ChanceDF *pTestChanceDF = NULL;
  610. VirtualDF *pTestVirtualDF = NULL;
  611. VirtualCtrNode *pVirtualDFRoot = NULL;
  612. LPTSTR pFileName = NULL;
  613. LPTSTR pNewRootDocFileName = NULL;
  614. LPOLESTR poszNewRootDocFileName = NULL;
  615. DWORD dwCRCOrg = 0;
  616. DWORD dwCRCNew = 0;
  617. DWORD dwCRCTemp = 0;
  618. DWORD dwRootMode = 0;
  619. DWORD dwStgMode = 0;
  620. LPSTORAGE pStgRootOrg = NULL;
  621. LPSTORAGE pStgRootNew = NULL;
  622. LPROOTSTORAGE pStgIRootStg = NULL;
  623. DG_STRING *pdgu = NULL;
  624. DG_INTEGER *pdgi = NULL;
  625. USHORT usErr = 0;
  626. ULONG ulRef = 0;
  627. BOOL fPass = TRUE;
  628. // Not for 2phase. Bail.
  629. if (DoingDistrib ())
  630. {
  631. return S_OK;
  632. }
  633. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("IROOTSTGTEST_101"));
  634. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  635. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_101 started.")) );
  636. DH_TRACE((DH_LVL_TRACE1,
  637. TEXT("IRootStorage-SwitchToFile, Save as both. Modify both DF/cmp")));
  638. // Create the new ChanceDocFile tree that would consist of chance nodes.
  639. if (S_OK == hr)
  640. {
  641. pTestChanceDF = new ChanceDF();
  642. if(NULL == pTestChanceDF)
  643. {
  644. hr = E_OUTOFMEMORY;
  645. }
  646. }
  647. if (S_OK == hr)
  648. {
  649. hr = pTestChanceDF->CreateFromParams(argc, argv);
  650. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  651. }
  652. if (S_OK == hr)
  653. {
  654. dwRootMode = pTestChanceDF->GetRootMode();
  655. dwStgMode = pTestChanceDF->GetStgMode();
  656. DH_TRACE((
  657. DH_LVL_TRACE1,
  658. TEXT("Run Mode for IROOTSTGTEST_101, Access mode: %lx"),
  659. dwRootMode));
  660. }
  661. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  662. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  663. // and VirtualStmNodes.
  664. if (S_OK == hr)
  665. {
  666. pTestVirtualDF = new VirtualDF();
  667. if(NULL == pTestVirtualDF)
  668. {
  669. hr = E_OUTOFMEMORY;
  670. }
  671. }
  672. if (S_OK == hr)
  673. {
  674. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  675. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  676. }
  677. if (S_OK == hr)
  678. {
  679. DH_TRACE((
  680. DH_LVL_TRACE1,
  681. TEXT("DocFile - CreateFromParams - successfully created.")));
  682. }
  683. else
  684. {
  685. DH_TRACE((
  686. DH_LVL_TRACE1,
  687. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  688. hr));
  689. }
  690. if(S_OK == hr)
  691. {
  692. hr = ParseVirtualDFAndCommitAllOpenStgs(
  693. pVirtualDFRoot,
  694. STGC_DEFAULT,
  695. NODE_EXC_TOPSTG);
  696. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  697. }
  698. // Commit root.
  699. if(S_OK == hr)
  700. {
  701. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  702. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  703. }
  704. if (S_OK == hr)
  705. {
  706. DH_TRACE((
  707. DH_LVL_TRACE1,
  708. TEXT("VirtualCtrNode::Commit completed successfully.")));
  709. }
  710. else
  711. {
  712. DH_TRACE((
  713. DH_LVL_TRACE1,
  714. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  715. hr));
  716. }
  717. if(S_OK == hr)
  718. {
  719. hr = ParseVirtualDFAndCloseOpenStgsStms(
  720. pVirtualDFRoot,
  721. NODE_EXC_TOPSTG);
  722. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  723. }
  724. // Get DG_INTEGER object pointer
  725. if (S_OK == hr)
  726. {
  727. pdgi = pTestVirtualDF->GetDataGenInteger();
  728. DH_ASSERT(NULL != pdgi) ;
  729. }
  730. // Get DG_STRING object pointer
  731. if (S_OK == hr)
  732. {
  733. pdgu = pTestVirtualDF->GetDataGenUnicode();
  734. DH_ASSERT(NULL != pdgu) ;
  735. }
  736. // Modify original docfile now and then calculate CRC for it which would
  737. // be the original CRC value.
  738. if (S_OK == hr)
  739. {
  740. hr = ModifyDocFile(
  741. pTestVirtualDF,
  742. pVirtualDFRoot,
  743. pdgi,
  744. pdgu,
  745. dwStgMode,
  746. TRUE);
  747. DH_HRCHECK(hr, TEXT("ModifyDocFile")) ;
  748. }
  749. if (S_OK == hr)
  750. {
  751. DH_TRACE((
  752. DH_LVL_TRACE1,
  753. TEXT("ModifyDF-Rename/Destroy/Open/Close elem- passed as exp.")));
  754. }
  755. else
  756. {
  757. DH_TRACE((
  758. DH_LVL_TRACE1,
  759. TEXT("ModifyDF-Rename/Destry/Open/Close elem- failed, hr=0x%lx"),
  760. hr));
  761. }
  762. // Calculate CRC for entire DocFile without the RootDocfile name for
  763. // original DocFile after making changes, but before calling SwitchToFile.
  764. // This is the original CRC value.
  765. if(S_OK == hr)
  766. {
  767. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  768. DH_ASSERT(NULL != pStgRootOrg);
  769. hr = CalculateCRCForDocFile(
  770. pStgRootOrg,
  771. VERIFY_EXC_TOPSTG_NAME,
  772. &dwCRCOrg);
  773. DH_TRACE ((DH_LVL_TRACE2, TEXT("CRC original file %#x"), dwCRCOrg));
  774. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  775. }
  776. // Get the IRootStorage interface pointer by doing QueryInterface on it.
  777. if(S_OK == hr)
  778. {
  779. hr = pVirtualDFRoot->QueryInterface(
  780. IID_IRootStorage,
  781. (LPVOID *) &pStgIRootStg);
  782. DH_HRCHECK(hr, TEXT("VirtualCtrNode::QueryInterface")) ;
  783. }
  784. if (S_OK == hr)
  785. {
  786. DH_TRACE((
  787. DH_LVL_TRACE1,
  788. TEXT("VirtualCtrNode::QueryInterface completed successfully.")));
  789. }
  790. else
  791. {
  792. DH_TRACE((
  793. DH_LVL_TRACE1,
  794. TEXT("VirtualCtrNode::QueryInterface unsuccessful, hr=0x%lx."),
  795. hr));
  796. }
  797. // Generates a new name for DocFile that we would switch to using the
  798. // IRootStorage::SwitchToFile
  799. if(S_OK == hr)
  800. {
  801. // Generate random name for new docfile that we would switch to
  802. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pNewRootDocFileName);
  803. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  804. }
  805. //prepend drive so IRootStorage::SwitchToFile goes onto a different drive.
  806. if(S_OK == hr && NULL != ptAlt)
  807. {
  808. LPTSTR ptszNewName = new TCHAR[_tcslen ((LPTSTR)pNewRootDocFileName)+4];
  809. if (NULL != ptszNewName)
  810. {
  811. _stprintf (ptszNewName, TEXT("%s%s"), ptAlt, pNewRootDocFileName);
  812. delete []pNewRootDocFileName;
  813. pNewRootDocFileName = ptszNewName;
  814. }
  815. }
  816. if(S_OK == hr)
  817. {
  818. // Convert the new name to OLECHAR
  819. hr = TStringToOleString(pNewRootDocFileName, &poszNewRootDocFileName);
  820. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  821. }
  822. // Call IRootStorage::SwitchToFile. Therafter the IStorage would become
  823. // assocaited with new switched to file rather than original file and all
  824. // changes, including uncommitted ones, would be reflected to the new
  825. // switched to file rather than original file.
  826. if(S_OK == hr)
  827. {
  828. // Call DeleteFile just to make sure that pNewRootDocFileName doesn't
  829. // exist, before calling SwitchToFile
  830. DeleteFile(pNewRootDocFileName);
  831. DH_TRACE ((DH_LVL_TRACE1, TEXT("SwitchToFile: %s"), pNewRootDocFileName));
  832. hr = pStgIRootStg->SwitchToFile(poszNewRootDocFileName);
  833. DH_HRCHECK(hr, TEXT("IRootStorage::SwitchToFile")) ;
  834. }
  835. if (S_OK == hr)
  836. {
  837. DH_TRACE((
  838. DH_LVL_TRACE1,
  839. TEXT("IRootStorage::SwitchToFile completed successfully.")));
  840. }
  841. else
  842. {
  843. DH_TRACE((
  844. DH_LVL_TRACE1,
  845. TEXT("IRootStorage::SwitchToFile unsuccessful, hr=0x%lx."),
  846. hr));
  847. }
  848. // Release the pStgIRootStg pointer
  849. if(S_OK == hr)
  850. {
  851. // Release the Reference count that was added by QueryInterface call.
  852. ulRef = pStgIRootStg->Release();
  853. DH_ASSERT(1 == ulRef);
  854. }
  855. // Get the new root DocFile CRC after switching to File, should be the
  856. // same as original root DocFile CRC at this point. Calculate CRC and
  857. // compare to make sure.
  858. if(S_OK == hr)
  859. {
  860. pStgRootOrg = NULL;
  861. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  862. DH_ASSERT(NULL != pStgRootOrg);
  863. hr = CalculateCRCForDocFile(
  864. pStgRootOrg,
  865. VERIFY_EXC_TOPSTG_NAME,
  866. &dwCRCTemp);
  867. DH_TRACE ((DH_LVL_TRACE2, TEXT("CRC switched file %#x"), dwCRCTemp));
  868. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  869. }
  870. // Compare CRC's at this point, these should match
  871. if(S_OK == hr)
  872. {
  873. if(dwCRCOrg == dwCRCTemp)
  874. {
  875. DH_TRACE((
  876. DH_LVL_TRACE1,
  877. TEXT("CRC's match of org & switched to file as exp")));
  878. }
  879. else
  880. {
  881. fPass = FALSE;
  882. DH_TRACE((
  883. DH_LVL_TRACE1,
  884. TEXT("CRC's don't match of org & switched to file unexp")));
  885. }
  886. }
  887. // Call ModifyDocFile call. All the canges are being getting reflected to
  888. // the new root DocFile since SwitchToFile associated IStorage with switch
  889. // to file rather than original file.
  890. if (S_OK == hr)
  891. {
  892. hr = ModifyDocFile(
  893. pTestVirtualDF,
  894. pVirtualDFRoot,
  895. pdgi,
  896. pdgu,
  897. dwStgMode,
  898. TRUE);
  899. DH_HRCHECK(hr, TEXT("ModifyDocFile")) ;
  900. }
  901. if (S_OK == hr)
  902. {
  903. DH_TRACE((
  904. DH_LVL_TRACE1,
  905. TEXT("ModifyDF-Rename/Destroy/Open/Close elem- passed as exp.")));
  906. }
  907. else
  908. {
  909. DH_TRACE((
  910. DH_LVL_TRACE1,
  911. TEXT("ModifyDF-Rename/Destry/Open/Close elem- failed, hr=0x%lx"),
  912. hr));
  913. }
  914. // Get new root DocFile CRC after making changes to new DocFile and commit
  915. // ing them. This will be compared to the new docfile CRC after release
  916. // and reinstantiation.
  917. if(S_OK == hr)
  918. {
  919. pStgRootOrg = NULL;
  920. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  921. DH_ASSERT(NULL != pStgRootOrg);
  922. hr = CalculateCRCForDocFile(
  923. pStgRootOrg,
  924. VERIFY_EXC_TOPSTG_NAME,
  925. &dwCRCNew);
  926. DH_TRACE ((DH_LVL_TRACE2, TEXT("CRC switched/modified file %#x"), dwCRCNew));
  927. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  928. }
  929. // Close the Original DocFile.
  930. if(S_OK == hr)
  931. {
  932. hr = pVirtualDFRoot->Close();
  933. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  934. }
  935. if (S_OK == hr)
  936. {
  937. DH_TRACE((
  938. DH_LVL_TRACE1,
  939. TEXT("VirtualCtrNode::Close completed successfully.")));
  940. }
  941. else
  942. {
  943. DH_TRACE((
  944. DH_LVL_TRACE1,
  945. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  946. hr));
  947. }
  948. // Open the new Root DocFile. The CRC will be computed on it, this
  949. // is expected to match dwCRCNew that was calculated before.
  950. if(S_OK == hr)
  951. {
  952. hr = StgOpenStorage(
  953. poszNewRootDocFileName,
  954. NULL,
  955. dwRootMode,
  956. NULL,
  957. 0,
  958. &pStgRootNew);
  959. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  960. }
  961. // Calculate the CRC on this new root DocFile
  962. if(S_OK == hr)
  963. {
  964. dwCRCTemp = 0;
  965. hr = CalculateCRCForDocFile(
  966. pStgRootNew,
  967. VERIFY_EXC_TOPSTG_NAME,
  968. &dwCRCTemp);
  969. DH_TRACE ((DH_LVL_TRACE2, TEXT("CRC new (after switch) file %#x"), dwCRCTemp));
  970. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  971. }
  972. // Compare CRC's at this point. The CRC of this new docfile and the
  973. // DocFile that was switched to and then modified should match.
  974. if(S_OK == hr)
  975. {
  976. if(dwCRCNew == dwCRCTemp)
  977. {
  978. DH_TRACE((
  979. DH_LVL_TRACE1,
  980. TEXT("CRC's match of new & switched to file as exp")));
  981. }
  982. else
  983. {
  984. fPass = FALSE;
  985. DH_TRACE((
  986. DH_LVL_TRACE1,
  987. TEXT("CRC's don't match of new & switched to file unexp")));
  988. }
  989. }
  990. // Close the new root DocFile
  991. if(S_OK == hr)
  992. {
  993. ulRef = pStgRootNew->Release();
  994. DH_ASSERT(0 == ulRef);
  995. pStgRootNew = NULL;
  996. }
  997. // Open the original Root DocFile again. The CRC would be calculated on
  998. // this, it is expected to match dwCRCOrg, thereby verifying that because
  999. // of SwitchToFile, the original file remained unchanged.
  1000. if(S_OK == hr)
  1001. {
  1002. hr = pVirtualDFRoot->Open(NULL, dwRootMode, NULL, 0);
  1003. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1004. }
  1005. if (S_OK == hr)
  1006. {
  1007. DH_TRACE((
  1008. DH_LVL_TRACE1,
  1009. TEXT("VirtualCtrNode::Open completed successfully.")));
  1010. }
  1011. else
  1012. {
  1013. DH_TRACE((
  1014. DH_LVL_TRACE1,
  1015. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  1016. hr));
  1017. }
  1018. // Calculate CRC for entire DocFile without the RootDocfile name
  1019. if(S_OK == hr)
  1020. {
  1021. pStgRootOrg = NULL;
  1022. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  1023. DH_ASSERT(NULL != pStgRootOrg);
  1024. dwCRCTemp = 0;
  1025. hr = CalculateCRCForDocFile(
  1026. pStgRootOrg,
  1027. VERIFY_EXC_TOPSTG_NAME,
  1028. &dwCRCTemp);
  1029. DH_TRACE ((DH_LVL_TRACE2, TEXT("CRC original file again %#x"), dwCRCTemp));
  1030. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1031. }
  1032. // Compare CRC's of the this orginal docfile after reinstantiation and
  1033. // the original value before SwitchToFile was done. These should match.
  1034. if(S_OK == hr)
  1035. {
  1036. if(dwCRCTemp == dwCRCOrg)
  1037. {
  1038. DH_TRACE((
  1039. DH_LVL_TRACE1,
  1040. TEXT("CRC's match, original file unchanged as exp")));
  1041. }
  1042. else
  1043. {
  1044. fPass = FALSE;
  1045. DH_TRACE((
  1046. DH_LVL_TRACE1,
  1047. TEXT("CRC's don't match, original file changed unexp")));
  1048. }
  1049. }
  1050. // Close original root docfile.
  1051. if(S_OK == hr)
  1052. {
  1053. hr = pVirtualDFRoot->Close();
  1054. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1055. }
  1056. if (S_OK == hr)
  1057. {
  1058. DH_TRACE((
  1059. DH_LVL_TRACE1,
  1060. TEXT("VirtualCtrNode::Close completed successfully.")));
  1061. }
  1062. else
  1063. {
  1064. DH_TRACE((
  1065. DH_LVL_TRACE1,
  1066. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1067. hr));
  1068. }
  1069. // Get some info about the test
  1070. TCHAR szFileSystemInfoBuffer[10] = {TEXT(" :(")};
  1071. GetVolumeInformation (ptAlt,
  1072. NULL, //lpVolumeNameBuffer
  1073. 0, //nVolumeNameSize
  1074. NULL,
  1075. NULL,
  1076. NULL, //lpFileSystemFlags
  1077. &szFileSystemInfoBuffer[3],
  1078. sizeof (szFileSystemInfoBuffer)-4);
  1079. _tcscat (szFileSystemInfoBuffer, TEXT(")"));
  1080. if (NULL != ptAlt)
  1081. {
  1082. *szFileSystemInfoBuffer = *ptAlt;
  1083. }
  1084. // if everything goes well, log test as passed else failed.
  1085. if ((S_OK == hr) && (TRUE == fPass))
  1086. {
  1087. DH_LOG((LOG_PASS,
  1088. TEXT("Test variation IROOTSTGTEST_101 passed. %s"),
  1089. szFileSystemInfoBuffer) );
  1090. }
  1091. else
  1092. {
  1093. DH_LOG((LOG_FAIL,
  1094. TEXT("Test variation IROOTSTGTEST_101 failed, hr = 0x%lx. %s"),
  1095. hr,
  1096. szFileSystemInfoBuffer) );
  1097. DH_DUMPCMD((LOG_FAIL, TEXT(" /seed:%u %s%c"),
  1098. pTestChanceDF->GetSeed(),
  1099. NULL == ptAlt ? TEXT("") : TEXT("/altpath:"),
  1100. NULL == ptAlt ? TCHAR('\0') : TCHAR(*ptAlt)));
  1101. // test failed. make it look like it failed.
  1102. hr = FirstError (hr, E_FAIL);
  1103. }
  1104. // Cleanup
  1105. // Get the name of file, will be used later to delete the file
  1106. if(NULL != pVirtualDFRoot)
  1107. {
  1108. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  1109. if (pFileName != NULL)
  1110. {
  1111. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  1112. }
  1113. }
  1114. // Delete Chance docfile tree
  1115. if(NULL != pTestChanceDF)
  1116. {
  1117. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1118. pTestChanceDF->GetChanceDFRoot());
  1119. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1120. delete pTestChanceDF;
  1121. pTestChanceDF = NULL;
  1122. }
  1123. // Delete Virtual docfile tree
  1124. if(NULL != pTestVirtualDF)
  1125. {
  1126. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1127. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  1128. delete pTestVirtualDF;
  1129. pTestVirtualDF = NULL;
  1130. }
  1131. // Delete the original docfile on disk
  1132. if((S_OK == hr) && (NULL != pFileName))
  1133. {
  1134. if(FALSE == DeleteFile(pFileName))
  1135. {
  1136. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1137. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1138. }
  1139. }
  1140. // Delete the new docfile on disk
  1141. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  1142. {
  1143. if(FALSE == DeleteFile(pNewRootDocFileName))
  1144. {
  1145. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1146. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1147. }
  1148. }
  1149. // Delete temp string
  1150. if(NULL != pFileName)
  1151. {
  1152. delete pFileName;
  1153. pFileName = NULL;
  1154. }
  1155. if(NULL != pNewRootDocFileName)
  1156. {
  1157. delete pNewRootDocFileName;
  1158. pNewRootDocFileName = NULL;
  1159. }
  1160. if(NULL != poszNewRootDocFileName)
  1161. {
  1162. delete poszNewRootDocFileName;
  1163. poszNewRootDocFileName = NULL;
  1164. }
  1165. // Stop logging the test
  1166. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_101 finished")) );
  1167. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1168. return hr;
  1169. }
  1170. //----------------------------------------------------------------------------
  1171. //
  1172. // Test: IROOTSTGTEST_102
  1173. //
  1174. // Synopsis: A random docfile with random number of storages/streams is
  1175. // created/committed/closed. The root docfile is instantiated,
  1176. // and CRC is calculated for the docfile. It is then modified &
  1177. // CRC'd again. The test then calls QueryInterface to get an
  1178. // IRootStorage and SwitchesToFile on a new name. The new docfile
  1179. // is committed, released, reinstantiated, and CRC'd. This CRC
  1180. // should match the CRC of the modified original root docfile.
  1181. // The original docfile is then instantiated and CRC'd. This
  1182. // CRC should match the *first* CRC of the original root docfile
  1183. // since we called SwitchToFile() before committing the changes.
  1184. //
  1185. // Arguments:[argc]
  1186. // [argv]
  1187. //
  1188. // Returns: HRESULT
  1189. //
  1190. // History: 26-July-1996 NarindK Created.
  1191. //
  1192. // Notes: This test runs in transacted, and transacted deny write modes.
  1193. //
  1194. // New Test Notes:
  1195. // 1. Old File: LTSVNEW.CXX
  1196. // 2. Old name of test : LegitTransactedSaveAsNew
  1197. // New Name of test : IROOTSTGTEST_102
  1198. // 3. To run the test, do the following at command prompt.
  1199. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  1200. // /t:IROOTSTGTEST-102 /dfRootMode:xactReadWriteShEx
  1201. // /dfStgMode:xactReadWriteShEx
  1202. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  1203. // /t:IROOTSTGTEST-102 /dfRootMode:xactReadWriteShDenyW
  1204. // /dfStgMode:xactReadWriteShEx
  1205. //
  1206. // BUGNOTE: Conversion: IROOTSTGTEST-102 NO - root stgs not suppd in nss
  1207. //
  1208. // Note: The IRootStorage interface is used to switch the underlying disk file
  1209. // that IStorage Objects are being saved to. SwitchToFile makes a new
  1210. // copy of the file underlying this Istorage and associated IStorage
  1211. // object with this new file, rather than its current file, including
  1212. // uncommitted changes.
  1213. //-----------------------------------------------------------------------------
  1214. HRESULT IROOTSTGTEST_102a(int argc, char *argv[], LPTSTR ptAlt)
  1215. {
  1216. HRESULT hr = S_OK;
  1217. HRESULT hr2 = S_OK;
  1218. ChanceDF *pTestChanceDF = NULL;
  1219. VirtualDF *pTestVirtualDF = NULL;
  1220. VirtualCtrNode *pVirtualDFRoot = NULL;
  1221. LPTSTR pFileName = NULL;
  1222. LPTSTR pNewRootDocFileName = NULL;
  1223. LPOLESTR poszNewRootDocFileName = NULL;
  1224. DWORD dwCRCOrg = 0;
  1225. DWORD dwCRCNew = 0;
  1226. DWORD dwCRCTemp = 0;
  1227. DWORD dwRootMode = 0;
  1228. DWORD dwStgMode = 0;
  1229. LPSTORAGE pStgRootOrg = NULL;
  1230. LPSTORAGE pStgRootNew = NULL;
  1231. LPROOTSTORAGE pStgIRootStg = NULL;
  1232. DG_STRING *pdgu = NULL;
  1233. DG_INTEGER *pdgi = NULL;
  1234. USHORT usErr = 0;
  1235. ULONG ulRef = 0;
  1236. BOOL fPass = TRUE;
  1237. // Not for 2phase. Bail.
  1238. if (DoingDistrib ())
  1239. {
  1240. return S_OK;
  1241. }
  1242. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("IROOTSTGTEST_102"));
  1243. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1244. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_102 started.")) );
  1245. DH_TRACE((DH_LVL_TRACE1,
  1246. TEXT("IRootStorage-SwitchToFile, Save as new.")));
  1247. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1248. if (S_OK == hr)
  1249. {
  1250. pTestChanceDF = new ChanceDF();
  1251. if(NULL == pTestChanceDF)
  1252. {
  1253. hr = E_OUTOFMEMORY;
  1254. }
  1255. }
  1256. if (S_OK == hr)
  1257. {
  1258. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1259. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1260. }
  1261. if (S_OK == hr)
  1262. {
  1263. dwRootMode = pTestChanceDF->GetRootMode();
  1264. dwStgMode = pTestChanceDF->GetStgMode();
  1265. DH_TRACE((
  1266. DH_LVL_TRACE1,
  1267. TEXT("Run Mode for IROOTSTGTEST_102, Access mode: %lx"),
  1268. dwRootMode));
  1269. }
  1270. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  1271. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  1272. // and VirtualStmNodes.
  1273. if (S_OK == hr)
  1274. {
  1275. pTestVirtualDF = new VirtualDF();
  1276. if(NULL == pTestVirtualDF)
  1277. {
  1278. hr = E_OUTOFMEMORY;
  1279. }
  1280. }
  1281. if (S_OK == hr)
  1282. {
  1283. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  1284. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  1285. }
  1286. if (S_OK == hr)
  1287. {
  1288. DH_TRACE((
  1289. DH_LVL_TRACE1,
  1290. TEXT("DocFile - CreateFromParams - successfully created.")));
  1291. }
  1292. else
  1293. {
  1294. DH_TRACE((
  1295. DH_LVL_TRACE1,
  1296. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  1297. hr));
  1298. }
  1299. if(S_OK == hr)
  1300. {
  1301. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1302. pVirtualDFRoot,
  1303. STGC_DEFAULT,
  1304. NODE_EXC_TOPSTG);
  1305. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  1306. }
  1307. // Commit root.
  1308. if(S_OK == hr)
  1309. {
  1310. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1311. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1312. }
  1313. if (S_OK == hr)
  1314. {
  1315. DH_TRACE((
  1316. DH_LVL_TRACE1,
  1317. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1318. }
  1319. else
  1320. {
  1321. DH_TRACE((
  1322. DH_LVL_TRACE1,
  1323. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1324. hr));
  1325. }
  1326. if(S_OK == hr)
  1327. {
  1328. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1329. pVirtualDFRoot,
  1330. NODE_EXC_TOPSTG);
  1331. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1332. }
  1333. // Get DG_INTEGER object pointer
  1334. if (S_OK == hr)
  1335. {
  1336. pdgi = pTestVirtualDF->GetDataGenInteger();
  1337. DH_ASSERT(NULL != pdgi) ;
  1338. }
  1339. // Get DG_STRING object pointer
  1340. if (S_OK == hr)
  1341. {
  1342. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1343. DH_ASSERT(NULL != pdgu) ;
  1344. }
  1345. // Calculate CRC for entire DocFile without the RootDocfile name for
  1346. // original DocFile before making changes. Then modify DocFile, but
  1347. // don't commit the changes. Get a new CRC reflecting these changes
  1348. // and then switch to a new file *but* don't commit first.
  1349. if(S_OK == hr)
  1350. {
  1351. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  1352. DH_ASSERT(NULL != pStgRootOrg);
  1353. hr = CalculateCRCForDocFile(
  1354. pStgRootOrg,
  1355. VERIFY_EXC_TOPSTG_NAME,
  1356. &dwCRCOrg);
  1357. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1358. DH_TRACE ((DH_LVL_TRACE4,
  1359. TEXT("CRC for docfile: %#lx"), dwCRCOrg));
  1360. }
  1361. // Modify original docfile now, but don't commit the changes to root.
  1362. if (S_OK == hr)
  1363. {
  1364. hr = ModifyDocFile(
  1365. pTestVirtualDF,
  1366. pVirtualDFRoot,
  1367. pdgi,
  1368. pdgu,
  1369. dwStgMode,
  1370. FALSE);
  1371. DH_HRCHECK(hr, TEXT("ModifyDocFile")) ;
  1372. }
  1373. if (S_OK == hr)
  1374. {
  1375. DH_TRACE((
  1376. DH_LVL_TRACE1,
  1377. TEXT("ModifyDF-Rename/Destroy/Open/Close elem- passed as exp.")));
  1378. }
  1379. else
  1380. {
  1381. DH_TRACE((
  1382. DH_LVL_TRACE1,
  1383. TEXT("ModifyDF-Rename/Destry/Open/Close elem- failed, hr=0x%lx"),
  1384. hr));
  1385. }
  1386. // Calculate CRC for entire DocFile without the RootDocfile name for
  1387. // original DocFile after making changes, but not commiting these to
  1388. // root. Let this be the new CRC value.
  1389. if(S_OK == hr)
  1390. {
  1391. hr = CalculateCRCForDocFile(
  1392. pStgRootOrg,
  1393. VERIFY_EXC_TOPSTG_NAME,
  1394. &dwCRCNew);
  1395. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1396. DH_TRACE ((DH_LVL_TRACE4,
  1397. TEXT("CRC for docfile: %#lx"), dwCRCNew));
  1398. }
  1399. // Get the IRootStorage interface pointer by doing QueryInterface on it.
  1400. if(S_OK == hr)
  1401. {
  1402. hr = pVirtualDFRoot->QueryInterface(
  1403. IID_IRootStorage,
  1404. (LPVOID *) &pStgIRootStg);
  1405. DH_HRCHECK(hr, TEXT("VirtualCtrNode::QueryInterface")) ;
  1406. }
  1407. if (S_OK == hr)
  1408. {
  1409. DH_TRACE((
  1410. DH_LVL_TRACE1,
  1411. TEXT("VirtualCtrNode::QueryInterface completed successfully.")));
  1412. }
  1413. else
  1414. {
  1415. DH_TRACE((
  1416. DH_LVL_TRACE1,
  1417. TEXT("VirtualCtrNode::QueryInterface unsuccessful, hr=0x%lx."),
  1418. hr));
  1419. }
  1420. // Generates a new name for DocFile that we would switch to using the
  1421. // IRootStorage::SwitchToFile
  1422. if(S_OK == hr)
  1423. {
  1424. // Generate random name for new docfile that we would switch to
  1425. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pNewRootDocFileName);
  1426. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1427. }
  1428. //prepend drive so IRootStorage::SwitchToFile goes onto a different drive.
  1429. if(S_OK == hr && NULL != ptAlt)
  1430. {
  1431. LPTSTR ptszNewName = new TCHAR[_tcslen ((LPTSTR)pNewRootDocFileName)+4];
  1432. if (NULL != ptszNewName)
  1433. {
  1434. _stprintf (ptszNewName, TEXT("%s%s"), ptAlt, pNewRootDocFileName);
  1435. delete []pNewRootDocFileName;
  1436. pNewRootDocFileName = ptszNewName;
  1437. }
  1438. }
  1439. // Call IRootStorage::SwitchToFile. Therafter the IStorage would become
  1440. // assocaited with new switched to file rather than original file and all
  1441. // changes, including uncommitted ones, would be reflected to the new
  1442. // switched to file rather than original file.
  1443. if (S_OK == hr)
  1444. {
  1445. // Convert name to OLECHAR
  1446. hr =TStringToOleString(pNewRootDocFileName,&poszNewRootDocFileName);
  1447. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  1448. }
  1449. if(S_OK == hr)
  1450. {
  1451. // Call DeleteFile just to make sure that pNewRootDocFileName doesn't
  1452. // exist, before calling SwitchToFile
  1453. DeleteFile(pNewRootDocFileName);
  1454. DH_TRACE ((DH_LVL_TRACE1, TEXT("SwitchToFile: %s"), pNewRootDocFileName));
  1455. hr = pStgIRootStg->SwitchToFile(poszNewRootDocFileName);
  1456. DH_HRCHECK(hr, TEXT("IRootStorage::SwitchToFile")) ;
  1457. }
  1458. if (S_OK == hr)
  1459. {
  1460. DH_TRACE((
  1461. DH_LVL_TRACE1,
  1462. TEXT("IRootStorage::SwitchToFile completed successfully.")));
  1463. }
  1464. else
  1465. {
  1466. DH_TRACE((
  1467. DH_LVL_TRACE1,
  1468. TEXT("IRootStorage::SwitchToFile unsuccessful, hr=0x%lx."),
  1469. hr));
  1470. }
  1471. // Release the pStgIRootStg pointer
  1472. if(S_OK == hr)
  1473. {
  1474. // Release the Reference count that was added by QueryInterface call.
  1475. ulRef = pStgIRootStg->Release();
  1476. DH_ASSERT(1 == ulRef);
  1477. }
  1478. // Commit the Original DocFile.
  1479. if(S_OK == hr)
  1480. {
  1481. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1482. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1483. }
  1484. if (S_OK == hr)
  1485. {
  1486. DH_TRACE((
  1487. DH_LVL_TRACE1,
  1488. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1489. }
  1490. else
  1491. {
  1492. DH_TRACE((
  1493. DH_LVL_TRACE1,
  1494. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1495. hr));
  1496. }
  1497. // Close the Original DocFile.
  1498. if(S_OK == hr)
  1499. {
  1500. hr = pVirtualDFRoot->Close();
  1501. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1502. }
  1503. if (S_OK == hr)
  1504. {
  1505. DH_TRACE((
  1506. DH_LVL_TRACE1,
  1507. TEXT("VirtualCtrNode::Close completed successfully.")));
  1508. }
  1509. else
  1510. {
  1511. DH_TRACE((
  1512. DH_LVL_TRACE1,
  1513. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1514. hr));
  1515. }
  1516. // Open the new Root DocFile. The CRC will be computed on it, this
  1517. // is expected to match dwCRCNew that was calculated before.
  1518. if(S_OK == hr)
  1519. {
  1520. hr = StgOpenStorage(
  1521. poszNewRootDocFileName,
  1522. NULL,
  1523. dwRootMode,
  1524. NULL,
  1525. 0,
  1526. &pStgRootNew);
  1527. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  1528. }
  1529. // Calculate the CRC on this new root DocFile
  1530. if(S_OK == hr)
  1531. {
  1532. dwCRCTemp = 0;
  1533. hr = CalculateCRCForDocFile(
  1534. pStgRootNew,
  1535. VERIFY_EXC_TOPSTG_NAME,
  1536. &dwCRCTemp);
  1537. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1538. DH_TRACE ((DH_LVL_TRACE4,
  1539. TEXT("CRC for docfile: %#lx"), dwCRCTemp));
  1540. }
  1541. // Compare CRC's at this point. The CRC of this new docfile and the
  1542. // DocFile that was switched to and then modified should match.
  1543. if(S_OK == hr)
  1544. {
  1545. if(dwCRCNew == dwCRCTemp)
  1546. {
  1547. DH_TRACE((
  1548. DH_LVL_TRACE1,
  1549. TEXT("CRC's match of new & switched to file as exp")));
  1550. }
  1551. else
  1552. {
  1553. fPass = FALSE;
  1554. DH_TRACE((
  1555. DH_LVL_TRACE1,
  1556. TEXT("CRC's don't match of new & switched to file unexp")));
  1557. }
  1558. }
  1559. // Close the new root DocFile
  1560. if(S_OK == hr)
  1561. {
  1562. ulRef = pStgRootNew->Release();
  1563. DH_ASSERT(0 == ulRef);
  1564. pStgRootNew = NULL;
  1565. }
  1566. // Open the original Root DocFile again. The CRC would be calculated on
  1567. // this, it is expected to match dwCRCOrg, thereby verifying that because
  1568. // of SwitchToFile, the original file remained unchanged.
  1569. if(S_OK == hr)
  1570. {
  1571. hr = pVirtualDFRoot->Open(NULL, dwRootMode, NULL, 0);
  1572. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1573. }
  1574. if (S_OK == hr)
  1575. {
  1576. DH_TRACE((
  1577. DH_LVL_TRACE1,
  1578. TEXT("VirtualCtrNode::Open completed successfully.")));
  1579. }
  1580. else
  1581. {
  1582. DH_TRACE((
  1583. DH_LVL_TRACE1,
  1584. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  1585. hr));
  1586. }
  1587. // Calculate CRC for original DocFile without the RootDocfile name
  1588. if(S_OK == hr)
  1589. {
  1590. pStgRootOrg = NULL;
  1591. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  1592. DH_ASSERT(NULL != pStgRootOrg);
  1593. dwCRCTemp = 0;
  1594. hr = CalculateCRCForDocFile(
  1595. pStgRootOrg,
  1596. VERIFY_EXC_TOPSTG_NAME,
  1597. &dwCRCTemp);
  1598. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1599. DH_TRACE ((DH_LVL_TRACE4,
  1600. TEXT("CRC for docfile: %#lx"), dwCRCTemp));
  1601. }
  1602. // Compare CRC's of the this orginal docfile after reinstantiation and
  1603. // the original value before SwitchToFile was done. These should match.
  1604. if(S_OK == hr)
  1605. {
  1606. if(dwCRCTemp == dwCRCOrg)
  1607. {
  1608. DH_TRACE((
  1609. DH_LVL_TRACE1,
  1610. TEXT("CRC's match, original file unchanged as exp")));
  1611. }
  1612. else
  1613. {
  1614. fPass = FALSE;
  1615. DH_TRACE((
  1616. DH_LVL_TRACE1,
  1617. TEXT("CRC's don't match, original file changed unexp")));
  1618. }
  1619. }
  1620. // Close original root docfile.
  1621. if(S_OK == hr)
  1622. {
  1623. hr = pVirtualDFRoot->Close();
  1624. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1625. }
  1626. if (S_OK == hr)
  1627. {
  1628. DH_TRACE((
  1629. DH_LVL_TRACE1,
  1630. TEXT("VirtualCtrNode::Close completed successfully.")));
  1631. }
  1632. else
  1633. {
  1634. DH_TRACE((
  1635. DH_LVL_TRACE1,
  1636. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1637. hr));
  1638. }
  1639. // Get some info about the test
  1640. TCHAR szFileSystemInfoBuffer[10] = {TEXT(" :(")};
  1641. GetVolumeInformation (ptAlt,
  1642. NULL, //lpVolumeNameBuffer
  1643. 0, //nVolumeNameSize
  1644. NULL,
  1645. NULL,
  1646. NULL, //lpFileSystemFlags
  1647. &szFileSystemInfoBuffer[3],
  1648. sizeof (szFileSystemInfoBuffer)-4);
  1649. _tcscat (szFileSystemInfoBuffer, TEXT(")"));
  1650. if (NULL != ptAlt)
  1651. {
  1652. *szFileSystemInfoBuffer = *ptAlt;
  1653. }
  1654. // if everything goes well, log test as passed else failed.
  1655. if ((S_OK == hr) && (TRUE == fPass))
  1656. {
  1657. DH_LOG((LOG_PASS,
  1658. TEXT("Test variation IROOTSTGTEST_102 passed. %s"),
  1659. szFileSystemInfoBuffer) );
  1660. }
  1661. else
  1662. {
  1663. DH_LOG((LOG_FAIL,
  1664. TEXT("Test variation IROOTSTGTEST_102 failed, hr = 0x%lx. %s"),
  1665. hr,
  1666. szFileSystemInfoBuffer) );
  1667. DH_DUMPCMD((LOG_FAIL, TEXT(" /seed:%u %s%c"),
  1668. pTestChanceDF->GetSeed(),
  1669. NULL == ptAlt ? TEXT("") : TEXT("/altpath:"),
  1670. NULL == ptAlt ? TCHAR('\0') : TCHAR(*ptAlt)));
  1671. // test failed. make it look like it failed.
  1672. hr = FirstError (hr, E_FAIL);
  1673. }
  1674. // Cleanup
  1675. // Get the name of file, will be used later to delete the file
  1676. if(NULL != pVirtualDFRoot)
  1677. {
  1678. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  1679. if (pFileName != NULL)
  1680. {
  1681. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  1682. }
  1683. }
  1684. // Delete Chance docfile tree
  1685. if(NULL != pTestChanceDF)
  1686. {
  1687. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1688. pTestChanceDF->GetChanceDFRoot());
  1689. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1690. delete pTestChanceDF;
  1691. pTestChanceDF = NULL;
  1692. }
  1693. // Delete Virtual docfile tree
  1694. if(NULL != pTestVirtualDF)
  1695. {
  1696. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1697. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  1698. delete pTestVirtualDF;
  1699. pTestVirtualDF = NULL;
  1700. }
  1701. // Delete the original docfile on disk
  1702. if((S_OK == hr) && (NULL != pFileName))
  1703. {
  1704. if(FALSE == DeleteFile(pFileName))
  1705. {
  1706. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1707. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1708. }
  1709. }
  1710. // Delete the new docfile on disk
  1711. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  1712. {
  1713. if(FALSE == DeleteFile(pNewRootDocFileName))
  1714. {
  1715. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1716. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1717. }
  1718. }
  1719. // Delete temp string
  1720. if(NULL != pFileName)
  1721. {
  1722. delete pFileName;
  1723. pFileName = NULL;
  1724. }
  1725. if(NULL != pNewRootDocFileName)
  1726. {
  1727. delete pNewRootDocFileName;
  1728. pNewRootDocFileName = NULL;
  1729. }
  1730. if(NULL != poszNewRootDocFileName)
  1731. {
  1732. delete poszNewRootDocFileName;
  1733. poszNewRootDocFileName = NULL;
  1734. }
  1735. // Stop logging the test
  1736. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_102 finished")) );
  1737. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1738. return hr;
  1739. }
  1740. //----------------------------------------------------------------------------
  1741. //
  1742. // Test: IROOTSTGTEST_103
  1743. //
  1744. // Synopsis: A random docfile with random number of storages/streams is
  1745. // created/committed/closed. The root docfile is instantiated,
  1746. // and CRC is calculated for the docfile. It is then modified &
  1747. // CRC'd again. The test then calls QueryInterface to get an
  1748. // IRootStorage and SwitchesToFile on a new name. The new docfile
  1749. // is reverted, released, reinstantiated, and CRC'd. This CRC
  1750. // should match the *first* CRC of the original root DocfFile,
  1751. // rather than the CRC of the modified original root docfile.
  1752. // The original docfile is then instantiated and CRC'd. This
  1753. // CRC should match the *first* CRC of the original root docfile
  1754. // since we called SwitchToFile() before committing the changes.
  1755. //
  1756. // Arguments:[argc]
  1757. // [argv]
  1758. //
  1759. // Returns: HRESULT
  1760. //
  1761. // History: 26-July-1996 NarindK Created.
  1762. //
  1763. // Notes: This test runs in transacted, and transacted deny write modes.
  1764. //
  1765. // New Test Notes:
  1766. // 1. Old File: LTSVREV.CXX
  1767. // 2. Old name of test : LegitTransactedSaveAsRevert
  1768. // New Name of test : IROOTSTGTEST_103
  1769. // 3. To run the test, do the following at command prompt.
  1770. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  1771. // /t:IROOTSTGTEST-103 /dfRootMode:xactReadWriteShEx
  1772. // /dfStgMode:xactReadWriteShEx
  1773. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:0-3
  1774. // /t:IROOTSTGTEST-103 /dfRootMode:xactReadWriteShDenyW
  1775. // /dfStgMode:xactReadWriteShEx
  1776. //
  1777. // BUGNOTE: Conversion: IROOTSTGTEST-103 NO - root stgs not suppd in nss
  1778. //
  1779. // Note: The IRootStorage interface is used to switch the underlying disk file
  1780. // that IStorage Objects are being saved to. SwitchToFile makes a new
  1781. // copy of the file underlying this Istorage and associated IStorage
  1782. // object with this new file, rather than its current file, including
  1783. // uncommitted changes.
  1784. //-----------------------------------------------------------------------------
  1785. HRESULT IROOTSTGTEST_103a(int argc, char *argv[], LPTSTR ptAlt)
  1786. {
  1787. HRESULT hr = S_OK;
  1788. HRESULT hr2 = S_OK;
  1789. ChanceDF *pTestChanceDF = NULL;
  1790. VirtualDF *pTestVirtualDF = NULL;
  1791. VirtualCtrNode *pVirtualDFRoot = NULL;
  1792. LPTSTR pFileName = NULL;
  1793. LPTSTR pNewRootDocFileName = NULL;
  1794. LPOLESTR poszNewRootDocFileName = NULL;
  1795. DWORD dwCRCOrg = 0;
  1796. DWORD dwCRCNew = 0;
  1797. DWORD dwCRCTemp = 0;
  1798. DWORD dwRootMode = 0;
  1799. DWORD dwStgMode = 0;
  1800. LPSTORAGE pStgRootOrg = NULL;
  1801. LPSTORAGE pStgRootNew = NULL;
  1802. LPROOTSTORAGE pStgIRootStg = NULL;
  1803. DG_STRING *pdgu = NULL;
  1804. DG_INTEGER *pdgi = NULL;
  1805. USHORT usErr = 0;
  1806. ULONG ulRef = 0;
  1807. BOOL fPass = TRUE;
  1808. // Not for 2phase. Bail.
  1809. if (DoingDistrib ())
  1810. {
  1811. return S_OK;
  1812. }
  1813. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("IROOTSTGTEST_103"));
  1814. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1815. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_103 started.")) );
  1816. DH_TRACE((DH_LVL_TRACE1,
  1817. TEXT("IRootStorage-SwitchToFile, Save as Revert")));
  1818. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1819. if (S_OK == hr)
  1820. {
  1821. pTestChanceDF = new ChanceDF();
  1822. if(NULL == pTestChanceDF)
  1823. {
  1824. hr = E_OUTOFMEMORY;
  1825. }
  1826. }
  1827. if (S_OK == hr)
  1828. {
  1829. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1830. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1831. }
  1832. if (S_OK == hr)
  1833. {
  1834. dwRootMode = pTestChanceDF->GetRootMode();
  1835. dwStgMode = pTestChanceDF->GetStgMode();
  1836. DH_TRACE((
  1837. DH_LVL_TRACE1,
  1838. TEXT("Run Mode for IROOTSTGTEST_103, Access mode: %lx"),
  1839. dwRootMode));
  1840. }
  1841. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  1842. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  1843. // and VirtualStmNodes.
  1844. if (S_OK == hr)
  1845. {
  1846. pTestVirtualDF = new VirtualDF();
  1847. if(NULL == pTestVirtualDF)
  1848. {
  1849. hr = E_OUTOFMEMORY;
  1850. }
  1851. }
  1852. if (S_OK == hr)
  1853. {
  1854. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  1855. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  1856. }
  1857. if (S_OK == hr)
  1858. {
  1859. DH_TRACE((
  1860. DH_LVL_TRACE1,
  1861. TEXT("DocFile - CreateFromParams - successfully created.")));
  1862. }
  1863. else
  1864. {
  1865. DH_TRACE((
  1866. DH_LVL_TRACE1,
  1867. TEXT("DocFile - CreateFromParams - failed, hr = 0x%lx."),
  1868. hr));
  1869. }
  1870. if(S_OK == hr)
  1871. {
  1872. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1873. pVirtualDFRoot,
  1874. STGC_DEFAULT,
  1875. NODE_EXC_TOPSTG);
  1876. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  1877. }
  1878. // Commit root.
  1879. if(S_OK == hr)
  1880. {
  1881. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1882. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1883. }
  1884. if (S_OK == hr)
  1885. {
  1886. DH_TRACE((
  1887. DH_LVL_TRACE1,
  1888. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1889. }
  1890. else
  1891. {
  1892. DH_TRACE((
  1893. DH_LVL_TRACE1,
  1894. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1895. hr));
  1896. }
  1897. if(S_OK == hr)
  1898. {
  1899. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1900. pVirtualDFRoot,
  1901. NODE_EXC_TOPSTG);
  1902. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1903. }
  1904. // Get DG_INTEGER object pointer
  1905. if (S_OK == hr)
  1906. {
  1907. pdgi = pTestVirtualDF->GetDataGenInteger();
  1908. DH_ASSERT(NULL != pdgi) ;
  1909. }
  1910. // Get DG_STRING object pointer
  1911. if (S_OK == hr)
  1912. {
  1913. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1914. DH_ASSERT(NULL != pdgu) ;
  1915. }
  1916. // Calculate CRC for entire DocFile without the RootDocfile name for
  1917. // original DocFile before making changes. Then modify DocFile, but
  1918. // don't commit the changes to root. Get new CRC reflecting these changes
  1919. // and then switch to a new file *but* don't commit first.
  1920. if(S_OK == hr)
  1921. {
  1922. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  1923. DH_ASSERT(NULL != pStgRootOrg);
  1924. hr = CalculateCRCForDocFile(
  1925. pStgRootOrg,
  1926. VERIFY_EXC_TOPSTG_NAME,
  1927. &dwCRCOrg);
  1928. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1929. }
  1930. // Modify original docfile now, but dont commit the changes to root.
  1931. if (S_OK == hr)
  1932. {
  1933. hr = ModifyDocFile(
  1934. pTestVirtualDF,
  1935. pVirtualDFRoot,
  1936. pdgi,
  1937. pdgu,
  1938. dwStgMode,
  1939. FALSE);
  1940. DH_HRCHECK(hr, TEXT("ModifyDocFile")) ;
  1941. }
  1942. if (S_OK == hr)
  1943. {
  1944. DH_TRACE((
  1945. DH_LVL_TRACE1,
  1946. TEXT("ModifyDF-Rename/Destroy/Open/Close elem- passed as exp.")));
  1947. }
  1948. else
  1949. {
  1950. DH_TRACE((
  1951. DH_LVL_TRACE1,
  1952. TEXT("ModifyDF-Rename/Destry/Open/Close elem- failed, hr=0x%lx"),
  1953. hr));
  1954. }
  1955. // Calculate CRC for entire DocFile without the RootDocfile name for
  1956. // original DocFile after making changes, but not commiting these to
  1957. // root. Let this be the new CRC value.
  1958. if(S_OK == hr)
  1959. {
  1960. hr = CalculateCRCForDocFile(
  1961. pStgRootOrg,
  1962. VERIFY_EXC_TOPSTG_NAME,
  1963. &dwCRCNew);
  1964. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1965. }
  1966. // Get the IRootStorage interface pointer by doing QueryInterface on it.
  1967. if(S_OK == hr)
  1968. {
  1969. hr = pVirtualDFRoot->QueryInterface(
  1970. IID_IRootStorage,
  1971. (LPVOID *) &pStgIRootStg);
  1972. DH_HRCHECK(hr, TEXT("VirtualCtrNode::QueryInterface")) ;
  1973. }
  1974. if (S_OK == hr)
  1975. {
  1976. DH_TRACE((
  1977. DH_LVL_TRACE1,
  1978. TEXT("VirtualCtrNode::QueryInterface completed successfully.")));
  1979. }
  1980. else
  1981. {
  1982. DH_TRACE((
  1983. DH_LVL_TRACE1,
  1984. TEXT("VirtualCtrNode::QueryInterface unsuccessful, hr=0x%lx."),
  1985. hr));
  1986. }
  1987. // Generates a new name for DocFile that we would switch to using the
  1988. // IRootStorage::SwitchToFile
  1989. if(S_OK == hr)
  1990. {
  1991. // Generate random name for new docfile that we would switch to
  1992. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pNewRootDocFileName);
  1993. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1994. }
  1995. //prepend drive so IRootStorage::SwitchToFile goes onto a different drive.
  1996. if(S_OK == hr && NULL != ptAlt)
  1997. {
  1998. LPTSTR ptszNewName = new TCHAR[_tcslen ((LPTSTR)pNewRootDocFileName)+4];
  1999. if (NULL != ptszNewName)
  2000. {
  2001. _stprintf (ptszNewName, TEXT("%s%s"), ptAlt, pNewRootDocFileName);
  2002. delete []pNewRootDocFileName;
  2003. pNewRootDocFileName = ptszNewName;
  2004. }
  2005. }
  2006. // Call IRootStorage::SwitchToFile. Therafter the IStorage would become
  2007. // assocaited with new switched to file rather than original file and all
  2008. // changes, including uncommitted ones, would be reflected to the new
  2009. // switched to file rather than original file.
  2010. if (S_OK == hr)
  2011. {
  2012. // Convert name to OLECHAR
  2013. hr =TStringToOleString(pNewRootDocFileName,&poszNewRootDocFileName);
  2014. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2015. }
  2016. if(S_OK == hr)
  2017. {
  2018. // Call DeleteFile just to make sure that pNewRootDocFileName doesn't
  2019. // exist, before calling SwitchToFile
  2020. DeleteFile(pNewRootDocFileName);
  2021. DH_TRACE ((DH_LVL_TRACE1, TEXT("SwitchToFile: %s"), pNewRootDocFileName));
  2022. hr = pStgIRootStg->SwitchToFile(poszNewRootDocFileName);
  2023. DH_HRCHECK(hr, TEXT("IRootStorage::SwitchToFile")) ;
  2024. }
  2025. if (S_OK == hr)
  2026. {
  2027. DH_TRACE((
  2028. DH_LVL_TRACE1,
  2029. TEXT("IRootStorage::SwitchToFile completed successfully.")));
  2030. }
  2031. else
  2032. {
  2033. DH_TRACE((
  2034. DH_LVL_TRACE1,
  2035. TEXT("IRootStorage::SwitchToFile unsuccessful, hr=0x%lx."),
  2036. hr));
  2037. }
  2038. // Release the pStgIRootStg pointer
  2039. if(S_OK == hr)
  2040. {
  2041. // Release the Reference count that was added by QueryInterface call.
  2042. ulRef = pStgIRootStg->Release();
  2043. DH_ASSERT(1 == ulRef);
  2044. }
  2045. // Revert the Original DocFile. This revert will revert all the changes
  2046. // made by the ModifyDocFile call.
  2047. if(S_OK == hr)
  2048. {
  2049. hr = pVirtualDFRoot->Revert();
  2050. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2051. }
  2052. if (S_OK == hr)
  2053. {
  2054. DH_TRACE((
  2055. DH_LVL_TRACE1,
  2056. TEXT("VirtualCtrNode::Revert completed successfully.")));
  2057. }
  2058. else
  2059. {
  2060. DH_TRACE((
  2061. DH_LVL_TRACE1,
  2062. TEXT("VirtualCtrNode::Revert unsuccessful, hr=0x%lx."),
  2063. hr));
  2064. }
  2065. // Close the Original DocFile.
  2066. if(S_OK == hr)
  2067. {
  2068. hr = pVirtualDFRoot->Close();
  2069. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2070. }
  2071. if (S_OK == hr)
  2072. {
  2073. DH_TRACE((
  2074. DH_LVL_TRACE1,
  2075. TEXT("VirtualCtrNode::Close completed successfully.")));
  2076. }
  2077. else
  2078. {
  2079. DH_TRACE((
  2080. DH_LVL_TRACE1,
  2081. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2082. hr));
  2083. }
  2084. // Open the new Root DocFile. The CRC will be computed on it, this
  2085. // is expected to match dwCRCOrg that was calculated on original
  2086. // DocFile before changes were made to it, because all the changes
  2087. // were reverted by doing revert on root.
  2088. if(S_OK == hr)
  2089. {
  2090. hr = StgOpenStorage(
  2091. poszNewRootDocFileName,
  2092. NULL,
  2093. dwRootMode,
  2094. NULL,
  2095. 0,
  2096. &pStgRootNew);
  2097. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  2098. }
  2099. // Calculate the CRC on this new root DocFile
  2100. if(S_OK == hr)
  2101. {
  2102. dwCRCTemp = 0;
  2103. hr = CalculateCRCForDocFile(
  2104. pStgRootNew,
  2105. VERIFY_EXC_TOPSTG_NAME,
  2106. &dwCRCTemp);
  2107. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2108. }
  2109. // Compare CRC's at this point. The CRC of this new docfile and the
  2110. // original DocFile before any changes were made to it should match,
  2111. // since the changes made were reverted.
  2112. if(S_OK == hr)
  2113. {
  2114. if((dwCRCNew != dwCRCTemp) && (dwCRCOrg == dwCRCTemp))
  2115. {
  2116. DH_TRACE((
  2117. DH_LVL_TRACE1,
  2118. TEXT("crc's match of new and org before changes as exp")));
  2119. }
  2120. else
  2121. {
  2122. fPass = FALSE;
  2123. DH_TRACE((
  2124. DH_LVL_TRACE1,
  2125. TEXT("CRC's don't match of new & org before changes unexp")));
  2126. }
  2127. }
  2128. // Close the new root DocFile
  2129. if(S_OK == hr)
  2130. {
  2131. ulRef = pStgRootNew->Release();
  2132. DH_ASSERT(0 == ulRef);
  2133. pStgRootNew = NULL;
  2134. }
  2135. // Open the original Root DocFile again. The CRC would be calculated on
  2136. // this, it is expected to match dwCRCOrg, thereby verifying that because
  2137. // of SwitchToFile, the original file remained unchanged.
  2138. if(S_OK == hr)
  2139. {
  2140. hr = pVirtualDFRoot->Open(NULL, dwRootMode, NULL, 0);
  2141. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2142. }
  2143. if (S_OK == hr)
  2144. {
  2145. DH_TRACE((
  2146. DH_LVL_TRACE1,
  2147. TEXT("VirtualCtrNode::Open completed successfully.")));
  2148. }
  2149. else
  2150. {
  2151. DH_TRACE((
  2152. DH_LVL_TRACE1,
  2153. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  2154. hr));
  2155. }
  2156. // Calculate CRC for original DocFile without the RootDocfile name
  2157. if(S_OK == hr)
  2158. {
  2159. pStgRootOrg = NULL;
  2160. pStgRootOrg = pVirtualDFRoot->GetIStoragePointer();
  2161. DH_ASSERT(NULL != pStgRootOrg);
  2162. dwCRCTemp = 0;
  2163. hr = CalculateCRCForDocFile(
  2164. pStgRootOrg,
  2165. VERIFY_EXC_TOPSTG_NAME,
  2166. &dwCRCTemp);
  2167. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2168. }
  2169. // Compare CRC's of the this orginal docfile after reinstantiation and
  2170. // the original value before SwitchToFile was done. These should match.
  2171. if(S_OK == hr)
  2172. {
  2173. if(dwCRCTemp == dwCRCOrg)
  2174. {
  2175. DH_TRACE((
  2176. DH_LVL_TRACE1,
  2177. TEXT("CRC's match, original file unchanged as exp")));
  2178. }
  2179. else
  2180. {
  2181. fPass = FALSE;
  2182. DH_TRACE((
  2183. DH_LVL_TRACE1,
  2184. TEXT("CRC's don't match, original file changed unexp")));
  2185. }
  2186. }
  2187. // Close original root docfile.
  2188. if(S_OK == hr)
  2189. {
  2190. hr = pVirtualDFRoot->Close();
  2191. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2192. }
  2193. if (S_OK == hr)
  2194. {
  2195. DH_TRACE((
  2196. DH_LVL_TRACE1,
  2197. TEXT("VirtualCtrNode::Close completed successfully.")));
  2198. }
  2199. else
  2200. {
  2201. DH_TRACE((
  2202. DH_LVL_TRACE1,
  2203. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2204. hr));
  2205. }
  2206. // Get some info about the test
  2207. TCHAR szFileSystemInfoBuffer[10] = {TEXT(" :(")};
  2208. GetVolumeInformation (ptAlt,
  2209. NULL, //lpVolumeNameBuffer
  2210. 0, //nVolumeNameSize
  2211. NULL,
  2212. NULL,
  2213. NULL, //lpFileSystemFlags
  2214. &szFileSystemInfoBuffer[3],
  2215. sizeof (szFileSystemInfoBuffer)-4);
  2216. _tcscat (szFileSystemInfoBuffer, TEXT(")"));
  2217. if (NULL != ptAlt)
  2218. {
  2219. *szFileSystemInfoBuffer = *ptAlt;
  2220. }
  2221. // if everything goes well, log test as passed else failed.
  2222. if ((S_OK == hr) && (TRUE == fPass))
  2223. {
  2224. DH_LOG((LOG_PASS,
  2225. TEXT("Test variation IROOTSTGTEST_103 passed. %s"),
  2226. szFileSystemInfoBuffer) );
  2227. }
  2228. else
  2229. {
  2230. DH_LOG((LOG_FAIL,
  2231. TEXT("Test variation IROOTSTGTEST_103 failed, hr = 0x%lx. %s"),
  2232. hr,
  2233. szFileSystemInfoBuffer) );
  2234. DH_DUMPCMD((LOG_FAIL, TEXT(" /seed:%u %s%c"),
  2235. pTestChanceDF->GetSeed(),
  2236. NULL == ptAlt ? TEXT("") : TEXT("/altpath:"),
  2237. NULL == ptAlt ? TCHAR('\0') : TCHAR(*ptAlt)));
  2238. // test failed. make it look like it failed.
  2239. hr = FirstError (hr, E_FAIL);
  2240. }
  2241. // Cleanup
  2242. // Get the name of file, will be used later to delete the file
  2243. if(NULL != pVirtualDFRoot)
  2244. {
  2245. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  2246. if (pFileName != NULL)
  2247. {
  2248. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  2249. }
  2250. }
  2251. // Delete Chance docfile tree
  2252. if(NULL != pTestChanceDF)
  2253. {
  2254. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  2255. pTestChanceDF->GetChanceDFRoot());
  2256. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  2257. delete pTestChanceDF;
  2258. pTestChanceDF = NULL;
  2259. }
  2260. // Delete Virtual docfile tree
  2261. if(NULL != pTestVirtualDF)
  2262. {
  2263. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  2264. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  2265. delete pTestVirtualDF;
  2266. pTestVirtualDF = NULL;
  2267. }
  2268. // Delete the original docfile on disk
  2269. if((S_OK == hr) && (NULL != pFileName))
  2270. {
  2271. if(FALSE == DeleteFile(pFileName))
  2272. {
  2273. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2274. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2275. }
  2276. }
  2277. // Delete the new docfile on disk
  2278. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  2279. {
  2280. if(FALSE == DeleteFile(pNewRootDocFileName))
  2281. {
  2282. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2283. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2284. }
  2285. }
  2286. // Delete temp string
  2287. if(NULL != pFileName)
  2288. {
  2289. delete pFileName;
  2290. pFileName = NULL;
  2291. }
  2292. if(NULL != pNewRootDocFileName)
  2293. {
  2294. delete pNewRootDocFileName;
  2295. pNewRootDocFileName = NULL;
  2296. }
  2297. if(NULL != poszNewRootDocFileName)
  2298. {
  2299. delete poszNewRootDocFileName;
  2300. poszNewRootDocFileName = NULL;
  2301. }
  2302. // Stop logging the test
  2303. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation IROOTSTGTEST_103 finished")) );
  2304. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2305. return hr;
  2306. }