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.

5040 lines
128 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: comtests.cxx
  7. //
  8. // Contents: storage base tests common to IStorage and IStream methoods
  9. //
  10. // Functions:
  11. //
  12. // History: 29-May-1996 NarindK Created.
  13. // 27-Mar-97 SCousens Conversionified
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <dfheader.hxx>
  17. #pragma hdrstop
  18. #include "init.hxx"
  19. //----------------------------------------------------------------------------
  20. //
  21. // Test: COMTEST_100
  22. //
  23. // Synopsis:Create a root docfile with a child IStorage and a child IStream.
  24. // Commit the root docfile.
  25. //
  26. // Add a random number of refcounts to IStorage via AddRef() method.
  27. // loop to release the refs, each release is followed by a Stat. After
  28. // the last ref (that we added) is released, release the ref created
  29. // during the Create... call. This frees the real object. Repeat for
  30. // the child IStream.
  31. //
  32. // Arguments: [argc]
  33. // [argv]
  34. //
  35. // Returns: HRESULT
  36. //
  37. // History: 29-May-1996 NarindK Created.
  38. //
  39. // Notes: This test runs in direct, transacted, and transacted deny write
  40. // modes
  41. //
  42. // New Test Notes:
  43. // 1. Old File: ADDREF.CXX
  44. // 2. Old name of test : MiscAddRef
  45. // New Name of test : COMTEST_100
  46. // 3. To run the test, do the following at command prompt.
  47. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-100
  48. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  49. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-100
  50. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  51. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-100
  52. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  53. //
  54. // Conversion: COMTEST_100
  55. //
  56. //-----------------------------------------------------------------------------
  57. HRESULT COMTEST_100(int argc, char *argv[])
  58. {
  59. HRESULT hr = S_OK;
  60. ChanceDF *pTestChanceDF = NULL;
  61. VirtualDF *pTestVirtualDF = NULL;
  62. VirtualCtrNode *pVirtualDFRoot = NULL;
  63. DG_STRING *pdgu = NULL;
  64. DG_INTEGER *pdgi = NULL;
  65. USHORT usErr = 0;
  66. VirtualStmNode *pvsnRootNewChildStream = NULL;
  67. LPTSTR pRootNewChildStmName = NULL;
  68. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  69. LPTSTR pRootNewChildStgName = NULL;
  70. ULONG cb = 0;
  71. ULONG cusIStorageRefs = 0;
  72. ULONG cusIStreamRefs = 0;
  73. ULONG i = 0;
  74. ULONG cRandomMinSize = 10;
  75. ULONG cRandomMaxSize = 100;
  76. ULONG cRandomMinVar = 2;
  77. ULONG cRandomMaxVar = 16;
  78. STATSTG statStg;
  79. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_100"));
  80. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  81. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_100 started.")) );
  82. DH_TRACE((DH_LVL_TRACE1, TEXT("AddRef/Release tests on IStorage/IStream")) );
  83. // Create our ChanceDF and VirtualDF
  84. hr = CreateTestDocfile (argc,
  85. argv,
  86. &pVirtualDFRoot,
  87. &pTestVirtualDF,
  88. &pTestChanceDF);
  89. // if creating the docfile - bail here
  90. if (NULL != pTestChanceDF && DoingCreate ())
  91. {
  92. UINT ulSeed = pTestChanceDF->GetSeed ();
  93. CleanupTestDocfile (&pVirtualDFRoot,
  94. &pTestVirtualDF,
  95. &pTestChanceDF,
  96. FALSE);
  97. return (HRESULT)ulSeed;
  98. }
  99. if (S_OK == hr)
  100. {
  101. DH_TRACE((
  102. DH_LVL_TRACE1,
  103. TEXT("Run Mode for COMTEST_100, Access mode: %lx"),
  104. pTestChanceDF->GetRootMode()));
  105. }
  106. // Get DG_UNICODE object pointer
  107. if (S_OK == hr)
  108. {
  109. pdgu = pTestVirtualDF->GetDataGenUnicode();
  110. DH_ASSERT(NULL != pdgu);
  111. }
  112. // Get DG_INTEGER object pointer
  113. if (S_OK == hr)
  114. {
  115. pdgi = pTestVirtualDF->GetDataGenInteger();
  116. DH_ASSERT(NULL != pdgi);
  117. }
  118. // Generate a random name for child IStorage
  119. if(S_OK == hr)
  120. {
  121. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  122. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  123. }
  124. // Adds a new storage to the root storage.
  125. // ----------- flatfile change ---------------
  126. if(!StorageIsFlat())
  127. {
  128. // ----------- flatfile change ---------------
  129. if(S_OK == hr)
  130. {
  131. hr = AddStorage(
  132. pTestVirtualDF,
  133. pVirtualDFRoot,
  134. pRootNewChildStgName,
  135. pTestChanceDF->GetStgMode()|
  136. STGM_CREATE |
  137. STGM_FAILIFTHERE,
  138. &pvcnRootNewChildStorage);
  139. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  140. }
  141. if(S_OK == hr)
  142. {
  143. DH_TRACE((
  144. DH_LVL_TRACE1,
  145. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  146. }
  147. else
  148. {
  149. DH_TRACE((
  150. DH_LVL_ERROR,
  151. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  152. hr));
  153. }
  154. // ----------- flatfile change ---------------
  155. }
  156. // ----------- flatfile change ---------------
  157. // Adds a new stream to the root storage.
  158. if(S_OK == hr)
  159. {
  160. // Generate random name for stream
  161. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  162. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  163. }
  164. if (S_OK == hr)
  165. {
  166. // Generate random size for stream.
  167. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  168. if (DG_RC_SUCCESS != usErr)
  169. {
  170. hr = E_FAIL;
  171. }
  172. }
  173. if(S_OK == hr)
  174. {
  175. hr = AddStream(
  176. pTestVirtualDF,
  177. pVirtualDFRoot,
  178. pRootNewChildStmName,
  179. cb,
  180. STGM_READWRITE |
  181. STGM_SHARE_EXCLUSIVE |
  182. STGM_FAILIFTHERE,
  183. &pvsnRootNewChildStream);
  184. DH_HRCHECK(hr, TEXT("AddStream")) ;
  185. }
  186. if(S_OK == hr)
  187. {
  188. DH_TRACE((
  189. DH_LVL_TRACE1,
  190. TEXT("VirtualStmNode::AddStream completed successfully.")));
  191. }
  192. else
  193. {
  194. DH_TRACE((
  195. DH_LVL_ERROR,
  196. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx."),
  197. hr));
  198. }
  199. // Commit the root storage.
  200. if(S_OK == hr)
  201. {
  202. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  203. }
  204. if (S_OK == hr)
  205. {
  206. DH_TRACE((
  207. DH_LVL_TRACE1,
  208. TEXT("VirtualCtrNode::Commit completed successfully.")));
  209. }
  210. else
  211. {
  212. DH_TRACE((
  213. DH_LVL_ERROR,
  214. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  215. hr));
  216. }
  217. // ----------- flatfile change ---------------
  218. if(!StorageIsFlat())
  219. {
  220. // ----------- flatfile change ---------------
  221. // add from 2 to 16 ref counts to child IStorage object and then
  222. // release each one followed by a Stat() call. The ref count should
  223. // be decremented after each release. There will already be one
  224. // ref count from the IStorage create call, so all Stat() calls in
  225. // the loop should be on a valid object. Finally, release remaining
  226. // IStorage (this is the ref from the creation)
  227. if (S_OK == hr)
  228. {
  229. // Generate random number for ref counts to be done.
  230. usErr = pdgi->Generate(&cusIStorageRefs, cRandomMinVar, cRandomMaxVar);
  231. if (DG_RC_SUCCESS != usErr)
  232. {
  233. hr = E_FAIL;
  234. }
  235. }
  236. for (i=0; i < cusIStorageRefs; i++)
  237. {
  238. // AddRef the storage
  239. hr = pvcnRootNewChildStorage->AddRefCount();
  240. if (S_OK == hr)
  241. {
  242. DH_TRACE((
  243. DH_LVL_TRACE1,
  244. TEXT("VirtualCtrNode::AddRefCount completed successfully.")));
  245. }
  246. else
  247. {
  248. DH_TRACE((
  249. DH_LVL_ERROR,
  250. TEXT("VirtualCtrNode::AddRefCount unsuccessful, hr = 0x%lx."),
  251. hr));
  252. break;
  253. }
  254. }
  255. while ((cusIStorageRefs--) && (S_OK == hr))
  256. {
  257. // Close the storage
  258. hr = pvcnRootNewChildStorage->Close();
  259. if (S_OK == hr)
  260. {
  261. DH_TRACE((
  262. DH_LVL_TRACE1,
  263. TEXT("VirtualCtrNode::Close completed successfully.")));
  264. }
  265. else
  266. {
  267. DH_TRACE((
  268. DH_LVL_ERROR,
  269. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  270. hr));
  271. }
  272. if (S_OK == hr)
  273. {
  274. // Stat the storage
  275. hr = pvcnRootNewChildStorage->Stat(&statStg, STATFLAG_NONAME);
  276. if (S_OK == hr)
  277. {
  278. DH_TRACE((
  279. DH_LVL_TRACE1,
  280. TEXT("VirtualCtrNode::Stat completed successfully.")));
  281. }
  282. else
  283. {
  284. DH_TRACE((
  285. DH_LVL_ERROR,
  286. TEXT("VirtualCtrNode::Stat unsuccessful, hr = 0x%lx."),
  287. hr));
  288. }
  289. }
  290. }
  291. // Close the root storage
  292. if (S_OK == hr)
  293. {
  294. hr = pvcnRootNewChildStorage->Close();
  295. }
  296. if (S_OK == hr)
  297. {
  298. DH_TRACE((
  299. DH_LVL_TRACE1,
  300. TEXT("VirtualCtrNode::Close completed successfully.")));
  301. }
  302. else
  303. {
  304. DH_TRACE((
  305. DH_LVL_ERROR,
  306. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  307. hr));
  308. }
  309. // ----------- flatfile change ---------------
  310. }
  311. // ----------- flatfile change ---------------
  312. // add from 2 to 16 ref counts to child IStream object and then
  313. // release each one followed by a Stat() call. The ref count should
  314. // be decremented after each release. There will already be one
  315. // ref count from the IStream create call, so all Stat() calls in
  316. // the loop should be on a valid object. Finally, release remaining
  317. // IStream (this is the ref from the creation)
  318. if (S_OK == hr)
  319. {
  320. // Generate random number for ref counts to be done.
  321. usErr = pdgi->Generate(&cusIStreamRefs, cRandomMinVar, cRandomMaxVar);
  322. if (DG_RC_SUCCESS != usErr)
  323. {
  324. hr = E_FAIL;
  325. }
  326. }
  327. for (i=0; i < cusIStreamRefs; i++)
  328. {
  329. // Addref the stream
  330. hr = pvsnRootNewChildStream->AddRefCount();
  331. if (S_OK == hr)
  332. {
  333. DH_TRACE((
  334. DH_LVL_TRACE1,
  335. TEXT("VirtualStmNode::AddRefCount completed successfully.")));
  336. }
  337. else
  338. {
  339. DH_TRACE((
  340. DH_LVL_ERROR,
  341. TEXT("VirtualStmNode::AddRefCount unsuccessful, hr = 0x%lx."),
  342. hr));
  343. break;
  344. }
  345. }
  346. while ((cusIStreamRefs--) && (S_OK == hr))
  347. {
  348. // Clsoe the stream
  349. hr = pvsnRootNewChildStream->Close();
  350. if (S_OK == hr)
  351. {
  352. DH_TRACE((
  353. DH_LVL_TRACE1,
  354. TEXT("VirtualStmNode::Close completed successfully.")));
  355. }
  356. else
  357. {
  358. DH_TRACE((
  359. DH_LVL_ERROR,
  360. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  361. hr));
  362. }
  363. if (S_OK == hr)
  364. {
  365. // Stat the stream
  366. hr = pvsnRootNewChildStream->Stat(&statStg, STATFLAG_NONAME);
  367. if (S_OK == hr)
  368. {
  369. DH_TRACE((
  370. DH_LVL_TRACE1,
  371. TEXT("VirtualStmNode::Stat completed successfully.")));
  372. }
  373. else
  374. {
  375. DH_TRACE((
  376. DH_LVL_ERROR,
  377. TEXT("VirtualStmNode::Stat unsuccessful, hr = 0x%lx."),
  378. hr));
  379. }
  380. }
  381. }
  382. // Close the stream
  383. if (S_OK == hr)
  384. {
  385. hr = pvsnRootNewChildStream->Close();
  386. }
  387. if (S_OK == hr)
  388. {
  389. DH_TRACE((
  390. DH_LVL_TRACE1,
  391. TEXT("VirtualStmNode::Close completed successfully.")));
  392. }
  393. else
  394. {
  395. DH_TRACE((
  396. DH_LVL_ERROR,
  397. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  398. hr));
  399. }
  400. // if everything goes well, log test as passed else failed.
  401. if (S_OK == hr)
  402. {
  403. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_100 passed.")) );
  404. }
  405. else
  406. {
  407. DH_LOG((
  408. LOG_FAIL,
  409. TEXT("Test variation COMTEST_100 failed, hr = 0x%lx."),
  410. hr) );
  411. }
  412. // Cleanup
  413. CleanupTestDocfile (&pVirtualDFRoot,
  414. &pTestVirtualDF,
  415. &pTestChanceDF,
  416. S_OK == hr);
  417. // Delete strings
  418. if(NULL != pRootNewChildStgName)
  419. {
  420. delete pRootNewChildStgName;
  421. pRootNewChildStgName = NULL;
  422. }
  423. if(NULL != pRootNewChildStmName)
  424. {
  425. delete pRootNewChildStmName;
  426. pRootNewChildStmName = NULL;
  427. }
  428. // Stop logging the test
  429. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_100 finished")) );
  430. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  431. return hr;
  432. }
  433. //----------------------------------------------------------------------------
  434. //
  435. // Test: COMTEST_101
  436. //
  437. // Synopsis: Regression test for root docfile creation, IStorage creation,
  438. // embedded stream creation/read/write, and IStorage commit
  439. // operations.
  440. //
  441. // Arguments: [argc]
  442. // [argv]
  443. //
  444. // Returns: HRESULT
  445. //
  446. // History: 29-May-1996 NarindK Created.
  447. //
  448. // Notes: This test runs in direct, transacted, and transacted deny write
  449. // modes
  450. //
  451. // New Test Notes:
  452. // 1. Old File: DFTEST.CXX
  453. // 2. Old name of test :
  454. // New Name of test : COMTEST_101
  455. // 3. To run the test, do the following at command prompt.
  456. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-101
  457. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  458. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-101
  459. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  460. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-101
  461. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  462. //
  463. // Conversion: COMTEST_101
  464. //
  465. //-----------------------------------------------------------------------------
  466. HRESULT COMTEST_101(int argc, char *argv[])
  467. {
  468. HRESULT hr = S_OK;
  469. ChanceDF *pTestChanceDF = NULL;
  470. VirtualDF *pTestVirtualDF = NULL;
  471. VirtualCtrNode *pVirtualDFRoot = NULL;
  472. DG_INTEGER *pdgi = NULL;
  473. DG_STRING *pdgu = NULL;
  474. USHORT usErr = 0;
  475. VirtualStmNode *pvsnRootNewChildStream = NULL;
  476. LPTSTR pRootNewChildStmName = NULL;
  477. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  478. LPTSTR pRootNewChildStgName = NULL;
  479. LPTSTR pwcsBuffer = NULL;
  480. LPTSTR pReadBuffer = NULL;
  481. ULONG cb = 0;
  482. ULONG culWritten = 0;
  483. ULONG culRead = 0;
  484. ULONG cRandomMinSize = 10;
  485. ULONG cRandomMaxSize = 100;
  486. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_101"));
  487. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  488. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_101 started.")) );
  489. DH_TRACE((DH_LVL_TRACE1,
  490. TEXT("Regression test for Docfile/IStorage/IStream creation.")) );
  491. DH_TRACE((DH_LVL_TRACE1,
  492. TEXT("IStream Read/Write, IStorage Commit opertaions.")) );
  493. // Create our ChanceDF and VirtualDF
  494. hr = CreateTestDocfile (argc,
  495. argv,
  496. &pVirtualDFRoot,
  497. &pTestVirtualDF,
  498. &pTestChanceDF);
  499. // if creating the docfile - bail here
  500. if (NULL != pTestChanceDF && DoingCreate ())
  501. {
  502. UINT ulSeed = pTestChanceDF->GetSeed ();
  503. CleanupTestDocfile (&pVirtualDFRoot,
  504. &pTestVirtualDF,
  505. &pTestChanceDF,
  506. FALSE);
  507. return (HRESULT)ulSeed;
  508. }
  509. if (S_OK == hr)
  510. {
  511. DH_TRACE((
  512. DH_LVL_TRACE1,
  513. TEXT("Run Mode for COMTEST_101, Access mode: %lx"),
  514. pTestChanceDF->GetRootMode()));
  515. }
  516. // Get DG_STRING object pointer
  517. if (S_OK == hr)
  518. {
  519. pdgu = pTestVirtualDF->GetDataGenUnicode();
  520. DH_ASSERT(NULL != pdgu);
  521. }
  522. // Get DG_INTEGER object pointer
  523. if (S_OK == hr)
  524. {
  525. pdgi = pTestVirtualDF->GetDataGenInteger();
  526. DH_ASSERT(NULL != pdgi);
  527. }
  528. // Generate a random name for child IStorage
  529. if(S_OK == hr)
  530. {
  531. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  532. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  533. }
  534. // ----------- flatfile change ---------------
  535. if(!StorageIsFlat())
  536. {
  537. // ----------- flatfile change ---------------
  538. // Adds a new storage to the root storage.
  539. if(S_OK == hr)
  540. {
  541. hr = AddStorage(
  542. pTestVirtualDF,
  543. pVirtualDFRoot,
  544. pRootNewChildStgName,
  545. pTestChanceDF->GetStgMode()|
  546. STGM_CREATE,
  547. &pvcnRootNewChildStorage);
  548. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  549. }
  550. if(S_OK == hr)
  551. {
  552. DH_TRACE((
  553. DH_LVL_TRACE1,
  554. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  555. }
  556. else
  557. {
  558. DH_TRACE((
  559. DH_LVL_ERROR,
  560. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  561. hr ));
  562. }
  563. // ----------- flatfile change ---------------
  564. }
  565. // ----------- flatfile change ---------------
  566. // Generate a random name for child IStream
  567. if(S_OK == hr)
  568. {
  569. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  570. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  571. }
  572. if (S_OK == hr)
  573. {
  574. // Generate random size for stream.
  575. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  576. if (DG_RC_SUCCESS != usErr)
  577. {
  578. hr = E_FAIL;
  579. }
  580. }
  581. // Adds a new stream to the root storage.
  582. if(S_OK == hr)
  583. {
  584. hr = AddStream(
  585. pTestVirtualDF,
  586. pVirtualDFRoot,
  587. pRootNewChildStmName,
  588. cb,
  589. STGM_READWRITE |
  590. STGM_SHARE_EXCLUSIVE,
  591. &pvsnRootNewChildStream);
  592. DH_HRCHECK(hr, TEXT("AddStream")) ;
  593. }
  594. if(S_OK == hr)
  595. {
  596. DH_TRACE((
  597. DH_LVL_TRACE1,
  598. TEXT("VirtualStmNode::AddStream completed successfully.")));
  599. }
  600. else
  601. {
  602. DH_TRACE((
  603. DH_LVL_ERROR,
  604. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx."),
  605. hr));
  606. }
  607. // Call VirtualStmNode::Write to create random bytes in the stream. For
  608. // our test purposes, we generate a random string of size cb using
  609. // GenerateRandomString function.
  610. if(S_OK == hr)
  611. {
  612. hr = GenerateRandomString(pdgu, cb, cb, &pwcsBuffer);
  613. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  614. }
  615. if (S_OK == hr)
  616. {
  617. hr = pvsnRootNewChildStream->Write(
  618. pwcsBuffer,
  619. cb,
  620. &culWritten);
  621. }
  622. if (S_OK == hr)
  623. {
  624. DH_TRACE((
  625. DH_LVL_TRACE1,
  626. TEXT("IStream::Write function completed successfully.")));
  627. }
  628. else
  629. {
  630. DH_TRACE((
  631. DH_LVL_ERROR,
  632. TEXT("IStream::Write function wasn't successful, hr = 0x%lx."),
  633. hr));
  634. }
  635. // Close the IStream
  636. if (S_OK == hr)
  637. {
  638. hr = pvsnRootNewChildStream->Close();
  639. }
  640. if (S_OK == hr)
  641. {
  642. DH_TRACE((
  643. DH_LVL_TRACE1,
  644. TEXT("VirtualStmNode::Close completed successfully.")));
  645. }
  646. else
  647. {
  648. DH_TRACE((
  649. DH_LVL_ERROR,
  650. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  651. hr));
  652. }
  653. // ----------- flatfile change ---------------
  654. if(!StorageIsFlat())
  655. {
  656. // ----------- flatfile change ---------------
  657. // Close the IStorage
  658. if (S_OK == hr)
  659. {
  660. hr = pvcnRootNewChildStorage->Close();
  661. }
  662. if (S_OK == hr)
  663. {
  664. DH_TRACE((
  665. DH_LVL_TRACE1,
  666. TEXT("VirtualCtrNode::Close completed successfully.")));
  667. }
  668. else
  669. {
  670. DH_TRACE((
  671. DH_LVL_ERROR,
  672. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  673. hr));
  674. }
  675. // ----------- flatfile change ---------------
  676. }
  677. // ----------- flatfile change ---------------
  678. // Commit the DocFile
  679. if(S_OK == hr)
  680. {
  681. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  682. }
  683. if (S_OK == hr)
  684. {
  685. DH_TRACE((
  686. DH_LVL_TRACE1,
  687. TEXT("VirtualCtrNode::Commit completed successfully.")));
  688. }
  689. else
  690. {
  691. DH_TRACE((
  692. DH_LVL_ERROR,
  693. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  694. hr));
  695. }
  696. // Close the Root DocFile
  697. if (S_OK == hr)
  698. {
  699. hr = pVirtualDFRoot->Close();
  700. }
  701. if (S_OK == hr)
  702. {
  703. DH_TRACE((
  704. DH_LVL_TRACE1,
  705. TEXT("VirtualCtrNode::Close completed successfully.")));
  706. }
  707. else
  708. {
  709. DH_TRACE((
  710. DH_LVL_ERROR,
  711. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  712. hr));
  713. }
  714. // Open the Root DocFile
  715. if (S_OK == hr)
  716. {
  717. hr = pVirtualDFRoot->OpenRoot(
  718. NULL,
  719. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  720. NULL,
  721. 0);
  722. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  723. }
  724. if (S_OK == hr)
  725. {
  726. DH_TRACE((
  727. DH_LVL_TRACE1,
  728. TEXT("VirtualCtrNode::Open completed successfully.")));
  729. }
  730. else
  731. {
  732. DH_TRACE((
  733. DH_LVL_ERROR,
  734. TEXT("VirtualCtrNode::Open unsuccessful, hr = 0x%lx."),
  735. hr));
  736. }
  737. // ----------- flatfile change ---------------
  738. if(!StorageIsFlat())
  739. {
  740. // ----------- flatfile change ---------------
  741. // Open the embedded IStorage
  742. if (S_OK == hr)
  743. {
  744. hr = pvcnRootNewChildStorage->Open(
  745. NULL,
  746. STGM_READWRITE |
  747. STGM_SHARE_EXCLUSIVE,
  748. NULL,
  749. 0);
  750. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  751. }
  752. if (S_OK == hr)
  753. {
  754. DH_TRACE((
  755. DH_LVL_TRACE1,
  756. TEXT("VirtualCtrNode::Open completed successfully.")));
  757. }
  758. else
  759. {
  760. DH_TRACE((
  761. DH_LVL_ERROR,
  762. TEXT("VirtualCtrNode::Open unsuccessful, hr = 0x%lx."),
  763. hr));
  764. }
  765. // ----------- flatfile change ---------------
  766. }
  767. // ----------- flatfile change ---------------
  768. // Open the IStream
  769. if (S_OK == hr)
  770. {
  771. hr = pvsnRootNewChildStream->Open(
  772. NULL,
  773. STGM_READWRITE |
  774. STGM_SHARE_EXCLUSIVE,
  775. 0);
  776. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  777. }
  778. if (S_OK == hr)
  779. {
  780. DH_TRACE((
  781. DH_LVL_TRACE1,
  782. TEXT("VirtualStmNode::Open completed successfully.")));
  783. }
  784. else
  785. {
  786. DH_TRACE((
  787. DH_LVL_ERROR,
  788. TEXT("VirtualStmNode::Open unsuccessful, hr = 0x%lx."),
  789. hr));
  790. }
  791. // Read the IStream.
  792. if (S_OK == hr)
  793. {
  794. pReadBuffer = new TCHAR [cb];
  795. if(NULL == pReadBuffer)
  796. {
  797. hr = E_OUTOFMEMORY;
  798. }
  799. }
  800. if(S_OK == hr)
  801. {
  802. memset(pReadBuffer, '\0', cb);
  803. hr = pvsnRootNewChildStream->Read(
  804. pReadBuffer,
  805. cb,
  806. &culRead);
  807. }
  808. if (S_OK == hr)
  809. {
  810. DH_TRACE((
  811. DH_LVL_TRACE1,
  812. TEXT("IStream::Read function completed successfully.")));
  813. }
  814. else
  815. {
  816. DH_TRACE((
  817. DH_LVL_ERROR,
  818. TEXT("IStream::Read function wasn't successful, hr = 0x%lx."),
  819. hr));
  820. }
  821. // Close the IStream
  822. if (S_OK == hr)
  823. {
  824. hr = pvsnRootNewChildStream->Close();
  825. }
  826. if (S_OK == hr)
  827. {
  828. DH_TRACE((
  829. DH_LVL_TRACE1,
  830. TEXT("VirtualStmNode::Close completed successfully.")));
  831. }
  832. else
  833. {
  834. DH_TRACE((
  835. DH_LVL_ERROR,
  836. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  837. hr));
  838. }
  839. // ----------- flatfile change ---------------
  840. if(!StorageIsFlat())
  841. {
  842. // ----------- flatfile change ---------------
  843. // Close the IStorage
  844. if (S_OK == hr)
  845. {
  846. hr = pvcnRootNewChildStorage->Close();
  847. }
  848. if (S_OK == hr)
  849. {
  850. DH_TRACE((
  851. DH_LVL_TRACE1,
  852. TEXT("VirtualCtrNode::Close completed successfully.")));
  853. }
  854. else
  855. {
  856. DH_TRACE((
  857. DH_LVL_ERROR,
  858. TEXT("VirtualCtrNode::Close unsuccessful.")));
  859. }
  860. // ----------- flatfile change ---------------
  861. }
  862. // ----------- flatfile change ---------------
  863. // Close the Root DocFile
  864. if (S_OK == hr)
  865. {
  866. hr = pVirtualDFRoot->Close();
  867. }
  868. if (S_OK == hr)
  869. {
  870. DH_TRACE((
  871. DH_LVL_TRACE1,
  872. TEXT("VirtualCtrNode::Close completed successfully.")));
  873. }
  874. else
  875. {
  876. DH_TRACE((
  877. DH_LVL_ERROR,
  878. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  879. hr));
  880. }
  881. // if everything goes well, log test as passed else failed.
  882. if (S_OK == hr)
  883. {
  884. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_101 passed.")) );
  885. }
  886. else
  887. {
  888. DH_LOG((
  889. LOG_FAIL,
  890. TEXT("Test variation COMTEST_101 failed, hr = 0x%lx."),
  891. hr) );
  892. }
  893. // Cleanup
  894. CleanupTestDocfile (&pVirtualDFRoot,
  895. &pTestVirtualDF,
  896. &pTestChanceDF,
  897. S_OK == hr);
  898. // Delete strings
  899. if(NULL != pRootNewChildStgName)
  900. {
  901. delete pRootNewChildStgName;
  902. pRootNewChildStgName = NULL;
  903. }
  904. if(NULL != pRootNewChildStmName)
  905. {
  906. delete pRootNewChildStmName;
  907. pRootNewChildStmName = NULL;
  908. }
  909. if(NULL != pwcsBuffer)
  910. {
  911. delete []pwcsBuffer;
  912. pwcsBuffer = NULL;
  913. }
  914. if(NULL != pReadBuffer)
  915. {
  916. delete []pReadBuffer;
  917. pReadBuffer = NULL;
  918. }
  919. if(NULL != pRootNewChildStmName)
  920. {
  921. delete pRootNewChildStmName;
  922. pRootNewChildStmName = NULL;
  923. }
  924. // Stop logging the test
  925. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_101 finished")) );
  926. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  927. return hr;
  928. }
  929. //----------------------------------------------------------------------------
  930. //
  931. // Test: COMTEST_102
  932. //
  933. // Synopsis: Create a root docfile with random name. Create a child IStorage
  934. // and a child IStream in this docfile. Attempt to do iilegal op
  935. // erations on this docfile - creating/instantiating storages/streams
  936. // /root docfiles with existing names with STGM_FAILIFTHERE flag. Also
  937. // attempts various illegal grfmodes.
  938. //
  939. // Arguments: [argc]
  940. // [argv]
  941. //
  942. // Returns: HRESULT
  943. //
  944. // History: 29-May-1996 NarindK Created.
  945. //
  946. // Notes: This test runs in direct, transacted, and transacted deny write
  947. // modes
  948. //
  949. // New Test Notes:
  950. // 1. Old File: IINORM.CXX
  951. // 2. Old name of test : IllegitInstEnumNormal Test
  952. // New Name of test : COMTEST_102
  953. // 3. To run the test, do the following at command prompt.
  954. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-102
  955. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  956. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-102
  957. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  958. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-102
  959. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  960. //
  961. // Conversion: COMTEST_102
  962. //
  963. // BUGBUG: Use Random Commit modes
  964. //-----------------------------------------------------------------------------
  965. HRESULT COMTEST_102(int argc, char *argv[])
  966. {
  967. HRESULT hr = S_OK;
  968. ChanceDF *pTestChanceDF = NULL;
  969. VirtualDF *pTestVirtualDF = NULL;
  970. VirtualCtrNode *pVirtualDFRoot = NULL;
  971. DG_INTEGER *pdgi = NULL;
  972. DG_STRING *pdgu = NULL;
  973. USHORT usErr = 0;
  974. VirtualStmNode *pvsnRootNewChildStream = NULL;
  975. LPTSTR pRootNewChildStmName = NULL;
  976. VirtualCtrNode *pvcnRootNewChildStorage = NULL;
  977. LPTSTR pRootNewChildStgName = NULL;
  978. ULONG cb = 0;
  979. VirtualCtrNode *pvcnRootSecondChildStorage = NULL;
  980. VirtualCtrNode *pvcnRootThirdChildStorage = NULL;
  981. VirtualStmNode *pvcnRootSecondChildStream = NULL;
  982. VirtualStmNode *pvcnRootThirdChildStream = NULL;
  983. LPSTORAGE pRootStg = NULL;
  984. LPSTORAGE pNonExistingStg = NULL;
  985. LPSTREAM pNonExistingStm = NULL;
  986. ULONG cRandomMinSize = 10;
  987. ULONG cRandomMaxSize = 100;
  988. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_102"));
  989. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  990. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_102 started.")) );
  991. DH_TRACE((DH_LVL_TRACE1,
  992. TEXT("Illegal operations on Docfile/IStorage/IStream.")) );
  993. DH_TRACE((DH_LVL_TRACE1,
  994. TEXT("Instantiating with existing names, invalid grfmodes.")) );
  995. // Create our ChanceDF and VirtualDF
  996. hr = CreateTestDocfile (argc,
  997. argv,
  998. &pVirtualDFRoot,
  999. &pTestVirtualDF,
  1000. &pTestChanceDF);
  1001. // if creating the docfile - bail here
  1002. if (NULL != pTestChanceDF && DoingCreate ())
  1003. {
  1004. UINT ulSeed = pTestChanceDF->GetSeed ();
  1005. CleanupTestDocfile (&pVirtualDFRoot,
  1006. &pTestVirtualDF,
  1007. &pTestChanceDF,
  1008. FALSE);
  1009. return (HRESULT)ulSeed;
  1010. }
  1011. if (S_OK == hr)
  1012. {
  1013. DH_TRACE((
  1014. DH_LVL_TRACE1,
  1015. TEXT("Run Mode for COMTEST_102, Access mode: %lx"),
  1016. pTestChanceDF->GetRootMode()));
  1017. }
  1018. // Get DG_STRING object pointer
  1019. if (S_OK == hr)
  1020. {
  1021. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1022. DH_ASSERT(NULL != pdgu);
  1023. }
  1024. // Get DG_INTEGER object pointer
  1025. if (S_OK == hr)
  1026. {
  1027. pdgi = pTestVirtualDF->GetDataGenInteger();
  1028. DH_ASSERT(NULL != pdgi);
  1029. }
  1030. // ----------- flatfile change ---------------
  1031. if(!StorageIsFlat())
  1032. {
  1033. // ----------- flatfile change ---------------
  1034. // Generate a random name for child IStorage
  1035. if(S_OK == hr)
  1036. {
  1037. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  1038. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1039. }
  1040. // Adds a new storage to the root storage.
  1041. if(S_OK == hr)
  1042. {
  1043. hr = AddStorage(
  1044. pTestVirtualDF,
  1045. pVirtualDFRoot,
  1046. pRootNewChildStgName,
  1047. pTestChanceDF->GetStgMode()|
  1048. STGM_CREATE,
  1049. &pvcnRootNewChildStorage);
  1050. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1051. }
  1052. if(S_OK == hr)
  1053. {
  1054. DH_TRACE((
  1055. DH_LVL_TRACE1,
  1056. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  1057. }
  1058. else
  1059. {
  1060. DH_TRACE((
  1061. DH_LVL_ERROR,
  1062. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  1063. hr));
  1064. }
  1065. // Commit the Storage
  1066. if(S_OK == hr)
  1067. {
  1068. hr = pvcnRootNewChildStorage->Commit(STGC_DEFAULT);
  1069. }
  1070. if (S_OK == hr)
  1071. {
  1072. DH_TRACE((
  1073. DH_LVL_TRACE1,
  1074. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1075. }
  1076. else
  1077. {
  1078. DH_TRACE((
  1079. DH_LVL_ERROR,
  1080. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1081. hr));
  1082. }
  1083. // Close the IStorage
  1084. if (S_OK == hr)
  1085. {
  1086. hr = pvcnRootNewChildStorage->Close();
  1087. }
  1088. if (S_OK == hr)
  1089. {
  1090. DH_TRACE((
  1091. DH_LVL_TRACE1,
  1092. TEXT("VirtualCtrNode::Close completed successfully.")));
  1093. }
  1094. else
  1095. {
  1096. DH_TRACE((
  1097. DH_LVL_ERROR,
  1098. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  1099. hr));
  1100. }
  1101. // ----------- flatfile change ---------------
  1102. }
  1103. // ----------- flatfile change ---------------
  1104. // Generate a random name for child IStream
  1105. if(S_OK == hr)
  1106. {
  1107. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  1108. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1109. }
  1110. if (S_OK == hr)
  1111. {
  1112. // Generate random size for stream.
  1113. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  1114. if (DG_RC_SUCCESS != usErr)
  1115. {
  1116. hr = E_FAIL;
  1117. }
  1118. }
  1119. // Adds a new stream to the root storage.
  1120. if(S_OK == hr)
  1121. {
  1122. hr = AddStream(
  1123. pTestVirtualDF,
  1124. pVirtualDFRoot,
  1125. pRootNewChildStmName,
  1126. cb,
  1127. STGM_READWRITE |
  1128. STGM_SHARE_EXCLUSIVE,
  1129. &pvsnRootNewChildStream);
  1130. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1131. }
  1132. if(S_OK == hr)
  1133. {
  1134. DH_TRACE((
  1135. DH_LVL_TRACE1,
  1136. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1137. }
  1138. else
  1139. {
  1140. DH_TRACE((
  1141. DH_LVL_ERROR,
  1142. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx."),
  1143. hr));
  1144. }
  1145. // Close the IStream
  1146. if (S_OK == hr)
  1147. {
  1148. hr = pvsnRootNewChildStream->Close();
  1149. }
  1150. if (S_OK == hr)
  1151. {
  1152. DH_TRACE((
  1153. DH_LVL_TRACE1,
  1154. TEXT("VirtualStmNode::Close completed successfully.")));
  1155. }
  1156. else
  1157. {
  1158. DH_TRACE((
  1159. DH_LVL_ERROR,
  1160. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  1161. hr));
  1162. }
  1163. // Commit the Root DocFile
  1164. if(S_OK == hr)
  1165. {
  1166. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1167. }
  1168. if (S_OK == hr)
  1169. {
  1170. DH_TRACE((
  1171. DH_LVL_TRACE1,
  1172. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1173. }
  1174. else
  1175. {
  1176. DH_TRACE((
  1177. DH_LVL_ERROR,
  1178. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1179. hr));
  1180. }
  1181. // ----------- flatfile change ---------------
  1182. if(!StorageIsFlat())
  1183. {
  1184. // ----------- flatfile change ---------------
  1185. // Attempt to create another Child IStorage with same name as existing
  1186. // IStorage above and STGM_FAILIFTHERE flag.
  1187. if(S_OK == hr)
  1188. {
  1189. // This call should fail with STG_E_FILEALREADYEXISTS error.
  1190. hr = AddStorage(
  1191. pTestVirtualDF,
  1192. pVirtualDFRoot,
  1193. pRootNewChildStgName,
  1194. pTestChanceDF->GetStgMode()|
  1195. STGM_FAILIFTHERE,
  1196. &pvcnRootSecondChildStorage);
  1197. if(STG_E_FILEALREADYEXISTS == hr)
  1198. {
  1199. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1200. hr = S_OK;
  1201. }
  1202. else
  1203. {
  1204. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1205. if(S_OK == hr)
  1206. {
  1207. hr = S_FALSE;
  1208. }
  1209. }
  1210. }
  1211. // Attempt to create another Child IStorage with same name as existing
  1212. // IStream above and STGM_FAILIFTHERE flag.
  1213. if(S_OK == hr)
  1214. {
  1215. // This call should fail with STG_E_FILEALREADYEXISTS error.
  1216. hr = AddStorage(
  1217. pTestVirtualDF,
  1218. pVirtualDFRoot,
  1219. pRootNewChildStmName,
  1220. pTestChanceDF->GetStgMode()|
  1221. STGM_FAILIFTHERE,
  1222. &pvcnRootSecondChildStorage);
  1223. if(STG_E_FILEALREADYEXISTS == hr)
  1224. {
  1225. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1226. hr = S_OK;
  1227. }
  1228. else
  1229. {
  1230. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1231. if(S_OK == hr)
  1232. {
  1233. hr = S_FALSE;
  1234. }
  1235. }
  1236. }
  1237. // Attempt to create another Child IStorage with same name as existing
  1238. // IStorage above and STGM_CREATE flag.
  1239. if(S_OK == hr)
  1240. {
  1241. // This call should pass.
  1242. hr = AddStorage(
  1243. pTestVirtualDF,
  1244. pVirtualDFRoot,
  1245. pRootNewChildStgName,
  1246. pTestChanceDF->GetStgMode()|
  1247. STGM_CREATE,
  1248. &pvcnRootSecondChildStorage);
  1249. if(S_OK == hr)
  1250. {
  1251. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1252. }
  1253. else
  1254. {
  1255. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1256. }
  1257. }
  1258. // Commit the above Storage
  1259. if(S_OK == hr)
  1260. {
  1261. hr = pvcnRootSecondChildStorage->Commit(STGC_DEFAULT);
  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_ERROR,
  1272. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  1273. hr));
  1274. }
  1275. }
  1276. // Now with the above IStorage created and instantiated, attempt to create
  1277. // another Child IStorage with same name as above which is both existing
  1278. // and instantiated. Should give STG_E_ACCESSDENIED error.
  1279. if(S_OK == hr)
  1280. {
  1281. // This call should give STG_E_ACCESSDENIED error.
  1282. hr = AddStorage(
  1283. pTestVirtualDF,
  1284. pVirtualDFRoot,
  1285. pRootNewChildStgName,
  1286. pTestChanceDF->GetStgMode()|
  1287. STGM_FAILIFTHERE,
  1288. &pvcnRootThirdChildStorage);
  1289. if(STG_E_ACCESSDENIED == hr)
  1290. {
  1291. DH_TRACE((DH_LVL_ERROR, TEXT("hr = 0x%lx received as expected."), hr));
  1292. hr = S_OK;
  1293. }
  1294. else
  1295. {
  1296. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1297. if(S_OK == hr)
  1298. {
  1299. hr = S_FALSE;
  1300. }
  1301. }
  1302. }
  1303. // Close the pvcnRootSecondChildStorage which is instantiated.
  1304. if (S_OK == hr)
  1305. {
  1306. hr = pvcnRootSecondChildStorage->Close();
  1307. if (S_OK == hr)
  1308. {
  1309. DH_TRACE((
  1310. DH_LVL_TRACE1,
  1311. TEXT("VirtualCtrNode::Close completed successfully.")));
  1312. }
  1313. else
  1314. {
  1315. DH_TRACE((
  1316. DH_LVL_ERROR,
  1317. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  1318. hr));
  1319. }
  1320. }
  1321. // ----------- flatfile change ---------------
  1322. }
  1323. // ----------- flatfile change ---------------
  1324. // Repeat the above with streams
  1325. // Attempt to create another Child IStream with same name as existing
  1326. // IStream above and STGM_FAILIFTHERE flag.
  1327. if(S_OK == hr)
  1328. {
  1329. // This call should fail with STG_E_FILEALREADYEXISTS error.
  1330. hr = AddStream(
  1331. pTestVirtualDF,
  1332. pVirtualDFRoot,
  1333. pRootNewChildStmName,
  1334. cb,
  1335. STGM_READWRITE |
  1336. STGM_SHARE_EXCLUSIVE|
  1337. STGM_FAILIFTHERE,
  1338. &pvcnRootSecondChildStream);
  1339. if(STG_E_FILEALREADYEXISTS == hr)
  1340. {
  1341. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1342. hr = S_OK;
  1343. }
  1344. else
  1345. {
  1346. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1347. if(S_OK == hr)
  1348. {
  1349. hr = S_FALSE;
  1350. }
  1351. }
  1352. }
  1353. // ----------- flatfile change ---------------
  1354. if(!StorageIsFlat())
  1355. {
  1356. // ----------- flatfile change ---------------
  1357. // Attempt to create another Child IStorage with same name as existing
  1358. // IStream above and STGM_FAILIFTHERE flag.
  1359. if(S_OK == hr)
  1360. {
  1361. // This call should fail with STG_E_FILEALREADYEXISTS error.
  1362. hr = AddStream(
  1363. pTestVirtualDF,
  1364. pVirtualDFRoot,
  1365. pRootNewChildStgName,
  1366. cb,
  1367. STGM_READWRITE |
  1368. STGM_SHARE_EXCLUSIVE|
  1369. STGM_FAILIFTHERE,
  1370. &pvcnRootSecondChildStream);
  1371. if(STG_E_FILEALREADYEXISTS == hr)
  1372. {
  1373. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1374. hr = S_OK;
  1375. }
  1376. else
  1377. {
  1378. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1379. if(S_OK == hr)
  1380. {
  1381. hr = S_FALSE;
  1382. }
  1383. }
  1384. }
  1385. // ----------- flatfile change ---------------
  1386. }
  1387. // ----------- flatfile change ---------------
  1388. // Attempt to create another Child IStorage with same name as existing
  1389. // IStorage above and STGM_CREATE flag.
  1390. if(S_OK == hr)
  1391. {
  1392. // This call should pass.
  1393. hr = AddStream(
  1394. pTestVirtualDF,
  1395. pVirtualDFRoot,
  1396. pRootNewChildStmName,
  1397. cb,
  1398. STGM_READWRITE |
  1399. STGM_SHARE_EXCLUSIVE |
  1400. STGM_CREATE,
  1401. &pvcnRootSecondChildStream);
  1402. if(S_OK == hr)
  1403. {
  1404. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1405. }
  1406. else
  1407. {
  1408. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1409. }
  1410. }
  1411. // Now with the above IStream created and instantiated, attempt to create
  1412. // another Child IStream with same name as above which is both existing
  1413. // and instantiated. Should give STG_E_ACCESSDENIED error.
  1414. if(S_OK == hr)
  1415. {
  1416. // This call should give STG_E_ACCESSDENIED error.
  1417. hr = AddStream(
  1418. pTestVirtualDF,
  1419. pVirtualDFRoot,
  1420. pRootNewChildStmName,
  1421. cb,
  1422. STGM_READWRITE |
  1423. STGM_SHARE_EXCLUSIVE,
  1424. &pvcnRootThirdChildStream);
  1425. if(STG_E_ACCESSDENIED == hr)
  1426. {
  1427. DH_TRACE((DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1428. hr = S_OK;
  1429. }
  1430. else
  1431. {
  1432. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1433. if(S_OK == hr)
  1434. {
  1435. hr = S_FALSE;
  1436. }
  1437. }
  1438. }
  1439. // Close the pvcnRootSecondChildStream which is instantiated.
  1440. if (S_OK == hr)
  1441. {
  1442. hr = pvcnRootSecondChildStream->Close();
  1443. if (S_OK == hr)
  1444. {
  1445. DH_TRACE((
  1446. DH_LVL_TRACE1,
  1447. TEXT("VirtualStmNode::Close completed successfully.")));
  1448. }
  1449. else
  1450. {
  1451. DH_TRACE((
  1452. DH_LVL_ERROR,
  1453. TEXT("VirtualStmNode::Close unsuccessful, hr =0x%lx."),
  1454. hr));
  1455. }
  1456. }
  1457. // Attempt to open a non existing IStorage/IStreams
  1458. // Close the Root DocFile
  1459. if (S_OK == hr)
  1460. {
  1461. hr = pVirtualDFRoot->Close();
  1462. if (S_OK == hr)
  1463. {
  1464. DH_TRACE((
  1465. DH_LVL_TRACE1,
  1466. TEXT("VirtualCtrNode::Close completed successfully.")));
  1467. }
  1468. else
  1469. {
  1470. DH_TRACE((
  1471. DH_LVL_ERROR,
  1472. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  1473. hr));
  1474. }
  1475. }
  1476. // Open the Root DocFile
  1477. if (S_OK == hr)
  1478. {
  1479. hr = pVirtualDFRoot->OpenRoot(
  1480. NULL,
  1481. pTestChanceDF->GetRootMode(),
  1482. NULL,
  1483. 0);
  1484. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  1485. if (S_OK == hr)
  1486. {
  1487. DH_TRACE((
  1488. DH_LVL_TRACE1,
  1489. TEXT("VirtualCtrNode::Open completed successfully.")));
  1490. }
  1491. else
  1492. {
  1493. DH_TRACE((
  1494. DH_LVL_ERROR,
  1495. TEXT("VirtualCtrNode::Open unsuccessful, hr =0x%lx."),
  1496. hr));
  1497. }
  1498. }
  1499. if (S_OK == hr)
  1500. {
  1501. pRootStg = pVirtualDFRoot->GetIStoragePointer();
  1502. DH_ASSERT(NULL != pRootStg);
  1503. }
  1504. // Attempt to open a non existing IStorage. This should give an error
  1505. // STG_E_FILENOTFOUND
  1506. if (S_OK == hr)
  1507. {
  1508. hr = pRootStg->OpenStorage(
  1509. OLESTR("Non-Existing"),
  1510. NULL,
  1511. pTestChanceDF->GetStgMode(),
  1512. NULL,
  1513. 0,
  1514. &pNonExistingStg);
  1515. // ----------- flatfile change ---------------
  1516. if(!StorageIsFlat())
  1517. {
  1518. // ----------- flatfile change ---------------
  1519. if(STG_E_FILENOTFOUND == hr)
  1520. {
  1521. DH_TRACE(( DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1522. hr = S_OK;
  1523. }
  1524. else
  1525. {
  1526. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1527. if(S_OK == hr)
  1528. {
  1529. hr = S_FALSE;
  1530. }
  1531. }
  1532. // ----------- flatfile change ---------------
  1533. }
  1534. else
  1535. {
  1536. if(E_NOTIMPL == hr)
  1537. {
  1538. DH_TRACE(( DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1539. hr = S_OK;
  1540. }
  1541. else
  1542. {
  1543. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1544. if(S_OK == hr)
  1545. {
  1546. hr = S_FALSE;
  1547. }
  1548. }
  1549. }
  1550. // ----------- flatfile change ---------------
  1551. }
  1552. // Attempt to open a non existing IStream. This should give an error
  1553. // STG_E_FILENOTFOUND
  1554. if (S_OK == hr)
  1555. {
  1556. hr = pRootStg->OpenStream(
  1557. OLESTR("Non-Existing"),
  1558. NULL,
  1559. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  1560. 0,
  1561. &pNonExistingStm);
  1562. if(STG_E_FILENOTFOUND == hr)
  1563. {
  1564. DH_TRACE(( DH_LVL_TRACE1, TEXT("hr = 0x%lx received as expected."), hr));
  1565. hr = S_OK;
  1566. }
  1567. else
  1568. {
  1569. DH_TRACE((DH_LVL_ERROR, TEXT("Got unexpected hr = 0x%lx "), hr));
  1570. if(S_OK == hr)
  1571. {
  1572. hr = S_FALSE;
  1573. }
  1574. }
  1575. }
  1576. // Close the Root DocFile Storage
  1577. if (S_OK == hr)
  1578. {
  1579. hr = pVirtualDFRoot->Close();
  1580. if (S_OK == hr)
  1581. {
  1582. DH_TRACE((
  1583. DH_LVL_TRACE1,
  1584. TEXT("VirtualCtrNode::Close completed successfully.")));
  1585. }
  1586. else
  1587. {
  1588. DH_TRACE((
  1589. DH_LVL_ERROR,
  1590. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  1591. hr));
  1592. }
  1593. }
  1594. // if everything goes well, log test as passed else failed.
  1595. if (S_OK == hr)
  1596. {
  1597. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_102 passed.")) );
  1598. }
  1599. else
  1600. {
  1601. DH_LOG((
  1602. LOG_FAIL,
  1603. TEXT("Test variation COMTEST_102 failed, hr =0x%lx."),
  1604. hr) );
  1605. }
  1606. // Cleanup
  1607. CleanupTestDocfile (&pVirtualDFRoot,
  1608. &pTestVirtualDF,
  1609. &pTestChanceDF,
  1610. S_OK == hr);
  1611. // Delete strings
  1612. if(NULL != pRootNewChildStgName)
  1613. {
  1614. delete pRootNewChildStgName;
  1615. pRootNewChildStgName = NULL;
  1616. }
  1617. if(NULL != pRootNewChildStmName)
  1618. {
  1619. delete pRootNewChildStmName;
  1620. pRootNewChildStmName = NULL;
  1621. }
  1622. // Stop logging the test
  1623. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_102 finished")) );
  1624. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1625. return hr;
  1626. }
  1627. //----------------------------------------------------------------------------
  1628. //
  1629. // Test: COMTEST_103
  1630. //
  1631. // Synopsis: Creates an IStream in the root docfile and writes a random number
  1632. // of bytes then releases the IStream. Creates an IStorage in the root
  1633. // docfile and an IStream inside of the IStorage. A random number of
  1634. // bytes are written to the IStream, the IStream is released, and the
  1635. // IStorage and root docfile are committed. The IStream in the IStorage
  1636. // is instantiated and the data is read and verified. The IStorage and
  1637. // contained IStream are released. The IStream in the root docfile is
  1638. // instantiated and the data is read and verified. The IStream and
  1639. // root docfile are then released.
  1640. //
  1641. // Arguments: [argc]
  1642. // [argv]
  1643. //
  1644. // Returns: HRESULT
  1645. //
  1646. // History: 29-May-1996 NarindK Created.
  1647. //
  1648. // Notes: This test runs in direct, transacted, and transacted deny write
  1649. // modes
  1650. //
  1651. // New Test Notes:
  1652. // 1. Old File: LINORM.CXX
  1653. // 2. Old name of test : LegitInstEnumNormal Test
  1654. // New Name of test : COMTEST_103
  1655. // 3. To run the test, do the following at command prompt.
  1656. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-103
  1657. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1658. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-103
  1659. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1660. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-103
  1661. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1662. //
  1663. // Conversion: COMTEST_103
  1664. //
  1665. // BUGBUG: Use Random Commit modes
  1666. //-----------------------------------------------------------------------------
  1667. HRESULT COMTEST_103(int argc, char *argv[])
  1668. {
  1669. HRESULT hr = S_OK;
  1670. ChanceDF *pTestChanceDF = NULL;
  1671. VirtualDF *pTestVirtualDF = NULL;
  1672. VirtualCtrNode *pVirtualDFRoot = NULL;
  1673. DG_INTEGER *pdgi = NULL;
  1674. DG_STRING *pdgu = NULL;
  1675. USHORT usErr = 0;
  1676. VirtualStmNode *pvsnRootNewChildStream = NULL;
  1677. LPTSTR pNewRootStmName = NULL;
  1678. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  1679. LPTSTR pRootNewChildStgName = NULL;
  1680. VirtualStmNode *pvsnNewChildStream = NULL;
  1681. LPTSTR pNewChildStmName = NULL;
  1682. LPTSTR pwcsBuffer = NULL;
  1683. ULONG culWritten = 0;
  1684. ULONG cb = 0;
  1685. ULONG cRandomMinSize = 10;
  1686. ULONG cRandomMaxSize = 100;
  1687. BOOL fPass = TRUE;
  1688. DWCRCSTM dwCRC1;
  1689. DWCRCSTM dwMemCRC1;
  1690. DWCRCSTM dwCRC2;
  1691. DWCRCSTM dwMemCRC2;
  1692. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("LINORM_1"));
  1693. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1694. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_103 started.")) );
  1695. // Initialize CRC values to zero
  1696. dwCRC1.dwCRCSum=dwCRC2.dwCRCSum=dwMemCRC1.dwCRCSum=dwMemCRC2.dwCRCSum=0;
  1697. // Create our ChanceDF and VirtualDF
  1698. hr = CreateTestDocfile (argc,
  1699. argv,
  1700. &pVirtualDFRoot,
  1701. &pTestVirtualDF,
  1702. &pTestChanceDF);
  1703. // if creating the docfile - bail here
  1704. if (NULL != pTestChanceDF && DoingCreate ())
  1705. {
  1706. UINT ulSeed = pTestChanceDF->GetSeed ();
  1707. CleanupTestDocfile (&pVirtualDFRoot,
  1708. &pTestVirtualDF,
  1709. &pTestChanceDF,
  1710. FALSE);
  1711. return (HRESULT)ulSeed;
  1712. }
  1713. if (S_OK == hr)
  1714. {
  1715. DH_TRACE((
  1716. DH_LVL_TRACE1,
  1717. TEXT("Run Mode for COMTEST_103, Access mode: %lx"),
  1718. pTestChanceDF->GetRootMode()));
  1719. }
  1720. // Get DG_STRING object pointer
  1721. if (S_OK == hr)
  1722. {
  1723. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1724. DH_ASSERT(NULL != pdgu);
  1725. }
  1726. // Get DG_INTEGER object pointer
  1727. if (S_OK == hr)
  1728. {
  1729. pdgi = pTestVirtualDF->GetDataGenInteger();
  1730. DH_ASSERT(NULL != pdgi);
  1731. }
  1732. // Adds a new stream to a root storage.
  1733. if (S_OK == hr)
  1734. {
  1735. // Generate random size for stream.
  1736. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  1737. if (DG_RC_SUCCESS != usErr)
  1738. {
  1739. hr = E_FAIL;
  1740. }
  1741. }
  1742. // Generate a random name for Root's child IStream
  1743. if(S_OK == hr)
  1744. {
  1745. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &pNewRootStmName);
  1746. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1747. }
  1748. if(S_OK == hr)
  1749. {
  1750. hr = AddStream(
  1751. pTestVirtualDF,
  1752. pVirtualDFRoot,
  1753. pNewRootStmName,
  1754. cb,
  1755. STGM_READWRITE |
  1756. STGM_SHARE_EXCLUSIVE |
  1757. STGM_FAILIFTHERE,
  1758. &pvsnRootNewChildStream);
  1759. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1760. }
  1761. if(S_OK == hr)
  1762. {
  1763. DH_TRACE((
  1764. DH_LVL_TRACE1,
  1765. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1766. }
  1767. else
  1768. {
  1769. DH_TRACE((
  1770. DH_LVL_ERROR,
  1771. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx."),
  1772. hr));
  1773. }
  1774. // Call VirtualStmNode::Write to create random bytes in the stream. For
  1775. // our test purposes, we generate a random string of size cb using
  1776. // GenerateRandomString function.
  1777. if(S_OK == hr)
  1778. {
  1779. hr = GenerateRandomString(pdgu, cb, cb, &pwcsBuffer);
  1780. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  1781. }
  1782. if (S_OK == hr)
  1783. {
  1784. hr = pvsnRootNewChildStream->Write(
  1785. pwcsBuffer,
  1786. cb,
  1787. &culWritten);
  1788. }
  1789. if (S_OK == hr)
  1790. {
  1791. DH_TRACE((
  1792. DH_LVL_TRACE1,
  1793. TEXT("IStream::Write function completed successfully.")));
  1794. }
  1795. else
  1796. {
  1797. DH_TRACE((
  1798. DH_LVL_ERROR,
  1799. TEXT("IStream::Write function wasn't successful, hr =0x%lx."),
  1800. hr));
  1801. }
  1802. // Calculate the CRC for stream name and data
  1803. if(S_OK == hr)
  1804. {
  1805. hr = CalculateInMemoryCRCForStm(
  1806. pvsnRootNewChildStream,
  1807. pwcsBuffer,
  1808. cb,
  1809. &dwMemCRC1);
  1810. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm")) ;
  1811. }
  1812. // Close the stream
  1813. if (S_OK == hr)
  1814. {
  1815. hr = pvsnRootNewChildStream->Close();
  1816. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  1817. }
  1818. if (S_OK == hr)
  1819. {
  1820. DH_TRACE((
  1821. DH_LVL_TRACE1,
  1822. TEXT("VirtualStmNode::Close completed successfully.")));
  1823. }
  1824. else
  1825. {
  1826. DH_TRACE((
  1827. DH_LVL_ERROR,
  1828. TEXT("VirtualStmNode::Close unsuccessful, hr =0x%lx."),
  1829. hr));
  1830. }
  1831. if(NULL != pwcsBuffer)
  1832. {
  1833. delete pwcsBuffer;
  1834. pwcsBuffer = NULL;
  1835. }
  1836. // ----------- flatfile change ---------------
  1837. if(!StorageIsFlat())
  1838. {
  1839. // ----------- flatfile change ---------------
  1840. // Generate a random name for Root's child IStorage
  1841. if(S_OK == hr)
  1842. {
  1843. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  1844. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1845. }
  1846. // Adds a new storage to the root.
  1847. if(S_OK == hr)
  1848. {
  1849. hr = AddStorage(
  1850. pTestVirtualDF,
  1851. pVirtualDFRoot,
  1852. pRootNewChildStgName,
  1853. pTestChanceDF->GetStgMode() |
  1854. STGM_CREATE |
  1855. STGM_FAILIFTHERE,
  1856. &pvcnRootNewChildStorage);
  1857. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1858. }
  1859. if(S_OK == hr)
  1860. {
  1861. DH_TRACE((
  1862. DH_LVL_TRACE1,
  1863. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  1864. }
  1865. else
  1866. {
  1867. DH_TRACE((
  1868. DH_LVL_ERROR,
  1869. TEXT("VirtualCtrNode::AddStorage not successful, hr =0x%lx."),
  1870. hr));
  1871. }
  1872. // Adds a new stream to the new storage. We would add a stream to
  1873. // newly created substorage "NewTestStg" of our root storage for test.
  1874. if (S_OK == hr)
  1875. {
  1876. // Generate random size for stream.
  1877. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  1878. if (DG_RC_SUCCESS != usErr)
  1879. {
  1880. hr = E_FAIL;
  1881. }
  1882. }
  1883. // Generate a random name for Root's child IStorage's new child IStream
  1884. if(S_OK == hr)
  1885. {
  1886. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &pNewChildStmName);
  1887. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1888. }
  1889. if(S_OK == hr)
  1890. {
  1891. hr = AddStream(
  1892. pTestVirtualDF,
  1893. pvcnRootNewChildStorage,
  1894. pNewChildStmName,
  1895. cb,
  1896. STGM_READWRITE |
  1897. STGM_SHARE_EXCLUSIVE |
  1898. STGM_FAILIFTHERE,
  1899. &pvsnNewChildStream);
  1900. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1901. }
  1902. if(S_OK == hr)
  1903. {
  1904. DH_TRACE((
  1905. DH_LVL_TRACE1,
  1906. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1907. }
  1908. else
  1909. {
  1910. DH_TRACE((
  1911. DH_LVL_ERROR,
  1912. TEXT("VirtualStmNode::AddStream not successful, hr =0x%lx."),
  1913. hr));
  1914. }
  1915. if(S_OK == hr)
  1916. {
  1917. hr = GenerateRandomString(pdgu, cb, cb, &pwcsBuffer);
  1918. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  1919. }
  1920. // Write into new stream
  1921. if (S_OK == hr)
  1922. {
  1923. hr = pvsnNewChildStream->Write(
  1924. pwcsBuffer,
  1925. cb,
  1926. &culWritten);
  1927. }
  1928. if (S_OK == hr)
  1929. {
  1930. DH_TRACE((
  1931. DH_LVL_TRACE1,
  1932. TEXT("IStream::Write function completed successfully.")));
  1933. }
  1934. else
  1935. {
  1936. DH_TRACE((
  1937. DH_LVL_ERROR,
  1938. TEXT("IStream::Write function wasn't successful, hr =0x%lx."),
  1939. hr));
  1940. }
  1941. // Calculate the CRC for stream name and data
  1942. if(S_OK == hr)
  1943. {
  1944. hr = CalculateInMemoryCRCForStm(
  1945. pvsnNewChildStream,
  1946. pwcsBuffer,
  1947. cb,
  1948. &dwMemCRC2);
  1949. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm")) ;
  1950. }
  1951. // Close the stream
  1952. if (S_OK == hr)
  1953. {
  1954. hr = pvsnNewChildStream->Close();
  1955. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  1956. }
  1957. if (S_OK == hr)
  1958. {
  1959. DH_TRACE((
  1960. DH_LVL_TRACE1,
  1961. TEXT("VirtualStmNode::Close completed successfully.")));
  1962. }
  1963. else
  1964. {
  1965. DH_TRACE((
  1966. DH_LVL_ERROR,
  1967. TEXT("VirtualStmNode::Close unsuccessful, hr =0x%lx."),
  1968. hr));
  1969. }
  1970. if (S_OK == hr)
  1971. {
  1972. hr = pvcnRootNewChildStorage->Commit(STGC_DEFAULT);
  1973. }
  1974. if (S_OK == hr)
  1975. {
  1976. DH_TRACE((
  1977. DH_LVL_TRACE1,
  1978. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1979. }
  1980. else
  1981. {
  1982. DH_TRACE((
  1983. DH_LVL_ERROR,
  1984. TEXT("VirtualCtrNode::Commit unsuccessful, hr =0x%lx."),
  1985. hr));
  1986. }
  1987. if (S_OK == hr)
  1988. {
  1989. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1990. }
  1991. if (S_OK == hr)
  1992. {
  1993. DH_TRACE((
  1994. DH_LVL_TRACE1,
  1995. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1996. }
  1997. else
  1998. {
  1999. DH_TRACE((
  2000. DH_LVL_ERROR,
  2001. TEXT("VirtualCtrNode::Commit unsuccessful, hr =0x%lx."),
  2002. hr));
  2003. }
  2004. if (S_OK == hr)
  2005. {
  2006. hr = pvcnRootNewChildStorage->Close();
  2007. }
  2008. if (S_OK == hr)
  2009. {
  2010. DH_TRACE((
  2011. DH_LVL_TRACE1,
  2012. TEXT("VirtualCtrNode::Close completed successfully.")));
  2013. }
  2014. else
  2015. {
  2016. DH_TRACE((
  2017. DH_LVL_ERROR,
  2018. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  2019. hr));
  2020. }
  2021. if (S_OK == hr)
  2022. {
  2023. hr = pvcnRootNewChildStorage->Open(
  2024. NULL,
  2025. pTestChanceDF->GetStgMode(),
  2026. NULL,
  2027. 0);
  2028. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2029. }
  2030. if (S_OK == hr)
  2031. {
  2032. DH_TRACE((
  2033. DH_LVL_TRACE1,
  2034. TEXT("VirtualCtrNode::Open completed successfully.")));
  2035. }
  2036. else
  2037. {
  2038. DH_TRACE((
  2039. DH_LVL_ERROR,
  2040. TEXT("VirtualCtrNode::Open unsuccessful, hr =0x%lx."),
  2041. hr));
  2042. }
  2043. if (S_OK == hr)
  2044. {
  2045. hr = pvsnNewChildStream->Open(
  2046. NULL,
  2047. STGM_READWRITE |
  2048. STGM_SHARE_EXCLUSIVE ,
  2049. 0);
  2050. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  2051. }
  2052. if (S_OK == hr)
  2053. {
  2054. DH_TRACE((
  2055. DH_LVL_TRACE1,
  2056. TEXT("VirtualStmNode::Open completed successfully.")));
  2057. }
  2058. else
  2059. {
  2060. DH_TRACE((
  2061. DH_LVL_ERROR,
  2062. TEXT("VirtualStmNode::Open unsuccessful, hr =0x%lx."),
  2063. hr));
  2064. }
  2065. if(S_OK == hr)
  2066. {
  2067. hr = ReadAndCalculateDiskCRCForStm(pvsnNewChildStream,&dwCRC2);
  2068. }
  2069. if (S_OK == hr)
  2070. {
  2071. DH_TRACE((
  2072. DH_LVL_TRACE1,
  2073. TEXT("ReadAndCalculateDiskCRCForStm function successful.")));
  2074. if(dwCRC2.dwCRCSum == dwMemCRC2.dwCRCSum)
  2075. {
  2076. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's for pvsnNewChildStream match.")));
  2077. }
  2078. else
  2079. {
  2080. DH_TRACE((
  2081. DH_LVL_ERROR,
  2082. TEXT("CRC's for pvsnNewChildStream don't match.")));
  2083. fPass = FALSE;
  2084. }
  2085. }
  2086. else
  2087. {
  2088. DH_TRACE((
  2089. DH_LVL_ERROR,
  2090. TEXT("ReadAndCalculateDiskCRCForStm unsuccessful, hr =0x%lx."),
  2091. hr));
  2092. }
  2093. // Close the stream
  2094. if (S_OK == hr)
  2095. {
  2096. hr = pvsnNewChildStream->Close();
  2097. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  2098. }
  2099. if (S_OK == hr)
  2100. {
  2101. DH_TRACE((
  2102. DH_LVL_TRACE1,
  2103. TEXT("VirtualStmNode::Close completed successfully.")));
  2104. }
  2105. else
  2106. {
  2107. DH_TRACE((
  2108. DH_LVL_ERROR,
  2109. TEXT("VirtualStmNode::Close unsuccessful, hr =0x%lx."),
  2110. hr));
  2111. }
  2112. // Close the storage
  2113. if (S_OK == hr)
  2114. {
  2115. hr = pvcnRootNewChildStorage->Close();
  2116. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2117. }
  2118. if (S_OK == hr)
  2119. {
  2120. DH_TRACE((
  2121. DH_LVL_TRACE1,
  2122. TEXT("VirtualCtrNode::Close completed successfully.")));
  2123. }
  2124. else
  2125. {
  2126. DH_TRACE((
  2127. DH_LVL_ERROR,
  2128. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  2129. hr));
  2130. }
  2131. // ----------- flatfile change ---------------
  2132. }
  2133. // ----------- flatfile change ---------------
  2134. if (S_OK == hr)
  2135. {
  2136. hr = pvsnRootNewChildStream->Open(
  2137. NULL,
  2138. STGM_READWRITE |
  2139. STGM_SHARE_EXCLUSIVE ,
  2140. 0);
  2141. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  2142. }
  2143. if (S_OK == hr)
  2144. {
  2145. DH_TRACE((
  2146. DH_LVL_TRACE1,
  2147. TEXT("VirtualStmNode::Open completed successfully.")));
  2148. }
  2149. else
  2150. {
  2151. DH_TRACE((
  2152. DH_LVL_ERROR,
  2153. TEXT("VirtualStmNode::Open unsuccessful, hr =0x%lx."),
  2154. hr));
  2155. }
  2156. // Read and verify
  2157. if(S_OK == hr)
  2158. {
  2159. hr = ReadAndCalculateDiskCRCForStm(pvsnRootNewChildStream,&dwCRC1);
  2160. }
  2161. // Compare this CRC with in memory CRC
  2162. if(S_OK == hr)
  2163. {
  2164. DH_TRACE((
  2165. DH_LVL_TRACE1,
  2166. TEXT("ReadAndCalculateDiskCRCForStm function successful.")));
  2167. if(dwCRC1.dwCRCSum == dwMemCRC1.dwCRCSum)
  2168. {
  2169. DH_TRACE((
  2170. DH_LVL_TRACE1,
  2171. TEXT("CRC's for pvsnRootNewChildStream match.")));
  2172. }
  2173. else
  2174. {
  2175. fPass = FALSE;
  2176. DH_TRACE((
  2177. DH_LVL_ERROR,
  2178. TEXT("CRC's for pvsnRootNewChildStream do not match.")));
  2179. }
  2180. }
  2181. else
  2182. {
  2183. DH_TRACE((
  2184. DH_LVL_ERROR,
  2185. TEXT("ReadAndCalculateDiskCRCForStm unsuccessful, hr =0x%lx."),
  2186. hr));
  2187. }
  2188. // Close the stream
  2189. if (S_OK == hr)
  2190. {
  2191. hr = pvsnRootNewChildStream->Close();
  2192. DH_HRCHECK(hr, TEXT("VirtualStmNode::Close")) ;
  2193. }
  2194. if (S_OK == hr)
  2195. {
  2196. DH_TRACE((
  2197. DH_LVL_TRACE1,
  2198. TEXT("VirtualStmNode::Close completed successfully.")));
  2199. }
  2200. else
  2201. {
  2202. DH_TRACE((
  2203. DH_LVL_ERROR,
  2204. TEXT("VirtualStmNode::Close unsuccessful, hr =0x%lx."),
  2205. hr));
  2206. }
  2207. // Close the storage
  2208. if (S_OK == hr)
  2209. {
  2210. hr = pVirtualDFRoot->Close();
  2211. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2212. }
  2213. if (S_OK == hr)
  2214. {
  2215. DH_TRACE((
  2216. DH_LVL_TRACE1,
  2217. TEXT("VirtualCtrNode::Close completed successfully.")));
  2218. }
  2219. else
  2220. {
  2221. DH_TRACE((
  2222. DH_LVL_ERROR,
  2223. TEXT("VirtualCtrNode::Close unsuccessful, hr =0x%lx."),
  2224. hr));
  2225. }
  2226. // if all goes well till here, the test variation has passed successfully,
  2227. // if not, then report failure.
  2228. if ((S_OK == hr) && (TRUE == fPass))
  2229. {
  2230. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_103 passed.")) );
  2231. }
  2232. else
  2233. {
  2234. DH_LOG((
  2235. LOG_FAIL,
  2236. TEXT("Test variation COMTEST_103 failed, hr =0x%lx."),
  2237. hr) );
  2238. // test failed. make sure it failed.
  2239. hr = FirstError (hr, E_FAIL);
  2240. }
  2241. // Cleanup
  2242. CleanupTestDocfile (&pVirtualDFRoot,
  2243. &pTestVirtualDF,
  2244. &pTestChanceDF,
  2245. S_OK == hr);
  2246. //Free buffer
  2247. if(NULL != pwcsBuffer)
  2248. {
  2249. delete pwcsBuffer;
  2250. pwcsBuffer = NULL;
  2251. }
  2252. // Delete strings
  2253. if(NULL != pRootNewChildStgName)
  2254. {
  2255. delete pRootNewChildStgName;
  2256. pRootNewChildStgName = NULL;
  2257. }
  2258. if(NULL != pNewRootStmName)
  2259. {
  2260. delete pNewRootStmName;
  2261. pNewRootStmName = NULL;
  2262. }
  2263. if(NULL != pNewChildStmName)
  2264. {
  2265. delete pNewChildStmName;
  2266. pNewChildStmName = NULL;
  2267. }
  2268. // Stop logging the test
  2269. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST-103 finished")) );
  2270. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2271. return hr;
  2272. }
  2273. //----------------------------------------------------------------------------
  2274. //
  2275. // Test: COMTEST_104
  2276. //
  2277. // Synopsis:Create a root docfile with a child IStorage and a child IStream.
  2278. // Commit the root docfile.
  2279. //
  2280. // Call QueryInterface on IID_IStorage created for IStorage and see if
  2281. // succeeded to verify OLE COM Reflexive behaviour. Then through
  2282. // the interface obtained, query for IID_Imarshal from which query
  2283. // for IUnknown and from that query for IID_IStorage. This should
  2284. // pass verifying the Transitive behaiour of IStorage COM interface.
  2285. // Repeat for the child IStream.
  2286. //
  2287. // Arguments: [argc]
  2288. // [argv]
  2289. //
  2290. // Returns: HRESULT
  2291. //
  2292. // History: 8-Aug-1996 NarindK Created.
  2293. //
  2294. // Notes: This test runs in direct, transacted, and transacted deny write
  2295. // modes
  2296. //
  2297. // New Test Notes:
  2298. // 1. Old File: STORAGE.CXX very briefly
  2299. // 2. Old name of test : ISTORAGE_TEST very briefly
  2300. // New Name of test : COMTEST_104
  2301. // 3. To run the test, do the following at command prompt.
  2302. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-104
  2303. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  2304. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-104
  2305. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  2306. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-104
  2307. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  2308. //
  2309. // Conversion: COMTEST_104 NO. BUGBUG:IRootStg not supported by NSS yet. maybe later?
  2310. //
  2311. //-----------------------------------------------------------------------------
  2312. HRESULT COMTEST_104(int argc, char *argv[])
  2313. {
  2314. HRESULT hr = S_OK;
  2315. ChanceDF *pTestChanceDF = NULL;
  2316. VirtualDF *pTestVirtualDF = NULL;
  2317. VirtualCtrNode *pVirtualDFRoot = NULL;
  2318. DG_STRING *pdgu = NULL;
  2319. DG_INTEGER *pdgi = NULL;
  2320. USHORT usErr = 0;
  2321. VirtualStmNode *pvsnRootNewChildStream = NULL;
  2322. LPTSTR pRootNewChildStmName = NULL;
  2323. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  2324. LPTSTR pRootNewChildStgName = NULL;
  2325. ULONG cb = 0;
  2326. ULONG cRandomMinSize = 10;
  2327. ULONG cRandomMaxSize = 100;
  2328. ULONG ulRef = 0;
  2329. LPSTORAGE pQueryChildStorage = NULL;
  2330. LPSTORAGE pQueryMarshalStorage = NULL;
  2331. LPSTORAGE pQueryUnknownStorage = NULL;
  2332. LPSTORAGE pQueryRetChildStorage = NULL;
  2333. LPSTREAM pQueryChildStream = NULL;
  2334. LPSTREAM pQueryRetChildStream = NULL;
  2335. LPSTREAM pQueryMarshalStream = NULL;
  2336. LPSTREAM pQueryUnknownStream = NULL;
  2337. // Not for 2phase. Bail.
  2338. if (DoingDistrib ())
  2339. {
  2340. return S_OK;
  2341. }
  2342. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_104"));
  2343. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2344. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_104 started.")) );
  2345. DH_TRACE((DH_LVL_TRACE1, TEXT("QueryInterface tests on IStorage/IStream")) );
  2346. // Create our ChanceDF and VirtualDF
  2347. hr = CreateTestDocfile (argc,
  2348. argv,
  2349. &pVirtualDFRoot,
  2350. &pTestVirtualDF,
  2351. &pTestChanceDF);
  2352. // if creating the docfile - bail here
  2353. if (NULL != pTestChanceDF && DoingCreate ())
  2354. {
  2355. UINT ulSeed = pTestChanceDF->GetSeed ();
  2356. CleanupTestDocfile (&pVirtualDFRoot,
  2357. &pTestVirtualDF,
  2358. &pTestChanceDF,
  2359. FALSE);
  2360. return (HRESULT)ulSeed;
  2361. }
  2362. if (S_OK == hr)
  2363. {
  2364. DH_TRACE((
  2365. DH_LVL_TRACE1,
  2366. TEXT("Run Mode for COMTEST_104, Access mode: %lx"),
  2367. pTestChanceDF->GetRootMode()));
  2368. }
  2369. // Get DG_STRING object pointer
  2370. if (S_OK == hr)
  2371. {
  2372. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2373. DH_ASSERT(NULL != pdgu);
  2374. }
  2375. // Get DG_INTEGER object pointer
  2376. if (S_OK == hr)
  2377. {
  2378. pdgi = pTestVirtualDF->GetDataGenInteger();
  2379. DH_ASSERT(NULL != pdgi);
  2380. }
  2381. // ----------- flatfile change ---------------
  2382. if(!StorageIsFlat())
  2383. {
  2384. // ----------- flatfile change ---------------
  2385. // Generate a random name for child IStorage
  2386. if(S_OK == hr)
  2387. {
  2388. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  2389. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2390. }
  2391. // Adds a new storage to the root storage.
  2392. if(S_OK == hr)
  2393. {
  2394. hr = AddStorage(
  2395. pTestVirtualDF,
  2396. pVirtualDFRoot,
  2397. pRootNewChildStgName,
  2398. pTestChanceDF->GetStgMode()|
  2399. STGM_CREATE |
  2400. STGM_FAILIFTHERE,
  2401. &pvcnRootNewChildStorage);
  2402. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  2403. }
  2404. if(S_OK == hr)
  2405. {
  2406. DH_TRACE((
  2407. DH_LVL_TRACE1,
  2408. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  2409. }
  2410. else
  2411. {
  2412. DH_TRACE((
  2413. DH_LVL_ERROR,
  2414. TEXT("VirtualCtrNode::AddStorage not successful, hr = 0x%lx."),
  2415. hr));
  2416. }
  2417. // ----------- flatfile change ---------------
  2418. }
  2419. // ----------- flatfile change ---------------
  2420. // Adds a new stream to the root storage.
  2421. if(S_OK == hr)
  2422. {
  2423. // Generate random name for stream
  2424. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  2425. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2426. }
  2427. if (S_OK == hr)
  2428. {
  2429. // Generate random size for stream.
  2430. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  2431. if (DG_RC_SUCCESS != usErr)
  2432. {
  2433. hr = E_FAIL;
  2434. }
  2435. }
  2436. if(S_OK == hr)
  2437. {
  2438. hr = AddStream(
  2439. pTestVirtualDF,
  2440. pVirtualDFRoot,
  2441. pRootNewChildStmName,
  2442. cb,
  2443. STGM_READWRITE |
  2444. STGM_SHARE_EXCLUSIVE |
  2445. STGM_FAILIFTHERE,
  2446. &pvsnRootNewChildStream);
  2447. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2448. }
  2449. if(S_OK == hr)
  2450. {
  2451. DH_TRACE((
  2452. DH_LVL_TRACE1,
  2453. TEXT("VirtualStmNode::AddStream completed successfully.")));
  2454. }
  2455. else
  2456. {
  2457. DH_TRACE((
  2458. DH_LVL_ERROR,
  2459. TEXT("VirtualStmNode::AddStream not successful, hr = 0x%lx."),
  2460. hr));
  2461. }
  2462. // Commit the root storage.
  2463. if(S_OK == hr)
  2464. {
  2465. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2466. }
  2467. if (S_OK == hr)
  2468. {
  2469. DH_TRACE((
  2470. DH_LVL_TRACE1,
  2471. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2472. }
  2473. else
  2474. {
  2475. DH_TRACE((
  2476. DH_LVL_ERROR,
  2477. TEXT("VirtualCtrNode::Commit unsuccessful, hr = 0x%lx."),
  2478. hr));
  2479. }
  2480. // ----------- flatfile change ---------------
  2481. if(!StorageIsFlat())
  2482. {
  2483. // ----------- flatfile change ---------------
  2484. // Check Reflexive/Transitive behaviour for IStorage Interface
  2485. // Do QueryInterface on child storage
  2486. if(S_OK == hr)
  2487. {
  2488. hr = pvcnRootNewChildStorage->QueryInterface(
  2489. IID_IStorage,
  2490. (LPVOID *) &pQueryChildStorage);
  2491. DH_HRCHECK(hr, TEXT("VirtualCtrNode::QueryInterface")) ;
  2492. }
  2493. if (S_OK == hr)
  2494. {
  2495. DH_ASSERT(NULL != pQueryChildStorage);
  2496. DH_TRACE((
  2497. DH_LVL_TRACE1,
  2498. TEXT("VirtualCtrNode::QueryInterface completed successfully.")));
  2499. }
  2500. else
  2501. {
  2502. DH_TRACE((
  2503. DH_LVL_ERROR,
  2504. TEXT("VirtualCtrNode::QueryInterface unsuccessful, hr = 0x%lx."),
  2505. hr));
  2506. }
  2507. // Query for IRootStorage from the above returned storage pointer, then
  2508. // query through IRootStorage for IID_IUnknown. From IUnknown, query for
  2509. // IID_IStorage
  2510. if(S_OK == hr)
  2511. {
  2512. hr = pQueryChildStorage->QueryInterface(
  2513. IID_IMarshal,
  2514. (LPVOID *) &pQueryMarshalStorage );
  2515. }
  2516. if (S_OK == hr)
  2517. {
  2518. DH_ASSERT(NULL != pQueryMarshalStorage);
  2519. DH_TRACE((
  2520. DH_LVL_TRACE1,
  2521. TEXT("IStorage::QueryInterface completed successfully.")));
  2522. }
  2523. else
  2524. {
  2525. DH_TRACE((
  2526. DH_LVL_ERROR,
  2527. TEXT("IStorage::QueryInterface unsuccessful, hr = 0x%lx."),
  2528. hr));
  2529. }
  2530. // Use the IMarshal interface to QueryInterface an IUnknown
  2531. // interface.
  2532. if(S_OK == hr)
  2533. {
  2534. hr = pQueryMarshalStorage->QueryInterface(
  2535. IID_IUnknown,
  2536. (LPVOID *) &pQueryUnknownStorage );
  2537. }
  2538. // Use the IUnknown interface to QueryInterface an IStorage interface.
  2539. if(S_OK == hr)
  2540. {
  2541. DH_ASSERT(NULL != pQueryUnknownStorage);
  2542. hr = pQueryUnknownStorage->QueryInterface(
  2543. IID_IStorage,
  2544. (LPVOID *) &pQueryRetChildStorage );
  2545. }
  2546. if (S_OK == hr)
  2547. {
  2548. DH_TRACE((
  2549. DH_LVL_TRACE1,
  2550. TEXT("IStorage:Reflexive/Transitive OLE COM behaviour passed.")));
  2551. }
  2552. else
  2553. {
  2554. DH_TRACE((
  2555. DH_LVL_ERROR,
  2556. TEXT("IStorage:Reflexive/Transitive COM behaviour fail,hr=0x%lx"),
  2557. hr));
  2558. }
  2559. // ----------- flatfile change ---------------
  2560. }
  2561. // ----------- flatfile change ---------------
  2562. // Check Reflexive/Transitive behaviour for IStream Interface
  2563. // Do QueryInterface on child stream
  2564. if(S_OK == hr)
  2565. {
  2566. hr = pvsnRootNewChildStream->QueryInterface(
  2567. IID_IStream,
  2568. (LPVOID *) &pQueryChildStream);
  2569. DH_HRCHECK(hr, TEXT("VirtualStmNode::QueryInterface")) ;
  2570. }
  2571. if (S_OK == hr)
  2572. {
  2573. DH_TRACE((
  2574. DH_LVL_TRACE1,
  2575. TEXT("VirtualStmNode::QueryInterface completed successfully.")));
  2576. }
  2577. else
  2578. {
  2579. DH_TRACE((
  2580. DH_LVL_ERROR,
  2581. TEXT("VirtualStmNode::QueryInterface unsuccessful, hr = 0x%lx."),
  2582. hr));
  2583. }
  2584. // Query for IMarshal from the above returned storage pointer, then
  2585. // query through IRootStream for IID_IUnknown. From IUnknown, query for
  2586. // IID_IStream
  2587. // --------- flatfile change ---------------
  2588. if(!StorageIsFlat())
  2589. {
  2590. // --------- flatfile change ---------------
  2591. if(S_OK == hr)
  2592. {
  2593. hr = pQueryChildStream->QueryInterface(
  2594. IID_IMarshal,
  2595. (LPVOID *) &pQueryMarshalStream );
  2596. }
  2597. if (S_OK == hr)
  2598. {
  2599. DH_ASSERT(NULL != pQueryMarshalStream);
  2600. DH_TRACE((
  2601. DH_LVL_TRACE1,
  2602. TEXT("IStream::QueryInterface completed successfully.")));
  2603. }
  2604. else
  2605. {
  2606. DH_TRACE((
  2607. DH_LVL_ERROR,
  2608. TEXT("IStream::QueryInterface unsuccessful, hr = 0x%lx."),
  2609. hr));
  2610. }
  2611. // --------- flatfile change ---------------
  2612. }
  2613. else
  2614. if(S_OK == hr)
  2615. {
  2616. hr = pQueryChildStream->QueryInterface(
  2617. IID_IStream,
  2618. (LPVOID *) &pQueryMarshalStream );
  2619. }
  2620. if (S_OK == hr)
  2621. {
  2622. DH_ASSERT(NULL != pQueryMarshalStream);
  2623. DH_TRACE((
  2624. DH_LVL_TRACE1,
  2625. TEXT("IStream::QueryInterface completed successfully.")));
  2626. }
  2627. else
  2628. {
  2629. DH_TRACE((
  2630. DH_LVL_ERROR,
  2631. TEXT("IStream::QueryInterface unsuccessful, hr = 0x%lx."),
  2632. hr));
  2633. }
  2634. // --------- flatfile change ---------------
  2635. // Use the IRootStream interface to QueryInterface an IUnknown
  2636. // interface.
  2637. if(S_OK == hr)
  2638. {
  2639. hr = pQueryMarshalStream->QueryInterface(
  2640. IID_IUnknown,
  2641. (LPVOID *) &pQueryUnknownStream );
  2642. }
  2643. // Use the IUnknown interface to QueryInterface an IStream interface.
  2644. if(S_OK == hr)
  2645. {
  2646. DH_ASSERT(NULL != pQueryUnknownStream);
  2647. hr = pQueryUnknownStream->QueryInterface(
  2648. IID_IStream,
  2649. (LPVOID *) &pQueryRetChildStream );
  2650. }
  2651. if (S_OK == hr)
  2652. {
  2653. DH_TRACE((
  2654. DH_LVL_TRACE1,
  2655. TEXT("IStream:Reflexive/Transitive OLE COM behaviour passed.")));
  2656. }
  2657. else
  2658. {
  2659. DH_TRACE((
  2660. DH_LVL_ERROR,
  2661. TEXT("IStream:Reflexive/Transitive COM behaviour fail, hr=0x%lx"),
  2662. hr));
  2663. }
  2664. // Clean up
  2665. if(NULL != pQueryChildStorage)
  2666. {
  2667. ulRef = pQueryChildStorage->Release();
  2668. DH_ASSERT(4 == ulRef);
  2669. pQueryChildStorage = NULL;
  2670. }
  2671. if(NULL != pQueryMarshalStorage)
  2672. {
  2673. ulRef = pQueryMarshalStorage->Release();
  2674. DH_ASSERT(3 == ulRef);
  2675. pQueryMarshalStorage = NULL;
  2676. }
  2677. if(NULL != pQueryUnknownStorage)
  2678. {
  2679. ulRef = pQueryUnknownStorage->Release();
  2680. DH_ASSERT(2 == ulRef);
  2681. pQueryUnknownStorage = NULL;
  2682. }
  2683. if(NULL != pQueryRetChildStorage)
  2684. {
  2685. ulRef = pQueryRetChildStorage->Release();
  2686. DH_ASSERT(1 == ulRef);
  2687. pQueryRetChildStorage = NULL;
  2688. }
  2689. if(NULL != pQueryChildStream)
  2690. {
  2691. ulRef = pQueryChildStream->Release();
  2692. DH_ASSERT(4 == ulRef);
  2693. pQueryChildStream = NULL;
  2694. }
  2695. if(NULL != pQueryMarshalStream)
  2696. {
  2697. ulRef = pQueryMarshalStream->Release();
  2698. DH_ASSERT(3 == ulRef);
  2699. pQueryMarshalStream = NULL;
  2700. }
  2701. if(NULL != pQueryUnknownStream)
  2702. {
  2703. ulRef = pQueryUnknownStream->Release();
  2704. DH_ASSERT(2 == ulRef);
  2705. pQueryUnknownStream = NULL;
  2706. }
  2707. if(NULL != pQueryRetChildStream)
  2708. {
  2709. ulRef = pQueryRetChildStream->Release();
  2710. DH_ASSERT(1 == ulRef);
  2711. pQueryRetChildStream = NULL;
  2712. }
  2713. // --------- flatfile change ---------------
  2714. if(!StorageIsFlat())
  2715. {
  2716. // --------- flatfile change ---------------
  2717. // Close the child storage
  2718. if (S_OK == hr)
  2719. {
  2720. hr = pvcnRootNewChildStorage->Close();
  2721. }
  2722. if (S_OK == hr)
  2723. {
  2724. DH_TRACE((
  2725. DH_LVL_TRACE1,
  2726. TEXT("VirtualCtrNode::Close completed successfully.")));
  2727. }
  2728. else
  2729. {
  2730. DH_TRACE((
  2731. DH_LVL_ERROR,
  2732. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  2733. hr));
  2734. }
  2735. // --------- flatfile change ---------------
  2736. }
  2737. // --------- flatfile change ---------------
  2738. // Close the child stream
  2739. if (S_OK == hr)
  2740. {
  2741. hr = pvsnRootNewChildStream->Close();
  2742. }
  2743. if (S_OK == hr)
  2744. {
  2745. DH_TRACE((
  2746. DH_LVL_TRACE1,
  2747. TEXT("VirtualStmNode::Close completed successfully.")));
  2748. }
  2749. else
  2750. {
  2751. DH_TRACE((
  2752. DH_LVL_ERROR,
  2753. TEXT("VirtualStmNode::Close unsuccessful, hr = 0x%lx."),
  2754. hr));
  2755. }
  2756. // Close the root
  2757. if (S_OK == hr)
  2758. {
  2759. hr = pVirtualDFRoot->Close();
  2760. }
  2761. if (S_OK == hr)
  2762. {
  2763. DH_TRACE((
  2764. DH_LVL_TRACE1,
  2765. TEXT("VirtualCtrNode::Close completed successfully.")));
  2766. }
  2767. else
  2768. {
  2769. DH_TRACE((
  2770. DH_LVL_ERROR,
  2771. TEXT("VirtualCtrNode::Close unsuccessful, hr = 0x%lx."),
  2772. hr));
  2773. }
  2774. // if everything goes well, log test as passed else failed.
  2775. if (S_OK == hr)
  2776. {
  2777. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_104 passed.")) );
  2778. }
  2779. else
  2780. {
  2781. DH_LOG((
  2782. LOG_FAIL,
  2783. TEXT("Test variation COMTEST_104 failed, hr = 0x%lx."),
  2784. hr) );
  2785. }
  2786. // Cleanup
  2787. CleanupTestDocfile (&pVirtualDFRoot,
  2788. &pTestVirtualDF,
  2789. &pTestChanceDF,
  2790. S_OK == hr);
  2791. // Delete strings
  2792. if(NULL != pRootNewChildStgName)
  2793. {
  2794. delete pRootNewChildStgName;
  2795. pRootNewChildStgName = NULL;
  2796. }
  2797. if(NULL != pRootNewChildStmName)
  2798. {
  2799. delete pRootNewChildStmName;
  2800. pRootNewChildStmName = NULL;
  2801. }
  2802. // Stop logging the test
  2803. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_104 finished")) );
  2804. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2805. return hr;
  2806. }
  2807. //----------------------------------------------------------------------------
  2808. //
  2809. // Test: COMTEST-105
  2810. //
  2811. // Synopsis: A root docfile with a child storage and a child stream is created,
  2812. // then check if Read/WriteClassStg and Read/WriteClassStm APIs work
  2813. // correctly as expected. Also have some illegitmate tests by passing
  2814. // invalid arguments to these APIs.
  2815. //
  2816. // Arguments:[argc]
  2817. // [argv]
  2818. //
  2819. // Returns: HRESULT
  2820. //
  2821. // Notes: This test runs in direct, transacted, and transacted deny write
  2822. // modes
  2823. //
  2824. // History: 15-Aug-1996 JiminLi Created.
  2825. //
  2826. // To run the test, do the following at command prompt.
  2827. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-105
  2828. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  2829. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-105
  2830. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  2831. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-105
  2832. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  2833. //
  2834. // Conversion: COMTEST_105
  2835. //
  2836. //-----------------------------------------------------------------------------
  2837. HRESULT COMTEST_105(int argc, char *argv[])
  2838. {
  2839. HRESULT hr = S_OK;
  2840. ChanceDF *pTestChanceDF = NULL;
  2841. VirtualDF *pTestVirtualDF = NULL;
  2842. VirtualCtrNode *pVirtualDFRoot = NULL;
  2843. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  2844. VirtualStmNode *pvsnRootNewChildStm = NULL;
  2845. LPTSTR pRootNewChildStgName = NULL;
  2846. DG_STRING *pdgu = NULL;
  2847. DG_INTEGER *pdgi = NULL;
  2848. LPSTORAGE pRootStg = NULL;
  2849. LPSTORAGE pChildStg = NULL;
  2850. LPSTREAM pChildStm = NULL;
  2851. USHORT usErr = 0;
  2852. LPTSTR ptszStreamName = NULL;
  2853. DWORD dwRootMode = 0;
  2854. DWORD dwStgMode = 0;
  2855. BOOL fPass = TRUE;
  2856. ULONG culWritten = 0;
  2857. ULONG ulPosition = 0;
  2858. STATSTG statStg;
  2859. STATSTG statStm;
  2860. LARGE_INTEGER liZero;
  2861. LARGE_INTEGER liStreamPos;
  2862. ULARGE_INTEGER uli;
  2863. GUID TEST_CLSID = { 0x9c6e9ed0,
  2864. 0xf701,
  2865. 0x11cf,
  2866. { 0x98,
  2867. 0x44,
  2868. 0x00,
  2869. 0xa0,
  2870. 0xc9,
  2871. 0x08,
  2872. 0xe4,
  2873. 0x6d }};
  2874. CLSID pclsid;
  2875. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_105"));
  2876. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2877. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_105 started.")) );
  2878. DH_TRACE((
  2879. DH_LVL_TRACE1,
  2880. TEXT("Attempt legit and illegit tests on Read/WriteClassStg/Stm ")));
  2881. pclsid = TEST_CLSID;
  2882. // Create our ChanceDF and VirtualDF
  2883. hr = CreateTestDocfile (argc,
  2884. argv,
  2885. &pVirtualDFRoot,
  2886. &pTestVirtualDF,
  2887. &pTestChanceDF);
  2888. // if creating the docfile - bail here
  2889. if (NULL != pTestChanceDF && DoingCreate ())
  2890. {
  2891. UINT ulSeed = pTestChanceDF->GetSeed ();
  2892. CleanupTestDocfile (&pVirtualDFRoot,
  2893. &pTestVirtualDF,
  2894. &pTestChanceDF,
  2895. FALSE);
  2896. return (HRESULT)ulSeed;
  2897. }
  2898. if (S_OK == hr)
  2899. {
  2900. pRootStg = pVirtualDFRoot->GetIStoragePointer();
  2901. dwRootMode = pTestChanceDF->GetRootMode();
  2902. dwStgMode = pTestChanceDF->GetStgMode();
  2903. DH_TRACE((
  2904. DH_LVL_TRACE1,
  2905. TEXT("Run Mode for COMTEST_105, Access mode: %lx"),
  2906. dwRootMode));
  2907. }
  2908. // Get DG_STRING object pointer
  2909. if (S_OK == hr)
  2910. {
  2911. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2912. DH_ASSERT(NULL != pdgu) ;
  2913. }
  2914. // Get DG_INTEGER object pointer
  2915. if (S_OK == hr)
  2916. {
  2917. pdgi = pTestVirtualDF->GetDataGenInteger();
  2918. DH_ASSERT(NULL != pdgi) ;
  2919. }
  2920. // Adds a new storage to the root storage.
  2921. if(S_OK == hr)
  2922. {
  2923. // Generate random name for storage
  2924. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  2925. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2926. }
  2927. // --------- flatfile change ---------------
  2928. if(!StorageIsFlat())
  2929. {
  2930. // --------- flatfile change ---------------
  2931. if(S_OK == hr)
  2932. {
  2933. hr = AddStorage(
  2934. pTestVirtualDF,
  2935. pVirtualDFRoot,
  2936. pRootNewChildStgName,
  2937. dwStgMode,
  2938. &pvcnRootNewChildStg);
  2939. pChildStg = pvcnRootNewChildStg->GetIStoragePointer();
  2940. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  2941. }
  2942. if(S_OK == hr)
  2943. {
  2944. DH_TRACE((
  2945. DH_LVL_TRACE1,
  2946. TEXT("AddStorage completed successfully.")));
  2947. }
  2948. else
  2949. {
  2950. DH_TRACE((
  2951. DH_LVL_ERROR,
  2952. TEXT("AddStorage not successful, hr=0x%lx."),
  2953. hr));
  2954. }
  2955. // --------- flatfile change ---------------
  2956. }
  2957. // --------- flatfile change ---------------
  2958. // Add a child stream under root storage
  2959. if(S_OK == hr)
  2960. {
  2961. // Generate random name for stream
  2962. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszStreamName);
  2963. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2964. }
  2965. if(S_OK == hr)
  2966. {
  2967. hr = AddStream(
  2968. pTestVirtualDF,
  2969. pVirtualDFRoot,
  2970. ptszStreamName,
  2971. 0,
  2972. STGM_READWRITE |
  2973. STGM_SHARE_EXCLUSIVE |
  2974. STGM_FAILIFTHERE,
  2975. &pvsnRootNewChildStm);
  2976. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2977. }
  2978. if(S_OK == hr && NULL != pvsnRootNewChildStm)
  2979. {
  2980. pChildStm = pvsnRootNewChildStm->GetIStreamPointer();
  2981. }
  2982. if(S_OK == hr)
  2983. {
  2984. DH_TRACE((
  2985. DH_LVL_TRACE1,
  2986. TEXT("VirtualStmNode::AddStream completed successfully.")));
  2987. }
  2988. else
  2989. {
  2990. DH_TRACE((
  2991. DH_LVL_ERROR,
  2992. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  2993. hr));
  2994. }
  2995. // Write a random stream to the stream, in order to test
  2996. // ReadClassStm later.
  2997. if(S_OK == hr)
  2998. {
  2999. hr = pvsnRootNewChildStm->Write(
  3000. ptszStreamName,
  3001. _tcslen(ptszStreamName),
  3002. &culWritten);
  3003. DH_HRCHECK(hr, TEXT("IStream::Write")) ;
  3004. }
  3005. // Legit tests of Read/WriteClassStg on the root storage
  3006. // First call Stat on root storage and check the CLSID of it.
  3007. if (S_OK == hr)
  3008. {
  3009. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  3010. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  3011. }
  3012. if (S_OK != hr)
  3013. {
  3014. DH_TRACE((
  3015. DH_LVL_ERROR,
  3016. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  3017. hr));
  3018. }
  3019. if ((S_OK == hr) && (IsEqualCLSID(statStg.clsid, CLSID_NULL)))
  3020. {
  3021. DH_TRACE((
  3022. DH_LVL_TRACE1,
  3023. TEXT("Root DocFile has CLSID_NULL as expected.")));
  3024. }
  3025. else
  3026. {
  3027. DH_TRACE((
  3028. DH_LVL_ERROR,
  3029. TEXT("Root DocFile doesn't have CLSID_NULL unexpectedly.")));
  3030. fPass = FALSE;
  3031. }
  3032. // Then call ReadClassStg to see if this API work correctly
  3033. if (S_OK == hr)
  3034. {
  3035. hr = ReadClassStg(pRootStg, &pclsid);
  3036. }
  3037. if ((S_OK == hr) && (IsEqualCLSID(pclsid, CLSID_NULL)))
  3038. {
  3039. DH_TRACE((
  3040. DH_LVL_TRACE1,
  3041. TEXT("ReadClassStg returns CLSID_NULL as expected.")));
  3042. }
  3043. else
  3044. {
  3045. DH_TRACE((
  3046. DH_LVL_ERROR,
  3047. TEXT("ReadClassStg not return CLSID_NULL as expected. hr=0x%lx"),
  3048. hr));
  3049. fPass = FALSE;
  3050. }
  3051. // Now write the new CLSID into the root storage object
  3052. if (S_OK == hr)
  3053. {
  3054. hr = WriteClassStg(pRootStg, TEST_CLSID);
  3055. DH_HRCHECK(hr, TEXT("WriteClassStg"));
  3056. }
  3057. // Call Stat again to check if the above WriteClassStg and the next
  3058. // ReadClassStg work correctly
  3059. if (S_OK == hr)
  3060. {
  3061. hr = pVirtualDFRoot->Stat(&statStg, STATFLAG_NONAME);
  3062. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  3063. }
  3064. if (S_OK != hr)
  3065. {
  3066. DH_TRACE((
  3067. DH_LVL_ERROR,
  3068. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  3069. hr));
  3070. }
  3071. if ((S_OK == hr) && (IsEqualCLSID(statStg.clsid, TEST_CLSID)))
  3072. {
  3073. DH_TRACE((
  3074. DH_LVL_TRACE1,
  3075. TEXT("Root DocFile has TEST_CLSID as expected.")));
  3076. }
  3077. else
  3078. {
  3079. DH_TRACE((
  3080. DH_LVL_ERROR,
  3081. TEXT("Root DocFile doesn't have TEST_CLSID unexpectedly.")));
  3082. fPass = FALSE;
  3083. }
  3084. if (S_OK == hr)
  3085. {
  3086. hr = ReadClassStg(pRootStg, &pclsid);
  3087. }
  3088. if ((S_OK == hr) && (IsEqualCLSID(pclsid, TEST_CLSID)))
  3089. {
  3090. DH_TRACE((
  3091. DH_LVL_TRACE1,
  3092. TEXT("ReadClassStg returns TEST_CLSID as expected.")));
  3093. }
  3094. else
  3095. {
  3096. DH_TRACE((
  3097. DH_LVL_ERROR,
  3098. TEXT("ReadClassStg not return TEST_CLSID as expected. hr=0x%lx"),
  3099. hr));
  3100. fPass = FALSE;
  3101. }
  3102. // --------- flatfile change ---------------
  3103. if(!StorageIsFlat())
  3104. {
  3105. // --------- flatfile change ---------------
  3106. // Legit tests of Set/GetConvertStg on the child storage
  3107. // First call Stat on root storage and check the CLSID of it.
  3108. if (S_OK == hr)
  3109. {
  3110. hr = pvcnRootNewChildStg->Stat(&statStg, STATFLAG_NONAME);
  3111. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  3112. }
  3113. if (S_OK != hr)
  3114. {
  3115. DH_TRACE((
  3116. DH_LVL_ERROR,
  3117. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  3118. hr));
  3119. }
  3120. if ((S_OK == hr) && (IsEqualCLSID(statStg.clsid, CLSID_NULL)))
  3121. {
  3122. DH_TRACE((
  3123. DH_LVL_TRACE1,
  3124. TEXT("Child Storage has CLSID_NULL as expected.")));
  3125. }
  3126. else
  3127. {
  3128. DH_TRACE((
  3129. DH_LVL_ERROR,
  3130. TEXT("Child Storage doesn't have CLSID_NULL unexpectedly.")));
  3131. fPass = FALSE;
  3132. }
  3133. // Then call ReadClassStg to see if this API work correctly
  3134. if (S_OK == hr)
  3135. {
  3136. hr = ReadClassStg(pChildStg, &pclsid);
  3137. }
  3138. if ((S_OK == hr) && (IsEqualCLSID(pclsid, CLSID_NULL)))
  3139. {
  3140. DH_TRACE((
  3141. DH_LVL_TRACE1,
  3142. TEXT("ReadClassStg returns CLSID_NULL as expected.")));
  3143. }
  3144. else
  3145. {
  3146. DH_TRACE((
  3147. DH_LVL_ERROR,
  3148. TEXT("ReadClassStg not return CLSID_NULL as expected. hr=0x%lx"),
  3149. hr));
  3150. fPass = FALSE;
  3151. }
  3152. // Now write the new CLSID into the child storage object
  3153. if (S_OK == hr)
  3154. {
  3155. hr = WriteClassStg(pChildStg, TEST_CLSID);
  3156. DH_HRCHECK(hr, TEXT("WriteClassStg"));
  3157. }
  3158. // Call Stat again to check if the above WriteClassStg and the next
  3159. // ReadClassStg work correctly
  3160. if (S_OK == hr)
  3161. {
  3162. hr = pvcnRootNewChildStg->Stat(&statStg, STATFLAG_NONAME);
  3163. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Stat")) ;
  3164. }
  3165. if (S_OK != hr)
  3166. {
  3167. DH_TRACE((
  3168. DH_LVL_ERROR,
  3169. TEXT("VirtualCtrNode::Stat unsuccessful, hr=0x%lx."),
  3170. hr));
  3171. }
  3172. if ((S_OK == hr) && (IsEqualCLSID(statStg.clsid, TEST_CLSID)))
  3173. {
  3174. DH_TRACE((
  3175. DH_LVL_TRACE1,
  3176. TEXT("Child Storage has TEST_CLSID as expected.")));
  3177. }
  3178. else
  3179. {
  3180. DH_TRACE((
  3181. DH_LVL_ERROR,
  3182. TEXT("Child Storage doesn't have TEST_CLSID unexpectedly.")));
  3183. fPass = FALSE;
  3184. }
  3185. if (S_OK == hr)
  3186. {
  3187. hr = ReadClassStg(pChildStg, &pclsid);
  3188. }
  3189. if ((S_OK == hr) && (IsEqualCLSID(pclsid, TEST_CLSID)))
  3190. {
  3191. DH_TRACE((
  3192. DH_LVL_TRACE1,
  3193. TEXT("ReadClassStg returns TEST_CLSID as expected.")));
  3194. }
  3195. else
  3196. {
  3197. DH_TRACE((
  3198. DH_LVL_ERROR,
  3199. TEXT("ReadClassStg not return TEST_CLSID as expected. hr=0x%lx"),
  3200. hr));
  3201. fPass = FALSE;
  3202. }
  3203. // --------- flatfile change ---------------
  3204. }
  3205. // --------- flatfile change ---------------
  3206. // Illegit tests
  3207. // Pass NULL as IStorage pointer, it should fail
  3208. #ifdef _MAC
  3209. DH_TRACE((
  3210. DH_LVL_ERROR,
  3211. TEXT("!!!!!!!!!!!!!!!!Invalid param testing skipped"),
  3212. hr));
  3213. #else
  3214. if (S_OK == hr)
  3215. {
  3216. hr = WriteClassStg(NULL, TEST_CLSID);
  3217. }
  3218. if (E_INVALIDARG == hr)
  3219. {
  3220. hr = S_OK;
  3221. }
  3222. else
  3223. {
  3224. DH_TRACE((
  3225. DH_LVL_ERROR,
  3226. TEXT("WriteClassStg did not return as expected, hr=0x%lx"),
  3227. hr));
  3228. fPass = FALSE;
  3229. }
  3230. if (S_OK == hr)
  3231. {
  3232. hr = ReadClassStg(NULL, &pclsid);
  3233. }
  3234. if (E_INVALIDARG == hr)
  3235. {
  3236. hr = S_OK;
  3237. }
  3238. else
  3239. {
  3240. DH_TRACE((
  3241. DH_LVL_ERROR,
  3242. TEXT("ReadClassStg did not return as expected, hr=0x%lx"),
  3243. hr));
  3244. fPass = FALSE;
  3245. }
  3246. #endif //_MAC
  3247. // Legit tests of Set/GetConvertStg on the child stream
  3248. // First call Stat on child stream and check the CLSID of it.
  3249. if (S_OK == hr)
  3250. {
  3251. hr = pvsnRootNewChildStm->Stat(&statStm, STATFLAG_NONAME);
  3252. DH_HRCHECK(hr, TEXT("VirtualStmNode::Stat")) ;
  3253. }
  3254. if (S_OK != hr)
  3255. {
  3256. DH_TRACE((
  3257. DH_LVL_ERROR,
  3258. TEXT("VirtualStmNode::Stat unsuccessful, hr=0x%lx."),
  3259. hr));
  3260. }
  3261. if ((S_OK == hr) && (IsEqualCLSID(statStm.clsid, CLSID_NULL)))
  3262. {
  3263. DH_TRACE((
  3264. DH_LVL_TRACE1,
  3265. TEXT("Child Stream has CLSID_NULL as expected.")));
  3266. }
  3267. else
  3268. {
  3269. DH_TRACE((
  3270. DH_LVL_ERROR,
  3271. TEXT("Child Stream doesn't have CLSID_NULL unexpectedly.")));
  3272. fPass = FALSE;
  3273. }
  3274. // Then call ReadClassStm to see if this API work correctly
  3275. // Since ReadClassStm can only read the CLSID written previously by
  3276. // WriteClassStm, it'll return STG_E_READFAULT in this case.
  3277. if (S_OK == hr)
  3278. {
  3279. hr = ReadClassStm(pChildStm, &pclsid);
  3280. }
  3281. if (STG_E_READFAULT == hr)
  3282. {
  3283. DH_TRACE((
  3284. DH_LVL_TRACE1,
  3285. TEXT("ReadClassStm returns STG_E_READFAULT as expected.")));
  3286. hr = S_OK;
  3287. }
  3288. else
  3289. {
  3290. DH_TRACE((
  3291. DH_LVL_ERROR,
  3292. TEXT("Err: ReadClassStm not return STG_E_READFAULT. hr=0x%lx"),
  3293. hr));
  3294. fPass = FALSE;
  3295. }
  3296. // Get the seek pointer before writing, then retore to this offset
  3297. // when we want to ReadClassStm later.
  3298. if (S_OK == hr)
  3299. {
  3300. LISet32(liZero, 0L);
  3301. hr = pChildStm->Seek(liZero, STREAM_SEEK_CUR, &uli);
  3302. ulPosition = ULIGetLow(uli);
  3303. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3304. }
  3305. // Now write a new CLSID into stream
  3306. if (S_OK == hr)
  3307. {
  3308. hr = WriteClassStm(pChildStm, TEST_CLSID);
  3309. DH_HRCHECK(hr, TEXT("WriteClassStm"));
  3310. }
  3311. // Call Stat again to check if the above WriteClassStm and the next
  3312. // ReadClassStm work correctly
  3313. if (S_OK == hr)
  3314. {
  3315. hr = pvsnRootNewChildStm->Stat(&statStm, STATFLAG_NONAME);
  3316. DH_HRCHECK(hr, TEXT("VirtualStmNode::Stat")) ;
  3317. }
  3318. if (S_OK != hr)
  3319. {
  3320. DH_TRACE((
  3321. DH_LVL_ERROR,
  3322. TEXT("VirtualStmNode::Stat unsuccessful, hr=0x%lx."),
  3323. hr));
  3324. }
  3325. if ((S_OK == hr) && (IsEqualCLSID(statStg.clsid, TEST_CLSID)))
  3326. {
  3327. DH_TRACE((
  3328. DH_LVL_TRACE1,
  3329. TEXT("Child Stream has TEST_CLSID as expected.")));
  3330. }
  3331. else
  3332. {
  3333. DH_TRACE((
  3334. DH_LVL_ERROR,
  3335. TEXT("Child Stream doesn't have TEST_CLSID unexpectedly.")));
  3336. fPass = FALSE;
  3337. }
  3338. // Since ReadClassStm calls pstm->ReadAt(...) but not get CLSID from
  3339. // pstm->Stat, basically it needs correct seek pointer, we need get it.
  3340. if (S_OK == hr)
  3341. {
  3342. LISet32(liStreamPos, ulPosition);
  3343. hr = pChildStm->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  3344. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3345. }
  3346. if (S_OK == hr)
  3347. {
  3348. hr = ReadClassStm(pChildStm, &pclsid);
  3349. }
  3350. if ((S_OK == hr) && (IsEqualCLSID(pclsid, TEST_CLSID)))
  3351. {
  3352. DH_TRACE((
  3353. DH_LVL_TRACE1,
  3354. TEXT("ReadClassStm returns TEST_CLSID as expected.")));
  3355. }
  3356. else
  3357. {
  3358. DH_TRACE((
  3359. DH_LVL_ERROR,
  3360. TEXT("ReadClassStm not return TEST_CLSID as expected. hr=0x%lx"),
  3361. hr));
  3362. fPass = FALSE;
  3363. }
  3364. // Illegit tests
  3365. // Pass NULL as IStream pointer, it should fail
  3366. #ifdef _MAC
  3367. DH_TRACE((
  3368. DH_LVL_ERROR,
  3369. TEXT("!!!!!!!!!!!!!!!!Invalid param testing skipped"),
  3370. hr));
  3371. #else
  3372. if (S_OK == hr)
  3373. {
  3374. hr = WriteClassStm(NULL, TEST_CLSID);
  3375. }
  3376. if (E_INVALIDARG == hr)
  3377. {
  3378. hr = S_OK;
  3379. }
  3380. else
  3381. {
  3382. DH_TRACE((
  3383. DH_LVL_ERROR,
  3384. TEXT("WriteClassStm did not return as expected, hr=0x%lx"),
  3385. hr));
  3386. fPass = FALSE;
  3387. }
  3388. if (S_OK == hr)
  3389. {
  3390. hr = ReadClassStm(NULL, &pclsid);
  3391. }
  3392. if (E_INVALIDARG == hr)
  3393. {
  3394. hr = S_OK;
  3395. }
  3396. else
  3397. {
  3398. DH_TRACE((
  3399. DH_LVL_ERROR,
  3400. TEXT("ReadClassStm did not return as expected, hr = 0x%lx"),
  3401. hr));
  3402. fPass = FALSE;
  3403. }
  3404. #endif //_MAC
  3405. // Commit the root
  3406. if (S_OK == hr)
  3407. {
  3408. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3409. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit"));
  3410. }
  3411. if (S_OK == hr)
  3412. {
  3413. DH_TRACE((
  3414. DH_LVL_TRACE1,
  3415. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3416. }
  3417. else
  3418. {
  3419. DH_TRACE((
  3420. DH_LVL_ERROR,
  3421. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  3422. hr));
  3423. }
  3424. // Release the child stream
  3425. if (S_OK == hr)
  3426. {
  3427. hr = pvsnRootNewChildStm->Close();
  3428. DH_HRCHECK(hr, TEXT("VirutalStmNode::Close"));
  3429. }
  3430. // --------- flatfile change ---------------
  3431. if(!StorageIsFlat())
  3432. {
  3433. // --------- flatfile change ---------------
  3434. // Release child and root storages
  3435. if (S_OK == hr)
  3436. {
  3437. hr = pvcnRootNewChildStg->Close();
  3438. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  3439. }
  3440. if (S_OK == hr)
  3441. {
  3442. DH_TRACE((
  3443. DH_LVL_TRACE1,
  3444. TEXT("VirtualStmNode::Close completed successfully.")));
  3445. }
  3446. else
  3447. {
  3448. DH_TRACE((
  3449. DH_LVL_ERROR,
  3450. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3451. hr));
  3452. }
  3453. // --------- flatfile change ---------------
  3454. }
  3455. // --------- flatfile change ---------------
  3456. if (S_OK == hr)
  3457. {
  3458. hr = pVirtualDFRoot->Close();
  3459. }
  3460. if (S_OK == hr)
  3461. {
  3462. DH_TRACE((
  3463. DH_LVL_TRACE1,
  3464. TEXT("VirtualCtrNode::Close completed successfully.")));
  3465. }
  3466. else
  3467. {
  3468. DH_TRACE((
  3469. DH_LVL_ERROR,
  3470. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3471. hr));
  3472. }
  3473. // if everything goes well, log test as passed else failed.
  3474. if ((S_OK == hr) && (TRUE == fPass))
  3475. {
  3476. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_105 passed.")) );
  3477. }
  3478. else if (4 == NTMAJVER()) //No fix bug in NT4.
  3479. {
  3480. DH_LOG((LOG_FAIL, TEXT("COMTEST_105 failed on NT4. Bug#54738")));
  3481. // test failed. make sure it failed.
  3482. hr = FirstError (hr, E_FAIL);
  3483. }
  3484. else
  3485. {
  3486. DH_LOG((
  3487. LOG_FAIL,
  3488. TEXT("Test variation COMTEST_105 failed, hr = 0x%lx."),
  3489. hr) );
  3490. // test failed. make sure it failed.
  3491. hr = FirstError (hr, E_FAIL);
  3492. }
  3493. // Cleanup
  3494. CleanupTestDocfile (&pVirtualDFRoot,
  3495. &pTestVirtualDF,
  3496. &pTestChanceDF,
  3497. S_OK == hr);
  3498. // Delete temp strings
  3499. if (NULL != pRootNewChildStgName)
  3500. {
  3501. delete []pRootNewChildStgName;
  3502. pRootNewChildStgName = NULL;
  3503. }
  3504. if (NULL != ptszStreamName)
  3505. {
  3506. delete []ptszStreamName;
  3507. ptszStreamName = NULL;
  3508. }
  3509. // Stop logging the test
  3510. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_105 finished")) );
  3511. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3512. return hr;
  3513. }
  3514. //----------------------------------------------------------------------------
  3515. //
  3516. // Test: COMTEST-106
  3517. //
  3518. // Synopsis: Create a root docfile with a child storage and an IStream inside
  3519. // of the child IStorage. Random data is written to the IStream and
  3520. // the CRC is computed for the data. Then commit the child storage,
  3521. // verify the CRC of data, if it is correct, then commit the root
  3522. // storage, and again verify the CRC of data. First round passed in
  3523. // STGC_DEFAULT, then change the IStream data, then repeat the above
  3524. // commit process by passed in STGC_OVERWRITE. Finally, change the
  3525. // IStream data again, repeat the process for commit by passed in
  3526. // STGC_DANGEROUSLYCIMMITMERELYTODISKCACHE.
  3527. //
  3528. // Since transacted tests contain more detail tests about Commit,
  3529. // here just keep it simple in base tests. Also, STGC_ONLYIFCURRENT
  3530. // is not test because it should be used in multiple users
  3531. // environment.
  3532. //
  3533. // Only IStorage::Commit is tested, because IStream::Commit has no
  3534. // effect other than flushing internal memory buffers to the parent
  3535. // storage object. It does not matter if commit changes to streams.
  3536. //
  3537. // Arguments:[argc]
  3538. // [argv]
  3539. //
  3540. // Returns: HRESULT
  3541. //
  3542. // Notes: This test runs in direct, transacted, and transacted deny write
  3543. // modes
  3544. //
  3545. // History: 15-Aug-1996 JiminLi Created.
  3546. //
  3547. // To run the test, do the following at command prompt.
  3548. // a. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-106
  3549. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  3550. // b. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-106
  3551. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3552. // c. stgbase /seed:0 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:COMTEST-106
  3553. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3554. //
  3555. // Conversion: COMTEST_106
  3556. //
  3557. //-----------------------------------------------------------------------------
  3558. HRESULT COMTEST_106(int argc, char *argv[])
  3559. {
  3560. HRESULT hr = S_OK;
  3561. ChanceDF *pTestChanceDF = NULL;
  3562. VirtualDF *pTestVirtualDF = NULL;
  3563. VirtualCtrNode *pVirtualDFRoot = NULL;
  3564. VirtualCtrNode *pvcnRootNewChildStg = NULL;
  3565. VirtualCtrNode *pstgCommitMe = NULL;
  3566. VirtualStmNode *pvsnNewChildStm = NULL;
  3567. LPTSTR pRootNewChildStgName = NULL;
  3568. LPTSTR ptcsBuffer = NULL;
  3569. DG_STRING *pdgu = NULL;
  3570. DG_INTEGER *pdgi = NULL;
  3571. USHORT usErr = 0;
  3572. LPTSTR ptszStreamName = NULL;
  3573. DWORD dwRootMode = 0;
  3574. DWORD dwStgMode = 0;
  3575. DWORD dwOriginalCRC = 0;
  3576. DWORD dwCommitCRC = 0;
  3577. BOOL fRetry = TRUE;
  3578. BOOL fPass = TRUE;
  3579. ULONG culWritten = 0;
  3580. ULONG ulPosition = 0;
  3581. ULONG culRandIOBytes = 0;
  3582. ULONG culRead = 0;
  3583. LARGE_INTEGER liZero;
  3584. ULARGE_INTEGER uliSize;
  3585. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("COMTEST_106"));
  3586. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3587. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_106 started.")) );
  3588. DH_TRACE((
  3589. DH_LVL_TRACE1,
  3590. TEXT("Attempt legit and illegit tests on IStorage::Commit.")));
  3591. // Create our ChanceDF and VirtualDF
  3592. hr = CreateTestDocfile (argc,
  3593. argv,
  3594. &pVirtualDFRoot,
  3595. &pTestVirtualDF,
  3596. &pTestChanceDF);
  3597. // if creating the docfile - bail here
  3598. if (NULL != pTestChanceDF && DoingCreate ())
  3599. {
  3600. UINT ulSeed = pTestChanceDF->GetSeed ();
  3601. CleanupTestDocfile (&pVirtualDFRoot,
  3602. &pTestVirtualDF,
  3603. &pTestChanceDF,
  3604. FALSE);
  3605. return (HRESULT)ulSeed;
  3606. }
  3607. if (S_OK == hr)
  3608. {
  3609. dwRootMode = pTestChanceDF->GetRootMode();
  3610. dwStgMode = pTestChanceDF->GetStgMode();
  3611. DH_TRACE((
  3612. DH_LVL_TRACE1,
  3613. TEXT("Run Mode for COMTEST_106, Access mode: %lx"),
  3614. dwRootMode));
  3615. }
  3616. // Get DG_STRING object pointer
  3617. if (S_OK == hr)
  3618. {
  3619. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3620. DH_ASSERT(NULL != pdgu) ;
  3621. }
  3622. // Get DG_INTEGER object pointer
  3623. if (S_OK == hr)
  3624. {
  3625. pdgi = pTestVirtualDF->GetDataGenInteger();
  3626. DH_ASSERT(NULL != pdgi) ;
  3627. }
  3628. // Adds a new storage to the root storage.
  3629. if(S_OK == hr)
  3630. {
  3631. // Generate random name for storage
  3632. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  3633. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3634. }
  3635. if(S_OK == hr)
  3636. {
  3637. hr = AddStorage(
  3638. pTestVirtualDF,
  3639. pVirtualDFRoot,
  3640. pRootNewChildStgName,
  3641. dwStgMode,
  3642. &pvcnRootNewChildStg);
  3643. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  3644. }
  3645. if(S_OK == hr)
  3646. {
  3647. DH_TRACE((
  3648. DH_LVL_TRACE1,
  3649. TEXT("AddStorage completed successfully.")));
  3650. }
  3651. else
  3652. {
  3653. DH_TRACE((
  3654. DH_LVL_ERROR,
  3655. TEXT("AddStorage not successful, hr=0x%lx."),
  3656. hr));
  3657. }
  3658. // Add a child stream under the child storage
  3659. if(S_OK == hr)
  3660. {
  3661. // Generate random name for stream
  3662. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszStreamName);
  3663. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3664. }
  3665. if(S_OK == hr)
  3666. {
  3667. hr = AddStream(
  3668. pTestVirtualDF,
  3669. pvcnRootNewChildStg,
  3670. ptszStreamName,
  3671. 0,
  3672. STGM_READWRITE |
  3673. STGM_SHARE_EXCLUSIVE |
  3674. STGM_FAILIFTHERE,
  3675. &pvsnNewChildStm);
  3676. DH_HRCHECK(hr, TEXT("AddStream")) ;
  3677. }
  3678. if(S_OK == hr)
  3679. {
  3680. DH_TRACE((
  3681. DH_LVL_TRACE1,
  3682. TEXT("VirtualStmNode::AddStream completed successfully.")));
  3683. }
  3684. else
  3685. {
  3686. DH_TRACE((
  3687. DH_LVL_ERROR,
  3688. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  3689. hr));
  3690. }
  3691. // Generate a random number culRandIOBytes
  3692. if (S_OK == hr)
  3693. {
  3694. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  3695. if (DG_RC_SUCCESS != usErr)
  3696. {
  3697. hr = E_FAIL;
  3698. }
  3699. }
  3700. if (S_OK == hr)
  3701. {
  3702. hr = GenerateRandomString(
  3703. pdgu,
  3704. culRandIOBytes,
  3705. culRandIOBytes,
  3706. &ptcsBuffer);
  3707. DH_HRCHECK(hr, TEXT("GenerateRandomString"));
  3708. }
  3709. if (S_OK == hr)
  3710. {
  3711. hr = pvsnNewChildStm->Write(
  3712. ptcsBuffer,
  3713. culRandIOBytes,
  3714. &culWritten);
  3715. }
  3716. if(S_OK != hr)
  3717. {
  3718. DH_TRACE((
  3719. DH_LVL_TRACE1,
  3720. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  3721. hr));
  3722. }
  3723. // Calculate the CRC for stream data
  3724. if (S_OK == hr)
  3725. {
  3726. hr = CalculateCRCForDataBuffer(
  3727. ptcsBuffer,
  3728. culRandIOBytes,
  3729. &dwOriginalCRC);
  3730. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3731. }
  3732. // Delete temp buffer
  3733. if (NULL != ptcsBuffer)
  3734. {
  3735. delete []ptcsBuffer;
  3736. ptcsBuffer = NULL;
  3737. }
  3738. // Test on STGC_DEFAULT
  3739. pstgCommitMe = pvcnRootNewChildStg;
  3740. while ((S_OK == hr) && (fRetry == TRUE))
  3741. {
  3742. hr = pstgCommitMe->Commit(STGC_DEFAULT);
  3743. if (S_OK == hr)
  3744. {
  3745. // verify IStream data after commit()
  3746. // Allocate a buffer of required size
  3747. ptcsBuffer = new TCHAR [culRandIOBytes];
  3748. if (NULL == ptcsBuffer)
  3749. {
  3750. hr = E_OUTOFMEMORY;
  3751. }
  3752. if (S_OK == hr)
  3753. {
  3754. LISet32(liZero, 0L);
  3755. hr = pvsnNewChildStm->Seek(liZero, STREAM_SEEK_SET, NULL);
  3756. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3757. }
  3758. if (S_OK == hr)
  3759. {
  3760. memset(ptcsBuffer, '\0', culRandIOBytes * sizeof(TCHAR));
  3761. hr = pvsnNewChildStm->Read(
  3762. ptcsBuffer,
  3763. culRandIOBytes,
  3764. &culRead);
  3765. }
  3766. if ((S_OK != hr) || (culRead != culRandIOBytes))
  3767. {
  3768. DH_TRACE((
  3769. DH_LVL_ERROR,
  3770. TEXT("IStream::Read not successful, hr=0x%lx."),
  3771. hr));
  3772. fPass = FALSE;
  3773. }
  3774. // Calculate the CRC for stream data
  3775. if (S_OK == hr)
  3776. {
  3777. hr = CalculateCRCForDataBuffer(
  3778. ptcsBuffer,
  3779. culRandIOBytes,
  3780. &dwCommitCRC);
  3781. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3782. }
  3783. // Compare corresponding dwMemCRC and dwActCRC and verify
  3784. if (S_OK == hr)
  3785. {
  3786. if (dwOriginalCRC != dwCommitCRC)
  3787. {
  3788. DH_TRACE((
  3789. DH_LVL_ERROR,
  3790. TEXT("CRC's before/after commit unmatch.")));
  3791. fPass = FALSE;
  3792. }
  3793. }
  3794. // Delete temp buffer
  3795. if (NULL != ptcsBuffer)
  3796. {
  3797. delete []ptcsBuffer;
  3798. ptcsBuffer = NULL;
  3799. }
  3800. // if child storage just commited ok, stay in loop and now
  3801. // commit root, otherwise set flag to terminate loop
  3802. if ((fPass == TRUE) && (pstgCommitMe == pvcnRootNewChildStg))
  3803. {
  3804. pstgCommitMe = pVirtualDFRoot;
  3805. }
  3806. else
  3807. {
  3808. fRetry = FALSE;
  3809. }
  3810. }
  3811. else
  3812. {
  3813. DH_TRACE((
  3814. DH_LVL_ERROR,
  3815. TEXT("VirtualCtrNode::Commit failed. hr = 0x%lx"),
  3816. hr));
  3817. break;
  3818. }
  3819. }
  3820. // Now make some changes on IStream data, re-set the stream size to
  3821. // a new random size, then seek from beginning and rewrite the stream
  3822. // data of the new size, and CRC it.
  3823. // Generate a random number culRandIOBytes
  3824. if (S_OK == hr)
  3825. {
  3826. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  3827. if (DG_RC_SUCCESS != usErr)
  3828. {
  3829. hr = E_FAIL;
  3830. }
  3831. }
  3832. if (S_OK == hr)
  3833. {
  3834. hr = GenerateRandomString(
  3835. pdgu,
  3836. culRandIOBytes,
  3837. culRandIOBytes,
  3838. &ptcsBuffer);
  3839. DH_HRCHECK(hr, TEXT("GenerateRandomString"));
  3840. }
  3841. if (S_OK == hr)
  3842. {
  3843. ULISet32(uliSize, culRandIOBytes);
  3844. hr = pvsnNewChildStm->SetSize(uliSize);
  3845. DH_HRCHECK(hr, TEXT("VirtualStmNode::SetSize"));
  3846. }
  3847. if (S_OK == hr)
  3848. {
  3849. LISet32(liZero, 0L);
  3850. hr = pvsnNewChildStm->Seek(liZero, STREAM_SEEK_SET, NULL);
  3851. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3852. }
  3853. if (S_OK == hr)
  3854. {
  3855. hr = pvsnNewChildStm->Write(
  3856. ptcsBuffer,
  3857. culRandIOBytes,
  3858. &culWritten);
  3859. }
  3860. if(S_OK != hr)
  3861. {
  3862. DH_TRACE((
  3863. DH_LVL_ERROR,
  3864. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  3865. hr));
  3866. }
  3867. // Calculate the CRC for stream data
  3868. if (S_OK == hr)
  3869. {
  3870. hr = CalculateCRCForDataBuffer(
  3871. ptcsBuffer,
  3872. culRandIOBytes,
  3873. &dwOriginalCRC);
  3874. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3875. }
  3876. // Delete temp buffer
  3877. if (NULL != ptcsBuffer)
  3878. {
  3879. delete []ptcsBuffer;
  3880. ptcsBuffer = NULL;
  3881. }
  3882. // Test on STGC_OVERWRITE
  3883. pstgCommitMe = pvcnRootNewChildStg;
  3884. while ((S_OK == hr) && (fRetry == TRUE))
  3885. {
  3886. hr = pstgCommitMe->Commit(STGC_OVERWRITE);
  3887. if (S_OK == hr)
  3888. {
  3889. // verify IStream data after commit()
  3890. // Allocate a buffer of required size
  3891. ptcsBuffer = new TCHAR [culRandIOBytes];
  3892. if (NULL == ptcsBuffer)
  3893. {
  3894. hr = E_OUTOFMEMORY;
  3895. }
  3896. if (S_OK == hr)
  3897. {
  3898. LISet32(liZero, 0L);
  3899. hr = pvsnNewChildStm->Seek(liZero, STREAM_SEEK_SET, NULL);
  3900. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3901. }
  3902. if (S_OK == hr)
  3903. {
  3904. memset(ptcsBuffer, '\0', culRandIOBytes * sizeof(TCHAR));
  3905. hr = pvsnNewChildStm->Read(
  3906. ptcsBuffer,
  3907. culRandIOBytes,
  3908. &culRead);
  3909. }
  3910. if ((S_OK != hr) || (culRead != culRandIOBytes))
  3911. {
  3912. DH_TRACE((
  3913. DH_LVL_ERROR,
  3914. TEXT("IStream::Read not successful, hr=0x%lx."),
  3915. hr));
  3916. fPass = FALSE;
  3917. }
  3918. // Calculate the CRC for stream data
  3919. if (S_OK == hr)
  3920. {
  3921. hr = CalculateCRCForDataBuffer(
  3922. ptcsBuffer,
  3923. culRandIOBytes,
  3924. &dwCommitCRC);
  3925. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3926. }
  3927. // Compare corresponding dwMemCRC and dwActCRC and verify
  3928. if (S_OK == hr)
  3929. {
  3930. if (dwOriginalCRC != dwCommitCRC)
  3931. {
  3932. DH_TRACE((
  3933. DH_LVL_ERROR,
  3934. TEXT("CRC's before/after commit unmatch.")));
  3935. fPass = FALSE;
  3936. }
  3937. }
  3938. // Delete temp buffer
  3939. if (NULL != ptcsBuffer)
  3940. {
  3941. delete []ptcsBuffer;
  3942. ptcsBuffer = NULL;
  3943. }
  3944. // if child storage just commited ok, stay in loop and now
  3945. // commit root, otherwise set flag to terminate loop
  3946. if ((fPass == TRUE) && (pstgCommitMe == pvcnRootNewChildStg))
  3947. {
  3948. pstgCommitMe = pVirtualDFRoot;
  3949. }
  3950. else
  3951. {
  3952. fRetry = FALSE;
  3953. }
  3954. }
  3955. else
  3956. {
  3957. DH_TRACE((
  3958. DH_LVL_ERROR,
  3959. TEXT("VirtualCtrNode::Commit failed. hr = 0x%lx"),
  3960. hr));
  3961. break;
  3962. }
  3963. }
  3964. // Now again make some changes on IStream data, re-set the stream size
  3965. // to a new random size, then seek from beginning and rewrite the stream
  3966. // data of the new size, and CRC it.
  3967. // Generate a random number culRandIOBytes
  3968. if (S_OK == hr)
  3969. {
  3970. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  3971. if (DG_RC_SUCCESS != usErr)
  3972. {
  3973. hr = E_FAIL;
  3974. }
  3975. }
  3976. if (S_OK == hr)
  3977. {
  3978. hr = GenerateRandomString(
  3979. pdgu,
  3980. culRandIOBytes,
  3981. culRandIOBytes,
  3982. &ptcsBuffer);
  3983. DH_HRCHECK(hr, TEXT("GenerateRandomString"));
  3984. }
  3985. if (S_OK == hr)
  3986. {
  3987. ULISet32(uliSize, culRandIOBytes);
  3988. hr = pvsnNewChildStm->SetSize(uliSize);
  3989. DH_HRCHECK(hr, TEXT("VirtualStmNode::SetSize"));
  3990. }
  3991. if (S_OK == hr)
  3992. {
  3993. LISet32(liZero, 0L);
  3994. hr = pvsnNewChildStm->Seek(liZero, STREAM_SEEK_SET, NULL);
  3995. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  3996. }
  3997. if (S_OK == hr)
  3998. {
  3999. hr = pvsnNewChildStm->Write(
  4000. ptcsBuffer,
  4001. culRandIOBytes,
  4002. &culWritten);
  4003. }
  4004. if(S_OK != hr)
  4005. {
  4006. DH_TRACE((
  4007. DH_LVL_ERROR,
  4008. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  4009. hr));
  4010. }
  4011. // Calculate the CRC for stream data
  4012. if (S_OK == hr)
  4013. {
  4014. hr = CalculateCRCForDataBuffer(
  4015. ptcsBuffer,
  4016. culRandIOBytes,
  4017. &dwOriginalCRC);
  4018. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  4019. }
  4020. // Delete temp buffer
  4021. if (NULL != ptcsBuffer)
  4022. {
  4023. delete []ptcsBuffer;
  4024. ptcsBuffer = NULL;
  4025. }
  4026. // Test on STGC_OVERWRITE
  4027. pstgCommitMe = pvcnRootNewChildStg;
  4028. while ((S_OK == hr) && (fRetry == TRUE))
  4029. {
  4030. hr = pstgCommitMe->Commit(STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE);
  4031. if (S_OK == hr)
  4032. {
  4033. // verify IStream data after commit()
  4034. // Allocate a buffer of required size
  4035. ptcsBuffer = new TCHAR [culRandIOBytes];
  4036. if (NULL == ptcsBuffer)
  4037. {
  4038. hr = E_OUTOFMEMORY;
  4039. }
  4040. if (S_OK == hr)
  4041. {
  4042. LISet32(liZero, 0L);
  4043. hr = pvsnNewChildStm->Seek(liZero, STREAM_SEEK_SET, NULL);
  4044. DH_HRCHECK(hr, TEXT("IStream::Seek"));
  4045. }
  4046. if (S_OK == hr)
  4047. {
  4048. memset(ptcsBuffer, '\0', culRandIOBytes * sizeof(TCHAR));
  4049. hr = pvsnNewChildStm->Read(
  4050. ptcsBuffer,
  4051. culRandIOBytes,
  4052. &culRead);
  4053. }
  4054. if ((S_OK != hr) || (culRead != culRandIOBytes))
  4055. {
  4056. DH_TRACE((
  4057. DH_LVL_ERROR,
  4058. TEXT("IStream::Read not successful, hr=0x%lx."),
  4059. hr));
  4060. fPass = FALSE;
  4061. }
  4062. // Calculate the CRC for stream data
  4063. if (S_OK == hr)
  4064. {
  4065. hr = CalculateCRCForDataBuffer(
  4066. ptcsBuffer,
  4067. culRandIOBytes,
  4068. &dwCommitCRC);
  4069. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  4070. }
  4071. // Compare corresponding dwMemCRC and dwActCRC and verify
  4072. if (S_OK == hr)
  4073. {
  4074. if (dwOriginalCRC != dwCommitCRC)
  4075. {
  4076. DH_TRACE((
  4077. DH_LVL_ERROR,
  4078. TEXT("CRC's before/after commit unmatch.")));
  4079. fPass = FALSE;
  4080. }
  4081. }
  4082. // Delete temp buffer
  4083. if (NULL != ptcsBuffer)
  4084. {
  4085. delete []ptcsBuffer;
  4086. ptcsBuffer = NULL;
  4087. }
  4088. // if child storage just commited ok, stay in loop and now
  4089. // commit root, otherwise set flag to terminate loop
  4090. if ((fPass == TRUE) && (pstgCommitMe == pvcnRootNewChildStg))
  4091. {
  4092. pstgCommitMe = pVirtualDFRoot;
  4093. }
  4094. else
  4095. {
  4096. fRetry = FALSE;
  4097. }
  4098. }
  4099. else
  4100. {
  4101. DH_TRACE((
  4102. DH_LVL_ERROR,
  4103. TEXT("VirtualCtrNode::Commit failed. hr = 0x%lx"),
  4104. hr));
  4105. break;
  4106. }
  4107. }
  4108. // Release the child stream
  4109. if (S_OK == hr)
  4110. {
  4111. hr = pvsnNewChildStm->Close();
  4112. DH_HRCHECK(hr, TEXT("VirutalStmNode::Close"));
  4113. }
  4114. // Release child and root storages
  4115. if (S_OK == hr)
  4116. {
  4117. hr = pvcnRootNewChildStg->Close();
  4118. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  4119. }
  4120. if (S_OK == hr)
  4121. {
  4122. DH_TRACE((
  4123. DH_LVL_TRACE1,
  4124. TEXT("VirtualStmNode::Close completed successfully.")));
  4125. }
  4126. else
  4127. {
  4128. DH_TRACE((
  4129. DH_LVL_ERROR,
  4130. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  4131. hr));
  4132. }
  4133. if (S_OK == hr)
  4134. {
  4135. hr = pVirtualDFRoot->Close();
  4136. }
  4137. if (S_OK == hr)
  4138. {
  4139. DH_TRACE((
  4140. DH_LVL_TRACE1,
  4141. TEXT("VirtualCtrNode::Close completed successfully.")));
  4142. }
  4143. else
  4144. {
  4145. DH_TRACE((
  4146. DH_LVL_ERROR,
  4147. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4148. hr));
  4149. }
  4150. // if everything goes well, log test as passed else failed.
  4151. if ((S_OK == hr) && (TRUE == fPass))
  4152. {
  4153. DH_LOG((LOG_PASS, TEXT("Test variation COMTEST_106 passed.")) );
  4154. }
  4155. else
  4156. {
  4157. DH_LOG((
  4158. LOG_FAIL,
  4159. TEXT("Test variation COMTEST_106 failed, hr = 0x%lx."),
  4160. hr) );
  4161. // test failed. make sure it failed.
  4162. hr = FirstError (hr, E_FAIL);
  4163. }
  4164. // Cleanup
  4165. CleanupTestDocfile (&pVirtualDFRoot,
  4166. &pTestVirtualDF,
  4167. &pTestChanceDF,
  4168. S_OK == hr);
  4169. // Delete temp strings
  4170. if (NULL != pRootNewChildStgName)
  4171. {
  4172. delete []pRootNewChildStgName;
  4173. pRootNewChildStgName = NULL;
  4174. }
  4175. if (NULL != ptszStreamName)
  4176. {
  4177. delete []ptszStreamName;
  4178. ptszStreamName = NULL;
  4179. }
  4180. // Stop logging the test
  4181. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation COMTEST_106 finished")) );
  4182. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4183. return hr;
  4184. }