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.

1678 lines
48 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. //----------------------------------------------------------------------------
  21. //
  22. // Test: ENUMTEST_100
  23. //
  24. // synopsis: A random root DF is created with random number of storages/streams
  25. // committed/close/reopened. An enumerator is obtained. For each object
  26. // found,attempt is made to convert object to an IStorage. If it already
  27. // was an IStorage, the conversion fails and the test continues. If an
  28. // IStream was converted to an IStorage, the new IStorage is committed
  29. // and enumerated to ensure that only a single IStream named "CONTENTS"
  30. // (STG_CONVERTED_NAME) exists. The CONTENTS IStream is instantiated,
  31. // read, verified, and released. When all IStreams in the top level of
  32. // the docfile have been converted ,root docfile is committed & released.
  33. //
  34. // Arguments:[argc]
  35. // [argv]
  36. //
  37. // Returns: HRESULT
  38. //
  39. // History: 22-July-1996 NarindK Created.
  40. //
  41. // Notes: This test runs in direct, transacted, and transacted deny write
  42. // modes
  43. //
  44. // New Test Notes:
  45. // 1. Old File: LICONV.CXX
  46. // 2. Old name of test : LegitInstEnumConvert Test
  47. // New Name of test : ENUMTEST_100
  48. // 3. To run the test, do the following at command prompt.
  49. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-100
  50. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  51. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-100
  52. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  53. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-100
  54. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  55. //
  56. // BUGNOTE: Conversion: ENUMTEST-100
  57. //
  58. //-----------------------------------------------------------------------------
  59. HRESULT ENUMTEST_100(int argc, char *argv[])
  60. {
  61. HRESULT hr = S_OK;
  62. ChanceDF *pTestChanceDF = NULL;
  63. VirtualDF *pTestVirtualDF = NULL;
  64. VirtualCtrNode *pVirtualDFRoot = NULL;
  65. VirtualCtrNode *pvcnTemp = NULL;
  66. DWORD dwRootMode = 0;
  67. DWORD dwStgMode = 0;
  68. BOOL fPass = TRUE;
  69. LPENUMSTATSTG penumWalk = NULL;
  70. LPENUMSTATSTG penumWalkConv = NULL;
  71. VirtualStmNode *pvsnTrav = NULL;
  72. VirtualStmNode *pvsnTempConv = NULL;
  73. LPMALLOC pMalloc = NULL;
  74. ULONG ulRef = 0;
  75. ULONG cElementsInConvStg = 0;
  76. LPTSTR ptszStatStgName = NULL;
  77. LPTSTR ptszStatStgConvName = NULL;
  78. STATSTG statStg;
  79. STATSTG statStgConv;
  80. DWCRCSTM dwMemCRC;
  81. DWCRCSTM dwActCRC;
  82. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ENUMTEST_100"));
  83. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  84. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_100 started.")) );
  85. DH_TRACE((
  86. DH_LVL_TRACE1,
  87. TEXT("Enumerate RootDF, do CreateStorage STGM_CONVERT on elements")));
  88. // BUGBUG: Bug in testcode. TO BE fixed by scousens soon.
  89. if (DoingDistrib ())
  90. {
  91. DH_LOG((
  92. LOG_ABORT,
  93. TEXT("Enumtest-100: Test bug. CRC not calcd for streams on open.")));
  94. return E_FAIL;
  95. }
  96. // Create our ChanceDF and VirtualDF
  97. hr = CreateTestDocfile (argc,
  98. argv,
  99. &pVirtualDFRoot,
  100. &pTestVirtualDF,
  101. &pTestChanceDF);
  102. // if creating the docfile - bail here
  103. if (NULL != pTestChanceDF && DoingCreate ())
  104. {
  105. UINT ulSeed = pTestChanceDF->GetSeed ();
  106. CleanupTestDocfile (&pVirtualDFRoot,
  107. &pTestVirtualDF,
  108. &pTestChanceDF,
  109. FALSE);
  110. return (HRESULT)ulSeed;
  111. }
  112. // Initialize CRC values to zero
  113. dwMemCRC.dwCRCData = dwActCRC.dwCRCData = 0;
  114. if (S_OK == hr)
  115. {
  116. dwRootMode = pTestChanceDF->GetRootMode();
  117. dwStgMode = pTestChanceDF->GetStgMode();
  118. DH_TRACE((
  119. DH_LVL_TRACE1,
  120. TEXT("Run Mode for ENUMTEST_100, Access mode: %lx"),
  121. dwRootMode));
  122. }
  123. // Commit root. BUGBUG df already commited
  124. if(S_OK == hr)
  125. {
  126. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  127. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  128. }
  129. if (S_OK == hr)
  130. {
  131. DH_TRACE((
  132. DH_LVL_TRACE1,
  133. TEXT("VirtualCtrNode::Commit completed successfully.")));
  134. }
  135. else
  136. {
  137. DH_TRACE((
  138. DH_LVL_TRACE1,
  139. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  140. hr));
  141. }
  142. if(S_OK == hr)
  143. {
  144. hr = ParseVirtualDFAndCloseOpenStgsStms(
  145. pVirtualDFRoot,
  146. NODE_EXC_TOPSTG);
  147. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  148. }
  149. // Close the Root Docfile.
  150. if (S_OK == hr)
  151. {
  152. hr = pVirtualDFRoot->Close();
  153. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  154. }
  155. if (S_OK == hr)
  156. {
  157. DH_TRACE((
  158. DH_LVL_TRACE1,
  159. TEXT("VirtualCtrNode::Close completed successfully.")));
  160. }
  161. else
  162. {
  163. DH_TRACE((
  164. DH_LVL_TRACE1,
  165. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  166. hr));
  167. }
  168. // Reopen the Root Docfile.
  169. if (S_OK == hr)
  170. {
  171. hr = pVirtualDFRoot->OpenRoot(
  172. NULL,
  173. dwRootMode,
  174. NULL,
  175. 0);
  176. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  177. }
  178. if (S_OK == hr)
  179. {
  180. DH_TRACE((
  181. DH_LVL_TRACE1,
  182. TEXT("VirtualCtrNode::Open completed successfully.")));
  183. }
  184. else
  185. {
  186. DH_TRACE((
  187. DH_LVL_TRACE1,
  188. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  189. hr));
  190. }
  191. // Get an enumerator for the root.
  192. if(S_OK == hr)
  193. {
  194. hr = pVirtualDFRoot->EnumElements(0, NULL, 0, &penumWalk);
  195. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  196. }
  197. // First get pMalloc that would be used to free up the name string from
  198. // STATSTG.
  199. if ( S_OK == hr )
  200. {
  201. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  202. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  203. }
  204. // In a loop, enumerate the DocFile at root level and call CreateStorage
  205. // with STGM_CONVERT on the found element. As a result, if the element
  206. // is a storage, it should return error STG_E_FILEALREADYEXISTS. If it
  207. // is a stream, it is replaced with a new storage object containing a
  208. // single stream called CONTENTS and hr returned is STG_S_CONVERTED.
  209. while(S_OK == hr && S_OK == penumWalk->Next(1, &statStg, NULL))
  210. {
  211. // Convert statStg.pwcsName to TCHAR
  212. hr = OleStringToTString(statStg.pwcsName, &ptszStatStgName);
  213. // Record CRC for this element before conversion if it is a stream
  214. if((STGTY_STREAM == statStg.type) && (S_OK == hr))
  215. {
  216. pvsnTrav = pVirtualDFRoot->GetFirstChildVirtualStmNode();
  217. while((NULL != pvsnTrav) &&
  218. (0 != _tcscmp(
  219. ptszStatStgName,
  220. pvsnTrav->GetVirtualStmNodeName())))
  221. {
  222. pvsnTrav = pvsnTrav->GetFirstSisterVirtualStmNode();
  223. }
  224. DH_ASSERT(NULL != pvsnTrav);
  225. dwMemCRC.dwCRCData = pvsnTrav->GetVirtualStmNodeCRCData();
  226. }
  227. // Call to CreateStorage with STGM_CONVERTED flag
  228. if(S_OK == hr)
  229. {
  230. hr = AddStorage(
  231. pTestVirtualDF,
  232. pVirtualDFRoot,
  233. ptszStatStgName,
  234. dwStgMode | STGM_CONVERT,
  235. &pvcnTemp);
  236. if((STGTY_STREAM == statStg.type) &&
  237. ((NULL == pvcnTemp)|| (STG_S_CONVERTED != hr)))
  238. {
  239. fPass = FALSE;
  240. DH_TRACE((
  241. DH_LVL_TRACE1,
  242. TEXT("Enumerated stream element not converted")));
  243. break;
  244. }
  245. else
  246. {
  247. if(STGTY_STORAGE == statStg.type)
  248. {
  249. if((NULL == pvcnTemp) && (STG_E_FILEALREADYEXISTS == hr))
  250. {
  251. // Expected result/condition, reset hr to S_OK
  252. hr = S_OK;
  253. // Delete the temp string
  254. if(NULL != ptszStatStgName)
  255. {
  256. delete ptszStatStgName;
  257. ptszStatStgName = NULL;
  258. }
  259. if ( NULL != statStg.pwcsName)
  260. {
  261. pMalloc->Free(statStg.pwcsName);
  262. statStg.pwcsName = NULL;
  263. }
  264. continue;
  265. }
  266. else
  267. {
  268. fPass = FALSE;
  269. DH_TRACE((
  270. DH_LVL_TRACE1,
  271. TEXT("Enum storage didn't return exp error")));
  272. break;
  273. }
  274. }
  275. }
  276. }
  277. // Delete the temp string
  278. if(NULL != ptszStatStgName)
  279. {
  280. delete ptszStatStgName;
  281. ptszStatStgName = NULL;
  282. }
  283. if(STG_S_CONVERTED == hr)
  284. {
  285. // If it comes here and hr is STG_S_CONVERTED, rest hr to S_OK.
  286. hr = S_OK;
  287. }
  288. // Commit the newly converted storage
  289. if(S_OK == hr)
  290. {
  291. hr = pvcnTemp->Commit(STGC_DEFAULT);
  292. if(S_OK != hr)
  293. {
  294. DH_TRACE((DH_LVL_TRACE1, TEXT("IStg::Commit failed, hr=0x%lx"), hr));
  295. break;
  296. }
  297. }
  298. // Enumerate this converted storage
  299. if(S_OK == hr)
  300. {
  301. hr = pvcnTemp->EnumElements(0, NULL, 0, &penumWalkConv);
  302. if(S_OK != hr)
  303. {
  304. DH_TRACE((DH_LVL_TRACE1, TEXT("IStg::EnumElem fail, hr=0x%lx"), hr));
  305. break;
  306. }
  307. }
  308. // Check the elements in conv storage. There should be only one
  309. // stream with name CONTENTS in this converted storage. If otherwise,
  310. // it is an error.
  311. cElementsInConvStg = 0;
  312. while(S_OK == hr && S_OK == penumWalkConv->Next(1, &statStgConv, NULL))
  313. {
  314. cElementsInConvStg++;
  315. // Convert statStg.pwcsName to TCHAR
  316. hr = OleStringToTString(statStgConv.pwcsName, &ptszStatStgConvName);
  317. if(S_OK == hr)
  318. {
  319. if((STGTY_STREAM != statStgConv.type) ||
  320. (0 != _tcscmp(STG_CONVERTED_NAME, ptszStatStgConvName)))
  321. {
  322. DH_TRACE((
  323. DH_LVL_TRACE1,
  324. TEXT("Conv stg contains other than CONTENTS stm.")));
  325. fPass = FALSE;
  326. break;
  327. }
  328. pvsnTempConv = pvcnTemp->GetFirstChildVirtualStmNode();
  329. while((NULL != pvsnTempConv) &&
  330. (0 != _tcscmp(
  331. ptszStatStgConvName,
  332. pvsnTempConv->GetVirtualStmNodeName())))
  333. {
  334. pvsnTempConv = pvsnTempConv->GetFirstSisterVirtualStmNode();
  335. }
  336. DH_ASSERT(NULL != pvsnTempConv);
  337. }
  338. // Open the stream and Read its contents
  339. if(S_OK == hr)
  340. {
  341. hr = pvsnTempConv->Open(NULL, STGM_SHARE_EXCLUSIVE|STGM_READ,0);
  342. }
  343. if(S_OK == hr)
  344. {
  345. hr = ReadAndCalculateDiskCRCForStm(pvsnTempConv,&dwActCRC);
  346. }
  347. // Delete the temp string
  348. if(NULL != ptszStatStgConvName)
  349. {
  350. delete ptszStatStgConvName;
  351. ptszStatStgConvName = NULL;
  352. }
  353. // Release name
  354. if ( NULL != statStg.pwcsName)
  355. {
  356. pMalloc->Free(statStgConv.pwcsName);
  357. statStgConv.pwcsName = NULL;
  358. }
  359. }
  360. // Release penumWalkConv
  361. if(NULL != penumWalkConv)
  362. {
  363. ulRef = penumWalkConv->Release();
  364. DH_ASSERT(0 == ulRef);
  365. penumWalkConv = NULL;
  366. }
  367. // Close child
  368. if(S_OK == hr)
  369. {
  370. hr = pvcnTemp->Close();
  371. if(S_OK != hr)
  372. {
  373. DH_TRACE((
  374. DH_LVL_TRACE1,
  375. TEXT("VCN::Close failed unexp, hr=0x%lx"),
  376. hr));
  377. break;
  378. }
  379. }
  380. // Verify that converted storage has only one CONTENTS stream in it
  381. if(1 != cElementsInConvStg)
  382. {
  383. DH_TRACE((
  384. DH_LVL_TRACE1,
  385. TEXT("Convert stg has other elements besides CONTENTS stm")));
  386. fPass = FALSE;
  387. break;
  388. }
  389. // Verify that CRC's match of original stream and CONTENTS stream in
  390. // this converted storage
  391. if(dwMemCRC.dwCRCData == dwActCRC.dwCRCData)
  392. {
  393. DH_TRACE((
  394. DH_LVL_TRACE1,
  395. TEXT("CRC of org stm and CONTENTS stm in conv stg match")));
  396. }
  397. else
  398. {
  399. DH_TRACE((
  400. DH_LVL_TRACE1,
  401. TEXT("CRC org stm and CONTENTS stm in convstg don't match")));
  402. fPass = FALSE;
  403. break;
  404. }
  405. // Release name
  406. if ( NULL != statStg.pwcsName)
  407. {
  408. pMalloc->Free(statStg.pwcsName);
  409. statStg.pwcsName = NULL;
  410. }
  411. }
  412. // Release penumWalk
  413. if(NULL != penumWalk)
  414. {
  415. ulRef = penumWalk->Release();
  416. DH_ASSERT(0 == ulRef);
  417. penumWalk = NULL;
  418. }
  419. if(NULL != pMalloc)
  420. {
  421. pMalloc->Release();
  422. pMalloc = NULL;
  423. }
  424. // if everything goes well, log test as passed else failed.
  425. if ((S_OK == hr) && (TRUE == fPass))
  426. {
  427. DH_LOG((LOG_PASS, TEXT("Test variation ENUMTEST_100 passed.")) );
  428. }
  429. else
  430. {
  431. DH_LOG((
  432. LOG_FAIL,
  433. TEXT("Test variation ENUMTEST_100 failed, hr=0x%lx."),
  434. hr) );
  435. // test failed. make it look like it failed.
  436. hr = FirstError (hr, E_FAIL);
  437. }
  438. // Cleanup
  439. CleanupTestDocfile (&pVirtualDFRoot,
  440. &pTestVirtualDF,
  441. &pTestChanceDF,
  442. S_OK == hr);
  443. // Stop logging the test
  444. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_100 finished")) );
  445. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  446. return hr;
  447. }
  448. //----------------------------------------------------------------------------
  449. //
  450. // Test: ENUMTEST_101
  451. //
  452. // synopsis: A random root DF is created with random number of storages/streams
  453. // committed/close/reopened. An enumerator is obtained in random chunks
  454. // and the child objects found are counted. The hierarchy is recursed
  455. // into so that all objects in the docfile are counted.
  456. //
  457. // Arguments:[argc]
  458. // [argv]
  459. //
  460. // Returns: HRESULT
  461. //
  462. // History: 23-July-1996 NarindK Created.
  463. //
  464. // Notes: This test runs in direct, transacted, transacted deny write modes
  465. //
  466. // New Test Notes:
  467. // 1. Old File: LINEXT.CXX
  468. // 2. Old name of test : LegitInstEnumNext Test
  469. // New Name of test : ENUMTEST_101
  470. // 3. To run the test, do the following at command prompt.
  471. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-101
  472. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  473. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-101
  474. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  475. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-101
  476. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  477. //
  478. // BUGNOTE: Conversion: ENUMTEST-101
  479. //
  480. //-----------------------------------------------------------------------------
  481. HRESULT ENUMTEST_101(int argc, char *argv[])
  482. {
  483. HRESULT hr = S_OK;
  484. ChanceDF *pTestChanceDF = NULL;
  485. VirtualDF *pTestVirtualDF = NULL;
  486. VirtualCtrNode *pVirtualDFRoot = NULL;
  487. DG_INTEGER *pdgi = NULL;
  488. USHORT usErr = 0;
  489. DWORD dwRootMode = 0;
  490. DWORD dwStgMode = 0;
  491. BOOL fPass = TRUE;
  492. ULONG cTotalStg = 0;
  493. ULONG cTotalStm = 0;
  494. ULONG cEnumStg = 0;
  495. ULONG cEnumStm = 0;
  496. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ENUMTEST_101"));
  497. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  498. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_101 started.")) );
  499. DH_TRACE((
  500. DH_LVL_TRACE1,
  501. TEXT("IEnumSTATSTG::Next in Random chunks and verify ")));
  502. // Create our ChanceDF and VirtualDF
  503. hr = CreateTestDocfile (argc,
  504. argv,
  505. &pVirtualDFRoot,
  506. &pTestVirtualDF,
  507. &pTestChanceDF);
  508. // if creating the docfile - bail here
  509. if (NULL != pTestChanceDF && DoingCreate ())
  510. {
  511. UINT ulSeed = pTestChanceDF->GetSeed ();
  512. CleanupTestDocfile (&pVirtualDFRoot,
  513. &pTestVirtualDF,
  514. &pTestChanceDF,
  515. FALSE);
  516. return (HRESULT)ulSeed;
  517. }
  518. if (S_OK == hr)
  519. {
  520. dwRootMode = pTestChanceDF->GetRootMode();
  521. dwStgMode = pTestChanceDF->GetStgMode();
  522. DH_TRACE((
  523. DH_LVL_TRACE1,
  524. TEXT("Run Mode for ENUMTEST_101, Access mode: %lx"),
  525. dwRootMode));
  526. }
  527. // BUGBUG df already commited
  528. if(S_OK == hr)
  529. {
  530. hr = ParseVirtualDFAndCommitAllOpenStgs(
  531. pVirtualDFRoot,
  532. STGC_DEFAULT,
  533. NODE_EXC_TOPSTG);
  534. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  535. }
  536. // Commit root.
  537. if(S_OK == hr)
  538. {
  539. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  540. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  541. }
  542. if (S_OK == hr)
  543. {
  544. DH_TRACE((
  545. DH_LVL_TRACE1,
  546. TEXT("VirtualCtrNode::Commit completed successfully.")));
  547. }
  548. else
  549. {
  550. DH_TRACE((
  551. DH_LVL_TRACE1,
  552. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  553. hr));
  554. }
  555. if(S_OK == hr)
  556. {
  557. hr = ParseVirtualDFAndCloseOpenStgsStms(
  558. pVirtualDFRoot,
  559. NODE_EXC_TOPSTG);
  560. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  561. }
  562. // Find the total number of elements in the DocFile
  563. if(S_OK == hr)
  564. {
  565. hr = EnumerateInMemoryDocFile(pVirtualDFRoot, &cTotalStg, &cTotalStm);
  566. DH_HRCHECK(hr, TEXT("EnumerateInMemoryDocFile")) ;
  567. }
  568. // Close the Root Docfile.
  569. if (S_OK == hr)
  570. {
  571. hr = pVirtualDFRoot->Close();
  572. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  573. }
  574. if (S_OK == hr)
  575. {
  576. DH_TRACE((
  577. DH_LVL_TRACE1,
  578. TEXT("VirtualCtrNode::Close completed successfully.")));
  579. }
  580. else
  581. {
  582. DH_TRACE((
  583. DH_LVL_TRACE1,
  584. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  585. hr));
  586. }
  587. // Reopen the Root Docfile.
  588. if (S_OK == hr)
  589. {
  590. hr = pVirtualDFRoot->OpenRoot(
  591. NULL,
  592. dwRootMode,
  593. NULL,
  594. 0);
  595. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  596. }
  597. if (S_OK == hr)
  598. {
  599. DH_TRACE((
  600. DH_LVL_TRACE1,
  601. TEXT("VirtualCtrNode::Open completed successfully.")));
  602. }
  603. else
  604. {
  605. DH_TRACE((
  606. DH_LVL_TRACE1,
  607. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  608. hr));
  609. }
  610. // The named docfile/IStorage is instantiated and an enumerator
  611. // is obtained. The docfile is walked in random chunks and each
  612. // contained IStorage/IStream is counted. If the object returned
  613. // by ->Next() is an IStorage, it is recursed into and processed.
  614. // Get DG_INTEGER object pointer
  615. if (S_OK == hr)
  616. {
  617. pdgi = pTestVirtualDF->GetDataGenInteger();
  618. DH_ASSERT(NULL != pdgi);
  619. }
  620. // Enumerate the DocFile in Random chunks
  621. if(S_OK == hr)
  622. {
  623. hr = EnumerateDocFileInRandomChunks(
  624. pVirtualDFRoot,
  625. pdgi,
  626. dwStgMode,
  627. cTotalStg+cTotalStm,
  628. &cEnumStg,
  629. &cEnumStm);
  630. DH_HRCHECK(hr, TEXT("EnumerateDocFileInRandomChunks")) ;
  631. }
  632. // Verify results
  633. if(S_OK == hr)
  634. {
  635. if(cEnumStg == cTotalStg)
  636. {
  637. DH_TRACE((
  638. DH_LVL_TRACE1,
  639. TEXT("Storages enum by IEnum::Next in rand chunks as exp")));
  640. }
  641. else
  642. {
  643. DH_TRACE((
  644. DH_LVL_TRACE1,
  645. TEXT("Storages enum by IEnum::Next in rand chunks not exp")));
  646. fPass = FALSE;
  647. }
  648. if(cEnumStm == cTotalStm)
  649. {
  650. DH_TRACE((
  651. DH_LVL_TRACE1,
  652. TEXT("Streams enum by IEnum::Next in rand chunks as exp")));
  653. }
  654. else
  655. {
  656. DH_TRACE((
  657. DH_LVL_TRACE1,
  658. TEXT("Streams enum by IEnum::Next in rand chunks not exp")));
  659. fPass = FALSE;
  660. }
  661. }
  662. // if everything goes well, log test as passed else failed.
  663. if ((S_OK == hr) && (TRUE == fPass))
  664. {
  665. DH_LOG((LOG_PASS, TEXT("Test variation ENUMTEST_101 passed.")) );
  666. }
  667. else
  668. {
  669. DH_LOG((
  670. LOG_FAIL,
  671. TEXT("Test variation ENUMTEST_101 failed, hr=0x%lx."),
  672. hr) );
  673. // test failed. make it look like it failed.
  674. hr = FirstError (hr, E_FAIL);
  675. }
  676. // Cleanup
  677. CleanupTestDocfile (&pVirtualDFRoot,
  678. &pTestVirtualDF,
  679. &pTestChanceDF,
  680. S_OK == hr);
  681. // Stop logging the test
  682. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_101 finished")) );
  683. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  684. return hr;
  685. }
  686. //----------------------------------------------------------------------------
  687. //
  688. // Test: ENUMTEST_102
  689. //
  690. // synopsis: A random root DF is created with random number of storages/streams
  691. // committed/close/reopened. An enumerator is obtained and docfile enum-
  692. // erated. A clone is made of enumerator. The clone uses Reset/Skip/Next
  693. // methods of enumerator to verify each of the objects found through the
  694. // original enumerator to see that it is the same. All child objects
  695. // found are counted and the hierarchy is recursed into so that all
  696. // objects in the docfile are counted.
  697. //
  698. // Arguments:[argc]
  699. // [argv]
  700. //
  701. // Returns: HRESULT
  702. //
  703. // History: 24-July-1996 NarindK Created.
  704. //
  705. // Notes: This test runs in direct, transacted, transacted deny write modes
  706. //
  707. // New Test Notes:
  708. // 1. Old File: LISKIP.CXX
  709. // 2. Old name of test : LegitInstEnumSkip Test
  710. // New Name of test : ENUMTEST_102
  711. // 3. To run the test, do the following at command prompt.
  712. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-102
  713. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  714. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-102
  715. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  716. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-102
  717. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  718. //
  719. // BUGNOTE: Conversion: ENUMTEST-102
  720. //
  721. //-----------------------------------------------------------------------------
  722. HRESULT ENUMTEST_102(int argc, char *argv[])
  723. {
  724. HRESULT hr = S_OK;
  725. ChanceDF *pTestChanceDF = NULL;
  726. VirtualDF *pTestVirtualDF = NULL;
  727. VirtualCtrNode *pVirtualDFRoot = NULL;
  728. DWORD dwRootMode = 0;
  729. DWORD dwStgMode = 0;
  730. BOOL fPass = TRUE;
  731. ULONG cTotalStg = 0;
  732. ULONG cTotalStm = 0;
  733. ULONG cEnumStg = 0;
  734. ULONG cEnumStm = 0;
  735. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ENUMTEST_102"));
  736. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  737. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_102 started.")) );
  738. DH_TRACE((
  739. DH_LVL_TRACE1,
  740. TEXT("IEnumSTATSTG::Clone/Reset/Skip/Next ops verify ")));
  741. // Create our ChanceDF and VirtualDF
  742. hr = CreateTestDocfile (argc,
  743. argv,
  744. &pVirtualDFRoot,
  745. &pTestVirtualDF,
  746. &pTestChanceDF);
  747. // if creating the docfile - bail here
  748. if (NULL != pTestChanceDF && DoingCreate ())
  749. {
  750. UINT ulSeed = pTestChanceDF->GetSeed ();
  751. CleanupTestDocfile (&pVirtualDFRoot,
  752. &pTestVirtualDF,
  753. &pTestChanceDF,
  754. FALSE);
  755. return (HRESULT)ulSeed;
  756. }
  757. if (S_OK == hr)
  758. {
  759. dwRootMode = pTestChanceDF->GetRootMode();
  760. dwStgMode = pTestChanceDF->GetStgMode();
  761. DH_TRACE((
  762. DH_LVL_TRACE1,
  763. TEXT("Run Mode for ENUMTEST_102, Access mode: %lx"),
  764. dwRootMode));
  765. }
  766. //BUGBUG df already commited
  767. if(S_OK == hr)
  768. {
  769. hr = ParseVirtualDFAndCommitAllOpenStgs(
  770. pVirtualDFRoot,
  771. STGC_DEFAULT,
  772. NODE_EXC_TOPSTG);
  773. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  774. }
  775. // Commit root.
  776. if(S_OK == hr)
  777. {
  778. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  779. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  780. }
  781. if (S_OK == hr)
  782. {
  783. DH_TRACE((
  784. DH_LVL_TRACE1,
  785. TEXT("VirtualCtrNode::Commit completed successfully.")));
  786. }
  787. else
  788. {
  789. DH_TRACE((
  790. DH_LVL_TRACE1,
  791. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  792. hr));
  793. }
  794. if(S_OK == hr)
  795. {
  796. hr = ParseVirtualDFAndCloseOpenStgsStms(
  797. pVirtualDFRoot,
  798. NODE_EXC_TOPSTG);
  799. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  800. }
  801. // Find the total number of elements in the DocFile
  802. if(S_OK == hr)
  803. {
  804. hr = EnumerateInMemoryDocFile(pVirtualDFRoot, &cTotalStg, &cTotalStm);
  805. DH_HRCHECK(hr, TEXT("EnumerateInMemoryDocFile")) ;
  806. }
  807. // Close the Root Docfile.
  808. if (S_OK == hr)
  809. {
  810. hr = pVirtualDFRoot->Close();
  811. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  812. }
  813. if (S_OK == hr)
  814. {
  815. DH_TRACE((
  816. DH_LVL_TRACE1,
  817. TEXT("VirtualCtrNode::Close completed successfully.")));
  818. }
  819. else
  820. {
  821. DH_TRACE((
  822. DH_LVL_TRACE1,
  823. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  824. hr));
  825. }
  826. // Reopen the Root Docfile.
  827. if (S_OK == hr)
  828. {
  829. hr = pVirtualDFRoot->OpenRoot(
  830. NULL,
  831. dwRootMode,
  832. NULL,
  833. 0);
  834. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  835. }
  836. if (S_OK == hr)
  837. {
  838. DH_TRACE((
  839. DH_LVL_TRACE1,
  840. TEXT("VirtualCtrNode::Open completed successfully.")));
  841. }
  842. else
  843. {
  844. DH_TRACE((
  845. DH_LVL_TRACE1,
  846. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  847. hr));
  848. }
  849. // The named docfile/IStorage is instantiated and an enumerator
  850. // is obtained. The docfile is enumerated all objects at one level.
  851. // A clone is made of the enumerator, and it uses reset/skip/next
  852. // methods of enumerator to verify each of the child objects found.
  853. // Each contained IStorage/IStream is counted. If the object returned
  854. // by ->Next() is an IStorage, it is recursed into and processed.
  855. if(S_OK == hr)
  856. {
  857. hr = EnumerateDocFileAndVerifyEnumCloneResetSkipNext(
  858. pVirtualDFRoot,
  859. dwStgMode,
  860. cTotalStg+cTotalStm,
  861. &cEnumStg,
  862. &cEnumStm);
  863. DH_HRCHECK(hr, TEXT("EnumerateDocFileInRandomChunks")) ;
  864. }
  865. // Verify results
  866. if(S_OK == hr)
  867. {
  868. if(cEnumStg == cTotalStg)
  869. {
  870. DH_TRACE((
  871. DH_LVL_TRACE1,
  872. TEXT("Stg enum by org and clone/reset/skip/next as exp")));
  873. }
  874. else
  875. {
  876. DH_TRACE((
  877. DH_LVL_TRACE1,
  878. TEXT("Stg enum by org and clone/reset/skip/next notas exp")));
  879. fPass = FALSE;
  880. }
  881. if(cEnumStm == cTotalStm)
  882. {
  883. DH_TRACE((
  884. DH_LVL_TRACE1,
  885. TEXT("Stm enum by org and clone/reset/skip/next as exp")));
  886. }
  887. else
  888. {
  889. DH_TRACE((
  890. DH_LVL_TRACE1,
  891. TEXT("Stm enum by org and clone/reset/skip/next notas exp")));
  892. fPass = FALSE;
  893. }
  894. }
  895. // if everything goes well, log test as passed else failed.
  896. if ((S_OK == hr) && (TRUE == fPass))
  897. {
  898. DH_LOG((LOG_PASS, TEXT("Test variation ENUMTEST_102 passed.")) );
  899. }
  900. else
  901. {
  902. DH_LOG((
  903. LOG_FAIL,
  904. TEXT("Test variation ENUMTEST_102 failed, hr=0x%lx."),
  905. hr) );
  906. // test failed. make it look like it failed.
  907. hr = FirstError (hr, E_FAIL);
  908. }
  909. // Cleanup
  910. CleanupTestDocfile (&pVirtualDFRoot,
  911. &pTestVirtualDF,
  912. &pTestChanceDF,
  913. S_OK == hr);
  914. // Stop logging the test
  915. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_102 finished")) );
  916. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  917. return hr;
  918. }
  919. //----------------------------------------------------------------------------
  920. //
  921. // Test: ENUMTEST_103
  922. //
  923. // synopsis: A random root DF is created with random number of storages/streams
  924. // committed/close/reopened.
  925. // From 4 to 8 times, the root IStorage (docfile) is instantiated and
  926. // an enumerator is obtained. A Stat call is made on the the IStorage
  927. // and then the IStorage is enumerated. About 10% of the time
  928. // the current object is either destroyed, renamed, or modified.
  929. // Once every 1 to 64 objects is enumerated, a new IStorage (33%)
  930. // or IStream (66%) is created in the parent IStorage. If an object
  931. // was destroyed, renamed, changed, or added, the parent IStorage is
  932. // committed 50% of time. If the current object returned by the
  933. // enumerator is an IStorage (that wasn't deleted), the test recurses
  934. // and repeats the above for that IStorage. Then 33% of time, the
  935. // storage is reverted, 66% committed.
  936. //
  937. // Arguments:[argc]
  938. // [argv]
  939. //
  940. // Returns: HRESULT
  941. //
  942. // History: 30-July-1996 NarindK Created.
  943. //
  944. // Notes: This test runs in direct, transacted, transacted deny write modes
  945. //
  946. // New Test Notes:
  947. // 1. Old File: LITERMOD.CXX
  948. // 2. Old name of test : LegitInstEnumIterMod Test
  949. // New Name of test : ENUMTEST_103
  950. // 3. To run the test, do the following at command prompt.
  951. // a. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:0-3 /t:ENUMTEST-103
  952. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  953. // b. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:0-3 /t:ENUMTEST-103
  954. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  955. // c. stgbase /seed:2 /dfdepth:1-2 /dfstg:1-3 /dfstm:0-3 /t:ENUMTEST-103
  956. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  957. //
  958. // BUGNOTE: Conversion: ENUMTEST-103
  959. //
  960. //-----------------------------------------------------------------------------
  961. HRESULT ENUMTEST_103(int argc, char *argv[])
  962. {
  963. HRESULT hr = S_OK;
  964. ChanceDF *pTestChanceDF = NULL;
  965. VirtualDF *pTestVirtualDF = NULL;
  966. VirtualCtrNode *pVirtualDFRoot = NULL;
  967. LPSTORAGE pIStorage = NULL;
  968. DG_INTEGER *pdgi = NULL;
  969. DG_STRING *pdgu = NULL;
  970. USHORT usErr = 0;
  971. DWORD dwRootMode = 0;
  972. DWORD dwStgMode = 0;
  973. UINT cRandomMinVars = 4;
  974. UINT cRandomMaxVars = 8;
  975. UINT cRandomVars = 0;
  976. UINT cRandomAction = 0;
  977. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ENUMTEST_103"));
  978. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  979. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_103 started.")) );
  980. DH_TRACE((
  981. DH_LVL_TRACE1,
  982. TEXT("IEnumSTATSTG::Next docfile,Create/Change/Commit/Revert elem")));
  983. // Create our ChanceDF and VirtualDF
  984. hr = CreateTestDocfile (argc,
  985. argv,
  986. &pVirtualDFRoot,
  987. &pTestVirtualDF,
  988. &pTestChanceDF);
  989. // if creating the docfile - bail here
  990. if (NULL != pTestChanceDF && DoingCreate ())
  991. {
  992. UINT ulSeed = pTestChanceDF->GetSeed ();
  993. CleanupTestDocfile (&pVirtualDFRoot,
  994. &pTestVirtualDF,
  995. &pTestChanceDF,
  996. FALSE);
  997. return (HRESULT)ulSeed;
  998. }
  999. if (S_OK == hr)
  1000. {
  1001. dwRootMode = pTestChanceDF->GetRootMode();
  1002. dwStgMode = pTestChanceDF->GetStgMode();
  1003. DH_TRACE((
  1004. DH_LVL_TRACE1,
  1005. TEXT("Run Mode for ENUMTEST_105, Access mode: %lx"),
  1006. dwRootMode));
  1007. }
  1008. // BUGBUG df already commited
  1009. if(S_OK == hr)
  1010. {
  1011. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1012. pVirtualDFRoot,
  1013. STGC_DEFAULT,
  1014. NODE_EXC_TOPSTG);
  1015. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  1016. }
  1017. // Commit root.
  1018. if(S_OK == hr)
  1019. {
  1020. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1021. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1022. }
  1023. if (S_OK == hr)
  1024. {
  1025. DH_TRACE((
  1026. DH_LVL_TRACE1,
  1027. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1028. }
  1029. else
  1030. {
  1031. DH_TRACE((
  1032. DH_LVL_TRACE1,
  1033. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1034. hr));
  1035. }
  1036. if(S_OK == hr)
  1037. {
  1038. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1039. pVirtualDFRoot,
  1040. NODE_EXC_TOPSTG);
  1041. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1042. }
  1043. // Close the Root Docfile.
  1044. if (S_OK == hr)
  1045. {
  1046. hr = pVirtualDFRoot->Close();
  1047. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1048. }
  1049. if (S_OK == hr)
  1050. {
  1051. DH_TRACE((
  1052. DH_LVL_TRACE1,
  1053. TEXT("VirtualCtrNode::Close completed successfully.")));
  1054. }
  1055. else
  1056. {
  1057. DH_TRACE((
  1058. DH_LVL_TRACE1,
  1059. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1060. hr));
  1061. }
  1062. // Get DG_INTEGER object pointer
  1063. if (S_OK == hr)
  1064. {
  1065. pdgi = pTestVirtualDF->GetDataGenInteger();
  1066. DH_ASSERT(NULL != pdgi);
  1067. }
  1068. // Generate random number of variations that would be performed.
  1069. if (S_OK == hr)
  1070. {
  1071. // Generate random size for stream.
  1072. usErr = pdgi->Generate(&cRandomVars, cRandomMinVars, cRandomMaxVars);
  1073. if (DG_RC_SUCCESS != usErr)
  1074. {
  1075. hr = E_FAIL;
  1076. }
  1077. }
  1078. // Get DG_INTEGER object pointer
  1079. if (S_OK == hr)
  1080. {
  1081. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1082. DH_ASSERT(NULL != pdgu);
  1083. }
  1084. while((0 != cRandomVars--) && (S_OK == hr))
  1085. {
  1086. // Generate Random number to see whether changes would be reverted/
  1087. // committed at end of lop. If need to be reverted, then make a
  1088. // copy of VirtualDF which can be used later on
  1089. usErr = pdgi->Generate(&cRandomAction, 0, 3);
  1090. if (DG_RC_SUCCESS != usErr)
  1091. {
  1092. hr = E_FAIL;
  1093. }
  1094. // Reopen the Root Docfile.
  1095. if (S_OK == hr)
  1096. {
  1097. hr = pVirtualDFRoot->OpenRoot(
  1098. NULL,
  1099. dwRootMode,
  1100. NULL,
  1101. 0);
  1102. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1103. }
  1104. if (S_OK == hr)
  1105. {
  1106. pIStorage = pVirtualDFRoot->GetIStoragePointer();
  1107. DH_ASSERT(NULL != pIStorage);
  1108. }
  1109. // The named docfile/IStorage is instantiated and an enumerator
  1110. // is obtained. The docfile is walked by getting or skipping
  1111. // random number of elements. If the child object got is a storage,
  1112. // it is recursed into
  1113. // Enumerate and walk DocFile by randomly getting/skipping random elem
  1114. // -ents.
  1115. if(S_OK == hr)
  1116. {
  1117. hr = EnumerateAndProcessIStorage(
  1118. pIStorage,
  1119. dwStgMode,
  1120. pdgi,
  1121. pdgu);
  1122. DH_HRCHECK(hr, TEXT("EnumerateAndProcessIStorage")) ;
  1123. }
  1124. if (S_OK == hr)
  1125. {
  1126. DH_TRACE((
  1127. DH_LVL_TRACE1,
  1128. TEXT("EnumerateAndProcessIStorage completed successfully.")));
  1129. }
  1130. else
  1131. {
  1132. DH_TRACE((
  1133. DH_LVL_TRACE1,
  1134. TEXT("EnumerateAndProcessIStorage unsuccessful, hr=0x%lx."),
  1135. hr));
  1136. }
  1137. // Close the root docfile
  1138. if (S_OK == hr)
  1139. {
  1140. hr = pVirtualDFRoot->Close();
  1141. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1142. }
  1143. }
  1144. // if everything goes well, log test as passed else failed.
  1145. if (S_OK == hr)
  1146. {
  1147. DH_LOG((LOG_PASS, TEXT("Test variation ENUMTEST_103 passed.")) );
  1148. }
  1149. else
  1150. {
  1151. DH_LOG((
  1152. LOG_FAIL,
  1153. TEXT("Test variation ENUMTEST_103 failed, hr=0x%lx."),
  1154. hr) );
  1155. }
  1156. // Cleanup
  1157. CleanupTestDocfile (&pVirtualDFRoot,
  1158. &pTestVirtualDF,
  1159. &pTestChanceDF,
  1160. S_OK == hr);
  1161. // Stop logging the test
  1162. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_103 finished")) );
  1163. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1164. return hr;
  1165. }
  1166. //----------------------------------------------------------------------------
  1167. //
  1168. // Test: ENUMTEST_104
  1169. //
  1170. // synopsis: A random root DF is created with random number of storages/streams
  1171. // committed/close/reopened. From 4 - 8 times, the root DocFile is
  1172. // instantiated and an enumerator is obtained. The root docfile is
  1173. // walked by getting or skipping a random number of elements and if
  1174. // child element got is a child storage, recursing into it. There is
  1175. // 33% chance of skipping elements and 67% chance of getting them.
  1176. //
  1177. // Arguments:[argc]
  1178. // [argv]
  1179. //
  1180. // Returns: HRESULT
  1181. //
  1182. // History: 29-July-1996 NarindK Created.
  1183. //
  1184. // Notes: This test runs in direct, transacted, transacted deny write modes
  1185. //
  1186. // New Test Notes:
  1187. // 1. Old File: LIWALK.CXX
  1188. // 2. Old name of test : LegitInstEnumWalk Test
  1189. // New Name of test : ENUMTEST_104
  1190. // 3. To run the test, do the following at command prompt.
  1191. // a. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-104
  1192. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1193. // b. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-104
  1194. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1195. // c. stgbase /seed:2 /dfdepth:1-1 /dfstg:1-3 /dfstm:1-3 /t:ENUMTEST-104
  1196. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1197. //
  1198. // BUGNOTE: Conversion: ENUMTEST-104
  1199. //
  1200. //-----------------------------------------------------------------------------
  1201. HRESULT ENUMTEST_104(int argc, char *argv[])
  1202. {
  1203. HRESULT hr = S_OK;
  1204. ChanceDF *pTestChanceDF = NULL;
  1205. VirtualDF *pTestVirtualDF = NULL;
  1206. VirtualCtrNode *pVirtualDFRoot = NULL;
  1207. DG_INTEGER *pdgi = NULL;
  1208. USHORT usErr = 0;
  1209. DWORD dwRootMode = 0;
  1210. DWORD dwStgMode = 0;
  1211. ULONG cTotalStg = 0;
  1212. ULONG cTotalStm = 0;
  1213. UINT cRandomMinVars = 4;
  1214. UINT cRandomMaxVars = 8;
  1215. UINT cRandomVars = 0;
  1216. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ENUMTEST_104"));
  1217. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1218. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_104 started.")) );
  1219. DH_TRACE((
  1220. DH_LVL_TRACE1,
  1221. TEXT("IEnumSTATSTG::Next/Skip randomly to walk DocFile ")));
  1222. // Create our ChanceDF and VirtualDF
  1223. hr = CreateTestDocfile (argc,
  1224. argv,
  1225. &pVirtualDFRoot,
  1226. &pTestVirtualDF,
  1227. &pTestChanceDF);
  1228. // if creating the docfile - bail here
  1229. if (NULL != pTestChanceDF && DoingCreate ())
  1230. {
  1231. UINT ulSeed = pTestChanceDF->GetSeed ();
  1232. CleanupTestDocfile (&pVirtualDFRoot,
  1233. &pTestVirtualDF,
  1234. &pTestChanceDF,
  1235. FALSE);
  1236. return (HRESULT)ulSeed;
  1237. }
  1238. if (S_OK == hr)
  1239. {
  1240. dwRootMode = pTestChanceDF->GetRootMode();
  1241. dwStgMode = pTestChanceDF->GetStgMode();
  1242. DH_TRACE((
  1243. DH_LVL_TRACE1,
  1244. TEXT("Run Mode for ENUMTEST_104, Access mode: %lx"),
  1245. dwRootMode));
  1246. }
  1247. //BUGBUG df already commited
  1248. if(S_OK == hr)
  1249. {
  1250. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1251. pVirtualDFRoot,
  1252. STGC_DEFAULT,
  1253. NODE_EXC_TOPSTG);
  1254. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  1255. }
  1256. // Commit root.
  1257. if(S_OK == hr)
  1258. {
  1259. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1260. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1261. }
  1262. if (S_OK == hr)
  1263. {
  1264. DH_TRACE((
  1265. DH_LVL_TRACE1,
  1266. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1267. }
  1268. else
  1269. {
  1270. DH_TRACE((
  1271. DH_LVL_TRACE1,
  1272. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  1273. hr));
  1274. }
  1275. if(S_OK == hr)
  1276. {
  1277. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1278. pVirtualDFRoot,
  1279. NODE_EXC_TOPSTG);
  1280. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms")) ;
  1281. }
  1282. // Find the total number of elements in the DocFile
  1283. if(S_OK == hr)
  1284. {
  1285. hr = EnumerateInMemoryDocFile(pVirtualDFRoot, &cTotalStg, &cTotalStm);
  1286. DH_HRCHECK(hr, TEXT("EnumerateInMemoryDocFile")) ;
  1287. }
  1288. // Close the Root Docfile.
  1289. if (S_OK == hr)
  1290. {
  1291. hr = pVirtualDFRoot->Close();
  1292. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1293. }
  1294. if (S_OK == hr)
  1295. {
  1296. DH_TRACE((
  1297. DH_LVL_TRACE1,
  1298. TEXT("VirtualCtrNode::Close completed successfully.")));
  1299. }
  1300. else
  1301. {
  1302. DH_TRACE((
  1303. DH_LVL_TRACE1,
  1304. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  1305. hr));
  1306. }
  1307. // Get DG_INTEGER object pointer
  1308. if (S_OK == hr)
  1309. {
  1310. pdgi = pTestVirtualDF->GetDataGenInteger();
  1311. DH_ASSERT(NULL != pdgi);
  1312. }
  1313. // Generate random number of variations that would be performed.
  1314. if (S_OK == hr)
  1315. {
  1316. // Generate random size for stream.
  1317. usErr = pdgi->Generate(&cRandomVars, cRandomMinVars, cRandomMaxVars);
  1318. if (DG_RC_SUCCESS != usErr)
  1319. {
  1320. hr = E_FAIL;
  1321. }
  1322. }
  1323. while(0 != cRandomVars--)
  1324. {
  1325. // Reopen the Root Docfile.
  1326. if (S_OK == hr)
  1327. {
  1328. hr = pVirtualDFRoot->OpenRoot(
  1329. NULL,
  1330. dwRootMode,
  1331. NULL,
  1332. 0);
  1333. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1334. }
  1335. // The named docfile/IStorage is instantiated and an enumerator
  1336. // is obtained. The docfile is walked by getting or skipping
  1337. // random number of elements. If the child object got is a storage,
  1338. // it is recursed into
  1339. // Enumerate and walk DocFile by randomly getting/skipping random elem
  1340. // -ents.
  1341. if(S_OK == hr)
  1342. {
  1343. hr = EnumerateAndWalkDocFile(
  1344. pVirtualDFRoot,
  1345. pdgi,
  1346. dwStgMode,
  1347. cTotalStg+cTotalStm);
  1348. DH_HRCHECK(hr, TEXT("EnumerateAndWalkDocFile")) ;
  1349. }
  1350. if (S_OK == hr)
  1351. {
  1352. DH_TRACE((
  1353. DH_LVL_TRACE1,
  1354. TEXT("EnumerateAndWalkDocFile completed successfully.")));
  1355. }
  1356. else
  1357. {
  1358. DH_TRACE((
  1359. DH_LVL_TRACE1,
  1360. TEXT("EnumerateAndWalkDocFile unsuccessful, hr=0x%lx."),
  1361. hr));
  1362. }
  1363. // Close the root docfile
  1364. if (S_OK == hr)
  1365. {
  1366. hr = pVirtualDFRoot->Close();
  1367. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1368. }
  1369. }
  1370. // if everything goes well, log test as passed else failed.
  1371. if (S_OK == hr)
  1372. {
  1373. DH_LOG((LOG_PASS, TEXT("Test variation ENUMTEST_104 passed.")) );
  1374. }
  1375. else
  1376. {
  1377. DH_LOG((
  1378. LOG_FAIL,
  1379. TEXT("Test variation ENUMTEST_104 failed, hr=0x%lx."),
  1380. hr) );
  1381. }
  1382. // Cleanup
  1383. CleanupTestDocfile (&pVirtualDFRoot,
  1384. &pTestVirtualDF,
  1385. &pTestChanceDF,
  1386. S_OK == hr);
  1387. // Stop logging the test
  1388. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ENUMTEST_104 finished")) );
  1389. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1390. return hr;
  1391. }