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.

5886 lines
160 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: stgtsts.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to IStorage interface
  9. //
  10. // Functions:
  11. //
  12. // History: 10-July-1996 NarindK Created.
  13. // 27-Mar-97 SCousens conversionified
  14. // 06-Aug-97 FarzanaR cleaned up tests for stress
  15. // BUGBUG : this file still requires to be cleaned up for stress.
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <dfheader.hxx>
  19. #pragma hdrstop
  20. #include "init.hxx"
  21. // externs
  22. extern BOOL g_fRevert;
  23. //----------------------------------------------------------------------------
  24. //
  25. // Test: STGTEST_100
  26. //
  27. // Synopsis: A root docfile and child IStorage are created and committed.
  28. // The child IStorage is released and then destroyed. The root is
  29. // then committed and a new child IStorage is created with the same
  30. // name as the original one. The child IStorage and root docfile
  31. // are then released without committing. The root docfile is then
  32. // reinstantiated. The test attempts to instantiate a child
  33. // IStorage with the name used for the original one. The test
  34. // verifies that no such IStorage exists because it should have been
  35. // deleted.
  36. //
  37. // Arguments:[argc]
  38. // [argv]
  39. //
  40. // Returns: HRESULT
  41. //
  42. // History: 10-July-1996 NarindK Created.
  43. //
  44. // Notes: This test runs in transacted, and transacted deny write modes
  45. //
  46. // New Test Notes:
  47. // 1. Old File: DFCOMREL.CXX
  48. // 2. Old name of test : MiscCommitRelease Test
  49. // New Name of test : STGTEST_100
  50. // 3. To run the test, do the following at command prompt.
  51. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-100
  52. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  53. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-100
  54. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  55. //
  56. // BUGNOTE: Conversion: STGTEST-100
  57. //
  58. //-----------------------------------------------------------------------------
  59. HRESULT STGTEST_100(int argc, char *argv[])
  60. {
  61. HRESULT hr = S_OK;
  62. ChanceDF *pTestChanceDF = NULL;
  63. VirtualDF *pTestVirtualDF = NULL;
  64. VirtualCtrNode *pVirtualDFRoot = NULL;
  65. DG_STRING *pdgu = NULL;
  66. USHORT usErr = 0;
  67. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  68. LPTSTR pRootNewChildStgName = NULL;
  69. DWORD dwRootMode = 0;
  70. DWORD dwStgMode = 0;
  71. BOOL fPass = TRUE;
  72. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_100"));
  73. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  74. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_100 started.")) );
  75. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt storage commit/release operations")) );
  76. // Create our ChanceDF and VirtualDF
  77. hr = CreateTestDocfile (argc,
  78. argv,
  79. &pVirtualDFRoot,
  80. &pTestVirtualDF,
  81. &pTestChanceDF);
  82. // if creating the docfile - bail here
  83. if (NULL != pTestChanceDF && DoingCreate ())
  84. {
  85. UINT ulSeed = pTestChanceDF->GetSeed ();
  86. CleanupTestDocfile (&pVirtualDFRoot,
  87. &pTestVirtualDF,
  88. &pTestChanceDF,
  89. FALSE);
  90. return (HRESULT)ulSeed;
  91. }
  92. if (S_OK == hr)
  93. {
  94. dwRootMode = pTestChanceDF->GetRootMode();
  95. dwStgMode = pTestChanceDF->GetStgMode();
  96. DH_TRACE((
  97. DH_LVL_TRACE1,
  98. TEXT("Run Mode for STGTEST_100, Access mode: %lx"),
  99. dwRootMode));
  100. }
  101. // Commit root. BUGBUG already commited
  102. if(S_OK == hr)
  103. {
  104. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  105. if (S_OK == hr)
  106. {
  107. DH_TRACE((
  108. DH_LVL_TRACE1,
  109. TEXT("VirtualCtrNode::Commit completed successfully.")));
  110. }
  111. else
  112. {
  113. DH_TRACE((
  114. DH_LVL_TRACE1,
  115. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  116. hr));
  117. }
  118. }
  119. // Get DG_STRING object pointer
  120. if (S_OK == hr)
  121. {
  122. pdgu = pTestVirtualDF->GetDataGenUnicode();
  123. DH_ASSERT(NULL != pdgu) ;
  124. }
  125. // Adds a new storage to the root storage.
  126. if(S_OK == hr)
  127. {
  128. // Generate random name for storage
  129. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  130. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  131. }
  132. if(S_OK == hr)
  133. {
  134. hr = AddStorage(
  135. pTestVirtualDF,
  136. pVirtualDFRoot,
  137. pRootNewChildStgName,
  138. dwStgMode,
  139. &pvcnRootNewChildStg);
  140. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  141. if(S_OK == hr)
  142. {
  143. DH_TRACE((
  144. DH_LVL_TRACE1,
  145. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  146. }
  147. else
  148. {
  149. DH_TRACE((
  150. DH_LVL_TRACE1,
  151. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  152. hr));
  153. }
  154. }
  155. // Commit root.
  156. if(S_OK == hr)
  157. {
  158. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  159. if (S_OK == hr)
  160. {
  161. DH_TRACE((
  162. DH_LVL_TRACE1,
  163. TEXT("VirtualCtrNode::Commit completed successfully.")));
  164. }
  165. else
  166. {
  167. DH_TRACE((
  168. DH_LVL_TRACE1,
  169. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  170. hr));
  171. }
  172. }
  173. // Release child storage
  174. if (S_OK == hr)
  175. {
  176. hr = pvcnRootNewChildStg->Close();
  177. if (S_OK == hr)
  178. {
  179. DH_TRACE((
  180. DH_LVL_TRACE1,
  181. TEXT("VirtualCtrNode::Close completed successfully.")));
  182. }
  183. else
  184. {
  185. DH_TRACE((
  186. DH_LVL_TRACE1,
  187. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  188. }
  189. }
  190. // Destroy child storage
  191. if (S_OK == hr)
  192. {
  193. hr = DestroyStorage(pTestVirtualDF, pvcnRootNewChildStg);
  194. if (S_OK == hr)
  195. {
  196. DH_TRACE((
  197. DH_LVL_TRACE1,
  198. TEXT("DestroyStorage completed successfully.")));
  199. }
  200. else
  201. {
  202. DH_TRACE((
  203. DH_LVL_TRACE1,
  204. TEXT("DestroyStorage unsuccessful, hr=0x%lx.")));
  205. }
  206. }
  207. // Commit root.
  208. if(S_OK == hr)
  209. {
  210. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  211. if (S_OK == hr)
  212. {
  213. DH_TRACE((
  214. DH_LVL_TRACE1,
  215. TEXT("VirtualCtrNode::Commit completed successfully.")));
  216. }
  217. else
  218. {
  219. DH_TRACE((
  220. DH_LVL_TRACE1,
  221. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  222. hr));
  223. }
  224. }
  225. // Add a child storage to root with same name
  226. if(S_OK == hr)
  227. {
  228. hr = AddStorage(
  229. pTestVirtualDF,
  230. pVirtualDFRoot,
  231. pRootNewChildStgName,
  232. dwStgMode,
  233. &pvcnRootNewChildStg);
  234. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  235. if(S_OK == hr)
  236. {
  237. DH_TRACE((
  238. DH_LVL_TRACE1,
  239. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  240. }
  241. else
  242. {
  243. DH_TRACE((
  244. DH_LVL_TRACE1,
  245. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  246. hr));
  247. }
  248. }
  249. // Release root w/o commiting
  250. if (S_OK == hr)
  251. {
  252. hr = pVirtualDFRoot->Close();
  253. if (S_OK == hr)
  254. {
  255. DH_TRACE((
  256. DH_LVL_TRACE1,
  257. TEXT("VirtualCtrNode::Close completed successfully.")));
  258. }
  259. else
  260. {
  261. DH_TRACE((
  262. DH_LVL_TRACE1,
  263. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  264. hr));
  265. }
  266. }
  267. // Release child storage
  268. if (S_OK == hr)
  269. {
  270. hr = pvcnRootNewChildStg->Close();
  271. if (S_OK == hr)
  272. {
  273. DH_TRACE((
  274. DH_LVL_TRACE1,
  275. TEXT("VirtualCtrNode::Close completed successfully.")));
  276. }
  277. else
  278. {
  279. DH_TRACE((
  280. DH_LVL_TRACE1,
  281. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  282. }
  283. }
  284. // Open root
  285. if (S_OK == hr)
  286. {
  287. hr = pVirtualDFRoot->OpenRoot(
  288. NULL,
  289. dwRootMode,
  290. NULL,
  291. 0);
  292. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  293. if (S_OK == hr)
  294. {
  295. DH_TRACE((
  296. DH_LVL_TRACE1,
  297. TEXT("VirtualCtrNode::Open completed successfully.")));
  298. }
  299. else
  300. {
  301. DH_TRACE((
  302. DH_LVL_TRACE1,
  303. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  304. hr));
  305. }
  306. }
  307. // Open child storage that was deleted first time, and second time when
  308. // created wasn't committed.
  309. if (S_OK == hr)
  310. {
  311. hr = pvcnRootNewChildStg->Open(
  312. NULL,
  313. dwStgMode,
  314. NULL,
  315. 0);
  316. if (STG_E_FILENOTFOUND == hr)
  317. {
  318. DH_TRACE((
  319. DH_LVL_TRACE1,
  320. TEXT("VirtualCtrNode::Open unsuccessful as exp,hr=0x%lx."),
  321. hr));
  322. }
  323. else
  324. {
  325. HRESULT hr2;
  326. DH_TRACE((
  327. DH_LVL_TRACE1,
  328. TEXT("Open should fail with STG_E_FILENOTFOUND, hr=0x%lx."),
  329. hr));
  330. fPass = FALSE;
  331. // close it coz we found & opened it
  332. if (S_OK == hr)
  333. {
  334. hr2 = pvcnRootNewChildStg->Close();
  335. DH_HRCHECK(hr2, TEXT("VirtualStgNode::Close")) ;
  336. }
  337. }
  338. hr = S_OK;
  339. }
  340. // Release root
  341. if (S_OK == hr)
  342. {
  343. hr = pVirtualDFRoot->Close();
  344. if (S_OK == hr)
  345. {
  346. DH_TRACE((
  347. DH_LVL_TRACE1,
  348. TEXT("VirtualCtrNode::Close completed successfully.")));
  349. }
  350. else
  351. {
  352. DH_TRACE((
  353. DH_LVL_TRACE1,
  354. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  355. hr));
  356. }
  357. }
  358. // if everything goes well, log test as passed else failed.
  359. if ((S_OK == hr) && (TRUE == fPass))
  360. {
  361. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_100 passed.")) );
  362. }
  363. else
  364. {
  365. DH_LOG((LOG_FAIL,
  366. TEXT("Test variation STGTEST_100 failed, hr=0x%lx."),
  367. hr) );
  368. // test failed. make sure it failed.
  369. hr = FirstError (hr, E_FAIL);
  370. }
  371. // Cleanup
  372. CleanupTestDocfile (&pVirtualDFRoot,
  373. &pTestVirtualDF,
  374. &pTestChanceDF,
  375. S_OK == hr);
  376. // Delete strings
  377. if(NULL != pRootNewChildStgName)
  378. {
  379. delete pRootNewChildStgName;
  380. pRootNewChildStgName = NULL;
  381. }
  382. // Stop logging the test
  383. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_100 finished")) );
  384. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  385. return hr;
  386. }
  387. //----------------------------------------------------------------------------
  388. //
  389. // Test: STGTEST_101
  390. //
  391. // Synopsis: Creates a root docfile, stats, and verifies that the CLSID == NULL
  392. // and state bits = 0. The test tries various random combinations
  393. // of setting state bits, changing class ids, committing changes
  394. // sometimes, reverting at others. After every event, the test
  395. // checks to ensure that the state bits and class id are set
  396. // correctly. It then creates a child IStorage and repeats the
  397. // above actions.
  398. //
  399. // Arguments:[argc]
  400. // [argv]
  401. //
  402. // Returns: HRESULT
  403. //
  404. // Notes: This test runs in direct, transacted, and transacted deny write
  405. // modes
  406. //
  407. // History: 14-July-1996 NarindK Created.
  408. //
  409. // New Test Notes:
  410. // 1. Old File: DFSET.CXX
  411. // 2. Old name of test : MiscSetItems Test
  412. // New Name of test : STGTEST_101
  413. // 3. To run the test, do the following at command prompt.
  414. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-101
  415. // /dfRootMode:dirReadWriteShEx
  416. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-101
  417. // /dfRootMode:xactReadWriteShEx
  418. // c. stgbase /seed:2 /dfdepth:1-3 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-101
  419. // /dfRootMode:xactReadWriteShDenyW
  420. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  421. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  422. //
  423. // BUGNOTE: Conversion: STGTEST-101
  424. //
  425. //-----------------------------------------------------------------------------
  426. HRESULT STGTEST_101(int argc, char *argv[])
  427. {
  428. HRESULT hr = S_OK;
  429. ChanceDF *pTestChanceDF = NULL;
  430. VirtualDF *pTestVirtualDF = NULL;
  431. VirtualCtrNode *pVirtualDFRoot = NULL;
  432. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  433. DG_STRING *pdgu = NULL;
  434. DG_INTEGER *pdgi = NULL;
  435. USHORT usErr = 0;
  436. LPTSTR pRootNewChildStgName = NULL;
  437. DWORD dwRootMode = 0;
  438. DWORD dwStgMode = 0;
  439. BOOL fPass = TRUE;
  440. STATSTG statStg;
  441. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_101"));
  442. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  443. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_101 started.")) );
  444. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt Misc setting state bits/class id'")) );
  445. // Create our ChanceDF and VirtualDF
  446. hr = CreateTestDocfile (argc,
  447. argv,
  448. &pVirtualDFRoot,
  449. &pTestVirtualDF,
  450. &pTestChanceDF);
  451. // if creating the docfile - bail here
  452. if (NULL != pTestChanceDF && DoingCreate ())
  453. {
  454. UINT ulSeed = pTestChanceDF->GetSeed ();
  455. CleanupTestDocfile (&pVirtualDFRoot,
  456. &pTestVirtualDF,
  457. &pTestChanceDF,
  458. FALSE);
  459. return (HRESULT)ulSeed;
  460. }
  461. if (S_OK == hr)
  462. {
  463. dwRootMode = pTestChanceDF->GetRootMode();
  464. dwStgMode = pTestChanceDF->GetStgMode();
  465. DH_TRACE((
  466. DH_LVL_TRACE1,
  467. TEXT("Run Mode for STGTEST_101, Access mode: %lx"),
  468. dwRootMode));
  469. }
  470. // Get DG_INTEGER object pointer
  471. if (S_OK == hr)
  472. {
  473. pdgi = pTestVirtualDF->GetDataGenInteger();
  474. DH_ASSERT(NULL != pdgi) ;
  475. }
  476. // Get DG_STRING object pointer
  477. if (S_OK == hr)
  478. {
  479. pdgu = pTestVirtualDF->GetDataGenUnicode();
  480. DH_ASSERT(NULL != pdgu) ;
  481. }
  482. // Call Stat on root.
  483. if (S_OK == hr)
  484. {
  485. statStg.grfStateBits = 0;
  486. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  487. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  488. if (S_OK == hr)
  489. {
  490. DH_TRACE((
  491. DH_LVL_TRACE1,
  492. TEXT("VirtualCtrNode::Stat completed successfully.")));
  493. }
  494. else
  495. {
  496. DH_TRACE((
  497. DH_LVL_TRACE1,
  498. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  499. hr));
  500. }
  501. // Check CLSID from STATSTG structure
  502. if((S_OK == hr) && (IsEqualCLSID(statStg.clsid, CLSID_NULL)))
  503. {
  504. DH_TRACE((
  505. DH_LVL_TRACE1,
  506. TEXT("Root DocFile has CLSID_NULL as expected.")));
  507. }
  508. else
  509. {
  510. DH_TRACE((
  511. DH_LVL_TRACE1,
  512. TEXT("Root DocFile doesn't have CLSID_NULL unexpectedly.")));
  513. fPass = FALSE;
  514. }
  515. // Check state bits from STATSTG structure.
  516. if((S_OK == hr) && (0 == statStg.grfStateBits))
  517. {
  518. DH_TRACE((
  519. DH_LVL_TRACE1,
  520. TEXT("Root DocFile has grfStateBits equal to 0 as expected.")));
  521. }
  522. else
  523. {
  524. DH_TRACE((
  525. DH_LVL_TRACE1,
  526. TEXT("Root DocFile doesn't have grfStateBits = 0 unexpectedly.")));
  527. fPass = FALSE;
  528. }
  529. }
  530. // Commit root.
  531. if(S_OK == hr)
  532. {
  533. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  534. if (S_OK == hr)
  535. {
  536. DH_TRACE((
  537. DH_LVL_TRACE1,
  538. TEXT("VirtualCtrNode::Commit completed successfully.")));
  539. }
  540. else
  541. {
  542. DH_TRACE((
  543. DH_LVL_TRACE1,
  544. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  545. hr));
  546. }
  547. }
  548. // Call SetItemsInStorage on Root
  549. if (S_OK == hr)
  550. {
  551. hr = SetItemsInStorage(pVirtualDFRoot, pdgi);
  552. DH_HRCHECK(hr, TEXT("SetItemsInStorage")) ;
  553. }
  554. // Adds a new storage to the root storage.
  555. if(S_OK == hr)
  556. {
  557. // Generate random name for storage
  558. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  559. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  560. }
  561. if(S_OK == hr)
  562. {
  563. hr = AddStorage(
  564. pTestVirtualDF,
  565. pVirtualDFRoot,
  566. pRootNewChildStgName,
  567. dwStgMode,
  568. &pvcnRootNewChildStg);
  569. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  570. if(S_OK == hr)
  571. {
  572. DH_TRACE((
  573. DH_LVL_TRACE1,
  574. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  575. }
  576. else
  577. {
  578. DH_TRACE((
  579. DH_LVL_TRACE1,
  580. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  581. hr));
  582. }
  583. }
  584. // Call Stat on new child storage.
  585. if (S_OK == hr)
  586. {
  587. statStg.grfStateBits = 0;
  588. hr = pvcnRootNewChildStg->Stat(&statStg, STATFLAG_NONAME);
  589. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  590. if (S_OK == hr)
  591. {
  592. DH_TRACE((
  593. DH_LVL_TRACE1,
  594. TEXT("VirtualCtrNode::Stat completed successfully.")));
  595. }
  596. else
  597. {
  598. DH_TRACE((
  599. DH_LVL_TRACE1,
  600. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  601. hr));
  602. }
  603. // Check CLSID from STATSTG structure
  604. if((S_OK == hr) && (IsEqualCLSID(statStg.clsid, CLSID_NULL)))
  605. {
  606. DH_TRACE((
  607. DH_LVL_TRACE1,
  608. TEXT("Child Storage has CLSID_NULL as expected.")));
  609. }
  610. else
  611. {
  612. DH_TRACE((
  613. DH_LVL_TRACE1,
  614. TEXT("Child storage doesn't have CLSID_NULL unexpectedly.")));
  615. fPass = FALSE;
  616. }
  617. // Check state bits from STATSTG structure.
  618. if((S_OK == hr) && (0 == statStg.grfStateBits))
  619. {
  620. DH_TRACE((
  621. DH_LVL_TRACE1,
  622. TEXT("Child Storage has grfStateBits equal to 0 as expected.")));
  623. }
  624. else
  625. {
  626. DH_TRACE((
  627. DH_LVL_TRACE1,
  628. TEXT("Child Storage doesn't have grfStateBits=0 unexpectedly.")));
  629. fPass = FALSE;
  630. }
  631. }
  632. // Commit root.
  633. if(S_OK == hr)
  634. {
  635. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  636. if (S_OK == hr)
  637. {
  638. DH_TRACE((
  639. DH_LVL_TRACE1,
  640. TEXT("VirtualCtrNode::Commit completed successfully.")));
  641. }
  642. else
  643. {
  644. DH_TRACE((
  645. DH_LVL_TRACE1,
  646. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  647. hr));
  648. }
  649. }
  650. // Call SetItemsInStorage on Child storage
  651. if (S_OK == hr)
  652. {
  653. hr = SetItemsInStorage(pvcnRootNewChildStg, pdgi);
  654. DH_HRCHECK(hr, TEXT("SetItemsInStorage")) ;
  655. }
  656. // Release child storage.
  657. if (S_OK == hr)
  658. {
  659. hr = pvcnRootNewChildStg->Close();
  660. if (S_OK == hr)
  661. {
  662. DH_TRACE((
  663. DH_LVL_TRACE1,
  664. TEXT("VirtualCtrNode::Close completed successfully.")));
  665. }
  666. else
  667. {
  668. DH_TRACE((
  669. DH_LVL_TRACE1,
  670. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  671. hr));
  672. }
  673. }
  674. // Release root.
  675. if (S_OK == hr)
  676. {
  677. hr = pVirtualDFRoot->Close();
  678. if (S_OK == hr)
  679. {
  680. DH_TRACE((
  681. DH_LVL_TRACE1,
  682. TEXT("VirtualCtrNode::Close completed successfully.")));
  683. }
  684. else
  685. {
  686. DH_TRACE((
  687. DH_LVL_TRACE1,
  688. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  689. hr));
  690. }
  691. }
  692. // if everything goes well, log test as passed else failed.
  693. if ((S_OK == hr) && (TRUE == fPass))
  694. {
  695. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_101 passed.")) );
  696. }
  697. else
  698. {
  699. DH_LOG((LOG_FAIL,
  700. TEXT("Test variation STGTEST_101 failed, hr=0x%lx."),
  701. hr) );
  702. // test failed. make sure it failed.
  703. hr = FirstError (hr, E_FAIL);
  704. }
  705. // Cleanup
  706. CleanupTestDocfile (&pVirtualDFRoot,
  707. &pTestVirtualDF,
  708. &pTestChanceDF,
  709. S_OK == hr);
  710. // Delete temp strings
  711. if(NULL != pRootNewChildStgName)
  712. {
  713. delete pRootNewChildStgName;
  714. pRootNewChildStgName = NULL;
  715. }
  716. // Stop logging the test
  717. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_101 finished")) );
  718. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  719. return hr;
  720. }
  721. //----------------------------------------------------------------------------
  722. //
  723. // Test: STGTEST_102
  724. //
  725. // Synopsis: The test attempts various illegitimate operations regarding the
  726. // renaming and deletion of contained IStorages.
  727. //
  728. // Arguments:[argc]
  729. // [argv]
  730. //
  731. // Returns: HRESULT
  732. //
  733. // Notes: This test runs in direct, transacted, and transacted deny write
  734. // modes
  735. //
  736. // History: 10-July-1996 NarindK Created.
  737. //
  738. // New Test Notes:
  739. // 1. Old File: IRENDEST.CXX
  740. // 2. Old name of test : IllegitRenDest Test
  741. // New Name of test : STGTEST_102
  742. // 3. To run the test, do the following at command prompt.
  743. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-102
  744. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /labmode
  745. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-102
  746. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /labmode
  747. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-102
  748. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  749. // /labmode
  750. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  751. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  752. //
  753. // BUGNOTE: Conversion: STGTEST-102
  754. //
  755. //-----------------------------------------------------------------------------
  756. HRESULT STGTEST_102(int argc, char *argv[])
  757. {
  758. HRESULT hr = S_OK;
  759. ChanceDF *pTestChanceDF = NULL;
  760. VirtualDF *pTestVirtualDF = NULL;
  761. VirtualCtrNode *pVirtualDFRoot = NULL;
  762. DG_STRING *pdgu = NULL;
  763. USHORT usErr = 0;
  764. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  765. VirtualCtrNode *pvcnRootNewChildStg0 = NULL;
  766. VirtualCtrNode *pvcnRootNewChildStg1 = NULL;
  767. LPTSTR pRootNewChildStgName = NULL;
  768. LPTSTR ptszNonExist = TEXT("NonExistStg");
  769. LPTSTR ptszNonExistNew = TEXT("NonExistStgNew");
  770. LPOLESTR poszNonExist = NULL;
  771. LPOLESTR poszNonExistNew = NULL;
  772. DWORD dwRootMode = 0;
  773. DWORD dwStgMode = 0;
  774. BOOL fPass = TRUE;
  775. ULONG i = 0;
  776. LPSTORAGE pStgRoot = NULL;
  777. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_102"));
  778. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  779. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_102 started.")) );
  780. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt illegitimate storage rename/del ops")) );
  781. // Create our ChanceDF and VirtualDF
  782. hr = CreateTestDocfile (argc,
  783. argv,
  784. &pVirtualDFRoot,
  785. &pTestVirtualDF,
  786. &pTestChanceDF);
  787. // if creating the docfile - bail here
  788. if (NULL != pTestChanceDF && DoingCreate ())
  789. {
  790. UINT ulSeed = pTestChanceDF->GetSeed ();
  791. CleanupTestDocfile (&pVirtualDFRoot,
  792. &pTestVirtualDF,
  793. &pTestChanceDF,
  794. FALSE);
  795. return (HRESULT)ulSeed;
  796. }
  797. if (S_OK == hr)
  798. {
  799. dwRootMode = pTestChanceDF->GetRootMode();
  800. dwStgMode = pTestChanceDF->GetStgMode();
  801. DH_TRACE((
  802. DH_LVL_TRACE1,
  803. TEXT("Run Mode for STGTEST_102, Access mode: %lx"),
  804. dwRootMode));
  805. }
  806. // Get DG_STRING object pointer
  807. if (S_OK == hr)
  808. {
  809. pdgu = pTestVirtualDF->GetDataGenUnicode();
  810. DH_ASSERT(NULL != pdgu) ;
  811. }
  812. // create two new IStorages and save their names.
  813. for (i=0;i<2;i++)
  814. {
  815. // Adds a new storage to the root storage.
  816. if(S_OK == hr)
  817. {
  818. // Generate random name for storage
  819. hr = GenerateRandomName(
  820. pdgu,
  821. MINLENGTH,
  822. MAXLENGTH,
  823. &pRootNewChildStgName);
  824. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  825. }
  826. if(S_OK == hr)
  827. {
  828. hr = AddStorage(
  829. pTestVirtualDF,
  830. pVirtualDFRoot,
  831. pRootNewChildStgName,
  832. dwStgMode,
  833. &pvcnRootNewChildStg);
  834. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  835. if(S_OK == hr)
  836. {
  837. DH_TRACE((
  838. DH_LVL_TRACE1,
  839. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  840. }
  841. else
  842. {
  843. DH_TRACE((
  844. DH_LVL_TRACE1,
  845. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  846. hr));
  847. }
  848. }
  849. // Commit root.
  850. if(S_OK == hr)
  851. {
  852. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  853. if (S_OK == hr)
  854. {
  855. DH_TRACE((
  856. DH_LVL_TRACE1,
  857. TEXT("VirtualCtrNode::Commit completed successfully.")));
  858. }
  859. else
  860. {
  861. DH_TRACE((
  862. DH_LVL_TRACE1,
  863. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  864. hr));
  865. }
  866. }
  867. // Release child storage
  868. if (S_OK == hr)
  869. {
  870. hr = pvcnRootNewChildStg->Close();
  871. if (S_OK == hr)
  872. {
  873. DH_TRACE((
  874. DH_LVL_TRACE1,
  875. TEXT("VirtualCtrNode::Close completed successfully.")));
  876. }
  877. else
  878. {
  879. DH_TRACE((
  880. DH_LVL_TRACE1,
  881. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  882. }
  883. }
  884. if(S_OK == hr)
  885. {
  886. if(i == 0)
  887. {
  888. pvcnRootNewChildStg0 = pvcnRootNewChildStg;
  889. }
  890. else
  891. {
  892. pvcnRootNewChildStg1 = pvcnRootNewChildStg;
  893. }
  894. }
  895. // Delete temp strings
  896. if(NULL != pRootNewChildStgName)
  897. {
  898. delete pRootNewChildStgName;
  899. pRootNewChildStgName = NULL;
  900. }
  901. // Break out of loop under failure conditions
  902. if(S_OK != hr)
  903. {
  904. break;
  905. }
  906. }
  907. // verify that the IStorages have been created by attempting to
  908. // instantiate them
  909. // Break out of loop under failure conditions
  910. for (i=0; i<2 && S_OK == hr; i++)
  911. {
  912. if(i == 0)
  913. {
  914. pvcnRootNewChildStg = pvcnRootNewChildStg0;
  915. }
  916. else
  917. {
  918. pvcnRootNewChildStg = pvcnRootNewChildStg1;
  919. }
  920. hr = pvcnRootNewChildStg->Open(
  921. NULL,
  922. dwStgMode | STGM_FAILIFTHERE,
  923. NULL,
  924. 0);
  925. if (S_OK == hr)
  926. {
  927. DH_TRACE((
  928. DH_LVL_TRACE1,
  929. TEXT("VirtualCtrNode::Open completed successfully.")));
  930. }
  931. else
  932. {
  933. DH_TRACE((
  934. DH_LVL_TRACE1,
  935. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  936. hr));
  937. }
  938. // Release child storage
  939. if (S_OK == hr)
  940. {
  941. hr = pvcnRootNewChildStg->Close();
  942. if (S_OK == hr)
  943. {
  944. DH_TRACE((
  945. DH_LVL_TRACE1,
  946. TEXT("VirtualCtrNode::Close completed successfully.")));
  947. }
  948. else
  949. {
  950. DH_TRACE((
  951. DH_LVL_TRACE1,
  952. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  953. }
  954. }
  955. }
  956. // Attempt to rename the storage to a name that already exists.
  957. if(S_OK == hr)
  958. {
  959. hr = pvcnRootNewChildStg0->Rename(
  960. pvcnRootNewChildStg1->GetVirtualCtrNodeName());
  961. if(STG_E_ACCESSDENIED == hr)
  962. {
  963. DH_TRACE((
  964. DH_LVL_TRACE1,
  965. TEXT("VirtualCtrNode::Rename failed as exp, hr = 0x%lx."),
  966. hr));
  967. hr = S_OK;
  968. }
  969. else
  970. {
  971. DH_TRACE((
  972. DH_LVL_TRACE1,
  973. TEXT("VirtualCtrNode::Rename didn't fail as exp, hr = 0x%lx."),
  974. hr));
  975. fPass = FALSE;
  976. }
  977. }
  978. // Attempt to rename an element that doesn't exist.
  979. // Covert the names to OLECHAR
  980. if(S_OK == hr)
  981. {
  982. // Convert test name to OLECHAR
  983. hr = TStringToOleString(ptszNonExist, &poszNonExist);
  984. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  985. }
  986. if(S_OK == hr)
  987. {
  988. // Convert test name to OLECHAR
  989. hr = TStringToOleString(ptszNonExistNew, &poszNonExistNew);
  990. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  991. }
  992. // First get IStorage pointer for root
  993. if(S_OK == hr)
  994. {
  995. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  996. DH_ASSERT(NULL != pStgRoot);
  997. hr = pStgRoot->RenameElement(
  998. poszNonExist,
  999. poszNonExistNew);
  1000. if(STG_E_FILENOTFOUND == hr)
  1001. {
  1002. DH_TRACE((
  1003. DH_LVL_TRACE1,
  1004. TEXT("IStorage::Rename failed as exp, hr = 0x%lx."),
  1005. hr));
  1006. hr = S_OK;
  1007. }
  1008. else
  1009. {
  1010. DH_TRACE((
  1011. DH_LVL_TRACE1,
  1012. TEXT("IStorage::Rename didn't fail as exp, hr = 0x%lx."),
  1013. hr));
  1014. fPass = FALSE;
  1015. }
  1016. }
  1017. // Attempt to delete an element that doesn't exist.
  1018. if(S_OK == hr)
  1019. {
  1020. hr = pStgRoot->DestroyElement(poszNonExist);
  1021. if(STG_E_FILENOTFOUND == hr)
  1022. {
  1023. DH_TRACE((
  1024. DH_LVL_TRACE1,
  1025. TEXT("IStorage::Destroy failed as exp, hr = 0x%lx."),
  1026. hr));
  1027. hr = S_OK;
  1028. }
  1029. else
  1030. {
  1031. DH_TRACE((
  1032. DH_LVL_TRACE1,
  1033. TEXT("IStorage::Destroy didn't fail as exp, hr = 0x%lx."),
  1034. hr));
  1035. fPass = FALSE;
  1036. }
  1037. }
  1038. // Release root
  1039. if (S_OK == hr)
  1040. {
  1041. hr = pVirtualDFRoot->Close();
  1042. if (S_OK == hr)
  1043. {
  1044. DH_TRACE((
  1045. DH_LVL_TRACE1,
  1046. TEXT("VirtualCtrNode::Close completed successfully.")));
  1047. }
  1048. else
  1049. {
  1050. DH_TRACE((
  1051. DH_LVL_TRACE1,
  1052. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1053. hr));
  1054. }
  1055. }
  1056. // if everything goes well, log test as passed else failed.
  1057. if ((S_OK == hr) && (TRUE == fPass))
  1058. {
  1059. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_102 passed.")) );
  1060. }
  1061. else
  1062. {
  1063. DH_LOG((LOG_FAIL,
  1064. TEXT("Test variation STGTEST_102 failed, hr=0x%lx."),
  1065. hr) );
  1066. // test failed. make sure it failed.
  1067. hr = FirstError (hr, E_FAIL);
  1068. }
  1069. // Cleanup
  1070. CleanupTestDocfile (&pVirtualDFRoot,
  1071. &pTestVirtualDF,
  1072. &pTestChanceDF,
  1073. S_OK == hr);
  1074. // Delete strings
  1075. if(NULL != poszNonExist)
  1076. {
  1077. delete poszNonExist;
  1078. poszNonExist = NULL;
  1079. }
  1080. if(NULL != poszNonExistNew)
  1081. {
  1082. delete poszNonExistNew;
  1083. poszNonExistNew = NULL;
  1084. }
  1085. // Stop logging the test
  1086. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_102 finished")) );
  1087. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1088. return hr;
  1089. }
  1090. //----------------------------------------------------------------------------
  1091. //
  1092. // Test: STGTEST_103
  1093. //
  1094. // Synopsis: A random docfile with some storages and some streams is generated.
  1095. // The root docfile is commited and closed.
  1096. // The root docfile is then instantiated & an enumerator is obtained. For
  1097. // each object found, the object is renamed to a new name but the old
  1098. // name is saved. An attempt is made to instantiate the object with
  1099. // the old name, this attempt should fail. The renamed object is then
  1100. // instantiated with the new name to verify that the rename worked. The
  1101. // object is then destroyed. This occurs for every object returned by
  1102. // the enumerator. The root docfile is then committed, the enumerator
  1103. // is released, and a new enumerator is obtained. The root docfile
  1104. // is enumerated to verify that no elements exist.
  1105. //
  1106. // Arguments:[argc]
  1107. // [argv]
  1108. //
  1109. // Returns: HRESULT
  1110. //
  1111. // Notes: This test runs in direct, transacted, and transacted deny write
  1112. // modes
  1113. //
  1114. // History: 11-July-1996 NarindK Created.
  1115. //
  1116. // New Test Notes:
  1117. // 1. Old File: LDRENDES.CXX
  1118. // 2. Old name of test : LegitRenDestNormal Test
  1119. // New Name of test : STGTEST_103
  1120. // 3. To run the test, do the following at command prompt.
  1121. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-103
  1122. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1123. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-103
  1124. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1125. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-103
  1126. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1127. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  1128. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  1129. //
  1130. // BUGNOTE: Conversion: STGTEST-103
  1131. //
  1132. //-----------------------------------------------------------------------------
  1133. HRESULT STGTEST_103(int argc, char *argv[])
  1134. {
  1135. HRESULT hr = S_OK;
  1136. ChanceDF *pTestChanceDF = NULL;
  1137. VirtualDF *pTestVirtualDF = NULL;
  1138. VirtualCtrNode *pVirtualDFRoot = NULL;
  1139. DG_STRING *pdgu = NULL;
  1140. USHORT usErr = 0;
  1141. DWORD dwRootMode = 0;
  1142. DWORD dwStgMode = 0;
  1143. LPENUMSTATSTG penumWalk = NULL;
  1144. LPMALLOC pMalloc = NULL;
  1145. LPSTORAGE pStgRoot = NULL;
  1146. LPSTORAGE pStgChild = NULL;
  1147. LPSTREAM pStmChild = NULL;
  1148. ULONG ulRef = 0;
  1149. BOOL fPass = TRUE;
  1150. BOOL fRenamedOK = TRUE;
  1151. LPTSTR ptszNewName = NULL;
  1152. LPOLESTR poszNewName = NULL;
  1153. LPTSTR ptszOldName = NULL;
  1154. LPOLESTR poszOldName = NULL;
  1155. STATSTG statStg;
  1156. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_103"));
  1157. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1158. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_103 started.")) );
  1159. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt legit rename/deleted ops on stgs/stms")));
  1160. // Create our ChanceDF and VirtualDF
  1161. hr = CreateTestDocfile (argc,
  1162. argv,
  1163. &pVirtualDFRoot,
  1164. &pTestVirtualDF,
  1165. &pTestChanceDF);
  1166. // if creating the docfile - bail here
  1167. if (NULL != pTestChanceDF && DoingCreate ())
  1168. {
  1169. UINT ulSeed = pTestChanceDF->GetSeed ();
  1170. CleanupTestDocfile (&pVirtualDFRoot,
  1171. &pTestVirtualDF,
  1172. &pTestChanceDF,
  1173. FALSE);
  1174. return (HRESULT)ulSeed;
  1175. }
  1176. if (S_OK == hr)
  1177. {
  1178. dwRootMode = pTestChanceDF->GetRootMode();
  1179. dwStgMode = pTestChanceDF->GetStgMode();
  1180. DH_TRACE((
  1181. DH_LVL_TRACE1,
  1182. TEXT("Run Mode for STGTEST_103, Access mode: %lx"),
  1183. dwRootMode));
  1184. }
  1185. // Commit substorages BUGBUG df already commited
  1186. if (S_OK == hr)
  1187. {
  1188. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1189. pVirtualDFRoot,
  1190. STGC_DEFAULT,
  1191. NODE_EXC_TOPSTG);
  1192. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1193. }
  1194. // Commit root.
  1195. if(S_OK == hr)
  1196. {
  1197. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1198. if (S_OK == hr)
  1199. {
  1200. DH_TRACE((
  1201. DH_LVL_TRACE1,
  1202. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1203. }
  1204. else
  1205. {
  1206. DH_TRACE((
  1207. DH_LVL_TRACE1,
  1208. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1209. hr));
  1210. }
  1211. }
  1212. // Release root and all substorages/streams too
  1213. if (S_OK == hr)
  1214. {
  1215. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1216. pVirtualDFRoot,
  1217. NODE_EXC_TOPSTG);
  1218. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1219. }
  1220. // Release root
  1221. if(S_OK == hr)
  1222. {
  1223. hr = pVirtualDFRoot->Close();
  1224. if (S_OK == hr)
  1225. {
  1226. DH_TRACE((
  1227. DH_LVL_TRACE1,
  1228. TEXT("VirtualCtrNode::Close completed successfully.")));
  1229. }
  1230. else
  1231. {
  1232. DH_TRACE((
  1233. DH_LVL_TRACE1,
  1234. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1235. hr));
  1236. }
  1237. }
  1238. // Reopen the root.
  1239. if (S_OK == hr)
  1240. {
  1241. hr = pVirtualDFRoot->OpenRoot(
  1242. NULL,
  1243. dwRootMode,
  1244. NULL,
  1245. 0);
  1246. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1247. if (S_OK == hr)
  1248. {
  1249. DH_TRACE((
  1250. DH_LVL_TRACE1,
  1251. TEXT("VirtualCtrNode::Open completed successfully.")));
  1252. }
  1253. else
  1254. {
  1255. DH_TRACE((
  1256. DH_LVL_TRACE1,
  1257. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  1258. hr));
  1259. }
  1260. }
  1261. // Call EnumElements to get a enumerator
  1262. if(S_OK == hr)
  1263. {
  1264. hr = pVirtualDFRoot->EnumElements(0, NULL, 0, &penumWalk);
  1265. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  1266. if(S_OK == hr)
  1267. {
  1268. DH_TRACE((
  1269. DH_LVL_TRACE1,
  1270. TEXT("VirtualCtrNode::EnumElements passed as expected")));
  1271. }
  1272. else
  1273. {
  1274. DH_TRACE((
  1275. DH_LVL_TRACE1,
  1276. TEXT("VirtualCtrNode::EnumElements unexpectedly failed hr=0x%lx"),
  1277. hr));
  1278. }
  1279. }
  1280. // First get pMalloc that would be used to free up the name string from
  1281. // STATSTG.
  1282. if ( S_OK == hr )
  1283. {
  1284. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  1285. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  1286. }
  1287. if(S_OK == hr)
  1288. {
  1289. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  1290. DH_ASSERT(NULL != pStgRoot);
  1291. // Get DG_STRING object pointer
  1292. if (S_OK == hr)
  1293. {
  1294. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1295. DH_ASSERT(NULL != pdgu) ;
  1296. }
  1297. }
  1298. while(S_OK == hr && S_OK == penumWalk->Next(1, &statStg, NULL))
  1299. {
  1300. // loop to rename object until a unique name is found, typically
  1301. // this will happen the first time and we'll fall out of the loop,
  1302. // but in the event of a duplicate name we have to keep trying.
  1303. fRenamedOK = FALSE;
  1304. while ((fRenamedOK == FALSE) && (S_OK == hr))
  1305. {
  1306. if(S_OK == hr)
  1307. {
  1308. // Generate random name for the element
  1309. hr = GenerateRandomName(
  1310. pdgu,
  1311. MINLENGTH,
  1312. MAXLENGTH,
  1313. &ptszNewName);
  1314. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1315. }
  1316. if(S_OK == hr)
  1317. {
  1318. // Convert above name to OLECHAR
  1319. hr = TStringToOleString(ptszNewName, &poszNewName);
  1320. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  1321. }
  1322. // Convert old name as retrieved from STATSTG structure to OLECHAR
  1323. // by first converting it to TSTR and then to OLECHAR.
  1324. if(S_OK == hr)
  1325. {
  1326. // Convert old name statStg.pwcsName to TCHAR
  1327. hr = OleStringToTString(statStg.pwcsName, &ptszOldName);
  1328. DH_HRCHECK(hr, TEXT("OleStringToTString")) ;
  1329. }
  1330. if(S_OK == hr)
  1331. {
  1332. // Now Convert old name to OLECHAR
  1333. hr = TStringToOleString(ptszOldName, &poszOldName);
  1334. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  1335. }
  1336. if(S_OK == hr)
  1337. {
  1338. // Rename the element to new name
  1339. hr = pStgRoot->RenameElement(
  1340. poszOldName,
  1341. poszNewName);
  1342. }
  1343. if(S_OK == hr)
  1344. {
  1345. DH_TRACE((
  1346. DH_LVL_TRACE1,
  1347. TEXT("IStorage::RenameElement successful as exp.")));
  1348. fRenamedOK = TRUE;
  1349. }
  1350. else
  1351. {
  1352. DH_TRACE((
  1353. DH_LVL_TRACE1,
  1354. TEXT("IStorage::RenameElement failed unexp, hr = 0x%lx."),
  1355. hr));
  1356. break;
  1357. }
  1358. } // ((fRenamedOK == FALSE) && (S_OK == hr))
  1359. // verify that the rename worked by first trying to instantiate
  1360. // the object with the original name (this should fail) and
  1361. // then instantiate it with the new name.
  1362. if((S_OK == hr) && (statStg.type == STGTY_STORAGE))
  1363. {
  1364. hr = pStgRoot->OpenStorage(
  1365. poszOldName,
  1366. NULL,
  1367. dwStgMode,
  1368. NULL,
  1369. 0,
  1370. &pStgChild);
  1371. if((NULL == pStgChild) && (STG_E_FILENOTFOUND == hr))
  1372. {
  1373. DH_TRACE((
  1374. DH_LVL_TRACE1,
  1375. TEXT("Instantiation with old name fail exp, hr = 0x%lx "),
  1376. hr));
  1377. hr = S_OK;
  1378. }
  1379. else
  1380. {
  1381. DH_TRACE((
  1382. DH_LVL_TRACE1,
  1383. TEXT("Instantiation with old name pass unexp, hr = 0x%lx"),
  1384. hr));
  1385. hr = S_FALSE;
  1386. }
  1387. if(S_OK == hr)
  1388. {
  1389. hr = pStgRoot->OpenStorage(
  1390. poszNewName,
  1391. NULL,
  1392. dwStgMode,
  1393. NULL,
  1394. 0,
  1395. &pStgChild);
  1396. DH_HRCHECK(hr, TEXT("IStorage::OpenStorage")) ;
  1397. if(S_OK == hr)
  1398. {
  1399. DH_TRACE((
  1400. DH_LVL_TRACE1,
  1401. TEXT("Instantiation with new name pass as exp")));
  1402. }
  1403. else
  1404. {
  1405. DH_TRACE((
  1406. DH_LVL_TRACE1,
  1407. TEXT("Instantiation with new name fail unexp, hr=0x%lx"),
  1408. hr));
  1409. }
  1410. }
  1411. // Release the element
  1412. if(NULL != pStgChild)
  1413. {
  1414. ulRef = pStgChild->Release();
  1415. DH_ASSERT(0 == ulRef);
  1416. pStgChild = NULL;
  1417. }
  1418. } // ((S_OK == hr) && (statStg.type == STGTY_STORAGE))
  1419. if ((S_OK == hr) && (statStg.type == STGTY_STREAM))
  1420. {
  1421. //element is a stream
  1422. hr = pStgRoot->OpenStream(
  1423. poszOldName,
  1424. NULL,
  1425. STGM_READ | STGM_SHARE_EXCLUSIVE,
  1426. 0,
  1427. &pStmChild);
  1428. if((NULL == pStmChild) && (STG_E_FILENOTFOUND == hr))
  1429. {
  1430. DH_TRACE((
  1431. DH_LVL_TRACE1,
  1432. TEXT("Instantiation with old name fail exp, hr = 0x%lx "),
  1433. hr));
  1434. hr = S_OK;
  1435. }
  1436. else
  1437. {
  1438. DH_TRACE((
  1439. DH_LVL_TRACE1,
  1440. TEXT("Instantiation with old name pass unexp,hr = 0x%lx "),
  1441. hr));
  1442. hr = S_FALSE;
  1443. }
  1444. if(S_OK == hr)
  1445. {
  1446. hr = pStgRoot->OpenStream(
  1447. poszNewName,
  1448. NULL,
  1449. STGM_READ | STGM_SHARE_EXCLUSIVE,
  1450. 0,
  1451. &pStmChild);
  1452. DH_HRCHECK(hr, TEXT("IStorage::OpenStream")) ;
  1453. if(S_OK == hr)
  1454. {
  1455. DH_TRACE((
  1456. DH_LVL_TRACE1,
  1457. TEXT("Instantiation with new name pass as exp")));
  1458. }
  1459. else
  1460. {
  1461. DH_TRACE((
  1462. DH_LVL_TRACE1,
  1463. TEXT("Instantiation with new name fail unexp, hr=0x%lx"),
  1464. hr));
  1465. }
  1466. }
  1467. // Release the element
  1468. if(NULL != pStmChild)
  1469. {
  1470. ulRef = pStmChild->Release();
  1471. DH_ASSERT(0 == ulRef);
  1472. pStmChild = NULL;
  1473. }
  1474. } // if ((S_OK == hr) && (statStg.type == STGTY_STREAM))
  1475. // Destroy the element
  1476. if(S_OK == hr)
  1477. {
  1478. hr = pStgRoot->DestroyElement(poszNewName);
  1479. DH_HRCHECK(hr, TEXT("IStorage::DestroyElement")) ;
  1480. if(S_OK == hr)
  1481. {
  1482. DH_TRACE((
  1483. DH_LVL_TRACE1,
  1484. TEXT("IStorage::DestoryElement succeeded as expected.")));
  1485. }
  1486. else
  1487. {
  1488. DH_TRACE((
  1489. DH_LVL_TRACE1,
  1490. TEXT("IStorage::DestoryElement fail unexp, hr = 0x%lx."),
  1491. hr));
  1492. }
  1493. }
  1494. // Release resources
  1495. if ( NULL != statStg.pwcsName)
  1496. {
  1497. pMalloc->Free(statStg.pwcsName);
  1498. statStg.pwcsName = NULL;
  1499. }
  1500. if(NULL != ptszNewName)
  1501. {
  1502. delete ptszNewName;
  1503. ptszNewName = NULL;
  1504. }
  1505. if(NULL != poszNewName)
  1506. {
  1507. delete poszNewName;
  1508. poszNewName = NULL;
  1509. }
  1510. if(NULL != ptszOldName)
  1511. {
  1512. delete ptszOldName;
  1513. ptszOldName = NULL;
  1514. }
  1515. if(NULL != poszOldName)
  1516. {
  1517. delete poszOldName;
  1518. poszOldName = NULL;
  1519. }
  1520. }
  1521. // Commit root.
  1522. if(S_OK == hr)
  1523. {
  1524. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1525. if (S_OK == hr)
  1526. {
  1527. DH_TRACE((
  1528. DH_LVL_TRACE1,
  1529. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1530. }
  1531. else
  1532. {
  1533. DH_TRACE((
  1534. DH_LVL_TRACE1,
  1535. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1536. hr));
  1537. }
  1538. }
  1539. // Release penumWalk
  1540. if(NULL != penumWalk)
  1541. {
  1542. ulRef = penumWalk->Release();
  1543. DH_ASSERT(0 == ulRef);
  1544. penumWalk = NULL;
  1545. }
  1546. // Call EnumElements to get a enumerator again
  1547. if(S_OK == hr)
  1548. {
  1549. hr = pVirtualDFRoot->EnumElements(0, NULL, 0, &penumWalk);
  1550. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  1551. if(S_OK == hr)
  1552. {
  1553. DH_TRACE((
  1554. DH_LVL_TRACE1,
  1555. TEXT("VirtualCtrNode::EnumElements passed as expected")));
  1556. }
  1557. else
  1558. {
  1559. DH_TRACE((
  1560. DH_LVL_TRACE1,
  1561. TEXT("VirtualCtrNode::EnumElements unexpectedly failed hr=0x%lx"),
  1562. hr));
  1563. }
  1564. }
  1565. // Try to call next on it. All elements should have been deleted
  1566. while(S_OK == hr && S_OK == penumWalk->Next(1, &statStg, NULL))
  1567. {
  1568. DH_TRACE((
  1569. DH_LVL_TRACE1,
  1570. TEXT("All elements should have been deleted.")));
  1571. fPass = FALSE;
  1572. }
  1573. // Release root
  1574. if(S_OK == hr)
  1575. {
  1576. hr = pVirtualDFRoot->Close();
  1577. if (S_OK == hr)
  1578. {
  1579. DH_TRACE((
  1580. DH_LVL_TRACE1,
  1581. TEXT("VirtualCtrNode::Close completed successfully.")));
  1582. }
  1583. else
  1584. {
  1585. DH_TRACE((
  1586. DH_LVL_TRACE1,
  1587. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1588. hr));
  1589. }
  1590. }
  1591. // Release pMalloc
  1592. if(NULL != pMalloc)
  1593. {
  1594. pMalloc->Release();
  1595. pMalloc = NULL;
  1596. }
  1597. // Release penumWalk
  1598. if(NULL != penumWalk)
  1599. {
  1600. ulRef = penumWalk->Release();
  1601. DH_ASSERT(0 == ulRef);
  1602. penumWalk = NULL;
  1603. }
  1604. // if everything goes well, log test as passed else failed.
  1605. if ((S_OK == hr) && (TRUE == fPass))
  1606. {
  1607. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_103 passed.")) );
  1608. }
  1609. else
  1610. {
  1611. DH_LOG((LOG_FAIL,
  1612. TEXT("Test variation STGTEST_103 failed, hr=0x%lx."),
  1613. hr) );
  1614. // test failed. make sure it failed.
  1615. hr = FirstError (hr, E_FAIL);
  1616. }
  1617. // Cleanup
  1618. CleanupTestDocfile (&pVirtualDFRoot,
  1619. &pTestVirtualDF,
  1620. &pTestChanceDF,
  1621. S_OK == hr);
  1622. // Stop logging the test
  1623. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_103 finished")) );
  1624. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1625. return hr;
  1626. }
  1627. //----------------------------------------------------------------------------
  1628. //
  1629. // Test: STGTEST_104
  1630. //
  1631. // Synopsis: This test first creates a root docfile. Two child IStorages
  1632. // are created inside of it.
  1633. // Child IStorage A is renamed to name C, child IStorage B is
  1634. // renamed to name A, child IStorage C (was originally A) is
  1635. // renames to B. The root docfile is committed. Verify
  1636. // proper renaming and no errors.
  1637. //
  1638. // Arguments:[argc]
  1639. // [argv]
  1640. //
  1641. // Returns: HRESULT
  1642. //
  1643. // Notes: This test runs in direct, transacted, and transacted deny write
  1644. // modes
  1645. //
  1646. // History: 11-July-1996 NarindK Created.
  1647. //
  1648. // New Test Notes:
  1649. // 1. Old File: LDRENSWP.CXX
  1650. // 2. Old name of test : LegitRenDestSwap Test
  1651. // New Name of test : STGTEST_104
  1652. // 3. To run the test, do the following at command prompt.
  1653. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-104
  1654. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1655. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-104
  1656. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1657. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-104
  1658. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1659. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  1660. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  1661. //
  1662. // BUGNOTE: Conversion: STGTEST-104
  1663. //
  1664. //-----------------------------------------------------------------------------
  1665. HRESULT STGTEST_104(int argc, char *argv[])
  1666. {
  1667. HRESULT hr = S_OK;
  1668. ChanceDF *pTestChanceDF = NULL;
  1669. VirtualDF *pTestVirtualDF = NULL;
  1670. VirtualCtrNode *pVirtualDFRoot = NULL;
  1671. DG_STRING *pdgu = NULL;
  1672. USHORT usErr = 0;
  1673. VirtualCtrNode *pvcnRootNewChildStg0 = NULL;
  1674. LPTSTR pRootNewChildStgName0 = NULL;
  1675. VirtualCtrNode *pvcnRootNewChildStg1 = NULL;
  1676. LPTSTR pRootNewChildStgName1 = NULL;
  1677. DWORD dwRootMode = 0;
  1678. DWORD dwStgMode = 0;
  1679. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_104"));
  1680. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1681. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_104 started.")) );
  1682. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt rename swap operations on child stgs")) );
  1683. // Create our ChanceDF and VirtualDF
  1684. hr = CreateTestDocfile (argc,
  1685. argv,
  1686. &pVirtualDFRoot,
  1687. &pTestVirtualDF,
  1688. &pTestChanceDF);
  1689. // if creating the docfile - bail here
  1690. if (NULL != pTestChanceDF && DoingCreate ())
  1691. {
  1692. UINT ulSeed = pTestChanceDF->GetSeed ();
  1693. CleanupTestDocfile (&pVirtualDFRoot,
  1694. &pTestVirtualDF,
  1695. &pTestChanceDF,
  1696. FALSE);
  1697. return (HRESULT)ulSeed;
  1698. }
  1699. if (S_OK == hr)
  1700. {
  1701. dwRootMode = pTestChanceDF->GetRootMode();
  1702. dwStgMode = pTestChanceDF->GetStgMode();
  1703. DH_TRACE((
  1704. DH_LVL_TRACE1,
  1705. TEXT("Run Mode for STGTEST_104, Access mode: %lx"),
  1706. dwRootMode));
  1707. }
  1708. // Get DG_STRING object pointer
  1709. if (S_OK == hr)
  1710. {
  1711. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1712. DH_ASSERT(NULL != pdgu) ;
  1713. }
  1714. // Adds first new child storage to the root storage.
  1715. if(S_OK == hr)
  1716. {
  1717. // Generate random name for first child storage
  1718. hr = GenerateRandomName(
  1719. pdgu,
  1720. MINLENGTH,
  1721. MAXLENGTH,
  1722. &pRootNewChildStgName0);
  1723. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1724. }
  1725. if(S_OK == hr)
  1726. {
  1727. hr = AddStorage(
  1728. pTestVirtualDF,
  1729. pVirtualDFRoot,
  1730. pRootNewChildStgName0,
  1731. dwStgMode,
  1732. &pvcnRootNewChildStg0);
  1733. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1734. if(S_OK == hr)
  1735. {
  1736. DH_TRACE((
  1737. DH_LVL_TRACE1,
  1738. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  1739. }
  1740. else
  1741. {
  1742. DH_TRACE((
  1743. DH_LVL_TRACE1,
  1744. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  1745. hr));
  1746. }
  1747. }
  1748. // Adds second new child storage to the root storage.
  1749. if(S_OK == hr)
  1750. {
  1751. // Generate random name for first child storage
  1752. hr = GenerateRandomName(
  1753. pdgu,
  1754. MINLENGTH,
  1755. MAXLENGTH,
  1756. &pRootNewChildStgName1);
  1757. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1758. }
  1759. if(S_OK == hr)
  1760. {
  1761. hr = AddStorage(
  1762. pTestVirtualDF,
  1763. pVirtualDFRoot,
  1764. pRootNewChildStgName1,
  1765. dwStgMode,
  1766. &pvcnRootNewChildStg1);
  1767. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1768. if(S_OK == hr)
  1769. {
  1770. DH_TRACE((
  1771. DH_LVL_TRACE1,
  1772. TEXT("VirtualStmNode::AddStorage completed successfully.")));
  1773. }
  1774. else
  1775. {
  1776. DH_TRACE((
  1777. DH_LVL_TRACE1,
  1778. TEXT("VirtualStmNode::AddStorage not successful, hr=0x%lx."),
  1779. hr));
  1780. }
  1781. }
  1782. // Commit root.
  1783. if(S_OK == hr)
  1784. {
  1785. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1786. if (S_OK == hr)
  1787. {
  1788. DH_TRACE((
  1789. DH_LVL_TRACE1,
  1790. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1791. }
  1792. else
  1793. {
  1794. DH_TRACE((
  1795. DH_LVL_TRACE1,
  1796. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1797. hr));
  1798. }
  1799. }
  1800. // Can't rename open storages so release the child storages
  1801. // Release first child storage.
  1802. if (S_OK == hr)
  1803. {
  1804. hr = pvcnRootNewChildStg0->Close();
  1805. if (S_OK == hr)
  1806. {
  1807. DH_TRACE((
  1808. DH_LVL_TRACE1,
  1809. TEXT("VirtualCtrNode::Close completed successfully.")));
  1810. }
  1811. else
  1812. {
  1813. DH_TRACE((
  1814. DH_LVL_TRACE1,
  1815. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  1816. }
  1817. }
  1818. // Release second child storage.
  1819. if (S_OK == hr)
  1820. {
  1821. hr = pvcnRootNewChildStg1->Close();
  1822. if (S_OK == hr)
  1823. {
  1824. DH_TRACE((
  1825. DH_LVL_TRACE1,
  1826. TEXT("VirtualCtrNode::Close completed successfully.")));
  1827. }
  1828. else
  1829. {
  1830. DH_TRACE((
  1831. DH_LVL_TRACE1,
  1832. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx.")));
  1833. }
  1834. }
  1835. // Attempt to rename the first child storage to RootDocFile's name
  1836. if(S_OK == hr)
  1837. {
  1838. DH_TRACE((
  1839. DH_LVL_TRACE1,
  1840. TEXT("pvcnRootNewChildStg0's old name, %s."),
  1841. pvcnRootNewChildStg0->GetVirtualCtrNodeName()));
  1842. hr = pvcnRootNewChildStg0->Rename(
  1843. pVirtualDFRoot->GetVirtualCtrNodeName());
  1844. if(S_OK == hr)
  1845. {
  1846. DH_TRACE((
  1847. DH_LVL_TRACE1,
  1848. TEXT("VirtualCtrNode::Rename passed as exp, new name %s."),
  1849. pvcnRootNewChildStg0->GetVirtualCtrNodeName()));
  1850. }
  1851. else
  1852. {
  1853. DH_TRACE((
  1854. DH_LVL_TRACE1,
  1855. TEXT("VirtualCtrNode::Rename failed unexp, hr = 0x%lx."),
  1856. hr));
  1857. }
  1858. }
  1859. // Attempt to rename the second child storage to first child stg's name
  1860. if(S_OK == hr)
  1861. {
  1862. DH_TRACE((
  1863. DH_LVL_TRACE1,
  1864. TEXT("pvcnRootNewChildStg1's old name, %s."),
  1865. pvcnRootNewChildStg1->GetVirtualCtrNodeName()));
  1866. hr = pvcnRootNewChildStg1->Rename(pRootNewChildStgName0);
  1867. if(S_OK == hr)
  1868. {
  1869. DH_TRACE((
  1870. DH_LVL_TRACE1,
  1871. TEXT("VirtualCtrNode::Rename passed as exp, new name %s."),
  1872. pvcnRootNewChildStg1->GetVirtualCtrNodeName()));
  1873. }
  1874. else
  1875. {
  1876. DH_TRACE((
  1877. DH_LVL_TRACE1,
  1878. TEXT("VirtualCtrNode::Rename failed unexp, hr = 0x%lx."),
  1879. hr));
  1880. }
  1881. }
  1882. // Attempt to rename third child storage (was originally first child
  1883. // storage) to second child stg's name
  1884. if(S_OK == hr)
  1885. {
  1886. DH_TRACE((
  1887. DH_LVL_TRACE1,
  1888. TEXT("pvcnRootNewChildStg0's old name, %s."),
  1889. pvcnRootNewChildStg0->GetVirtualCtrNodeName()));
  1890. hr = pvcnRootNewChildStg0->Rename(pRootNewChildStgName1);
  1891. if(S_OK == hr)
  1892. {
  1893. DH_TRACE((
  1894. DH_LVL_TRACE1,
  1895. TEXT("VirtualCtrNode::Rename passed as exp, new name %s."),
  1896. pvcnRootNewChildStg0->GetVirtualCtrNodeName()));
  1897. }
  1898. else
  1899. {
  1900. DH_TRACE((
  1901. DH_LVL_TRACE1,
  1902. TEXT("VirtualCtrNode::Rename failed unexp, hr = 0x%lx."),
  1903. hr));
  1904. }
  1905. }
  1906. // Release root
  1907. if (S_OK == hr)
  1908. {
  1909. hr = pVirtualDFRoot->Close();
  1910. if (S_OK == hr)
  1911. {
  1912. DH_TRACE((
  1913. DH_LVL_TRACE1,
  1914. TEXT("VirtualCtrNode::Close completed successfully.")));
  1915. }
  1916. else
  1917. {
  1918. DH_TRACE((
  1919. DH_LVL_TRACE1,
  1920. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1921. hr));
  1922. }
  1923. }
  1924. // if everything goes well, log test as passed else failed.
  1925. if (S_OK == hr)
  1926. {
  1927. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_104 passed.")) );
  1928. }
  1929. else
  1930. {
  1931. DH_LOG((LOG_FAIL,
  1932. TEXT("Test variation STGTEST_104 failed, hr=0x%lx."),
  1933. hr) );
  1934. }
  1935. // Cleanup
  1936. CleanupTestDocfile (&pVirtualDFRoot,
  1937. &pTestVirtualDF,
  1938. &pTestChanceDF,
  1939. S_OK == hr);
  1940. // Delete strings
  1941. if(NULL != pRootNewChildStgName0)
  1942. {
  1943. delete pRootNewChildStgName0;
  1944. pRootNewChildStgName0 = NULL;
  1945. }
  1946. if(NULL != pRootNewChildStgName1)
  1947. {
  1948. delete pRootNewChildStgName1;
  1949. pRootNewChildStgName1 = NULL;
  1950. }
  1951. // Stop logging the test
  1952. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_104 finished")) );
  1953. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1954. return hr;
  1955. }
  1956. //----------------------------------------------------------------------------
  1957. //
  1958. // Test: STGTEST_105
  1959. //
  1960. // Synopsis: A random docfile with random number of storages and streams is
  1961. // generated. Root is committed and closed.
  1962. // The root docfile is instantiated and the CRC is computed for the
  1963. // entire docfile. A new root docfile with a random name is then
  1964. // created and a CRC is generated for the empty root docfile. An
  1965. // enumerator is obtained on the source docfile, each element returned
  1966. // is MoveElementTo()'d the destination docfile. If fRevertAfterMove
  1967. // equals TRUE, the dest is reverted, else the dest is committed.
  1968. // The dest is released and reinstantiated and CRC'd. If the dest
  1969. // was reverted, the CRC is compared against the empty CRC for a match.
  1970. // Otherwise, we compare against the original root docfile CRC. The
  1971. // original file is CRC'd again to verify that STGMOVE_COPY didn't
  1972. // move the elements from orginal position but copied them, the CRC
  1973. // now computed should match with the one calculated originally.
  1974. //
  1975. // This tests differs from STGTEST-107 in the way that MoveElementTo
  1976. // is called with STGMOVE_COPY flag instead of STGMOVE_MOVE.
  1977. //
  1978. // Arguments:[argc]
  1979. // [argv]
  1980. //
  1981. // Returns: HRESULT
  1982. //
  1983. // Notes: This test runs in direct, transacted, and transacted deny write
  1984. // modes
  1985. //
  1986. // History: 12-July-1996 NarindK Created.
  1987. //
  1988. // New Test Notes:
  1989. // 1. Old File: LVROOT.CXX
  1990. // 2. Old name of test : LegitMoveDFToRootDF Test
  1991. // New Name of test : STGTEST_105
  1992. // 3. To run the test, do the following at command prompt.
  1993. // a. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-105
  1994. // /dfRootMode:dirReadWriteShEx
  1995. // b. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-105
  1996. // /dfRootMode:xactReadWriteShEx
  1997. // c. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-105
  1998. // /dfRootMode:xactReadWriteShDenyW
  1999. // d. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-105
  2000. // /dfRootMode:xactReadWriteShEx /frevertaftermove
  2001. // e. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-105
  2002. // /dfRootMode:xactReadWriteShDenyW /frevertaftermove
  2003. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  2004. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  2005. // BUGBUG: dont have /stdblock up yet. -scousens
  2006. // BUGBUG: note this fails sometimes for nssfiles need to dig deeper -scousens working seed=21590084
  2007. //
  2008. // In case of direct mode, the flag revertaftermove is not meaningful since
  2009. // changes are always directly written to disk doc file.
  2010. //
  2011. // BUGNOTE: Conversion: STGTEST-105
  2012. //
  2013. //-----------------------------------------------------------------------------
  2014. HRESULT STGTEST_105(int argc, char *argv[])
  2015. {
  2016. HRESULT hr = S_OK;
  2017. HRESULT hr2 = S_OK;
  2018. ChanceDF *pTestChanceDF = NULL;
  2019. VirtualDF *pTestVirtualDF = NULL;
  2020. VirtualCtrNode *pVirtualDFRoot = NULL;
  2021. DG_STRING *pdgu = NULL;
  2022. USHORT usErr = 0;
  2023. LPTSTR ptszRootNewDocFile = NULL;
  2024. LPOLESTR poszRootNewDocFile = NULL;
  2025. DWORD dwRootMode = 0;
  2026. LPSTORAGE pStgRoot1 = NULL;
  2027. LPSTORAGE pStgRoot2 = NULL;
  2028. LPSTORAGE pStgRoot11 = NULL;
  2029. ULONG ulRef = 0;
  2030. DWORD dwCRC1 = 0;
  2031. DWORD dwCRC2 = 0;
  2032. DWORD dwCRC3 = 0;
  2033. DWORD dwCRC4 = 0;
  2034. LPMALLOC pMalloc = NULL;
  2035. LPENUMSTATSTG penumWalk = NULL;
  2036. LPTSTR ptszElementName = NULL;
  2037. LPOLESTR poszElementName = NULL;
  2038. BOOL fPass = TRUE;
  2039. STATSTG statStg;
  2040. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_105"));
  2041. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2042. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_105 started.")) );
  2043. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt MoveElementTo-STGMOVE_COPY operations")));
  2044. // Create our ChanceDF and VirtualDF
  2045. hr = CreateTestDocfile (argc,
  2046. argv,
  2047. &pVirtualDFRoot,
  2048. &pTestVirtualDF,
  2049. &pTestChanceDF);
  2050. // if creating the docfile - bail here
  2051. if (NULL != pTestChanceDF && DoingCreate ())
  2052. {
  2053. UINT ulSeed = pTestChanceDF->GetSeed ();
  2054. CleanupTestDocfile (&pVirtualDFRoot,
  2055. &pTestVirtualDF,
  2056. &pTestChanceDF,
  2057. FALSE);
  2058. return (HRESULT)ulSeed;
  2059. }
  2060. if (S_OK == hr)
  2061. {
  2062. dwRootMode = pTestChanceDF->GetRootMode();
  2063. DH_TRACE((
  2064. DH_LVL_TRACE1,
  2065. TEXT("Run Mode for STGTEST_105, Access mode: %lx"),
  2066. dwRootMode));
  2067. }
  2068. // Commit substorages
  2069. if (S_OK == hr)
  2070. {
  2071. hr = ParseVirtualDFAndCommitAllOpenStgs(
  2072. pVirtualDFRoot,
  2073. STGC_DEFAULT,
  2074. NODE_EXC_TOPSTG);
  2075. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2076. }
  2077. // Commit root.
  2078. if(S_OK == hr)
  2079. {
  2080. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2081. if (S_OK == hr)
  2082. {
  2083. DH_TRACE((
  2084. DH_LVL_TRACE1,
  2085. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2086. }
  2087. else
  2088. {
  2089. DH_TRACE((
  2090. DH_LVL_TRACE1,
  2091. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  2092. hr));
  2093. }
  2094. }
  2095. // Release root and all substorages/streams too
  2096. if (S_OK == hr)
  2097. {
  2098. hr = ParseVirtualDFAndCloseOpenStgsStms(
  2099. pVirtualDFRoot,
  2100. NODE_INC_TOPSTG);
  2101. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2102. }
  2103. // Open the root only
  2104. if (S_OK == hr)
  2105. {
  2106. hr = pVirtualDFRoot->OpenRoot(
  2107. NULL,
  2108. dwRootMode,
  2109. NULL,
  2110. 0);
  2111. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2112. if (S_OK == hr)
  2113. {
  2114. DH_TRACE((
  2115. DH_LVL_TRACE1,
  2116. TEXT("VirtualCtrNode::Open completed successfully.")));
  2117. }
  2118. else
  2119. {
  2120. DH_TRACE((
  2121. DH_LVL_TRACE1,
  2122. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  2123. hr));
  2124. }
  2125. }
  2126. // Calculate CRC for entire DocFile without the RootDocfile name
  2127. if(S_OK == hr)
  2128. {
  2129. pStgRoot1 = pVirtualDFRoot->GetIStoragePointer();
  2130. DH_ASSERT(NULL != pStgRoot1);
  2131. hr = CalculateCRCForDocFile(pStgRoot1, VERIFY_EXC_TOPSTG_NAME, &dwCRC1);
  2132. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2133. }
  2134. // Get DG_STRING object pointer
  2135. if (S_OK == hr)
  2136. {
  2137. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2138. DH_ASSERT(NULL != pdgu) ;
  2139. }
  2140. if(S_OK == hr)
  2141. {
  2142. // Generate random name for first child storage
  2143. hr = GenerateRandomName(
  2144. pdgu,
  2145. MINLENGTH,
  2146. MAXLENGTH,
  2147. &ptszRootNewDocFile);
  2148. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2149. }
  2150. if(S_OK == hr)
  2151. {
  2152. // Convert RootDocFile name to OLECHAR
  2153. hr = TStringToOleString(ptszRootNewDocFile, &poszRootNewDocFile);
  2154. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2155. }
  2156. if (S_OK == hr)
  2157. {
  2158. hr = StgCreateDocfile(
  2159. poszRootNewDocFile,
  2160. dwRootMode,
  2161. 0,
  2162. &pStgRoot2);
  2163. DH_HRCHECK(hr, TEXT("StgCreateDocFile")) ;
  2164. if(S_OK == hr)
  2165. {
  2166. DH_TRACE((
  2167. DH_LVL_TRACE1,
  2168. TEXT("StgCreateDocfile successful as exp.")));
  2169. }
  2170. else
  2171. {
  2172. DH_TRACE((
  2173. DH_LVL_TRACE1,
  2174. TEXT("StgCreateDocfile not successful, hr=0x%lx."),
  2175. hr));
  2176. }
  2177. }
  2178. if(S_OK == hr)
  2179. {
  2180. hr = CalculateCRCForDocFile(pStgRoot2, VERIFY_EXC_TOPSTG_NAME, &dwCRC2);
  2181. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2182. }
  2183. // Call EnumElements to get a enumerator for first DocFile
  2184. if(S_OK == hr)
  2185. {
  2186. hr = pVirtualDFRoot->EnumElements(0, NULL, 0, &penumWalk);
  2187. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  2188. if(S_OK == hr)
  2189. {
  2190. DH_TRACE((
  2191. DH_LVL_TRACE1,
  2192. TEXT("VirtualCtrNode::EnumElements passed as expected")));
  2193. }
  2194. else
  2195. {
  2196. DH_TRACE((
  2197. DH_LVL_TRACE1,
  2198. TEXT("VirtualCtrNode::EnumElements unexpectedly failed hr=0x%lx"),
  2199. hr));
  2200. }
  2201. }
  2202. // First get pMalloc that would be used to free up the name string from
  2203. // STATSTG.
  2204. if ( S_OK == hr )
  2205. {
  2206. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  2207. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  2208. }
  2209. while((S_OK == hr) && (S_OK == penumWalk->Next(1, &statStg, NULL)))
  2210. {
  2211. if(S_OK == hr)
  2212. {
  2213. // Convert statStg.pwcsName to TCHAR
  2214. hr = OleStringToTString(statStg.pwcsName, &ptszElementName);
  2215. DH_HRCHECK(hr, TEXT("OleStringToTString")) ;
  2216. }
  2217. if(S_OK == hr)
  2218. {
  2219. // Now Convert old name to OLECHAR
  2220. hr = TStringToOleString(ptszElementName, &poszElementName);
  2221. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2222. }
  2223. if(S_OK == hr)
  2224. {
  2225. // Move the element to second DocFile
  2226. hr = pStgRoot1->MoveElementTo(
  2227. poszElementName,
  2228. pStgRoot2,
  2229. poszElementName,
  2230. STGMOVE_COPY);
  2231. DH_HRCHECK(hr, TEXT("IStorage::MoveElementTo")) ;
  2232. if(S_OK == hr)
  2233. {
  2234. DH_TRACE((
  2235. DH_LVL_TRACE1,
  2236. TEXT("IStorage::MoveElementTo passed as expected")));
  2237. }
  2238. else
  2239. {
  2240. DH_TRACE((
  2241. DH_LVL_TRACE1,
  2242. TEXT("IStorage::MoveElementTo unexpectedly failed hr=0x%lx"),
  2243. hr));
  2244. }
  2245. }
  2246. // Release resources
  2247. if ( NULL != statStg.pwcsName)
  2248. {
  2249. pMalloc->Free(statStg.pwcsName);
  2250. statStg.pwcsName = NULL;
  2251. }
  2252. if(NULL != ptszElementName)
  2253. {
  2254. delete ptszElementName;
  2255. ptszElementName = NULL;
  2256. }
  2257. if(NULL != poszElementName)
  2258. {
  2259. delete poszElementName;
  2260. poszElementName = NULL;
  2261. }
  2262. // Break out of loop in error case
  2263. if(S_OK != hr)
  2264. {
  2265. break;
  2266. }
  2267. }
  2268. // Commit or Revert the second docfile as the case may be.
  2269. if((S_OK == hr) && (FALSE == g_fRevert))
  2270. {
  2271. hr = pStgRoot2->Commit(STGC_DEFAULT);
  2272. if(S_OK == hr)
  2273. {
  2274. DH_TRACE((
  2275. DH_LVL_TRACE1,
  2276. TEXT("IStorage::Commit completed successfully.")));
  2277. }
  2278. else
  2279. {
  2280. DH_TRACE((
  2281. DH_LVL_TRACE1,
  2282. TEXT("IStorage::Commit unsuccessful, hr=0x%lx."),
  2283. hr));
  2284. }
  2285. }
  2286. else
  2287. if((S_OK == hr) && (TRUE == g_fRevert))
  2288. {
  2289. hr = pStgRoot2->Revert();
  2290. if(S_OK == hr)
  2291. {
  2292. DH_TRACE((
  2293. DH_LVL_TRACE1,
  2294. TEXT("IStorage::Revert completed successfully.")));
  2295. }
  2296. else
  2297. {
  2298. DH_TRACE((
  2299. DH_LVL_TRACE1,
  2300. TEXT("IStorage::Revert unsuccessful, hr=0x%lx."),
  2301. hr));
  2302. }
  2303. }
  2304. // Close the second DocFile
  2305. if(NULL != pStgRoot2)
  2306. {
  2307. ulRef = pStgRoot2->Release();
  2308. DH_ASSERT(0 == ulRef);
  2309. pStgRoot2 = NULL;
  2310. }
  2311. // Open it again and do StgIsStorageFile to verify.
  2312. if(S_OK == hr)
  2313. {
  2314. hr = StgOpenStorage(
  2315. poszRootNewDocFile,
  2316. NULL,
  2317. dwRootMode,
  2318. NULL,
  2319. 0,
  2320. &pStgRoot2);
  2321. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  2322. if (S_OK == hr)
  2323. {
  2324. DH_TRACE((
  2325. DH_LVL_TRACE1,
  2326. TEXT("StgOpenStorage completed successfully.")));
  2327. DH_ASSERT(NULL != pStgRoot2);
  2328. }
  2329. else
  2330. {
  2331. DH_TRACE((
  2332. DH_LVL_TRACE1,
  2333. TEXT("StgOpenStorage unsuccessful, hr=0x%lx."),
  2334. hr));
  2335. }
  2336. }
  2337. // Do StgIsStorageFile to verify
  2338. if(S_OK == hr)
  2339. {
  2340. hr = StgIsStorageFile(poszRootNewDocFile);
  2341. DH_HRCHECK(hr, TEXT("StgIsStorageFile")) ;
  2342. if (S_OK == hr)
  2343. {
  2344. DH_TRACE((
  2345. DH_LVL_TRACE1,
  2346. TEXT("StgIsStorageFile completed successfully.")));
  2347. }
  2348. else
  2349. {
  2350. DH_TRACE((
  2351. DH_LVL_TRACE1,
  2352. TEXT("StgIsStorageFile unsuccessful, hr=0x%lx."),
  2353. hr));
  2354. }
  2355. }
  2356. // Calculate CRC on this second Root DocFile.
  2357. if(S_OK == hr)
  2358. {
  2359. hr = CalculateCRCForDocFile(pStgRoot2, VERIFY_EXC_TOPSTG_NAME, &dwCRC3);
  2360. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2361. // Compare CRC's
  2362. if((S_OK == hr) && ( FALSE == g_fRevert))
  2363. {
  2364. if (dwCRC3 == dwCRC1)
  2365. {
  2366. DH_TRACE((
  2367. DH_LVL_TRACE1,
  2368. TEXT("CRC's for docfile1 & docfile2 after commit match.")));
  2369. }
  2370. else
  2371. {
  2372. DH_TRACE((
  2373. DH_LVL_TRACE1,
  2374. TEXT("CRC for docfile1 & docfile2 aftr commit don't match")));
  2375. fPass = FALSE;
  2376. }
  2377. }
  2378. else
  2379. if((S_OK == hr) && ( TRUE == g_fRevert))
  2380. {
  2381. if (dwCRC3 == dwCRC2)
  2382. {
  2383. DH_TRACE((
  2384. DH_LVL_TRACE1,
  2385. TEXT("CRC's for docfile2 before & after Revert match.")));
  2386. }
  2387. else
  2388. {
  2389. DH_TRACE((
  2390. DH_LVL_TRACE1,
  2391. TEXT("CRC for docfile2 before & after Revert don't match")));
  2392. fPass = FALSE;
  2393. }
  2394. }
  2395. }
  2396. // Close the second DocFile
  2397. if(NULL != pStgRoot2)
  2398. {
  2399. ulRef = pStgRoot2->Release();
  2400. DH_ASSERT(0 == ulRef);
  2401. pStgRoot2 = NULL;
  2402. }
  2403. // Release penumWalk
  2404. if(NULL != penumWalk)
  2405. {
  2406. ulRef = penumWalk->Release();
  2407. DH_ASSERT(0 == ulRef);
  2408. penumWalk = NULL;
  2409. }
  2410. // Release root
  2411. if (S_OK == hr)
  2412. {
  2413. hr = pVirtualDFRoot->Close();
  2414. if (S_OK == hr)
  2415. {
  2416. DH_TRACE((
  2417. DH_LVL_TRACE1,
  2418. TEXT("VirtualCtrNode::Close completed successfully.")));
  2419. }
  2420. else
  2421. {
  2422. DH_TRACE((
  2423. DH_LVL_TRACE1,
  2424. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2425. hr));
  2426. }
  2427. }
  2428. // Open the Root DocFile again to verify the STGMOVE_COPY flags specified
  2429. // while doing MoveElementTo
  2430. if (S_OK == hr)
  2431. {
  2432. hr = pVirtualDFRoot->OpenRoot(
  2433. NULL,
  2434. dwRootMode,
  2435. NULL,
  2436. 0);
  2437. if (S_OK == hr)
  2438. {
  2439. DH_TRACE((
  2440. DH_LVL_TRACE1,
  2441. TEXT("VirtualCtrNode::Open completed successfully.")));
  2442. }
  2443. else
  2444. {
  2445. DH_TRACE((
  2446. DH_LVL_TRACE1,
  2447. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  2448. hr));
  2449. }
  2450. }
  2451. // Now get the CRC again on the original DocFile to verify that flag
  2452. // STGMOVE_COPY copied the elements and not moved them, so this CRC
  2453. // should match with CRC originally obtained on this DocFile.
  2454. if(S_OK == hr)
  2455. {
  2456. pStgRoot11 = pVirtualDFRoot->GetIStoragePointer();
  2457. DH_ASSERT(NULL != pStgRoot11);
  2458. hr = CalculateCRCForDocFile(pStgRoot11, VERIFY_EXC_TOPSTG_NAME,&dwCRC4);
  2459. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2460. if(S_OK == hr)
  2461. {
  2462. if (dwCRC4 == dwCRC1)
  2463. {
  2464. DH_TRACE((
  2465. DH_LVL_TRACE1,
  2466. TEXT("CRC's for original docfle match after move as copy.")));
  2467. }
  2468. else
  2469. {
  2470. DH_TRACE((
  2471. DH_LVL_TRACE1,
  2472. TEXT("CRC for original DF don't match after move as copy.")));
  2473. fPass = FALSE;
  2474. }
  2475. }
  2476. }
  2477. // Release the first root docfile
  2478. if (S_OK == hr)
  2479. {
  2480. hr = pVirtualDFRoot->Close();
  2481. if (S_OK == hr)
  2482. {
  2483. DH_TRACE((
  2484. DH_LVL_TRACE1,
  2485. TEXT("VirtualCtrNode::Close completed successfully.")));
  2486. }
  2487. else
  2488. {
  2489. DH_TRACE((
  2490. DH_LVL_TRACE1,
  2491. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2492. hr));
  2493. }
  2494. }
  2495. // if everything goes well, log test as passed else failed.
  2496. if ((S_OK == hr) && (TRUE == fPass))
  2497. {
  2498. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_105 passed.")) );
  2499. }
  2500. else
  2501. {
  2502. DH_LOG((LOG_FAIL,
  2503. TEXT("Test variation STGTEST_105 failed, hr=0x%lx."),
  2504. hr) );
  2505. // test failed. make sure it failed.
  2506. hr = FirstError (hr, E_FAIL);
  2507. }
  2508. // Cleanup
  2509. CleanupTestDocfile (&pVirtualDFRoot,
  2510. &pTestVirtualDF,
  2511. &pTestChanceDF,
  2512. S_OK == hr);
  2513. // Release pMalloc
  2514. if(NULL != pMalloc)
  2515. {
  2516. pMalloc->Release();
  2517. pMalloc = NULL;
  2518. }
  2519. // Delete strings
  2520. if(NULL != poszRootNewDocFile)
  2521. {
  2522. delete poszRootNewDocFile;
  2523. poszRootNewDocFile = NULL;
  2524. }
  2525. // Delete the second docfile on disk
  2526. if((S_OK == hr) && (NULL != ptszRootNewDocFile))
  2527. {
  2528. if(FALSE == DeleteFile(ptszRootNewDocFile))
  2529. {
  2530. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2531. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2532. }
  2533. }
  2534. // Delete temp string
  2535. if(NULL != ptszRootNewDocFile)
  2536. {
  2537. delete ptszRootNewDocFile;
  2538. ptszRootNewDocFile = NULL;
  2539. }
  2540. // Stop logging the test
  2541. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_105 finished")) );
  2542. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2543. return hr;
  2544. }
  2545. //----------------------------------------------------------------------------
  2546. //
  2547. // Test: STGTEST_106
  2548. //
  2549. // Synopsis: This test first creates a root docfile. A child IStorage is
  2550. // then created with STGM_DENY_WRITE set. An IStream is created
  2551. // inside the child IStorage and a random number of bytes are
  2552. // written to it. The stream is released, the child and root
  2553. // IStorages are committed, and the child IStorage is released.
  2554. // The child IStorage is instantiated in STGM_TRANSACTED mode
  2555. // and then released. A count of the files in the current directory
  2556. // is then made and saved. The child IStorage is then instantiated
  2557. // in STGM_TRANSACTED | STGM_DENY_WRITE mode and another count is
  2558. // made. We then verify that only 1 scratch file was created,
  2559. // indicating that for STGM_DENY_WRITE mode, no copy is made of
  2560. // the instantiated IStorage.
  2561. //
  2562. // Arguments:[argc]
  2563. // [argv]
  2564. //
  2565. // Returns: HRESULT
  2566. //
  2567. // History: 26-July-1996 NarindK Created.
  2568. //
  2569. // Notes: THIS TEST IS NOT APPLICABLE WITH PRESENT STORAGE CODE, PRESENT
  2570. // ONLY FOR DOCUMENTATION/REFERENCE PURPOSES. BY DESIGN, THE PRESENT
  2571. // DOCFILE REQUIRES THAT ALL SUBSTORAGES/SUBSTREAMS BE CREATED/OPENED
  2572. // WITH STGM_SHARE_EXCLUSIVE FLAG.
  2573. //
  2574. // This test runs in transacted modes
  2575. //
  2576. // New Test Notes:
  2577. // 1. Old File: LITWWDW.CXX
  2578. // 2. Old name of test : LegitInstRootTwwDenyWrite test
  2579. // New Name of test : STGTEST_106
  2580. // 3. To run the test, do the following at command prompt.
  2581. // stgbase /t:STGTEST-106
  2582. // 4. To run for conversion, add /dfStgType:conversion to the above
  2583. // 5. To run for nssfile, add /dfStgType:nssfile to the above
  2584. //
  2585. // BUGNOTE: Conversion: STGTEST-106
  2586. //
  2587. //-----------------------------------------------------------------------------
  2588. HRESULT STGTEST_106(ULONG ulSeed)
  2589. {
  2590. #ifdef _MAC
  2591. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!STGTEST_106 crashes")) );
  2592. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!To be investigated")) );
  2593. return E_NOTIMPL;
  2594. #else
  2595. HRESULT hr = S_OK;
  2596. ChanceDF *pTestChanceDF = NULL;
  2597. VirtualDF *pTestVirtualDF = NULL;
  2598. VirtualCtrNode *pVirtualDFRoot = NULL;
  2599. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  2600. VirtualStmNode *pvsnNewChildStream = NULL;
  2601. DWORD dwRootMode = STGM_READWRITE | STGM_TRANSACTED;
  2602. DG_STRING *pdgu = NULL;
  2603. DG_INTEGER *pdgi = NULL;
  2604. USHORT usErr = 0;
  2605. LPTSTR ptszRootName = NULL;
  2606. LPTSTR ptszRootNewChildStgName = NULL;
  2607. LPTSTR ptszStreamName = NULL;
  2608. BOOL fPass = TRUE;
  2609. LPTSTR ptcsBuffer = NULL;
  2610. ULONG culWritten = 0;
  2611. ULONG culFilesInDirectory = 0;
  2612. ULONG cb = 0;
  2613. DWCRCSTM dwMemCRC;
  2614. DWCRCSTM dwActCRC;
  2615. CDFD cdfd;
  2616. dwMemCRC.dwCRCSum = dwActCRC.dwCRCSum = 0;
  2617. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_106"));
  2618. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2619. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_106 started.")) );
  2620. DH_TRACE((DH_LVL_TRACE1,
  2621. TEXT("Attempt operations on child storage in transacted mode.")));
  2622. if(S_OK == hr)
  2623. {
  2624. // Create a new DataGen object to create random UNICODE strings.
  2625. pdgu = new(NullOnFail) DG_STRING(ulSeed);
  2626. if (NULL == pdgu)
  2627. {
  2628. hr = E_OUTOFMEMORY;
  2629. }
  2630. else
  2631. {
  2632. //want to create only one seed. Once that has been done,
  2633. //use what we created from now on.
  2634. ulSeed = pdgu->GetSeed ();
  2635. }
  2636. }
  2637. // Generate RootDocFile name
  2638. if(S_OK == hr)
  2639. {
  2640. hr=GenerateRandomName(pdgu, MINLENGTH,MAXLENGTH, &ptszRootName);
  2641. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2642. }
  2643. if(S_OK == hr)
  2644. {
  2645. cdfd.cDepthMin = 0;
  2646. cdfd.cDepthMax = 0;
  2647. cdfd.cStgMin = 0;
  2648. cdfd.cStgMax = 0;
  2649. cdfd.cStmMin = 0;
  2650. cdfd.cStmMax = 0;
  2651. cdfd.cbStmMin = 0;
  2652. cdfd.cbStmMax = 0;
  2653. cdfd.ulSeed = ulSeed;
  2654. cdfd.dwRootMode = dwRootMode | STGM_CREATE;
  2655. hr = CreateTestDocfile (&cdfd,
  2656. ptszRootName,
  2657. &pVirtualDFRoot,
  2658. &pTestVirtualDF,
  2659. &pTestChanceDF);
  2660. DH_HRCHECK(hr, TEXT("CreateTestDocfile"));
  2661. }
  2662. // if creating the docfile - bail here
  2663. if (NULL != pTestChanceDF && DoingCreate ())
  2664. {
  2665. ulSeed = pTestChanceDF->GetSeed ();
  2666. CleanupTestDocfile (&pVirtualDFRoot,
  2667. &pTestVirtualDF,
  2668. &pTestChanceDF,
  2669. FALSE);
  2670. return (HRESULT)ulSeed;
  2671. }
  2672. // Adds a new storage to the root storage.
  2673. if(S_OK == hr)
  2674. {
  2675. // Generate random name for storage
  2676. hr = GenerateRandomName(
  2677. pdgu,
  2678. MINLENGTH,
  2679. MAXLENGTH,
  2680. &ptszRootNewChildStgName);
  2681. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2682. }
  2683. if(S_OK == hr)
  2684. {
  2685. hr = AddStorage(
  2686. pTestVirtualDF,
  2687. pVirtualDFRoot,
  2688. ptszRootNewChildStgName,
  2689. dwRootMode | STGM_SHARE_DENY_WRITE | STGM_FAILIFTHERE,
  2690. &pvcnRootNewChildStg);
  2691. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  2692. if(S_OK == hr)
  2693. {
  2694. DH_TRACE((
  2695. DH_LVL_TRACE1,
  2696. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  2697. }
  2698. else
  2699. {
  2700. DH_TRACE((
  2701. DH_LVL_TRACE1,
  2702. TEXT("VirtualCtrNode::AddStorage not successful, hr=0x%lx."),
  2703. hr));
  2704. }
  2705. }
  2706. // Now add a stream to this child storage
  2707. // Generate random name for stream
  2708. if(S_OK == hr)
  2709. {
  2710. hr=GenerateRandomName(pdgu, MINLENGTH,MAXLENGTH, &ptszStreamName);
  2711. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2712. }
  2713. // Get DG_INTEGER object pointer
  2714. if (S_OK == hr)
  2715. {
  2716. pdgi = pTestVirtualDF->GetDataGenInteger();
  2717. DH_ASSERT(NULL != pdgi);
  2718. }
  2719. if (S_OK == hr)
  2720. {
  2721. // Generate random size for stream.
  2722. usErr = pdgi->Generate(&cb, 1, USHRT_MAX);
  2723. if (DG_RC_SUCCESS != usErr)
  2724. {
  2725. hr = E_FAIL;
  2726. }
  2727. }
  2728. if(S_OK == hr)
  2729. {
  2730. hr = AddStream(
  2731. pTestVirtualDF,
  2732. pvcnRootNewChildStg,
  2733. ptszStreamName,
  2734. cb,
  2735. STGM_READWRITE |
  2736. STGM_SHARE_EXCLUSIVE |
  2737. STGM_FAILIFTHERE,
  2738. &pvsnNewChildStream);
  2739. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2740. if(S_OK == hr)
  2741. {
  2742. DH_TRACE((
  2743. DH_LVL_TRACE1,
  2744. TEXT("VirtualStmNode::AddStream completed successfully.")));
  2745. }
  2746. else
  2747. {
  2748. DH_TRACE((
  2749. DH_LVL_TRACE1,
  2750. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  2751. hr));
  2752. }
  2753. }
  2754. // Write random data into stream
  2755. if(S_OK == hr)
  2756. {
  2757. hr = GenerateRandomString(pdgu, cb, cb, &ptcsBuffer);
  2758. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  2759. }
  2760. if(S_OK == hr)
  2761. {
  2762. hr = pvsnNewChildStream->Write(
  2763. ptcsBuffer,
  2764. cb,
  2765. &culWritten);
  2766. DH_HRCHECK(hr, TEXT("IStream::Write")) ;
  2767. }
  2768. // Calculate the CRC for stream name and data
  2769. if(S_OK == hr)
  2770. {
  2771. hr = CalculateInMemoryCRCForStm(
  2772. pvsnNewChildStream,
  2773. ptcsBuffer,
  2774. cb,
  2775. &dwMemCRC);
  2776. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm")) ;
  2777. }
  2778. // Release stream
  2779. if (S_OK == hr)
  2780. {
  2781. hr = pvsnNewChildStream->Close();
  2782. if (S_OK == hr)
  2783. {
  2784. DH_TRACE((
  2785. DH_LVL_TRACE1,
  2786. TEXT("VirtualStmNode::Close completed successfully.")));
  2787. }
  2788. else
  2789. {
  2790. DH_TRACE((
  2791. DH_LVL_TRACE1,
  2792. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx.")));
  2793. }
  2794. }
  2795. // Now do a commit of child storage with STGC_ONLYIFCURRENT.
  2796. if (S_OK == hr)
  2797. {
  2798. hr = pvcnRootNewChildStg->Commit(STGC_ONLYIFCURRENT);
  2799. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2800. if (S_OK == hr)
  2801. {
  2802. DH_TRACE((
  2803. DH_LVL_TRACE1,
  2804. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2805. }
  2806. else
  2807. {
  2808. DH_TRACE((
  2809. DH_LVL_TRACE1,
  2810. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  2811. hr));
  2812. }
  2813. }
  2814. // Now do a commit of root storage with STGC_ONLYIFCURRENT.
  2815. if (S_OK == hr)
  2816. {
  2817. hr = pVirtualDFRoot->Commit(STGC_ONLYIFCURRENT);
  2818. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2819. if (S_OK == hr)
  2820. {
  2821. DH_TRACE((
  2822. DH_LVL_TRACE1,
  2823. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2824. }
  2825. else
  2826. {
  2827. DH_TRACE((
  2828. DH_LVL_TRACE1,
  2829. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  2830. hr));
  2831. }
  2832. }
  2833. // Close the child storage
  2834. if (S_OK == hr)
  2835. {
  2836. hr = pvcnRootNewChildStg->Close();
  2837. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2838. if (S_OK == hr)
  2839. {
  2840. DH_TRACE((
  2841. DH_LVL_TRACE1,
  2842. TEXT("VirtualCtrNode::Close completed successfully.")));
  2843. }
  2844. else
  2845. {
  2846. DH_TRACE((
  2847. DH_LVL_TRACE1,
  2848. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2849. hr));
  2850. }
  2851. }
  2852. // Open the child storage
  2853. if (S_OK == hr)
  2854. {
  2855. hr = pvcnRootNewChildStg->Open(
  2856. NULL,
  2857. dwRootMode | STGM_SHARE_EXCLUSIVE,
  2858. NULL,
  2859. 0);
  2860. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2861. if (S_OK == hr)
  2862. {
  2863. DH_TRACE((
  2864. DH_LVL_TRACE1,
  2865. TEXT("VirtualCtrNode::Open completed successfully.")));
  2866. }
  2867. else
  2868. {
  2869. DH_TRACE((
  2870. DH_LVL_TRACE1,
  2871. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  2872. hr));
  2873. }
  2874. }
  2875. // Close the child storage
  2876. if (S_OK == hr)
  2877. {
  2878. hr = pvcnRootNewChildStg->Close();
  2879. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2880. if (S_OK == hr)
  2881. {
  2882. DH_TRACE((
  2883. DH_LVL_TRACE1,
  2884. TEXT("VirtualCtrNode::Close completed successfully.")));
  2885. }
  2886. else
  2887. {
  2888. DH_TRACE((
  2889. DH_LVL_TRACE1,
  2890. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2891. hr));
  2892. }
  2893. }
  2894. // count number of files in directory
  2895. if (S_OK == hr)
  2896. {
  2897. culFilesInDirectory = CountFilesInDirectory(WILD_MASK);
  2898. }
  2899. // Open the with STGM_SHARE_DENY_WRITE
  2900. if (S_OK == hr)
  2901. {
  2902. hr = pvcnRootNewChildStg->Open(
  2903. NULL,
  2904. dwRootMode | STGM_SHARE_DENY_WRITE,
  2905. NULL,
  2906. 0);
  2907. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2908. if (S_OK == hr)
  2909. {
  2910. DH_TRACE((
  2911. DH_LVL_TRACE1,
  2912. TEXT("VirtualCtrNode::Open completed successfully.")));
  2913. }
  2914. else
  2915. {
  2916. DH_TRACE((
  2917. DH_LVL_TRACE1,
  2918. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  2919. hr));
  2920. }
  2921. }
  2922. // Check number of files
  2923. if(S_OK == hr)
  2924. {
  2925. if((culFilesInDirectory + 1) != CountFilesInDirectory(WILD_MASK))
  2926. {
  2927. DH_TRACE((
  2928. DH_LVL_TRACE1,
  2929. TEXT(">1 scratch file unexp STGM_SHARE_DENY_WRITE inst.")));
  2930. hr = S_FALSE;
  2931. }
  2932. else
  2933. {
  2934. DH_TRACE((
  2935. DH_LVL_TRACE1,
  2936. TEXT("1 scratchfile as exp STGM_SHARE_DENY_WRITE inst")));
  2937. }
  2938. }
  2939. // OpenStream
  2940. if (S_OK == hr)
  2941. {
  2942. hr = pvsnNewChildStream->Open(
  2943. NULL,
  2944. dwRootMode | STGM_SHARE_DENY_WRITE,
  2945. 0);
  2946. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  2947. if (S_OK == hr)
  2948. {
  2949. DH_TRACE((
  2950. DH_LVL_TRACE1,
  2951. TEXT("VirtualStmNode::Open completed successfully.")));
  2952. }
  2953. else
  2954. {
  2955. DH_TRACE((
  2956. DH_LVL_TRACE1,
  2957. TEXT("VirtualStmNode::Open unsuccessful, hr=0x%lx."),
  2958. hr));
  2959. }
  2960. }
  2961. // Read stream, CRC and verify
  2962. if(S_OK == hr)
  2963. {
  2964. hr = ReadAndCalculateDiskCRCForStm(pvsnNewChildStream,&dwActCRC);
  2965. DH_HRCHECK(hr, TEXT("ReadAndCalculateDiskCRCForStm")) ;
  2966. if (S_OK == hr)
  2967. {
  2968. DH_TRACE((
  2969. DH_LVL_TRACE1,
  2970. TEXT("ReadAndCalculateDiskCRCForStm function successful.")));
  2971. if(dwActCRC.dwCRCSum == dwMemCRC.dwCRCSum)
  2972. {
  2973. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's for pvsnNewChildStream match.")));
  2974. }
  2975. else
  2976. {
  2977. DH_TRACE((
  2978. DH_LVL_TRACE1,
  2979. TEXT("CRC's for pvsnNewChildStream don't match.")));
  2980. fPass = FALSE;
  2981. }
  2982. }
  2983. else
  2984. {
  2985. DH_TRACE((
  2986. DH_LVL_TRACE1,
  2987. TEXT("ReadAndCalculateDiskCRCForStm not successful, hr=0x%lx."),
  2988. hr));
  2989. }
  2990. }
  2991. // Close the stream in child storage
  2992. if (S_OK == hr)
  2993. {
  2994. hr = pvsnNewChildStream->Close();
  2995. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  2996. if (S_OK == hr)
  2997. {
  2998. DH_TRACE((
  2999. DH_LVL_TRACE1,
  3000. TEXT("VirtualStmNode::Close completed successfully.")));
  3001. }
  3002. else
  3003. {
  3004. DH_TRACE((
  3005. DH_LVL_TRACE1,
  3006. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3007. hr));
  3008. }
  3009. }
  3010. // Close the child storage
  3011. if (S_OK == hr)
  3012. {
  3013. hr = pvcnRootNewChildStg->Close();
  3014. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  3015. if (S_OK == hr)
  3016. {
  3017. DH_TRACE((
  3018. DH_LVL_TRACE1,
  3019. TEXT("VirtualCtrNode::Close completed successfully.")));
  3020. }
  3021. else
  3022. {
  3023. DH_TRACE((
  3024. DH_LVL_TRACE1,
  3025. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3026. hr));
  3027. }
  3028. }
  3029. // Close the root
  3030. if (S_OK == hr)
  3031. {
  3032. hr = pVirtualDFRoot->Close();
  3033. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  3034. if (S_OK == hr)
  3035. {
  3036. DH_TRACE((
  3037. DH_LVL_TRACE1,
  3038. TEXT("VirtualCtrNode::Close completed successfully.")));
  3039. }
  3040. else
  3041. {
  3042. DH_TRACE((
  3043. DH_LVL_TRACE1,
  3044. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3045. hr));
  3046. }
  3047. }
  3048. // if everything goes well, log test as passed else failed.
  3049. if (S_OK == hr)
  3050. {
  3051. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_106 passed.")) );
  3052. }
  3053. else
  3054. {
  3055. DH_LOG((LOG_FAIL,
  3056. TEXT("Test variation STGTEST_106 failed, hr=0x%lx."),
  3057. hr) );
  3058. }
  3059. // Cleanup
  3060. CleanupTestDocfile (&pVirtualDFRoot,
  3061. &pTestVirtualDF,
  3062. &pTestChanceDF,
  3063. S_OK == hr);
  3064. // Delete DataGen object
  3065. if(NULL != pdgu)
  3066. {
  3067. delete pdgu;
  3068. pdgu = NULL;
  3069. }
  3070. // Delete temp string
  3071. if(NULL != ptszRootNewChildStgName)
  3072. {
  3073. delete ptszRootNewChildStgName;
  3074. ptszRootNewChildStgName = NULL;
  3075. }
  3076. if(NULL != ptszStreamName)
  3077. {
  3078. delete ptszStreamName;
  3079. ptszStreamName = NULL;
  3080. }
  3081. if(NULL != ptcsBuffer)
  3082. {
  3083. delete ptcsBuffer;
  3084. ptcsBuffer = NULL;
  3085. }
  3086. // Delete temp string
  3087. if(NULL != ptszRootName)
  3088. {
  3089. delete ptszRootName;
  3090. ptszRootName = NULL;
  3091. }
  3092. // Stop logging the test
  3093. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_106 finished")) );
  3094. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3095. return hr;
  3096. #endif //_MAC
  3097. }
  3098. //----------------------------------------------------------------------------
  3099. //
  3100. // Test: STGTEST_107
  3101. //
  3102. // Synopsis: A random docfile with random number of storages and streams is
  3103. // generated. Root is committed and closed.
  3104. // The root docfile is instantiated and the CRC is computed for the
  3105. // entire docfile. A new root docfile with a random name is then
  3106. // created and a CRC is generated for the empty root docfile. An
  3107. // enumerator is obtained on the source docfile, each element returned
  3108. // is MoveElementTo()'d with STGM_MOVE to the destination docfile.
  3109. // If fRevertAfterMove equals TRUE, the dest is reverted, else the
  3110. // dest is committed. The dest is released and reinstantiated and
  3111. // CRC'd. If the dest was reverted, the CRC is compared against the
  3112. // empty CRC for a match. Otherwise, we compare against the original
  3113. // root docfile CRC. Original file is CRC'd again to verify that
  3114. // STGMOVE_MOVE moved the elements from orginal position instead of
  3115. // copying, the CRC now computed should differ from the one calculated
  3116. // originally.
  3117. //
  3118. // This tests differs from STGTEST-105 in the way that MoveElementTo
  3119. // is called with STGMOVE_MOVE flag instead of STGMOVE_COPY.
  3120. //
  3121. // Arguments:[argc]
  3122. // [argv]
  3123. //
  3124. // Returns: HRESULT
  3125. //
  3126. // Notes: This test runs in direct, transacted, and transacted deny write
  3127. // modes
  3128. //
  3129. // History: 8-Aug-1996 NarindK Created.
  3130. //
  3131. // New Test Notes:
  3132. // 1. Old File: A part of STORAGE.CXX
  3133. // 2. Old name of test : A part of STORAGE_TEST Test
  3134. // New Name of test : STGTEST_107
  3135. // 3. To run the test, do the following at command prompt.
  3136. // a. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-107
  3137. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  3138. // b. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-107
  3139. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3140. // c. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-107
  3141. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3142. // d. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-107
  3143. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3144. // /frevertaftermove
  3145. // e. stgbase /seed:2 /dfdepth:1-3 /dfstg:1-3 /dfstm:2-3 /t:STGTEST-107
  3146. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3147. // /frevertaftermove
  3148. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  3149. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  3150. // BUGBUG: dont have /stdblock up yet. -scousens
  3151. //
  3152. // In case of direct mode, the flag revertaftermove is not meaningful since
  3153. // changes are always directly written to disk doc file.
  3154. //
  3155. // BUGNOTE: Conversion: STGTEST-107
  3156. //
  3157. //-----------------------------------------------------------------------------
  3158. HRESULT STGTEST_107(int argc, char *argv[])
  3159. {
  3160. HRESULT hr = S_OK;
  3161. HRESULT hr2 = S_OK;
  3162. ChanceDF *pTestChanceDF = NULL;
  3163. VirtualDF *pTestVirtualDF = NULL;
  3164. VirtualCtrNode *pVirtualDFRoot = NULL;
  3165. DG_STRING *pdgu = NULL;
  3166. USHORT usErr = 0;
  3167. LPTSTR ptszRootNewDocFile = NULL;
  3168. LPOLESTR poszRootNewDocFile = NULL;
  3169. DWORD dwRootMode = 0;
  3170. LPSTORAGE pStgRoot1 = NULL;
  3171. LPSTORAGE pStgRoot2 = NULL;
  3172. LPSTORAGE pStgRoot11 = NULL;
  3173. ULONG ulRef = 0;
  3174. DWORD dwCRC1 = 0;
  3175. DWORD dwCRC2 = 0;
  3176. DWORD dwCRC3 = 0;
  3177. DWORD dwCRC4 = 0;
  3178. LPMALLOC pMalloc = NULL;
  3179. LPENUMSTATSTG penumWalk = NULL;
  3180. LPTSTR ptszElementName = NULL;
  3181. LPOLESTR poszElementName = NULL;
  3182. BOOL fPass = TRUE;
  3183. STATSTG statStg;
  3184. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_107"));
  3185. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3186. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_107 started.")) );
  3187. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt MoveElementTo-STGMOVE_MOVE operations")));
  3188. // Create our ChanceDF and VirtualDF
  3189. hr = CreateTestDocfile (argc,
  3190. argv,
  3191. &pVirtualDFRoot,
  3192. &pTestVirtualDF,
  3193. &pTestChanceDF);
  3194. // if creating the docfile - bail here
  3195. if (NULL != pTestChanceDF && DoingCreate ())
  3196. {
  3197. UINT ulSeed = pTestChanceDF->GetSeed ();
  3198. CleanupTestDocfile (&pVirtualDFRoot,
  3199. &pTestVirtualDF,
  3200. &pTestChanceDF,
  3201. FALSE);
  3202. return (HRESULT)ulSeed;
  3203. }
  3204. if (S_OK == hr)
  3205. {
  3206. dwRootMode = pTestChanceDF->GetRootMode();
  3207. DH_TRACE((
  3208. DH_LVL_TRACE1,
  3209. TEXT("Run Mode for STGTEST_107, Access mode: %lx"),
  3210. dwRootMode));
  3211. }
  3212. // Commit all substgs BUGBUG df already commited
  3213. if (S_OK == hr)
  3214. {
  3215. hr = ParseVirtualDFAndCommitAllOpenStgs(
  3216. pVirtualDFRoot,
  3217. STGC_DEFAULT,
  3218. NODE_EXC_TOPSTG);
  3219. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  3220. }
  3221. // Commit root.
  3222. if(S_OK == hr)
  3223. {
  3224. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3225. if (S_OK == hr)
  3226. {
  3227. DH_TRACE((
  3228. DH_LVL_TRACE1,
  3229. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3230. }
  3231. else
  3232. {
  3233. DH_TRACE((
  3234. DH_LVL_TRACE1,
  3235. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  3236. hr));
  3237. }
  3238. }
  3239. // Release root and all substorages/streams too
  3240. if (S_OK == hr)
  3241. {
  3242. hr = ParseVirtualDFAndCloseOpenStgsStms(
  3243. pVirtualDFRoot,
  3244. NODE_INC_TOPSTG);
  3245. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  3246. }
  3247. // Open the root only
  3248. if (S_OK == hr)
  3249. {
  3250. hr = pVirtualDFRoot->OpenRoot(
  3251. NULL,
  3252. dwRootMode,
  3253. NULL,
  3254. 0);
  3255. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  3256. if (S_OK == hr)
  3257. {
  3258. DH_TRACE((
  3259. DH_LVL_TRACE1,
  3260. TEXT("VirtualCtrNode::Open completed successfully.")));
  3261. }
  3262. else
  3263. {
  3264. DH_TRACE((
  3265. DH_LVL_TRACE1,
  3266. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  3267. hr));
  3268. }
  3269. }
  3270. // Calculate CRC for entire DocFile without the RootDocfile name
  3271. if(S_OK == hr)
  3272. {
  3273. pStgRoot1 = pVirtualDFRoot->GetIStoragePointer();
  3274. DH_ASSERT(NULL != pStgRoot1);
  3275. hr = CalculateCRCForDocFile(pStgRoot1, VERIFY_EXC_TOPSTG_NAME, &dwCRC1);
  3276. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  3277. }
  3278. // Get DG_STRING object pointer
  3279. if (S_OK == hr)
  3280. {
  3281. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3282. DH_ASSERT(NULL != pdgu) ;
  3283. }
  3284. if(S_OK == hr)
  3285. {
  3286. // Generate random name for first child storage
  3287. hr = GenerateRandomName(
  3288. pdgu,
  3289. MINLENGTH,
  3290. MAXLENGTH,
  3291. &ptszRootNewDocFile);
  3292. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3293. }
  3294. if(S_OK == hr)
  3295. {
  3296. // Convert RootDocFile name to OLECHAR
  3297. hr = TStringToOleString(ptszRootNewDocFile, &poszRootNewDocFile);
  3298. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3299. }
  3300. if (S_OK == hr)
  3301. {
  3302. hr = StgCreateDocfile(
  3303. poszRootNewDocFile,
  3304. dwRootMode,
  3305. 0,
  3306. &pStgRoot2);
  3307. DH_HRCHECK(hr, TEXT("StgCreateDocFile")) ;
  3308. if(S_OK == hr)
  3309. {
  3310. DH_TRACE((
  3311. DH_LVL_TRACE1,
  3312. TEXT("StgCreateDocfile successful as exp.")));
  3313. }
  3314. else
  3315. {
  3316. DH_TRACE((
  3317. DH_LVL_TRACE1,
  3318. TEXT("StgCreateDocfile not successful, hr=0x%lx."),
  3319. hr));
  3320. }
  3321. }
  3322. if(S_OK == hr)
  3323. {
  3324. hr = CalculateCRCForDocFile(pStgRoot2, VERIFY_EXC_TOPSTG_NAME, &dwCRC2);
  3325. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  3326. }
  3327. // Call EnumElements to get a enumerator for first DocFile
  3328. if(S_OK == hr)
  3329. {
  3330. hr = pVirtualDFRoot->EnumElements(0, NULL, 0, &penumWalk);
  3331. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  3332. if(S_OK == hr)
  3333. {
  3334. DH_TRACE((
  3335. DH_LVL_TRACE1,
  3336. TEXT("VirtualCtrNode::EnumElements passed as expected")));
  3337. }
  3338. else
  3339. {
  3340. DH_TRACE((
  3341. DH_LVL_TRACE1,
  3342. TEXT("VirtualCtrNode::EnumElements unexpectedly failed hr=0x%lx"),
  3343. hr));
  3344. }
  3345. }
  3346. // First get pMalloc that would be used to free up the name string from
  3347. // STATSTG.
  3348. if ( S_OK == hr )
  3349. {
  3350. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  3351. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  3352. }
  3353. while(S_OK == hr && S_OK == penumWalk->Next(1, &statStg, NULL))
  3354. {
  3355. if(S_OK == hr)
  3356. {
  3357. // Convert statStg.pwcsName to TCHAR
  3358. hr = OleStringToTString(statStg.pwcsName, &ptszElementName);
  3359. DH_HRCHECK(hr, TEXT("OleStringToTString")) ;
  3360. }
  3361. if(S_OK == hr)
  3362. {
  3363. // Now Convert old name to OLECHAR
  3364. hr = TStringToOleString(ptszElementName, &poszElementName);
  3365. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3366. }
  3367. if(S_OK == hr)
  3368. {
  3369. // Move the element to second DocFile
  3370. hr = pStgRoot1->MoveElementTo(
  3371. poszElementName,
  3372. pStgRoot2,
  3373. poszElementName,
  3374. STGMOVE_COPY);
  3375. DH_HRCHECK(hr, TEXT("IStorage::MoveElementTo")) ;
  3376. if(S_OK == hr)
  3377. {
  3378. DH_TRACE((
  3379. DH_LVL_TRACE1,
  3380. TEXT("IStorage::MoveElementTo passed as expected")));
  3381. }
  3382. else
  3383. {
  3384. DH_TRACE((
  3385. DH_LVL_TRACE1,
  3386. TEXT("IStorage::MoveElementTo unexpectedly failed hr=0x%lx"),
  3387. hr));
  3388. }
  3389. }
  3390. // Release resources
  3391. if ( NULL != statStg.pwcsName)
  3392. {
  3393. pMalloc->Free(statStg.pwcsName);
  3394. statStg.pwcsName = NULL;
  3395. }
  3396. if(NULL != ptszElementName)
  3397. {
  3398. delete ptszElementName;
  3399. ptszElementName = NULL;
  3400. }
  3401. if(NULL != poszElementName)
  3402. {
  3403. delete poszElementName;
  3404. poszElementName = NULL;
  3405. }
  3406. }
  3407. // Commit or Revert the second docfile as the case may be.
  3408. if((S_OK == hr) && (FALSE == g_fRevert))
  3409. {
  3410. hr = pStgRoot2->Commit(STGC_DEFAULT);
  3411. if(S_OK == hr)
  3412. {
  3413. DH_TRACE((
  3414. DH_LVL_TRACE1,
  3415. TEXT("IStorage::Commit completed successfully.")));
  3416. }
  3417. else
  3418. {
  3419. DH_TRACE((
  3420. DH_LVL_TRACE1,
  3421. TEXT("IStorage::Commit unsuccessful, hr=0x%lx."),
  3422. hr));
  3423. }
  3424. }
  3425. else
  3426. if((S_OK == hr) && (TRUE == g_fRevert))
  3427. {
  3428. hr = pStgRoot2->Revert();
  3429. if(S_OK == hr)
  3430. {
  3431. DH_TRACE((
  3432. DH_LVL_TRACE1,
  3433. TEXT("IStorage::Revert completed successfully.")));
  3434. }
  3435. else
  3436. {
  3437. DH_TRACE((
  3438. DH_LVL_TRACE1,
  3439. TEXT("IStorage::Revert unsuccessful, hr=0x%lx."),
  3440. hr));
  3441. }
  3442. }
  3443. // Close the second DocFile
  3444. if(NULL != pStgRoot2)
  3445. {
  3446. ulRef = pStgRoot2->Release();
  3447. DH_ASSERT(0 == ulRef);
  3448. pStgRoot2 = NULL;
  3449. }
  3450. // Open it again and do StgIsStorageFile to verify.
  3451. if(S_OK == hr)
  3452. {
  3453. hr = StgOpenStorage(
  3454. poszRootNewDocFile,
  3455. NULL,
  3456. dwRootMode,
  3457. NULL,
  3458. 0,
  3459. &pStgRoot2);
  3460. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  3461. if (S_OK == hr)
  3462. {
  3463. DH_TRACE((
  3464. DH_LVL_TRACE1,
  3465. TEXT("StgOpenStorage completed successfully.")));
  3466. }
  3467. else
  3468. {
  3469. DH_TRACE((
  3470. DH_LVL_TRACE1,
  3471. TEXT("StgOpenStorage unsuccessful, hr=0x%lx."),
  3472. hr));
  3473. }
  3474. }
  3475. // Do StgIsStorageFile to verify
  3476. if(S_OK == hr)
  3477. {
  3478. hr = StgIsStorageFile(poszRootNewDocFile);
  3479. DH_HRCHECK(hr, TEXT("StgIsStorageFile")) ;
  3480. if (S_OK == hr)
  3481. {
  3482. DH_TRACE((
  3483. DH_LVL_TRACE1,
  3484. TEXT("StgIsStorageFile completed successfully.")));
  3485. }
  3486. else
  3487. {
  3488. DH_TRACE((
  3489. DH_LVL_TRACE1,
  3490. TEXT("StgIsStorageFile unsuccessful, hr=0x%lx."),
  3491. hr));
  3492. }
  3493. }
  3494. // Calculate CRC on this second Root DocFile.
  3495. if(S_OK == hr)
  3496. {
  3497. hr = CalculateCRCForDocFile(pStgRoot2, VERIFY_EXC_TOPSTG_NAME, &dwCRC3);
  3498. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  3499. }
  3500. // Compare CRC's
  3501. if((S_OK == hr) && ( FALSE == g_fRevert))
  3502. {
  3503. if (dwCRC3 == dwCRC1)
  3504. {
  3505. DH_TRACE((
  3506. DH_LVL_TRACE1,
  3507. TEXT("CRC's for docfile1 & docfile2 after commit match.")));
  3508. }
  3509. else
  3510. {
  3511. DH_TRACE((
  3512. DH_LVL_TRACE1,
  3513. TEXT("CRC for docfile1 & docfile2 aftr commit don't match")));
  3514. fPass = FALSE;
  3515. }
  3516. }
  3517. else
  3518. if((S_OK == hr) && ( TRUE == g_fRevert))
  3519. {
  3520. if (dwCRC3 == dwCRC2)
  3521. {
  3522. DH_TRACE((
  3523. DH_LVL_TRACE1,
  3524. TEXT("CRC's for docfile2 before & after Revert match.")));
  3525. }
  3526. else
  3527. {
  3528. DH_TRACE((
  3529. DH_LVL_TRACE1,
  3530. TEXT("CRC for docfile2 before & after Revert don't match")));
  3531. fPass = FALSE;
  3532. }
  3533. }
  3534. // Close the second DocFile
  3535. if(NULL != pStgRoot2)
  3536. {
  3537. ulRef = pStgRoot2->Release();
  3538. DH_ASSERT(0 == ulRef);
  3539. pStgRoot2 = NULL;
  3540. }
  3541. // Release penumWalk
  3542. if(NULL != penumWalk)
  3543. {
  3544. ulRef = penumWalk->Release();
  3545. DH_ASSERT(0 == ulRef);
  3546. penumWalk = NULL;
  3547. }
  3548. // Release the first root docfile
  3549. if (S_OK == hr)
  3550. {
  3551. hr = pVirtualDFRoot->Close();
  3552. if (S_OK == hr)
  3553. {
  3554. DH_TRACE((
  3555. DH_LVL_TRACE1,
  3556. TEXT("VirtualCtrNode::Close completed successfully.")));
  3557. }
  3558. else
  3559. {
  3560. DH_TRACE((
  3561. DH_LVL_TRACE1,
  3562. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3563. hr));
  3564. }
  3565. }
  3566. // Open the Root DocFile again to verify the STGMOVE_MOVE flags specified
  3567. // while doing MoveElementTo
  3568. if (S_OK == hr)
  3569. {
  3570. hr = pVirtualDFRoot->OpenRoot(
  3571. NULL,
  3572. dwRootMode,
  3573. NULL,
  3574. 0);
  3575. if (S_OK == hr)
  3576. {
  3577. DH_TRACE((
  3578. DH_LVL_TRACE1,
  3579. TEXT("VirtualCtrNode::Open completed successfully.")));
  3580. }
  3581. else
  3582. {
  3583. DH_TRACE((
  3584. DH_LVL_TRACE1,
  3585. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  3586. hr));
  3587. }
  3588. }
  3589. // Now get the CRC again on the original DocFile to verify that flag
  3590. // STGMOVE_COPY copied the elements and not moved them, so this CRC
  3591. // should match with CRC originally obtained on this DocFile.
  3592. if(S_OK == hr)
  3593. {
  3594. pStgRoot11 = pVirtualDFRoot->GetIStoragePointer();
  3595. DH_ASSERT(NULL != pStgRoot11);
  3596. hr = CalculateCRCForDocFile(pStgRoot11, VERIFY_EXC_TOPSTG_NAME,&dwCRC4);
  3597. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  3598. if(S_OK == hr)
  3599. {
  3600. if (dwCRC4 == dwCRC1)
  3601. {
  3602. DH_TRACE((
  3603. DH_LVL_TRACE1,
  3604. TEXT("CRC for org docfile don't match as exp-move as move")));
  3605. }
  3606. else
  3607. {
  3608. DH_TRACE((
  3609. DH_LVL_TRACE1,
  3610. TEXT("CRC for org docfile match unexp -move as move")));
  3611. fPass = FALSE;
  3612. }
  3613. }
  3614. }
  3615. // Release the first root docfile
  3616. if (S_OK == hr)
  3617. {
  3618. hr = pVirtualDFRoot->Close();
  3619. if (S_OK == hr)
  3620. {
  3621. DH_TRACE((
  3622. DH_LVL_TRACE1,
  3623. TEXT("VirtualCtrNode::Close completed successfully.")));
  3624. }
  3625. else
  3626. {
  3627. DH_TRACE((
  3628. DH_LVL_TRACE1,
  3629. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3630. hr));
  3631. }
  3632. }
  3633. // Release pMalloc
  3634. if(NULL != pMalloc)
  3635. {
  3636. pMalloc->Release();
  3637. pMalloc = NULL;
  3638. }
  3639. // if everything goes well, log test as passed else failed.
  3640. if ((S_OK == hr) && (TRUE == fPass))
  3641. {
  3642. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_107 passed.")) );
  3643. }
  3644. else
  3645. {
  3646. DH_LOG((LOG_FAIL,
  3647. TEXT("Test variation STGTEST_107 failed, hr=0x%lx."),
  3648. hr) );
  3649. // test failed. make sure it failed.
  3650. hr = FirstError (hr, E_FAIL);
  3651. }
  3652. // Cleanup
  3653. CleanupTestDocfile (&pVirtualDFRoot,
  3654. &pTestVirtualDF,
  3655. &pTestChanceDF,
  3656. S_OK == hr);
  3657. // Delete strings
  3658. if(NULL != poszRootNewDocFile)
  3659. {
  3660. delete poszRootNewDocFile;
  3661. poszRootNewDocFile = NULL;
  3662. }
  3663. // Delete the second docfile on disk
  3664. if((S_OK == hr) && (NULL != ptszRootNewDocFile))
  3665. {
  3666. if(FALSE == DeleteFile(ptszRootNewDocFile))
  3667. {
  3668. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  3669. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  3670. }
  3671. }
  3672. // Delete temp string
  3673. if(NULL != ptszRootNewDocFile)
  3674. {
  3675. delete ptszRootNewDocFile;
  3676. ptszRootNewDocFile = NULL;
  3677. }
  3678. // Stop logging the test
  3679. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_107 finished")) );
  3680. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3681. return hr;
  3682. }
  3683. //----------------------------------------------------------------------------
  3684. //
  3685. // Test: STGTEST_108
  3686. //
  3687. // Synopsis: A root docfile with a child storage is created, then check if
  3688. // Set/GetConvertStorage APIs work correctly as expected by passed
  3689. // in a storage pointer(here, we test both root storage and child
  3690. // storage pointer). Also have some illegitmate tests by passing
  3691. // invalid arguments to these APIs.
  3692. //
  3693. // Arguments:[argc]
  3694. // [argv]
  3695. //
  3696. // Returns: HRESULT
  3697. //
  3698. // Notes: This test runs in direct, transacted, and transacted deny write
  3699. // modes
  3700. //
  3701. // History: 14-Aug-1996 JiminLi Created.
  3702. //
  3703. // New Test Notes:
  3704. // 1. Old File: A part of STORAGE.CXX
  3705. // 2. Old name of test : A part of STORAGE_TEST Test
  3706. // New Name of test : STGTEST_108
  3707. // 3. To run the test, do the following at command prompt.
  3708. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-108
  3709. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  3710. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-108
  3711. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3712. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-108
  3713. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3714. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  3715. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  3716. //
  3717. // BUGNOTE: Conversion: STGTEST-108
  3718. //
  3719. //-----------------------------------------------------------------------------
  3720. HRESULT STGTEST_108(int argc, char *argv[])
  3721. {
  3722. HRESULT hr = S_OK;
  3723. ChanceDF *pTestChanceDF = NULL;
  3724. VirtualDF *pTestVirtualDF = NULL;
  3725. VirtualCtrNode *pVirtualDFRoot = NULL;
  3726. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  3727. LPTSTR pRootNewChildStgName = NULL;
  3728. DG_STRING *pdgu = NULL;
  3729. DG_INTEGER *pdgi = NULL;
  3730. LPSTORAGE pRootStg = NULL;
  3731. LPSTORAGE pChildStg = NULL;
  3732. USHORT usErr = 0;
  3733. DWORD dwRootMode = 0;
  3734. DWORD dwStgMode = 0;
  3735. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_108"));
  3736. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3737. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_108 started.")) );
  3738. DH_TRACE((
  3739. DH_LVL_TRACE1,
  3740. TEXT("Attempt legit and illegit tests on Set/GetConvertStg APIs")));
  3741. // Create our ChanceDF and VirtualDF
  3742. hr = CreateTestDocfile (argc,
  3743. argv,
  3744. &pVirtualDFRoot,
  3745. &pTestVirtualDF,
  3746. &pTestChanceDF);
  3747. // if creating the docfile - bail here
  3748. if (NULL != pTestChanceDF && DoingCreate ())
  3749. {
  3750. UINT ulSeed = pTestChanceDF->GetSeed ();
  3751. CleanupTestDocfile (&pVirtualDFRoot,
  3752. &pTestVirtualDF,
  3753. &pTestChanceDF,
  3754. FALSE);
  3755. return (HRESULT)ulSeed;
  3756. }
  3757. if (S_OK == hr)
  3758. {
  3759. dwRootMode = pTestChanceDF->GetRootMode();
  3760. dwStgMode = pTestChanceDF->GetStgMode();
  3761. DH_TRACE((
  3762. DH_LVL_TRACE1,
  3763. TEXT("Run Mode for STGTEST_108, Access mode: %lx"),
  3764. dwRootMode));
  3765. }
  3766. // Get root storage pointer
  3767. if (NULL != pVirtualDFRoot)
  3768. {
  3769. pRootStg = pVirtualDFRoot->GetIStoragePointer();
  3770. }
  3771. // Get DG_STRING object pointer
  3772. if (S_OK == hr)
  3773. {
  3774. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3775. DH_ASSERT(NULL != pdgu) ;
  3776. }
  3777. // Get DG_INTEGER object pointer
  3778. if (S_OK == hr)
  3779. {
  3780. pdgi = pTestVirtualDF->GetDataGenInteger();
  3781. DH_ASSERT(NULL != pdgi) ;
  3782. }
  3783. // Adds a new storage to the root storage.
  3784. if(S_OK == hr)
  3785. {
  3786. // Generate random name for storage
  3787. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  3788. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3789. }
  3790. if(S_OK == hr)
  3791. {
  3792. hr = AddStorage(
  3793. pTestVirtualDF,
  3794. pVirtualDFRoot,
  3795. pRootNewChildStgName,
  3796. dwStgMode,
  3797. &pvcnRootNewChildStg);
  3798. pChildStg = pvcnRootNewChildStg->GetIStoragePointer();
  3799. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  3800. if(S_OK == hr)
  3801. {
  3802. DH_TRACE((
  3803. DH_LVL_TRACE1,
  3804. TEXT("AddStorage completed successfully.")));
  3805. }
  3806. else
  3807. {
  3808. DH_TRACE((
  3809. DH_LVL_TRACE1,
  3810. TEXT("AddStorage not successful, hr=0x%lx."),
  3811. hr));
  3812. }
  3813. }
  3814. // Legit tests of Set/GetConvertStg on the root storage
  3815. if (S_OK == hr)
  3816. {
  3817. hr = SetConvertStg(pRootStg, TRUE);
  3818. if (S_OK == hr)
  3819. {
  3820. hr = GetConvertStg(pRootStg);
  3821. }
  3822. else
  3823. {
  3824. DH_TRACE((
  3825. DH_LVL_TRACE1,
  3826. TEXT("SetConvertStg did not return S_OK as expected.")));
  3827. }
  3828. if (S_OK == hr)
  3829. {
  3830. hr = SetConvertStg(pRootStg, FALSE);
  3831. }
  3832. else
  3833. {
  3834. DH_TRACE((
  3835. DH_LVL_TRACE1,
  3836. TEXT("GetConvertStg did not return S_OK as expected.")));
  3837. }
  3838. if (S_OK == hr)
  3839. {
  3840. hr = GetConvertStg(pRootStg);
  3841. }
  3842. else
  3843. {
  3844. DH_TRACE((
  3845. DH_LVL_TRACE1,
  3846. TEXT("SetConvertStg did not return S_OK as expected.")));
  3847. }
  3848. if (S_FALSE == hr)
  3849. {
  3850. hr = S_OK;
  3851. }
  3852. else
  3853. {
  3854. DH_TRACE((
  3855. DH_LVL_TRACE1,
  3856. TEXT("GetConvertStg did not return S_FALSE as expected.")));
  3857. hr = E_FAIL;
  3858. }
  3859. }
  3860. // Legit tests of Set/GetConvertStg on the child storage
  3861. if (S_OK == hr)
  3862. {
  3863. hr = SetConvertStg(pChildStg, TRUE);
  3864. if (S_OK == hr)
  3865. {
  3866. hr = GetConvertStg(pChildStg);
  3867. }
  3868. else
  3869. {
  3870. DH_TRACE((
  3871. DH_LVL_TRACE1,
  3872. TEXT("SetConvertStg did not return S_OK as expected.")));
  3873. }
  3874. if (S_OK == hr)
  3875. {
  3876. hr = SetConvertStg(pChildStg, FALSE);
  3877. }
  3878. else
  3879. {
  3880. DH_TRACE((
  3881. DH_LVL_TRACE1,
  3882. TEXT("GetConvertStg did not return S_OK as expected.")));
  3883. }
  3884. if (S_OK == hr)
  3885. {
  3886. hr = GetConvertStg(pChildStg);
  3887. }
  3888. else
  3889. {
  3890. DH_TRACE((
  3891. DH_LVL_TRACE1,
  3892. TEXT("SetConvertStg did not return S_OK as expected.")));
  3893. }
  3894. if (S_FALSE == hr)
  3895. {
  3896. hr = S_OK;
  3897. }
  3898. else
  3899. {
  3900. DH_TRACE((
  3901. DH_LVL_TRACE1,
  3902. TEXT("GetConvertStg did not return S_FALSE as expected.")));
  3903. hr = E_FAIL;
  3904. }
  3905. }
  3906. // Illegit tests
  3907. #ifdef _MAC
  3908. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!SetConvertStg with NULL IStorage skipped")) );
  3909. #else
  3910. // Pass NULL as IStorage pointer, it should fail
  3911. if (S_OK == hr)
  3912. {
  3913. hr = SetConvertStg(NULL, TRUE);
  3914. if (E_INVALIDARG == hr)
  3915. {
  3916. hr = S_OK;
  3917. }
  3918. else
  3919. {
  3920. DH_TRACE((
  3921. DH_LVL_TRACE1,
  3922. TEXT("SetConvertStg did not return E_INVALIDARG as expected")));
  3923. hr = E_FAIL;
  3924. }
  3925. if (S_OK == hr)
  3926. {
  3927. hr = GetConvertStg(NULL);
  3928. }
  3929. if (E_INVALIDARG == hr)
  3930. {
  3931. hr = S_OK;
  3932. }
  3933. else
  3934. {
  3935. DH_TRACE((
  3936. DH_LVL_TRACE1,
  3937. TEXT("GetConvertStg did not return E_INVALIDARG as expected")));
  3938. hr = E_FAIL;
  3939. }
  3940. }
  3941. #endif //_MAC
  3942. // Commit the root
  3943. if (S_OK == hr)
  3944. {
  3945. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3946. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit"));
  3947. if (S_OK == hr)
  3948. {
  3949. DH_TRACE((
  3950. DH_LVL_TRACE1,
  3951. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3952. }
  3953. else
  3954. {
  3955. DH_TRACE((
  3956. DH_LVL_TRACE1,
  3957. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  3958. hr));
  3959. }
  3960. }
  3961. // Release child and root storages
  3962. if (S_OK == hr)
  3963. {
  3964. hr = pvcnRootNewChildStg->Close();
  3965. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  3966. }
  3967. if (S_OK == hr)
  3968. {
  3969. hr = pVirtualDFRoot->Close();
  3970. if (S_OK == hr)
  3971. {
  3972. DH_TRACE((
  3973. DH_LVL_TRACE1,
  3974. TEXT("VirtualCtrNode::Close completed successfully.")));
  3975. }
  3976. else
  3977. {
  3978. DH_TRACE((
  3979. DH_LVL_TRACE1,
  3980. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3981. hr));
  3982. }
  3983. }
  3984. // if everything goes well, log test as passed else failed.
  3985. if (S_OK == hr)
  3986. {
  3987. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_108 passed.")) );
  3988. }
  3989. else
  3990. {
  3991. DH_LOG((LOG_FAIL,
  3992. TEXT("Test variation STGTEST_108 failed, hr = 0x%lx."),
  3993. hr) );
  3994. }
  3995. // Cleanup
  3996. CleanupTestDocfile (&pVirtualDFRoot,
  3997. &pTestVirtualDF,
  3998. &pTestChanceDF,
  3999. S_OK == hr);
  4000. // Delete temp strings
  4001. if (NULL != pRootNewChildStgName)
  4002. {
  4003. delete []pRootNewChildStgName;
  4004. pRootNewChildStgName = NULL;
  4005. }
  4006. // Stop logging the test
  4007. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_108 finished")) );
  4008. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4009. return hr;
  4010. }
  4011. //----------------------------------------------------------------------------
  4012. //
  4013. // Test: STGTEST_109
  4014. //
  4015. // Synopsis: A root docfile is created with a child storage. Check StgSetTimes
  4016. // API work as expected to set times on root Storage and IStorage::
  4017. // SetElementTimes on child storage. Verify by stat'ng on Storages
  4018. // and comparing stat'd times. Then attempt setting times with NULL
  4019. // time parameters. Verify that earlier time set on storage remain
  4020. // untouched. Attempt illegitmate ops on the API.
  4021. //
  4022. // Arguments:[argc]
  4023. // [argv]
  4024. //
  4025. // Returns: HRESULT
  4026. //
  4027. // Notes: This test runs in direct, transacted, and transacted deny write
  4028. // modes
  4029. //
  4030. // History: 15-Aug-1996 NarindK Created.
  4031. //
  4032. // New Test Notes:
  4033. // 1. Old File: A part of OLECMN.CXX
  4034. // 2. Old name of test : TestStgSetTime
  4035. // New Name of test : STGTEST_109
  4036. // 3. To run the test, do the following at command prompt.
  4037. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-109
  4038. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  4039. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-109
  4040. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  4041. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-109
  4042. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  4043. // 4. To run for conversion, NA (add /dfStgType:conversion to each of the above)
  4044. // 5. To run for nssfile, NA (add /dfStgType:nssfile to each of the above)
  4045. // BUGBUG: -scousens StgSetTimes not supported for nssfiles????
  4046. //
  4047. // BUGNOTE: Conversion: STGTEST-109
  4048. //
  4049. //-----------------------------------------------------------------------------
  4050. HRESULT STGTEST_109(int argc, char *argv[])
  4051. {
  4052. HRESULT hr = S_OK;
  4053. ChanceDF *pTestChanceDF = NULL;
  4054. VirtualDF *pTestVirtualDF = NULL;
  4055. VirtualCtrNode *pVirtualDFRoot = NULL;
  4056. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  4057. LPTSTR pRootNewChildStgName = NULL;
  4058. LPOLESTR poszVirtualDFRootName = NULL;
  4059. DG_STRING *pdgu = NULL;
  4060. DWORD dwRootMode = 0;
  4061. DWORD dwStgMode = 0;
  4062. BOOL fRet = FALSE;
  4063. BOOL fPass = TRUE;
  4064. FILETIME cNewRootStgFileTime = {dwDefLowDateTime,
  4065. dwDefHighDateTime};
  4066. FILETIME cNewChildStgFileTime = {dwDefLowDateTime,
  4067. dwDefHighDateTime};
  4068. SYSTEMTIME cCurrentSystemTime;
  4069. STATSTG statStg;
  4070. STATSTG statStgChild;
  4071. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_109"));
  4072. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4073. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_109 started.")) );
  4074. DH_TRACE((
  4075. DH_LVL_TRACE1,
  4076. TEXT("Attempt legit/illegit tests on StgSetTimes API")));
  4077. // Create our ChanceDF and VirtualDF
  4078. hr = CreateTestDocfile (argc,
  4079. argv,
  4080. &pVirtualDFRoot,
  4081. &pTestVirtualDF,
  4082. &pTestChanceDF);
  4083. // if creating the docfile - bail here
  4084. if (NULL != pTestChanceDF && DoingCreate ())
  4085. {
  4086. UINT ulSeed = pTestChanceDF->GetSeed ();
  4087. CleanupTestDocfile (&pVirtualDFRoot,
  4088. &pTestVirtualDF,
  4089. &pTestChanceDF,
  4090. FALSE);
  4091. return (HRESULT)ulSeed;
  4092. }
  4093. if (S_OK == hr)
  4094. {
  4095. dwRootMode = pTestChanceDF->GetRootMode();
  4096. dwStgMode = pTestChanceDF->GetStgMode();
  4097. DH_TRACE((
  4098. DH_LVL_TRACE1,
  4099. TEXT("Run Mode for STGTEST_109, Access mode: %lx"),
  4100. dwRootMode));
  4101. }
  4102. // Get DG_STRING object pointer
  4103. if (S_OK == hr)
  4104. {
  4105. pdgu = pTestVirtualDF->GetDataGenUnicode();
  4106. DH_ASSERT(NULL != pdgu) ;
  4107. }
  4108. // Adds a new storage to the root storage.
  4109. if(S_OK == hr)
  4110. {
  4111. // Generate random name for storage
  4112. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  4113. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4114. }
  4115. if(S_OK == hr)
  4116. {
  4117. hr = AddStorage(
  4118. pTestVirtualDF,
  4119. pVirtualDFRoot,
  4120. pRootNewChildStgName,
  4121. dwStgMode,
  4122. &pvcnRootNewChildStg);
  4123. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  4124. if(S_OK == hr)
  4125. {
  4126. DH_TRACE((
  4127. DH_LVL_TRACE1,
  4128. TEXT("AddStorage completed successfully.")));
  4129. }
  4130. else
  4131. {
  4132. DH_TRACE((
  4133. DH_LVL_TRACE1,
  4134. TEXT("AddStorage not successful, hr=0x%lx."),
  4135. hr));
  4136. }
  4137. }
  4138. // Commit the root
  4139. if (S_OK == hr)
  4140. {
  4141. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4142. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit"));
  4143. if (S_OK == hr)
  4144. {
  4145. DH_TRACE((
  4146. DH_LVL_TRACE1,
  4147. TEXT("VirtualCtrNode::Commit completed successfully.")));
  4148. }
  4149. else
  4150. {
  4151. DH_TRACE((
  4152. DH_LVL_TRACE1,
  4153. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  4154. hr));
  4155. }
  4156. }
  4157. // StgSetTimes on Root stg
  4158. if(S_OK == hr)
  4159. {
  4160. // Convert test name to OLECHAR
  4161. hr = TStringToOleString(
  4162. pVirtualDFRoot->GetVirtualCtrNodeName(),
  4163. &poszVirtualDFRootName);
  4164. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  4165. }
  4166. if(S_OK == hr)
  4167. {
  4168. GetSystemTime(&cCurrentSystemTime);
  4169. fRet = SystemTimeToFileTime(&cCurrentSystemTime, &cNewRootStgFileTime);
  4170. DH_ASSERT(TRUE == fRet);
  4171. DH_ASSERT(dwDefLowDateTime != cNewRootStgFileTime.dwLowDateTime);
  4172. DH_ASSERT(dwDefHighDateTime != cNewRootStgFileTime.dwHighDateTime);
  4173. hr = StgSetTimes(
  4174. poszVirtualDFRootName,
  4175. &cNewRootStgFileTime,
  4176. &cNewRootStgFileTime,
  4177. &cNewRootStgFileTime);
  4178. DH_HRCHECK(hr, TEXT("StgSetTimes")) ;
  4179. if(S_OK == hr)
  4180. {
  4181. DH_TRACE((
  4182. DH_LVL_TRACE1,
  4183. TEXT("StgSetTimes API passed as exp.")));
  4184. }
  4185. else
  4186. {
  4187. DH_TRACE((
  4188. DH_LVL_TRACE1,
  4189. TEXT("StgSetTimes API failed unexp, hr = 0x%lx."),
  4190. hr));
  4191. }
  4192. }
  4193. // Now stat on root storage to see times are set correctly.
  4194. if (S_OK == hr)
  4195. {
  4196. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  4197. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  4198. if (S_OK == hr)
  4199. {
  4200. DH_TRACE((
  4201. DH_LVL_TRACE1,
  4202. TEXT("VirtualCtrNode::Stat completed successfully.")));
  4203. }
  4204. else
  4205. {
  4206. DH_TRACE((
  4207. DH_LVL_TRACE1,
  4208. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  4209. hr));
  4210. }
  4211. }
  4212. // Compare times from STATSTG structure. FAT doesn't have enough
  4213. // resolution, so we would retrict to comapring dwHighDateTime part only
  4214. // for mtime and ctime.
  4215. if(S_OK == hr)
  4216. {
  4217. if(cNewRootStgFileTime.dwHighDateTime == statStg.mtime.dwHighDateTime)
  4218. {
  4219. DH_TRACE((
  4220. DH_LVL_TRACE1,
  4221. TEXT("Root DocFile mtime set as expected.")));
  4222. }
  4223. else
  4224. {
  4225. DH_TRACE((
  4226. DH_LVL_TRACE1,
  4227. TEXT("Root DocFile mtime didn't set unexpectedly.")));
  4228. fPass = FALSE;
  4229. }
  4230. if(cNewRootStgFileTime.dwHighDateTime == statStg.ctime.dwHighDateTime)
  4231. {
  4232. DH_TRACE((
  4233. DH_LVL_TRACE1,
  4234. TEXT("Root DocFile ctime set as expected.")));
  4235. }
  4236. else
  4237. {
  4238. DH_TRACE((
  4239. DH_LVL_TRACE1,
  4240. TEXT("Root DocFile ctime didn't set unexpectedly.")));
  4241. fPass = FALSE;
  4242. }
  4243. }
  4244. // Release child storage
  4245. if (S_OK == hr)
  4246. {
  4247. hr = pvcnRootNewChildStg->Close();
  4248. if (S_OK == hr)
  4249. {
  4250. DH_TRACE((
  4251. DH_LVL_TRACE1,
  4252. TEXT("VirtualCtrNode::Close completed successfully.")));
  4253. }
  4254. else
  4255. {
  4256. DH_TRACE((
  4257. DH_LVL_TRACE1,
  4258. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4259. hr));
  4260. }
  4261. }
  4262. // SetElementTimes on Child Storage
  4263. if(S_OK == hr)
  4264. {
  4265. GetSystemTime(&cCurrentSystemTime);
  4266. fRet = SystemTimeToFileTime(&cCurrentSystemTime, &cNewChildStgFileTime);
  4267. DH_ASSERT(TRUE == fRet);
  4268. DH_ASSERT(dwDefLowDateTime != cNewChildStgFileTime.dwLowDateTime);
  4269. DH_ASSERT(dwDefHighDateTime != cNewChildStgFileTime.dwHighDateTime);
  4270. hr = pvcnRootNewChildStg->SetElementTimes(
  4271. &cNewChildStgFileTime,
  4272. &cNewChildStgFileTime,
  4273. &cNewChildStgFileTime);
  4274. DH_HRCHECK(hr, TEXT("VirtualCtrNode::SetElementTimes")) ;
  4275. if(S_OK == hr)
  4276. {
  4277. DH_TRACE((
  4278. DH_LVL_TRACE1,
  4279. TEXT("VirtualCtrNode::SetElementTimes passed as exp.")));
  4280. }
  4281. else
  4282. {
  4283. DH_TRACE((
  4284. DH_LVL_TRACE1,
  4285. TEXT("VirtualCtrNode::SetElementTimes failed unexp, hr = 0x%lx."),
  4286. hr));
  4287. }
  4288. }
  4289. // Now open and stat on child storage to see times are set correctly.
  4290. // Open child storage
  4291. if (S_OK == hr)
  4292. {
  4293. hr = pvcnRootNewChildStg->Open(NULL, dwStgMode, NULL, 0);
  4294. if (S_OK == hr)
  4295. {
  4296. DH_TRACE((
  4297. DH_LVL_TRACE1,
  4298. TEXT("VirtualCtrNode::Open completed successfully.")));
  4299. }
  4300. else
  4301. {
  4302. DH_TRACE((
  4303. DH_LVL_TRACE1,
  4304. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  4305. hr));
  4306. }
  4307. }
  4308. // Stat on child storage
  4309. if (S_OK == hr)
  4310. {
  4311. hr = pvcnRootNewChildStg->Stat(&statStgChild, STATFLAG_NONAME);
  4312. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  4313. if (S_OK == hr)
  4314. {
  4315. DH_TRACE((
  4316. DH_LVL_TRACE1,
  4317. TEXT("VirtualCtrNode::Stat completed successfully.")));
  4318. }
  4319. else
  4320. {
  4321. DH_TRACE((
  4322. DH_LVL_TRACE1,
  4323. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  4324. hr));
  4325. }
  4326. }
  4327. // Compare times from STATSTG structure. FAT doesn't have enough
  4328. // resolution, so we would retrict to comapring dwHighDateTime part only
  4329. // for mtime and ctime.
  4330. if(S_OK == hr)
  4331. {
  4332. if(cNewChildStgFileTime.dwHighDateTime ==
  4333. statStgChild.mtime.dwHighDateTime)
  4334. {
  4335. DH_TRACE((
  4336. DH_LVL_TRACE1,
  4337. TEXT("Child Stg mtime set as expected.")));
  4338. }
  4339. else
  4340. {
  4341. DH_TRACE((
  4342. DH_LVL_TRACE1,
  4343. TEXT("Child stg mtime didn't set unexpectedly.")));
  4344. fPass = FALSE;
  4345. }
  4346. if(cNewChildStgFileTime.dwHighDateTime ==
  4347. statStgChild.ctime.dwHighDateTime)
  4348. {
  4349. DH_TRACE((
  4350. DH_LVL_TRACE1,
  4351. TEXT("Child stg ctime set as expected.")));
  4352. }
  4353. else
  4354. {
  4355. DH_TRACE((
  4356. DH_LVL_TRACE1,
  4357. TEXT("Child Stg ctime didn't set unexpectedly.")));
  4358. fPass = FALSE;
  4359. }
  4360. }
  4361. // Release child storage
  4362. if (S_OK == hr)
  4363. {
  4364. hr = pvcnRootNewChildStg->Close();
  4365. }
  4366. if (S_OK == hr)
  4367. {
  4368. DH_TRACE((
  4369. DH_LVL_TRACE1,
  4370. TEXT("VirtualCtrNode::Close completed successfully.")));
  4371. }
  4372. else
  4373. {
  4374. DH_TRACE((
  4375. DH_LVL_TRACE1,
  4376. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4377. hr));
  4378. }
  4379. // StgSetTimes on Root stg with all NULL time elements. Verify that the
  4380. // time doesn't change,
  4381. if(S_OK == hr)
  4382. {
  4383. hr = StgSetTimes(
  4384. poszVirtualDFRootName,
  4385. NULL,
  4386. NULL,
  4387. NULL);
  4388. DH_HRCHECK(hr, TEXT("StgSetTimes with NULL time parameters")) ;
  4389. if(S_OK == hr)
  4390. {
  4391. DH_TRACE((
  4392. DH_LVL_TRACE1,
  4393. TEXT("StgSetTimes API with NULL time param passed as exp.")));
  4394. }
  4395. else
  4396. {
  4397. DH_TRACE((
  4398. DH_LVL_TRACE1,
  4399. TEXT("StgSetTimes API with NULL time param fail unexp, hr=0x%lx"),
  4400. hr));
  4401. }
  4402. }
  4403. // Now stat on root storage to seeearlier times have remain untouched.
  4404. if (S_OK == hr)
  4405. {
  4406. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  4407. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  4408. if (S_OK == hr)
  4409. {
  4410. DH_TRACE((
  4411. DH_LVL_TRACE1,
  4412. TEXT("VirtualCtrNode::Stat completed successfully.")));
  4413. }
  4414. else
  4415. {
  4416. DH_TRACE((
  4417. DH_LVL_TRACE1,
  4418. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  4419. hr));
  4420. }
  4421. }
  4422. // Compare times from STATSTG structure. FAT doesn't have enough
  4423. // resolution, so we would retrict to comapring dwHighDateTime part only
  4424. // for mtime and ctime.
  4425. if(S_OK == hr)
  4426. {
  4427. if(cNewRootStgFileTime.dwHighDateTime == statStg.mtime.dwHighDateTime)
  4428. {
  4429. DH_TRACE((
  4430. DH_LVL_TRACE1,
  4431. TEXT("Root DocFile mtime unchanged as expected.")));
  4432. }
  4433. else
  4434. {
  4435. DH_TRACE((
  4436. DH_LVL_TRACE1,
  4437. TEXT("Root DocFile mtime changed unexpectedly.")));
  4438. fPass = FALSE;
  4439. }
  4440. if(cNewRootStgFileTime.dwHighDateTime == statStg.ctime.dwHighDateTime)
  4441. {
  4442. DH_TRACE((
  4443. DH_LVL_TRACE1,
  4444. TEXT("Root DocFile ctime unchanged as expected.")));
  4445. }
  4446. else
  4447. {
  4448. DH_TRACE((
  4449. DH_LVL_TRACE1,
  4450. TEXT("Root DocFile ctime changed unexpectedly.")));
  4451. fPass = FALSE;
  4452. }
  4453. }
  4454. // SetElementTimes on Child Storage with all NULL times. Verify that
  4455. // the times remain unchanged.
  4456. if(S_OK == hr)
  4457. {
  4458. hr = pvcnRootNewChildStg->SetElementTimes(NULL,NULL,NULL);
  4459. DH_HRCHECK(hr, TEXT("VirtualCtrNode::SetElementTimes")) ;
  4460. if(S_OK == hr)
  4461. {
  4462. DH_TRACE((
  4463. DH_LVL_TRACE1,
  4464. TEXT("VCN::SetElementTimes with NULL times passed as exp.")));
  4465. }
  4466. else
  4467. {
  4468. DH_TRACE((
  4469. DH_LVL_TRACE1,
  4470. TEXT("VCN:SetElementTimes with NULL times failed unexp,hr=0x%lx"),
  4471. hr));
  4472. }
  4473. }
  4474. // Now open and stat on child storage to see times are set correctly.
  4475. // Open child storage
  4476. if (S_OK == hr)
  4477. {
  4478. hr = pvcnRootNewChildStg->Open(NULL, dwStgMode, NULL, 0);
  4479. if (S_OK == hr)
  4480. {
  4481. DH_TRACE((
  4482. DH_LVL_TRACE1,
  4483. TEXT("VirtualCtrNode::Open completed successfully.")));
  4484. }
  4485. else
  4486. {
  4487. DH_TRACE((
  4488. DH_LVL_TRACE1,
  4489. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  4490. hr));
  4491. }
  4492. }
  4493. // Stat on child storage
  4494. if (S_OK == hr)
  4495. {
  4496. hr = pvcnRootNewChildStg->Stat(&statStgChild, STATFLAG_NONAME);
  4497. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  4498. if (S_OK == hr)
  4499. {
  4500. DH_TRACE((
  4501. DH_LVL_TRACE1,
  4502. TEXT("VirtualCtrNode::Stat completed successfully.")));
  4503. }
  4504. else
  4505. {
  4506. DH_TRACE((
  4507. DH_LVL_TRACE1,
  4508. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  4509. hr));
  4510. }
  4511. }
  4512. // Compare times from STATSTG structure. FAT doesn't have enough
  4513. // resolution, so we would retrict to comapring dwHighDateTime part only
  4514. // for mtime and ctime.
  4515. if(S_OK == hr)
  4516. {
  4517. if(cNewChildStgFileTime.dwHighDateTime ==
  4518. statStgChild.mtime.dwHighDateTime)
  4519. {
  4520. DH_TRACE((
  4521. DH_LVL_TRACE1,
  4522. TEXT("Child Stg mtime unchanged as expected.")));
  4523. }
  4524. else
  4525. {
  4526. DH_TRACE((
  4527. DH_LVL_TRACE1,
  4528. TEXT("Child stg mtime changed unexpectedly.")));
  4529. fPass = FALSE;
  4530. }
  4531. if(cNewChildStgFileTime.dwHighDateTime ==
  4532. statStgChild.ctime.dwHighDateTime)
  4533. {
  4534. DH_TRACE((
  4535. DH_LVL_TRACE1,
  4536. TEXT("Child stg ctime unchanged as expected.")));
  4537. }
  4538. else
  4539. {
  4540. DH_TRACE((
  4541. DH_LVL_TRACE1,
  4542. TEXT("Child Stg ctime changed unexpectedly.")));
  4543. fPass = FALSE;
  4544. }
  4545. }
  4546. // Release child storage
  4547. if (S_OK == hr)
  4548. {
  4549. hr = pvcnRootNewChildStg->Close();
  4550. if (S_OK == hr)
  4551. {
  4552. DH_TRACE((
  4553. DH_LVL_TRACE1,
  4554. TEXT("VirtualCtrNode::Close completed successfully.")));
  4555. }
  4556. else
  4557. {
  4558. DH_TRACE((
  4559. DH_LVL_TRACE1,
  4560. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4561. hr));
  4562. }
  4563. }
  4564. // Attempt calling StgSetTimes with NULL name.
  4565. if(S_OK == hr)
  4566. {
  4567. GetSystemTime(&cCurrentSystemTime);
  4568. fRet = SystemTimeToFileTime(&cCurrentSystemTime, &cNewRootStgFileTime);
  4569. DH_ASSERT(TRUE == fRet);
  4570. DH_ASSERT(dwDefLowDateTime != cNewRootStgFileTime.dwLowDateTime);
  4571. DH_ASSERT(dwDefHighDateTime != cNewRootStgFileTime.dwHighDateTime);
  4572. hr = StgSetTimes(
  4573. NULL,
  4574. &cNewRootStgFileTime,
  4575. &cNewRootStgFileTime,
  4576. &cNewRootStgFileTime);
  4577. DH_HRCHECK(hr, TEXT("StgSetTimes")) ;
  4578. if(STG_E_INVALIDNAME == hr)
  4579. {
  4580. DH_TRACE((
  4581. DH_LVL_TRACE1,
  4582. TEXT("StgSetTimes API with NULL name failed as exp, hr = 0x%lx."),
  4583. hr));
  4584. hr = S_OK;
  4585. }
  4586. else
  4587. {
  4588. DH_TRACE((
  4589. DH_LVL_TRACE1,
  4590. TEXT("StgSetTimes with NULL name didn't fail as exp, hr=0x%lx"),
  4591. hr));
  4592. }
  4593. }
  4594. // Release root
  4595. if (S_OK == hr)
  4596. {
  4597. hr = pVirtualDFRoot->Close();
  4598. if (S_OK == hr)
  4599. {
  4600. DH_TRACE((
  4601. DH_LVL_TRACE1,
  4602. TEXT("VirtualCtrNode::Close completed successfully.")));
  4603. }
  4604. else
  4605. {
  4606. DH_TRACE((
  4607. DH_LVL_TRACE1,
  4608. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4609. hr));
  4610. }
  4611. }
  4612. // if everything goes well, log test as passed else failed.
  4613. if ((S_OK == hr) && (TRUE == fPass))
  4614. {
  4615. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_109 passed.")) );
  4616. }
  4617. else
  4618. {
  4619. DH_LOG((LOG_FAIL,
  4620. TEXT("Test variation STGTEST_109 failed, hr = 0x%lx."),
  4621. hr) );
  4622. // test failed. make sure it failed.
  4623. hr = FirstError (hr, E_FAIL);
  4624. }
  4625. // Cleanup
  4626. CleanupTestDocfile (&pVirtualDFRoot,
  4627. &pTestVirtualDF,
  4628. &pTestChanceDF,
  4629. S_OK == hr);
  4630. // Delete temp strings
  4631. if (NULL != poszVirtualDFRootName)
  4632. {
  4633. delete poszVirtualDFRootName;
  4634. poszVirtualDFRootName = NULL;
  4635. }
  4636. if (NULL != pRootNewChildStgName)
  4637. {
  4638. delete pRootNewChildStgName;
  4639. pRootNewChildStgName = NULL;
  4640. }
  4641. // Stop logging the test
  4642. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_109 finished")) );
  4643. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4644. return hr;
  4645. }
  4646. //----------------------------------------------------------------------------
  4647. //
  4648. // Test: STGTEST_110
  4649. //
  4650. // Synopsis: A root docfile is created, then add a random number of streams
  4651. // under the root storage, make sure the last stream's size is
  4652. // less than 4K(ministream), then commit and release the docfile.
  4653. //
  4654. // Arguments:[argc]
  4655. // [argv]
  4656. //
  4657. // Returns: HRESULT
  4658. //
  4659. // Notes: This test runs in direct, transacted, and transacted deny write
  4660. // modes
  4661. //
  4662. // History: 29-Oct-1996 JiminLi Created.
  4663. //
  4664. // Notes:
  4665. // To run the test, do the following at command prompt.
  4666. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-110
  4667. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  4668. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-110
  4669. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  4670. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STGTEST-110
  4671. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  4672. // 4. To run for conversion, add /dfStgType:conversion to each of the above
  4673. // 5. To run for nssfile, add /dfStgType:nssfile to each of the above
  4674. //
  4675. // BUGNOTE: Conversion: STGTEST-110
  4676. //
  4677. //-----------------------------------------------------------------------------
  4678. HRESULT STGTEST_110(int argc, char *argv[])
  4679. {
  4680. HRESULT hr = S_OK;
  4681. ChanceDF *pTestChanceDF = NULL;
  4682. VirtualDF *pTestVirtualDF = NULL;
  4683. VirtualCtrNode *pVirtualDFRoot = NULL;
  4684. VirtualStmNode **pvsnRootNewChildStream = NULL;
  4685. LPTSTR *pRootNewChildStmName = NULL;
  4686. ULONG culBytesWrite = 0;
  4687. DG_INTEGER *pdgi = NULL;
  4688. LPTSTR ptcsBuffer = NULL;
  4689. DG_STRING *pdgu = NULL;
  4690. DWORD dwRootMode = 0;
  4691. ULONG ulIndex = 0;
  4692. ULONG ulStmNum = 0;
  4693. ULONG ulMinStm = 2;
  4694. ULONG ulMaxStm = 5;
  4695. ULONG culWritten = 0;
  4696. USHORT usErr = 0;
  4697. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STGTEST_110"));
  4698. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4699. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_110 started.")) );
  4700. DH_TRACE((
  4701. DH_LVL_TRACE1,
  4702. TEXT("Test on adding a ministream into the root storage")));
  4703. // Create our ChanceDF and VirtualDF
  4704. hr = CreateTestDocfile (argc,
  4705. argv,
  4706. &pVirtualDFRoot,
  4707. &pTestVirtualDF,
  4708. &pTestChanceDF);
  4709. // if creating the docfile - bail here
  4710. if (NULL != pTestChanceDF && DoingCreate ())
  4711. {
  4712. UINT ulSeed = pTestChanceDF->GetSeed ();
  4713. CleanupTestDocfile (&pVirtualDFRoot,
  4714. &pTestVirtualDF,
  4715. &pTestChanceDF,
  4716. FALSE);
  4717. return (HRESULT)ulSeed;
  4718. }
  4719. if (S_OK == hr)
  4720. {
  4721. dwRootMode = pTestChanceDF->GetRootMode();
  4722. DH_TRACE((
  4723. DH_LVL_TRACE1,
  4724. TEXT("Run Mode for STGTEST_110, Access mode: %lx"),
  4725. dwRootMode));
  4726. }
  4727. // Get DG_UNICODE object pointer
  4728. if (S_OK == hr)
  4729. {
  4730. pdgu = pTestVirtualDF->GetDataGenUnicode();
  4731. DH_ASSERT(NULL != pdgu) ;
  4732. }
  4733. // Get DG_INTEGER object pointer
  4734. if (S_OK == hr)
  4735. {
  4736. pdgi = pTestVirtualDF->GetDataGenInteger();
  4737. DH_ASSERT(NULL != pdgi) ;
  4738. }
  4739. // Generate the number of streams to create
  4740. if (S_OK == hr)
  4741. {
  4742. usErr = pdgi->Generate(&ulStmNum, ulMinStm, ulMaxStm);
  4743. if (DG_RC_SUCCESS != usErr)
  4744. {
  4745. hr = E_FAIL;
  4746. }
  4747. }
  4748. // Initialization
  4749. if (S_OK == hr)
  4750. {
  4751. pvsnRootNewChildStream = new VirtualStmNode*[ulStmNum];
  4752. pRootNewChildStmName = new LPTSTR[ulStmNum];
  4753. if ((NULL == pvsnRootNewChildStream) || (NULL == pRootNewChildStmName))
  4754. {
  4755. hr = E_OUTOFMEMORY;
  4756. }
  4757. }
  4758. if (S_OK == hr)
  4759. {
  4760. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  4761. {
  4762. pvsnRootNewChildStream[ulIndex] = NULL;
  4763. pRootNewChildStmName[ulIndex] = NULL;
  4764. }
  4765. }
  4766. // Create ulStmNum streams under the root storage
  4767. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  4768. {
  4769. if (S_OK == hr)
  4770. {
  4771. // Generate random name for stream
  4772. hr = GenerateRandomName(
  4773. pdgu,
  4774. MINLENGTH,
  4775. MAXLENGTH,
  4776. &pRootNewChildStmName[ulIndex]);
  4777. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4778. }
  4779. if (S_OK == hr)
  4780. {
  4781. hr = AddStream(
  4782. pTestVirtualDF,
  4783. pVirtualDFRoot,
  4784. pRootNewChildStmName[ulIndex],
  4785. 0,
  4786. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4787. &pvsnRootNewChildStream[ulIndex]);
  4788. DH_HRCHECK(hr, TEXT("AddStream")) ;
  4789. if(S_OK == hr)
  4790. {
  4791. DH_TRACE((
  4792. DH_LVL_TRACE1,
  4793. TEXT("VirtualStmNode::AddStream completed successfully.")));
  4794. }
  4795. else
  4796. {
  4797. DH_TRACE((
  4798. DH_LVL_TRACE1,
  4799. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx"),
  4800. hr));
  4801. }
  4802. }
  4803. if (S_OK == hr)
  4804. {
  4805. // Generate random size for stream between MIN_STMSIZE and
  4806. // MAX_STMSIZE if it's not the last stream, otherwise generate a
  4807. // size between 0 and MAXSIZEOFMINISTM(4k).
  4808. if (ulStmNum-1 == ulIndex)
  4809. {
  4810. usErr = pdgi->Generate(&culBytesWrite,0L,MAXSIZEOFMINISTM);
  4811. }
  4812. else
  4813. {
  4814. usErr = pdgi->Generate(&culBytesWrite,MIN_STMSIZE,MAX_STMSIZE);
  4815. }
  4816. if (DG_RC_SUCCESS != usErr)
  4817. {
  4818. hr = E_FAIL;
  4819. }
  4820. }
  4821. if (S_OK == hr)
  4822. {
  4823. // Generate a random string of size culBytesWrite
  4824. hr = GenerateRandomString(
  4825. pdgu,
  4826. culBytesWrite,
  4827. culBytesWrite,
  4828. &ptcsBuffer);
  4829. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  4830. }
  4831. if (S_OK == hr)
  4832. {
  4833. hr = pvsnRootNewChildStream[ulIndex]->Write(
  4834. ptcsBuffer,
  4835. culBytesWrite,
  4836. &culWritten);
  4837. if (S_OK != hr)
  4838. {
  4839. DH_TRACE((
  4840. DH_LVL_TRACE1,
  4841. TEXT("VirtualStmNode::Write not successful, hr=0x%lx."),
  4842. hr));
  4843. }
  4844. }
  4845. // Delete the temp buffer
  4846. if (NULL != ptcsBuffer)
  4847. {
  4848. delete ptcsBuffer;
  4849. ptcsBuffer = NULL;
  4850. }
  4851. }
  4852. // Commit the root
  4853. if (S_OK == hr)
  4854. {
  4855. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4856. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit"));
  4857. if (S_OK == hr)
  4858. {
  4859. DH_TRACE((
  4860. DH_LVL_TRACE1,
  4861. TEXT("VirtualCtrNode::Commit completed successfully.")));
  4862. }
  4863. else
  4864. {
  4865. DH_TRACE((
  4866. DH_LVL_TRACE1,
  4867. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  4868. hr));
  4869. }
  4870. }
  4871. // Release root
  4872. if (S_OK == hr)
  4873. {
  4874. hr = pVirtualDFRoot->Close();
  4875. if (S_OK == hr)
  4876. {
  4877. DH_TRACE((
  4878. DH_LVL_TRACE1,
  4879. TEXT("VirtualCtrNode::Close completed successfully.")));
  4880. }
  4881. else
  4882. {
  4883. DH_TRACE((
  4884. DH_LVL_TRACE1,
  4885. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4886. hr));
  4887. }
  4888. }
  4889. // if everything goes well, log test as passed else failed.
  4890. if (S_OK == hr)
  4891. {
  4892. DH_LOG((LOG_PASS, TEXT("Test variation STGTEST_110 passed.")) );
  4893. }
  4894. else
  4895. {
  4896. DH_LOG((LOG_FAIL,
  4897. TEXT("Test variation STGTEST_110 failed, hr = 0x%lx."),
  4898. hr) );
  4899. }
  4900. // Cleanup
  4901. CleanupTestDocfile (&pVirtualDFRoot,
  4902. &pTestVirtualDF,
  4903. &pTestChanceDF,
  4904. S_OK == hr);
  4905. // Delete temp strings
  4906. if (NULL != pvsnRootNewChildStream)
  4907. {
  4908. delete []pvsnRootNewChildStream;
  4909. pvsnRootNewChildStream = NULL;
  4910. }
  4911. for (ulIndex = 0; ulIndex < ulStmNum; ulIndex++)
  4912. {
  4913. if (NULL != pRootNewChildStmName[ulIndex])
  4914. {
  4915. delete pRootNewChildStmName[ulIndex];
  4916. pRootNewChildStmName[ulIndex] = NULL;
  4917. }
  4918. }
  4919. if (NULL != pRootNewChildStmName)
  4920. {
  4921. delete pRootNewChildStmName;
  4922. pRootNewChildStmName = NULL;
  4923. }
  4924. // Stop logging the test
  4925. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STGTEST_110 finished")) );
  4926. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4927. return hr;
  4928. }