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.

7335 lines
194 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: stmtsts.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to IStream interface
  9. //
  10. // Functions:
  11. //
  12. // History: 28-June-1996 NarindK Created.
  13. // 27-Mar-97 SCousens conversionified
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <dfheader.hxx>
  17. #pragma hdrstop
  18. #include "init.hxx"
  19. // externs
  20. extern BOOL g_fDoLargeSeekAndWrite;
  21. extern BOOL g_fUseStdBlk;
  22. extern USHORT ausSIZE_ARRAY[];
  23. #define SECTORSIZE 512
  24. #define SMALL_OBJ_SIZE 4096
  25. //----------------------------------------------------------------------------
  26. //
  27. // Test: STMTEST_100
  28. //
  29. // Synopsis: Creates a root docfile with a random name.
  30. // Creates an IStream in the root docfile and writes and CRCs a
  31. // random number of bytes then releases the IStream. The root
  32. // is then committed and released. The root docfile and child IStream
  33. // are then instantiated. CRC's are compared to verify.
  34. // A random offset is chosen within the child IStream and a random number
  35. // of bytes are written to the IStream, taking care *NOT* to grow the
  36. // length of the IStream. The IStream and root are then released.
  37. //
  38. // Arguments:[argc]
  39. // [argv]
  40. //
  41. // Returns: HRESULT
  42. //
  43. // Notes: This test runs in direct, transacted, and transacted deny write
  44. // modes
  45. //
  46. // History: 28-June-1996 NarindK Created.
  47. //
  48. // New Test Notes:
  49. // 1. Old File: LSCHANGE.CXX
  50. // 2. Old name of test : LegitStreamChange test
  51. // New Name of test : STMTEST_100
  52. // 3. To run the test, do the following at command prompt.
  53. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-100
  54. // /dfRootMode:dirReadWriteShEx
  55. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-100
  56. // /dfRootMode:xactReadWriteShEx
  57. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-100
  58. // /dfRootMode:xactReadWriteShDenyW
  59. //
  60. // BUGNOTE: Conversion: STMTEST-100
  61. //
  62. //-----------------------------------------------------------------------------
  63. HRESULT STMTEST_100(int argc, char *argv[])
  64. {
  65. HRESULT hr = S_OK;
  66. ChanceDF *pTestChanceDF = NULL;
  67. VirtualDF *pTestVirtualDF = NULL;
  68. VirtualCtrNode *pVirtualDFRoot = NULL;
  69. DG_STRING *pdgu = NULL;
  70. DG_INTEGER *pdgi = NULL;
  71. USHORT usErr = 0;
  72. VirtualStmNode *pvsnRootNewChildStream = NULL;
  73. LPTSTR pRootNewChildStmName = NULL;
  74. ULONG cb = 0;
  75. LPTSTR ptcsBuffer = NULL;
  76. ULONG culWritten = 0;
  77. ULONG culRandomPos = 0;
  78. ULONG culRemWritten = 0;
  79. DWORD dwRootMode = 0;
  80. BOOL fPass = TRUE;
  81. LARGE_INTEGER liStreamPos;
  82. ULONG cRandomMinSize = 10;
  83. ULONG cRandomMaxSize = 100;
  84. DWCRCSTM dwMemCRC;
  85. DWCRCSTM dwActCRC;
  86. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_100"));
  87. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  88. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_100 started.")) );
  89. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stream change operations")) );
  90. // Initialize CRC values to zero
  91. dwMemCRC.dwCRCSum = dwActCRC.dwCRCSum = 0;
  92. // Create our ChanceDF and VirtualDF
  93. hr = CreateTestDocfile (argc,
  94. argv,
  95. &pVirtualDFRoot,
  96. &pTestVirtualDF,
  97. &pTestChanceDF);
  98. // if creating the docfile - bail here
  99. if (NULL != pTestChanceDF && DoingCreate ())
  100. {
  101. UINT ulSeed = pTestChanceDF->GetSeed ();
  102. CleanupTestDocfile (&pVirtualDFRoot,
  103. &pTestVirtualDF,
  104. &pTestChanceDF,
  105. FALSE);
  106. return (HRESULT)ulSeed;
  107. }
  108. if (S_OK == hr)
  109. {
  110. dwRootMode = pTestChanceDF->GetRootMode();
  111. DH_TRACE((
  112. DH_LVL_TRACE1,
  113. TEXT("Run Mode for STMTEST_100, Access mode: %lx"),
  114. dwRootMode));
  115. }
  116. // Get DG_STRING object pointer
  117. if (S_OK == hr)
  118. {
  119. pdgu = pTestVirtualDF->GetDataGenUnicode();
  120. DH_ASSERT(NULL != pdgu) ;
  121. if(NULL == pdgu)
  122. {
  123. hr = E_FAIL;
  124. }
  125. }
  126. // Get DG_INTEGER object pointer
  127. if (S_OK == hr)
  128. {
  129. pdgi = pTestVirtualDF->GetDataGenInteger();
  130. DH_ASSERT(NULL != pdgi);
  131. if(NULL == pdgi)
  132. {
  133. hr = E_FAIL;
  134. }
  135. }
  136. // Adds a new stream to the root storage.
  137. if(S_OK == hr)
  138. {
  139. // Generate random name for stream
  140. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  141. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  142. }
  143. if(S_OK == hr)
  144. {
  145. // Generate random size for stream.
  146. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  147. if (DG_RC_SUCCESS != usErr)
  148. {
  149. hr = E_FAIL;
  150. }
  151. }
  152. if(S_OK == hr)
  153. {
  154. hr = AddStream(
  155. pTestVirtualDF,
  156. pVirtualDFRoot,
  157. pRootNewChildStmName,
  158. cb,
  159. STGM_READWRITE |
  160. STGM_SHARE_EXCLUSIVE |
  161. STGM_FAILIFTHERE,
  162. &pvsnRootNewChildStream);
  163. DH_HRCHECK(hr, TEXT("AddStream")) ;
  164. if(S_OK == hr)
  165. {
  166. DH_TRACE((
  167. DH_LVL_TRACE1,
  168. TEXT("VirtualStmNode::AddStream completed successfully.")));
  169. }
  170. else
  171. {
  172. DH_TRACE((
  173. DH_LVL_TRACE1,
  174. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  175. hr));
  176. }
  177. }
  178. // Call VirtualStmNode::Write to create random bytes in the stream. For
  179. // our test purposes, we generate a random string of size 1 to cb using
  180. // GenerateRandomString function.
  181. if(S_OK == hr)
  182. {
  183. hr = GenerateRandomString(pdgu, cb, cb, &ptcsBuffer);
  184. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  185. }
  186. if (S_OK == hr)
  187. {
  188. hr = pvsnRootNewChildStream->Write(
  189. ptcsBuffer,
  190. cb,
  191. &culWritten);
  192. if (S_OK == hr)
  193. {
  194. DH_TRACE((
  195. DH_LVL_TRACE1,
  196. TEXT("IStream::Write function completed successfully.")));
  197. }
  198. else
  199. {
  200. DH_TRACE((
  201. DH_LVL_TRACE1,
  202. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  203. hr));
  204. }
  205. }
  206. // Calculate the CRC for stream name and data
  207. if(S_OK == hr)
  208. {
  209. hr = CalculateInMemoryCRCForStm(
  210. pvsnRootNewChildStream,
  211. ptcsBuffer,
  212. cb,
  213. &dwMemCRC);
  214. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm")) ;
  215. }
  216. // Release stream
  217. if (S_OK == hr)
  218. {
  219. hr = pvsnRootNewChildStream->Close();
  220. if (S_OK == hr)
  221. {
  222. DH_TRACE((
  223. DH_LVL_TRACE1,
  224. TEXT("VirtualStmNode::Close completed successfully.")));
  225. }
  226. else
  227. {
  228. DH_TRACE((
  229. DH_LVL_TRACE1,
  230. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx.")));
  231. }
  232. }
  233. // Delete temp buffer
  234. if(NULL != ptcsBuffer)
  235. {
  236. delete ptcsBuffer;
  237. ptcsBuffer = NULL;
  238. }
  239. // Commit root. BUGBUG: Use random modes
  240. if(S_OK == hr)
  241. {
  242. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  243. if (S_OK == hr)
  244. {
  245. DH_TRACE((
  246. DH_LVL_TRACE1,
  247. TEXT("VirtualCtrNode::Commit completed successfully.")));
  248. }
  249. else
  250. {
  251. DH_TRACE((
  252. DH_LVL_TRACE1,
  253. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  254. hr));
  255. }
  256. }
  257. // Release root
  258. if (S_OK == hr)
  259. {
  260. hr = pVirtualDFRoot->Close();
  261. if (S_OK == hr)
  262. {
  263. DH_TRACE((
  264. DH_LVL_TRACE1,
  265. TEXT("VirtualCtrNode::Close completed successfully.")));
  266. }
  267. else
  268. {
  269. DH_TRACE((
  270. DH_LVL_TRACE1,
  271. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  272. hr));
  273. }
  274. }
  275. // Open root
  276. if (S_OK == hr)
  277. {
  278. hr = pVirtualDFRoot->OpenRoot(
  279. NULL,
  280. dwRootMode,
  281. NULL,
  282. 0);
  283. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  284. if (S_OK == hr)
  285. {
  286. DH_TRACE((
  287. DH_LVL_TRACE1,
  288. TEXT("VirtualCtrNode::Open completed successfully.")));
  289. }
  290. else
  291. {
  292. DH_TRACE((
  293. DH_LVL_TRACE1,
  294. TEXT("VirtualCtrNode::Open unsuccessful, hr=0x%lx."),
  295. hr));
  296. }
  297. }
  298. // Open stream
  299. if (S_OK == hr)
  300. {
  301. hr = pvsnRootNewChildStream->Open(
  302. NULL,
  303. STGM_READWRITE |
  304. STGM_SHARE_EXCLUSIVE ,
  305. 0);
  306. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  307. if (S_OK == hr)
  308. {
  309. DH_TRACE((
  310. DH_LVL_TRACE1,
  311. TEXT("VirtualStmNode::Open completed successfully.")));
  312. }
  313. else
  314. {
  315. DH_TRACE((
  316. DH_LVL_TRACE1,
  317. TEXT("VirtualStmNode::Open unsuccessful,hr=0x%lx."),
  318. hr));
  319. }
  320. }
  321. // Read and verify
  322. if(S_OK == hr)
  323. {
  324. hr = ReadAndCalculateDiskCRCForStm(pvsnRootNewChildStream,&dwActCRC);
  325. if (S_OK == hr)
  326. {
  327. DH_TRACE((
  328. DH_LVL_TRACE1,
  329. TEXT("ReadAndCalculateDiskCRCForStm function successful.")));
  330. if(dwActCRC.dwCRCSum == dwMemCRC.dwCRCSum)
  331. {
  332. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's for pvsnNewChildStream match.")));
  333. }
  334. else
  335. {
  336. DH_TRACE((
  337. DH_LVL_TRACE1,
  338. TEXT("CRC's for pvsnNewChildStream don't match.")));
  339. fPass = FALSE;
  340. }
  341. }
  342. else
  343. {
  344. DH_TRACE((
  345. DH_LVL_TRACE1,
  346. TEXT("ReadAndCalculateDiskCRCForStm not successful, hr=0x%lx."),
  347. hr));
  348. }
  349. }
  350. // If it is ok till now, then all the bytes were written correctly into
  351. // stream and read correctly from there, so choose any postion b/w 1 and
  352. // culWritten - number of bytes written and therafter read.
  353. if (S_OK == hr)
  354. {
  355. // Generate random size for stream.
  356. usErr = pdgi->Generate(&culRandomPos, 1, culWritten);
  357. if (DG_RC_SUCCESS != usErr)
  358. {
  359. hr = E_FAIL;
  360. }
  361. }
  362. // Now seek to this position
  363. if(S_OK == hr)
  364. {
  365. LISet32(liStreamPos, culRandomPos);
  366. // Position the stream header to the postion from begining
  367. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_SET, NULL);
  368. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  369. if (S_OK == hr)
  370. {
  371. DH_TRACE((
  372. DH_LVL_TRACE1,
  373. TEXT("IStream::Seek function completed successfully.")));
  374. }
  375. else
  376. {
  377. DH_TRACE((
  378. DH_LVL_TRACE1,
  379. TEXT("IStream::Seek function wasn't successful, hr=0x%lx."),
  380. hr));
  381. }
  382. }
  383. // Now write into this part of stream with random data w/o growing the
  384. // stream
  385. if(S_OK == hr)
  386. {
  387. hr = GenerateRandomString(
  388. pdgu,
  389. culWritten - culRandomPos,
  390. culWritten - culRandomPos,
  391. &ptcsBuffer);
  392. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  393. }
  394. if (S_OK == hr)
  395. {
  396. hr = pvsnRootNewChildStream->Write(
  397. ptcsBuffer,
  398. culWritten - culRandomPos,
  399. &culRemWritten);
  400. if (S_OK == hr)
  401. {
  402. DH_TRACE((
  403. DH_LVL_TRACE1,
  404. TEXT("IStream::Write function completed successfully.")));
  405. }
  406. else
  407. {
  408. DH_TRACE((
  409. DH_LVL_TRACE1,
  410. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  411. hr));
  412. }
  413. }
  414. // Check length of stream not grown if stream written to correctly.
  415. if(S_OK == hr)
  416. {
  417. if(culRemWritten == culWritten - culRandomPos)
  418. {
  419. DH_TRACE((
  420. DH_LVL_TRACE1,
  421. TEXT("Stream data changed okay w/o changing stream len.")));
  422. }
  423. else
  424. {
  425. DH_TRACE((
  426. DH_LVL_TRACE1,
  427. TEXT("Stream data change not okay.")));
  428. fPass = FALSE;
  429. }
  430. }
  431. // Commit root. BUGBUG: Use random modes
  432. if(S_OK == hr)
  433. {
  434. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  435. if (S_OK == hr)
  436. {
  437. DH_TRACE((
  438. DH_LVL_TRACE1,
  439. TEXT("VirtualCtrNode::Commit completed successfully.")));
  440. }
  441. else
  442. {
  443. DH_TRACE((
  444. DH_LVL_TRACE1,
  445. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  446. hr));
  447. }
  448. }
  449. // Release stream
  450. if (S_OK == hr)
  451. {
  452. hr = pvsnRootNewChildStream->Close();
  453. if (S_OK == hr)
  454. {
  455. DH_TRACE((
  456. DH_LVL_TRACE1,
  457. TEXT("VirtualStmNode::Close completed successfully.")));
  458. }
  459. else
  460. {
  461. DH_TRACE((
  462. DH_LVL_TRACE1,
  463. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  464. hr));
  465. }
  466. }
  467. // Release root
  468. if (S_OK == hr)
  469. {
  470. hr = pVirtualDFRoot->Close();
  471. if (S_OK == hr)
  472. {
  473. DH_TRACE((
  474. DH_LVL_TRACE1,
  475. TEXT("VirtualCtrNode::Close completed successfully.")));
  476. }
  477. else
  478. {
  479. DH_TRACE((
  480. DH_LVL_TRACE1,
  481. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  482. hr));
  483. }
  484. }
  485. // if everything goes well, log test as passed else failed.
  486. if ((S_OK == hr) && (TRUE == fPass))
  487. {
  488. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_100 passed.")) );
  489. }
  490. else
  491. {
  492. DH_LOG((LOG_FAIL,
  493. TEXT("Test variation STMTEST_100 failed, hr=0x%lx."),
  494. hr) );
  495. // test failed. make it look like it failed.
  496. hr = FirstError (hr, E_FAIL);
  497. }
  498. // Cleanup
  499. CleanupTestDocfile (&pVirtualDFRoot,
  500. &pTestVirtualDF,
  501. &pTestChanceDF,
  502. S_OK == hr);
  503. // Delete strings
  504. if(NULL != pRootNewChildStmName)
  505. {
  506. delete pRootNewChildStmName;
  507. pRootNewChildStmName = NULL;
  508. }
  509. // Delete temp buffer
  510. if(NULL != ptcsBuffer)
  511. {
  512. delete ptcsBuffer;
  513. ptcsBuffer = NULL;
  514. }
  515. // Stop logging the test
  516. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_100 finished")) );
  517. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  518. return hr;
  519. }
  520. //----------------------------------------------------------------------------
  521. //
  522. // Test: STMTEST_101
  523. //
  524. // Synopsis: The test creates a root docfile and a child IStream. A random
  525. // number of bytes are written to the IStream and then the IStream
  526. // is cloned.
  527. // From 1 to 5 times, either the ORIGINAL or CLONE IStream is
  528. // randomly chosen as the operation target. The current seek
  529. // pointer positions of both IStreams are saved. There is then a
  530. // 33% chance each that the target stream will be used for a
  531. // seek, write, or read operation. Next, the stream that was
  532. // *NOT* the target IStream is seeked upon to determine the
  533. // current pointer position. Verify that the *non target*
  534. // IStream pointer hasn't changed. Repeat.
  535. //
  536. // Arguments:[argc]
  537. // [argv]
  538. //
  539. // Returns: HRESULT
  540. //
  541. // Notes: This test runs in direct, transacted, and transacted deny write
  542. // modes
  543. //
  544. // History: 28-June-1996 NarindK Created.
  545. //
  546. // New Test Notes:
  547. // 1. Old File: LSCLONE.CXX
  548. // 2. Old name of test : LegitStreamClone test
  549. // New Name of test : STMTEST_101
  550. // 3. To run the test, do the following at command prompt.
  551. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-101
  552. // /dfRootMode:dirReadWriteShEx
  553. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-101
  554. // /dfRootMode:xactReadWriteShEx
  555. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-101
  556. // /dfRootMode:xactReadWriteShDenyW
  557. //
  558. // BUGNOTE: Conversion: STMTEST-101
  559. //
  560. //-----------------------------------------------------------------------------
  561. HRESULT STMTEST_101(int argc, char *argv[])
  562. {
  563. HRESULT hr = S_OK;
  564. ChanceDF *pTestChanceDF = NULL;
  565. VirtualDF *pTestVirtualDF = NULL;
  566. VirtualCtrNode *pVirtualDFRoot = NULL;
  567. DG_STRING *pdgu = NULL;
  568. DG_INTEGER *pdgi = NULL;
  569. USHORT usErr = 0;
  570. VirtualStmNode *pvsnRootNewChildStream = NULL;
  571. LPTSTR pRootNewChildStmName = NULL;
  572. ULONG cb = 0;
  573. LPTSTR ptcsBuffer = NULL;
  574. ULONG culWritten = 0;
  575. DWORD dwRootMode = 0;
  576. BOOL fPass = TRUE;
  577. BOOL fFindSeekPosition = FALSE;
  578. LARGE_INTEGER liStreamPos;
  579. ULONG culRandIOBytes = 0;
  580. ULONG culBytesLeftToWrite = 0;
  581. LPSTREAM pIStreamClone = NULL;
  582. ULONG ulCurPosition[2];
  583. ULONG ulOldPosition[2];
  584. ULONG culRandomVar = 0;
  585. ULONG culRandomPos = 0;
  586. ULONG culRandomCommit = 0;
  587. ULONG cStreamInUse = 0;
  588. ULONG cStreamNotInUse = 0;
  589. ULONG cOpInUse = 0;
  590. ULONG ulRef = 0;
  591. LPSTREAM pIStream[2];
  592. ULARGE_INTEGER uli;
  593. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_101"));
  594. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  595. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_101 started.")) );
  596. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stream clone operations")) );
  597. // Create our ChanceDF and VirtualDF
  598. hr = CreateTestDocfile (argc,
  599. argv,
  600. &pVirtualDFRoot,
  601. &pTestVirtualDF,
  602. &pTestChanceDF);
  603. // if creating the docfile - bail here
  604. if (NULL != pTestChanceDF && DoingCreate ())
  605. {
  606. UINT ulSeed = pTestChanceDF->GetSeed ();
  607. CleanupTestDocfile (&pVirtualDFRoot,
  608. &pTestVirtualDF,
  609. &pTestChanceDF,
  610. FALSE);
  611. return (HRESULT)ulSeed;
  612. }
  613. if (S_OK == hr)
  614. {
  615. dwRootMode = pTestChanceDF->GetRootMode();
  616. DH_TRACE((
  617. DH_LVL_TRACE1,
  618. TEXT("Run Mode for STMTEST_101, Access mode: %lx"),
  619. dwRootMode));
  620. }
  621. // Get DG_STRING object pointer
  622. if (S_OK == hr)
  623. {
  624. pdgu = pTestVirtualDF->GetDataGenUnicode();
  625. DH_ASSERT(NULL != pdgu);
  626. if(NULL == pdgu)
  627. {
  628. hr = E_FAIL;
  629. }
  630. }
  631. // Get DG_INTEGER object pointer
  632. if (S_OK == hr)
  633. {
  634. pdgi = pTestVirtualDF->GetDataGenInteger();
  635. DH_ASSERT(NULL != pdgi) ;
  636. if(NULL == pdgi)
  637. {
  638. hr = E_FAIL;
  639. }
  640. }
  641. // Adds a new stream to the root storage.
  642. if(S_OK == hr)
  643. {
  644. // Generate random name for stream
  645. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  646. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  647. }
  648. if (S_OK == hr)
  649. {
  650. // Generate random size for stream between 4L, and MIN_SIZE * 1.5
  651. // (range taken from old test).
  652. usErr = pdgi->Generate(&cb, 4, (ULONG) (MIN_SIZE * 1.5));
  653. if (DG_RC_SUCCESS != usErr)
  654. {
  655. hr = E_FAIL;
  656. }
  657. }
  658. if(S_OK == hr)
  659. {
  660. hr = AddStream(
  661. pTestVirtualDF,
  662. pVirtualDFRoot,
  663. pRootNewChildStmName,
  664. cb,
  665. STGM_READWRITE |
  666. STGM_SHARE_EXCLUSIVE |
  667. STGM_FAILIFTHERE,
  668. &pvsnRootNewChildStream);
  669. DH_HRCHECK(hr, TEXT("AddStream")) ;
  670. if(S_OK == hr)
  671. {
  672. culBytesLeftToWrite = cb;
  673. DH_TRACE((
  674. DH_LVL_TRACE1,
  675. TEXT("VirtualStmNode::AddStream completed successfully.")));
  676. }
  677. else
  678. {
  679. DH_TRACE((
  680. DH_LVL_TRACE1,
  681. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  682. hr));
  683. }
  684. }
  685. // Loop to write new IStream in RAND_IO size chunks unless size
  686. // remaining to write is less than RAND_IO, then write the remaining bytes
  687. while((S_OK == hr) && (0 != culBytesLeftToWrite))
  688. {
  689. if (S_OK == hr)
  690. {
  691. // Generate random number of bytes to write b/w RAND_IO_MIN ,
  692. // RAND_IO_MAX (range taken from old test).
  693. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  694. if (DG_RC_SUCCESS != usErr)
  695. {
  696. hr = E_FAIL;
  697. }
  698. }
  699. if(culBytesLeftToWrite > culRandIOBytes)
  700. {
  701. culBytesLeftToWrite = culBytesLeftToWrite - culRandIOBytes;
  702. }
  703. else
  704. {
  705. culRandIOBytes = culBytesLeftToWrite;
  706. culBytesLeftToWrite = 0;
  707. }
  708. // Call VirtualStmNode::Write to create random bytes in the stream. For
  709. // our test purposes, we generate a random string of size 1 to cb using
  710. // GenerateRandomString function.
  711. if(S_OK == hr)
  712. {
  713. hr = GenerateRandomString(
  714. pdgu,
  715. culRandIOBytes,
  716. culRandIOBytes,
  717. &ptcsBuffer);
  718. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  719. }
  720. if (S_OK == hr)
  721. {
  722. hr = pvsnRootNewChildStream->Write(
  723. ptcsBuffer,
  724. culRandIOBytes,
  725. &culWritten);
  726. if (S_OK == hr)
  727. {
  728. DH_TRACE((
  729. DH_LVL_TRACE1,
  730. TEXT("IStream::Write function completed successfully.")));
  731. }
  732. else
  733. {
  734. DH_TRACE((
  735. DH_LVL_TRACE1,
  736. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  737. hr));
  738. }
  739. }
  740. // Delete temp buffer
  741. if(NULL != ptcsBuffer)
  742. {
  743. delete ptcsBuffer;
  744. ptcsBuffer = NULL;
  745. }
  746. }
  747. // Commit root. BUGBUG: Use random modes
  748. if(S_OK == hr)
  749. {
  750. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  751. if (S_OK == hr)
  752. {
  753. DH_TRACE((
  754. DH_LVL_TRACE1,
  755. TEXT("VirtualCtrNode::Commit completed successfully.")));
  756. }
  757. else
  758. {
  759. DH_TRACE((
  760. DH_LVL_TRACE1,
  761. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  762. hr));
  763. }
  764. }
  765. // Now seek to the current stream to end of stream
  766. if(S_OK == hr)
  767. {
  768. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  769. // Position the stream header to the postion from begining
  770. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  771. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  772. ulCurPosition[ORIGINAL] = ULIGetLow(uli);
  773. if(S_OK == hr)
  774. {
  775. DH_TRACE((
  776. DH_LVL_TRACE1,
  777. TEXT("VirtualStmNode::Seek completed successfully.")));
  778. }
  779. else
  780. {
  781. DH_TRACE((
  782. DH_LVL_TRACE1,
  783. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  784. hr));
  785. }
  786. }
  787. // Clone the stream
  788. if(S_OK == hr)
  789. {
  790. hr = pvsnRootNewChildStream->Clone(&pIStreamClone);
  791. DH_HRCHECK(hr, TEXT("IStream::Clone")) ;
  792. if(S_OK == hr)
  793. {
  794. DH_TRACE((
  795. DH_LVL_TRACE1,
  796. TEXT("VirtualStmNode::Clone completed successfully.")));
  797. }
  798. else
  799. {
  800. DH_TRACE((
  801. DH_LVL_TRACE1,
  802. TEXT("VirtualStmNode::Clone not successful, hr=0x%lx."),
  803. hr));
  804. }
  805. }
  806. //clone IStream should really already be positioned to the end since
  807. //the original IStream was there. The seek below simply ensures
  808. //this plus gets the seek position into the Clone current position
  809. //array element
  810. if(S_OK == hr)
  811. {
  812. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  813. // Position the stream header to the postion from begining
  814. hr = pIStreamClone->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  815. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  816. ulCurPosition[CLONE] = ULIGetLow(uli);
  817. if(S_OK == hr)
  818. {
  819. DH_TRACE((
  820. DH_LVL_TRACE1,
  821. TEXT("VirtualStmNode::Seek completed successfully.")));
  822. }
  823. else
  824. {
  825. DH_TRACE((
  826. DH_LVL_TRACE1,
  827. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  828. hr));
  829. }
  830. }
  831. // Copy the ulCurPosition array to ulOldPosition array. Now in a loop,
  832. // in a random fashion, select either the original stream or Clone stream,
  833. // do either seek, read or write operation on it. Check that the unused
  834. // stream's seek pointer hasn't changed. Update the ulOldPosition array
  835. // with ulCurPostion araay and repeat the loop random number of times.
  836. if (S_OK == hr)
  837. {
  838. // Generate random variations for while loop
  839. usErr = pdgi->Generate(&culRandomVar, 1, 5);
  840. if (DG_RC_SUCCESS != usErr)
  841. {
  842. hr = E_FAIL;
  843. }
  844. // Also fill up stream pointer array
  845. pIStream[0] = pvsnRootNewChildStream->GetIStreamPointer();
  846. pIStream[1] = pIStreamClone;
  847. }
  848. while ((S_OK == hr) && (culRandomVar--))
  849. {
  850. //save current seek pointer positions
  851. ulOldPosition[ORIGINAL] = ulCurPosition[ORIGINAL];
  852. ulOldPosition[CLONE] = ulCurPosition[CLONE];
  853. // pick an IStream to use (either ORIGINAL or CLONE) then
  854. // decide whether to seek on it, write it, or read it
  855. usErr = pdgi->Generate(&cStreamInUse, ORIGINAL, CLONE);
  856. if (DG_RC_SUCCESS != usErr)
  857. {
  858. hr = E_FAIL;
  859. }
  860. //pick an operation to do on the stream (either SEEK, WRITE, READ)
  861. if(S_OK == hr)
  862. {
  863. usErr = pdgi->Generate(&cOpInUse, SEEK, READ);
  864. if (DG_RC_SUCCESS != usErr)
  865. {
  866. hr = E_FAIL;
  867. }
  868. }
  869. if(S_OK == hr)
  870. {
  871. //Seek to a random position in stream
  872. usErr = pdgi->Generate(&culRandomPos, 0, culWritten);
  873. if (DG_RC_SUCCESS != usErr)
  874. {
  875. hr = E_FAIL;
  876. }
  877. if(S_OK == hr)
  878. {
  879. LISet32(liStreamPos, culRandomPos);
  880. // Position stream header to the postion from begining
  881. hr = pIStream[cStreamInUse]->Seek(
  882. liStreamPos,
  883. STREAM_SEEK_SET,
  884. &uli);
  885. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  886. if(S_OK == hr)
  887. {
  888. DH_TRACE((
  889. DH_LVL_TRACE1,
  890. TEXT("IStream::Seek completed successfully.")));
  891. }
  892. else
  893. {
  894. DH_TRACE((
  895. DH_LVL_TRACE1,
  896. TEXT("IStream::Seek not successful.")));
  897. }
  898. }
  899. }
  900. if(S_OK == hr)
  901. {
  902. DH_TRACE((
  903. DH_LVL_TRACE1,
  904. TEXT("cOpInUse %d on cStreamInUse %d"),
  905. cOpInUse,
  906. cStreamInUse));
  907. switch(cOpInUse)
  908. {
  909. case SEEK:
  910. {
  911. ulCurPosition[cStreamInUse] = ULIGetLow(uli);
  912. fFindSeekPosition = FALSE;
  913. break;
  914. }
  915. case WRITE:
  916. {
  917. hr = GenerateRandomString(
  918. pdgu,
  919. 0,
  920. STM_BUFLEN,
  921. &ptcsBuffer);
  922. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  923. if (S_OK == hr)
  924. {
  925. hr = pIStream[cStreamInUse]->Write(
  926. ptcsBuffer,
  927. _tcslen(ptcsBuffer),
  928. NULL);
  929. }
  930. fFindSeekPosition = TRUE;
  931. break;
  932. }
  933. case READ:
  934. {
  935. ptcsBuffer = new TCHAR [STM_BUFLEN];
  936. if (ptcsBuffer == NULL)
  937. {
  938. hr = E_OUTOFMEMORY;
  939. }
  940. if(S_OK == hr)
  941. {
  942. // Initialize buffer
  943. memset(ptcsBuffer, '\0', STM_BUFLEN);
  944. hr = pIStream[cStreamInUse]->Read(
  945. ptcsBuffer,
  946. STM_BUFLEN,
  947. NULL);
  948. }
  949. fFindSeekPosition = TRUE;
  950. break;
  951. }
  952. }
  953. if(S_OK != hr)
  954. {
  955. DH_TRACE((
  956. DH_LVL_TRACE1,
  957. TEXT("cOpInUse %d on cStreamInUse %d failed, hr = 0x%lx"),
  958. cOpInUse,
  959. cStreamInUse,
  960. hr));
  961. fPass = FALSE;
  962. // Break out of while loop
  963. break;
  964. }
  965. else
  966. {
  967. DH_TRACE((
  968. DH_LVL_TRACE1,
  969. TEXT("cOpInUse %d on cStreamInUse %d passed. "),
  970. cOpInUse,
  971. cStreamInUse));
  972. }
  973. }
  974. // Determine current seek position if above operation might have change
  975. // it on the stream operated upon by seeking on it.
  976. if((S_OK == hr) && (TRUE == fFindSeekPosition))
  977. {
  978. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  979. hr = pIStream[cStreamInUse]->Seek(
  980. liStreamPos,
  981. STREAM_SEEK_CUR,
  982. &uli);
  983. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  984. if(S_OK == hr)
  985. {
  986. ulCurPosition[cStreamInUse] = ULIGetLow(uli);
  987. DH_TRACE((
  988. DH_LVL_TRACE1,
  989. TEXT("VirtualStmNode::Seek completed successfully.")));
  990. }
  991. else
  992. {
  993. DH_TRACE((
  994. DH_LVL_TRACE1,
  995. TEXT("VirtualStmNode::Seek not successful.")));
  996. }
  997. }
  998. // Determine the seek pointer of the stream that was NOT operated upon
  999. // hasn't changed.
  1000. if(S_OK == hr)
  1001. {
  1002. cStreamNotInUse = (cStreamInUse == ORIGINAL) ? CLONE : ORIGINAL;
  1003. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  1004. hr = pIStream[cStreamNotInUse]->Seek(
  1005. liStreamPos,
  1006. STREAM_SEEK_CUR,
  1007. &uli);
  1008. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  1009. if(S_OK == hr)
  1010. {
  1011. ulCurPosition[cStreamNotInUse] = ULIGetLow(uli);
  1012. DH_TRACE((
  1013. DH_LVL_TRACE1,
  1014. TEXT("IStream::Seek completed successfully.")));
  1015. }
  1016. else
  1017. {
  1018. DH_TRACE((
  1019. DH_LVL_TRACE1,
  1020. TEXT("IStream::Seek not successful.")));
  1021. }
  1022. }
  1023. if((S_OK == hr) &&
  1024. (ulCurPosition[cStreamNotInUse] == ulOldPosition[cStreamNotInUse]))
  1025. {
  1026. DH_TRACE((
  1027. DH_LVL_TRACE1,
  1028. TEXT("Old & new seek ptr for unused stream same as exp.")));
  1029. }
  1030. else
  1031. {
  1032. DH_TRACE((
  1033. DH_LVL_TRACE1,
  1034. TEXT("Old & new seek ptr for unused stream different unexp")));
  1035. fPass = FALSE;
  1036. break;
  1037. }
  1038. // Commit the root storage half of time.
  1039. if(S_OK == hr)
  1040. {
  1041. usErr = pdgi->Generate(&culRandomCommit, 1, 100);
  1042. if (DG_RC_SUCCESS != usErr)
  1043. {
  1044. hr = E_FAIL;
  1045. }
  1046. }
  1047. if((S_OK == hr) && (culRandomCommit > 50))
  1048. {
  1049. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1050. if (S_OK == hr)
  1051. {
  1052. DH_TRACE((
  1053. DH_LVL_TRACE1,
  1054. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1055. }
  1056. else
  1057. {
  1058. DH_TRACE((
  1059. DH_LVL_TRACE1,
  1060. TEXT("VirtualCtrNode::Commit not successful.")));
  1061. fPass = FALSE;
  1062. break;
  1063. }
  1064. }
  1065. }
  1066. // Release original stream
  1067. if (NULL != pvsnRootNewChildStream)
  1068. {
  1069. hr = pvsnRootNewChildStream->Close();
  1070. if (S_OK == hr)
  1071. {
  1072. DH_TRACE((
  1073. DH_LVL_TRACE1,
  1074. TEXT("VirtualStmNode::Close completed successfully.")));
  1075. }
  1076. else
  1077. {
  1078. DH_TRACE((
  1079. DH_LVL_TRACE1,
  1080. TEXT("VirtualStmNode::Close unsuccessful.")));
  1081. }
  1082. }
  1083. // Release Clone stream
  1084. if (NULL != pIStreamClone)
  1085. {
  1086. ulRef = pIStreamClone->Release();
  1087. DH_ASSERT(0 == ulRef);
  1088. if (S_OK == hr)
  1089. {
  1090. DH_TRACE((
  1091. DH_LVL_TRACE1,
  1092. TEXT("IStream::Close completed successfully.")));
  1093. }
  1094. else
  1095. {
  1096. DH_TRACE((
  1097. DH_LVL_TRACE1,
  1098. TEXT("IStream::Close unsuccessful.")));
  1099. }
  1100. }
  1101. // Release root
  1102. if (NULL != pVirtualDFRoot)
  1103. {
  1104. hr = pVirtualDFRoot->Close();
  1105. if (S_OK == hr)
  1106. {
  1107. DH_TRACE((
  1108. DH_LVL_TRACE1,
  1109. TEXT("VirtualCtrNode::Close completed successfully.")));
  1110. }
  1111. else
  1112. {
  1113. DH_TRACE((
  1114. DH_LVL_TRACE1,
  1115. TEXT("VirtualCtrNode::Close unsuccessful.")));
  1116. }
  1117. }
  1118. // if everything goes well, log test as passed else failed.
  1119. if ((S_OK == hr) && (TRUE == fPass))
  1120. {
  1121. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_101 passed.")) );
  1122. }
  1123. else
  1124. {
  1125. DH_LOG((LOG_FAIL, TEXT("Test variation STMTEST_101 failed.")) );
  1126. // test failed. make it look like it failed.
  1127. hr = FirstError (hr, E_FAIL);
  1128. }
  1129. // Cleanup
  1130. CleanupTestDocfile (&pVirtualDFRoot,
  1131. &pTestVirtualDF,
  1132. &pTestChanceDF,
  1133. S_OK == hr);
  1134. // Delete strings
  1135. if(NULL != pRootNewChildStmName)
  1136. {
  1137. delete pRootNewChildStmName;
  1138. pRootNewChildStmName = NULL;
  1139. }
  1140. // Delete temp buffer
  1141. if(NULL != ptcsBuffer)
  1142. {
  1143. delete ptcsBuffer;
  1144. ptcsBuffer = NULL;
  1145. }
  1146. // Stop logging the test
  1147. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_101 finished")) );
  1148. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1149. return hr;
  1150. }
  1151. //----------------------------------------------------------------------------
  1152. //
  1153. // Test: STMTEST_102
  1154. //
  1155. // Synopsis: Create a root docfile with a child IStream. Write a random number
  1156. // of bytes to the IStream and commit the root docfile. Do the same
  1157. // with a child IStorage inside of the root docfile.
  1158. // The root docfile is instantiated and the IStream is instantiated.
  1159. // MAX_SIZE_ARRAY SetSize calls are made on the IStream, the size for
  1160. // the setsize is a random ulong. After each setsize, there is a 50%
  1161. // chance that change will be immediately commited.After all setsizes are
  1162. // complete, the IStream is released, the root docfile is commited
  1163. // and then the root docfile is deleted.
  1164. //
  1165. // Arguments:[argc]
  1166. // [argv]
  1167. //
  1168. // Returns: HRESULT
  1169. //
  1170. // Notes: This test runs in direct, transacted, and transacted deny write
  1171. // modes
  1172. //
  1173. // History: 1-July-1996 NarindK Created.
  1174. //
  1175. // New Test Notes:
  1176. // 1. Old File: LSETSIZE.CXX
  1177. // 2. Old name of test : LegitStreamSetSize test
  1178. // New Name of test : STMTEST_102
  1179. // 3. To run the test, do the following at command prompt.
  1180. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1181. // /dfRootMode:dirReadWriteShEx
  1182. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1183. // /dfRootMode:xactReadWriteShEx
  1184. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1185. // /dfRootMode:xactReadWriteShDenyW
  1186. // d. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1187. // /dfRootMode:dirReadWriteShEx /stdblock
  1188. // e. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1189. // /dfRootMode:xactReadWriteShEx /stdblock
  1190. // f. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-102
  1191. // /dfRootMode:xactReadWriteShDenyW /stdblock
  1192. //
  1193. // BUGNOTE: Conversion: STMTEST-102
  1194. //
  1195. //-----------------------------------------------------------------------------
  1196. HRESULT STMTEST_102(int argc, char *argv[])
  1197. {
  1198. HRESULT hr = S_OK;
  1199. ChanceDF *pTestChanceDF = NULL;
  1200. VirtualDF *pTestVirtualDF = NULL;
  1201. VirtualCtrNode *pVirtualDFRoot = NULL;
  1202. DG_STRING *pdgu = NULL;
  1203. DG_INTEGER *pdgi = NULL;
  1204. USHORT usErr = 0;
  1205. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  1206. VirtualStmNode *pvsnRootNewChildStream = NULL;
  1207. VirtualStmNode *pvsnChildStgNewChildStm= NULL;
  1208. LPTSTR pRootNewChildStgName = NULL;
  1209. LPTSTR pRootNewChildStmName = NULL;
  1210. LPTSTR pChildStgNewChildStmName= NULL;
  1211. LPTSTR ptcsBuffer = NULL;
  1212. ULONG culWritten = 0;
  1213. DWORD dwRootMode = 0;
  1214. ULONG ulThisSetSize = 0;
  1215. ULONG culRandIOBytes = 0;
  1216. ULONG culBytesLeftToWrite = 0;
  1217. ULONG culRandomCommit = 0;
  1218. ULONG culArrayIndex = 0;
  1219. ULONG i = 0;
  1220. ULONG j = 0;
  1221. VirtualCtrNode *pvcnInUse = NULL;
  1222. VirtualStmNode *pvsnInUse = NULL;
  1223. LARGE_INTEGER liStreamPos;
  1224. ULARGE_INTEGER uli;
  1225. ULARGE_INTEGER uliCopy;
  1226. ULARGE_INTEGER uliSet;
  1227. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_102"));
  1228. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1229. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_102 started.")) );
  1230. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stream SetSize operations")) );
  1231. // Create our ChanceDF and VirtualDF
  1232. hr = CreateTestDocfile (argc,
  1233. argv,
  1234. &pVirtualDFRoot,
  1235. &pTestVirtualDF,
  1236. &pTestChanceDF);
  1237. // if creating the docfile - bail here
  1238. if (NULL != pTestChanceDF && DoingCreate ())
  1239. {
  1240. UINT ulSeed = pTestChanceDF->GetSeed ();
  1241. CleanupTestDocfile (&pVirtualDFRoot,
  1242. &pTestVirtualDF,
  1243. &pTestChanceDF,
  1244. FALSE);
  1245. return (HRESULT)ulSeed;
  1246. }
  1247. if (S_OK == hr)
  1248. {
  1249. dwRootMode = pTestChanceDF->GetRootMode();
  1250. DH_TRACE((
  1251. DH_LVL_TRACE1,
  1252. TEXT("Run Mode for STMTEST_102, Access mode: %lx"),
  1253. dwRootMode));
  1254. }
  1255. // Get DG_STRING object pointer
  1256. if (S_OK == hr)
  1257. {
  1258. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1259. DH_ASSERT(NULL != pdgu) ;
  1260. if(NULL == pdgu)
  1261. {
  1262. hr = E_FAIL;
  1263. }
  1264. }
  1265. // Get DG_INTEGER object pointer
  1266. if (S_OK == hr)
  1267. {
  1268. pdgi = pTestVirtualDF->GetDataGenInteger();
  1269. DH_ASSERT(NULL != pdgi) ;
  1270. if(NULL == pdgi)
  1271. {
  1272. hr = E_FAIL;
  1273. }
  1274. }
  1275. // Adds a new stream to the root storage.
  1276. if(S_OK == hr)
  1277. {
  1278. // Generate random name for stream
  1279. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  1280. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1281. }
  1282. if(S_OK == hr)
  1283. {
  1284. hr = AddStream(
  1285. pTestVirtualDF,
  1286. pVirtualDFRoot,
  1287. pRootNewChildStmName,
  1288. 0,
  1289. STGM_READWRITE |
  1290. STGM_SHARE_EXCLUSIVE |
  1291. STGM_FAILIFTHERE,
  1292. &pvsnRootNewChildStream);
  1293. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1294. if(S_OK == hr)
  1295. {
  1296. DH_TRACE((
  1297. DH_LVL_TRACE1,
  1298. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1299. }
  1300. else
  1301. {
  1302. DH_TRACE((
  1303. DH_LVL_TRACE1,
  1304. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  1305. hr));
  1306. }
  1307. }
  1308. // Generate a random name for child IStorage
  1309. if(S_OK == hr)
  1310. {
  1311. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  1312. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1313. }
  1314. // ----------- flatfile change ---------------
  1315. if(!StorageIsFlat())
  1316. {
  1317. // ----------- flatfile change ---------------
  1318. // Adds a new storage to the root storage.
  1319. if(S_OK == hr)
  1320. {
  1321. hr = AddStorage(
  1322. pTestVirtualDF,
  1323. pVirtualDFRoot,
  1324. pRootNewChildStgName,
  1325. pTestChanceDF->GetStgMode()|
  1326. STGM_CREATE |
  1327. STGM_FAILIFTHERE,
  1328. &pvcnRootNewChildStorage);
  1329. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1330. if(S_OK == hr)
  1331. {
  1332. DH_TRACE((
  1333. DH_LVL_TRACE1,
  1334. TEXT("VirtualCtrNode::AddStorage completed successfully.")));
  1335. }
  1336. else
  1337. {
  1338. DH_TRACE((
  1339. DH_LVL_TRACE1,
  1340. TEXT("VirtualCtrNode::AddStorage not successful, hr=0x%lx."),
  1341. hr));
  1342. }
  1343. }
  1344. // ----------- flatfile change ---------------
  1345. }
  1346. else
  1347. {
  1348. pvcnRootNewChildStorage = pVirtualDFRoot;
  1349. }
  1350. // ----------- flatfile change ---------------
  1351. // Create a stream inside this child storage.
  1352. if(S_OK == hr)
  1353. {
  1354. // Generate random name for stream
  1355. hr = GenerateRandomName(
  1356. pdgu,
  1357. MINLENGTH,
  1358. MAXLENGTH,
  1359. &pChildStgNewChildStmName);
  1360. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1361. }
  1362. if(S_OK == hr)
  1363. {
  1364. hr = AddStream(
  1365. pTestVirtualDF,
  1366. pvcnRootNewChildStorage,
  1367. pChildStgNewChildStmName,
  1368. 0,
  1369. STGM_READWRITE |
  1370. STGM_SHARE_EXCLUSIVE |
  1371. STGM_FAILIFTHERE,
  1372. &pvsnChildStgNewChildStm);
  1373. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1374. if(S_OK == hr)
  1375. {
  1376. DH_TRACE((
  1377. DH_LVL_TRACE1,
  1378. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1379. }
  1380. else
  1381. {
  1382. DH_TRACE((
  1383. DH_LVL_TRACE1,
  1384. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  1385. hr));
  1386. }
  1387. }
  1388. if (S_OK == hr)
  1389. {
  1390. // Generate random size for stream between 0L, and MIN_SIZE * 1.5
  1391. // (range taken from old test).
  1392. usErr = pdgi->Generate(&culBytesLeftToWrite, 0,(ULONG)(MIN_SIZE * 1.5));
  1393. if (DG_RC_SUCCESS != usErr)
  1394. {
  1395. hr = E_FAIL;
  1396. }
  1397. }
  1398. // Loop to write new IStream in RAND_IO size chunks unless size
  1399. // remaining to write is less than RAND_IO, then write the remaining bytes
  1400. while((S_OK == hr) && (0 != culBytesLeftToWrite))
  1401. {
  1402. culRandIOBytes = RAND_IO_MIN;
  1403. if(culBytesLeftToWrite > culRandIOBytes)
  1404. {
  1405. culBytesLeftToWrite = culBytesLeftToWrite - culRandIOBytes;
  1406. }
  1407. else
  1408. {
  1409. culRandIOBytes = culBytesLeftToWrite;
  1410. culBytesLeftToWrite = 0;
  1411. }
  1412. // Call VirtualStmNode::Write to create random bytes in the stream. For
  1413. // our test purposes, we generate a random string of size culRandomBytes
  1414. // using GenerateRandomString function.
  1415. if(S_OK == hr)
  1416. {
  1417. hr = GenerateRandomString(
  1418. pdgu,
  1419. culRandIOBytes,
  1420. culRandIOBytes,
  1421. &ptcsBuffer);
  1422. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  1423. }
  1424. if (S_OK == hr)
  1425. {
  1426. hr = pvsnRootNewChildStream->Write(
  1427. ptcsBuffer,
  1428. culRandIOBytes,
  1429. &culWritten);
  1430. if (S_OK == hr)
  1431. {
  1432. DH_TRACE((
  1433. DH_LVL_TRACE1,
  1434. TEXT("IStream::Write function completed successfully.")));
  1435. }
  1436. else
  1437. {
  1438. DH_TRACE((
  1439. DH_LVL_TRACE1,
  1440. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  1441. hr));
  1442. }
  1443. }
  1444. // Delete temp buffer
  1445. if(NULL != ptcsBuffer)
  1446. {
  1447. delete ptcsBuffer;
  1448. ptcsBuffer = NULL;
  1449. }
  1450. }
  1451. // Now seek to the start of this stream
  1452. if(S_OK == hr)
  1453. {
  1454. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  1455. // Position the stream header to the postion from begining
  1456. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_SET, &uli);
  1457. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  1458. if(S_OK == hr)
  1459. {
  1460. DH_TRACE((
  1461. DH_LVL_TRACE1,
  1462. TEXT("VirtualStmNode::Seek completed successfully.")));
  1463. }
  1464. else
  1465. {
  1466. DH_TRACE((
  1467. DH_LVL_TRACE1,
  1468. TEXT("VirtualStmNode::Seek not successful.")));
  1469. }
  1470. }
  1471. //Copy this stream pvsnRootNewChildStream to pvsnChildStgNewChildStm
  1472. if(S_OK == hr)
  1473. {
  1474. ULISet32(uliCopy, ULONG_MAX);
  1475. hr = pvsnRootNewChildStream->CopyTo(
  1476. pvsnChildStgNewChildStm,
  1477. uliCopy,
  1478. 0,
  1479. 0);
  1480. DH_HRCHECK(hr, TEXT("VirtualStmNode::CopyTo")) ;
  1481. if(S_OK == hr)
  1482. {
  1483. DH_TRACE((
  1484. DH_LVL_TRACE1,
  1485. TEXT("VirtualStmNode::CopyTo completed successfully.")));
  1486. }
  1487. else
  1488. {
  1489. DH_TRACE((
  1490. DH_LVL_TRACE1,
  1491. TEXT("VirtualStmNode::CopyTo not successful.")));
  1492. }
  1493. }
  1494. // Commit child storage. BUGBUG: Use random modes
  1495. if(S_OK == hr)
  1496. {
  1497. hr = pvcnRootNewChildStorage->Commit(STGC_DEFAULT);
  1498. if (S_OK == hr)
  1499. {
  1500. DH_TRACE((
  1501. DH_LVL_TRACE1,
  1502. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1503. }
  1504. else
  1505. {
  1506. DH_TRACE((
  1507. DH_LVL_TRACE1,
  1508. TEXT("VirtualCtrNode::Commit couldn't complete successfully.")));
  1509. }
  1510. }
  1511. // Commit root. BUGBUG: Use random modes
  1512. if(S_OK == hr)
  1513. {
  1514. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1515. if (S_OK == hr)
  1516. {
  1517. DH_TRACE((
  1518. DH_LVL_TRACE1,
  1519. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1520. }
  1521. else
  1522. {
  1523. DH_TRACE((
  1524. DH_LVL_TRACE1,
  1525. TEXT("VirtualCtrNode::Commit couldn't complete successfully.")));
  1526. }
  1527. }
  1528. //do MAX_SIZE_ARRAY setsize calls on just created IStreams. Size
  1529. //to use in SetSize call for each iteration through the loop is
  1530. //a random ulong.
  1531. if(S_OK == hr)
  1532. {
  1533. for (j=0; j <= 1; j++)
  1534. {
  1535. if (j == 0)
  1536. {
  1537. pvsnInUse = pvsnRootNewChildStream;
  1538. pvcnInUse = pVirtualDFRoot;
  1539. }
  1540. else
  1541. {
  1542. pvsnInUse = pvsnChildStgNewChildStm;
  1543. pvcnInUse = pvcnRootNewChildStorage;
  1544. }
  1545. for(i=0; i<=MAX_SIZE_ARRAY; i++)
  1546. {
  1547. if(TRUE == g_fUseStdBlk)
  1548. {
  1549. // Pick up a random array element.
  1550. usErr = pdgi->Generate(&culArrayIndex, 0, MAX_SIZE_ARRAY);
  1551. if (DG_RC_SUCCESS != usErr)
  1552. {
  1553. hr = E_FAIL;
  1554. }
  1555. else
  1556. {
  1557. ulThisSetSize= ausSIZE_ARRAY[culArrayIndex];
  1558. }
  1559. }
  1560. else
  1561. {
  1562. usErr = pdgi->Generate(&ulThisSetSize, 0, MIN_SIZE * 3);
  1563. if (DG_RC_SUCCESS != usErr)
  1564. {
  1565. hr = E_FAIL;
  1566. }
  1567. }
  1568. if(S_OK == hr)
  1569. {
  1570. ULISet32(uliSet, ulThisSetSize);
  1571. hr = pvsnInUse->SetSize(uliSet);
  1572. if (S_OK == hr)
  1573. {
  1574. DH_TRACE((
  1575. DH_LVL_TRACE1,
  1576. TEXT("VirtualStmNode::SetSize completed successfully.")));
  1577. }
  1578. else
  1579. {
  1580. DH_TRACE((
  1581. DH_LVL_TRACE1,
  1582. TEXT("VirtualStmNode::SetSize not successful, hr=0x%lx."),
  1583. hr));
  1584. }
  1585. }
  1586. // Commit the storage in use, half of time.
  1587. if(S_OK == hr)
  1588. {
  1589. usErr = pdgi->Generate(&culRandomCommit, 1, 100);
  1590. if (DG_RC_SUCCESS != usErr)
  1591. {
  1592. hr = E_FAIL;
  1593. }
  1594. }
  1595. if((S_OK == hr) && (culRandomCommit > 50))
  1596. {
  1597. hr = pvcnInUse->Commit(STGC_DEFAULT);
  1598. if (S_OK == hr)
  1599. {
  1600. DH_TRACE((
  1601. DH_LVL_TRACE1,
  1602. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1603. }
  1604. else
  1605. {
  1606. DH_TRACE((
  1607. DH_LVL_TRACE1,
  1608. TEXT("VirtualCtrNode::Commit not successful, hr =0x%lx"),
  1609. hr));
  1610. }
  1611. }
  1612. if (S_OK == hr)
  1613. {
  1614. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  1615. // Position the stream header to the end of stream
  1616. hr = pvsnInUse->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  1617. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  1618. if (S_OK == hr)
  1619. {
  1620. DH_TRACE((
  1621. DH_LVL_TRACE1,
  1622. TEXT("VirtualStmNode::Seek completed successfully.")));
  1623. }
  1624. else
  1625. {
  1626. DH_TRACE((
  1627. DH_LVL_TRACE1,
  1628. TEXT("VirtualStmNode::Seek not successful, hr = 0x%lx."),
  1629. hr));
  1630. }
  1631. }
  1632. if(S_OK != hr)
  1633. {
  1634. break;
  1635. }
  1636. }
  1637. }
  1638. }
  1639. // Release root's child stream
  1640. if (NULL != pvsnRootNewChildStream)
  1641. {
  1642. hr = pvsnRootNewChildStream->Close();
  1643. if (S_OK == hr)
  1644. {
  1645. DH_TRACE((
  1646. DH_LVL_TRACE1,
  1647. TEXT("VirtualStmNode::Close completed successfully.")));
  1648. }
  1649. else
  1650. {
  1651. DH_TRACE((
  1652. DH_LVL_TRACE1,
  1653. TEXT("VirtualStmNode::Close unsuccessful.")));
  1654. }
  1655. }
  1656. // Release child stg's child stream
  1657. if (NULL != pvsnChildStgNewChildStm)
  1658. {
  1659. hr = pvsnChildStgNewChildStm->Close();
  1660. if (S_OK == hr)
  1661. {
  1662. DH_TRACE((
  1663. DH_LVL_TRACE1,
  1664. TEXT("VirtualStmNode::Close completed successfully.")));
  1665. }
  1666. else
  1667. {
  1668. DH_TRACE((
  1669. DH_LVL_TRACE1,
  1670. TEXT("VirtualStmNode::Close unsuccessful.")));
  1671. }
  1672. }
  1673. // Commit child storage. BUGBUG: Use random modes
  1674. if(S_OK == hr)
  1675. {
  1676. hr = pvcnRootNewChildStorage->Commit(STGC_DEFAULT);
  1677. if (S_OK == hr)
  1678. {
  1679. DH_TRACE((
  1680. DH_LVL_TRACE1,
  1681. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1682. }
  1683. else
  1684. {
  1685. DH_TRACE((
  1686. DH_LVL_TRACE1,
  1687. TEXT("VirtualCtrNode::Commit couldn't complete successfully.")));
  1688. }
  1689. }
  1690. // ----------- flatfile change ---------------
  1691. if(!StorageIsFlat())
  1692. {
  1693. // ----------- flatfile change ---------------
  1694. // Release child storage
  1695. if (NULL != pvcnRootNewChildStorage)
  1696. {
  1697. hr = pvcnRootNewChildStorage->Close();
  1698. if (S_OK == hr)
  1699. {
  1700. DH_TRACE((
  1701. DH_LVL_TRACE1,
  1702. TEXT("VirtualCtrNode::Close completed successfully.")));
  1703. }
  1704. else
  1705. {
  1706. DH_TRACE((
  1707. DH_LVL_TRACE1,
  1708. TEXT("VirtualCtrNode::Close unsuccessful.")));
  1709. }
  1710. }
  1711. // ----------- flatfile change ---------------
  1712. }
  1713. // ----------- flatfile change ---------------
  1714. // Commit root. BUGBUG: Use random modes
  1715. if(S_OK == hr)
  1716. {
  1717. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1718. if (S_OK == hr)
  1719. {
  1720. DH_TRACE((
  1721. DH_LVL_TRACE1,
  1722. TEXT("VirtualCtrNode::Commit completed successfully.")));
  1723. }
  1724. else
  1725. {
  1726. DH_TRACE((
  1727. DH_LVL_TRACE1,
  1728. TEXT("VirtualCtrNode::Commit couldn't complete successfully.")));
  1729. }
  1730. }
  1731. // Release root
  1732. if (NULL != pVirtualDFRoot)
  1733. {
  1734. hr = pVirtualDFRoot->Close();
  1735. if (S_OK == hr)
  1736. {
  1737. DH_TRACE((
  1738. DH_LVL_TRACE1,
  1739. TEXT("VirtualCtrNode::Close completed successfully.")));
  1740. }
  1741. else
  1742. {
  1743. DH_TRACE((
  1744. DH_LVL_TRACE1,
  1745. TEXT("VirtualCtrNode::Close unsuccessful.")));
  1746. }
  1747. }
  1748. // if everything goes well, log test as passed else failed.
  1749. if (S_OK == hr)
  1750. {
  1751. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_102 passed.")) );
  1752. }
  1753. else
  1754. {
  1755. DH_LOG((LOG_FAIL, TEXT("Test variation STMTEST_102 failed.")) );
  1756. }
  1757. // Cleanup
  1758. CleanupTestDocfile (&pVirtualDFRoot,
  1759. &pTestVirtualDF,
  1760. &pTestChanceDF,
  1761. S_OK == hr);
  1762. // Delete strings
  1763. if(NULL != pRootNewChildStmName)
  1764. {
  1765. delete pRootNewChildStmName;
  1766. pRootNewChildStmName = NULL;
  1767. }
  1768. if(NULL != pChildStgNewChildStmName)
  1769. {
  1770. delete pChildStgNewChildStmName;
  1771. pChildStgNewChildStmName = NULL;
  1772. }
  1773. if(NULL != pRootNewChildStgName)
  1774. {
  1775. delete pRootNewChildStgName;
  1776. pRootNewChildStgName = NULL;
  1777. }
  1778. // Delete temp buffer
  1779. if(NULL != ptcsBuffer)
  1780. {
  1781. delete ptcsBuffer;
  1782. ptcsBuffer = NULL;
  1783. }
  1784. // Stop logging the test
  1785. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_102 finished")) );
  1786. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1787. return hr;
  1788. }
  1789. //----------------------------------------------------------------------------
  1790. //
  1791. // Test: STMTEST_103
  1792. //
  1793. // Synopsis: The test create a root docfile with a child IStream. Writes and
  1794. // CRCs a random number of bytes to the IStream in random block
  1795. // size chunks, or if the /stdblock (use size array) option is
  1796. // specified in cmdline, then in random block size from
  1797. // ausSIZE_ARRAY[] chunks, then releases the IStream. The root
  1798. // docfile is then committed and released.
  1799. // The root docfile is instantiated and the IStream is instantiated.
  1800. // The IStream is read in same random block size chunks as written,
  1801. // and CRCs are compared to verify. The stream and the root docfile
  1802. // are then released and the root file is deleted.
  1803. //
  1804. // Arguments:[argc]
  1805. // [argv]
  1806. //
  1807. // Returns: HRESULT
  1808. //
  1809. // Notes: This test runs in direct, transacted, and transacted deny write
  1810. // modes
  1811. //
  1812. // New Test Notes:
  1813. // 1. Old File(s): LSREAD.CXX LSWRITE.CXX
  1814. // 2. Old name of test(s) : LegitStreamRead LegitStreamWrite tests
  1815. // New Name of test(s) : STMTEST_103
  1816. // 3. To run the test, do the following at command prompt.
  1817. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1818. // /dfRootMode:dirReadWriteShEx
  1819. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1820. // /dfRootMode:xactReadWriteShEx
  1821. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1822. // /dfRootMode:xactReadWriteShDenyW
  1823. // d. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1824. // /dfRootMode:dirReadWriteShEx /stdblock
  1825. // e. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1826. // /dfRootMode:xactReadWriteShEx /stdblock
  1827. // f. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-103
  1828. // /dfRootMode:xactReadWriteShDenyW /stdblock
  1829. //
  1830. // History: Jiminli 08-July-96 Created
  1831. //
  1832. // BUGNOTE: Conversion: STMTEST-103
  1833. //
  1834. //-----------------------------------------------------------------------------
  1835. HRESULT STMTEST_103(int argc, char *argv[])
  1836. {
  1837. HRESULT hr = S_OK;
  1838. ChanceDF *pTestChanceDF = NULL;
  1839. VirtualDF *pTestVirtualDF = NULL;
  1840. VirtualCtrNode *pVirtualDFRoot = NULL;
  1841. DG_STRING *pdgu = NULL;
  1842. DG_INTEGER *pdgi = NULL;
  1843. USHORT usErr = 0;
  1844. VirtualStmNode *pvsnRootNewChildStream = NULL;
  1845. LPTSTR pRootNewChildStmName = NULL;
  1846. LPTSTR ptcsBuffer = NULL;
  1847. ULONG culWritten = 0;
  1848. ULONG culRead = 0;
  1849. DWORD dwRootMode = 0;
  1850. ULONG culRandIOBytes = 0;
  1851. ULONG culBytesLeftToWrite = 0;
  1852. ULONG culBytesLeftToRead = 0;
  1853. ULONG tmpBytes = 0;
  1854. ULONG culArrayIndex = 0;
  1855. ULONG cStartIndex = 6;
  1856. DWCRCSTM *dwMemCRC = NULL;
  1857. DWCRCSTM *dwActCRC = NULL;
  1858. ULONG numofchunks = 0;
  1859. ULONG index = 0;
  1860. BOOL fPass = TRUE;
  1861. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_103"));
  1862. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1863. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_103 started.")) );
  1864. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stream Read operations")) );
  1865. // Create our ChanceDF and VirtualDF
  1866. hr = CreateTestDocfile (argc,
  1867. argv,
  1868. &pVirtualDFRoot,
  1869. &pTestVirtualDF,
  1870. &pTestChanceDF);
  1871. // if creating the docfile - bail here
  1872. if (NULL != pTestChanceDF && DoingCreate ())
  1873. {
  1874. UINT ulSeed = pTestChanceDF->GetSeed ();
  1875. CleanupTestDocfile (&pVirtualDFRoot,
  1876. &pTestVirtualDF,
  1877. &pTestChanceDF,
  1878. FALSE);
  1879. return (HRESULT)ulSeed;
  1880. }
  1881. if (S_OK == hr)
  1882. {
  1883. dwRootMode = pTestChanceDF->GetRootMode();
  1884. DH_TRACE((
  1885. DH_LVL_TRACE1,
  1886. TEXT("Run Mode for STMTEST_103, Access mode: %lx"),
  1887. dwRootMode));
  1888. }
  1889. // Get DG_STRING object pointer
  1890. if (S_OK == hr)
  1891. {
  1892. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1893. DH_ASSERT(NULL != pdgu) ;
  1894. if(NULL == pdgu)
  1895. {
  1896. hr = E_FAIL;
  1897. }
  1898. }
  1899. // Get DG_INTEGER object pointer
  1900. if (S_OK == hr)
  1901. {
  1902. pdgi = pTestVirtualDF->GetDataGenInteger();
  1903. DH_ASSERT(NULL != pdgi) ;
  1904. if(NULL == pdgi)
  1905. {
  1906. hr = E_FAIL;
  1907. }
  1908. }
  1909. // Adds a new stream to the root storage.
  1910. if(S_OK == hr)
  1911. {
  1912. // Generate random name for stream
  1913. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  1914. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1915. }
  1916. if(S_OK == hr)
  1917. {
  1918. hr = AddStream(
  1919. pTestVirtualDF,
  1920. pVirtualDFRoot,
  1921. pRootNewChildStmName,
  1922. 0,
  1923. STGM_READWRITE |
  1924. STGM_SHARE_EXCLUSIVE |
  1925. STGM_FAILIFTHERE,
  1926. &pvsnRootNewChildStream);
  1927. DH_HRCHECK(hr, TEXT("AddStream")) ;
  1928. if(S_OK == hr)
  1929. {
  1930. DH_TRACE((
  1931. DH_LVL_TRACE1,
  1932. TEXT("VirtualStmNode::AddStream completed successfully.")));
  1933. }
  1934. else
  1935. {
  1936. DH_TRACE((
  1937. DH_LVL_TRACE1,
  1938. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  1939. hr));
  1940. }
  1941. }
  1942. if (S_OK == hr)
  1943. {
  1944. // Generate random size for stream between 0L, and MIN_SIZE * 2
  1945. usErr = pdgi->Generate(&culBytesLeftToWrite, 0, MIN_SIZE * 2);
  1946. if (DG_RC_SUCCESS != usErr)
  1947. {
  1948. hr = E_FAIL;
  1949. }
  1950. }
  1951. if (S_OK == hr)
  1952. {
  1953. // Record for later use.
  1954. culBytesLeftToRead = culBytesLeftToWrite;
  1955. tmpBytes = culBytesLeftToWrite;
  1956. }
  1957. if (S_OK == hr)
  1958. {
  1959. if (TRUE == g_fUseStdBlk)
  1960. {
  1961. // Pick up a random array element. Choosing cStartIndex of the
  1962. // array (with random blocks) as 6 because do not want to write
  1963. // byte by byte or in too small chunks a large docfile.
  1964. usErr = pdgi->Generate(&culArrayIndex, cStartIndex, MAX_SIZE_ARRAY);
  1965. if (DG_RC_SUCCESS != usErr)
  1966. {
  1967. hr = E_FAIL;
  1968. }
  1969. else
  1970. {
  1971. culRandIOBytes = ausSIZE_ARRAY[culArrayIndex];
  1972. }
  1973. }
  1974. else
  1975. {
  1976. // Generate random number of bytes to write per chunk b/w
  1977. // RAND_IO_MIN and RAND_IO_MAX.
  1978. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  1979. if (DG_RC_SUCCESS != usErr)
  1980. {
  1981. hr = E_FAIL;
  1982. }
  1983. }
  1984. }
  1985. // Calculate how many chunks be written, i.e how many CRC's be calculated
  1986. if (S_OK == hr)
  1987. {
  1988. if (0 == culRandIOBytes)
  1989. {
  1990. hr = E_FAIL;
  1991. }
  1992. else
  1993. {
  1994. while (0 != culBytesLeftToWrite)
  1995. {
  1996. numofchunks++;
  1997. if (culBytesLeftToWrite >= culRandIOBytes)
  1998. {
  1999. culBytesLeftToWrite -= culRandIOBytes;
  2000. }
  2001. else
  2002. {
  2003. culBytesLeftToWrite = 0;
  2004. }
  2005. }
  2006. }
  2007. }
  2008. if (S_OK == hr)
  2009. {
  2010. culBytesLeftToWrite = tmpBytes;
  2011. tmpBytes = culRandIOBytes;
  2012. }
  2013. // Allocate memory
  2014. if (S_OK == hr)
  2015. {
  2016. dwMemCRC = new DWCRCSTM[numofchunks];
  2017. dwActCRC = new DWCRCSTM[numofchunks];
  2018. if ((NULL == dwMemCRC) || (NULL == dwActCRC))
  2019. {
  2020. hr = E_OUTOFMEMORY;
  2021. }
  2022. }
  2023. // Initilize each CRC to zero
  2024. if (S_OK == hr)
  2025. {
  2026. for (index=0; index<numofchunks; index++)
  2027. {
  2028. (*(dwMemCRC + index)).dwCRCSum = 0;
  2029. (*(dwActCRC + index)).dwCRCSum = 0;
  2030. }
  2031. }
  2032. // Loop to write new IStream in RAND_IO size chunks unless size
  2033. // remaining to write is less than RAND_IO, then write the remaining bytes
  2034. index = 0;
  2035. while ((S_OK == hr) && (0 != culBytesLeftToWrite))
  2036. {
  2037. if (culBytesLeftToWrite > culRandIOBytes)
  2038. {
  2039. culBytesLeftToWrite = culBytesLeftToWrite - culRandIOBytes;
  2040. }
  2041. else
  2042. {
  2043. culRandIOBytes = culBytesLeftToWrite;
  2044. culBytesLeftToWrite = 0;
  2045. }
  2046. // Call VirtualStmNode::Write to create random bytes in the stream. For
  2047. // our test purposes, we generate a random string of size culRandIOBytes
  2048. // using GenerateRandomString function.
  2049. if (S_OK == hr)
  2050. {
  2051. hr = GenerateRandomString(
  2052. pdgu,
  2053. culRandIOBytes,
  2054. culRandIOBytes,
  2055. &ptcsBuffer);
  2056. }
  2057. if (S_OK == hr)
  2058. {
  2059. hr = pvsnRootNewChildStream->Write(
  2060. ptcsBuffer,
  2061. culRandIOBytes,
  2062. &culWritten);
  2063. }
  2064. if(S_OK != hr)
  2065. {
  2066. DH_TRACE((
  2067. DH_LVL_TRACE1,
  2068. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  2069. hr));
  2070. }
  2071. // Calculate the CRC for stream name and data
  2072. if (S_OK == hr)
  2073. {
  2074. hr = CalculateInMemoryCRCForStm(
  2075. pvsnRootNewChildStream,
  2076. ptcsBuffer,
  2077. culRandIOBytes,
  2078. (dwMemCRC+index));
  2079. }
  2080. // Delete temp buffer
  2081. if(NULL != ptcsBuffer)
  2082. {
  2083. delete []ptcsBuffer;
  2084. ptcsBuffer = NULL;
  2085. }
  2086. index++;
  2087. }
  2088. // Log while loop result
  2089. DH_HRCHECK(hr, TEXT("While loop - GenrateRandomName/IStream::Write,CRC"));
  2090. if (S_OK == hr)
  2091. {
  2092. DH_TRACE((
  2093. DH_LVL_TRACE1,
  2094. TEXT("VirtualStmNode::Write completed successfully.")));
  2095. }
  2096. // Release stream
  2097. if (S_OK == hr)
  2098. {
  2099. hr = pvsnRootNewChildStream->Close();
  2100. if (S_OK == hr)
  2101. {
  2102. DH_TRACE((
  2103. DH_LVL_TRACE1,
  2104. TEXT("VirtualStmNode::Close completed successfully.")));
  2105. }
  2106. else
  2107. {
  2108. DH_TRACE((
  2109. DH_LVL_TRACE1,
  2110. TEXT("VirtulaStmNode::Close unsuccessful, hr=0x%lx."),
  2111. hr));
  2112. }
  2113. }
  2114. // Commit root. BUGBUG: Use random modes
  2115. if (S_OK == hr)
  2116. {
  2117. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2118. if(S_OK == hr)
  2119. {
  2120. DH_TRACE((
  2121. DH_LVL_TRACE1,
  2122. TEXT("VirtualCtrNode::Commit completed successfully.")));
  2123. }
  2124. else
  2125. {
  2126. DH_TRACE((
  2127. DH_LVL_TRACE1,
  2128. TEXT("VirtualCtrNode::Commit wasn't successfully, hr=0x%lx."),
  2129. hr));
  2130. }
  2131. }
  2132. // Release root
  2133. if (S_OK == hr)
  2134. {
  2135. hr = pVirtualDFRoot->Close();
  2136. }
  2137. if (S_OK == hr)
  2138. {
  2139. DH_TRACE((
  2140. DH_LVL_TRACE1,
  2141. TEXT("VirtualCtrNode::Close completed successfully.")));
  2142. }
  2143. else
  2144. {
  2145. DH_TRACE((
  2146. DH_LVL_TRACE1,
  2147. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2148. hr));
  2149. }
  2150. // Open root
  2151. if (S_OK == hr)
  2152. {
  2153. hr = pVirtualDFRoot->OpenRoot(
  2154. NULL,
  2155. dwRootMode,
  2156. NULL,
  2157. 0);
  2158. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open")) ;
  2159. }
  2160. if (S_OK == hr)
  2161. {
  2162. DH_TRACE((
  2163. DH_LVL_TRACE1,
  2164. TEXT("VirtualCtrNode::Open completed successfully.")));
  2165. }
  2166. else
  2167. {
  2168. DH_TRACE((
  2169. DH_LVL_TRACE1,
  2170. TEXT("VirtualCtrNode::Open wasn't successfully, hr=0x%lx."),
  2171. hr));
  2172. }
  2173. // Open stream
  2174. if (S_OK == hr)
  2175. {
  2176. hr = pvsnRootNewChildStream->Open(
  2177. NULL,
  2178. STGM_READWRITE |
  2179. STGM_SHARE_EXCLUSIVE ,
  2180. 0);
  2181. DH_HRCHECK(hr, TEXT("VirtualStmNode::Open")) ;
  2182. }
  2183. if (S_OK == hr)
  2184. {
  2185. DH_TRACE((
  2186. DH_LVL_TRACE1,
  2187. TEXT("VirtualStmNode::Open completed successfully.")));
  2188. }
  2189. else
  2190. {
  2191. DH_TRACE((
  2192. DH_LVL_TRACE1,
  2193. TEXT("VirtualStmNode::Open wasn't successfully, hr=0x%lx."),
  2194. hr));
  2195. }
  2196. // Read and verify
  2197. index = 0;
  2198. culRandIOBytes = tmpBytes;
  2199. while ((S_OK == hr) && (0 != culBytesLeftToRead))
  2200. {
  2201. if (culBytesLeftToRead > culRandIOBytes)
  2202. {
  2203. culBytesLeftToRead = culBytesLeftToRead - culRandIOBytes;
  2204. }
  2205. else
  2206. {
  2207. culRandIOBytes = culBytesLeftToRead;
  2208. culBytesLeftToRead = 0;
  2209. }
  2210. // Allocate a buffer of required size
  2211. if (S_OK == hr)
  2212. {
  2213. ptcsBuffer = new TCHAR [culRandIOBytes];
  2214. if (NULL == ptcsBuffer)
  2215. {
  2216. hr = E_OUTOFMEMORY;
  2217. }
  2218. }
  2219. if (S_OK == hr)
  2220. {
  2221. memset(ptcsBuffer, '\0', culRandIOBytes*sizeof(TCHAR));
  2222. hr = pvsnRootNewChildStream->Read(
  2223. ptcsBuffer,
  2224. culRandIOBytes,
  2225. &culRead);
  2226. }
  2227. if (S_OK != hr)
  2228. {
  2229. DH_TRACE((
  2230. DH_LVL_TRACE1,
  2231. TEXT("IStream::Read function wasn't successful, hr=0x%lx."),
  2232. hr));
  2233. }
  2234. // Calculate the CRC for stream name and data
  2235. if (S_OK == hr)
  2236. {
  2237. hr = CalculateInMemoryCRCForStm(
  2238. pvsnRootNewChildStream,
  2239. ptcsBuffer,
  2240. culRandIOBytes,
  2241. (dwActCRC+index));
  2242. DH_HRCHECK(hr, TEXT("CalculateInMemoryCRCForStm"));
  2243. }
  2244. // Compare corresponding dwMemCRC and dwActCRC and verify
  2245. if (S_OK == hr)
  2246. {
  2247. if ( (*(dwActCRC+index)).dwCRCSum != (*(dwMemCRC+index)).dwCRCSum )
  2248. {
  2249. DH_TRACE((
  2250. DH_LVL_TRACE1,
  2251. TEXT("CRC's for pvsnNewChildStream don't match. ")));
  2252. fPass = FALSE;
  2253. break;
  2254. }
  2255. }
  2256. // Delete temp buffer
  2257. if (NULL != ptcsBuffer)
  2258. {
  2259. delete []ptcsBuffer;
  2260. ptcsBuffer = NULL;
  2261. }
  2262. index++;
  2263. }
  2264. // Log results of while loop
  2265. DH_HRCHECK(hr, TEXT("While loop - GenrateRandomName/IStream::Write,CRC"));
  2266. if (S_OK == hr)
  2267. {
  2268. DH_TRACE((
  2269. DH_LVL_TRACE1,
  2270. TEXT("VirtualStmNode::Write completed successfully.")));
  2271. }
  2272. if (S_OK == hr)
  2273. {
  2274. if (TRUE == fPass)
  2275. {
  2276. DH_TRACE((
  2277. DH_LVL_TRACE1,
  2278. TEXT("CRC's for pvsnNewChildStream all matched.")));
  2279. }
  2280. }
  2281. // Release stream
  2282. if (S_OK == hr)
  2283. {
  2284. hr = pvsnRootNewChildStream->Close();
  2285. }
  2286. if (S_OK == hr)
  2287. {
  2288. DH_TRACE((
  2289. DH_LVL_TRACE1,
  2290. TEXT("VirtualStmNode::Close completed successfully.")));
  2291. }
  2292. else
  2293. {
  2294. DH_TRACE((
  2295. DH_LVL_TRACE1,
  2296. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  2297. hr));
  2298. }
  2299. // Release Root
  2300. if (S_OK == hr)
  2301. {
  2302. hr = pVirtualDFRoot->Close();
  2303. }
  2304. if (S_OK == hr)
  2305. {
  2306. DH_TRACE((
  2307. DH_LVL_TRACE1,
  2308. TEXT("VirtualCtrNode::Close completed successfully.")));
  2309. }
  2310. else
  2311. {
  2312. DH_TRACE((
  2313. DH_LVL_TRACE1,
  2314. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  2315. hr));
  2316. }
  2317. // if everything goes well, log test as passed else failed.
  2318. if ((S_OK == hr) && (TRUE == fPass))
  2319. {
  2320. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_103 passed.")) );
  2321. }
  2322. else
  2323. {
  2324. DH_LOG((LOG_FAIL,
  2325. TEXT("Test variation STMTEST_103 failed, hr=0x%lx."),
  2326. hr));
  2327. // test failed. make it look like it failed.
  2328. hr = FirstError (hr, E_FAIL);
  2329. }
  2330. // Cleanup
  2331. CleanupTestDocfile (&pVirtualDFRoot,
  2332. &pTestVirtualDF,
  2333. &pTestChanceDF,
  2334. S_OK == hr);
  2335. // Delete strings
  2336. if (NULL != pRootNewChildStmName)
  2337. {
  2338. delete pRootNewChildStmName;
  2339. pRootNewChildStmName = NULL;
  2340. }
  2341. // Delete temp buffer
  2342. if (NULL != ptcsBuffer)
  2343. {
  2344. delete []ptcsBuffer;
  2345. ptcsBuffer = NULL;
  2346. }
  2347. if (NULL != dwMemCRC)
  2348. {
  2349. delete []dwMemCRC;
  2350. dwMemCRC = NULL;
  2351. }
  2352. if (NULL != dwActCRC)
  2353. {
  2354. delete []dwActCRC;
  2355. dwActCRC = NULL;
  2356. }
  2357. // Stop logging the test
  2358. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_103 finished")) );
  2359. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2360. return hr;
  2361. }
  2362. //----------------------------------------------------------------------------
  2363. //
  2364. // Test: STMTEST_104
  2365. //
  2366. // Synopsis: Create a root docfile and an IStream in that. Write to IStream.
  2367. // The test seeks to the end of the IStream to determine the size
  2368. // and then makes 4 seek passes through the IStream:
  2369. //
  2370. // 1) Seek cumulative offset from STREAM_SEEK_SET (beginning)
  2371. // to end, then rewind IStream to beginning
  2372. // 2) Seek relative offset from STREAM_SEEK_CUR (current)
  2373. // to end, then seek IStream to end
  2374. // 3) Seek negative cumulative offset from STREAM_SEEK_END (end)
  2375. // to beginning, then seek IStream to end
  2376. // 4) Seek negative relative offset from STREAM_SEEK_CUR (current)
  2377. // to beginning
  2378. // 5) Perform several random large offset seeks from
  2379. // STREAM_SEEK_SET (beginning)
  2380. // 6) Attempt to write one byte at the current position in stream
  2381. //
  2382. // The root docfile and stream are then releases and root docfile
  2383. // deleted
  2384. //
  2385. // Note: It is an error to seek before beginning of stream (tested
  2386. // in part 4, but it is not an error to seek past end of stream.
  2387. //
  2388. // Arguments:[argc]
  2389. // [argv]
  2390. //
  2391. // Returns: HRESULT
  2392. //
  2393. // Notes: This test runs in direct, transacted, and transacted deny write
  2394. // modes
  2395. //
  2396. // History: 2-July-1996 NarindK Created.
  2397. //
  2398. // New Test Notes:
  2399. // 1. Old File: LSSEEK.CXX
  2400. // 2. Old name of test : LegitStreamSeek test
  2401. // New Name of test : STMTEST_104
  2402. // 3. To run the test, do the following at command prompt.
  2403. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2404. // /dfRootMode:dirReadWriteShEx /labmode
  2405. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2406. // /dfRootMode:xactReadWriteShEx /labmode
  2407. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2408. // /dfRootMode:xactReadWriteShDenyW /labmode
  2409. // d. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2410. // /dfRootMode:dirReadWriteShEx /labmode /stdblock
  2411. // e. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2412. // /dfRootMode:xactReadWriteShEx /labmode /stdblock
  2413. // f. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2414. // /dfRootMode:xactReadWriteShDenyW /labmode /stdblock
  2415. // g. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2416. // /dfRootMode:dirReadWriteShEx /labmode /stdblock /lgseekwrite
  2417. // h. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2418. // /dfRootMode:xactReadWriteShEx /labmode /stdblock /lgseekwrite
  2419. // i. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-104
  2420. // /dfRootMode:xactReadWriteShDenyW /labmode /stdblock /lgseekwrite
  2421. //
  2422. // BUGNOTE: Conversion: STMTEST-104
  2423. //
  2424. //-----------------------------------------------------------------------------
  2425. HRESULT STMTEST_104(int argc, char *argv[])
  2426. {
  2427. HRESULT hr = S_OK;
  2428. ChanceDF *pTestChanceDF = NULL;
  2429. VirtualDF *pTestVirtualDF = NULL;
  2430. VirtualCtrNode *pVirtualDFRoot = NULL;
  2431. DG_STRING *pdgu = NULL;
  2432. DG_INTEGER *pdgi = NULL;
  2433. USHORT usErr = 0;
  2434. VirtualStmNode *pvsnRootNewChildStream = NULL;
  2435. LPTSTR pRootNewChildStmName = NULL;
  2436. LPTSTR ptcsBuffer = NULL;
  2437. ULONG culWritten = 0;
  2438. DWORD dwRootMode = 0;
  2439. ULONG culRandIOBytes = 0;
  2440. ULONG culBytesLeftToWrite = 0;
  2441. ULONG ulStreamSize = 0;
  2442. LONG lSeekThisTime = 0;
  2443. ULONG cArrayIndex = 0;
  2444. ULONG ulCurrentPosition = 0;
  2445. ULONG cNumVars = 0;
  2446. ULONG cMinVars = 5;
  2447. ULONG cMaxVars = 10;
  2448. BOOL fPass = TRUE;
  2449. LARGE_INTEGER liStreamPos;
  2450. LARGE_INTEGER liSeekThisTime;
  2451. ULARGE_INTEGER uli;
  2452. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_104"));
  2453. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2454. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_104 started.")) );
  2455. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stream Seek operations")) );
  2456. // Create our ChanceDF and VirtualDF
  2457. hr = CreateTestDocfile (argc,
  2458. argv,
  2459. &pVirtualDFRoot,
  2460. &pTestVirtualDF,
  2461. &pTestChanceDF);
  2462. // if creating the docfile - bail here
  2463. if (NULL != pTestChanceDF && DoingCreate ())
  2464. {
  2465. UINT ulSeed = pTestChanceDF->GetSeed ();
  2466. CleanupTestDocfile (&pVirtualDFRoot,
  2467. &pTestVirtualDF,
  2468. &pTestChanceDF,
  2469. FALSE);
  2470. return (HRESULT)ulSeed;
  2471. }
  2472. if (S_OK == hr)
  2473. {
  2474. dwRootMode = pTestChanceDF->GetRootMode();
  2475. DH_TRACE((
  2476. DH_LVL_TRACE1,
  2477. TEXT("Run Mode for STMTEST_104, Access mode: %lx"),
  2478. dwRootMode));
  2479. }
  2480. // Get DG_STRING object pointer
  2481. if (S_OK == hr)
  2482. {
  2483. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2484. DH_ASSERT(NULL != pdgu);
  2485. if(NULL == pdgu)
  2486. {
  2487. hr = E_FAIL;
  2488. }
  2489. }
  2490. // Get DG_INTEGER object pointer
  2491. if (S_OK == hr)
  2492. {
  2493. pdgi = pTestVirtualDF->GetDataGenInteger();
  2494. DH_ASSERT(NULL != pdgi) ;
  2495. if(NULL == pdgi)
  2496. {
  2497. hr = E_FAIL;
  2498. }
  2499. }
  2500. // Adds a new stream to the root storage.
  2501. if(S_OK == hr)
  2502. {
  2503. // Generate random name for stream
  2504. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  2505. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2506. }
  2507. if(S_OK == hr)
  2508. {
  2509. hr = AddStream(
  2510. pTestVirtualDF,
  2511. pVirtualDFRoot,
  2512. pRootNewChildStmName,
  2513. 0,
  2514. STGM_READWRITE |
  2515. STGM_SHARE_EXCLUSIVE |
  2516. STGM_FAILIFTHERE,
  2517. &pvsnRootNewChildStream);
  2518. DH_HRCHECK(hr, TEXT("AddStream")) ;
  2519. }
  2520. if(S_OK == hr)
  2521. {
  2522. DH_TRACE((
  2523. DH_LVL_TRACE1,
  2524. TEXT("VirtualStmNode::AddStream completed successfully.")));
  2525. }
  2526. else
  2527. {
  2528. DH_TRACE((
  2529. DH_LVL_TRACE1,
  2530. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  2531. hr));
  2532. }
  2533. if (S_OK == hr)
  2534. {
  2535. // Generate random size for stream between 0L, and MIN_SIZE * 1.5
  2536. // (range taken from old test).
  2537. usErr = pdgi->Generate(&culBytesLeftToWrite, 0,(ULONG)(MIN_SIZE * 1.5));
  2538. if (DG_RC_SUCCESS != usErr)
  2539. {
  2540. hr = E_FAIL;
  2541. }
  2542. }
  2543. // Loop to write new IStream in RAND_IO size chunks unless size
  2544. // remaining to write is less than RAND_IO, then write the remaining bytes
  2545. while((S_OK == hr) && (0 != culBytesLeftToWrite))
  2546. {
  2547. culRandIOBytes = RAND_IO_MIN;
  2548. if(culBytesLeftToWrite > culRandIOBytes)
  2549. {
  2550. culBytesLeftToWrite = culBytesLeftToWrite - culRandIOBytes;
  2551. }
  2552. else
  2553. {
  2554. culRandIOBytes = culBytesLeftToWrite;
  2555. culBytesLeftToWrite = 0;
  2556. }
  2557. // Call VirtualStmNode::Write to create random bytes in the stream. For
  2558. // our test purposes, we generate a random string of size culRandomBytes
  2559. // using GenerateRandomString function.
  2560. if(S_OK == hr)
  2561. {
  2562. hr = GenerateRandomString(
  2563. pdgu,
  2564. culRandIOBytes,
  2565. culRandIOBytes,
  2566. &ptcsBuffer);
  2567. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  2568. }
  2569. if (S_OK == hr)
  2570. {
  2571. hr = pvsnRootNewChildStream->Write(
  2572. ptcsBuffer,
  2573. culRandIOBytes,
  2574. &culWritten);
  2575. }
  2576. if (S_OK == hr)
  2577. {
  2578. DH_TRACE((
  2579. DH_LVL_TRACE1,
  2580. TEXT("IStream::Write function completed successfully.")));
  2581. }
  2582. else
  2583. {
  2584. DH_TRACE((
  2585. DH_LVL_TRACE1,
  2586. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  2587. hr));
  2588. }
  2589. // Delete temp buffer
  2590. if(NULL != ptcsBuffer)
  2591. {
  2592. delete ptcsBuffer;
  2593. ptcsBuffer = NULL;
  2594. }
  2595. }
  2596. // Now seek to the end of this stream and determine its size
  2597. if(S_OK == hr)
  2598. {
  2599. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2600. // Seek to end of stream and determine size of stream
  2601. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  2602. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2603. }
  2604. if(S_OK == hr)
  2605. {
  2606. ulStreamSize = ULIGetLow(uli);
  2607. DH_TRACE((
  2608. DH_LVL_TRACE1,
  2609. TEXT("VirtualStmNode::Seek completed successfully.")));
  2610. }
  2611. else
  2612. {
  2613. DH_TRACE((
  2614. DH_LVL_TRACE1,
  2615. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2616. hr));
  2617. }
  2618. // loop through the entire IStream, each time seeking relative to the
  2619. // beginning of the IStream (STREAM_SEEK_SET). The amount to add to
  2620. // the offset from the beginning is a random number or a random array
  2621. // element of ausSIZE_ARRAY if command line option specifies that.
  2622. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2623. while ((ulCurrentPosition < ulStreamSize) && (S_OK == hr))
  2624. {
  2625. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2626. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2627. if(S_OK == hr)
  2628. {
  2629. LISet32(liSeekThisTime, lSeekThisTime);
  2630. hr = pvsnRootNewChildStream->Seek(
  2631. liSeekThisTime,
  2632. STREAM_SEEK_SET,
  2633. &uli);
  2634. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2635. ulCurrentPosition = ULIGetLow(uli);
  2636. }
  2637. }
  2638. DH_TRACE((
  2639. DH_LVL_TRACE1,
  2640. TEXT("Current position is now %lu"),
  2641. ulCurrentPosition));
  2642. if(S_OK == hr)
  2643. {
  2644. DH_TRACE((
  2645. DH_LVL_TRACE1,
  2646. TEXT("VirtualStmNode::Seek completed successfully.")));
  2647. }
  2648. else
  2649. {
  2650. DH_TRACE((
  2651. DH_LVL_TRACE1,
  2652. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2653. hr));
  2654. }
  2655. if(S_OK == hr)
  2656. {
  2657. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2658. hr = pvsnRootNewChildStream->Seek(
  2659. liStreamPos,
  2660. STREAM_SEEK_SET,
  2661. &uli);
  2662. ulCurrentPosition = ULIGetLow(uli);
  2663. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2664. }
  2665. if(S_OK == hr)
  2666. {
  2667. DH_TRACE((
  2668. DH_LVL_TRACE1,
  2669. TEXT("VirtualStmNode::Seek completed successfully.")));
  2670. }
  2671. else
  2672. {
  2673. DH_TRACE((
  2674. DH_LVL_TRACE1,
  2675. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2676. hr));
  2677. }
  2678. // loop through the entire IStream, each time seeking relative to the
  2679. // current seek pointer (STREAM_SEEK_CUR). The distance to seek is a
  2680. // random ushort.
  2681. lSeekThisTime = 0;
  2682. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2683. while ((ulCurrentPosition < ulStreamSize) && (S_OK == hr))
  2684. {
  2685. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2686. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2687. if(S_OK == hr)
  2688. {
  2689. LISet32(liSeekThisTime, lSeekThisTime);
  2690. hr = pvsnRootNewChildStream->Seek(
  2691. liSeekThisTime,
  2692. STREAM_SEEK_CUR,
  2693. &uli);
  2694. ulCurrentPosition = ULIGetLow(uli);
  2695. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2696. }
  2697. }
  2698. DH_TRACE((
  2699. DH_LVL_TRACE1,
  2700. TEXT("Current position is now %lu"),
  2701. ulCurrentPosition));
  2702. if(S_OK == hr)
  2703. {
  2704. DH_TRACE((
  2705. DH_LVL_TRACE1,
  2706. TEXT("VirtualStmNode::Seek completed successfully.")));
  2707. }
  2708. else
  2709. {
  2710. DH_TRACE((
  2711. DH_LVL_TRACE1,
  2712. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2713. hr));
  2714. }
  2715. // Seek to the end of Stream. Then we would seek negative cumulative
  2716. // offset from the STREAM_SEEK_END.
  2717. if(S_OK == hr)
  2718. {
  2719. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2720. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2721. hr = pvsnRootNewChildStream->Seek(
  2722. liStreamPos,
  2723. STREAM_SEEK_END,
  2724. &uli);
  2725. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2726. ulCurrentPosition = ULIGetLow(uli);
  2727. }
  2728. if(S_OK == hr)
  2729. {
  2730. DH_TRACE((
  2731. DH_LVL_TRACE1,
  2732. TEXT("VirtualStmNode::Seek completed successfully.")));
  2733. }
  2734. else
  2735. {
  2736. DH_TRACE((
  2737. DH_LVL_TRACE1,
  2738. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2739. hr));
  2740. }
  2741. // loop through the entire IStream, each time seeking relative to the
  2742. // end of the IStream (STREAM_SEEK_END). The amount to add to
  2743. // the offset from the end is a random ushort
  2744. lSeekThisTime = 0;
  2745. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2746. while ((ulCurrentPosition != 0) && (S_OK == hr))
  2747. {
  2748. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2749. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2750. // if generated seek offset would cause a seek to before beginning
  2751. // of file, ensure that it won't do that by enforcing to seek to
  2752. // the beginnining.
  2753. if(S_OK == hr)
  2754. {
  2755. if(lSeekThisTime > (LONG) ulStreamSize)
  2756. {
  2757. lSeekThisTime = (LONG) ulStreamSize;
  2758. }
  2759. // Unary minus opeartion is applied to seek offset to cause a neg
  2760. // seek opeartion
  2761. LISet32(liSeekThisTime, -lSeekThisTime);
  2762. hr = pvsnRootNewChildStream->Seek(
  2763. liSeekThisTime,
  2764. STREAM_SEEK_END,
  2765. &uli);
  2766. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2767. ulCurrentPosition = ULIGetLow(uli);
  2768. }
  2769. }
  2770. if(S_OK == hr)
  2771. {
  2772. DH_TRACE((
  2773. DH_LVL_TRACE1,
  2774. TEXT("VirtualStmNode::Seek completed successfully.")));
  2775. }
  2776. else
  2777. {
  2778. DH_TRACE((
  2779. DH_LVL_TRACE1,
  2780. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2781. hr));
  2782. }
  2783. if(S_OK == hr)
  2784. {
  2785. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2786. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2787. hr = pvsnRootNewChildStream->Seek(
  2788. liStreamPos,
  2789. STREAM_SEEK_END,
  2790. &uli);
  2791. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2792. ulCurrentPosition = ULIGetLow(uli);
  2793. }
  2794. if(S_OK == hr)
  2795. {
  2796. DH_TRACE((
  2797. DH_LVL_TRACE1,
  2798. TEXT("VirtualStmNode::Seek completed successfully.")));
  2799. }
  2800. else
  2801. {
  2802. DH_TRACE((
  2803. DH_LVL_TRACE1,
  2804. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2805. hr));
  2806. }
  2807. //loop through the entire IStream, each time seeking relative to the
  2808. //current seek pointer (STREAM_SEEK_CUR). The distance to seek is a
  2809. //random ushort or a random block size chosen from ausSIZE_ARRAY[].
  2810. //This loop seeks in a negative direction.
  2811. lSeekThisTime = 0;
  2812. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2813. while ((ulCurrentPosition != 0) && (S_OK == hr))
  2814. {
  2815. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2816. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2817. // if generated seek offset would cause a seek to before beginning
  2818. // of file, ensure that it won't do that by enforcing to seek to
  2819. // the beginnining.
  2820. if(S_OK == hr)
  2821. {
  2822. if(lSeekThisTime > (LONG) ulCurrentPosition)
  2823. {
  2824. lSeekThisTime = (LONG) ulCurrentPosition;
  2825. }
  2826. // Unary minus operation is applied to seek offset to cause a neg
  2827. // seek opeartion
  2828. LISet32(liSeekThisTime, -lSeekThisTime);
  2829. hr = pvsnRootNewChildStream->Seek(
  2830. liSeekThisTime,
  2831. STREAM_SEEK_CUR,
  2832. &uli);
  2833. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2834. ulCurrentPosition = ULIGetLow(uli);
  2835. }
  2836. }
  2837. if(S_OK == hr)
  2838. {
  2839. DH_TRACE((
  2840. DH_LVL_TRACE1,
  2841. TEXT("VirtualStmNode::Seek completed successfully.")));
  2842. }
  2843. else
  2844. {
  2845. DH_TRACE((
  2846. DH_LVL_TRACE1,
  2847. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2848. hr));
  2849. }
  2850. if(S_OK == hr)
  2851. {
  2852. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  2853. memset(&uli, 0, sizeof(LARGE_INTEGER));
  2854. hr = pvsnRootNewChildStream->Seek(
  2855. liStreamPos,
  2856. STREAM_SEEK_SET,
  2857. &uli);
  2858. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  2859. ulCurrentPosition = ULIGetLow(uli);
  2860. }
  2861. if(S_OK == hr)
  2862. {
  2863. DH_TRACE((
  2864. DH_LVL_TRACE1,
  2865. TEXT("VirtualStmNode::Seek completed successfully.")));
  2866. }
  2867. else
  2868. {
  2869. DH_TRACE((
  2870. DH_LVL_TRACE1,
  2871. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2872. hr));
  2873. }
  2874. // Peform random number of seeks before beginning of the stream.
  2875. if (S_OK == hr)
  2876. {
  2877. // Generate random number of variations to be done.
  2878. usErr = pdgi->Generate(&cNumVars, cMinVars, cMaxVars);
  2879. if (DG_RC_SUCCESS != usErr)
  2880. {
  2881. hr = E_FAIL;
  2882. }
  2883. }
  2884. if(S_OK == hr)
  2885. {
  2886. while((cNumVars--) && (S_OK == hr))
  2887. {
  2888. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2889. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2890. if(S_OK == hr)
  2891. {
  2892. // Unary minus operation is applied to seek offset to cause a
  2893. // negative seek opeartion
  2894. LISet32(liSeekThisTime, -lSeekThisTime);
  2895. hr = pvsnRootNewChildStream->Seek(
  2896. liSeekThisTime,
  2897. STREAM_SEEK_CUR,
  2898. &uli);
  2899. ulCurrentPosition = ULIGetLow(uli);
  2900. if(S_OK == hr)
  2901. {
  2902. DH_TRACE((
  2903. DH_LVL_TRACE1,
  2904. TEXT("Seek to pos - %ld on IStream should have failed."),
  2905. lSeekThisTime));
  2906. fPass = FALSE;
  2907. break;
  2908. }
  2909. else
  2910. {
  2911. DH_TRACE((
  2912. DH_LVL_TRACE1,
  2913. TEXT("Seek pos -%ld on IStream failed as exp, hr=0x%lx."),
  2914. lSeekThisTime,
  2915. hr));
  2916. hr = S_OK;
  2917. }
  2918. }
  2919. }
  2920. }
  2921. // Now perform large offset seeks on IStream and the try to write 1 byte
  2922. // at the last offset if g_fDoLargeSeekAndWrite is set.
  2923. if (S_OK == hr)
  2924. {
  2925. // Generate random number of variations to be done.
  2926. usErr = pdgi->Generate(&cNumVars, cMinVars, cMaxVars);
  2927. if (DG_RC_SUCCESS != usErr)
  2928. {
  2929. hr = E_FAIL;
  2930. }
  2931. }
  2932. if(S_OK == hr)
  2933. {
  2934. while((cNumVars--) && (S_OK == hr))
  2935. {
  2936. hr = GetRandomSeekOffset(&lSeekThisTime, pdgi);
  2937. DH_HRCHECK(hr, TEXT("GetRandomSeekOffset")) ;
  2938. if(S_OK == hr)
  2939. {
  2940. LISet32(liSeekThisTime, lSeekThisTime);
  2941. hr = pvsnRootNewChildStream->Seek(
  2942. liSeekThisTime,
  2943. STREAM_SEEK_SET,
  2944. &uli);
  2945. ulCurrentPosition = ULIGetLow(uli);
  2946. }
  2947. }
  2948. }
  2949. if(S_OK == hr)
  2950. {
  2951. DH_TRACE((
  2952. DH_LVL_TRACE1,
  2953. TEXT("VirtualStmNode::Seek completed successfully.")));
  2954. }
  2955. else
  2956. {
  2957. DH_TRACE((
  2958. DH_LVL_TRACE1,
  2959. TEXT("VirtualStmNode::Seek not successful, hr=0x%lx."),
  2960. hr));
  2961. }
  2962. // Now atempt to write
  2963. LPTSTR ptszSample = TEXT("Test");
  2964. if((TRUE == g_fDoLargeSeekAndWrite) && (S_OK == hr))
  2965. {
  2966. hr = pvsnRootNewChildStream->Write(
  2967. ptszSample,
  2968. 1,
  2969. NULL);
  2970. if((S_OK == hr) ||
  2971. (STG_E_MEDIUMFULL == hr) ||
  2972. (STG_E_INSUFFICIENTMEMORY == hr))
  2973. {
  2974. DH_TRACE((DH_LVL_TRACE1,
  2975. TEXT("Attempt to write 1 byte at offset %lu, hr = 0x%lx"),
  2976. ulCurrentPosition,
  2977. hr));
  2978. hr = S_OK;
  2979. }
  2980. else
  2981. {
  2982. DH_TRACE((DH_LVL_TRACE1,
  2983. TEXT("Attempt to write 1 byte ar offset %lu, hr = 0x%lx"),
  2984. ulCurrentPosition,
  2985. hr));
  2986. }
  2987. }
  2988. // Release root's child stream
  2989. if (NULL != pvsnRootNewChildStream)
  2990. {
  2991. hr = pvsnRootNewChildStream->Close();
  2992. if (S_OK == hr)
  2993. {
  2994. DH_TRACE((
  2995. DH_LVL_TRACE1,
  2996. TEXT("VirtualStmNode::Close completed successfully.")));
  2997. }
  2998. else
  2999. {
  3000. DH_TRACE((
  3001. DH_LVL_TRACE1,
  3002. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3003. hr));
  3004. }
  3005. }
  3006. // Release root
  3007. if (NULL != pVirtualDFRoot)
  3008. {
  3009. hr = pVirtualDFRoot->Close();
  3010. if (S_OK == hr)
  3011. {
  3012. DH_TRACE((
  3013. DH_LVL_TRACE1,
  3014. TEXT("VirtualCtrNode::Close completed successfully.")));
  3015. }
  3016. else
  3017. {
  3018. DH_TRACE((
  3019. DH_LVL_TRACE1,
  3020. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3021. hr));
  3022. }
  3023. }
  3024. // if everything goes well, log test as passed else failed.
  3025. if((S_OK == hr) && (TRUE == fPass))
  3026. {
  3027. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_104 passed.")) );
  3028. }
  3029. else
  3030. {
  3031. DH_LOG((LOG_FAIL,
  3032. TEXT("Test variation STMTEST_104 failed, hr=0x%lx."),
  3033. hr) );
  3034. // test failed. make it look like it failed.
  3035. hr = FirstError (hr, E_FAIL);
  3036. }
  3037. // Cleanup
  3038. CleanupTestDocfile (&pVirtualDFRoot,
  3039. &pTestVirtualDF,
  3040. &pTestChanceDF,
  3041. S_OK == hr);
  3042. // Delete strings
  3043. if(NULL != pRootNewChildStmName)
  3044. {
  3045. delete pRootNewChildStmName;
  3046. pRootNewChildStmName = NULL;
  3047. }
  3048. // Stop logging the test
  3049. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_104 finished")) );
  3050. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3051. return hr;
  3052. }
  3053. //----------------------------------------------------------------------------
  3054. //
  3055. // Test: STMTEST_105
  3056. //
  3057. // Synopsis: The test create a root docfile with a child IStream. Write a
  3058. // random number of bytes to the IStream and commit the root
  3059. // docfile.
  3060. //
  3061. // The test seeks to a position before the end of the IStream,
  3062. // SetSizes() the IStream to a size less than the current seek
  3063. // pointer position. The root docfile is committed. Verify that
  3064. // the seek pointer didn't change during the SetSize() call. Now
  3065. // write 0 bytes at the current seek pointer position(which is
  3066. // beyond the end of the IStream). The seek pointer still should
  3067. // not move and no error should occur. Finally, seek to the end of
  3068. // the IStream and verify the correct IStream size, then stream and
  3069. // the root docfile are released and the root file is deleted upon
  3070. // success.
  3071. //
  3072. // Arguments:[argc]
  3073. // [argv]
  3074. //
  3075. // Returns: HRESULT
  3076. //
  3077. // Notes: This test runs in direct, transacted, and transacted deny write
  3078. // modes
  3079. //
  3080. // New Test Notes:
  3081. // 1. Old File(s): LSETSIZA.CXX
  3082. // 2. Old name of test(s) : LegitStreamSetSizeAbandon test
  3083. // New Name of test(s) : STMTEST_105
  3084. // 3. To run the test, do the following at command prompt.
  3085. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-105
  3086. // /dfRootMode:dirReadWriteShEx
  3087. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-105
  3088. // /dfRootMode:xactReadWriteShEx
  3089. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-105
  3090. // /dfRootMode:xactReadWriteShDenyW
  3091. //
  3092. // History: Jiminli 16-July-96 Created
  3093. //
  3094. // BUGNOTE: Conversion: STMTEST-105
  3095. //
  3096. //-----------------------------------------------------------------------------
  3097. HRESULT STMTEST_105(int argc, char *argv[])
  3098. {
  3099. HRESULT hr = S_OK;
  3100. ChanceDF *pTestChanceDF = NULL;
  3101. VirtualDF *pTestVirtualDF = NULL;
  3102. VirtualCtrNode *pVirtualDFRoot = NULL;
  3103. DG_STRING *pdgu = NULL;
  3104. DG_INTEGER *pdgi = NULL;
  3105. USHORT usErr = 0;
  3106. VirtualStmNode *pvsnRootNewChildStream = NULL;
  3107. LPTSTR pRootNewChildStmName = NULL;
  3108. LPTSTR ptcsBuffer = NULL;
  3109. ULONG culBytesLeftToWrite = 0;
  3110. ULONG culWritten = 0;
  3111. ULONG culRead = 0;
  3112. DWORD dwRootMode = 0;
  3113. ULONG culRandIOBytes = 0;
  3114. ULONG ulRandOffset = 0;
  3115. ULONG ulOriginalPosition = 0;
  3116. ULONG ulNewPosition = 0;
  3117. ULONG ulSizeParam = 0;
  3118. BOOL fPass = TRUE;
  3119. ULARGE_INTEGER uli;
  3120. ULARGE_INTEGER uliOffset;
  3121. LARGE_INTEGER liStreamPos;
  3122. LARGE_INTEGER liOffset;
  3123. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_105"));
  3124. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3125. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_105 started.")) );
  3126. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt SetSize using the IStream interface.")) );
  3127. // Create our ChanceDF and VirtualDF
  3128. hr = CreateTestDocfile (argc,
  3129. argv,
  3130. &pVirtualDFRoot,
  3131. &pTestVirtualDF,
  3132. &pTestChanceDF);
  3133. // if creating the docfile - bail here
  3134. if (NULL != pTestChanceDF && DoingCreate ())
  3135. {
  3136. UINT ulSeed = pTestChanceDF->GetSeed ();
  3137. CleanupTestDocfile (&pVirtualDFRoot,
  3138. &pTestVirtualDF,
  3139. &pTestChanceDF,
  3140. FALSE);
  3141. return (HRESULT)ulSeed;
  3142. }
  3143. if (S_OK == hr)
  3144. {
  3145. dwRootMode = pTestChanceDF->GetRootMode();
  3146. DH_TRACE((
  3147. DH_LVL_TRACE1,
  3148. TEXT("Run Mode for STMTEST_105, Access mode: %lx"),
  3149. dwRootMode));
  3150. }
  3151. // Get DG_STRING object pointer
  3152. if (S_OK == hr)
  3153. {
  3154. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3155. DH_ASSERT(NULL != pdgu) ;
  3156. if(NULL == pdgu)
  3157. {
  3158. hr = E_FAIL;
  3159. }
  3160. }
  3161. // Get DG_INTEGER object pointer
  3162. if (S_OK == hr)
  3163. {
  3164. pdgi = pTestVirtualDF->GetDataGenInteger();
  3165. DH_ASSERT(NULL != pdgi);
  3166. if(NULL == pdgi)
  3167. {
  3168. hr = E_FAIL;
  3169. }
  3170. }
  3171. // Adds a new stream to the root storage.
  3172. if(S_OK == hr)
  3173. {
  3174. // Generate random name for stream
  3175. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  3176. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3177. }
  3178. if(S_OK == hr)
  3179. {
  3180. hr = AddStream(
  3181. pTestVirtualDF,
  3182. pVirtualDFRoot,
  3183. pRootNewChildStmName,
  3184. 0,
  3185. STGM_READWRITE |
  3186. STGM_SHARE_EXCLUSIVE |
  3187. STGM_FAILIFTHERE,
  3188. &pvsnRootNewChildStream);
  3189. DH_HRCHECK(hr, TEXT("AddStream")) ;
  3190. }
  3191. if(S_OK == hr)
  3192. {
  3193. DH_TRACE((
  3194. DH_LVL_TRACE1,
  3195. TEXT("VirtualStmNode::AddStream completed successfully.")));
  3196. }
  3197. else
  3198. {
  3199. DH_TRACE((
  3200. DH_LVL_TRACE1,
  3201. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  3202. hr));
  3203. }
  3204. if (S_OK == hr)
  3205. {
  3206. // Generate random size for stream between 4L, and MIN_SIZE * 1.5
  3207. // (from old test)
  3208. usErr = pdgi->Generate(&culBytesLeftToWrite,4L,(ULONG)(MIN_SIZE * 1.5));
  3209. if (DG_RC_SUCCESS != usErr)
  3210. {
  3211. hr = E_FAIL;
  3212. }
  3213. }
  3214. if (S_OK == hr)
  3215. {
  3216. // Generate random number of bytes to write per chunk b/w
  3217. // RAND_IO_MIN and RAND_IO_MAX.
  3218. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  3219. if (DG_RC_SUCCESS != usErr)
  3220. {
  3221. hr = E_FAIL;
  3222. }
  3223. }
  3224. // Loop to write new IStream in culRandIOBytes size chunks unless size
  3225. // remaining to write is less than culRandIOBytes, then write the
  3226. // remaining bytes. CRC is not important for this test, so no check for it.
  3227. while ((S_OK == hr) && (0 != culBytesLeftToWrite))
  3228. {
  3229. if (culBytesLeftToWrite > culRandIOBytes)
  3230. {
  3231. culBytesLeftToWrite = culBytesLeftToWrite - culRandIOBytes;
  3232. }
  3233. else
  3234. {
  3235. culRandIOBytes = culBytesLeftToWrite;
  3236. culBytesLeftToWrite = 0;
  3237. }
  3238. // Call VirtualStmNode::Write to create random bytes in the stream. For
  3239. // our test purposes, we generate a random string of size culRandIOBytes
  3240. // using GenerateRandomString function.
  3241. if (S_OK == hr)
  3242. {
  3243. hr = GenerateRandomString(
  3244. pdgu,
  3245. culRandIOBytes,
  3246. culRandIOBytes,
  3247. &ptcsBuffer);
  3248. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  3249. }
  3250. if (S_OK == hr)
  3251. {
  3252. hr = pvsnRootNewChildStream->Write(
  3253. ptcsBuffer,
  3254. culRandIOBytes,
  3255. &culWritten);
  3256. }
  3257. if (S_OK == hr)
  3258. {
  3259. DH_TRACE((
  3260. DH_LVL_TRACE1,
  3261. TEXT("IStream::Write function completed successfully.")));
  3262. }
  3263. else
  3264. {
  3265. DH_TRACE((
  3266. DH_LVL_TRACE1,
  3267. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  3268. hr));
  3269. }
  3270. // Delete temp buffer
  3271. if(NULL != ptcsBuffer)
  3272. {
  3273. delete []ptcsBuffer;
  3274. ptcsBuffer = NULL;
  3275. }
  3276. }
  3277. // Commit root. BUGBUG: Use random modes
  3278. if (S_OK == hr)
  3279. {
  3280. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3281. }
  3282. if (S_OK == hr)
  3283. {
  3284. DH_TRACE((
  3285. DH_LVL_TRACE1,
  3286. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3287. }
  3288. else
  3289. {
  3290. DH_TRACE((
  3291. DH_LVL_TRACE1,
  3292. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  3293. hr));
  3294. }
  3295. // Seek to the end of stream
  3296. if (S_OK == hr)
  3297. {
  3298. memset(&liStreamPos, 0, sizeof(LARGE_INTEGER));
  3299. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  3300. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3301. ulOriginalPosition = ULIGetLow(uli);
  3302. }
  3303. if (S_OK == hr)
  3304. {
  3305. DH_TRACE((
  3306. DH_LVL_TRACE1,
  3307. TEXT("VirtualStmNode::Seek completed Ok. EndofStream = %lu"),
  3308. ulOriginalPosition));
  3309. }
  3310. else
  3311. {
  3312. DH_TRACE((
  3313. DH_LVL_TRACE1,
  3314. TEXT("VirtualStmNode::Seek not Ok, hr=0x%lx. EndofStream = %lu"),
  3315. hr,
  3316. ulOriginalPosition));
  3317. }
  3318. // Seeking to a negative value from end
  3319. if (S_OK == hr)
  3320. {
  3321. usErr = pdgi->Generate(&ulRandOffset, 1L, ulOriginalPosition / 2);
  3322. if (DG_RC_SUCCESS != usErr)
  3323. {
  3324. hr = E_FAIL;
  3325. }
  3326. else
  3327. {
  3328. DH_TRACE((
  3329. DH_LVL_TRACE1,
  3330. TEXT("Seek to end of IStream - %lu bytes"),
  3331. ulRandOffset));
  3332. }
  3333. }
  3334. if(S_OK == hr)
  3335. {
  3336. LISet32(liOffset, (- (LONG)ulRandOffset));
  3337. hr = pvsnRootNewChildStream->Seek(liOffset, STREAM_SEEK_END, &uli);
  3338. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3339. ulOriginalPosition = ULIGetLow(uli);
  3340. }
  3341. if (S_OK == hr)
  3342. {
  3343. DH_TRACE((
  3344. DH_LVL_TRACE1,
  3345. TEXT("VirtualStmNode::Seek completed Ok. New seek ptr=%lu"),
  3346. ulOriginalPosition));
  3347. }
  3348. else
  3349. {
  3350. DH_TRACE((
  3351. DH_LVL_TRACE1,
  3352. TEXT("IStream::Seek wasn't Ok, hr=0x%lx. New seek ptr=%lu"),
  3353. hr,
  3354. ulOriginalPosition));
  3355. }
  3356. // Generate number of bytes less than current seek pointer to
  3357. // SetSize the stream to.
  3358. if (S_OK == hr)
  3359. {
  3360. usErr = pdgi->Generate(&ulRandOffset, 1L, ulOriginalPosition / 2);
  3361. if (DG_RC_SUCCESS != usErr)
  3362. {
  3363. hr = E_FAIL;
  3364. }
  3365. else
  3366. {
  3367. DH_TRACE((
  3368. DH_LVL_TRACE1,
  3369. TEXT("Random offset(i.e. new size of stream) = %lu bytes"),
  3370. ulRandOffset));
  3371. }
  3372. }
  3373. if (S_OK == hr)
  3374. {
  3375. ulSizeParam = ulOriginalPosition - ulRandOffset;
  3376. ULISet32(uliOffset, ulSizeParam);
  3377. hr = pvsnRootNewChildStream->SetSize(uliOffset);
  3378. DH_HRCHECK(hr, TEXT("VirtualStmNode::SetSize")) ;
  3379. }
  3380. if (S_OK == hr)
  3381. {
  3382. DH_TRACE((
  3383. DH_LVL_TRACE1,
  3384. TEXT("VirtualStmNode::SetSize completed successfully. Size=%lu"),
  3385. ulSizeParam));
  3386. }
  3387. else
  3388. {
  3389. DH_TRACE((
  3390. DH_LVL_TRACE1,
  3391. TEXT("VirtualStmNode::SetSize unsuccessful, hr=0x%lx, Size=%lu"),
  3392. hr,
  3393. ulSizeParam));
  3394. }
  3395. // Commit root. BUGBUG: Use random modes
  3396. if (S_OK == hr)
  3397. {
  3398. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3399. }
  3400. if (S_OK == hr)
  3401. {
  3402. DH_TRACE((
  3403. DH_LVL_TRACE1,
  3404. TEXT("VirtualCtrNode::Commit completed successfully.")));
  3405. }
  3406. else
  3407. {
  3408. DH_TRACE((
  3409. DH_LVL_TRACE1,
  3410. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  3411. hr));
  3412. }
  3413. // Get current seek pointer, should be same as ulOriginalPosition
  3414. if (S_OK == hr)
  3415. {
  3416. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_CUR, &uli);
  3417. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3418. ulNewPosition = ULIGetLow(uli);
  3419. }
  3420. if (S_OK == hr)
  3421. {
  3422. DH_TRACE((
  3423. DH_LVL_TRACE1,
  3424. TEXT("VirtualStmNode::Seek completed successfully. Seek ptr=%lu"),
  3425. ulNewPosition));
  3426. }
  3427. else
  3428. {
  3429. DH_TRACE((
  3430. DH_LVL_TRACE1,
  3431. TEXT("VirtualStmNode::Seek not Ok, hr=0x%lx, seek ptr=%lu"),
  3432. hr,
  3433. ulNewPosition));
  3434. }
  3435. if (S_OK == hr)
  3436. {
  3437. if (ulOriginalPosition != ulNewPosition)
  3438. {
  3439. DH_TRACE((
  3440. DH_LVL_TRACE1,
  3441. TEXT("VirtualCtrNode::SetSize changed seek ptr position.")));
  3442. fPass = FALSE;
  3443. }
  3444. else
  3445. {
  3446. DH_TRACE((
  3447. DH_LVL_TRACE1,
  3448. TEXT("Ok, VirtualCtrNode::SetSize not change seek ptr.")));
  3449. }
  3450. }
  3451. // Tset 0 byte write beyond end of IStream, shouldn't move seek pointer
  3452. if (S_OK == hr)
  3453. {
  3454. hr = GenerateRandomString(
  3455. pdgu,
  3456. 0,
  3457. 0,
  3458. &ptcsBuffer);
  3459. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  3460. }
  3461. if (S_OK == hr)
  3462. {
  3463. hr = pvsnRootNewChildStream->Write(
  3464. ptcsBuffer,
  3465. 0,
  3466. &culWritten);
  3467. }
  3468. if (S_OK == hr)
  3469. {
  3470. DH_TRACE((
  3471. DH_LVL_TRACE1,
  3472. TEXT("IStream::Write function completed successfully.")));
  3473. }
  3474. else
  3475. {
  3476. DH_TRACE((
  3477. DH_LVL_TRACE1,
  3478. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  3479. hr));
  3480. }
  3481. // Delete temp buffer
  3482. if (NULL != ptcsBuffer)
  3483. {
  3484. delete []ptcsBuffer;
  3485. ptcsBuffer = NULL;
  3486. }
  3487. // Get current seek pointer, should be same as ulOriginalPosition
  3488. if (S_OK == hr)
  3489. {
  3490. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_CUR, &uli);
  3491. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3492. ulNewPosition = ULIGetLow(uli);
  3493. }
  3494. if (S_OK == hr)
  3495. {
  3496. DH_TRACE((
  3497. DH_LVL_TRACE1,
  3498. TEXT("VirtualStmNode::Seek completed successfully. Seek ptr=%lu"),
  3499. ulNewPosition));
  3500. }
  3501. else
  3502. {
  3503. DH_TRACE((
  3504. DH_LVL_TRACE1,
  3505. TEXT("VirtualStmNode::Seek not Ok, hr=0x%lx, Seek ptr=%lu"),
  3506. hr,
  3507. ulNewPosition));
  3508. }
  3509. if (S_OK == hr)
  3510. {
  3511. if (ulOriginalPosition != ulNewPosition)
  3512. {
  3513. DH_TRACE((
  3514. DH_LVL_TRACE1,
  3515. TEXT("0 byte write changed seek pointer position.")));
  3516. fPass = FALSE;
  3517. }
  3518. else
  3519. {
  3520. DH_TRACE((
  3521. DH_LVL_TRACE1,
  3522. TEXT("Ok, 0 byte write not change seek pointer position.")));
  3523. }
  3524. }
  3525. // Verify correct end of IStream
  3526. if (S_OK == hr)
  3527. {
  3528. hr = pvsnRootNewChildStream->Seek(liStreamPos, STREAM_SEEK_END, &uli);
  3529. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3530. ulNewPosition = ULIGetLow(uli);
  3531. }
  3532. if (S_OK == hr)
  3533. {
  3534. DH_TRACE((
  3535. DH_LVL_TRACE1,
  3536. TEXT("VirtualStmNode::Seek completed successfully. EndofStm=%lu"),
  3537. ulNewPosition));
  3538. }
  3539. else
  3540. {
  3541. DH_TRACE((
  3542. DH_LVL_TRACE1,
  3543. TEXT("VirtualStmNode::Seek not Ok, hr=0x%lx, EndofStm=%lu"),
  3544. hr,
  3545. ulNewPosition));
  3546. }
  3547. if (S_OK == hr)
  3548. {
  3549. if (ulSizeParam != ulNewPosition)
  3550. {
  3551. DH_TRACE((
  3552. DH_LVL_TRACE1,
  3553. TEXT("Seek to end is not same position as SetSize().")));
  3554. fPass = FALSE;
  3555. }
  3556. else
  3557. {
  3558. DH_TRACE((
  3559. DH_LVL_TRACE1,
  3560. TEXT("Ok, Seek to end is the same position as SetSize().")));
  3561. }
  3562. }
  3563. // Release stream
  3564. if (S_OK == hr)
  3565. {
  3566. hr = pvsnRootNewChildStream->Close();
  3567. }
  3568. if (S_OK == hr)
  3569. {
  3570. DH_TRACE((
  3571. DH_LVL_TRACE1,
  3572. TEXT("VirtualStmNode::Close completed successfully.")));
  3573. }
  3574. else
  3575. {
  3576. DH_TRACE((
  3577. DH_LVL_TRACE1,
  3578. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  3579. hr));
  3580. }
  3581. // Release Root
  3582. if (S_OK == hr)
  3583. {
  3584. hr = pVirtualDFRoot->Close();
  3585. }
  3586. if (S_OK == hr)
  3587. {
  3588. DH_TRACE((
  3589. DH_LVL_TRACE1,
  3590. TEXT("VirtualCtrNode::Close completed successfully.")));
  3591. }
  3592. else
  3593. {
  3594. DH_TRACE((
  3595. DH_LVL_TRACE1,
  3596. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  3597. hr));
  3598. }
  3599. // if everything goes well, log test as passed else failed.
  3600. if ((S_OK == hr) && (TRUE == fPass))
  3601. {
  3602. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_105 passed.")) );
  3603. }
  3604. else
  3605. {
  3606. DH_LOG((LOG_FAIL,
  3607. TEXT("Test variation STMTEST_105 failed, hr=0x%lx."),
  3608. hr));
  3609. // test failed. make it look like it failed.
  3610. hr = FirstError (hr, E_FAIL);
  3611. }
  3612. // Cleanup
  3613. CleanupTestDocfile (&pVirtualDFRoot,
  3614. &pTestVirtualDF,
  3615. &pTestChanceDF,
  3616. S_OK == hr);
  3617. // Delete strings
  3618. if (NULL != pRootNewChildStmName)
  3619. {
  3620. delete pRootNewChildStmName;
  3621. pRootNewChildStmName = NULL;
  3622. }
  3623. // Stop logging the test
  3624. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_105 finished")) );
  3625. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3626. return hr;
  3627. }
  3628. //----------------------------------------------------------------------------
  3629. //
  3630. // Test: STMTEST_106
  3631. //
  3632. // Synopsis: The test create a root docfile with a child IStream. 3 random
  3633. // SECTORSIZE byte blocks are generated and the CRC is computed.
  3634. // The data is written to the IStream. then the IStream is
  3635. // rewound and read back, and the CRC returned from the read is
  3636. // compared with the CRC when written. The seek pointer is changed
  3637. // to an offset somewhere in the first sector, but not the first
  3638. // or last byte. A SECTORSIZE block of the in-memory buffer is
  3639. // changed starting at the same offset used for the seek. The CRC
  3640. // is computed for the entire memory buffer. The block is written
  3641. // to the IStream, the IStream is rewound, read, and the CRCs are
  3642. // again compared. Finally, the root docfile is committed and the
  3643. // read/CRC compare is repeated. Then stream and the root docfile
  3644. // are released and the root file is deleted upon success.
  3645. //
  3646. //
  3647. // Arguments:[argc]
  3648. // [argv]
  3649. //
  3650. // Returns: HRESULT
  3651. //
  3652. // Notes: This test runs in direct, transacted, and transacted deny write
  3653. // modes
  3654. //
  3655. // New Test Notes:
  3656. // 1. Old File(s): LSECTSPN.CXX
  3657. // 2. Old name of test(s) : LegitStreamSectorSpan test
  3658. // New Name of test(s) : STMTEST_106
  3659. // 3. To run the test, do the following at command prompt.
  3660. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-106
  3661. // /dfRootMode:dirReadWriteShEx
  3662. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-106
  3663. // /dfRootMode:xactReadWriteShEx
  3664. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-106
  3665. // /dfRootMode:xactReadWriteShDenyW
  3666. //
  3667. // History: Jiminli 18-July-96 Created
  3668. //
  3669. // BUGNOTE: Conversion: STMTEST-106
  3670. //
  3671. //-----------------------------------------------------------------------------
  3672. HRESULT STMTEST_106(int argc, char *argv[])
  3673. {
  3674. HRESULT hr = S_OK;
  3675. ChanceDF *pTestChanceDF = NULL;
  3676. VirtualDF *pTestVirtualDF = NULL;
  3677. VirtualCtrNode *pVirtualDFRoot = NULL;
  3678. DG_STRING *pdgu = NULL;
  3679. DG_INTEGER *pdgi = NULL;
  3680. USHORT usErr = 0;
  3681. VirtualStmNode *pvsnRootNewChildStream = NULL;
  3682. LPTSTR pRootNewChildStmName = NULL;
  3683. LPTSTR ptTempBuf1 = NULL;
  3684. LPTSTR ptTempBuf2 = NULL;
  3685. LPBYTE ptcsBuffer = NULL;
  3686. LPBYTE ptcsDataBuffer = NULL;
  3687. ULONG culNumBytes = 0;
  3688. ULONG culWritten = 0;
  3689. ULONG ulRandOffset = 0;
  3690. ULONG culRead = 0;
  3691. ULONG index1 = 0;
  3692. ULONG index2 = 0;
  3693. DWORD dwRootMode = 0;
  3694. DWORD dwBufCRC = 0;
  3695. DWORD dwActCRC = 0;
  3696. BOOL fPass = TRUE;
  3697. LARGE_INTEGER liZero;
  3698. LARGE_INTEGER liOffset;
  3699. ULARGE_INTEGER uli;
  3700. ULONG ulOriginalPosition = 0;
  3701. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_106"));
  3702. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  3703. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_106 started.")) );
  3704. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt SectorSpan using the Stm interface.")) );
  3705. // Create our ChanceDF and VirtualDF
  3706. hr = CreateTestDocfile (argc,
  3707. argv,
  3708. &pVirtualDFRoot,
  3709. &pTestVirtualDF,
  3710. &pTestChanceDF);
  3711. // if creating the docfile - bail here
  3712. if (NULL != pTestChanceDF && DoingCreate ())
  3713. {
  3714. UINT ulSeed = pTestChanceDF->GetSeed ();
  3715. CleanupTestDocfile (&pVirtualDFRoot,
  3716. &pTestVirtualDF,
  3717. &pTestChanceDF,
  3718. FALSE);
  3719. return (HRESULT)ulSeed;
  3720. }
  3721. if (S_OK == hr)
  3722. {
  3723. dwRootMode = pTestChanceDF->GetRootMode();
  3724. DH_TRACE((
  3725. DH_LVL_TRACE1,
  3726. TEXT("Run Mode for STMTEST_106, Access mode: %lx"),
  3727. dwRootMode));
  3728. }
  3729. // Get DG_STRING object pointer
  3730. if (S_OK == hr)
  3731. {
  3732. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3733. DH_ASSERT(NULL != pdgu) ;
  3734. if(NULL == pdgu)
  3735. {
  3736. hr = E_FAIL;
  3737. }
  3738. }
  3739. // Get DG_INTEGER object pointer
  3740. if (S_OK == hr)
  3741. {
  3742. pdgi = pTestVirtualDF->GetDataGenInteger();
  3743. DH_ASSERT(NULL != pdgi) ;
  3744. if(NULL == pdgi)
  3745. {
  3746. hr = E_FAIL;
  3747. }
  3748. }
  3749. // Adds a new stream to the root storage.
  3750. if (S_OK == hr)
  3751. {
  3752. // Generate random name for stream
  3753. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  3754. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3755. }
  3756. if (S_OK == hr)
  3757. {
  3758. hr = AddStream(
  3759. pTestVirtualDF,
  3760. pVirtualDFRoot,
  3761. pRootNewChildStmName,
  3762. 0,
  3763. STGM_READWRITE |
  3764. STGM_SHARE_EXCLUSIVE |
  3765. STGM_FAILIFTHERE,
  3766. &pvsnRootNewChildStream);
  3767. DH_HRCHECK(hr, TEXT("AddStream")) ;
  3768. }
  3769. if (S_OK == hr)
  3770. {
  3771. DH_TRACE((
  3772. DH_LVL_TRACE1,
  3773. TEXT("VirtualStmNode::AddStream completed successfully.")));
  3774. }
  3775. else
  3776. {
  3777. DH_TRACE((
  3778. DH_LVL_TRACE1,
  3779. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  3780. hr));
  3781. }
  3782. // Generate three sectors worth of random bytes and compute CRC
  3783. // then write the bytes to the IStream, rewind IStream, then read
  3784. // back the data and compare CRCs to ensure valid write/read
  3785. if (S_OK == hr)
  3786. {
  3787. // Generate a random string of size culNumBytes
  3788. culNumBytes = SECTORSIZE * 3;
  3789. hr = GenerateRandomString(
  3790. pdgu,
  3791. culNumBytes,
  3792. culNumBytes,
  3793. &ptTempBuf1);
  3794. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  3795. }
  3796. if (S_OK == hr)
  3797. {
  3798. // Let ptcsBuffer point to temporary buffer(for purpose of
  3799. // type casting, because IStream:Seek proceeds by BYTE)
  3800. ptcsBuffer = (LPBYTE)ptTempBuf1;
  3801. hr = CalculateCRCForDataBuffer(
  3802. (LPTSTR)ptcsBuffer,
  3803. culNumBytes,
  3804. &dwBufCRC);
  3805. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3806. }
  3807. if (S_OK == hr)
  3808. {
  3809. hr = pvsnRootNewChildStream->Write(
  3810. ptcsBuffer,
  3811. culNumBytes,
  3812. &culWritten);
  3813. }
  3814. if (S_OK == hr)
  3815. {
  3816. DH_TRACE((
  3817. DH_LVL_TRACE1,
  3818. TEXT("VirtualStmNode::Write function completed successfully.")));
  3819. }
  3820. else
  3821. {
  3822. DH_TRACE((
  3823. DH_LVL_TRACE1,
  3824. TEXT("VirtualStmNode::Write function not successful, hr=0x%lx."),
  3825. hr));
  3826. }
  3827. // Allocate required space
  3828. if (S_OK == hr)
  3829. {
  3830. ptcsDataBuffer = new BYTE[culNumBytes];
  3831. if (NULL == ptcsDataBuffer)
  3832. {
  3833. hr = E_OUTOFMEMORY;
  3834. }
  3835. }
  3836. if (S_OK == hr)
  3837. {
  3838. memset(ptcsDataBuffer, '\0', culNumBytes * sizeof(BYTE));
  3839. while (culNumBytes--)
  3840. {
  3841. ptcsDataBuffer[index1] = ptcsBuffer[index1];
  3842. index1++;
  3843. }
  3844. culNumBytes = SECTORSIZE * 3;
  3845. }
  3846. // delete temp buffer (ptcsBuffer and ptTempBuf1 point to the same memory)
  3847. if (NULL != ptcsBuffer)
  3848. {
  3849. delete []ptcsBuffer;
  3850. ptcsBuffer = NULL;
  3851. ptTempBuf1 = NULL;
  3852. }
  3853. if (S_OK == hr)
  3854. {
  3855. LISet32(liZero, 0L);
  3856. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  3857. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  3858. }
  3859. if (S_OK == hr)
  3860. {
  3861. DH_TRACE((
  3862. DH_LVL_TRACE1,
  3863. TEXT("VirtualStmNode::Seek function completed successfully.")));
  3864. }
  3865. else
  3866. {
  3867. DH_TRACE((
  3868. DH_LVL_TRACE1,
  3869. TEXT("VirtualStmNode::Seek function not successful, hr=0x%lx."),
  3870. hr));
  3871. }
  3872. if (S_OK == hr)
  3873. {
  3874. ptcsBuffer = new BYTE[culNumBytes];
  3875. if (NULL == ptcsBuffer)
  3876. {
  3877. hr = E_OUTOFMEMORY;
  3878. }
  3879. }
  3880. if (S_OK == hr)
  3881. {
  3882. memset(ptcsBuffer, '\0', culNumBytes * sizeof(BYTE));
  3883. hr = pvsnRootNewChildStream->Read(
  3884. ptcsBuffer,
  3885. culNumBytes,
  3886. &culRead);
  3887. }
  3888. if (S_OK == hr)
  3889. {
  3890. DH_TRACE((
  3891. DH_LVL_TRACE1,
  3892. TEXT("VirtualStmNode::Read function completed successfully.")));
  3893. }
  3894. else
  3895. {
  3896. DH_TRACE((
  3897. DH_LVL_TRACE1,
  3898. TEXT("VirtualStmNode::Read function not successful, hr=0x%lx."),
  3899. hr));
  3900. }
  3901. if (S_OK == hr)
  3902. {
  3903. hr = CalculateCRCForDataBuffer(
  3904. (LPTSTR)ptcsBuffer,
  3905. culNumBytes,
  3906. &dwActCRC);
  3907. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  3908. }
  3909. // Compare CRCs
  3910. if (S_OK == hr)
  3911. {
  3912. if (dwBufCRC != dwActCRC)
  3913. {
  3914. DH_TRACE((
  3915. DH_LVL_TRACE1,
  3916. TEXT("IStream write/read mismatch before change, hr=0x%lx."),
  3917. hr));
  3918. fPass = FALSE;
  3919. }
  3920. else
  3921. {
  3922. DH_TRACE((
  3923. DH_LVL_TRACE1,
  3924. TEXT("IStream write/read matched before change.")));
  3925. }
  3926. }
  3927. // Delete temp buffer
  3928. if (NULL != ptcsBuffer)
  3929. {
  3930. delete []ptcsBuffer;
  3931. ptcsBuffer = NULL;
  3932. }
  3933. // Pick a random offset somewhere in the first sector, but not the first
  3934. // or last byte. Seek to the new position. Starting at the same offset in
  3935. // the in-memory buffer, replace 1 SECTORSIZE block with new random data.
  3936. // After the replace, re-compute the CRC for the entire buffer.
  3937. if (S_OK == hr)
  3938. {
  3939. usErr = pdgi->Generate(&ulRandOffset, 1, (SECTORSIZE - 1));
  3940. if (DG_RC_SUCCESS != usErr)
  3941. {
  3942. hr = E_FAIL;
  3943. }
  3944. else
  3945. {
  3946. DH_TRACE((
  3947. DH_LVL_TRACE1,
  3948. TEXT("Seek to position of the first SECTOR: %lu"),
  3949. (ULONG)ulRandOffset));
  3950. }
  3951. }
  3952. if (S_OK == hr)
  3953. {
  3954. LISet32(liOffset, ulRandOffset);
  3955. hr = pvsnRootNewChildStream->Seek(liOffset, STREAM_SEEK_SET, &uli);
  3956. DH_HRCHECK(hr, TEXT("VirtualStmNode::Seek")) ;
  3957. ulOriginalPosition = ULIGetLow(uli);
  3958. DH_TRACE((
  3959. DH_LVL_TRACE1,
  3960. TEXT("Seekpos = %lu"),
  3961. ulOriginalPosition));
  3962. }
  3963. if (S_OK == hr)
  3964. {
  3965. DH_TRACE((
  3966. DH_LVL_TRACE1,
  3967. TEXT("VirtualStmNode::Seek completed successfully.")));
  3968. }
  3969. else
  3970. {
  3971. DH_TRACE((
  3972. DH_LVL_TRACE1,
  3973. TEXT("IStream::Seek wasn't successful, hr=0x%lx."),
  3974. hr));
  3975. }
  3976. if (S_OK == hr)
  3977. {
  3978. // Generate a random string of size SECTORSIZE
  3979. hr = GenerateRandomString(
  3980. pdgu,
  3981. SECTORSIZE,
  3982. SECTORSIZE,
  3983. &ptTempBuf2);
  3984. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  3985. }
  3986. if (S_OK == hr)
  3987. {
  3988. // Let ptcsBuffer point to the temporary buffer(for purpose of
  3989. // typecasting, because IStream::Seek proceeds by BYTE)
  3990. ptcsBuffer = (LPBYTE)ptTempBuf2;
  3991. // Change the memory buffer ptcsDataBuffer
  3992. culNumBytes = SECTORSIZE;
  3993. index1 = ulRandOffset;
  3994. index2 = 0;
  3995. while (culNumBytes--)
  3996. {
  3997. ptcsDataBuffer[index1++] = ptcsBuffer[index2++];
  3998. }
  3999. culNumBytes = SECTORSIZE * 3;
  4000. // Calculate CRC for the changed buffer
  4001. hr = CalculateCRCForDataBuffer(
  4002. (LPTSTR)ptcsDataBuffer,
  4003. culNumBytes,
  4004. &dwBufCRC);
  4005. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  4006. }
  4007. if (S_OK == hr)
  4008. {
  4009. hr = pvsnRootNewChildStream->Write(
  4010. ptcsBuffer,
  4011. SECTORSIZE,
  4012. &culWritten);
  4013. }
  4014. if (S_OK == hr)
  4015. {
  4016. DH_TRACE((
  4017. DH_LVL_TRACE1,
  4018. TEXT("VirtualStmNode::Write function completed successfully.")));
  4019. }
  4020. else
  4021. {
  4022. DH_TRACE((
  4023. DH_LVL_TRACE1,
  4024. TEXT("VirtualStmNode::Write function not successful, hr=0x%lx."),
  4025. hr));
  4026. }
  4027. // delete temp buffer (ptcsBuffer and ptTempBuf2 point to the same memory)
  4028. if ( NULL != ptcsBuffer)
  4029. {
  4030. delete []ptcsBuffer;
  4031. ptcsBuffer = NULL;
  4032. ptTempBuf2 = NULL;
  4033. }
  4034. if (S_OK == hr)
  4035. {
  4036. memset(&liZero, 0, sizeof(LARGE_INTEGER));
  4037. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  4038. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  4039. }
  4040. if (S_OK == hr)
  4041. {
  4042. DH_TRACE((
  4043. DH_LVL_TRACE1,
  4044. TEXT("VirtualStmNode::Seek function completed successfully.")));
  4045. }
  4046. else
  4047. {
  4048. DH_TRACE((
  4049. DH_LVL_TRACE1,
  4050. TEXT("VirtualStmNode::Seek function not successful, hr=0x%lx."),
  4051. hr));
  4052. }
  4053. if (S_OK == hr)
  4054. {
  4055. ptcsBuffer = new BYTE[culNumBytes];
  4056. if (NULL == ptcsBuffer)
  4057. {
  4058. hr = E_OUTOFMEMORY;
  4059. }
  4060. }
  4061. if (S_OK == hr)
  4062. {
  4063. memset(ptcsBuffer, '\0', culNumBytes * sizeof(BYTE));
  4064. hr = pvsnRootNewChildStream->Read(
  4065. ptcsBuffer,
  4066. culNumBytes,
  4067. &culRead);
  4068. }
  4069. if (S_OK == hr)
  4070. {
  4071. DH_TRACE((
  4072. DH_LVL_TRACE1,
  4073. TEXT("VirtualStmNode::Read function completed successfully.")));
  4074. }
  4075. else
  4076. {
  4077. DH_TRACE((
  4078. DH_LVL_TRACE1,
  4079. TEXT("VirtualStmNode::Read function not successful, hr=0x%lx."),
  4080. hr));
  4081. }
  4082. if (S_OK == hr)
  4083. {
  4084. hr = CalculateCRCForDataBuffer(
  4085. (LPTSTR)ptcsBuffer,
  4086. culNumBytes,
  4087. &dwActCRC);
  4088. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  4089. }
  4090. // Compare CRCs
  4091. if (S_OK == hr)
  4092. {
  4093. if (dwBufCRC != dwActCRC)
  4094. {
  4095. DH_TRACE((
  4096. DH_LVL_TRACE1,
  4097. TEXT("IStream write/read mismatch after change, hr=0x%lx."),
  4098. hr));
  4099. fPass = FALSE;
  4100. }
  4101. else
  4102. {
  4103. DH_TRACE((
  4104. DH_LVL_TRACE1,
  4105. TEXT("IStream write/read matched after change.")));
  4106. }
  4107. }
  4108. // Commit root. BUGBUG: Use random modes
  4109. if (S_OK == hr)
  4110. {
  4111. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4112. }
  4113. if (S_OK == hr)
  4114. {
  4115. DH_TRACE((
  4116. DH_LVL_TRACE1,
  4117. TEXT("VirtualCtrNode::Commit completed successfully.")));
  4118. }
  4119. else
  4120. {
  4121. DH_TRACE((
  4122. DH_LVL_TRACE1,
  4123. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  4124. hr));
  4125. }
  4126. if ( NULL != ptcsBuffer)
  4127. {
  4128. delete []ptcsBuffer;
  4129. ptcsBuffer = NULL;
  4130. }
  4131. if (S_OK == hr)
  4132. {
  4133. memset(&liZero, 0, sizeof(LARGE_INTEGER));
  4134. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  4135. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  4136. }
  4137. if (S_OK == hr)
  4138. {
  4139. DH_TRACE((
  4140. DH_LVL_TRACE1,
  4141. TEXT("VirtualStmNode::Seek function completed successfully.")));
  4142. }
  4143. else
  4144. {
  4145. DH_TRACE((
  4146. DH_LVL_TRACE1,
  4147. TEXT("VirtualStmNode::Seek function not successful, hr=0x%lx."),
  4148. hr));
  4149. }
  4150. if (S_OK == hr)
  4151. {
  4152. ptcsBuffer = new BYTE[culNumBytes];
  4153. if (NULL == ptcsBuffer)
  4154. {
  4155. hr = E_OUTOFMEMORY;
  4156. }
  4157. }
  4158. if (S_OK == hr)
  4159. {
  4160. memset(ptcsBuffer, '\0', culNumBytes * sizeof(BYTE));
  4161. hr = pvsnRootNewChildStream->Read(
  4162. ptcsBuffer,
  4163. culNumBytes,
  4164. &culRead);
  4165. }
  4166. if (S_OK == hr)
  4167. {
  4168. DH_TRACE((
  4169. DH_LVL_TRACE1,
  4170. TEXT("VirtualStmNode::Read function completed successfully.")));
  4171. }
  4172. else
  4173. {
  4174. DH_TRACE((
  4175. DH_LVL_TRACE1,
  4176. TEXT("VirtualStmNode::Read function not successful, hr=0x%lx."),
  4177. hr));
  4178. }
  4179. if (S_OK == hr)
  4180. {
  4181. hr = CalculateCRCForDataBuffer(
  4182. (LPTSTR)ptcsBuffer,
  4183. culNumBytes,
  4184. &dwActCRC);
  4185. DH_HRCHECK(hr, TEXT("CalculateCRCForDataBuffer"));
  4186. }
  4187. // Compare CRCs
  4188. if (S_OK == hr)
  4189. {
  4190. if (dwBufCRC != dwActCRC)
  4191. {
  4192. DH_TRACE((
  4193. DH_LVL_TRACE1,
  4194. TEXT("IStream write/read mismatch after commit, hr=0x%lx."),
  4195. hr));
  4196. fPass = FALSE;
  4197. }
  4198. else
  4199. {
  4200. DH_TRACE((
  4201. DH_LVL_TRACE1,
  4202. TEXT("IStream write/read matched after commit.")));
  4203. }
  4204. }
  4205. // Delete temp buffers
  4206. if (NULL != ptcsDataBuffer)
  4207. {
  4208. delete []ptcsDataBuffer;
  4209. ptcsDataBuffer = NULL;
  4210. }
  4211. if (NULL != ptcsBuffer)
  4212. {
  4213. delete []ptcsBuffer;
  4214. ptcsBuffer = NULL;
  4215. }
  4216. // Release stream
  4217. if (S_OK == hr)
  4218. {
  4219. hr = pvsnRootNewChildStream->Close();
  4220. }
  4221. if (S_OK == hr)
  4222. {
  4223. DH_TRACE((
  4224. DH_LVL_TRACE1,
  4225. TEXT("VirtualStmNode::Close completed successfully.")));
  4226. }
  4227. else
  4228. {
  4229. DH_TRACE((
  4230. DH_LVL_TRACE1,
  4231. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  4232. hr));
  4233. }
  4234. // Release Root
  4235. if (S_OK == hr)
  4236. {
  4237. hr = pVirtualDFRoot->Close();
  4238. }
  4239. if (S_OK == hr)
  4240. {
  4241. DH_TRACE((
  4242. DH_LVL_TRACE1,
  4243. TEXT("VirtualCtrNode::Close completed successfully.")));
  4244. }
  4245. else
  4246. {
  4247. DH_TRACE((
  4248. DH_LVL_TRACE1,
  4249. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4250. hr));
  4251. }
  4252. // if everything goes well, log test as passed else failed.
  4253. if ((S_OK == hr) && (TRUE == fPass))
  4254. {
  4255. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_106 passed.")) );
  4256. }
  4257. else
  4258. {
  4259. DH_LOG((LOG_FAIL,
  4260. TEXT("Test variation STMTEST_106 failed, hr=0x%lx."),
  4261. hr));
  4262. // test failed. make it look like it failed.
  4263. hr = FirstError (hr, E_FAIL);
  4264. }
  4265. // Cleanup
  4266. CleanupTestDocfile (&pVirtualDFRoot,
  4267. &pTestVirtualDF,
  4268. &pTestChanceDF,
  4269. S_OK == hr);
  4270. // Delete strings
  4271. if (NULL != pRootNewChildStmName)
  4272. {
  4273. delete pRootNewChildStmName;
  4274. pRootNewChildStmName = NULL;
  4275. }
  4276. // Stop logging the test
  4277. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_106 finished")) );
  4278. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4279. return hr;
  4280. }
  4281. //----------------------------------------------------------------------------
  4282. //
  4283. // Test: STMTEST_107
  4284. //
  4285. // Synopsis: The test create a root docfile with a child IStream. Then perform
  4286. // various illegitimate operating using the IStream interface. The
  4287. // stream and the root docfile are then released and the root file
  4288. // is deleted upon success.
  4289. //
  4290. // Arguments:[argc]
  4291. // [argv]
  4292. //
  4293. // Returns: HRESULT
  4294. //
  4295. // Notes: This test runs in direct, transacted, and transacted deny write
  4296. // modes
  4297. //
  4298. // New Test Notes:
  4299. // 1. Old File(s): ISNORM.CXX
  4300. // 2. Old name of test(s) : IllegitStreamNorm test
  4301. // New Name of test(s) : STMTEST_107
  4302. // 3. To run the test, do the following at command prompt.
  4303. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-107
  4304. // /dfRootMode:dirReadWriteShEx
  4305. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-107
  4306. // /dfRootMode:xactReadWriteShEx
  4307. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-107
  4308. // /dfRootMode:xactReadWriteShDenyW
  4309. //
  4310. // History: Jiminli 14-July-96 Created
  4311. //
  4312. // BUGNOTE: Conversion: STMTEST-107
  4313. //
  4314. //-----------------------------------------------------------------------------
  4315. HRESULT STMTEST_107(int argc, char *argv[])
  4316. {
  4317. HRESULT hr = S_OK;
  4318. HRESULT hr1 = S_OK;
  4319. ChanceDF *pTestChanceDF = NULL;
  4320. VirtualDF *pTestVirtualDF = NULL;
  4321. VirtualCtrNode *pVirtualDFRoot = NULL;
  4322. DG_STRING *pdgu = NULL;
  4323. DG_INTEGER *pdgi = NULL;
  4324. USHORT usErr = 0;
  4325. VirtualStmNode *pvsnRootNewChildStream0 = NULL;
  4326. VirtualStmNode *pvsnRootNewChildStream1 = NULL;
  4327. LPSTREAM pstm0 = NULL;
  4328. LPSTREAM pstm1 = NULL;
  4329. LPSTREAM pCloneStm = NULL;
  4330. LPTSTR pRootNewChildStmName0 = NULL;
  4331. LPTSTR pRootNewChildStmName1 = NULL;
  4332. LPTSTR ptcsBuffer = NULL;
  4333. ULONG culWritten = 0;
  4334. ULONG culRead = 0;
  4335. DWORD dwRootMode = 0;
  4336. ULONG culRandIOBytes = 0;
  4337. ULONG ulRef = 0;
  4338. BOOL fPass = TRUE;
  4339. ULARGE_INTEGER uliCopy;
  4340. LARGE_INTEGER liOffset;
  4341. LARGE_INTEGER liZero;
  4342. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_107"));
  4343. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4344. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_107 started.")) );
  4345. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt illegitimate operations on IStream.")) );
  4346. // Create our ChanceDF and VirtualDF
  4347. hr = CreateTestDocfile (argc,
  4348. argv,
  4349. &pVirtualDFRoot,
  4350. &pTestVirtualDF,
  4351. &pTestChanceDF);
  4352. // if creating the docfile - bail here
  4353. if (NULL != pTestChanceDF && DoingCreate ())
  4354. {
  4355. UINT ulSeed = pTestChanceDF->GetSeed ();
  4356. CleanupTestDocfile (&pVirtualDFRoot,
  4357. &pTestVirtualDF,
  4358. &pTestChanceDF,
  4359. FALSE);
  4360. return (HRESULT)ulSeed;
  4361. }
  4362. if (S_OK == hr)
  4363. {
  4364. dwRootMode = pTestChanceDF->GetRootMode();
  4365. DH_TRACE((
  4366. DH_LVL_TRACE1,
  4367. TEXT("Run Mode for STMTEST_107, Access mode: %lx"),
  4368. dwRootMode));
  4369. }
  4370. // Get DG_STRING object pointer
  4371. if (S_OK == hr)
  4372. {
  4373. pdgu = pTestVirtualDF->GetDataGenUnicode();
  4374. DH_ASSERT(NULL != pdgu) ;
  4375. if(NULL == pdgu)
  4376. {
  4377. hr = E_FAIL;
  4378. }
  4379. }
  4380. // Get DG_INTEGER object pointer
  4381. if (S_OK == hr)
  4382. {
  4383. pdgi = pTestVirtualDF->GetDataGenInteger();
  4384. DH_ASSERT(NULL != pdgi);
  4385. if(NULL == pdgi)
  4386. {
  4387. hr = E_FAIL;
  4388. }
  4389. }
  4390. // Adds a new stream to the root storage.
  4391. if(S_OK == hr)
  4392. {
  4393. // Generate random name for stream
  4394. hr = GenerateRandomName(
  4395. pdgu,
  4396. MINLENGTH,
  4397. MAXLENGTH,
  4398. &pRootNewChildStmName0);
  4399. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4400. }
  4401. if(S_OK == hr)
  4402. {
  4403. hr = AddStream(
  4404. pTestVirtualDF,
  4405. pVirtualDFRoot,
  4406. pRootNewChildStmName0,
  4407. 0,
  4408. STGM_READWRITE |
  4409. STGM_SHARE_EXCLUSIVE |
  4410. STGM_FAILIFTHERE,
  4411. &pvsnRootNewChildStream0);
  4412. DH_HRCHECK(hr, TEXT("AddFirstStream")) ;
  4413. }
  4414. if(S_OK == hr)
  4415. {
  4416. DH_TRACE((
  4417. DH_LVL_TRACE1,
  4418. TEXT("VirtualStmNode0::AddStream completed successfully.")));
  4419. }
  4420. else
  4421. {
  4422. DH_TRACE((
  4423. DH_LVL_TRACE1,
  4424. TEXT("VirtualStmNode0::AddStream not successful, hr=0x%lx."),
  4425. hr));
  4426. }
  4427. // Generate random number of bytes to write to stream b/w
  4428. // RAND_IO_MIN and RAND_IO_MAX.
  4429. if (S_OK == hr)
  4430. {
  4431. usErr = pdgi->Generate(&culRandIOBytes, RAND_IO_MIN, RAND_IO_MAX);
  4432. if (DG_RC_SUCCESS != usErr)
  4433. {
  4434. hr = E_FAIL;
  4435. }
  4436. }
  4437. // Call Virtual::Write to create random bytes in the stream. For our test
  4438. // purposes, we generate a random string of size culRandIOBytes using
  4439. // GenerateRandomString function.
  4440. if (S_OK == hr)
  4441. {
  4442. hr = GenerateRandomString(
  4443. pdgu,
  4444. culRandIOBytes,
  4445. culRandIOBytes,
  4446. &ptcsBuffer);
  4447. DH_HRCHECK(hr, TEXT("GenerateRandomString"));
  4448. }
  4449. if (S_OK == hr)
  4450. {
  4451. hr = pvsnRootNewChildStream0->Write(
  4452. ptcsBuffer,
  4453. culRandIOBytes,
  4454. &culWritten);
  4455. }
  4456. if (S_OK == hr)
  4457. {
  4458. DH_TRACE((
  4459. DH_LVL_TRACE1,
  4460. TEXT("IStream::Write function completed successfully.")));
  4461. }
  4462. else
  4463. {
  4464. DH_TRACE((
  4465. DH_LVL_TRACE1,
  4466. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  4467. hr));
  4468. }
  4469. // Delete temp buffer
  4470. if (NULL != ptcsBuffer)
  4471. {
  4472. delete []ptcsBuffer;
  4473. ptcsBuffer = NULL;
  4474. }
  4475. // Adds another new stream to the root storage.
  4476. if(S_OK == hr)
  4477. {
  4478. // Generate random name for stream
  4479. hr = GenerateRandomName(
  4480. pdgu,
  4481. MINLENGTH,
  4482. MAXLENGTH,
  4483. &pRootNewChildStmName1);
  4484. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4485. }
  4486. if(S_OK == hr)
  4487. {
  4488. hr = AddStream(
  4489. pTestVirtualDF,
  4490. pVirtualDFRoot,
  4491. pRootNewChildStmName1,
  4492. 0,
  4493. STGM_READWRITE |
  4494. STGM_SHARE_EXCLUSIVE |
  4495. STGM_FAILIFTHERE,
  4496. &pvsnRootNewChildStream1);
  4497. DH_HRCHECK(hr, TEXT("AddSecondStream")) ;
  4498. }
  4499. if(S_OK == hr)
  4500. {
  4501. DH_TRACE((
  4502. DH_LVL_TRACE1,
  4503. TEXT("VirtualStmNode1::AddStream completed successfully.")));
  4504. }
  4505. else
  4506. {
  4507. DH_TRACE((
  4508. DH_LVL_TRACE1,
  4509. TEXT("VirtualStmNode1::AddStream not successful, hr=0x%lx."),
  4510. hr));
  4511. }
  4512. // Pass NULL pv to read call, should fail
  4513. if (S_OK == hr)
  4514. {
  4515. pstm0 = pvsnRootNewChildStream0->GetIStreamPointer();
  4516. pstm1 = pvsnRootNewChildStream1->GetIStreamPointer();
  4517. DH_ASSERT(NULL != pstm0);
  4518. DH_ASSERT(NULL != pstm1);
  4519. }
  4520. if (S_OK == hr)
  4521. {
  4522. hr1 = pstm0->Read(
  4523. NULL,
  4524. culRandIOBytes,
  4525. &culRead);
  4526. if (STG_E_INVALIDPOINTER != hr1)
  4527. {
  4528. DH_TRACE((
  4529. DH_LVL_TRACE1,
  4530. TEXT("Read should return STG_E_INVALIDPOINTER, hr=0x%lx."),
  4531. hr1));
  4532. fPass = FALSE;
  4533. }
  4534. else
  4535. {
  4536. // Reset hr value for other tests
  4537. DH_TRACE((
  4538. DH_LVL_TRACE1,
  4539. TEXT("Read failed as expected, hr=0x%lx."),
  4540. hr1));
  4541. hr1 = S_OK;
  4542. }
  4543. }
  4544. //
  4545. // coverage for bug# 143546
  4546. //
  4547. //
  4548. // commented out to avoid av'ing;
  4549. // we should activate it when bug it's fixed
  4550. //
  4551. /*
  4552. if (S_OK == hr)
  4553. {
  4554. const char *szDummy = "foo"; // readonly
  4555. // make stream nonempty
  4556. HRESULT hr2 = pstm0->Write(szDummy, strlen(szDummy), &culWritten);
  4557. DH_HRCHECK(hr2, TEXT("IStream::Write"));
  4558. if (S_OK == hr2)
  4559. {
  4560. LARGE_INTEGER li;
  4561. LISet32(li, 0L);
  4562. hr2 = pstm0->Seek(li, SEEK_SET,NULL);
  4563. DH_HRCHECK(hr2, TEXT("IStream::Seek SEEK_SET"));
  4564. }
  4565. if(S_OK == hr2)
  4566. {
  4567. hr1 = pstm0->Read((void*)szDummy,
  4568. strlen(szDummy),
  4569. &culRead);
  4570. if (STG_E_INVALIDPOINTER != hr1)
  4571. {
  4572. DH_TRACE((
  4573. DH_LVL_ERROR,
  4574. TEXT("Read should return STG_E_INVALIDPOINTER when in buffer is readonly, hr=0x%lx."),
  4575. hr1));
  4576. fPass = FALSE;
  4577. }
  4578. else
  4579. {
  4580. // Reset hr value for other tests
  4581. DH_TRACE((
  4582. DH_LVL_TRACE1,
  4583. TEXT("Read failed as expected, hr=0x%lx."),
  4584. hr1));
  4585. hr1 = S_OK;
  4586. }
  4587. }
  4588. if(S_OK == hr2)
  4589. {
  4590. // restore empty stream
  4591. ULARGE_INTEGER uli;
  4592. LISet32(uli, 0L);
  4593. hr = pstm1->SetSize(uli);
  4594. DH_HRCHECK(hr, TEXT("IStream::SetSize 0"));
  4595. }
  4596. }
  4597. */
  4598. // Pass NULL pv to write call, should fail
  4599. if (S_OK == hr)
  4600. {
  4601. hr1 = pstm1->Write(
  4602. NULL,
  4603. culRandIOBytes,
  4604. &culWritten);
  4605. if (STG_E_INVALIDPOINTER != hr1)
  4606. {
  4607. DH_TRACE((
  4608. DH_LVL_TRACE1,
  4609. TEXT("Write should return STG_E_INVALIDPOINTER, hr=0x%lx."),
  4610. hr1));
  4611. fPass = FALSE;
  4612. }
  4613. else
  4614. {
  4615. // Reset hr value for other tests
  4616. DH_TRACE((
  4617. DH_LVL_TRACE1,
  4618. TEXT("Write failed as expected, hr=0x%lx."),
  4619. hr1));
  4620. hr1 = S_OK;
  4621. }
  4622. }
  4623. // Pass NULL ppstm to clone call, should fail
  4624. if (S_OK == hr)
  4625. {
  4626. hr1 = pstm0->Clone(
  4627. NULL);
  4628. if (STG_E_INVALIDPOINTER != hr1)
  4629. {
  4630. DH_TRACE((
  4631. DH_LVL_TRACE1,
  4632. TEXT("Clone should have failed, hr=0x%lx."),
  4633. hr1));
  4634. fPass = FALSE;
  4635. }
  4636. else
  4637. {
  4638. // Reset hr value for other tests
  4639. DH_TRACE((
  4640. DH_LVL_TRACE1,
  4641. TEXT("Clone failed as expected, hr=0x%lx."),
  4642. hr1));
  4643. hr1 = S_OK;
  4644. }
  4645. }
  4646. // Pass NULL pstm to CopyTo call, should fail
  4647. if(S_OK == hr)
  4648. {
  4649. ULISet32(uliCopy, culRandIOBytes);
  4650. hr1 = pstm0->CopyTo(NULL, uliCopy, NULL, NULL);
  4651. if (STG_E_INVALIDPOINTER != hr1)
  4652. {
  4653. DH_TRACE((
  4654. DH_LVL_TRACE1,
  4655. TEXT("CopyTo should have failed, hr=0x%lx."),
  4656. hr1));
  4657. fPass = FALSE;
  4658. }
  4659. else
  4660. {
  4661. // Reset hr value for other tests
  4662. DH_TRACE((
  4663. DH_LVL_TRACE1,
  4664. TEXT("CopyTo failed as expected, hr=0x%lx."),
  4665. hr1));
  4666. hr1 = S_OK;
  4667. }
  4668. }
  4669. // Pass 'cb' > length of stream to CopyTo(), should pass
  4670. if (S_OK == hr)
  4671. {
  4672. ULISet32(uliCopy, ULONG_MAX);
  4673. hr1 = pvsnRootNewChildStream0->CopyTo(
  4674. pvsnRootNewChildStream1,
  4675. uliCopy,
  4676. NULL,
  4677. NULL);
  4678. if (S_OK == hr1)
  4679. {
  4680. DH_TRACE((
  4681. DH_LVL_TRACE1,
  4682. TEXT("IStream0::CopyTo completed successfully.")));
  4683. }
  4684. else
  4685. {
  4686. DH_TRACE((
  4687. DH_LVL_TRACE1,
  4688. TEXT("IStream0::CopyTo not successful, hr=0x%lx."),
  4689. hr1));
  4690. }
  4691. }
  4692. // Release Stream1
  4693. if (S_OK == hr)
  4694. {
  4695. hr = pvsnRootNewChildStream1->Close();
  4696. if (S_OK == hr)
  4697. {
  4698. DH_TRACE((
  4699. DH_LVL_TRACE1,
  4700. TEXT("VirtualStmNode1::Close completed successfully.")));
  4701. }
  4702. else
  4703. {
  4704. DH_TRACE((
  4705. DH_LVL_TRACE1,
  4706. TEXT("VirtualStmNode1::Close unsuccessful, hr=0x%lx."),
  4707. hr));
  4708. }
  4709. }
  4710. // Pass 'cb' > length of stream to CopyTo() w/dest Clone() of Istream,
  4711. // should pass
  4712. if(S_OK == hr)
  4713. {
  4714. LISet32(liZero, 0L);
  4715. hr1 = pvsnRootNewChildStream0->Seek(liZero, STREAM_SEEK_SET, NULL);
  4716. DH_HRCHECK(hr1, TEXT("IStream::Seek")) ;
  4717. if (S_OK == hr1)
  4718. {
  4719. DH_TRACE((
  4720. DH_LVL_TRACE1,
  4721. TEXT("IStream0::Seek function completed successfully.")));
  4722. }
  4723. else
  4724. {
  4725. DH_TRACE((
  4726. DH_LVL_TRACE1,
  4727. TEXT("IStream0::Seek function wasn't successful, hr=0x%lx."),
  4728. hr1));
  4729. }
  4730. }
  4731. if (S_OK == hr)
  4732. {
  4733. hr = pvsnRootNewChildStream0->Clone(&pCloneStm);
  4734. DH_HRCHECK(hr, TEXT("IStream::Clone"));
  4735. }
  4736. if (S_OK == hr)
  4737. {
  4738. DH_TRACE((
  4739. DH_LVL_TRACE1,
  4740. TEXT("IStream::Clone function completed successfully.")));
  4741. }
  4742. else
  4743. {
  4744. DH_TRACE((
  4745. DH_LVL_TRACE1,
  4746. TEXT("IStream::Clone function wasn't successful, hr=0x%lx."),
  4747. hr));
  4748. }
  4749. if (S_OK == hr)
  4750. {
  4751. hr = pstm0->CopyTo(pCloneStm, uliCopy, NULL, NULL);
  4752. }
  4753. if (S_OK == hr)
  4754. {
  4755. DH_TRACE((
  4756. DH_LVL_TRACE1,
  4757. TEXT("IStream0::CopyTo completed successfully.")));
  4758. }
  4759. else
  4760. {
  4761. DH_TRACE((
  4762. DH_LVL_TRACE1,
  4763. TEXT("IStream0::CopyTo not successful, hr=0x%lx."),
  4764. hr));
  4765. }
  4766. // Pass 'cb' > length of stream to CopyTo() w/dest Clone() of IStream,
  4767. // and seek pointer in source stream past end of file, should pass
  4768. // This also tests seek function in case of seeking past end of stream
  4769. if(S_OK == hr)
  4770. {
  4771. LISet32(liOffset, culRandIOBytes);
  4772. hr = pvsnRootNewChildStream0->Seek(liOffset, STREAM_SEEK_CUR, NULL);
  4773. DH_HRCHECK(hr, TEXT("IStream::Seek")) ;
  4774. }
  4775. if (S_OK == hr)
  4776. {
  4777. DH_TRACE((
  4778. DH_LVL_TRACE1,
  4779. TEXT("IStream0::Seeking past the end of stream successfully.")));
  4780. }
  4781. else
  4782. {
  4783. DH_TRACE((
  4784. DH_LVL_TRACE1,
  4785. TEXT("IStream0::Seek past end of stream not Ok, hr=0x%lx."),
  4786. hr));
  4787. }
  4788. if (S_OK == hr)
  4789. {
  4790. hr = pstm0->CopyTo(pCloneStm, uliCopy, NULL, NULL);
  4791. }
  4792. if (S_OK == hr)
  4793. {
  4794. DH_TRACE((
  4795. DH_LVL_TRACE1,
  4796. TEXT("IStream0::CopyTo completed successfully.")));
  4797. }
  4798. else
  4799. {
  4800. DH_TRACE((
  4801. DH_LVL_TRACE1,
  4802. TEXT("IStream0::CopyTo not successful, hr=0x%lx."),
  4803. hr));
  4804. }
  4805. // Pass invalid dwOrigin(from old test) to seek call, should fail
  4806. if (S_OK == hr)
  4807. {
  4808. hr1 = pstm0->Seek(
  4809. liZero,
  4810. STREAM_SEEK_SET | STREAM_SEEK_CUR | STREAM_SEEK_END,
  4811. NULL);
  4812. if (STG_E_INVALIDFUNCTION != hr1)
  4813. {
  4814. DH_TRACE((
  4815. DH_LVL_TRACE1,
  4816. TEXT("Seek should have failed, hr=0x%lx."),
  4817. hr1));
  4818. fPass = FALSE;
  4819. }
  4820. else
  4821. {
  4822. // Reset hr value for other tests
  4823. DH_TRACE((
  4824. DH_LVL_TRACE1,
  4825. TEXT("Seek failed as expected, hr=0x%lx."),
  4826. hr1));
  4827. hr1 = S_OK;
  4828. }
  4829. }
  4830. // Commit root. BUGBUG: Use random modes
  4831. if (S_OK == hr)
  4832. {
  4833. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4834. }
  4835. if (S_OK == hr)
  4836. {
  4837. DH_TRACE((
  4838. DH_LVL_TRACE1,
  4839. TEXT("VirtualCtrNode::Commit completed successfully.")));
  4840. }
  4841. else
  4842. {
  4843. DH_TRACE((
  4844. DH_LVL_TRACE1,
  4845. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  4846. hr));
  4847. }
  4848. //Release streams
  4849. if (S_OK == hr)
  4850. {
  4851. hr = pvsnRootNewChildStream0->Close();
  4852. }
  4853. if (S_OK == hr)
  4854. {
  4855. DH_TRACE((
  4856. DH_LVL_TRACE1,
  4857. TEXT("VirtualStmNode0::Close completed successfully.")));
  4858. }
  4859. else
  4860. {
  4861. DH_TRACE((
  4862. DH_LVL_TRACE1,
  4863. TEXT("VirtualStmNode0::Close unsuccessful, hr=0x%lx."),
  4864. hr));
  4865. }
  4866. // Release Clone stream
  4867. if (NULL != pCloneStm)
  4868. {
  4869. ulRef = pCloneStm->Release();
  4870. DH_ASSERT(0 == ulRef);
  4871. }
  4872. if (S_OK == hr)
  4873. {
  4874. DH_TRACE((
  4875. DH_LVL_TRACE1,
  4876. TEXT("IStream1::Close completed successfully.")));
  4877. }
  4878. else
  4879. {
  4880. DH_TRACE((
  4881. DH_LVL_TRACE1,
  4882. TEXT("IStream1::Close unsuccessful.")));
  4883. }
  4884. // Release Root
  4885. if (S_OK == hr)
  4886. {
  4887. hr = pVirtualDFRoot->Close();
  4888. }
  4889. if (S_OK == hr)
  4890. {
  4891. DH_TRACE((
  4892. DH_LVL_TRACE1,
  4893. TEXT("VirtualCtrNode::Close completed successfully.")));
  4894. }
  4895. else
  4896. {
  4897. DH_TRACE((
  4898. DH_LVL_TRACE1,
  4899. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  4900. hr));
  4901. }
  4902. // if everything goes well, log test as passed else failed.
  4903. if ((S_OK == hr) && (TRUE == fPass))
  4904. {
  4905. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_107 passed.")) );
  4906. }
  4907. else
  4908. {
  4909. DH_LOG((LOG_FAIL,
  4910. TEXT("Test variation STMTEST_107 failed, hr=0x%lx."),
  4911. hr));
  4912. // test failed. make it look like it failed.
  4913. hr = FirstError (hr, E_FAIL);
  4914. }
  4915. // Cleanup
  4916. CleanupTestDocfile (&pVirtualDFRoot,
  4917. &pTestVirtualDF,
  4918. &pTestChanceDF,
  4919. S_OK == hr);
  4920. // Delete strings
  4921. if (NULL != pRootNewChildStmName0)
  4922. {
  4923. delete pRootNewChildStmName0;
  4924. pRootNewChildStmName0 = NULL;
  4925. }
  4926. if (NULL != pRootNewChildStmName1)
  4927. {
  4928. delete pRootNewChildStmName1;
  4929. pRootNewChildStmName1 = NULL;
  4930. }
  4931. // Stop logging the test
  4932. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_107 finished")) );
  4933. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  4934. return hr;
  4935. }
  4936. //----------------------------------------------------------------------------
  4937. //
  4938. // Test: STMTEST_108
  4939. //
  4940. // Synopsis: The test create a root docfile with an IStream inside of it.
  4941. // A random block small object size block is generated and the CRC
  4942. // is computed. The data is written to the IStream. The IStream is
  4943. // rewound and read back. The CRC returned from the read is compared
  4944. // with the CRC computed during generation. A new random block bigger
  4945. // larger than small object size is generated at a random offset
  4946. // in the data buffer, and then the block is written to the IStream
  4947. // at that offset. This has the effect of transforming the small
  4948. // object into a regular object. The IStream is then rewound, read,
  4949. // and the read/write CRCs are compared. After a commit of the root
  4950. // docfile, the rewind, read, CRC compare is repeated. A random
  4951. // small object size is then chosen and the IStream is SetSized
  4952. // back to that size. The CRC is computed for the in-memory data
  4953. // buffer up to the new size. The IStream is rewound, read back,
  4954. // and CRC'd. The read/write CRCs are again compared to verify
  4955. // that the shrink back to small object size retained the correct
  4956. // data. After the root docfile is committed, we rewind, read,
  4957. // and compare read/write CRCs again. From 10 to 20 small objects
  4958. // are processed this way.
  4959. // Then stream and the root docfile are released and the root file
  4960. // is deleted upon success.
  4961. //
  4962. //
  4963. // Arguments:[argc]
  4964. // [argv]
  4965. //
  4966. // Returns: HRESULT
  4967. //
  4968. // Notes: This test runs in direct, transacted, and transacted deny write
  4969. // modes
  4970. //
  4971. // New Test Notes:
  4972. // 1. Old File(s): LSSMALLO.CXX
  4973. // 2. Old name of test(s) : LegitStreamSmallObjects test
  4974. // New Name of test(s) : STMTEST_108
  4975. // 3. To run the test, do the following at command prompt.
  4976. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-108
  4977. // /dfRootMode:dirReadWriteShEx
  4978. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-108
  4979. // /dfRootMode:xactReadWriteShEx
  4980. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-108
  4981. // /dfRootMode:xactReadWriteShDenyW
  4982. //
  4983. // History: Jiminli 23-July-96 Created
  4984. //
  4985. // BUGNOTE: Conversion: STMTEST-108
  4986. //
  4987. //-----------------------------------------------------------------------------
  4988. HRESULT STMTEST_108(int argc, char *argv[])
  4989. {
  4990. HRESULT hr = S_OK;
  4991. ChanceDF *pTestChanceDF = NULL;
  4992. VirtualDF *pTestVirtualDF = NULL;
  4993. VirtualCtrNode *pVirtualDFRoot = NULL;
  4994. DG_STRING *pdgu = NULL;
  4995. DG_INTEGER *pdgi = NULL;
  4996. USHORT usErr = 0;
  4997. VirtualStmNode *pvsnRootNewChildStream = NULL;
  4998. LPTSTR pRootNewChildStmName = NULL;
  4999. LPTSTR ptTempBuf1 = NULL;
  5000. LPTSTR ptTempBuf2 = NULL;
  5001. LPBYTE ptcsBuffer = NULL;
  5002. LPBYTE ptcsReadBuffer = NULL;
  5003. LPBYTE ptChangeBuf = NULL;
  5004. USHORT cusNumSmallObjects = 0;
  5005. USHORT cusMinSmallObjects = 10;
  5006. USHORT cusMaxSmallObjects = 20;
  5007. ULONG culNumBytes = 0;
  5008. ULONG culIOBytes = 0;
  5009. ULONG culWritten = 0;
  5010. ULONG ulRandOffset = 0;
  5011. ULONG culRead = 0;
  5012. ULONG index = 0;
  5013. DWORD dwRootMode = 0;
  5014. DWORD dwBufCRC = 0;
  5015. DWORD dwActCRC = 0;
  5016. BOOL fPass = TRUE;
  5017. LARGE_INTEGER liZero;
  5018. LARGE_INTEGER liOffset;
  5019. ULARGE_INTEGER uliOffset;
  5020. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_108"));
  5021. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  5022. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_108 started.")) );
  5023. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt IStream operations on small objects.")) );
  5024. // Create our ChanceDF and VirtualDF
  5025. hr = CreateTestDocfile (argc,
  5026. argv,
  5027. &pVirtualDFRoot,
  5028. &pTestVirtualDF,
  5029. &pTestChanceDF);
  5030. // if creating the docfile - bail here
  5031. if (NULL != pTestChanceDF && DoingCreate ())
  5032. {
  5033. UINT ulSeed = pTestChanceDF->GetSeed ();
  5034. CleanupTestDocfile (&pVirtualDFRoot,
  5035. &pTestVirtualDF,
  5036. &pTestChanceDF,
  5037. FALSE);
  5038. return (HRESULT)ulSeed;
  5039. }
  5040. if (S_OK == hr)
  5041. {
  5042. dwRootMode = pTestChanceDF->GetRootMode();
  5043. DH_TRACE((
  5044. DH_LVL_TRACE1,
  5045. TEXT("Run Mode for STMTEST_108, Access mode: %lx"),
  5046. dwRootMode));
  5047. }
  5048. // Get DG_STRING object pointer
  5049. if (S_OK == hr)
  5050. {
  5051. pdgu = pTestVirtualDF->GetDataGenUnicode();
  5052. DH_ASSERT(NULL != pdgu) ;
  5053. if(NULL == pdgu)
  5054. {
  5055. hr = E_FAIL;
  5056. }
  5057. }
  5058. // Get DG_INTEGER object pointer
  5059. if (S_OK == hr)
  5060. {
  5061. pdgi = pTestVirtualDF->GetDataGenInteger();
  5062. DH_ASSERT(NULL != pdgi) ;
  5063. if(NULL == pdgi)
  5064. {
  5065. hr = E_FAIL;
  5066. }
  5067. }
  5068. // Adds a new stream to the root storage.
  5069. if (S_OK == hr)
  5070. {
  5071. // Generate random name for stream
  5072. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  5073. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  5074. }
  5075. if (S_OK == hr)
  5076. {
  5077. hr = AddStream(
  5078. pTestVirtualDF,
  5079. pVirtualDFRoot,
  5080. pRootNewChildStmName,
  5081. 0,
  5082. STGM_READWRITE |
  5083. STGM_SHARE_EXCLUSIVE |
  5084. STGM_FAILIFTHERE,
  5085. &pvsnRootNewChildStream);
  5086. DH_HRCHECK(hr, TEXT("AddStream")) ;
  5087. }
  5088. if (S_OK == hr)
  5089. {
  5090. DH_TRACE((
  5091. DH_LVL_TRACE1,
  5092. TEXT("VirtualStmNode::AddStream completed successfully.")));
  5093. }
  5094. else
  5095. {
  5096. DH_TRACE((
  5097. DH_LVL_TRACE1,
  5098. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  5099. hr));
  5100. }
  5101. if (S_OK == hr)
  5102. {
  5103. // Generate random # of small objects for test between
  5104. // cusMinSmallObjects and cusMaxSmallObjects
  5105. usErr = pdgi->Generate(
  5106. &cusNumSmallObjects,
  5107. cusMinSmallObjects,
  5108. cusMaxSmallObjects);
  5109. if (DG_RC_SUCCESS != usErr)
  5110. {
  5111. hr = E_FAIL;
  5112. }
  5113. }
  5114. if (S_OK == hr)
  5115. {
  5116. DH_TRACE((
  5117. DH_LVL_TRACE1,
  5118. TEXT("Random # of small objects to test is: %d"),
  5119. cusNumSmallObjects));
  5120. }
  5121. // Loop for testing each small object
  5122. while ((cusNumSmallObjects--) && (S_OK == hr))
  5123. {
  5124. // Pick a random size for this small object, generate data to
  5125. // write in memory, compute CRC for databuffer, and write it.
  5126. usErr = pdgi->Generate(&culIOBytes, 0L, SMALL_OBJ_SIZE);
  5127. if (DG_RC_SUCCESS != usErr)
  5128. {
  5129. hr = E_FAIL;
  5130. }
  5131. if (S_OK == hr)
  5132. {
  5133. culNumBytes = SMALL_OBJ_SIZE * 4 + 1;
  5134. hr = GenerateRandomString(
  5135. pdgu,
  5136. culNumBytes,
  5137. culNumBytes,
  5138. &ptTempBuf1);
  5139. }
  5140. if (S_OK == hr)
  5141. {
  5142. // Let ptcsBuffer point to temporary buffer(for purpose of
  5143. // type casting, because IStream:Seek proceeds by BYTE)
  5144. ptcsBuffer = (LPBYTE)ptTempBuf1;
  5145. culNumBytes = culIOBytes;
  5146. hr = CalculateCRCForDataBuffer(
  5147. (LPTSTR)ptcsBuffer,
  5148. culNumBytes,
  5149. &dwBufCRC);
  5150. }
  5151. if (S_OK == hr)
  5152. {
  5153. hr = pvsnRootNewChildStream->Write(
  5154. ptcsBuffer,
  5155. culNumBytes,
  5156. &culWritten);
  5157. }
  5158. if (S_OK != hr)
  5159. {
  5160. DH_TRACE((
  5161. DH_LVL_TRACE1,
  5162. TEXT("VirtualStmNode::Write wasn't successful, hr=0x%lx."),
  5163. hr));
  5164. }
  5165. if (S_OK == hr)
  5166. {
  5167. LISet32(liZero, 0L);
  5168. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  5169. }
  5170. if (S_OK != hr)
  5171. {
  5172. DH_TRACE((
  5173. DH_LVL_TRACE1,
  5174. TEXT("VirtualStmNode::Seek wasn't successful, hr=0x%lx."),
  5175. hr));
  5176. }
  5177. // read all data in the IStream(SMALL_OBJ_SIZE * 4) and compute CRC.
  5178. // We attempt to read SMALL_OBJ_SIZE * 4 instead of the number of bytes
  5179. // actually written so we catch the case of extra data pegged onto the
  5180. // end of the stream. IStream::Read() returns the number of bytes
  5181. // actually read, which in this case should be culIOBytes. Next,
  5182. // compare r/w CRCs.
  5183. if (S_OK == hr)
  5184. {
  5185. culNumBytes = SMALL_OBJ_SIZE * 4;
  5186. ptcsReadBuffer = new BYTE[culNumBytes];
  5187. if (NULL == ptcsReadBuffer)
  5188. {
  5189. hr = E_OUTOFMEMORY;
  5190. }
  5191. }
  5192. if (S_OK == hr)
  5193. {
  5194. memset(ptcsReadBuffer, '\0', culNumBytes * sizeof(BYTE));
  5195. hr = pvsnRootNewChildStream->Read(
  5196. ptcsReadBuffer,
  5197. culNumBytes,
  5198. &culRead);
  5199. }
  5200. if (S_OK != hr)
  5201. {
  5202. DH_TRACE((
  5203. DH_LVL_TRACE1,
  5204. TEXT("VirtualStmNode::Read wasn't successful, hr=0x%lx."),
  5205. hr));
  5206. }
  5207. // culRead is the actual number of bytes read from IStream
  5208. if (S_OK == hr)
  5209. {
  5210. hr = CalculateCRCForDataBuffer(
  5211. (LPTSTR)ptcsReadBuffer,
  5212. culRead,
  5213. &dwActCRC);
  5214. }
  5215. // Compare CRCs
  5216. if (S_OK == hr)
  5217. {
  5218. if (dwBufCRC != dwActCRC)
  5219. {
  5220. DH_TRACE((
  5221. DH_LVL_TRACE1,
  5222. TEXT("Small object w/r mismatch before grow, hr=0x%lx."),
  5223. hr));
  5224. fPass = FALSE;
  5225. }
  5226. }
  5227. // Delete temp buffer
  5228. if (NULL != ptcsReadBuffer)
  5229. {
  5230. delete []ptcsReadBuffer;
  5231. ptcsReadBuffer = NULL;
  5232. }
  5233. // Pick a random offset somewhere in the small object to begin changing
  5234. // data at. Position the IStream pointer to this location. Generate a
  5235. // random number of bytes into the in-memory buffer starting at this
  5236. // position, we generate enough new bytes to replace some that were
  5237. // already in the IStream and to expand the IStream beyond small object
  5238. // size.
  5239. if (S_OK == hr)
  5240. {
  5241. usErr = pdgi->Generate(&ulRandOffset, 0L, culIOBytes);
  5242. if (DG_RC_SUCCESS != usErr)
  5243. {
  5244. hr = E_FAIL;
  5245. }
  5246. }
  5247. // Seek to the random offset
  5248. if(S_OK == hr)
  5249. {
  5250. LISet32(liOffset, ulRandOffset);
  5251. hr = pvsnRootNewChildStream->Seek(liOffset, STREAM_SEEK_SET, NULL);
  5252. }
  5253. if (S_OK != hr)
  5254. {
  5255. DH_TRACE((
  5256. DH_LVL_TRACE1,
  5257. TEXT("IStream::Seek wasn't successful, hr=0x%lx"),
  5258. hr));
  5259. }
  5260. // Generate random nubmer of bytes to grow
  5261. if(S_OK == hr)
  5262. {
  5263. usErr = pdgi->Generate(
  5264. &culIOBytes, SMALL_OBJ_SIZE+1, SMALL_OBJ_SIZE*3);
  5265. if (DG_RC_SUCCESS != usErr)
  5266. {
  5267. hr = E_FAIL;
  5268. }
  5269. }
  5270. if (S_OK == hr)
  5271. {
  5272. culNumBytes = culIOBytes;
  5273. hr = GenerateRandomString(
  5274. pdgu,
  5275. culNumBytes,
  5276. culNumBytes,
  5277. &ptTempBuf2);
  5278. }
  5279. if (S_OK == hr)
  5280. {
  5281. ptChangeBuf = (LPBYTE)ptTempBuf2;
  5282. for (index = 0; index < culIOBytes; index++)
  5283. {
  5284. ptcsBuffer[ulRandOffset+index] = ptChangeBuf[index];
  5285. }
  5286. }
  5287. if (S_OK == hr)
  5288. {
  5289. // Calculate the new length of the object, and compute CRC for the
  5290. // whole buffer
  5291. culNumBytes = culIOBytes + ulRandOffset;
  5292. hr = CalculateCRCForDataBuffer(
  5293. (LPTSTR)ptcsBuffer,
  5294. culNumBytes,
  5295. &dwBufCRC);
  5296. }
  5297. if (S_OK == hr)
  5298. {
  5299. // Write growing data from seek pointer
  5300. hr = pvsnRootNewChildStream->Write(
  5301. ptChangeBuf,
  5302. culIOBytes,
  5303. &culWritten);
  5304. }
  5305. if (S_OK != hr)
  5306. {
  5307. DH_TRACE((
  5308. DH_LVL_TRACE1,
  5309. TEXT("VirtualStmNode::Write wasn't successful, hr=0x%lx."),
  5310. hr));
  5311. }
  5312. if (S_OK == hr)
  5313. {
  5314. LISet32(liZero, 0L);
  5315. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  5316. }
  5317. if (S_OK != hr)
  5318. {
  5319. DH_TRACE((
  5320. DH_LVL_TRACE1,
  5321. TEXT("VirtualStmNode::Seek wasn't successful, hr=0x%lx."),
  5322. hr));
  5323. }
  5324. // Read back the entire IStream, compute the CRC, and compare r/w CRCs
  5325. // Commit the root docfile and repeat this step
  5326. if (S_OK == hr)
  5327. {
  5328. culNumBytes = SMALL_OBJ_SIZE * 4;
  5329. ptcsReadBuffer = new BYTE[culNumBytes];
  5330. if (NULL == ptcsReadBuffer)
  5331. {
  5332. hr = E_OUTOFMEMORY;
  5333. }
  5334. }
  5335. if (S_OK == hr)
  5336. {
  5337. memset(ptcsReadBuffer, '\0', culNumBytes * sizeof(BYTE));
  5338. hr = pvsnRootNewChildStream->Read(
  5339. ptcsReadBuffer,
  5340. culNumBytes,
  5341. &culRead);
  5342. }
  5343. if (S_OK != hr)
  5344. {
  5345. DH_TRACE((
  5346. DH_LVL_TRACE1,
  5347. TEXT("VirtualStmNode::Read wasn't successful, hr=0x%lx."),
  5348. hr));
  5349. }
  5350. // culRead is the actual number of bytes read from IStream
  5351. if (S_OK == hr)
  5352. {
  5353. hr = CalculateCRCForDataBuffer(
  5354. (LPTSTR)ptcsReadBuffer,
  5355. culRead,
  5356. &dwActCRC);
  5357. }
  5358. // Compare CRCs
  5359. if (S_OK == hr)
  5360. {
  5361. if (dwBufCRC != dwActCRC)
  5362. {
  5363. DH_TRACE((
  5364. DH_LVL_TRACE1,
  5365. TEXT("Small object w/r mismatch after grow, hr=0x%lx."),
  5366. hr));
  5367. fPass = FALSE;
  5368. }
  5369. }
  5370. // Delete temp buffer
  5371. if (NULL != ptcsReadBuffer)
  5372. {
  5373. delete []ptcsReadBuffer;
  5374. ptcsReadBuffer = NULL;
  5375. }
  5376. // Commit root. BUGBUG: Use random modes
  5377. if (S_OK == hr)
  5378. {
  5379. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  5380. }
  5381. if (S_OK != hr)
  5382. {
  5383. DH_TRACE((
  5384. DH_LVL_TRACE1,
  5385. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  5386. hr));
  5387. }
  5388. if (S_OK == hr)
  5389. {
  5390. memset(&liZero, 0, sizeof(LARGE_INTEGER));
  5391. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  5392. }
  5393. if (S_OK != hr)
  5394. {
  5395. DH_TRACE((
  5396. DH_LVL_TRACE1,
  5397. TEXT("VirtualStmNode::Seek wasn't successful, hr=0x%lx."),
  5398. hr));
  5399. }
  5400. if (S_OK == hr)
  5401. {
  5402. ptcsReadBuffer = new BYTE[culNumBytes];
  5403. if (NULL == ptcsReadBuffer)
  5404. {
  5405. hr = E_OUTOFMEMORY;
  5406. }
  5407. }
  5408. if (S_OK == hr)
  5409. {
  5410. memset(ptcsReadBuffer, '\0', culNumBytes * sizeof(BYTE));
  5411. hr = pvsnRootNewChildStream->Read(
  5412. ptcsReadBuffer,
  5413. culNumBytes,
  5414. &culRead);
  5415. }
  5416. if (S_OK != hr)
  5417. {
  5418. DH_TRACE((
  5419. DH_LVL_TRACE1,
  5420. TEXT("VirtualStmNode::Read wasn't successful, hr=0x%lx."),
  5421. hr));
  5422. }
  5423. if (S_OK == hr)
  5424. {
  5425. hr = CalculateCRCForDataBuffer(
  5426. (LPTSTR)ptcsReadBuffer,
  5427. culRead,
  5428. &dwActCRC);
  5429. }
  5430. // Compare CRCs
  5431. if (S_OK == hr)
  5432. {
  5433. if (dwBufCRC != dwActCRC)
  5434. {
  5435. DH_TRACE((
  5436. DH_LVL_TRACE1,
  5437. TEXT("IStream w/r mismatch after grow/commit, hr=0x%lx."),
  5438. hr));
  5439. fPass = FALSE;
  5440. }
  5441. }
  5442. // Delete temp buffers
  5443. if (NULL != ptcsReadBuffer)
  5444. {
  5445. delete []ptcsReadBuffer;
  5446. ptcsReadBuffer = NULL;
  5447. }
  5448. // Pick a random small object size to set the IStream to. Shrink the
  5449. // IStream with SetSize. Compute the CRC for the in-memory data buffer
  5450. // up to the new size of the IStream.
  5451. if(S_OK == hr)
  5452. {
  5453. usErr = pdgi->Generate(&culIOBytes, 1L, SMALL_OBJ_SIZE);
  5454. if (DG_RC_SUCCESS != usErr)
  5455. {
  5456. hr = E_FAIL;
  5457. }
  5458. }
  5459. if (S_OK == hr)
  5460. {
  5461. ULISet32(uliOffset, culIOBytes);
  5462. hr = pvsnRootNewChildStream->SetSize(uliOffset);
  5463. }
  5464. if (S_OK != hr)
  5465. {
  5466. DH_TRACE((
  5467. DH_LVL_TRACE1,
  5468. TEXT("VirtualStmNode::SetSize unsuccessful, hr=0x%lx"),
  5469. hr));
  5470. }
  5471. if (S_OK == hr)
  5472. {
  5473. culNumBytes = culIOBytes;
  5474. hr = CalculateCRCForDataBuffer(
  5475. (LPTSTR)ptcsBuffer,
  5476. culNumBytes,
  5477. &dwBufCRC);
  5478. }
  5479. // Seek to beginning of IStream we just shrank, read the whole thing
  5480. // back, compute CRC, and compare r/w CRCs. Finally, commit the root
  5481. // docfile and repeat this step.
  5482. if (S_OK == hr)
  5483. {
  5484. LISet32(liZero, 0L);
  5485. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  5486. }
  5487. if (S_OK != hr)
  5488. {
  5489. DH_TRACE((
  5490. DH_LVL_TRACE1,
  5491. TEXT("VirtualStmNode::Seek wasn't successful, hr=0x%lx."),
  5492. hr));
  5493. }
  5494. if (S_OK == hr)
  5495. {
  5496. culNumBytes = SMALL_OBJ_SIZE * 4;
  5497. ptcsReadBuffer = new BYTE[culNumBytes];
  5498. if (NULL == ptcsReadBuffer)
  5499. {
  5500. hr = E_OUTOFMEMORY;
  5501. }
  5502. }
  5503. if (S_OK == hr)
  5504. {
  5505. memset(ptcsReadBuffer, '\0', culNumBytes * sizeof(BYTE));
  5506. hr = pvsnRootNewChildStream->Read(
  5507. ptcsReadBuffer,
  5508. culNumBytes,
  5509. &culRead);
  5510. }
  5511. if (S_OK != hr)
  5512. {
  5513. DH_TRACE((
  5514. DH_LVL_TRACE1,
  5515. TEXT("VirtualStmNode::Read wasn't successful, hr=0x%lx."),
  5516. hr));
  5517. }
  5518. // culRead is the actual number of bytes read from IStream
  5519. if (S_OK == hr)
  5520. {
  5521. hr = CalculateCRCForDataBuffer(
  5522. (LPTSTR)ptcsReadBuffer,
  5523. culRead,
  5524. &dwActCRC);
  5525. }
  5526. // Compare CRCs
  5527. if (S_OK == hr)
  5528. {
  5529. if (dwBufCRC != dwActCRC)
  5530. {
  5531. DH_TRACE((
  5532. DH_LVL_TRACE1,
  5533. TEXT("Small object w/r mismatch after shrink, hr=0x%lx."),
  5534. hr));
  5535. fPass = FALSE;
  5536. }
  5537. }
  5538. // Delete temp buffer
  5539. if (NULL != ptcsReadBuffer)
  5540. {
  5541. delete []ptcsReadBuffer;
  5542. ptcsReadBuffer = NULL;
  5543. }
  5544. // Commit root. BUGBUG: Use random modes
  5545. if (S_OK == hr)
  5546. {
  5547. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  5548. }
  5549. if (S_OK != hr)
  5550. {
  5551. DH_TRACE((
  5552. DH_LVL_TRACE1,
  5553. TEXT("VirtualCtrNode::Commit wasn't successful, hr=0x%lx."),
  5554. hr));
  5555. }
  5556. if (S_OK == hr)
  5557. {
  5558. memset(&liZero, 0, sizeof(LARGE_INTEGER));
  5559. hr = pvsnRootNewChildStream->Seek(liZero, STREAM_SEEK_SET, NULL);
  5560. }
  5561. if (S_OK != hr)
  5562. {
  5563. DH_TRACE((
  5564. DH_LVL_TRACE1,
  5565. TEXT("VirtualStmNode::Seek wasn't successful, hr=0x%lx."),
  5566. hr));
  5567. }
  5568. if (S_OK == hr)
  5569. {
  5570. ptcsReadBuffer = new BYTE[culNumBytes];
  5571. if (NULL == ptcsReadBuffer)
  5572. {
  5573. hr = E_OUTOFMEMORY;
  5574. }
  5575. }
  5576. if (S_OK == hr)
  5577. {
  5578. memset(ptcsReadBuffer, '\0', culNumBytes * sizeof(BYTE));
  5579. hr = pvsnRootNewChildStream->Read(
  5580. ptcsReadBuffer,
  5581. culNumBytes,
  5582. &culRead);
  5583. }
  5584. if (S_OK != hr)
  5585. {
  5586. DH_TRACE((
  5587. DH_LVL_TRACE1,
  5588. TEXT("VirtualStmNode::Read wasn't successful, hr=0x%lx."),
  5589. hr));
  5590. }
  5591. if (S_OK == hr)
  5592. {
  5593. hr = CalculateCRCForDataBuffer(
  5594. (LPTSTR)ptcsReadBuffer,
  5595. culRead,
  5596. &dwActCRC);
  5597. }
  5598. // Compare CRCs
  5599. if (S_OK == hr)
  5600. {
  5601. if (dwBufCRC != dwActCRC)
  5602. {
  5603. DH_TRACE((
  5604. DH_LVL_TRACE1,
  5605. TEXT("IStream w/r mismatch after shrink/commit,hr=0x%lx"),
  5606. hr));
  5607. fPass = FALSE;
  5608. }
  5609. }
  5610. // Delete temp buffers
  5611. // ptcsBuffer and ptTempBuf1 point to the same memory chunk
  5612. // ptChangeBuf and ptTempBuf2 point to the same memory chunk
  5613. if (NULL != ptcsReadBuffer)
  5614. {
  5615. delete []ptcsReadBuffer;
  5616. ptcsReadBuffer = NULL;
  5617. }
  5618. if (NULL != ptcsBuffer)
  5619. {
  5620. delete []ptcsBuffer;
  5621. ptcsBuffer = NULL;
  5622. ptTempBuf1 = NULL;
  5623. }
  5624. if (NULL != ptTempBuf1)
  5625. {
  5626. delete []ptTempBuf1;
  5627. ptTempBuf1 = NULL;
  5628. ptcsBuffer = NULL;
  5629. }
  5630. if (NULL != ptTempBuf2)
  5631. {
  5632. delete []ptTempBuf2;
  5633. ptTempBuf2 = NULL;
  5634. ptChangeBuf = NULL;
  5635. }
  5636. // Reset IStream for next iteration of the loop
  5637. if (S_OK == hr)
  5638. {
  5639. ULISet32(uliOffset, 0L);
  5640. hr = pvsnRootNewChildStream->SetSize(uliOffset);
  5641. }
  5642. if (S_OK != hr)
  5643. {
  5644. DH_TRACE((
  5645. DH_LVL_TRACE1,
  5646. TEXT("VirtualStmNode::SetSize unsuccessful, hr=0x%lx"),
  5647. hr));
  5648. }
  5649. if (S_OK == hr)
  5650. {
  5651. LISet32(liOffset, 0L);
  5652. hr = pvsnRootNewChildStream->Seek(liOffset, STREAM_SEEK_SET, NULL);
  5653. }
  5654. if (S_OK != hr)
  5655. {
  5656. DH_TRACE((
  5657. DH_LVL_TRACE1,
  5658. TEXT("VirtualStmNode::Seek unsuccessful, hr=0x%lx"),
  5659. hr));
  5660. }
  5661. if ((S_OK != hr) || (TRUE != fPass))
  5662. {
  5663. break;
  5664. }
  5665. }
  5666. // Release stream
  5667. if (S_OK == hr)
  5668. {
  5669. hr = pvsnRootNewChildStream->Close();
  5670. }
  5671. if (S_OK == hr)
  5672. {
  5673. DH_TRACE((
  5674. DH_LVL_TRACE1,
  5675. TEXT("VirtualStmNode::Close completed successfully.")));
  5676. }
  5677. else
  5678. {
  5679. DH_TRACE((
  5680. DH_LVL_TRACE1,
  5681. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx."),
  5682. hr));
  5683. }
  5684. // Release Root
  5685. if (S_OK == hr)
  5686. {
  5687. hr = pVirtualDFRoot->Close();
  5688. }
  5689. if (S_OK == hr)
  5690. {
  5691. DH_TRACE((
  5692. DH_LVL_TRACE1,
  5693. TEXT("VirtualCtrNode::Close completed successfully.")));
  5694. }
  5695. else
  5696. {
  5697. DH_TRACE((
  5698. DH_LVL_TRACE1,
  5699. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  5700. hr));
  5701. }
  5702. // if everything goes well, log test as passed else failed.
  5703. if ((S_OK == hr) && (TRUE == fPass))
  5704. {
  5705. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_108 passed.")) );
  5706. }
  5707. else
  5708. {
  5709. DH_LOG((LOG_FAIL,
  5710. TEXT("Test variation STMTEST_108 failed, hr=0x%lx."),
  5711. hr));
  5712. // test failed. make it look like it failed.
  5713. hr = FirstError (hr, E_FAIL);
  5714. }
  5715. // Cleanup
  5716. CleanupTestDocfile (&pVirtualDFRoot,
  5717. &pTestVirtualDF,
  5718. &pTestChanceDF,
  5719. S_OK == hr);
  5720. // Delete strings
  5721. if (NULL != pRootNewChildStmName)
  5722. {
  5723. delete pRootNewChildStmName;
  5724. pRootNewChildStmName = NULL;
  5725. }
  5726. // Stop logging the test
  5727. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_108 finished")) );
  5728. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  5729. return hr;
  5730. }
  5731. //----------------------------------------------------------------------------
  5732. //
  5733. // Test: STMTEST_109
  5734. //
  5735. // Synopsis: Creates a root docfile with a random name. Creates an IStream in
  5736. // the root docfile and writes random number of bytes. ILockRegion,
  5737. // IUnlockRegion and Stat operations are attempted on stream.
  5738. // The IStream and root are then released.
  5739. //
  5740. // Arguments:[argc]
  5741. // [argv]
  5742. //
  5743. // Returns: HRESULT
  5744. //
  5745. // Notes: This test runs in direct, transacted, and transacted deny write
  5746. // modes
  5747. //
  5748. // History: 13-Aug-1996 NarindK Created.
  5749. //
  5750. // New Test Notes:
  5751. // 1. Old File: -part of common.cxx-
  5752. // 2. Old name of test :
  5753. // New Name of test : STMTEST_109
  5754. // 3. To run the test, do the following at command prompt.
  5755. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-109
  5756. // /dfRootMode:dirReadWriteShEx
  5757. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-109
  5758. // /dfRootMode:xactReadWriteShEx
  5759. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:STMTEST-109
  5760. // /dfRootMode:xactReadWriteShDenyW
  5761. //
  5762. // BUGNOTE: Conversion: STMTEST-109
  5763. //
  5764. //-----------------------------------------------------------------------------
  5765. HRESULT STMTEST_109(int argc, char *argv[])
  5766. {
  5767. HRESULT hr = S_OK;
  5768. ChanceDF *pTestChanceDF = NULL;
  5769. VirtualDF *pTestVirtualDF = NULL;
  5770. VirtualCtrNode *pVirtualDFRoot = NULL;
  5771. DG_STRING *pdgu = NULL;
  5772. DG_INTEGER *pdgi = NULL;
  5773. USHORT usErr = 0;
  5774. VirtualStmNode *pvsnRootNewChildStream = NULL;
  5775. LPTSTR pRootNewChildStmName = NULL;
  5776. ULONG cb = 0;
  5777. LPTSTR ptcsBuffer = NULL;
  5778. ULONG culWritten = 0;
  5779. DWORD dwRootMode = 0;
  5780. ULONG cRandomMinSize = 10;
  5781. ULONG cRandomMaxSize = 100;
  5782. BOOL fPass = TRUE;
  5783. LPMALLOC pMalloc = NULL;
  5784. STATSTG statStg;
  5785. ULARGE_INTEGER uliOffset;
  5786. ULARGE_INTEGER uliBytes;
  5787. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("STMTEST_109"));
  5788. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  5789. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_109 started.")) );
  5790. DH_TRACE((DH_LVL_TRACE1, TEXT("Attempt stm LockRegion/UnLockRegion/Stat ops")));
  5791. // Create our ChanceDF and VirtualDF
  5792. hr = CreateTestDocfile (argc,
  5793. argv,
  5794. &pVirtualDFRoot,
  5795. &pTestVirtualDF,
  5796. &pTestChanceDF);
  5797. // if creating the docfile - bail here
  5798. if (NULL != pTestChanceDF && DoingCreate ())
  5799. {
  5800. UINT ulSeed = pTestChanceDF->GetSeed ();
  5801. CleanupTestDocfile (&pVirtualDFRoot,
  5802. &pTestVirtualDF,
  5803. &pTestChanceDF,
  5804. FALSE);
  5805. return (HRESULT)ulSeed;
  5806. }
  5807. if (S_OK == hr)
  5808. {
  5809. dwRootMode = pTestChanceDF->GetRootMode();
  5810. DH_TRACE((
  5811. DH_LVL_TRACE1,
  5812. TEXT("Run Mode for STMTEST_109, Access mode: %lx"),
  5813. dwRootMode));
  5814. }
  5815. // Get DG_STRING object pointer
  5816. if (S_OK == hr)
  5817. {
  5818. pdgu = pTestVirtualDF->GetDataGenUnicode();
  5819. DH_ASSERT(NULL != pdgu) ;
  5820. if(NULL == pdgu)
  5821. {
  5822. hr = E_FAIL;
  5823. }
  5824. }
  5825. // Get DG_INTEGER object pointer
  5826. if (S_OK == hr)
  5827. {
  5828. pdgi = pTestVirtualDF->GetDataGenInteger();
  5829. DH_ASSERT(NULL != pdgi);
  5830. if(NULL == pdgi)
  5831. {
  5832. hr = E_FAIL;
  5833. }
  5834. }
  5835. // Adds a new stream to the root storage.
  5836. if(S_OK == hr)
  5837. {
  5838. // Generate random name for stream
  5839. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStmName);
  5840. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  5841. }
  5842. if (S_OK == hr)
  5843. {
  5844. // Generate random size for stream.
  5845. usErr = pdgi->Generate(&cb, cRandomMinSize, cRandomMaxSize);
  5846. if (DG_RC_SUCCESS != usErr)
  5847. {
  5848. hr = E_FAIL;
  5849. }
  5850. }
  5851. if(S_OK == hr)
  5852. {
  5853. hr = AddStream(
  5854. pTestVirtualDF,
  5855. pVirtualDFRoot,
  5856. pRootNewChildStmName,
  5857. cb,
  5858. STGM_READWRITE |
  5859. STGM_SHARE_EXCLUSIVE,
  5860. &pvsnRootNewChildStream);
  5861. DH_HRCHECK(hr, TEXT("AddStream")) ;
  5862. if(S_OK == hr)
  5863. {
  5864. DH_TRACE((
  5865. DH_LVL_TRACE1,
  5866. TEXT("VirtualStmNode::AddStream completed successfully.")));
  5867. }
  5868. else
  5869. {
  5870. DH_TRACE((
  5871. DH_LVL_TRACE1,
  5872. TEXT("VirtualStmNode::AddStream not successful, hr=0x%lx."),
  5873. hr));
  5874. }
  5875. }
  5876. // Call VirtualStmNode::Write to create random bytes in the stream. For
  5877. // our test purposes, we generate a random string of size 1 to cb using
  5878. // GenerateRandomString function.
  5879. if(S_OK == hr)
  5880. {
  5881. hr = GenerateRandomString(pdgu, cb, cb, &ptcsBuffer);
  5882. DH_HRCHECK(hr, TEXT("GenerateRandomString")) ;
  5883. }
  5884. if (S_OK == hr)
  5885. {
  5886. hr = pvsnRootNewChildStream->Write(
  5887. ptcsBuffer,
  5888. cb,
  5889. &culWritten);
  5890. if (S_OK == hr)
  5891. {
  5892. DH_TRACE((
  5893. DH_LVL_TRACE1,
  5894. TEXT("IStream::Write function completed successfully.")));
  5895. }
  5896. else
  5897. {
  5898. DH_TRACE((
  5899. DH_LVL_TRACE1,
  5900. TEXT("IStream::Write function wasn't successful, hr=0x%lx."),
  5901. hr));
  5902. }
  5903. }
  5904. // Attemp IStream::LockRegion. Ole's implementation doesn't have this
  5905. // function implemented and returns STG_E_INVALIDFUNCTION for the call.
  5906. if (S_OK == hr)
  5907. {
  5908. ULISet32(uliOffset, 0);
  5909. ULISet32(uliBytes, 20);
  5910. hr = pvsnRootNewChildStream->LockRegion(
  5911. uliOffset,
  5912. uliBytes,
  5913. LOCK_WRITE);
  5914. // Check STG_E_INVALIDFUNCTION returned as expected.
  5915. if (STG_E_INVALIDFUNCTION == hr)
  5916. {
  5917. DH_TRACE((
  5918. DH_LVL_TRACE1,
  5919. TEXT("IStream::LockRegion return STG_E_INVALIDFUNCTION as exp")));
  5920. hr = S_OK;
  5921. }
  5922. else
  5923. {
  5924. DH_TRACE((
  5925. DH_LVL_TRACE1,
  5926. TEXT("IStream::LockRegion didn't return hr as exp, hr=0x%lx."),
  5927. hr));
  5928. hr = E_FAIL;
  5929. }
  5930. }
  5931. // Attempt IStream::Stat and check the locks supported.
  5932. // First get pMalloc that would be used to free up the name string from
  5933. // STATSTG.
  5934. if ( S_OK == hr )
  5935. {
  5936. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  5937. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  5938. }
  5939. if (S_OK == hr)
  5940. {
  5941. statStg.pwcsName = NULL;
  5942. hr = pvsnRootNewChildStream->Stat(&statStg, STATFLAG_DEFAULT);
  5943. DH_HRCHECK(hr, TEXT("VirtualStmNode::Stat")) ;
  5944. }
  5945. // Check that locks suupported are zero.
  5946. if (S_OK == hr)
  5947. {
  5948. if(0 == statStg.grfLocksSupported)
  5949. {
  5950. DH_TRACE((DH_LVL_TRACE1, TEXT("Locks supported zero as exp.")));
  5951. }
  5952. else
  5953. {
  5954. DH_TRACE((DH_LVL_TRACE1, TEXT("Locks supported not zero as exp.")));
  5955. hr = E_FAIL;
  5956. }
  5957. }
  5958. // Release resources
  5959. if (( NULL != statStg.pwcsName) && ( NULL != pMalloc))
  5960. {
  5961. pMalloc->Free(statStg.pwcsName);
  5962. statStg.pwcsName = NULL;
  5963. }
  5964. // Attempt IStream::UnlockRegion. Ole's implementation doesn't have this
  5965. // function implemented and returns STG_E_INVALIDFUNCTION for the call.
  5966. if (S_OK == hr)
  5967. {
  5968. ULISet32(uliOffset, 0);
  5969. ULISet32(uliBytes, 20);
  5970. hr = pvsnRootNewChildStream->UnlockRegion(
  5971. uliOffset,
  5972. uliBytes,
  5973. LOCK_WRITE);
  5974. // Check STG_E_INVALIDFUNCTION returned as expected.
  5975. if (STG_E_INVALIDFUNCTION == hr)
  5976. {
  5977. DH_TRACE((
  5978. DH_LVL_TRACE1,
  5979. TEXT("IStm::UnlockRegion return STG_E_INVALIDFUNCTION as exp")));
  5980. hr = S_OK;
  5981. }
  5982. else
  5983. {
  5984. DH_TRACE((
  5985. DH_LVL_TRACE1,
  5986. TEXT("IStream::UnlockRegion didn't return hr as exp, hr=0x%lx."),
  5987. hr));
  5988. hr = E_FAIL;
  5989. }
  5990. }
  5991. // Attempt IStream::Stat again and check the locks supported.
  5992. if (S_OK == hr)
  5993. {
  5994. hr = pvsnRootNewChildStream->Stat(&statStg, STATFLAG_DEFAULT);
  5995. DH_HRCHECK(hr, TEXT("VirtualStmNode::Stat")) ;
  5996. }
  5997. // Check that locks suupported are zero.
  5998. if (S_OK == hr)
  5999. {
  6000. DH_ASSERT(statStg.type == STGTY_STREAM);
  6001. if(0 == statStg.grfLocksSupported)
  6002. {
  6003. DH_TRACE((DH_LVL_TRACE1, TEXT("Locks supported zero as exp.")));
  6004. }
  6005. else
  6006. {
  6007. DH_TRACE((DH_LVL_TRACE1, TEXT("Locks supported not zero as exp.")));
  6008. fPass = FALSE;
  6009. }
  6010. }
  6011. // Release resources
  6012. if ((NULL != statStg.pwcsName) && (NULL != pMalloc))
  6013. {
  6014. pMalloc->Free(statStg.pwcsName);
  6015. statStg.pwcsName = NULL;
  6016. }
  6017. // Release stream
  6018. if (S_OK == hr)
  6019. {
  6020. hr = pvsnRootNewChildStream->Close();
  6021. if (S_OK == hr)
  6022. {
  6023. DH_TRACE((
  6024. DH_LVL_TRACE1,
  6025. TEXT("VirtualStmNode::Close completed successfully.")));
  6026. }
  6027. else
  6028. {
  6029. DH_TRACE((
  6030. DH_LVL_TRACE1,
  6031. TEXT("VirtualStmNode::Close unsuccessful, hr=0x%lx.")));
  6032. }
  6033. }
  6034. // Commit root.
  6035. if(S_OK == hr)
  6036. {
  6037. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  6038. if (S_OK == hr)
  6039. {
  6040. DH_TRACE((
  6041. DH_LVL_TRACE1,
  6042. TEXT("VirtualCtrNode::Commit completed successfully.")));
  6043. }
  6044. else
  6045. {
  6046. DH_TRACE((
  6047. DH_LVL_TRACE1,
  6048. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  6049. hr));
  6050. }
  6051. }
  6052. // Release root
  6053. if (S_OK == hr)
  6054. {
  6055. hr = pVirtualDFRoot->Close();
  6056. if (S_OK == hr)
  6057. {
  6058. DH_TRACE((
  6059. DH_LVL_TRACE1,
  6060. TEXT("VirtualCtrNode::Close completed successfully.")));
  6061. }
  6062. else
  6063. {
  6064. DH_TRACE((
  6065. DH_LVL_TRACE1,
  6066. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  6067. hr));
  6068. }
  6069. }
  6070. // if everything goes well, log test as passed else failed.
  6071. if ((S_OK == hr) && (TRUE == fPass))
  6072. {
  6073. DH_LOG((LOG_PASS, TEXT("Test variation STMTEST_109 passed.")) );
  6074. }
  6075. else
  6076. {
  6077. DH_LOG((LOG_FAIL,
  6078. TEXT("Test variation STMTEST_109 failed, hr=0x%lx."),
  6079. hr) );
  6080. // test failed. make it look like it failed.
  6081. hr = FirstError (hr, E_FAIL);
  6082. }
  6083. // Cleanup
  6084. CleanupTestDocfile (&pVirtualDFRoot,
  6085. &pTestVirtualDF,
  6086. &pTestChanceDF,
  6087. S_OK == hr);
  6088. // Release pMalloc
  6089. if(NULL != pMalloc)
  6090. {
  6091. pMalloc->Release();
  6092. pMalloc = NULL;
  6093. }
  6094. // Delete strings
  6095. if(NULL != pRootNewChildStmName)
  6096. {
  6097. delete pRootNewChildStmName;
  6098. pRootNewChildStmName = NULL;
  6099. }
  6100. // Delete temp buffer
  6101. if(NULL != ptcsBuffer)
  6102. {
  6103. delete [] ptcsBuffer;
  6104. ptcsBuffer = NULL;
  6105. }
  6106. // Stop logging the test
  6107. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation STMTEST_109 finished")) );
  6108. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  6109. return hr;
  6110. }