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.

4225 lines
120 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: vcpytsts.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to IStorage/IStream copy
  9. // ops
  10. //
  11. // Functions:
  12. //
  13. // History: 15-July-1996 NarindK Created.
  14. // 27-Mar-97 SCousens conversionified
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <dfheader.hxx>
  18. #pragma hdrstop
  19. #include "init.hxx"
  20. //externs
  21. extern BOOL g_fRevert;
  22. //----------------------------------------------------------------------------
  23. //
  24. // Test: VCPYTEST_100
  25. //
  26. // Synopsis: A random root DF is created with random storages/stms, committed
  27. // The root docfile is searched to find a VirtualCtrNode node in tree
  28. // that is a child of the root IStorage. The child IStorage
  29. // is then copied with the destination being the root docfile itself.
  30. // If the 'RevertAfterCopy' switch was specified, the root docfile
  31. // is then reverted and the CRC is recomputed on the root docfile
  32. // and compared to the before copy CRC to verify that no changes
  33. // occurred in the docfile hierarchy. Also it is verified by enum
  34. // rating the docfile before and after opeartion and testing the total
  35. // number of storages and streams in file remain unchanged.
  36. // If case of Revert being FALSE, the contents of the child IStorage
  37. // should be merged in with the contents of the root level of the docfile.
  38. // Verify this case by enumerating the docfile before and after
  39. // CopyTo is done and test that the resulting number of storages &
  40. // streams in the DocFile is as expected.
  41. //
  42. // Arguments:[argc]
  43. // [argv]
  44. //
  45. // Returns: HRESULT
  46. //
  47. // History: 15-July-1996 NarindK Created.
  48. //
  49. // Notes: This test runs in transacted, and transacted deny write modes
  50. //
  51. // New Test Notes:
  52. // 1. Old File: LCCTOP.CXX
  53. // 2. Old name of test : LegitCopyChildDFToParentDF Test
  54. // New Name of test : VCPYTEST_100
  55. // 3. To run the test, do the following at command prompt.
  56. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:2-4 /dfstm:2-3 /t:VCPYTEST-100
  57. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  58. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:2-4 /dfstm:2-3 /t:VCPYTEST-100
  59. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  60. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:2-4 /dfstm:2-3 /t:VCPYTEST-100
  61. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  62. // d. stgbase /seed:2 /dfdepth:1-1 /dfstg:2-4 /dfstm:2-3 /t:VCPYTEST-100
  63. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  64. // e. stgbase /seed:2 /dfdepth:1-1 /dfstg:2-4 /dfstm:2-3 /t:VCPYTEST-100
  65. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  66. //
  67. // BUGNOTE: Conversion: VCPYTEST-100
  68. //
  69. //-----------------------------------------------------------------------------
  70. HRESULT VCPYTEST_100(int argc, char *argv[])
  71. {
  72. HRESULT hr = S_OK;
  73. ChanceDF *pTestChanceDF = NULL;
  74. VirtualDF *pTestVirtualDF = NULL;
  75. VirtualCtrNode *pVirtualDFRoot = NULL;
  76. VirtualCtrNode *pvcnRandomChild = NULL;
  77. VirtualCtrNode *pvcnTrav = NULL;
  78. LPSTORAGE pStgRoot = NULL;
  79. LPSTORAGE pStgChild = NULL;
  80. DG_INTEGER *pdgi = NULL;
  81. USHORT usErr = 0;
  82. ULONG cChildren = 0;
  83. ULONG cRandomChild = 0;
  84. DWORD dwRootMode = 0;
  85. DWORD dwStgMode = 0;
  86. DWORD dwCRC1 = 0;
  87. DWORD dwCRC2 = 0;
  88. ULONG cTotalStg = 0;
  89. ULONG cTotalStm = 0;
  90. ULONG cChildStg = 0;
  91. ULONG cChildStm = 0;
  92. ULONG cResStg = 0;
  93. ULONG cResStm = 0;
  94. BOOL fPass = TRUE;
  95. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_100"));
  96. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  97. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_100 started.")) );
  98. DH_TRACE((DH_LVL_TRACE1,TEXT("Attempt valid copyto op fm child IStg to root")));
  99. // Create our ChanceDF and VirtualDF
  100. hr = CreateTestDocfile (argc,
  101. argv,
  102. &pVirtualDFRoot,
  103. &pTestVirtualDF,
  104. &pTestChanceDF);
  105. // if creating the docfile - bail here
  106. if (NULL != pTestChanceDF && DoingCreate ())
  107. {
  108. UINT ulSeed = pTestChanceDF->GetSeed ();
  109. CleanupTestDocfile (&pVirtualDFRoot,
  110. &pTestVirtualDF,
  111. &pTestChanceDF,
  112. FALSE);
  113. return (HRESULT)ulSeed;
  114. }
  115. if (S_OK == hr)
  116. {
  117. dwRootMode = pTestChanceDF->GetRootMode();
  118. dwStgMode = pTestChanceDF->GetStgMode();
  119. DH_TRACE((
  120. DH_LVL_TRACE1,
  121. TEXT("Run Mode for VCPYTEST_100, Access mode: %lx"),
  122. dwRootMode));
  123. }
  124. // Commit root. BUGBUG whole df already commited
  125. if(S_OK == hr)
  126. {
  127. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  128. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  129. }
  130. if (S_OK == hr)
  131. {
  132. DH_TRACE((
  133. DH_LVL_TRACE1,
  134. TEXT("VirtualCtrNode::Commit completed successfully.")));
  135. }
  136. else
  137. {
  138. DH_TRACE((
  139. DH_LVL_TRACE1,
  140. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  141. hr));
  142. }
  143. if(S_OK == hr)
  144. {
  145. hr = ParseVirtualDFAndCloseOpenStgsStms(
  146. pVirtualDFRoot,
  147. NODE_EXC_TOPSTG);
  148. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  149. }
  150. // Get IStorage pointer for Root
  151. if(S_OK == hr)
  152. {
  153. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  154. DH_ASSERT(NULL != pStgRoot) ;
  155. if(NULL == pStgRoot)
  156. {
  157. hr = E_FAIL;
  158. }
  159. }
  160. // Calulcate CRC for entire docfile.
  161. if((S_OK == hr) && (TRUE == g_fRevert))
  162. {
  163. hr = CalculateCRCForDocFile(pStgRoot,VERIFY_INC_TOPSTG_NAME,&dwCRC1);
  164. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  165. }
  166. // Get DG_INTEGER object pointer
  167. if (S_OK == hr)
  168. {
  169. pdgi = pTestVirtualDF->GetDataGenInteger();
  170. DH_ASSERT(NULL != pdgi);
  171. if(NULL == pdgi)
  172. {
  173. hr = E_FAIL;
  174. }
  175. }
  176. // Find the total number of VirtualCtrNodes and VirtualStmNodes in the
  177. // DocFile
  178. if(S_OK == hr)
  179. {
  180. hr = EnumerateDiskDocFile(pStgRoot, VERIFY_SHORT,&cTotalStg, &cTotalStm);
  181. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  182. }
  183. // Find a random child VirtualCtrNode in the file. First verify there
  184. // are child storages in the tree.
  185. if(S_OK == hr)
  186. {
  187. cChildren = pVirtualDFRoot->GetVirtualCtrNodeChildrenCount();
  188. if(0 == cChildren)
  189. {
  190. DH_TRACE((
  191. DH_LVL_TRACE1,
  192. TEXT("Max original tree depth inadequate to find a child")));
  193. hr = S_FALSE;
  194. }
  195. }
  196. if(S_OK == hr)
  197. {
  198. // Find a random child storage to pick from
  199. usErr = pdgi->Generate(&cRandomChild, 1, cChildren);
  200. if (DG_RC_SUCCESS != usErr)
  201. {
  202. hr = E_FAIL;
  203. }
  204. }
  205. // Pick up the random child node.
  206. if(S_OK == hr)
  207. {
  208. pvcnTrav = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  209. DH_ASSERT(NULL != pvcnTrav);
  210. while((0 != --cRandomChild) &&
  211. (NULL != pvcnTrav->GetFirstSisterVirtualCtrNode()))
  212. {
  213. pvcnTrav = pvcnTrav->GetFirstSisterVirtualCtrNode();
  214. }
  215. pvcnRandomChild = pvcnTrav;
  216. }
  217. if(S_OK == hr)
  218. {
  219. hr = OpenRandomVirtualCtrNodeStg(pvcnRandomChild, dwStgMode);
  220. DH_HRCHECK(hr, TEXT("OpenRandomVirtualCtrNodeStg")) ;
  221. }
  222. if(S_OK == hr)
  223. {
  224. pStgChild = pvcnRandomChild->GetIStoragePointer();
  225. DH_ASSERT(NULL != pStgChild) ;
  226. }
  227. // Find the total number of VirtualCtrNode(s) and VirtualStmNode(s) under
  228. // this node.
  229. if(S_OK == hr)
  230. {
  231. hr = EnumerateDiskDocFile(pStgChild,VERIFY_SHORT,&cChildStg,&cChildStm);
  232. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  233. }
  234. // Copy everything under this child node to the Root node.
  235. if(S_OK == hr)
  236. {
  237. hr = pvcnRandomChild->CopyTo(0, NULL, NULL, pVirtualDFRoot);
  238. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  239. }
  240. if (S_OK == hr)
  241. {
  242. DH_TRACE((
  243. DH_LVL_TRACE1,
  244. TEXT("VirtualCtrNode::CopyTo completed successfully.")));
  245. }
  246. else
  247. {
  248. DH_TRACE((
  249. DH_LVL_TRACE1,
  250. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  251. hr));
  252. }
  253. // Adjust the virtual tree as a result of above operation.
  254. if((S_OK == hr) && (FALSE == g_fRevert))
  255. {
  256. hr = pTestVirtualDF->AdjustTreeOnCopyTo(pvcnRandomChild, pVirtualDFRoot);
  257. DH_HRCHECK(hr, TEXT("VirtualDF::AdjustTreeOnCopyTo")) ;
  258. }
  259. // Commit if g_fRevert is false, else revert
  260. if(S_OK == hr)
  261. {
  262. if(FALSE == g_fRevert)
  263. {
  264. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  265. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  266. if (S_OK == hr)
  267. {
  268. DH_TRACE((
  269. DH_LVL_TRACE1,
  270. TEXT("VirtualCtrNode::Commit completed successfully.")));
  271. }
  272. else
  273. {
  274. DH_TRACE((
  275. DH_LVL_TRACE1,
  276. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  277. hr));
  278. }
  279. }
  280. else
  281. {
  282. hr = pVirtualDFRoot->Revert();
  283. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  284. if (S_OK == hr)
  285. {
  286. DH_TRACE((
  287. DH_LVL_TRACE1,
  288. TEXT("VirtualCtrNode::Revert completed successfully.")));
  289. }
  290. else
  291. {
  292. DH_TRACE((
  293. DH_LVL_TRACE1,
  294. TEXT("VirtualCtrNode::Revert unsuccessful, hr=0x%lx."),
  295. hr));
  296. }
  297. }
  298. }
  299. if(S_OK == hr)
  300. {
  301. hr = CloseRandomVirtualCtrNodeStg(pvcnRandomChild);
  302. DH_HRCHECK(hr, TEXT("CloseRandomVirtualCtrNodeStg")) ;
  303. }
  304. // Calculate the CRC now for the docfile
  305. if((S_OK == hr) && (TRUE == g_fRevert))
  306. {
  307. hr = CalculateCRCForDocFile(pStgRoot,VERIFY_INC_TOPSTG_NAME,&dwCRC2);
  308. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  309. }
  310. // Enumerate the DocFile now
  311. if(S_OK == hr)
  312. {
  313. hr = EnumerateDiskDocFile(pStgRoot,VERIFY_SHORT,&cResStg, &cResStm);
  314. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  315. }
  316. // For verification, if this was a commit opeartion, then CRC's won't match
  317. // ,verify by checking total number of VirtualCtrNodes and VirtualStmNodes
  318. // expected as result of copy opeartion, therby number of IStorages/IStreams
  319. if(S_OK == hr)
  320. {
  321. if(FALSE == g_fRevert)
  322. {
  323. if(cResStg == cTotalStg + (cChildStg-1))
  324. {
  325. DH_TRACE((
  326. DH_LVL_TRACE1,
  327. TEXT("Enum of Stg's after CopyTo & commit as exp.")));
  328. }
  329. else
  330. {
  331. fPass = FALSE;
  332. DH_TRACE((
  333. DH_LVL_TRACE1,
  334. TEXT("Enum of Stg's after CopyTo & Commit not as exp")));
  335. }
  336. if(cResStm == cTotalStm + cChildStm)
  337. {
  338. DH_TRACE((
  339. DH_LVL_TRACE1,
  340. TEXT("Enum of Stm's after CopyTo & commit as exp.")));
  341. }
  342. else
  343. {
  344. fPass = FALSE;
  345. DH_TRACE((
  346. DH_LVL_TRACE1,
  347. TEXT("Enum of Stm's after CopyTo & commit not as exp.")));
  348. }
  349. }
  350. else
  351. {
  352. if(cResStg == cTotalStg)
  353. {
  354. DH_TRACE((
  355. DH_LVL_TRACE1,
  356. TEXT("Enum of Stg's after CopyTo & Revert as exp.")));
  357. }
  358. else
  359. {
  360. fPass = FALSE;
  361. DH_TRACE((
  362. DH_LVL_TRACE1,
  363. TEXT("Enum of Stg's after CopyTo & Revert not as exp.")));
  364. }
  365. if(cResStm == cTotalStm)
  366. {
  367. DH_TRACE((
  368. DH_LVL_TRACE1,
  369. TEXT("Enum of Stm's after CopyTo & Revert as exp.")));
  370. }
  371. else
  372. {
  373. fPass = FALSE;
  374. DH_TRACE((
  375. DH_LVL_TRACE1,
  376. TEXT("Enum of Stm's after CopyTo & Revert not as exp.")));
  377. }
  378. }
  379. }
  380. // If revert operations, the CRC's should match.
  381. if((S_OK == hr) && (TRUE == g_fRevert))
  382. {
  383. if(dwCRC1 == dwCRC2)
  384. {
  385. DH_TRACE((
  386. DH_LVL_TRACE1,
  387. TEXT("CRC's match as exp after CopyTo & Revert Ops")));
  388. }
  389. else
  390. {
  391. fPass = FALSE;
  392. DH_TRACE((
  393. DH_LVL_TRACE1,
  394. TEXT("CRC's don't match as exp after CopyTo & Revert Ops")));
  395. }
  396. }
  397. // Close the Root Docfile.
  398. if (S_OK == hr)
  399. {
  400. hr = pVirtualDFRoot->Close();
  401. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  402. }
  403. if (S_OK == hr)
  404. {
  405. DH_TRACE((
  406. DH_LVL_TRACE1,
  407. TEXT("VirtualCtrNode::Close completed successfully.")));
  408. }
  409. else
  410. {
  411. DH_TRACE((
  412. DH_LVL_TRACE1,
  413. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  414. hr));
  415. }
  416. // if everything goes well, log test as passed else failed.
  417. if ((S_OK == hr) && (TRUE == fPass))
  418. {
  419. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_100 passed.")) );
  420. }
  421. else
  422. {
  423. DH_LOG((LOG_FAIL,
  424. TEXT("Test variation VCPYTEST_100 failed, hr=0x%lx."),
  425. hr) );
  426. // test failed. make sure it failed.
  427. hr = FirstError (hr, E_FAIL);
  428. }
  429. // Cleanup
  430. CleanupTestDocfile (&pVirtualDFRoot,
  431. &pTestVirtualDF,
  432. &pTestChanceDF,
  433. S_OK == hr);
  434. // Stop logging the test
  435. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_100 finished")) );
  436. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  437. return hr;
  438. }
  439. //----------------------------------------------------------------------------
  440. //
  441. // Test: VCPYTEST_101
  442. //
  443. // Synopsis: A random root DF is created with random storages/stms, committed
  444. // The root docfile is tree is then searched for, and for each child
  445. // IStorage found, the CRC is computed for that IStorage (only
  446. // if Revert wasn't specified on the command line). A new child IStorage
  447. // is then created in the root docfile with a unique, random name.
  448. // If Revert was specified in command line,this new empty stg is CRC'd
  449. // The IStorage is then copied to the new child IStorage via CopyTo(). If
  450. // Revert was *not* speficied, the new child IStorage and the root
  451. // docfile are committed, else the dest IStorage is Reverted(). The CRC
  452. // is then computed for the dest IStorage and the CRCs are compared.
  453. //
  454. // Arguments:[argc]
  455. // [argv]
  456. //
  457. // Returns: HRESULT
  458. //
  459. // History: 17-July-1996 NarindK Created.
  460. //
  461. // Notes: This test runs in transacted, and transacted deny write modes
  462. //
  463. // New Test Notes:
  464. // 1. Old File: LCCWPAR.CXX
  465. // 2. Old name of test : LegitCopyChildDFWithinParent Test
  466. // New Name of test : VCPYTEST_101
  467. // 3. To run the test, do the following at command prompt.
  468. // a. stgbase /seed:2 /dfdepth:1-3 /dfstg:2-5 /dfstm:2-3 /t:VCPYTEST-101
  469. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  470. // b. stgbase /seed:2 /dfdepth:1-3 /dfstg:2-5 /dfstm:2-3 /t:VCPYTEST-101
  471. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  472. // c. stgbase /seed:2 /dfdepth:1-3 /dfstg:2-5 /dfstm:2-3 /t:VCPYTEST-101
  473. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  474. // d. stgbase /seed:2 /dfdepth:1-3 /dfstg:2-5 /dfstm:2-3 /t:VCPYTEST-101
  475. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  476. // e. stgbase /seed:2 /dfdepth:1-3 /dfstg:2-5 /dfstm:2-3 /t:VCPYTEST-101
  477. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  478. //
  479. // BUGNOTE: Conversion: VCPYTEST-101
  480. //
  481. //-----------------------------------------------------------------------------
  482. HRESULT VCPYTEST_101(int argc, char *argv[])
  483. {
  484. HRESULT hr = S_OK;
  485. ChanceDF *pTestChanceDF = NULL;
  486. VirtualDF *pTestVirtualDF = NULL;
  487. VirtualCtrNode *pVirtualDFRoot = NULL;
  488. VirtualCtrNode *pvcnTravChild = NULL;
  489. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  490. LPSTORAGE pStgChild = NULL;
  491. DG_STRING *pdgu = NULL;
  492. LPTSTR pRootNewChildStgName = NULL;
  493. DWORD dwRootMode = 0;
  494. DWORD dwStgMode = 0;
  495. DWORD dwCRC1 = 0;
  496. DWORD dwCRC2 = 0;
  497. BOOL fPass = TRUE;
  498. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_101"));
  499. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  500. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_101 started.")) );
  501. DH_TRACE((
  502. DH_LVL_TRACE1,
  503. TEXT("Attempt valid copyto fm childstg to new child stg of parent")));
  504. // Create our ChanceDF and VirtualDF
  505. hr = CreateTestDocfile (argc,
  506. argv,
  507. &pVirtualDFRoot,
  508. &pTestVirtualDF,
  509. &pTestChanceDF);
  510. // if creating the docfile - bail here
  511. if (NULL != pTestChanceDF && DoingCreate ())
  512. {
  513. UINT ulSeed = pTestChanceDF->GetSeed ();
  514. CleanupTestDocfile (&pVirtualDFRoot,
  515. &pTestVirtualDF,
  516. &pTestChanceDF,
  517. FALSE);
  518. return (HRESULT)ulSeed;
  519. }
  520. if (S_OK == hr)
  521. {
  522. dwRootMode = pTestChanceDF->GetRootMode();
  523. dwStgMode = pTestChanceDF->GetStgMode();
  524. DH_TRACE((
  525. DH_LVL_TRACE1,
  526. TEXT("Run Mode for VCPYTEST_101, Access mode: %lx"),
  527. dwRootMode));
  528. }
  529. // Commit root. BUGBUG whole df already commited
  530. if(S_OK == hr)
  531. {
  532. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  533. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  534. }
  535. if (S_OK == hr)
  536. {
  537. DH_TRACE((
  538. DH_LVL_TRACE1,
  539. TEXT("VirtualCtrNode::Commit completed successfully.")));
  540. }
  541. else
  542. {
  543. DH_TRACE((
  544. DH_LVL_TRACE1,
  545. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  546. hr));
  547. }
  548. // Get DG_INTEGER object pointer
  549. if (S_OK == hr)
  550. {
  551. pdgu = pTestVirtualDF->GetDataGenUnicode();
  552. DH_ASSERT(NULL != pdgu) ;
  553. if(NULL == pdgu)
  554. {
  555. hr = E_FAIL;
  556. }
  557. }
  558. // Go in a loop and for each child storage (child VirtualCtrNode) found,
  559. // do a CopyTo operation. Verify with CRC mechanism usnder both commit/
  560. // Rvert conditions.
  561. if (S_OK == hr)
  562. {
  563. pvcnTravChild = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  564. if(NULL == pvcnTravChild)
  565. {
  566. DH_TRACE((
  567. DH_LVL_TRACE1,
  568. TEXT("VirtualDF tree depth inadeuate to have a child.")));
  569. hr = S_FALSE;
  570. }
  571. }
  572. while((NULL != pvcnTravChild) && (S_OK == hr))
  573. {
  574. if(S_OK == hr)
  575. {
  576. hr = ParseVirtualDFAndCloseOpenStgsStms(
  577. pvcnTravChild,
  578. NODE_EXC_TOPSTG);
  579. }
  580. // Calculate CRC for this child VirtualCtrNode
  581. if((S_OK == hr) && (FALSE == g_fRevert))
  582. {
  583. pStgChild = pvcnTravChild->GetIStoragePointer();
  584. hr = CalculateCRCForDocFile(
  585. pStgChild,
  586. VERIFY_EXC_TOPSTG_NAME,
  587. &dwCRC1);
  588. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  589. }
  590. // Now add a new storage
  591. if(S_OK == hr)
  592. {
  593. // Generate random name for storage
  594. hr = GenerateRandomName(
  595. pdgu,
  596. MINLENGTH,
  597. MAXLENGTH,
  598. &pRootNewChildStgName);
  599. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  600. }
  601. if(S_OK == hr)
  602. {
  603. hr = AddStorage(
  604. pTestVirtualDF,
  605. pVirtualDFRoot,
  606. pRootNewChildStgName,
  607. dwStgMode | STGM_FAILIFTHERE,
  608. &pvcnRootNewChildStg);
  609. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  610. DH_ASSERT(S_OK == hr);
  611. }
  612. if(S_OK == hr)
  613. {
  614. DH_TRACE((DH_LVL_TRACE1, TEXT("AddStorage successful.")));
  615. }
  616. else
  617. {
  618. DH_TRACE((
  619. DH_LVL_TRACE1,
  620. TEXT("AddStorage unsuccessful, hr=0x%lx."),
  621. hr));
  622. }
  623. if((S_OK == hr) && (TRUE == g_fRevert))
  624. {
  625. pStgChild = pvcnRootNewChildStg->GetIStoragePointer();
  626. hr = CalculateCRCForDocFile(
  627. pStgChild,
  628. VERIFY_EXC_TOPSTG_NAME,
  629. &dwCRC1);
  630. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  631. }
  632. if(S_OK == hr)
  633. {
  634. hr = pvcnTravChild->CopyTo(0, NULL, NULL, pvcnRootNewChildStg);
  635. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  636. }
  637. if(S_OK == hr)
  638. {
  639. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::CopyTo successful.")));
  640. }
  641. else
  642. {
  643. DH_TRACE((
  644. DH_LVL_TRACE1,
  645. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  646. hr));
  647. }
  648. if(S_OK == hr)
  649. {
  650. if(FALSE == g_fRevert)
  651. {
  652. // Commit the new VirtualCtrNode and Root Node
  653. hr = pvcnRootNewChildStg->Commit(STGC_DEFAULT);
  654. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  655. if(S_OK == hr)
  656. {
  657. DH_TRACE((
  658. DH_LVL_TRACE1,
  659. TEXT("Child VirtualCtrNode::Commit successful.")));
  660. }
  661. else
  662. {
  663. DH_TRACE((
  664. DH_LVL_TRACE1,
  665. TEXT("Child VCN::Commit unsuccessful,hr=0x%lx"),
  666. hr));
  667. }
  668. if(S_OK == hr)
  669. {
  670. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  671. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  672. }
  673. if(S_OK == hr)
  674. {
  675. DH_TRACE((
  676. DH_LVL_TRACE1,
  677. TEXT("Root VirtualCtrNode::Commit successful.")));
  678. }
  679. else
  680. {
  681. DH_TRACE((
  682. DH_LVL_TRACE1,
  683. TEXT("Root VCN::Commit unsuccessful,hr=0x%lx"),
  684. hr));
  685. }
  686. }
  687. else
  688. {
  689. // Revert the new child storage
  690. hr = pvcnRootNewChildStg->Revert();
  691. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  692. if(S_OK == hr)
  693. {
  694. DH_TRACE((
  695. DH_LVL_TRACE1,
  696. TEXT("Child VirtualCtrNode::Revert successful.")));
  697. }
  698. else
  699. {
  700. DH_TRACE((
  701. DH_LVL_TRACE1,
  702. TEXT("Child VCN::Revert unsuccessful,hr=0x%lx"),
  703. hr));
  704. }
  705. }
  706. }
  707. // Calculate CRC for the destination storage now
  708. if(S_OK == hr)
  709. {
  710. pStgChild = pvcnRootNewChildStg->GetIStoragePointer();
  711. if(NULL == pStgChild)
  712. {
  713. hr = E_FAIL;
  714. }
  715. }
  716. if(S_OK == hr)
  717. {
  718. hr = CalculateCRCForDocFile(
  719. pStgChild,
  720. VERIFY_EXC_TOPSTG_NAME,
  721. &dwCRC2);
  722. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  723. }
  724. // Verify CRC
  725. if((S_OK == hr) && (dwCRC1 == dwCRC2))
  726. {
  727. DH_TRACE((
  728. DH_LVL_TRACE1,
  729. TEXT("CRC's of source and dest copied to Stg match.")));
  730. }
  731. else
  732. {
  733. fPass = FALSE;
  734. DH_TRACE((
  735. DH_LVL_TRACE1,
  736. TEXT("CRC's of source and dest copied to Stg don't match.")));
  737. break;
  738. }
  739. // Release source child stg
  740. if(NULL != pvcnTravChild)
  741. {
  742. hr = pvcnTravChild->Close();
  743. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  744. }
  745. // Release new child stg
  746. if(NULL != pvcnRootNewChildStg)
  747. {
  748. hr = pvcnRootNewChildStg->Close();
  749. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  750. }
  751. // Destory new child stg since we are done with it. Also the while
  752. // loop condition depends upon original number of VirtualCtrNodes
  753. if(NULL != pvcnRootNewChildStg)
  754. {
  755. hr = DestroyStorage(pTestVirtualDF, pvcnRootNewChildStg);
  756. DH_HRCHECK(hr, TEXT("DestroyStorage")) ;
  757. }
  758. // Release temp string
  759. if(NULL != pRootNewChildStgName)
  760. {
  761. delete pRootNewChildStgName;
  762. pRootNewChildStgName = NULL;
  763. }
  764. // Advance pvcnTravChild to next and reset pointers to NULL.
  765. pvcnTravChild = pvcnTravChild->GetFirstSisterVirtualCtrNode();
  766. pStgChild = NULL;
  767. pvcnRootNewChildStg = NULL;
  768. }
  769. // Close the Root Docfile.
  770. if (S_OK == hr)
  771. {
  772. hr = pVirtualDFRoot->Close();
  773. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  774. }
  775. if (S_OK == hr)
  776. {
  777. DH_TRACE((
  778. DH_LVL_TRACE1,
  779. TEXT("VirtualCtrNode::Close completed successfully.")));
  780. }
  781. else
  782. {
  783. DH_TRACE((
  784. DH_LVL_TRACE1,
  785. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  786. hr));
  787. }
  788. // if everything goes well, log test as passed else failed.
  789. if ((S_OK == hr) && (TRUE == fPass))
  790. {
  791. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_101 passed.")) );
  792. }
  793. else
  794. {
  795. DH_LOG((LOG_FAIL,
  796. TEXT("Test variation VCPYTEST_101 failed, hr=0x%lx."),
  797. hr) );
  798. // test failed. make sure it failed.
  799. hr = FirstError (hr, E_FAIL);
  800. }
  801. // Cleanup
  802. CleanupTestDocfile (&pVirtualDFRoot,
  803. &pTestVirtualDF,
  804. &pTestChanceDF,
  805. S_OK == hr);
  806. // Stop logging the test
  807. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_101 finished")) );
  808. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  809. return hr;
  810. }
  811. //----------------------------------------------------------------------------
  812. //
  813. // Test: VCPYTEST_102
  814. //
  815. // Synopsis: A random root DF is created with random storages/stms.
  816. // The root docfile is searched for until an IStorage is found that is
  817. // a grandchild of the root IStorage. The docfile is commited.
  818. // The grandchild IStorage is then copied with the destination being
  819. // the root docfile itself.
  820. // If the 'Rever' switch was specified, the root docfile
  821. // is then reverted and the CRC is recomputed on the root docfile
  822. // and compared to the before copy CRC to verify that no changes
  823. // occurred in the docfile hierarchy. Also it is verified by enum
  824. // rating the docfile before and after opeartion and testing the total
  825. // number of storages and streams in file remain unchanged.
  826. // If case of Revert being FALSE, the contents of the grandchild IStorage
  827. // should be merged in with the contents of the root level of the docfile.
  828. // Verify this case by enumerating the docfile before and after
  829. // CopyTo is done and test that the resulting number of storages &
  830. // streams in the DocFile is as expected.
  831. //
  832. // Arguments:[argc]
  833. // [argv]
  834. //
  835. // Returns: HRESULT
  836. //
  837. // History: 17-July-1996 NarindK Created.
  838. //
  839. // Notes: This test runs in transacted, and transacted deny write modes
  840. //
  841. // New Test Notes:
  842. // 1. Old File: LCGCTANC.CXX
  843. // 2. Old name of test : LegitCopyChildDFToAncestorDF Test
  844. // New Name of test : VCPYTEST_102
  845. // 3. To run the test, do the following at command prompt.
  846. // a. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:2-3 /t:VCPYTEST-102
  847. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  848. // b. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:2-3 /t:VCPYTEST-102
  849. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  850. // c. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:2-3 /t:VCPYTEST-102
  851. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  852. // d. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:2-3 /t:VCPYTEST-102
  853. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  854. // e. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:2-3 /t:VCPYTEST-102
  855. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  856. //
  857. // BUGNOTE: Conversion: VCPYTEST-102
  858. //
  859. // This test is almost same as VCPYTEST-100 with difference being that the
  860. // root's grandchild's contents are copied to the root. The difference in
  861. // code is in picking up the random child and in command line parameters.
  862. //-----------------------------------------------------------------------------
  863. HRESULT VCPYTEST_102(int argc, char *argv[])
  864. {
  865. HRESULT hr = S_OK;
  866. ChanceDF *pTestChanceDF = NULL;
  867. VirtualDF *pTestVirtualDF = NULL;
  868. VirtualCtrNode *pVirtualDFRoot = NULL;
  869. VirtualCtrNode *pvcnTrav = NULL;
  870. VirtualCtrNode *pvcnRandomParent = NULL;
  871. VirtualCtrNode *pvcnRandomGrandChild = NULL;
  872. LPSTORAGE pStgRoot = NULL;
  873. LPSTORAGE pStgGrandChild = NULL;
  874. DG_INTEGER *pdgi = NULL;
  875. USHORT usErr = 0;
  876. DWORD dwRootMode = 0;
  877. DWORD dwStgMode = 0;
  878. DWORD dwCRC1 = 0;
  879. DWORD dwCRC2 = 0;
  880. ULONG cTotalStg = 0;
  881. ULONG cTotalStm = 0;
  882. ULONG cChildStg = 0;
  883. ULONG cChildStm = 0;
  884. ULONG cResStg = 0;
  885. ULONG cResStm = 0;
  886. ULONG cDepth = 0;
  887. BOOL fPass = TRUE;
  888. ULONG cChildren = 0;
  889. ULONG cGrandChildren = 0;
  890. ULONG cParentOfGrandChild = 0;
  891. ULONG cRandomGrandChild = 0;
  892. ULONG cRandomParent = 0;
  893. ULONG counter = 0;
  894. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_102"));
  895. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  896. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_102 started.")) );
  897. DH_TRACE((
  898. DH_LVL_TRACE1,
  899. TEXT("Attempt valid copyto operatons from grandchild to root stg")));
  900. // Create our ChanceDF and VirtualDF
  901. hr = CreateTestDocfile (argc,
  902. argv,
  903. &pVirtualDFRoot,
  904. &pTestVirtualDF,
  905. &pTestChanceDF);
  906. // if creating the docfile - bail here
  907. if (NULL != pTestChanceDF && DoingCreate ())
  908. {
  909. UINT ulSeed = pTestChanceDF->GetSeed ();
  910. CleanupTestDocfile (&pVirtualDFRoot,
  911. &pTestVirtualDF,
  912. &pTestChanceDF,
  913. FALSE);
  914. return (HRESULT)ulSeed;
  915. }
  916. if (S_OK == hr)
  917. {
  918. dwRootMode = pTestChanceDF->GetRootMode();
  919. dwStgMode = pTestChanceDF->GetStgMode();
  920. DH_TRACE((
  921. DH_LVL_TRACE1,
  922. TEXT("Run Mode for VCPYTEST_102, Access mode: %lx"),
  923. dwRootMode));
  924. }
  925. // Get DG_INTEGER object pointer
  926. if (S_OK == hr)
  927. {
  928. pdgi = pTestVirtualDF->GetDataGenInteger();
  929. DH_ASSERT(NULL != pdgi);
  930. if(NULL == pdgi)
  931. {
  932. hr = E_FAIL;
  933. }
  934. }
  935. // Find a random grandchild VirtualCtrNode in the file.
  936. // For that first find a random child storage in tree that has grandchild
  937. // storages in tree
  938. if(S_OK == hr)
  939. {
  940. cChildren = pVirtualDFRoot->GetVirtualCtrNodeChildrenCount();
  941. if(0 == cChildren)
  942. {
  943. DH_TRACE((
  944. DH_LVL_TRACE1,
  945. TEXT("Max tree depth inadequate to find a child")));
  946. hr = S_FALSE;
  947. }
  948. }
  949. // Find child nodes with grandchildren.
  950. if(S_OK == hr)
  951. {
  952. pvcnTrav = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  953. DH_ASSERT(NULL != pvcnTrav);
  954. while(NULL != pvcnTrav)
  955. {
  956. if(0 != pvcnTrav->GetVirtualCtrNodeChildrenCount())
  957. {
  958. cParentOfGrandChild++;
  959. }
  960. pvcnTrav = pvcnTrav->GetFirstSisterVirtualCtrNode();
  961. }
  962. if(0 == cParentOfGrandChild)
  963. {
  964. DH_TRACE((
  965. DH_LVL_TRACE1,
  966. TEXT("Max tree depth inadequate to find grandchild")));
  967. hr = S_FALSE;
  968. }
  969. }
  970. // Pick up a random Parent VirtualCtrNode whos have Grand children
  971. // Generate random number
  972. if(S_OK == hr)
  973. {
  974. // Find a random child storage to pick from
  975. usErr = pdgi->Generate(&cRandomParent, 1, cParentOfGrandChild);
  976. if (DG_RC_SUCCESS != usErr)
  977. {
  978. hr = E_FAIL;
  979. }
  980. }
  981. // Pick up the random parent
  982. if(S_OK == hr)
  983. {
  984. pvcnTrav = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  985. while(NULL != pvcnTrav)
  986. {
  987. if(0 != pvcnTrav->GetVirtualCtrNodeChildrenCount())
  988. {
  989. counter++;
  990. }
  991. if(counter == cRandomParent)
  992. {
  993. pvcnRandomParent = pvcnTrav;
  994. break;
  995. }
  996. pvcnTrav = pvcnTrav->GetFirstSisterVirtualCtrNode();
  997. }
  998. }
  999. // Now pick up a random GrandChild storage node from the above random
  1000. // parent
  1001. if(S_OK == hr)
  1002. {
  1003. cGrandChildren = pvcnRandomParent->GetVirtualCtrNodeChildrenCount();
  1004. DH_ASSERT(0 != cGrandChildren);
  1005. // Find a random grandchild storage to pick from
  1006. usErr = pdgi->Generate(&cRandomGrandChild, 1, cGrandChildren);
  1007. if (DG_RC_SUCCESS != usErr)
  1008. {
  1009. hr = E_FAIL;
  1010. }
  1011. if(S_OK == hr)
  1012. {
  1013. pvcnRandomGrandChild =
  1014. pvcnRandomParent->GetFirstChildVirtualCtrNode();
  1015. while((0 != --cRandomGrandChild) && (NULL != pvcnRandomGrandChild))
  1016. {
  1017. pvcnRandomGrandChild =
  1018. pvcnRandomGrandChild->GetFirstSisterVirtualCtrNode();
  1019. }
  1020. }
  1021. }
  1022. // Commit the storages from here upto root.
  1023. if(S_OK == hr)
  1024. {
  1025. hr = pvcnRandomGrandChild->Commit(STGC_DEFAULT);
  1026. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1027. }
  1028. if(S_OK == hr)
  1029. {
  1030. hr = pvcnRandomParent->Commit(STGC_DEFAULT);
  1031. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1032. }
  1033. // Commit root.
  1034. if(S_OK == hr)
  1035. {
  1036. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1037. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1038. }
  1039. if (S_OK == hr)
  1040. {
  1041. DH_TRACE((
  1042. DH_LVL_TRACE1,
  1043. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1044. }
  1045. else
  1046. {
  1047. DH_TRACE((
  1048. DH_LVL_TRACE1,
  1049. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1050. hr));
  1051. }
  1052. // Close all open stgs/stms except root
  1053. if(S_OK == hr)
  1054. {
  1055. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1056. pVirtualDFRoot,
  1057. NODE_EXC_TOPSTG);
  1058. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1059. }
  1060. // Get IStorage pointer for Root
  1061. if(S_OK == hr)
  1062. {
  1063. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  1064. DH_ASSERT(NULL != pStgRoot) ;
  1065. if(NULL == pStgRoot)
  1066. {
  1067. hr = E_FAIL;
  1068. }
  1069. }
  1070. // Calulcate CRC for entire docfile.
  1071. if((S_OK == hr) && (TRUE == g_fRevert))
  1072. {
  1073. hr = CalculateCRCForDocFile(pStgRoot,VERIFY_INC_TOPSTG_NAME,&dwCRC1);
  1074. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1075. }
  1076. // Find the total number of VirtualCtrNodes and VirtualStmNodes in the
  1077. // DocFile
  1078. if(S_OK == hr)
  1079. {
  1080. hr = EnumerateDiskDocFile(pStgRoot, VERIFY_SHORT,&cTotalStg, &cTotalStm);
  1081. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  1082. }
  1083. // Open the grandChildStg from where CopyTo would be done to root.
  1084. if(S_OK == hr)
  1085. {
  1086. hr = OpenRandomVirtualCtrNodeStg(pvcnRandomGrandChild, dwStgMode);
  1087. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1088. }
  1089. // get its istorage pointer.
  1090. if(S_OK == hr)
  1091. {
  1092. pStgGrandChild = pvcnRandomGrandChild->GetIStoragePointer();
  1093. DH_ASSERT(NULL != pStgGrandChild) ;
  1094. if(NULL == pStgGrandChild)
  1095. {
  1096. hr = E_FAIL;
  1097. }
  1098. }
  1099. // Find the total number of VirtualCtrNode(s) and VirtualStmNode(s) under
  1100. // this node. Used for verification of copyto operation.
  1101. if(S_OK == hr)
  1102. {
  1103. hr = EnumerateDiskDocFile(
  1104. pStgGrandChild,
  1105. VERIFY_SHORT,
  1106. &cChildStg,
  1107. &cChildStm);
  1108. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  1109. }
  1110. // Copy everything under this child node to the Root node.
  1111. if(S_OK == hr)
  1112. {
  1113. hr = pvcnRandomGrandChild->CopyTo(0, NULL, NULL, pVirtualDFRoot);
  1114. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  1115. }
  1116. if (S_OK == hr)
  1117. {
  1118. DH_TRACE((
  1119. DH_LVL_TRACE1,
  1120. TEXT("VirtualCtrNode::CopyTo completed successfully.")));
  1121. }
  1122. else
  1123. {
  1124. DH_TRACE((
  1125. DH_LVL_TRACE1,
  1126. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  1127. hr));
  1128. }
  1129. // Adjust the virtual tree as a result of above operation.
  1130. if((S_OK == hr) && (FALSE == g_fRevert))
  1131. {
  1132. hr = pTestVirtualDF->AdjustTreeOnCopyTo(
  1133. pvcnRandomGrandChild,
  1134. pVirtualDFRoot);
  1135. DH_HRCHECK(hr, TEXT("VirtualDF::AdjustTreeOnCopyTo")) ;
  1136. }
  1137. // Commit if g_fRevert is false, else revert
  1138. if(S_OK == hr)
  1139. {
  1140. if(FALSE == g_fRevert)
  1141. {
  1142. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1143. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1144. if (S_OK == hr)
  1145. {
  1146. DH_TRACE((
  1147. DH_LVL_TRACE1,
  1148. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1149. }
  1150. else
  1151. {
  1152. DH_TRACE((
  1153. DH_LVL_TRACE1,
  1154. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1155. hr));
  1156. }
  1157. }
  1158. else
  1159. {
  1160. hr = pVirtualDFRoot->Revert();
  1161. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  1162. if (S_OK == hr)
  1163. {
  1164. DH_TRACE((
  1165. DH_LVL_TRACE1,
  1166. TEXT("VirtualCtrNode::Revert completed successfully.")));
  1167. }
  1168. else
  1169. {
  1170. DH_TRACE((
  1171. DH_LVL_TRACE1,
  1172. TEXT("VirtualCtrNode::Revert unsuccessful, hr=0x%lx."),
  1173. hr));
  1174. }
  1175. }
  1176. }
  1177. if(S_OK == hr)
  1178. {
  1179. hr = CloseRandomVirtualCtrNodeStg(pvcnRandomGrandChild);
  1180. DH_HRCHECK(hr, TEXT("CloseRandomVirtualCtrNodeStg")) ;
  1181. }
  1182. // Calculate the CRC now for the docfile
  1183. if((S_OK == hr) && (TRUE == g_fRevert))
  1184. {
  1185. hr = CalculateCRCForDocFile(pStgRoot,VERIFY_INC_TOPSTG_NAME,&dwCRC2);
  1186. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1187. }
  1188. // Enumerate the DocFile now
  1189. if(S_OK == hr)
  1190. {
  1191. hr = EnumerateDiskDocFile(pStgRoot,VERIFY_SHORT,&cResStg, &cResStm);
  1192. DH_HRCHECK(hr, TEXT("EnumerateDiskDocFile")) ;
  1193. }
  1194. // For verification, if this was a commit opeartion, then CRC's won't match
  1195. // ,verify by checking total number of VirtualCtrNodes and VirtualStmNodes
  1196. // expected as result of copy opeartion, therby number of IStorages/IStreams
  1197. if(S_OK == hr)
  1198. {
  1199. if(FALSE == g_fRevert)
  1200. {
  1201. if(cResStg == cTotalStg + (cChildStg-1))
  1202. {
  1203. DH_TRACE((
  1204. DH_LVL_TRACE1,
  1205. TEXT("Enum of Stg's after CopyTo & commit as exp.")));
  1206. }
  1207. else
  1208. {
  1209. fPass = FALSE;
  1210. DH_TRACE((
  1211. DH_LVL_TRACE1,
  1212. TEXT("Enum of Stg's after CopyTo & Commit not as exp")));
  1213. }
  1214. if(cResStm == cTotalStm + cChildStm)
  1215. {
  1216. DH_TRACE((
  1217. DH_LVL_TRACE1,
  1218. TEXT("Enum of Stm's after CopyTo & commit as exp.")));
  1219. }
  1220. else
  1221. {
  1222. fPass = FALSE;
  1223. DH_TRACE((
  1224. DH_LVL_TRACE1,
  1225. TEXT("Enum of Stm's after CopyTo & commit not as exp.")));
  1226. }
  1227. }
  1228. else
  1229. {
  1230. if(cResStg == cTotalStg)
  1231. {
  1232. DH_TRACE((
  1233. DH_LVL_TRACE1,
  1234. TEXT("Enum of Stg's after CopyTo & Revert as exp.")));
  1235. }
  1236. else
  1237. {
  1238. fPass = FALSE;
  1239. DH_TRACE((
  1240. DH_LVL_TRACE1,
  1241. TEXT("Enum of Stg's after CopyTo & Revert not as exp.")));
  1242. }
  1243. if(cResStm == cTotalStm)
  1244. {
  1245. DH_TRACE((
  1246. DH_LVL_TRACE1,
  1247. TEXT("Enum of Stm's after CopyTo & Revert as exp.")));
  1248. }
  1249. else
  1250. {
  1251. fPass = FALSE;
  1252. DH_TRACE((
  1253. DH_LVL_TRACE1,
  1254. TEXT("Enum of Stm's after CopyTo & Revert not as exp.")));
  1255. }
  1256. }
  1257. }
  1258. // If revert operations, the CRC's should match.
  1259. if((S_OK == hr) && (TRUE == g_fRevert))
  1260. {
  1261. if(dwCRC1 == dwCRC2)
  1262. {
  1263. DH_TRACE((
  1264. DH_LVL_TRACE1,
  1265. TEXT("CRC's match as exp after CopyTo & Revert Ops")));
  1266. }
  1267. else
  1268. {
  1269. fPass = FALSE;
  1270. DH_TRACE((
  1271. DH_LVL_TRACE1,
  1272. TEXT("CRC's don't match as exp after CopyTo & Revert Ops")));
  1273. }
  1274. }
  1275. // Close the Root Docfile.
  1276. if (S_OK == hr)
  1277. {
  1278. hr = pVirtualDFRoot->Close();
  1279. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1280. }
  1281. if (S_OK == hr)
  1282. {
  1283. DH_TRACE((
  1284. DH_LVL_TRACE1,
  1285. TEXT("VirtualCtrNode::Close completed successfully.")));
  1286. }
  1287. else
  1288. {
  1289. DH_TRACE((
  1290. DH_LVL_TRACE1,
  1291. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1292. hr));
  1293. }
  1294. // if everything goes well, log test as passed else failed.
  1295. if ((S_OK == hr) && (TRUE == fPass))
  1296. {
  1297. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_102 passed.")) );
  1298. }
  1299. else
  1300. {
  1301. DH_LOG((LOG_FAIL,
  1302. TEXT("Test variation VCPYTEST_102 failed, hr=0x%lx."),
  1303. hr) );
  1304. // test failed. make sure it failed.
  1305. hr = FirstError (hr, E_FAIL);
  1306. }
  1307. // Cleanup
  1308. CleanupTestDocfile (&pVirtualDFRoot,
  1309. &pTestVirtualDF,
  1310. &pTestChanceDF,
  1311. S_OK == hr);
  1312. // Stop logging the test
  1313. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_102 finished")) );
  1314. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1315. return hr;
  1316. }
  1317. //----------------------------------------------------------------------------
  1318. //
  1319. // Test: VCPYTEST_103
  1320. //
  1321. // Synopsis: A random root DF is created with random storages/stms, committed
  1322. // The root docfile is tree is then searched for, and for each grandchild
  1323. // IStorage found, the CRC is computed for that IStorage (only
  1324. // if Revert wasn't specified on the command line). A new child IStorage
  1325. // is then created in the root docfile with a unique, random name.
  1326. // If Revert was specified in command line,this new empty stg is CRC'd
  1327. // The GrandChild IStorage is copied to new child IStorage via CopyTo().If
  1328. // Revert was *not* speficied, the new child IStorage and the root
  1329. // docfile are committed, else the dest IStorage is Reverted(). The CRC
  1330. // is then computed for the dest IStorage and the CRCs are compared.
  1331. //
  1332. // Arguments:[argc]
  1333. // [argv]
  1334. //
  1335. // Returns: HRESULT
  1336. //
  1337. // History: 18-July-1996 NarindK Created.
  1338. //
  1339. // Notes: This test runs in transacted, and transacted deny write modes
  1340. //
  1341. // New Test Notes:
  1342. // 1. Old File: LCGCWANC.CXX
  1343. // 2. Old name of test : LegitCopyGrandChildDFWithinAncestorDF Test
  1344. // New Name of test : VCPYTEST_103
  1345. // 3. To run the test, do the following at command prompt.
  1346. // a. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:1-3 /t:VCPYTEST-103
  1347. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1348. // b. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:1-3 /t:VCPYTEST-103
  1349. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1350. // c. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:1-3 /t:VCPYTEST-103
  1351. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1352. // d. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:1-3 /t:VCPYTEST-103
  1353. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  1354. // e. stgbase /seed:2 /dfdepth:3-4 /dfstg:4-6 /dfstm:1-3 /t:VCPYTEST-103
  1355. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  1356. //
  1357. // BUGNOTE: Conversion: VCPYTEST-103
  1358. //
  1359. // This test is almost same as VCPYTEST-101 with difference being that the
  1360. // root's grandchild's contents are copied to the root's new child stg.
  1361. //-----------------------------------------------------------------------------
  1362. HRESULT VCPYTEST_103(int argc, char *argv[])
  1363. {
  1364. HRESULT hr = S_OK;
  1365. ChanceDF *pTestChanceDF = NULL;
  1366. VirtualDF *pTestVirtualDF = NULL;
  1367. VirtualCtrNode *pVirtualDFRoot = NULL;
  1368. VirtualCtrNode *pvcnTravGrandChild = NULL;
  1369. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  1370. LPSTORAGE pStgGrandChild = NULL;
  1371. DG_STRING *pdgu = NULL;
  1372. LPTSTR pRootNewChildStgName = NULL;
  1373. DWORD dwRootMode = 0;
  1374. DWORD dwStgMode = 0;
  1375. DWORD dwCRC1 = 0;
  1376. DWORD dwCRC2 = 0;
  1377. BOOL fPass = TRUE;
  1378. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_103"));
  1379. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1380. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_103 started.")) );
  1381. DH_TRACE((
  1382. DH_LVL_TRACE1,
  1383. TEXT("Attempt copyto fm grandchild stg to new childstg of grandparent")));
  1384. // Create our ChanceDF and VirtualDF
  1385. hr = CreateTestDocfile (argc,
  1386. argv,
  1387. &pVirtualDFRoot,
  1388. &pTestVirtualDF,
  1389. &pTestChanceDF);
  1390. // if creating the docfile - bail here
  1391. if (NULL != pTestChanceDF && DoingCreate ())
  1392. {
  1393. UINT ulSeed = pTestChanceDF->GetSeed ();
  1394. CleanupTestDocfile (&pVirtualDFRoot,
  1395. &pTestVirtualDF,
  1396. &pTestChanceDF,
  1397. FALSE);
  1398. return (HRESULT)ulSeed;
  1399. }
  1400. if (S_OK == hr)
  1401. {
  1402. dwRootMode = pTestChanceDF->GetRootMode();
  1403. dwStgMode = pTestChanceDF->GetStgMode();
  1404. DH_TRACE((
  1405. DH_LVL_TRACE1,
  1406. TEXT("Run Mode for VCPYTEST_103, Access mode: %lx"),
  1407. dwRootMode));
  1408. }
  1409. // Commit root. BUGBUG df already commited
  1410. if(S_OK == hr)
  1411. {
  1412. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1413. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1414. }
  1415. if (S_OK == hr)
  1416. {
  1417. DH_TRACE((
  1418. DH_LVL_TRACE1,
  1419. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1420. }
  1421. else
  1422. {
  1423. DH_TRACE((
  1424. DH_LVL_TRACE1,
  1425. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1426. hr));
  1427. }
  1428. // Get DG_INTEGER object pointer
  1429. if (S_OK == hr)
  1430. {
  1431. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1432. DH_ASSERT(NULL != pdgu) ;
  1433. if(NULL == pdgu)
  1434. {
  1435. hr = E_FAIL;
  1436. }
  1437. }
  1438. // Go in a loop and for each grandchild storage (grandchild VirtualCtrNode)
  1439. // found, do a CopyTo operation. Verify with CRC mechanism under both
  1440. // commit/Revert conditions.
  1441. if (S_OK == hr)
  1442. {
  1443. VirtualCtrNode* pNode = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  1444. //keep looking till we think we find one
  1445. while (NULL != pNode && NULL == pNode->GetFirstChildVirtualCtrNode())
  1446. {
  1447. pNode = pNode->GetFirstSisterVirtualCtrNode();
  1448. }
  1449. //this one has the the grandchild
  1450. if (NULL != pNode)
  1451. {
  1452. pvcnTravGrandChild = pNode->GetFirstChildVirtualCtrNode();
  1453. }
  1454. if (NULL == pvcnTravGrandChild)
  1455. {
  1456. hr = S_FALSE;
  1457. DH_TRACE((
  1458. DH_LVL_ERROR,
  1459. TEXT("VirtualDF tree depth inadequate to have grandChild.")));
  1460. }
  1461. }
  1462. while((NULL != pvcnTravGrandChild) && (S_OK == hr))
  1463. {
  1464. if(S_OK == hr)
  1465. {
  1466. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1467. pvcnTravGrandChild,
  1468. NODE_EXC_TOPSTG);
  1469. }
  1470. // Calculate CRC for this grandchild VirtualCtrNode
  1471. if((S_OK == hr) && (FALSE == g_fRevert))
  1472. {
  1473. pStgGrandChild = pvcnTravGrandChild->GetIStoragePointer();
  1474. hr = CalculateCRCForDocFile(
  1475. pStgGrandChild,
  1476. VERIFY_EXC_TOPSTG_NAME,
  1477. &dwCRC1);
  1478. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1479. }
  1480. // Now add a new storage
  1481. if(S_OK == hr)
  1482. {
  1483. // Generate random name for storage
  1484. hr = GenerateRandomName(
  1485. pdgu,
  1486. MINLENGTH,
  1487. MAXLENGTH,
  1488. &pRootNewChildStgName);
  1489. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1490. }
  1491. if(S_OK == hr)
  1492. {
  1493. hr = AddStorage(
  1494. pTestVirtualDF,
  1495. pVirtualDFRoot,
  1496. pRootNewChildStgName,
  1497. dwStgMode | STGM_FAILIFTHERE,
  1498. &pvcnRootNewChildStg);
  1499. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1500. DH_ASSERT(S_OK == hr);
  1501. }
  1502. if(S_OK == hr)
  1503. {
  1504. DH_TRACE((DH_LVL_TRACE1, TEXT("AddStorage successful.")));
  1505. }
  1506. else
  1507. {
  1508. DH_TRACE((
  1509. DH_LVL_TRACE1,
  1510. TEXT("AddStorage unsuccessful, hr=0x%lx."),
  1511. hr));
  1512. }
  1513. if((S_OK == hr) && (TRUE == g_fRevert))
  1514. {
  1515. pStgGrandChild = pvcnRootNewChildStg->GetIStoragePointer();
  1516. hr = CalculateCRCForDocFile(
  1517. pStgGrandChild,
  1518. VERIFY_EXC_TOPSTG_NAME,
  1519. &dwCRC1);
  1520. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1521. }
  1522. if(S_OK == hr)
  1523. {
  1524. hr = pvcnTravGrandChild->CopyTo(0, NULL, NULL, pvcnRootNewChildStg);
  1525. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  1526. }
  1527. if(S_OK == hr)
  1528. {
  1529. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::CopyTo successful.")));
  1530. }
  1531. else
  1532. {
  1533. DH_TRACE((
  1534. DH_LVL_TRACE1,
  1535. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  1536. hr));
  1537. }
  1538. if(S_OK == hr)
  1539. {
  1540. if(FALSE == g_fRevert)
  1541. {
  1542. // Commit the new VirtualCtrNode and Root Node
  1543. hr = pvcnRootNewChildStg->Commit(STGC_DEFAULT);
  1544. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1545. if(S_OK == hr)
  1546. {
  1547. DH_TRACE((
  1548. DH_LVL_TRACE1,
  1549. TEXT("Child VirtualCtrNode::Commit successful.")));
  1550. }
  1551. else
  1552. {
  1553. DH_TRACE((
  1554. DH_LVL_TRACE1,
  1555. TEXT("Child VCN::Commit unsuccessful,hr=0x%lx"),
  1556. hr));
  1557. }
  1558. if(S_OK == hr)
  1559. {
  1560. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1561. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1562. }
  1563. if(S_OK == hr)
  1564. {
  1565. DH_TRACE((
  1566. DH_LVL_TRACE1,
  1567. TEXT("Root VirtualCtrNode::Commit successful.")));
  1568. }
  1569. else
  1570. {
  1571. DH_TRACE((
  1572. DH_LVL_TRACE1,
  1573. TEXT("Root VCN::Commit unsuccessful,hr=0x%lx"),
  1574. hr));
  1575. }
  1576. }
  1577. else
  1578. {
  1579. // Revert the new child storage
  1580. hr = pvcnRootNewChildStg->Revert();
  1581. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  1582. if(S_OK == hr)
  1583. {
  1584. DH_TRACE((
  1585. DH_LVL_TRACE1,
  1586. TEXT("Child VirtualCtrNode::Revert successful.")));
  1587. }
  1588. else
  1589. {
  1590. DH_TRACE((
  1591. DH_LVL_TRACE1,
  1592. TEXT("Child VCN::Revert unsuccessful,hr=0x%lx"),
  1593. hr));
  1594. }
  1595. }
  1596. }
  1597. // Calculate CRC for the destination storage now
  1598. if(S_OK == hr)
  1599. {
  1600. pStgGrandChild = pvcnRootNewChildStg->GetIStoragePointer();
  1601. if(NULL == pStgGrandChild)
  1602. {
  1603. hr = E_FAIL;
  1604. }
  1605. }
  1606. if(S_OK == hr)
  1607. {
  1608. hr = CalculateCRCForDocFile(
  1609. pStgGrandChild,
  1610. VERIFY_EXC_TOPSTG_NAME,
  1611. &dwCRC2);
  1612. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1613. }
  1614. // Verify CRC
  1615. if((S_OK == hr) && (dwCRC1 == dwCRC2))
  1616. {
  1617. DH_TRACE((
  1618. DH_LVL_TRACE1,
  1619. TEXT("CRC's of source and dest copied to Stg match.")));
  1620. }
  1621. else
  1622. {
  1623. fPass = FALSE;
  1624. DH_TRACE((
  1625. DH_LVL_TRACE1,
  1626. TEXT("CRC's of source and dest copied to Stg don't match.")));
  1627. break;
  1628. }
  1629. // Release source child stg
  1630. if(NULL != pvcnTravGrandChild)
  1631. {
  1632. hr = pvcnTravGrandChild->Close();
  1633. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1634. }
  1635. // Release new child stg
  1636. if(NULL != pvcnRootNewChildStg)
  1637. {
  1638. hr = pvcnRootNewChildStg->Close();
  1639. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1640. }
  1641. // Destory new child stg since we are done with it. Also the while
  1642. // loop condition depends upon original number of VirtualCtrNodes
  1643. if(NULL != pvcnRootNewChildStg)
  1644. {
  1645. hr = DestroyStorage(pTestVirtualDF, pvcnRootNewChildStg);
  1646. DH_HRCHECK(hr, TEXT("DestroyStorage")) ;
  1647. }
  1648. // Release temp string
  1649. if(NULL != pRootNewChildStgName)
  1650. {
  1651. delete pRootNewChildStgName;
  1652. pRootNewChildStgName = NULL;
  1653. }
  1654. // Advance pvcnTravGrandChild to next and reset pointers to NULL.
  1655. pvcnTravGrandChild = pvcnTravGrandChild->GetFirstSisterVirtualCtrNode();
  1656. pStgGrandChild = NULL;
  1657. pvcnRootNewChildStg = NULL;
  1658. }
  1659. // Close the Root Docfile.
  1660. if (S_OK == hr)
  1661. {
  1662. hr = pVirtualDFRoot->Close();
  1663. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1664. }
  1665. if (S_OK == hr)
  1666. {
  1667. DH_TRACE((
  1668. DH_LVL_TRACE1,
  1669. TEXT("VirtualCtrNode::Close completed successfully.")));
  1670. }
  1671. else
  1672. {
  1673. DH_TRACE((
  1674. DH_LVL_TRACE1,
  1675. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1676. hr));
  1677. }
  1678. // if everything goes well, log test as passed else failed.
  1679. if ((S_OK == hr) && (TRUE == fPass))
  1680. {
  1681. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_103 passed.")) );
  1682. }
  1683. else
  1684. {
  1685. DH_LOG((LOG_FAIL,
  1686. TEXT("Test variation VCPYTEST_103 failed, hr=0x%lx."),
  1687. hr) );
  1688. // test failed. make sure it failed.
  1689. hr = FirstError (hr, E_FAIL);
  1690. }
  1691. // Cleanup
  1692. CleanupTestDocfile (&pVirtualDFRoot,
  1693. &pTestVirtualDF,
  1694. &pTestChanceDF,
  1695. S_OK == hr);
  1696. // Stop logging the test
  1697. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_103 finished")) );
  1698. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1699. return hr;
  1700. }
  1701. //----------------------------------------------------------------------------
  1702. //
  1703. // Test: VCPYTEST_104
  1704. //
  1705. // Synopsis: A random root DF is created with random storages/stms, committed .
  1706. // Then CRC is computed for entire entire docfile. A new root docfile
  1707. // with a random name is then created. The original root docfile is next
  1708. // copied to the new root docfile via CopyTo() and the new root docfile
  1709. // is committed. The CRC is computed for the new docfile and the CRCs
  1710. // are compared. If revert flag given, the new root docfile is reverted
  1711. // instead of committed and the CRC of the new tree is compared
  1712. // against the CRC of the empty tree.
  1713. //
  1714. // Arguments:[argc]
  1715. // [argv]
  1716. //
  1717. // Returns: HRESULT
  1718. //
  1719. // History: 18-July-1996 NarindK Created.
  1720. //
  1721. // Notes: This test runs in transacted, and transacted deny write modes
  1722. //
  1723. // New Test Notes:
  1724. // 1. Old File: LCROOT.CXX
  1725. // 2. Old name of test : LegitCopyDFToRootDF Test
  1726. // New Name of test : VCPYTEST_104
  1727. // 3. To run the test, do the following at command prompt.
  1728. // a. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-104
  1729. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1730. // b. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-104
  1731. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1732. // c. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-104
  1733. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1734. // d. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-104
  1735. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  1736. // e. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-104
  1737. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  1738. //
  1739. // BUGNOTE: Conversion: VCPYTEST-104
  1740. //
  1741. //-----------------------------------------------------------------------------
  1742. HRESULT VCPYTEST_104(int argc, char *argv[])
  1743. {
  1744. HRESULT hr = S_OK;
  1745. HRESULT hr2 = S_OK;
  1746. ChanceDF *pTestChanceDF = NULL;
  1747. VirtualDF *pTestVirtualDF = NULL;
  1748. VirtualCtrNode *pVirtualDFRoot = NULL;
  1749. ChanceDF *pNewTestChanceDF = NULL;
  1750. VirtualDF *pNewTestVirtualDF = NULL;
  1751. VirtualCtrNode *pNewVirtualDFRoot = NULL;
  1752. DG_STRING *pdgu = NULL;
  1753. LPSTORAGE pStgRootFirstDF = NULL;
  1754. LPSTORAGE pStgRootSecondDF = NULL;
  1755. LPTSTR pNewRootDocFileName = NULL;
  1756. DWORD dwRootMode = 0;
  1757. DWORD dwCRC1 = 0;
  1758. DWORD dwCRC2 = 0;
  1759. BOOL fPass = TRUE;
  1760. CDFD cdfd;
  1761. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_104"));
  1762. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1763. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_104 started.")) );
  1764. DH_TRACE((
  1765. DH_LVL_TRACE1,
  1766. TEXT("Attempt copyto from one Root DocFile to new DocFile root")));
  1767. // Create our ChanceDF and VirtualDF
  1768. hr = CreateTestDocfile (argc,
  1769. argv,
  1770. &pVirtualDFRoot,
  1771. &pTestVirtualDF,
  1772. &pTestChanceDF);
  1773. // if creating the docfile - bail here
  1774. if (NULL != pTestChanceDF && DoingCreate ())
  1775. {
  1776. UINT ulSeed = pTestChanceDF->GetSeed ();
  1777. CleanupTestDocfile (&pVirtualDFRoot,
  1778. &pTestVirtualDF,
  1779. &pTestChanceDF,
  1780. FALSE);
  1781. return (HRESULT)ulSeed;
  1782. }
  1783. if (S_OK == hr)
  1784. {
  1785. dwRootMode = pTestChanceDF->GetRootMode();
  1786. DH_TRACE((
  1787. DH_LVL_TRACE1,
  1788. TEXT("Run Mode for VCPYTEST_104, Access mode: %lx"),
  1789. dwRootMode));
  1790. }
  1791. // Commit root. BUGBUG df already commited
  1792. if(S_OK == hr)
  1793. {
  1794. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1795. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1796. }
  1797. if (S_OK == hr)
  1798. {
  1799. DH_TRACE((
  1800. DH_LVL_TRACE1,
  1801. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1802. }
  1803. else
  1804. {
  1805. DH_TRACE((
  1806. DH_LVL_TRACE1,
  1807. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1808. hr));
  1809. }
  1810. // Close all open stgs/stms except root
  1811. if(S_OK == hr)
  1812. {
  1813. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1814. pVirtualDFRoot,
  1815. NODE_EXC_TOPSTG);
  1816. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1817. }
  1818. if ((S_OK == hr) && (FALSE == g_fRevert))
  1819. {
  1820. pStgRootFirstDF = pVirtualDFRoot->GetIStoragePointer();
  1821. DH_ASSERT(NULL != pStgRootFirstDF);
  1822. hr = CalculateCRCForDocFile(
  1823. pStgRootFirstDF,
  1824. VERIFY_EXC_TOPSTG_NAME,
  1825. &dwCRC1);
  1826. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1827. }
  1828. // Get DG_INTEGER object pointer
  1829. if (S_OK == hr)
  1830. {
  1831. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1832. DH_ASSERT(NULL != pdgu) ;
  1833. if(NULL == pdgu)
  1834. {
  1835. hr = E_FAIL;
  1836. }
  1837. }
  1838. if(S_OK == hr)
  1839. {
  1840. // Generate random name for storage
  1841. hr = GenerateRandomName(
  1842. pdgu,
  1843. MINLENGTH,
  1844. MAXLENGTH,
  1845. &pNewRootDocFileName);
  1846. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1847. }
  1848. // Now Create a new DocFile with random name.
  1849. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1850. if (S_OK == hr)
  1851. {
  1852. pNewTestChanceDF = new ChanceDF();
  1853. if(NULL == pNewTestChanceDF)
  1854. {
  1855. hr = E_OUTOFMEMORY;
  1856. }
  1857. }
  1858. if(S_OK == hr)
  1859. {
  1860. cdfd.cDepthMin = 0;
  1861. cdfd.cDepthMax = 0;
  1862. cdfd.cStgMin = 0;
  1863. cdfd.cStgMax = 0;
  1864. cdfd.cStmMin = 0;
  1865. cdfd.cStmMax = 0;
  1866. cdfd.cbStmMin = 0;
  1867. cdfd.cbStmMax = 0;
  1868. cdfd.ulSeed = pTestChanceDF->GetSeed();
  1869. cdfd.dwRootMode = dwRootMode;
  1870. hr = pNewTestChanceDF->Create(&cdfd, pNewRootDocFileName);
  1871. DH_HRCHECK(hr, TEXT("pNewTestChanceDF->Create"));
  1872. }
  1873. if (S_OK == hr)
  1874. {
  1875. pNewTestVirtualDF = new VirtualDF();
  1876. if(NULL == pNewTestVirtualDF)
  1877. {
  1878. hr = E_OUTOFMEMORY;
  1879. }
  1880. }
  1881. if (S_OK == hr)
  1882. {
  1883. hr = pNewTestVirtualDF->GenerateVirtualDF(
  1884. pNewTestChanceDF,
  1885. &pNewVirtualDFRoot);
  1886. DH_HRCHECK(hr, TEXT("pNewTestVirtualDF->GenerateVirtualDF")) ;
  1887. }
  1888. if (S_OK == hr)
  1889. {
  1890. DH_TRACE((
  1891. DH_LVL_TRACE1,
  1892. TEXT("DocFile - CreateFromParams - successfully created.")));
  1893. }
  1894. else
  1895. {
  1896. DH_TRACE((
  1897. DH_LVL_TRACE1,
  1898. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  1899. hr));
  1900. }
  1901. if(S_OK == hr)
  1902. {
  1903. pStgRootSecondDF = pNewVirtualDFRoot->GetIStoragePointer();
  1904. DH_ASSERT(NULL != pStgRootSecondDF);
  1905. if(NULL == pStgRootSecondDF)
  1906. {
  1907. hr = E_FAIL;
  1908. }
  1909. }
  1910. if((S_OK == hr) && (TRUE == g_fRevert))
  1911. {
  1912. hr = CalculateCRCForDocFile(
  1913. pStgRootSecondDF,
  1914. VERIFY_EXC_TOPSTG_NAME,
  1915. &dwCRC1);
  1916. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1917. }
  1918. if(S_OK == hr)
  1919. {
  1920. hr = pVirtualDFRoot->CopyTo(0, NULL, NULL, pNewVirtualDFRoot);
  1921. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  1922. }
  1923. if(S_OK == hr)
  1924. {
  1925. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::CopyTo successful.")));
  1926. }
  1927. else
  1928. {
  1929. DH_TRACE((
  1930. DH_LVL_TRACE1,
  1931. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  1932. hr));
  1933. }
  1934. if(S_OK == hr)
  1935. {
  1936. if(FALSE == g_fRevert)
  1937. {
  1938. // Commit the new Root Node
  1939. hr = pNewVirtualDFRoot->Commit(STGC_DEFAULT);
  1940. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1941. if(S_OK == hr)
  1942. {
  1943. DH_TRACE((
  1944. DH_LVL_TRACE1,
  1945. TEXT("Child VirtualCtrNode::Commit successful.")));
  1946. }
  1947. else
  1948. {
  1949. DH_TRACE((
  1950. DH_LVL_TRACE1,
  1951. TEXT("Child VCN::Commit unsuccessful,hr=0x%lx"),
  1952. hr));
  1953. }
  1954. }
  1955. else
  1956. {
  1957. // Revert the new root storage
  1958. hr = pNewVirtualDFRoot->Revert();
  1959. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  1960. if(S_OK == hr)
  1961. {
  1962. DH_TRACE((
  1963. DH_LVL_TRACE1,
  1964. TEXT("Child VirtualCtrNode::Revert successful.")));
  1965. }
  1966. else
  1967. {
  1968. DH_TRACE((
  1969. DH_LVL_TRACE1,
  1970. TEXT("Child VCN::Revert unsuccessful,hr=0x%lx"),
  1971. hr));
  1972. }
  1973. }
  1974. }
  1975. // Calculate CRC for the destination root storage now
  1976. if(S_OK == hr)
  1977. {
  1978. hr = CalculateCRCForDocFile(
  1979. pStgRootSecondDF,
  1980. VERIFY_EXC_TOPSTG_NAME,
  1981. &dwCRC2);
  1982. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1983. }
  1984. // Verify CRC
  1985. if((S_OK == hr) && (dwCRC1 == dwCRC2))
  1986. {
  1987. DH_TRACE((
  1988. DH_LVL_TRACE1,
  1989. TEXT("CRC's of source docfile and dest docfile match.")));
  1990. }
  1991. else
  1992. {
  1993. fPass = FALSE;
  1994. DH_TRACE((
  1995. DH_LVL_TRACE1,
  1996. TEXT("CRC's of source docfile and dest docfile don't match.")));
  1997. }
  1998. // Close first Root Docfile.
  1999. if (S_OK == hr)
  2000. {
  2001. hr = pVirtualDFRoot->Close();
  2002. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2003. }
  2004. if (S_OK == hr)
  2005. {
  2006. DH_TRACE((
  2007. DH_LVL_TRACE1,
  2008. TEXT("VirtualCtrNode::Close completed successfully.")));
  2009. }
  2010. else
  2011. {
  2012. DH_TRACE((
  2013. DH_LVL_TRACE1,
  2014. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2015. hr));
  2016. }
  2017. // Close second Root Docfile.
  2018. if (S_OK == hr)
  2019. {
  2020. hr = pNewVirtualDFRoot->Close();
  2021. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2022. }
  2023. if (S_OK == hr)
  2024. {
  2025. DH_TRACE((
  2026. DH_LVL_TRACE1,
  2027. TEXT("VirtualCtrNode::Close completed successfully.")));
  2028. }
  2029. else
  2030. {
  2031. DH_TRACE((
  2032. DH_LVL_TRACE1,
  2033. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2034. hr));
  2035. }
  2036. // if everything goes well, log test as passed else failed.
  2037. if ((S_OK == hr) && (TRUE == fPass))
  2038. {
  2039. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_104 passed.")) );
  2040. }
  2041. else
  2042. {
  2043. DH_LOG((LOG_FAIL,
  2044. TEXT("Test variation VCPYTEST_104 failed, hr=0x%lx."),
  2045. hr) );
  2046. // test failed. make sure it failed.
  2047. hr = FirstError (hr, E_FAIL);
  2048. }
  2049. // Cleanup
  2050. CleanupTestDocfile (&pVirtualDFRoot,
  2051. &pTestVirtualDF,
  2052. &pTestChanceDF,
  2053. S_OK == hr);
  2054. // Delete Chance docfile tree for second DocFile
  2055. if(NULL != pNewTestChanceDF)
  2056. {
  2057. hr2 = pNewTestChanceDF->DeleteChanceDocFileTree(
  2058. pNewTestChanceDF->GetChanceDFRoot());
  2059. DH_HRCHECK(hr2, TEXT("pNewTestChanceDF->DeleteChanceFileDocTree")) ;
  2060. delete pNewTestChanceDF;
  2061. pNewTestChanceDF = NULL;
  2062. }
  2063. // Delete Virtual docfile tree for second docfile
  2064. if(NULL != pNewTestVirtualDF)
  2065. {
  2066. hr2 = pNewTestVirtualDF->DeleteVirtualDocFileTree(pNewVirtualDFRoot);
  2067. DH_HRCHECK(hr2, TEXT("pNewTestVirtualDF->DeleteVirtualFileDocTree")) ;
  2068. delete pNewTestVirtualDF;
  2069. pNewTestVirtualDF = NULL;
  2070. }
  2071. // Delete the second docfile on disk
  2072. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  2073. {
  2074. if(FALSE == DeleteFile(pNewRootDocFileName))
  2075. {
  2076. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2077. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2078. }
  2079. }
  2080. // Delete temp strings
  2081. if(NULL != pNewRootDocFileName)
  2082. {
  2083. delete pNewRootDocFileName;
  2084. pNewRootDocFileName = NULL;
  2085. }
  2086. // Stop logging the test
  2087. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_104 finished")) );
  2088. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2089. return hr;
  2090. }
  2091. //----------------------------------------------------------------------------
  2092. //
  2093. // Test: VCPYTEST_105
  2094. //
  2095. // Synopsis: A random root DF is created with random storages/stms, committed .
  2096. // Then CRC is computed for entire entire docfile. A new root docfile
  2097. // with a random name is then created and a child storage is created
  2098. // inside that. The original root docfile is next copied to the child
  2099. // storage of new root docfile via CopyTo() and the new child & root
  2100. // is committed. The CRC is computed for child storage of new docfile
  2101. // and the CRCs are compared. If revert flag given, the new root docfile
  2102. // child stg is reverted instead of committed and the CRC of the new
  2103. // tree's child stg is compared against the CRC of the child stg before
  2104. // revert.
  2105. //
  2106. // Arguments:[argc]
  2107. // [argv]
  2108. //
  2109. // Returns: HRESULT
  2110. //
  2111. // History: 19-July-1996 NarindK Created.
  2112. //
  2113. // Notes: This test runs in transacted, and transacted deny write modes
  2114. //
  2115. // New Test Notes:
  2116. // 1. Old File: LCNEWPAR.CXX
  2117. // 2. Old name of test : LegitCopyDFWithinNewPar Test
  2118. // New Name of test : VCPYTEST_105
  2119. // 3. To run the test, do the following at command prompt.
  2120. // a. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-105
  2121. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  2122. // b. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-105
  2123. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  2124. // c. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-105
  2125. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  2126. // d. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-105
  2127. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /revert
  2128. // e. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-2 /t:VCPYTEST-105
  2129. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /revert
  2130. //
  2131. // BUGNOTE: Conversion: VCPYTEST-105
  2132. //
  2133. //-----------------------------------------------------------------------------
  2134. HRESULT VCPYTEST_105(int argc, char *argv[])
  2135. {
  2136. HRESULT hr = S_OK;
  2137. HRESULT hr2 = S_OK;
  2138. ChanceDF *pTestChanceDF = NULL;
  2139. VirtualDF *pTestVirtualDF = NULL;
  2140. VirtualCtrNode *pVirtualDFRoot = NULL;
  2141. ChanceDF *pNewTestChanceDF = NULL;
  2142. VirtualDF *pNewTestVirtualDF = NULL;
  2143. VirtualCtrNode *pNewVirtualDFRoot = NULL;
  2144. VirtualCtrNode *pvcnNewRootNewChildStg = NULL;
  2145. DG_STRING *pdgu = NULL;
  2146. LPSTORAGE pStgRootFirstDF = NULL;
  2147. LPTSTR pNewRootDocFileName = NULL;
  2148. LPTSTR pNewRootNewChildStgName = NULL;
  2149. LPSTORAGE pStgChildRootSecondDF = NULL;
  2150. DWORD dwRootMode = 0;
  2151. DWORD dwStgMode = 0;
  2152. DWORD dwCRC1 = 0;
  2153. DWORD dwCRC2 = 0;
  2154. BOOL fPass = TRUE;
  2155. CDFD cdfd;
  2156. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_105"));
  2157. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2158. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_105 started.")) );
  2159. DH_TRACE((
  2160. DH_LVL_TRACE1,
  2161. TEXT("Do copyto fm one Root DocFile to new DocFile's child stg")));
  2162. // Create our ChanceDF and VirtualDF
  2163. hr = CreateTestDocfile (argc,
  2164. argv,
  2165. &pVirtualDFRoot,
  2166. &pTestVirtualDF,
  2167. &pTestChanceDF);
  2168. // if creating the docfile - bail here
  2169. if (NULL != pTestChanceDF && DoingCreate ())
  2170. {
  2171. UINT ulSeed = pTestChanceDF->GetSeed ();
  2172. CleanupTestDocfile (&pVirtualDFRoot,
  2173. &pTestVirtualDF,
  2174. &pTestChanceDF,
  2175. FALSE);
  2176. return (HRESULT)ulSeed;
  2177. }
  2178. if (S_OK == hr)
  2179. {
  2180. dwRootMode = pTestChanceDF->GetRootMode();
  2181. dwStgMode = pTestChanceDF->GetStgMode();
  2182. DH_TRACE((
  2183. DH_LVL_TRACE1,
  2184. TEXT("Run Mode for VCPYTEST_105, Access mode: %lx"),
  2185. dwRootMode));
  2186. }
  2187. // Commit root. BUGBUG df already commited
  2188. if(S_OK == hr)
  2189. {
  2190. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2191. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2192. }
  2193. if (S_OK == hr)
  2194. {
  2195. DH_TRACE((
  2196. DH_LVL_TRACE1,
  2197. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2198. }
  2199. else
  2200. {
  2201. DH_TRACE((
  2202. DH_LVL_TRACE1,
  2203. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  2204. hr));
  2205. }
  2206. // Close all open stgs/stms except root
  2207. if(S_OK == hr)
  2208. {
  2209. hr = ParseVirtualDFAndCloseOpenStgsStms(
  2210. pVirtualDFRoot,
  2211. NODE_EXC_TOPSTG);
  2212. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  2213. }
  2214. if ((S_OK == hr) && (FALSE == g_fRevert))
  2215. {
  2216. pStgRootFirstDF = pVirtualDFRoot->GetIStoragePointer();
  2217. DH_ASSERT(NULL != pStgRootFirstDF);
  2218. hr = CalculateCRCForDocFile(
  2219. pStgRootFirstDF,
  2220. VERIFY_EXC_TOPSTG_NAME,
  2221. &dwCRC1);
  2222. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2223. }
  2224. // Get DG_INTEGER object pointer
  2225. if (S_OK == hr)
  2226. {
  2227. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2228. DH_ASSERT(NULL != pdgu) ;
  2229. if(NULL == pdgu)
  2230. {
  2231. hr = E_FAIL;
  2232. }
  2233. }
  2234. if(S_OK == hr)
  2235. {
  2236. // Generate random name for storage
  2237. hr = GenerateRandomName(
  2238. pdgu,
  2239. MINLENGTH,
  2240. MAXLENGTH,
  2241. &pNewRootDocFileName);
  2242. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2243. }
  2244. // Now Create a new DocFile with random name.
  2245. // Create the new ChanceDocFile tree that would consist of chance nodes.
  2246. if (S_OK == hr)
  2247. {
  2248. pNewTestChanceDF = new ChanceDF();
  2249. if(NULL == pNewTestChanceDF)
  2250. {
  2251. hr = E_OUTOFMEMORY;
  2252. }
  2253. }
  2254. if(S_OK == hr)
  2255. {
  2256. cdfd.cDepthMin = 0;
  2257. cdfd.cDepthMax = 0;
  2258. cdfd.cStgMin = 0;
  2259. cdfd.cStgMax = 0;
  2260. cdfd.cStmMin = 0;
  2261. cdfd.cStmMax = 0;
  2262. cdfd.cbStmMin = 0;
  2263. cdfd.cbStmMax = 0;
  2264. cdfd.ulSeed = pTestChanceDF->GetSeed();
  2265. cdfd.dwRootMode = dwRootMode;
  2266. hr = pNewTestChanceDF->Create(&cdfd, pNewRootDocFileName);
  2267. DH_HRCHECK(hr, TEXT("pNewTestChanceDF->Create"));
  2268. }
  2269. if (S_OK == hr)
  2270. {
  2271. pNewTestVirtualDF = new VirtualDF();
  2272. if(NULL == pNewTestVirtualDF)
  2273. {
  2274. hr = E_OUTOFMEMORY;
  2275. }
  2276. }
  2277. if (S_OK == hr)
  2278. {
  2279. hr = pNewTestVirtualDF->GenerateVirtualDF(
  2280. pNewTestChanceDF,
  2281. &pNewVirtualDFRoot);
  2282. DH_HRCHECK(hr, TEXT("pNewTestVirtualDF->GenerateVirtualDF")) ;
  2283. }
  2284. if (S_OK == hr)
  2285. {
  2286. DH_TRACE((
  2287. DH_LVL_TRACE1,
  2288. TEXT("DocFile - CreateFromParams - successfully created.")));
  2289. }
  2290. else
  2291. {
  2292. DH_TRACE((
  2293. DH_LVL_TRACE1,
  2294. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  2295. hr));
  2296. }
  2297. // Create a new child storage in this new root docfile.
  2298. if(S_OK == hr)
  2299. {
  2300. // Generate random name for this child stg
  2301. hr = GenerateRandomName(
  2302. pdgu,
  2303. MINLENGTH,
  2304. MAXLENGTH,
  2305. &pNewRootNewChildStgName);
  2306. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2307. }
  2308. if(S_OK == hr)
  2309. {
  2310. hr = AddStorage(
  2311. pTestVirtualDF,
  2312. pNewVirtualDFRoot,
  2313. pNewRootNewChildStgName,
  2314. dwStgMode | STGM_FAILIFTHERE,
  2315. &pvcnNewRootNewChildStg);
  2316. }
  2317. if(S_OK == hr)
  2318. {
  2319. DH_TRACE((DH_LVL_TRACE1, TEXT("AddStorage successful.")));
  2320. }
  2321. else
  2322. {
  2323. DH_TRACE((
  2324. DH_LVL_TRACE1,
  2325. TEXT("AddStorage unsuccessful, hr=0x%lx."),
  2326. hr));
  2327. }
  2328. if(S_OK == hr)
  2329. {
  2330. pStgChildRootSecondDF = pvcnNewRootNewChildStg->GetIStoragePointer();
  2331. DH_ASSERT(NULL != pStgChildRootSecondDF);
  2332. if(NULL == pStgChildRootSecondDF)
  2333. {
  2334. hr = E_FAIL;
  2335. }
  2336. }
  2337. if((S_OK == hr) && (TRUE == g_fRevert))
  2338. {
  2339. hr = CalculateCRCForDocFile(
  2340. pStgChildRootSecondDF,
  2341. VERIFY_EXC_TOPSTG_NAME,
  2342. &dwCRC1);
  2343. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2344. }
  2345. if(S_OK == hr)
  2346. {
  2347. hr = pVirtualDFRoot->CopyTo(0, NULL, NULL, pvcnNewRootNewChildStg);
  2348. DH_HRCHECK(hr, TEXT("VirtualCtrNode::CopyTo")) ;
  2349. }
  2350. if(S_OK == hr)
  2351. {
  2352. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::CopyTo successful.")));
  2353. }
  2354. else
  2355. {
  2356. DH_TRACE((
  2357. DH_LVL_TRACE1,
  2358. TEXT("VirtualCtrNode::CopyTo unsuccessful, hr=0x%lx."),
  2359. hr));
  2360. }
  2361. if(S_OK == hr)
  2362. {
  2363. if(FALSE == g_fRevert)
  2364. {
  2365. // Commit the new VirtualCtrNode and Root Node
  2366. hr = pvcnNewRootNewChildStg->Commit(STGC_DEFAULT);
  2367. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2368. if(S_OK == hr)
  2369. {
  2370. DH_TRACE((
  2371. DH_LVL_TRACE1,
  2372. TEXT("Child VirtualCtrNode::Commit successful.")));
  2373. }
  2374. else
  2375. {
  2376. DH_TRACE((
  2377. DH_LVL_TRACE1,
  2378. TEXT("Child VCN::Commit unsuccessful,hr=0x%lx"),
  2379. hr));
  2380. }
  2381. if(S_OK == hr)
  2382. {
  2383. hr = pNewVirtualDFRoot->Commit(STGC_DEFAULT);
  2384. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  2385. if(S_OK == hr)
  2386. {
  2387. DH_TRACE((
  2388. DH_LVL_TRACE1,
  2389. TEXT("Root VirtualCtrNode::Commit successful.")));
  2390. }
  2391. else
  2392. {
  2393. DH_TRACE((
  2394. DH_LVL_TRACE1,
  2395. TEXT("Root VCN::Commit unsuccessful,hr=0x%lx"),
  2396. hr));
  2397. }
  2398. }
  2399. }
  2400. else
  2401. {
  2402. // Revert the new child storage
  2403. hr = pvcnNewRootNewChildStg->Revert();
  2404. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Revert")) ;
  2405. if(S_OK == hr)
  2406. {
  2407. DH_TRACE((
  2408. DH_LVL_TRACE1,
  2409. TEXT("Child VirtualCtrNode::Revert successful.")));
  2410. }
  2411. else
  2412. {
  2413. DH_TRACE((
  2414. DH_LVL_TRACE1,
  2415. TEXT("Child VCN::Revert unsuccessful,hr=0x%lx"),
  2416. hr));
  2417. }
  2418. }
  2419. }
  2420. // Calculate CRC for the destination storage now
  2421. if(S_OK == hr)
  2422. {
  2423. hr = CalculateCRCForDocFile(
  2424. pStgChildRootSecondDF,
  2425. VERIFY_EXC_TOPSTG_NAME,
  2426. &dwCRC2);
  2427. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  2428. }
  2429. // Verify CRC
  2430. if((S_OK == hr) && (dwCRC1 == dwCRC2))
  2431. {
  2432. DH_TRACE((
  2433. DH_LVL_TRACE1,
  2434. TEXT("CRC's of source docfile and dest docfile's stg match.")));
  2435. }
  2436. else
  2437. {
  2438. fPass = FALSE;
  2439. DH_TRACE((
  2440. DH_LVL_TRACE1,
  2441. TEXT("CRC's of source docfile &dest docfile's stg don't match.")));
  2442. }
  2443. // Close first Root Docfile.
  2444. if (S_OK == hr)
  2445. {
  2446. hr = pVirtualDFRoot->Close();
  2447. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2448. }
  2449. if (S_OK == hr)
  2450. {
  2451. DH_TRACE((
  2452. DH_LVL_TRACE1,
  2453. TEXT("VirtualCtrNode::Close completed successfully.")));
  2454. }
  2455. else
  2456. {
  2457. DH_TRACE((
  2458. DH_LVL_TRACE1,
  2459. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2460. hr));
  2461. }
  2462. // Close second Root Docfile's child stg.
  2463. if (S_OK == hr)
  2464. {
  2465. hr = pvcnNewRootNewChildStg->Close();
  2466. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2467. }
  2468. if (S_OK == hr)
  2469. {
  2470. DH_TRACE((
  2471. DH_LVL_TRACE1,
  2472. TEXT("VirtualCtrNode::Close completed successfully.")));
  2473. }
  2474. else
  2475. {
  2476. DH_TRACE((
  2477. DH_LVL_TRACE1,
  2478. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2479. hr));
  2480. }
  2481. // Close second Root Docfile.
  2482. if (S_OK == hr)
  2483. {
  2484. hr = pNewVirtualDFRoot->Close();
  2485. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2486. }
  2487. if (S_OK == hr)
  2488. {
  2489. DH_TRACE((
  2490. DH_LVL_TRACE1,
  2491. TEXT("VirtualCtrNode::Close completed successfully.")));
  2492. }
  2493. else
  2494. {
  2495. DH_TRACE((
  2496. DH_LVL_TRACE1,
  2497. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2498. hr));
  2499. }
  2500. // if everything goes well, log test as passed else failed.
  2501. if ((S_OK == hr) && (TRUE == fPass))
  2502. {
  2503. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_105 passed.")) );
  2504. }
  2505. else
  2506. {
  2507. DH_LOG((LOG_FAIL,
  2508. TEXT("Test variation VCPYTEST_105 failed, hr=0x%lx."),
  2509. hr) );
  2510. // test failed. make sure it failed.
  2511. hr = FirstError (hr, E_FAIL);
  2512. }
  2513. // Cleanup
  2514. CleanupTestDocfile (&pVirtualDFRoot,
  2515. &pTestVirtualDF,
  2516. &pTestChanceDF,
  2517. S_OK == hr);
  2518. // Delete Chance docfile tree for second DocFile
  2519. if(NULL != pNewTestChanceDF)
  2520. {
  2521. hr2 = pNewTestChanceDF->DeleteChanceDocFileTree(
  2522. pNewTestChanceDF->GetChanceDFRoot());
  2523. DH_HRCHECK(hr2, TEXT("pNewTestChanceDF->DeleteChanceFileDocTree")) ;
  2524. delete pNewTestChanceDF;
  2525. pNewTestChanceDF = NULL;
  2526. }
  2527. // Delete Virtual docfile tree for second docfile
  2528. if(NULL != pNewTestVirtualDF)
  2529. {
  2530. hr2 = pNewTestVirtualDF->DeleteVirtualDocFileTree(pNewVirtualDFRoot);
  2531. DH_HRCHECK(hr2, TEXT("pNewTestVirtualDF->DeleteVirtualFileDocTree")) ;
  2532. delete pNewTestVirtualDF;
  2533. pNewTestVirtualDF = NULL;
  2534. }
  2535. // Delete the second docfile on disk
  2536. if((S_OK == hr) && (NULL != pNewRootDocFileName))
  2537. {
  2538. if(FALSE == DeleteFile(pNewRootDocFileName))
  2539. {
  2540. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2541. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2542. }
  2543. }
  2544. // Delete temp strings
  2545. if(NULL != pNewRootDocFileName)
  2546. {
  2547. delete pNewRootDocFileName;
  2548. pNewRootDocFileName = NULL;
  2549. }
  2550. if(NULL != pNewRootNewChildStgName)
  2551. {
  2552. delete pNewRootNewChildStgName;
  2553. pNewRootNewChildStgName = NULL;
  2554. }
  2555. // Stop logging the test
  2556. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_105 finished")) );
  2557. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2558. return hr;
  2559. }
  2560. //----------------------------------------------------------------------------
  2561. //
  2562. // Test: VCPYTEST_106
  2563. //
  2564. // Synopsis: A root docfile is created and two streams are created within it,
  2565. // a SOURCE IStream and a DEST IStream. A clone is made of the DEST
  2566. // IStream. A random number of bytes are written to the SOURCE
  2567. // IStream.
  2568. // From 10 to 20 times, a random starting position and number of
  2569. // bytes to copy is chosen in the SOURCE IStream. These bytes are
  2570. // read and CRC'd and the SOURCE IStream seek pointer is then
  2571. // repositoned to the intended copy source offset. A random copy
  2572. // destination offset is chosen in either the DEST or CLONE IStream.
  2573. // The non-target regions of the destination IStream (those bytes
  2574. // before and after the copy target region) are read and CRC'd
  2575. // and the destination seek pointer is re-positioned to the
  2576. // destination offset. The SOURCE IStream region is then copied to
  2577. // destination (DEST or CLONE) IStream. The entire destination
  2578. // stream is then read and CRCs are verified to ensure that the copy
  2579. // was successful.
  2580. //
  2581. // Arguments:[argc]
  2582. // [argv]
  2583. //
  2584. // Returns: HRESULT
  2585. //
  2586. // Notes: This test runs in direct, transacted, and transacted deny write
  2587. // modes
  2588. //
  2589. // New Test Notes:
  2590. // 1. Old File(s): LCSTREAM.CXX
  2591. // 2. Old name of test(s) : LegitCopyStream test
  2592. // New Name of test(s) : VCPYTEST_106
  2593. // 3. To run the test, do the following at command prompt.
  2594. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:VCPYTEST-106
  2595. // /dfRootMode:dirReadWriteShEx
  2596. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:VCPYTEST-106
  2597. // /dfRootMode:xactReadWriteShEx
  2598. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:VCPYTEST-106
  2599. // /dfRootMode:xactReadWriteShDenyW
  2600. //
  2601. // BUGNOTE: Conversion: VCPYTEST-106
  2602. //
  2603. // History: Jiminli 24-July-96 Created
  2604. //-----------------------------------------------------------------------------
  2605. HRESULT VCPYTEST_106(int argc, char *argv[])
  2606. {
  2607. HRESULT hr = S_OK;
  2608. ChanceDF *pTestChanceDF = NULL;
  2609. VirtualDF *pTestVirtualDF = NULL;
  2610. VirtualCtrNode *pVirtualDFRoot = NULL;
  2611. DG_STRING *pdgu = NULL;
  2612. DG_INTEGER *pdgi = NULL;
  2613. USHORT usErr = 0;
  2614. LPTSTR ptcsBuffer = NULL;
  2615. LPBYTE ptcsReadBuffer = NULL;
  2616. USHORT usNumIterations = 0;
  2617. USHORT usMinIteration = 10;
  2618. USHORT usMaxIteration = 20;
  2619. ULONG culBytesLeftToWrite = 0;
  2620. ULONG culBytesRead = 0;
  2621. ULONG ulIStreamSize = 0;
  2622. ULONG culIOBytes = 0;
  2623. ULONG culWritten = 0;
  2624. ULONG culRead = 0;
  2625. ULONG culRandomCommit = 0;
  2626. ULONG ulRef = 0;
  2627. DWORD dwRootMode = 0;
  2628. DWORD dwCRC[3][3];
  2629. DWORD dwTempCRC = 0;
  2630. DWORD dwSourceCRC = 0;
  2631. BYTE biIStream = 0;
  2632. BYTE biInUse = 0;
  2633. BOOL fPass = TRUE;
  2634. ULONG ulPosition[3];
  2635. ULONG ulNewPosition[3];
  2636. VirtualStmNode *pvsnRootNewChildStream[2];
  2637. LPTSTR pRootNewChildStmName[2];
  2638. LPSTREAM pIStream[3];
  2639. LARGE_INTEGER liStreamPos;
  2640. ULARGE_INTEGER uliCopy;
  2641. ULARGE_INTEGER uli;
  2642. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("VCPYTEST_106"));
  2643. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2644. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_106 started.")) );
  2645. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt valid CopyTo operation b/w streams.")) );
  2646. // Initialize pointers
  2647. pIStream[SOURCESTM] = pIStream[DESTSTM] = pIStream[CLONESTM] = NULL;
  2648. pRootNewChildStmName[SOURCESTM] = pRootNewChildStmName[DESTSTM] = NULL;
  2649. pvsnRootNewChildStream[SOURCESTM] = pvsnRootNewChildStream[DESTSTM] = NULL;
  2650. // Create our ChanceDF and VirtualDF
  2651. hr = CreateTestDocfile (argc,
  2652. argv,
  2653. &pVirtualDFRoot,
  2654. &pTestVirtualDF,
  2655. &pTestChanceDF);
  2656. // if creating the docfile - bail here
  2657. if (NULL != pTestChanceDF && DoingCreate ())
  2658. {
  2659. UINT ulSeed = pTestChanceDF->GetSeed ();
  2660. CleanupTestDocfile (&pVirtualDFRoot,
  2661. &pTestVirtualDF,
  2662. &pTestChanceDF,
  2663. FALSE);
  2664. return (HRESULT)ulSeed;
  2665. }
  2666. if (S_OK == hr)
  2667. {
  2668. dwRootMode = pTestChanceDF->GetRootMode();
  2669. DH_TRACE((
  2670. DH_LVL_TRACE1,
  2671. TEXT("Run Mode for VCPYTEST_106, Access mode: %lx"),
  2672. dwRootMode));
  2673. }
  2674. // Get DG_STRING object pointer
  2675. if (S_OK == hr)
  2676. {
  2677. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2678. DH_ASSERT(NULL != pdgu) ;
  2679. if(NULL == pdgu)
  2680. {
  2681. hr = E_FAIL;
  2682. }
  2683. }
  2684. // Get DG_INTEGER object pointer
  2685. if (S_OK == hr)
  2686. {
  2687. pdgi = pTestVirtualDF->GetDataGenInteger();
  2688. DH_ASSERT(NULL != pdgi) ;
  2689. if(NULL == pdgi)
  2690. {
  2691. hr = E_FAIL;
  2692. }
  2693. }
  2694. // Adds source and destination IStreams to the root storage.
  2695. if (S_OK == hr)
  2696. {
  2697. // Generate random names for streams
  2698. for (biIStream=SOURCESTM; biIStream <= DESTSTM; biIStream++)
  2699. {
  2700. pRootNewChildStmName[biIStream] = NULL;
  2701. hr = GenerateRandomName(
  2702. pdgu,
  2703. MINLENGTH,
  2704. MAXLENGTH,
  2705. &pRootNewChildStmName[biIStream]);
  2706. if(S_OK != hr)
  2707. {
  2708. break;
  2709. }
  2710. }
  2711. DH_HRCHECK(hr, TEXT("GenerateRandomName"));
  2712. }
  2713. if (S_OK == hr)
  2714. {
  2715. for (biIStream=SOURCESTM; biIStream <= DESTSTM; biIStream++)
  2716. {
  2717. // Initialize
  2718. pIStream[biIStream] = NULL;
  2719. ulPosition[biIStream] = 0L;
  2720. hr = AddStream(
  2721. pTestVirtualDF,
  2722. pVirtualDFRoot,
  2723. pRootNewChildStmName[biIStream],
  2724. 0,
  2725. STGM_READWRITE |
  2726. STGM_SHARE_EXCLUSIVE |
  2727. STGM_FAILIFTHERE,
  2728. &pvsnRootNewChildStream[biIStream]);
  2729. if(S_OK != hr)
  2730. {
  2731. break;
  2732. }
  2733. // Get IStream pointers
  2734. if(S_OK == hr)
  2735. {
  2736. pIStream[biIStream] = pvsnRootNewChildStream[biIStream]->
  2737. GetIStreamPointer();
  2738. }
  2739. }
  2740. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2741. }
  2742. if (S_OK == hr)
  2743. {
  2744. DH_TRACE((
  2745. DH_LVL_TRACE1,
  2746. TEXT("VirtualStmNode::AddStream completed successfully.")));
  2747. }
  2748. else
  2749. {
  2750. DH_TRACE((
  2751. DH_LVL_TRACE1,
  2752. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  2753. hr));
  2754. }
  2755. //
  2756. // Generate Cloned IStream
  2757. if(S_OK == hr)
  2758. {
  2759. hr = pvsnRootNewChildStream[SOURCESTM]->Clone(&pIStream[CLONESTM]);
  2760. ulPosition[CLONESTM] = 0L;
  2761. DH_HRCHECK(hr, TEXT("VirtualStmNode::Clone")) ;
  2762. }
  2763. if(S_OK == hr)
  2764. {
  2765. DH_TRACE((
  2766. DH_LVL_TRACE1,
  2767. TEXT("VirtualStmNode::Clone completed successfully.")));
  2768. }
  2769. else
  2770. {
  2771. DH_TRACE((
  2772. DH_LVL_TRACE1,
  2773. TEXT("VirtualStmNode::Clone not successful, hr=0x%lx."),
  2774. hr));
  2775. }
  2776. // Pick a size for the source IStream
  2777. if (S_OK == hr)
  2778. {
  2779. // Generate random size for stream between 1L, and MIN_SIZE * 1.5
  2780. // (from old test)
  2781. usErr = pdgi->Generate(&ulIStreamSize, 1L, (ULONG) (MIN_SIZE * 1.5));
  2782. culIOBytes = ulIStreamSize;
  2783. if (DG_RC_SUCCESS != usErr)
  2784. {
  2785. hr = E_FAIL;
  2786. }
  2787. }
  2788. // Call VirtualStmNode::Write to create random bytes in the stream.
  2789. // For our test purposes, we generate a random string of size
  2790. // culIOBytes using GenerateRandomString function.
  2791. if (S_OK == hr)
  2792. {
  2793. hr = GenerateRandomString(
  2794. pdgu,
  2795. culIOBytes,
  2796. culIOBytes,
  2797. &ptcsBuffer);
  2798. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  2799. }
  2800. if (S_OK == hr)
  2801. {
  2802. hr = pvsnRootNewChildStream[SOURCESTM]->Write(
  2803. (LPBYTE)ptcsBuffer,
  2804. culIOBytes,
  2805. &culWritten);
  2806. }
  2807. if (S_OK != hr)
  2808. {
  2809. DH_TRACE((
  2810. DH_LVL_TRACE1,
  2811. TEXT("VirtualStmNode::Write wasn't successful, hr=0x%lx."),
  2812. hr));
  2813. }
  2814. // Calculate dwSourceCRC to be used in the first pass of the loop
  2815. if (S_OK == hr)
  2816. {
  2817. hr = CalculateCRCForDataBuffer(
  2818. ptcsBuffer,
  2819. culIOBytes,
  2820. &dwSourceCRC);
  2821. }
  2822. if (S_OK != hr)
  2823. {
  2824. DH_TRACE((
  2825. DH_LVL_TRACE1,
  2826. TEXT("CalculateCRCForDataBuffer wasn't successful, hr=0x%lx."),
  2827. hr));
  2828. }
  2829. // Delete temp buffer
  2830. if (NULL != ptcsBuffer)
  2831. {
  2832. delete []ptcsBuffer;
  2833. ptcsBuffer = NULL;
  2834. }
  2835. // Commit root. BUGBUG: Use random modes
  2836. if (S_OK == hr)
  2837. {
  2838. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2839. }
  2840. if (S_OK == hr)
  2841. {
  2842. DH_TRACE((
  2843. DH_LVL_TRACE1,
  2844. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2845. }
  2846. else
  2847. {
  2848. DH_TRACE((
  2849. DH_LVL_TRACE1,
  2850. TEXT("VirtualCtrNode::Commit wasn't successfully, hr=0x%lx."),
  2851. hr));
  2852. }
  2853. // Reposition to start offset of the source IStream
  2854. if (S_OK == hr)
  2855. {
  2856. memset(&liStreamPos, ulPosition[SOURCESTM], sizeof(LARGE_INTEGER));
  2857. hr = pvsnRootNewChildStream[SOURCESTM]->Seek(
  2858. liStreamPos,
  2859. STREAM_SEEK_SET,
  2860. NULL);
  2861. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2862. }
  2863. if (S_OK == hr)
  2864. {
  2865. DH_TRACE((
  2866. DH_LVL_TRACE1,
  2867. TEXT("VirtualStmNode::Seek completed successfully.")));
  2868. }
  2869. else
  2870. {
  2871. DH_TRACE((
  2872. DH_LVL_TRACE1,
  2873. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2874. hr));
  2875. }
  2876. // For the first pass of the loop, we'll specify that the DEST IStream
  2877. // (as opposed to the CLONE) IStream will be the copy destination.
  2878. // Also, for the first pass, we'll copy the whole source IStream to
  2879. // dest/clone IStream, so the length of bytes before/after CopyTo both
  2880. // are 0L, i.e. ulPosition[biInUse].
  2881. biInUse = DESTSTM;
  2882. if (S_OK == hr)
  2883. {
  2884. // Generate random # of small objects for test between
  2885. // usMinIteration and usMaxIteration
  2886. usErr = pdgi->Generate(
  2887. &usNumIterations,
  2888. usMinIteration,
  2889. usMaxIteration);
  2890. if (DG_RC_SUCCESS != usErr)
  2891. {
  2892. hr = E_FAIL;
  2893. }
  2894. }
  2895. if (S_OK == hr)
  2896. {
  2897. DH_TRACE((
  2898. DH_LVL_TRACE1,
  2899. TEXT("Random # of small objects to test is: %d"),
  2900. usNumIterations));
  2901. }
  2902. // Before doing a copy, we read and CRC the bytes in the destinaiton
  2903. // IStream(DEST or CLONE) that *won't* be overwritten by the copy
  2904. // call because we'll later need to ensure that these bytes weren't
  2905. // inadvertently changed by the copy - because that would be a bug.
  2906. while ((S_OK == hr) && (0 != usNumIterations))
  2907. {
  2908. // ***BEFORE COPY***
  2909. // Read & CRC bytes in dest/clone before intended CopyTo() start
  2910. // Offset
  2911. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2912. hr = pIStream[biInUse]->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  2913. if (S_OK != hr)
  2914. {
  2915. DH_TRACE((
  2916. DH_LVL_TRACE1,
  2917. TEXT("IStream::Seek not successful, hr=0x%lx."),
  2918. hr));
  2919. }
  2920. if (S_OK == hr)
  2921. {
  2922. culBytesRead = ulIStreamSize;
  2923. ptcsReadBuffer = new BYTE[culBytesRead];
  2924. if (NULL == ptcsReadBuffer)
  2925. {
  2926. hr = E_OUTOFMEMORY;
  2927. }
  2928. }
  2929. if (S_OK == hr)
  2930. {
  2931. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  2932. hr = pIStream[biInUse]->Read(
  2933. ptcsReadBuffer,
  2934. ulPosition[biInUse],
  2935. &culRead);
  2936. }
  2937. if (S_OK != hr)
  2938. {
  2939. DH_TRACE((
  2940. DH_LVL_TRACE1,
  2941. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  2942. hr));
  2943. }
  2944. // culRead is the actual number of bytes read from IStream
  2945. if (S_OK == hr)
  2946. {
  2947. hr = CalculateCRCForDataBuffer(
  2948. (LPTSTR)ptcsReadBuffer,
  2949. culRead,
  2950. &dwCRC[biInUse][BYTES_BEFORE]);
  2951. }
  2952. if (S_OK != hr)
  2953. {
  2954. DH_TRACE((
  2955. DH_LVL_TRACE1,
  2956. TEXT("CalculateCRCForDataBuffer not successful, hr=0x%lx."),
  2957. hr));
  2958. }
  2959. if (NULL != ptcsReadBuffer)
  2960. {
  2961. delete []ptcsReadBuffer;
  2962. ptcsReadBuffer = NULL;
  2963. }
  2964. // read & CRC bytes in dest/clone after intended CopyTo() start offset
  2965. if (S_OK == hr)
  2966. {
  2967. LISet32(liStreamPos, (ulPosition[biInUse] + culIOBytes));
  2968. hr = pIStream[biInUse]->Seek(
  2969. liStreamPos,
  2970. STREAM_SEEK_SET,
  2971. NULL);
  2972. }
  2973. if (S_OK != hr)
  2974. {
  2975. DH_TRACE((
  2976. DH_LVL_TRACE1,
  2977. TEXT("IStream::Seek not successful, hr=0x%lx."),
  2978. hr));
  2979. }
  2980. if (S_OK == hr)
  2981. {
  2982. culBytesRead = ulIStreamSize;
  2983. ptcsReadBuffer = new BYTE[culBytesRead];
  2984. if (NULL == ptcsReadBuffer)
  2985. {
  2986. hr = E_OUTOFMEMORY;
  2987. }
  2988. }
  2989. if (S_OK == hr)
  2990. {
  2991. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  2992. hr = pIStream[biInUse]->Read(
  2993. ptcsReadBuffer,
  2994. culBytesRead,
  2995. &culRead);
  2996. }
  2997. if (S_OK != hr)
  2998. {
  2999. DH_TRACE((
  3000. DH_LVL_TRACE1,
  3001. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  3002. hr));
  3003. }
  3004. // culRead is the actual number of bytes read from IStream
  3005. if (S_OK == hr)
  3006. {
  3007. hr = CalculateCRCForDataBuffer(
  3008. (LPTSTR)ptcsReadBuffer,
  3009. culRead,
  3010. &dwCRC[biInUse][BYTES_AFTER]);
  3011. }
  3012. if (S_OK != hr)
  3013. {
  3014. DH_TRACE((
  3015. DH_LVL_TRACE1,
  3016. TEXT("CalculateCRCForDataBuffer not successful, hr=0x%lx."),
  3017. hr));
  3018. }
  3019. if (NULL != ptcsReadBuffer)
  3020. {
  3021. delete []ptcsReadBuffer;
  3022. ptcsReadBuffer = NULL;
  3023. }
  3024. // Position to dest/clone intended start offset, ready for CopyTo().
  3025. if (S_OK == hr)
  3026. {
  3027. LISet32(liStreamPos, ulPosition[biInUse]);
  3028. hr = pIStream[biInUse]->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  3029. }
  3030. if (S_OK != hr)
  3031. {
  3032. DH_TRACE((
  3033. DH_LVL_TRACE1,
  3034. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3035. hr));
  3036. }
  3037. // Copy from current position of SOURCE IStream to the specified
  3038. // position in the dest/clone IStream
  3039. if (S_OK == hr)
  3040. {
  3041. ULISet32(uliCopy, culIOBytes);
  3042. hr = pIStream[SOURCESTM]->CopyTo(
  3043. pIStream[biInUse],
  3044. uliCopy,
  3045. NULL,
  3046. NULL);
  3047. }
  3048. if (S_OK != hr)
  3049. {
  3050. DH_TRACE((
  3051. DH_LVL_TRACE1,
  3052. TEXT("IStream::CopyTo not successful, hr=0x%lx."),
  3053. hr));
  3054. }
  3055. // For variety, only commit to the root 50% of the time
  3056. if (S_OK == hr)
  3057. {
  3058. usErr = pdgi->Generate(&culRandomCommit, 1, 100);
  3059. if (DG_RC_SUCCESS != usErr)
  3060. {
  3061. hr = E_FAIL;
  3062. }
  3063. }
  3064. if ((S_OK == hr) && (culRandomCommit > 50))
  3065. {
  3066. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3067. }
  3068. if (S_OK != hr)
  3069. {
  3070. DH_TRACE((
  3071. DH_LVL_TRACE1,
  3072. TEXT("VirtualCtrNode::Commit wasn't successfully, hr=0x%lx."),
  3073. hr));
  3074. }
  3075. // ***AFTER COPY***
  3076. // After the copy, verify that the source and destination seek pointers
  3077. // are set correctly
  3078. if (S_OK == hr)
  3079. {
  3080. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  3081. hr = pIStream[SOURCESTM]->Seek(liStreamPos, STREAM_SEEK_CUR, &uli);
  3082. ulNewPosition[SOURCESTM] = ULIGetLow(uli);
  3083. }
  3084. if (S_OK != hr)
  3085. {
  3086. DH_TRACE((
  3087. DH_LVL_TRACE1,
  3088. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3089. hr));
  3090. }
  3091. if ((S_OK == hr) &&
  3092. (ulNewPosition[SOURCESTM] != (ulPosition[SOURCESTM] + culIOBytes)))
  3093. {
  3094. DH_TRACE((
  3095. DH_LVL_TRACE1,
  3096. TEXT("Source seek pointer incorrect after copy.")));
  3097. fPass = FALSE;
  3098. }
  3099. if (S_OK == hr)
  3100. {
  3101. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  3102. hr = pIStream[biInUse]->Seek(liStreamPos, STREAM_SEEK_CUR, &uli);
  3103. ulNewPosition[biInUse] = ULIGetLow(uli);
  3104. }
  3105. if (S_OK != hr)
  3106. {
  3107. DH_TRACE((
  3108. DH_LVL_TRACE1,
  3109. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3110. hr));
  3111. }
  3112. if ((S_OK == hr) &&
  3113. (ulNewPosition[biInUse] != (ulPosition[biInUse] + culIOBytes)))
  3114. {
  3115. DH_TRACE((
  3116. DH_LVL_TRACE1,
  3117. TEXT("Destination seek pointer incorrect after copy.")));
  3118. fPass = FALSE;
  3119. }
  3120. // After copy, read & CRC bytes in dest/clone before CopyTo() start
  3121. // offset and compare CRCs to ensure that these bytes haven't changed
  3122. if (S_OK == hr)
  3123. {
  3124. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  3125. hr = pIStream[biInUse]->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  3126. }
  3127. if (S_OK != hr)
  3128. {
  3129. DH_TRACE((
  3130. DH_LVL_TRACE1,
  3131. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3132. hr));
  3133. }
  3134. if (S_OK == hr)
  3135. {
  3136. culBytesRead = ulIStreamSize;
  3137. ptcsReadBuffer = new BYTE[culBytesRead];
  3138. if (NULL == ptcsReadBuffer)
  3139. {
  3140. hr = E_OUTOFMEMORY;
  3141. }
  3142. }
  3143. if (S_OK == hr)
  3144. {
  3145. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  3146. hr = pIStream[biInUse]->Read(
  3147. ptcsReadBuffer,
  3148. ulPosition[biInUse],
  3149. &culRead);
  3150. }
  3151. if (S_OK != hr)
  3152. {
  3153. DH_TRACE((
  3154. DH_LVL_TRACE1,
  3155. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  3156. hr));
  3157. }
  3158. // culRead is the actual number of bytes read from IStream
  3159. if (S_OK == hr)
  3160. {
  3161. hr = CalculateCRCForDataBuffer(
  3162. (LPTSTR)ptcsReadBuffer,
  3163. culRead,
  3164. &dwTempCRC);
  3165. }
  3166. if (S_OK != hr)
  3167. {
  3168. DH_TRACE((
  3169. DH_LVL_TRACE1,
  3170. TEXT("CalculateCRCForDataBuffer not successful, hr=0x%lx."),
  3171. hr));
  3172. }
  3173. if (NULL != ptcsReadBuffer)
  3174. {
  3175. delete []ptcsReadBuffer;
  3176. ptcsReadBuffer = NULL;
  3177. }
  3178. if (dwCRC[biInUse][BYTES_BEFORE] != dwTempCRC)
  3179. {
  3180. DH_TRACE((
  3181. DH_LVL_TRACE1,
  3182. TEXT("CRC mismatched at bytes before CopyTo start offset.")));
  3183. fPass = FALSE;
  3184. }
  3185. // Read & CRC bytes in dest/clone that were target of CopyTo()
  3186. if (S_OK == hr)
  3187. {
  3188. culBytesRead = culIOBytes;
  3189. ptcsReadBuffer = new BYTE[culBytesRead];
  3190. if (NULL == ptcsReadBuffer)
  3191. {
  3192. hr = E_OUTOFMEMORY;
  3193. }
  3194. }
  3195. if (S_OK == hr)
  3196. {
  3197. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  3198. hr = pIStream[biInUse]->Read(
  3199. ptcsReadBuffer,
  3200. culBytesRead,
  3201. &culRead);
  3202. }
  3203. if (S_OK != hr)
  3204. {
  3205. DH_TRACE((
  3206. DH_LVL_TRACE1,
  3207. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  3208. hr));
  3209. }
  3210. // culRead is the actual number of bytes read from IStream
  3211. if (S_OK == hr)
  3212. {
  3213. hr = CalculateCRCForDataBuffer(
  3214. (LPTSTR)ptcsReadBuffer,
  3215. culRead,
  3216. &dwCRC[biInUse][BYTES_COPIED]);
  3217. }
  3218. if (S_OK != hr)
  3219. {
  3220. DH_TRACE((
  3221. DH_LVL_TRACE1,
  3222. TEXT("CalculateCRCForDataBuffer not successful, hr=0x%lx."),
  3223. hr));
  3224. }
  3225. if (NULL != ptcsReadBuffer)
  3226. {
  3227. delete []ptcsReadBuffer;
  3228. ptcsReadBuffer = NULL;
  3229. }
  3230. if (dwCRC[biInUse][BYTES_COPIED] != dwSourceCRC)
  3231. {
  3232. DH_TRACE((
  3233. DH_LVL_TRACE1,
  3234. TEXT("CRC mismatched at bytes of CopyTo() target.")));
  3235. fPass = FALSE;
  3236. }
  3237. // Read & CRC bytes in dest/clone after CopyTo() start offset
  3238. if (S_OK == hr)
  3239. {
  3240. culBytesRead = ulIStreamSize;
  3241. ptcsReadBuffer = new BYTE[culBytesRead];
  3242. if (NULL == ptcsReadBuffer)
  3243. {
  3244. hr = E_OUTOFMEMORY;
  3245. }
  3246. }
  3247. if (S_OK == hr)
  3248. {
  3249. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  3250. hr = pIStream[biInUse]->Read(
  3251. ptcsReadBuffer,
  3252. culBytesRead,
  3253. &culRead);
  3254. }
  3255. if (S_OK != hr)
  3256. {
  3257. DH_TRACE((
  3258. DH_LVL_TRACE1,
  3259. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  3260. hr));
  3261. }
  3262. // culRead is the actual number of bytes read from IStream
  3263. if (S_OK == hr)
  3264. {
  3265. hr = CalculateCRCForDataBuffer(
  3266. (LPTSTR)ptcsReadBuffer,
  3267. culRead,
  3268. &dwTempCRC);
  3269. }
  3270. if (S_OK != hr)
  3271. {
  3272. DH_TRACE((
  3273. DH_LVL_TRACE1,
  3274. TEXT("CalculateCRCForDataBuffer not successful, hr=0x%lx."),
  3275. hr));
  3276. }
  3277. if (NULL != ptcsReadBuffer)
  3278. {
  3279. delete []ptcsReadBuffer;
  3280. ptcsReadBuffer = NULL;
  3281. }
  3282. if (dwCRC[biInUse][BYTES_AFTER] != dwTempCRC)
  3283. {
  3284. DH_TRACE((
  3285. DH_LVL_TRACE1,
  3286. TEXT("CRC mismatched at bytes after CopyTo() target.")));
  3287. fPass = FALSE;
  3288. }
  3289. if (--usNumIterations)
  3290. {
  3291. // if we'll be looping again, pick a random copy starting position
  3292. // in the source IStream and a random number of bytes to copy.
  3293. if (S_OK == hr)
  3294. {
  3295. usErr = pdgi->Generate(
  3296. &ulPosition[SOURCESTM],
  3297. 0L,
  3298. ulIStreamSize);
  3299. if (DG_RC_SUCCESS != usErr)
  3300. {
  3301. hr = E_FAIL;
  3302. }
  3303. }
  3304. if (S_OK == hr)
  3305. {
  3306. if((ulIStreamSize - ulPosition[SOURCESTM]) > 0)
  3307. {
  3308. usErr = pdgi->Generate(
  3309. &culIOBytes,
  3310. 1L,
  3311. ulIStreamSize - ulPosition[SOURCESTM]);
  3312. }
  3313. else
  3314. {
  3315. culIOBytes = 1L;
  3316. }
  3317. if (DG_RC_SUCCESS != usErr)
  3318. {
  3319. hr = E_FAIL;
  3320. }
  3321. }
  3322. // Now seek, read and CRC the source bytes and then seek back to
  3323. // the intended copy start position
  3324. if (S_OK == hr)
  3325. {
  3326. LISet32(liStreamPos, ulPosition[SOURCESTM]);
  3327. hr = pIStream[SOURCESTM]->Seek(
  3328. liStreamPos,
  3329. STREAM_SEEK_SET,
  3330. NULL);
  3331. }
  3332. if (S_OK != hr)
  3333. {
  3334. DH_TRACE((
  3335. DH_LVL_TRACE1,
  3336. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3337. hr));
  3338. }
  3339. if (S_OK == hr)
  3340. {
  3341. culBytesRead = culIOBytes;
  3342. ptcsReadBuffer = new BYTE[culBytesRead];
  3343. if (NULL == ptcsReadBuffer)
  3344. {
  3345. hr = E_OUTOFMEMORY;
  3346. }
  3347. }
  3348. if (S_OK == hr)
  3349. {
  3350. memset(ptcsReadBuffer, '\0', culBytesRead * sizeof(BYTE));
  3351. hr = pIStream[SOURCESTM]->Read(
  3352. ptcsReadBuffer,
  3353. culIOBytes,
  3354. &culRead);
  3355. }
  3356. if (S_OK != hr)
  3357. {
  3358. DH_TRACE((
  3359. DH_LVL_TRACE1,
  3360. TEXT("IStream::Read wasn't successful, hr=0x%lx."),
  3361. hr));
  3362. }
  3363. // culRead is the actual number of bytes read from IStream
  3364. if (S_OK == hr)
  3365. {
  3366. hr = CalculateCRCForDataBuffer(
  3367. (LPTSTR)ptcsReadBuffer,
  3368. culRead,
  3369. &dwSourceCRC);
  3370. }
  3371. if (S_OK != hr)
  3372. {
  3373. DH_TRACE((
  3374. DH_LVL_TRACE1,
  3375. TEXT("CalculateCRCForDataBuffer not Ok, hr=0x%lx."),
  3376. hr));
  3377. }
  3378. if (NULL != ptcsReadBuffer)
  3379. {
  3380. delete []ptcsReadBuffer;
  3381. ptcsReadBuffer = NULL;
  3382. }
  3383. if (S_OK == hr)
  3384. {
  3385. LISet32(liStreamPos, ulPosition[SOURCESTM]);
  3386. hr = pIStream[SOURCESTM]->Seek(
  3387. liStreamPos,
  3388. STREAM_SEEK_SET,
  3389. NULL);
  3390. }
  3391. if (S_OK != hr)
  3392. {
  3393. DH_TRACE((
  3394. DH_LVL_TRACE1,
  3395. TEXT("IStream::Seek not successful, hr=0x%lx."),
  3396. hr));
  3397. }
  3398. // Pick an IStream for the copy destination and a destination
  3399. // offset within that IStream
  3400. if (S_OK == hr)
  3401. {
  3402. usErr = pdgi->Generate(&biInUse, DESTSTM, CLONESTM);
  3403. if (DG_RC_SUCCESS != usErr)
  3404. {
  3405. hr = E_FAIL;
  3406. }
  3407. }
  3408. if (S_OK == hr)
  3409. {
  3410. usErr = pdgi->Generate(&ulPosition[biInUse], 0L, ulIStreamSize);
  3411. if (DG_RC_SUCCESS != usErr)
  3412. {
  3413. hr = E_FAIL;
  3414. }
  3415. }
  3416. }
  3417. if ((S_OK != hr) || (TRUE != fPass))
  3418. {
  3419. break;
  3420. }
  3421. }
  3422. // Release Clone stream
  3423. if (NULL != pIStream[CLONESTM])
  3424. {
  3425. ulRef = pIStream[CLONESTM]->Release();
  3426. DH_ASSERT(0 == ulRef);
  3427. }
  3428. if (S_OK == hr)
  3429. {
  3430. DH_TRACE((
  3431. DH_LVL_TRACE1,
  3432. TEXT("IStream::Close completed successfully.")));
  3433. }
  3434. else
  3435. {
  3436. DH_TRACE((
  3437. DH_LVL_TRACE1,
  3438. TEXT("IStream::Close unsuccessful.")));
  3439. }
  3440. // Release all streams, irrespective of result
  3441. if (S_OK == hr)
  3442. {
  3443. for (biIStream=SOURCESTM; biIStream <= DESTSTM; biIStream++)
  3444. {
  3445. hr = pvsnRootNewChildStream[biIStream]->Close();
  3446. if (S_OK == hr)
  3447. {
  3448. DH_TRACE((
  3449. DH_LVL_TRACE1,
  3450. TEXT("VirtualStmNode::Close completed successfully.")));
  3451. }
  3452. else
  3453. {
  3454. DH_TRACE((
  3455. DH_LVL_TRACE1,
  3456. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3457. hr));
  3458. }
  3459. }
  3460. }
  3461. // Release Root
  3462. if (NULL != pVirtualDFRoot)
  3463. {
  3464. hr = pVirtualDFRoot->Close();
  3465. if (S_OK == hr)
  3466. {
  3467. DH_TRACE((
  3468. DH_LVL_TRACE1,
  3469. TEXT("VirtualCtrNode::Close completed successfully.")));
  3470. }
  3471. else
  3472. {
  3473. DH_TRACE((
  3474. DH_LVL_TRACE1,
  3475. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3476. hr));
  3477. }
  3478. }
  3479. // if everything goes well, log test as passed else failed.
  3480. if ((S_OK == hr) && (TRUE == fPass))
  3481. {
  3482. DH_LOG((LOG_PASS, TEXT("Test variation VCPYTEST_106 passed.")) );
  3483. }
  3484. else
  3485. {
  3486. DH_LOG((LOG_FAIL,
  3487. TEXT("Test variation VCPYTEST_106 failed, hr=0x%lx."),
  3488. hr));
  3489. // test failed. make sure it failed.
  3490. hr = FirstError (hr, E_FAIL);
  3491. }
  3492. // Cleanup
  3493. CleanupTestDocfile (&pVirtualDFRoot,
  3494. &pTestVirtualDF,
  3495. &pTestChanceDF,
  3496. S_OK == hr);
  3497. // Delete strings
  3498. for (biIStream=SOURCESTM; biIStream <= DESTSTM; biIStream++)
  3499. {
  3500. if (NULL != pRootNewChildStmName[biIStream])
  3501. {
  3502. delete pRootNewChildStmName[biIStream];
  3503. pRootNewChildStmName[biIStream] = NULL;
  3504. }
  3505. }
  3506. // Stop logging the test
  3507. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation VCPYTEST_106 finished")) );
  3508. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3509. return hr;
  3510. }