Source code of Windows XP (NT5)
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.

2666 lines
55 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: Fail.CXX
  7. //
  8. // Contents: Docfile Failure Test
  9. //
  10. // History: 21-Jan-93 AlexT Created
  11. //
  12. // Notes: This test cycles through all failure points for each call,
  13. // verifying that we clean up correctly.
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <headers.cxx>
  17. #pragma hdrstop
  18. #include <sift.hxx>
  19. #if DBG != 1
  20. #error FAIL.EXE requires DBG == 1
  21. #endif
  22. // #define BREADTHTEST // Comment out for depth testing (just most recent tests)
  23. //+-------------------------------------------------------------------------
  24. //
  25. // Function: VerifyDisk
  26. //
  27. // Synopsis: verify that disk file does or does not exist
  28. //
  29. // Arguments: [fExist] -- TRUE if file should exist, else FALSE
  30. // [iteration] -- iteration number
  31. //
  32. // History: 22-Jan-93 AlexT Created
  33. //
  34. //--------------------------------------------------------------------------
  35. void VerifyDisk(BOOL fExist, LONG iteration)
  36. {
  37. if (_access("c:\\testfail.dfl", 0) == 0)
  38. {
  39. if (!fExist)
  40. {
  41. printf("..Iteration %ld, file still exists\n", iteration);
  42. }
  43. }
  44. else
  45. {
  46. if (fExist)
  47. {
  48. printf("..Iteration %ld, file doesn't exist\n", iteration);
  49. }
  50. }
  51. }
  52. //+-------------------------------------------------------------------------
  53. //
  54. // Function: VerifyMemory
  55. //
  56. // Arguments: [iteration] -- iteration number
  57. //
  58. // Requires: Caller should expect 0 memory to be allocated
  59. //
  60. // History: 22-Jan-93 AlexT Created
  61. //
  62. //--------------------------------------------------------------------------
  63. void VerifyMemory(LONG iteration)
  64. {
  65. if (DfGetMemAlloced() > 0L)
  66. {
  67. printf("..Iteration %ld - memory allocated\n", iteration);
  68. DfPrintAllocs();
  69. }
  70. }
  71. //+-------------------------------------------------------------------------
  72. //
  73. // Function: VerifyClean
  74. //
  75. // Synopsis: checks disk, memory
  76. //
  77. // Arguments: [sc] -- status code
  78. // [dwMode] -- Docfile mode
  79. // [iteration] -- iteration
  80. //
  81. // History: 22-Jan-93 AlexT Created
  82. //
  83. //--------------------------------------------------------------------------
  84. void VerifyClean(SCODE sc, DWORD dwMode, LONG iteration)
  85. {
  86. VerifyDisk(SUCCEEDED(sc) &&
  87. !(dwMode & STGM_DELETEONRELEASE), iteration);
  88. VerifyMemory(iteration);
  89. }
  90. //+-------------------------------------------------------------------------
  91. //
  92. // Function: CreateWorkingDocfile
  93. //
  94. // Synopsis: create and verify the test Docfile
  95. //
  96. // Arguments: [dwMode] -- Docfile creation mode
  97. // [ppstg] -- placeholder for IStorage
  98. // [iteration] -- iteration number
  99. //
  100. // Returns: SCODE
  101. //
  102. // Modifies: ppstg
  103. //
  104. // History: 22-Jan-93 AlexT Created
  105. //
  106. //--------------------------------------------------------------------------
  107. SCODE CreateWorkingDocfile(DWORD dwMode, IStorage **ppstg, LONG iteration)
  108. {
  109. SCODE sc;
  110. // Make sample call
  111. remove("c:\\testfail.dfl");
  112. sc = DfGetScode(StgCreateDocfile(
  113. "c:\\testfail.dfl",
  114. dwMode,
  115. 0,
  116. ppstg));
  117. if (FAILED(sc))
  118. {
  119. if (iteration == 0)
  120. {
  121. // This was a prep call. Prep calls aren't supposed to fail
  122. if (sc == STG_E_INVALIDFLAG)
  123. {
  124. // Probably a bad combination of mode flags
  125. printf("..Iteration %ld, sc = STG_E_INVALIDFLAG (OK)\n",
  126. iteration);
  127. }
  128. else if (FAILED(sc))
  129. {
  130. // Something unexpected
  131. printf("..Iteration %ld failed - sc = 0x%lX\n",
  132. iteration, sc);
  133. }
  134. }
  135. else // iteration != 0
  136. {
  137. if (sc == STG_E_INSUFFICIENTMEMORY || sc == STG_E_MEDIUMFULL)
  138. {
  139. // we expected these failures; do nothing
  140. ;
  141. }
  142. else
  143. {
  144. printf("..Iteration %ld failed - sc = 0x%lX (??)\n",
  145. iteration, sc);
  146. }
  147. }
  148. }
  149. return(sc);
  150. }
  151. //+-------------------------------------------------------------------------
  152. //
  153. // Class: CTestStgCreate
  154. //
  155. // Purpose: Test StgCreateDocfile
  156. //
  157. // Interface: CTestCase
  158. //
  159. // History: 26-Jan-93 AlexT Created
  160. //
  161. // Notes:
  162. //
  163. //--------------------------------------------------------------------------
  164. class CTestStgCreate : public CTestCase
  165. {
  166. private:
  167. SCODE _sc;
  168. CModeDf _mdf;
  169. IStorage *_pstg;
  170. public:
  171. virtual BOOL Init(void);
  172. virtual SCODE Prep(LONG iteration);
  173. virtual SCODE Call(LONG iteration);
  174. virtual void EndCall(LONG iteration);
  175. virtual void CallVerify(LONG iteration);
  176. virtual void EndPrep(LONG iteration);
  177. virtual void EndVerify(LONG iteration);
  178. virtual BOOL Next(void);
  179. };
  180. BOOL CTestStgCreate::Init(void)
  181. {
  182. printf("SIFT StgCreateDocfile\n");
  183. _mdf.Init();
  184. return(TRUE);
  185. }
  186. SCODE CTestStgCreate::Prep(LONG iteration)
  187. {
  188. // inherit this?
  189. return(NOERROR);
  190. }
  191. SCODE CTestStgCreate::Call(LONG iteration)
  192. {
  193. if (iteration == 0)
  194. printf("Docfile Mode 0x%lX\n", _mdf.GetMode());
  195. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, iteration);
  196. return(_sc);
  197. }
  198. void CTestStgCreate::EndCall(LONG iteration)
  199. {
  200. _pstg->Release();
  201. }
  202. void CTestStgCreate::CallVerify(LONG iteration)
  203. {
  204. VerifyClean(_sc, _mdf.GetMode(), iteration);
  205. }
  206. void CTestStgCreate::EndPrep(LONG iteration)
  207. {
  208. // inherit this?
  209. }
  210. void CTestStgCreate::EndVerify(LONG iteration)
  211. {
  212. VerifyClean(_sc, _mdf.GetMode(), iteration);
  213. }
  214. BOOL CTestStgCreate::Next(void)
  215. {
  216. if (!_mdf.Next())
  217. return FALSE;
  218. return(TRUE);
  219. }
  220. //+-------------------------------------------------------------------------
  221. //
  222. // Class: CTestCreateStorage
  223. //
  224. // Purpose: Test IStorage::CreateStorage
  225. //
  226. // Interface: CTestCase
  227. //
  228. // History: 26-Jan-93 AlexT Created
  229. //
  230. // Notes:
  231. //
  232. //--------------------------------------------------------------------------
  233. class CTestCreateStorage : public CTestCase
  234. {
  235. private:
  236. SCODE _sc;
  237. CModeDf _mdf;
  238. IStorage *_pstg;
  239. CModeStg _mstg;
  240. IStorage *_pstgChild;
  241. public:
  242. virtual BOOL Init(void);
  243. virtual SCODE Prep(LONG iteration);
  244. virtual SCODE Call(LONG iteration);
  245. virtual void EndCall(LONG iteration);
  246. virtual void CallVerify(LONG iteration);
  247. virtual void EndPrep(LONG iteration);
  248. virtual void EndVerify(LONG iteration);
  249. virtual BOOL Next(void);
  250. };
  251. BOOL CTestCreateStorage::Init(void)
  252. {
  253. printf("SIFT IStorage::CreateStorage\n");
  254. _mdf.Init();
  255. _mstg.Init();
  256. return(TRUE);
  257. }
  258. SCODE CTestCreateStorage::Prep(LONG iteration)
  259. {
  260. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  261. return(_sc);
  262. }
  263. SCODE CTestCreateStorage::Call(LONG iteration)
  264. {
  265. SCODE sc;
  266. if (iteration == 0)
  267. printf("Docfile Mode 0x%lX, Child Storage Mode 0x%lX\n",
  268. _mdf.GetMode(), _mstg.GetMode());
  269. sc = DfGetScode(_pstg->CreateStorage(
  270. "TestFail Storage",
  271. _mstg.GetMode(),
  272. 0,
  273. 0,
  274. &_pstgChild));
  275. return(sc);
  276. }
  277. void CTestCreateStorage::EndCall(LONG iteration)
  278. {
  279. _pstgChild->Release();
  280. }
  281. void CTestCreateStorage::CallVerify(LONG iteration)
  282. {
  283. }
  284. void CTestCreateStorage::EndPrep(LONG iteration)
  285. {
  286. _pstg->Release();
  287. }
  288. void CTestCreateStorage::EndVerify(LONG iteration)
  289. {
  290. VerifyClean(_sc, _mdf.GetMode(), iteration);
  291. }
  292. BOOL CTestCreateStorage::Next(void)
  293. {
  294. if (!_mstg.Next())
  295. {
  296. _mstg.Init();
  297. if (!_mdf.Next())
  298. return(FALSE);
  299. }
  300. return(TRUE);
  301. }
  302. //+-------------------------------------------------------------------------
  303. //
  304. // Class: CTestCreateStream
  305. //
  306. // Purpose: Test IStorage::CreateStream
  307. //
  308. // Interface: CTestCase
  309. //
  310. // History: 26-Jan-93 AlexT Created
  311. //
  312. // Notes:
  313. //
  314. //--------------------------------------------------------------------------
  315. class CTestCreateStream : public CTestCase
  316. {
  317. private:
  318. SCODE _sc;
  319. CModeDf _mdf;
  320. IStorage *_pstg;
  321. CModeStm _mstm;
  322. IStream *_pstmChild;
  323. public:
  324. virtual BOOL Init(void);
  325. virtual SCODE Prep(LONG iteration);
  326. virtual SCODE Call(LONG iteration);
  327. virtual void EndCall(LONG iteration);
  328. virtual void CallVerify(LONG iteration);
  329. virtual void EndPrep(LONG iteration);
  330. virtual void EndVerify(LONG iteration);
  331. virtual BOOL Next(void);
  332. };
  333. BOOL CTestCreateStream::Init(void)
  334. {
  335. printf("SIFT IStorage::CreateStream\n");
  336. _mdf.Init();
  337. _mstm.Init();
  338. return(TRUE);
  339. }
  340. SCODE CTestCreateStream::Prep(LONG iteration)
  341. {
  342. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  343. return(_sc);
  344. }
  345. SCODE CTestCreateStream::Call(LONG iteration)
  346. {
  347. SCODE sc;
  348. if (iteration == 0)
  349. printf("Docfile Mode 0x%lX, Child Stream Mode 0x%lX\n",
  350. _mdf.GetMode(), _mstm.GetMode());
  351. sc = DfGetScode(_pstg->CreateStream(
  352. "TestFail Stream",
  353. _mstm.GetMode(),
  354. 0,
  355. 0,
  356. &_pstmChild));
  357. return(sc);
  358. }
  359. void CTestCreateStream::EndCall(LONG iteration)
  360. {
  361. _pstmChild->Release();
  362. }
  363. void CTestCreateStream::CallVerify(LONG iteration)
  364. {
  365. }
  366. void CTestCreateStream::EndPrep(LONG iteration)
  367. {
  368. _pstg->Release();
  369. }
  370. void CTestCreateStream::EndVerify(LONG iteration)
  371. {
  372. VerifyClean(_sc, _mdf.GetMode(), iteration);
  373. }
  374. BOOL CTestCreateStream::Next(void)
  375. {
  376. if (!_mstm.Next())
  377. {
  378. _mstm.Init();
  379. if (!_mdf.Next())
  380. return(FALSE);
  381. }
  382. return(TRUE);
  383. }
  384. //+-------------------------------------------------------------------------
  385. //
  386. // Class: CTestWrite
  387. //
  388. // Purpose: Test IStream::Write
  389. //
  390. // Interface: CTestCase
  391. //
  392. // History: 26-Jan-93 AlexT Created
  393. //
  394. // Notes:
  395. //
  396. //--------------------------------------------------------------------------
  397. class CTestWrite : public CTestCase
  398. {
  399. private:
  400. SCODE _sc;
  401. CModeDf _mdf;
  402. IStorage *_pstg;
  403. CModeStm _mstm;
  404. IStream *_pstmChild;
  405. public:
  406. virtual BOOL Init(void);
  407. virtual SCODE Prep(LONG iteration);
  408. virtual SCODE Call(LONG iteration);
  409. virtual void EndCall(LONG iteration);
  410. virtual void CallVerify(LONG iteration);
  411. virtual void EndPrep(LONG iteration);
  412. virtual void EndVerify(LONG iteration);
  413. virtual BOOL Next(void);
  414. };
  415. BOOL CTestWrite::Init(void)
  416. {
  417. printf("SIFT IStream::Write\n");
  418. _mdf.Init();
  419. _mstm.Init();
  420. return(TRUE);
  421. }
  422. SCODE CTestWrite::Prep(LONG iteration)
  423. {
  424. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  425. if (SUCCEEDED(_sc))
  426. {
  427. _sc = DfGetScode(_pstg->CreateStream(
  428. "TestFail Stream",
  429. _mstm.GetMode(),
  430. 0,
  431. 0,
  432. &_pstmChild));
  433. if (FAILED(_sc))
  434. _pstg->Release();
  435. }
  436. return(_sc);
  437. }
  438. SCODE CTestWrite::Call(LONG iteration)
  439. {
  440. SCODE sc;
  441. ULONG cb = 1;
  442. char c = 'X';
  443. ULONG cbWritten;
  444. if (iteration == 0)
  445. printf("Docfile Mode 0x%lX, Stream Mode 0x%lX, Write %ld bytes\n",
  446. _mdf.GetMode(), _mstm.GetMode(), cb);
  447. sc = DfGetScode(_pstmChild->Write(&c, cb, &cbWritten));
  448. if (FAILED(sc))
  449. {
  450. if (sc != STG_E_MEDIUMFULL)
  451. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  452. iteration, sc);
  453. }
  454. return(sc);
  455. }
  456. void CTestWrite::EndCall(LONG iteration)
  457. {
  458. }
  459. void CTestWrite::CallVerify(LONG iteration)
  460. {
  461. }
  462. void CTestWrite::EndPrep(LONG iteration)
  463. {
  464. _pstmChild->Release();
  465. _pstg->Release();
  466. }
  467. void CTestWrite::EndVerify(LONG iteration)
  468. {
  469. VerifyClean(_sc, _mdf.GetMode(), iteration);
  470. }
  471. BOOL CTestWrite::Next(void)
  472. {
  473. if (!_mstm.Next())
  474. {
  475. _mstm.Init();
  476. if (!_mdf.Next())
  477. return(FALSE);
  478. }
  479. return(TRUE);
  480. }
  481. //+-------------------------------------------------------------------------
  482. //
  483. // Class: CTestOpenStream
  484. //
  485. // Purpose: Test IStorage::OpenStream
  486. //
  487. // Interface: CTestCase
  488. //
  489. // History: 26-Jan-93 AlexT Created
  490. //
  491. // Notes:
  492. //
  493. //--------------------------------------------------------------------------
  494. class CTestOpenStream : public CTestCase
  495. {
  496. private:
  497. SCODE _sc;
  498. CModeDf _mdf;
  499. IStorage *_pstg;
  500. CModeStm _mstm;
  501. IStream *_pstm;
  502. public:
  503. virtual BOOL Init(void);
  504. virtual SCODE Prep(LONG iteration);
  505. virtual SCODE Call(LONG iteration);
  506. virtual void EndCall(LONG iteration);
  507. virtual void CallVerify(LONG iteration);
  508. virtual void EndPrep(LONG iteration);
  509. virtual void EndVerify(LONG iteration);
  510. virtual BOOL Next(void);
  511. };
  512. BOOL CTestOpenStream::Init(void)
  513. {
  514. printf("SIFT IStorage::OpenStream\n");
  515. _mdf.Init();
  516. _mstm.Init();
  517. return(TRUE);
  518. }
  519. SCODE CTestOpenStream::Prep(LONG iteration)
  520. {
  521. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  522. if (SUCCEEDED(_sc))
  523. {
  524. _sc = DfGetScode(_pstg->CreateStream(
  525. "TestFail Stream",
  526. _mstm.GetMode(),
  527. 0,
  528. 0,
  529. &_pstm));
  530. if (FAILED(_sc))
  531. _pstg->Release();
  532. else
  533. _pstm->Release();
  534. }
  535. return(_sc);
  536. }
  537. SCODE CTestOpenStream::Call(LONG iteration)
  538. {
  539. SCODE sc;
  540. if (iteration == 0)
  541. printf("Docfile Mode 0x%lX, Stream Mode 0x%lX\n",
  542. _mdf.GetMode(), _mstm.GetMode());
  543. sc = DfGetScode(_pstg->OpenStream(
  544. "TestFail Stream",
  545. 0,
  546. _mstm.GetMode(),
  547. 0,
  548. &_pstm));
  549. return(sc);
  550. }
  551. void CTestOpenStream::EndCall(LONG iteration)
  552. {
  553. _pstm->Release();
  554. }
  555. void CTestOpenStream::CallVerify(LONG iteration)
  556. {
  557. }
  558. void CTestOpenStream::EndPrep(LONG iteration)
  559. {
  560. _pstg->Release();
  561. }
  562. void CTestOpenStream::EndVerify(LONG iteration)
  563. {
  564. VerifyClean(_sc, _mdf.GetMode(), iteration);
  565. }
  566. BOOL CTestOpenStream::Next(void)
  567. {
  568. if (!_mstm.Next())
  569. {
  570. _mstm.Init();
  571. if (!_mdf.Next())
  572. return(FALSE);
  573. }
  574. return(TRUE);
  575. }
  576. //+-------------------------------------------------------------------------
  577. //
  578. // Class: CTestOpenStorage
  579. //
  580. // Purpose: Test IStorage::OpenStorage
  581. //
  582. // Interface: CTestCase
  583. //
  584. // History: 26-Jan-93 AlexT Created
  585. //
  586. // Notes:
  587. //
  588. //--------------------------------------------------------------------------
  589. class CTestOpenStorage : public CTestCase
  590. {
  591. private:
  592. SCODE _sc;
  593. CModeDf _mdf;
  594. IStorage *_pstg;
  595. CModeStg _mstg;
  596. IStorage *_pstgChild;
  597. public:
  598. virtual BOOL Init(void);
  599. virtual SCODE Prep(LONG iteration);
  600. virtual SCODE Call(LONG iteration);
  601. virtual void EndCall(LONG iteration);
  602. virtual void CallVerify(LONG iteration);
  603. virtual void EndPrep(LONG iteration);
  604. virtual void EndVerify(LONG iteration);
  605. virtual BOOL Next(void);
  606. };
  607. BOOL CTestOpenStorage::Init(void)
  608. {
  609. printf("SIFT IStorage::OpenStorage\n");
  610. _mdf.Init();
  611. _mstg.Init();
  612. return(TRUE);
  613. }
  614. SCODE CTestOpenStorage::Prep(LONG iteration)
  615. {
  616. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  617. if (SUCCEEDED(_sc))
  618. {
  619. _sc = DfGetScode(_pstg->CreateStorage(
  620. "TestFail Storage",
  621. _mstg.GetMode(),
  622. 0,
  623. 0,
  624. &_pstgChild));
  625. if (FAILED(_sc))
  626. _pstg->Release();
  627. else
  628. _pstgChild->Release();
  629. }
  630. return(_sc);
  631. }
  632. SCODE CTestOpenStorage::Call(LONG iteration)
  633. {
  634. SCODE sc;
  635. if (iteration == 0)
  636. printf("Docfile Mode 0x%lX, Storage Mode 0x%lX\n",
  637. _mdf.GetMode(), _mstg.GetMode());
  638. sc = DfGetScode(_pstg->OpenStorage("TestFail Storage", 0,
  639. _mstg.GetMode(), 0, 0, &_pstgChild));
  640. return(sc);
  641. }
  642. void CTestOpenStorage::EndCall(LONG iteration)
  643. {
  644. _pstgChild->Release();
  645. }
  646. void CTestOpenStorage::CallVerify(LONG iteration)
  647. {
  648. }
  649. void CTestOpenStorage::EndPrep(LONG iteration)
  650. {
  651. _pstg->Release();
  652. }
  653. void CTestOpenStorage::EndVerify(LONG iteration)
  654. {
  655. VerifyClean(_sc, _mdf.GetMode(), iteration);
  656. }
  657. BOOL CTestOpenStorage::Next(void)
  658. {
  659. if (!_mstg.Next())
  660. {
  661. _mstg.Init();
  662. if (!_mdf.Next())
  663. return(FALSE);
  664. }
  665. return(TRUE);
  666. }
  667. //+-------------------------------------------------------------------------
  668. //
  669. // Class: CTestCommit
  670. //
  671. // Purpose: Test IStream::Write
  672. //
  673. // Interface: CTestCase
  674. //
  675. // History: 26-Jan-93 AlexT Created
  676. //
  677. // Notes:
  678. //
  679. //--------------------------------------------------------------------------
  680. class CTestCommit : public CTestCase
  681. {
  682. private:
  683. CModeDf _mdf;
  684. IStorage *_pstg;
  685. CModeStg _mstg;
  686. IStorage *_pstgChild;
  687. public:
  688. virtual BOOL Init(void);
  689. virtual SCODE Prep(LONG iteration);
  690. virtual SCODE Call(LONG iteration);
  691. virtual void EndCall(LONG iteration);
  692. virtual void CallVerify(LONG iteration);
  693. virtual void EndPrep(LONG iteration);
  694. virtual void EndVerify(LONG iteration);
  695. virtual BOOL Next(void);
  696. };
  697. BOOL CTestCommit::Init(void)
  698. {
  699. printf("SIFT IStorage::Commit\n");
  700. _mdf.Init();
  701. _mstg.Init();
  702. return(TRUE);
  703. }
  704. SCODE CTestCommit::Prep(LONG iteration)
  705. {
  706. SCODE sc;
  707. sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  708. if (SUCCEEDED(sc))
  709. {
  710. sc = DfGetScode(_pstg->CreateStorage(
  711. "TestFail Storage",
  712. _mstg.GetMode(),
  713. 0,
  714. 0,
  715. &_pstgChild));
  716. if (FAILED(sc))
  717. _pstg->Release();
  718. }
  719. return(sc);
  720. }
  721. SCODE CTestCommit::Call(LONG iteration)
  722. {
  723. SCODE sc;
  724. if (iteration == 0)
  725. printf("Docfile Mode 0x%lX, Storage Mode 0x%lX\n",
  726. _mdf.GetMode(), _mstg.GetMode());
  727. sc = DfGetScode(_pstgChild->Commit(0));
  728. if (FAILED(sc))
  729. {
  730. if (sc != STG_E_MEDIUMFULL)
  731. printf("..Iteration %ld - STG_E_MEDIUMFULL\n", iteration);
  732. else
  733. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  734. iteration, sc);
  735. }
  736. return(sc);
  737. }
  738. void CTestCommit::EndCall(LONG iteration)
  739. {
  740. }
  741. void CTestCommit::CallVerify(LONG iteration)
  742. {
  743. }
  744. void CTestCommit::EndPrep(LONG iteration)
  745. {
  746. _pstgChild->Release();
  747. _pstg->Release();
  748. }
  749. void CTestCommit::EndVerify(LONG iteration)
  750. {
  751. VerifyClean(S_OK, _mdf.GetMode(), iteration);
  752. }
  753. BOOL CTestCommit::Next(void)
  754. {
  755. if (!_mstg.Next())
  756. {
  757. _mstg.Init();
  758. if (!_mdf.Next())
  759. return(FALSE);
  760. }
  761. return(TRUE);
  762. }
  763. //+-------------------------------------------------------------------------
  764. //
  765. // Class: CTestCommit2
  766. //
  767. // Purpose: Test IStorage::Commit
  768. //
  769. // Interface: CTestCase
  770. //
  771. // History: 26-Jan-93 AlexT Created
  772. //
  773. // Notes:
  774. //
  775. //--------------------------------------------------------------------------
  776. class CTestCommit2 : public CTestCase
  777. {
  778. private:
  779. CModeDf _mdf;
  780. IStorage *_pstg;
  781. CModeStg _mstg;
  782. IStorage *_pstgChild;
  783. IStream *_pstmChild;
  784. public:
  785. virtual BOOL Init(void);
  786. virtual SCODE Prep(LONG iteration);
  787. virtual SCODE Call(LONG iteration);
  788. virtual void EndCall(LONG iteration);
  789. virtual void CallVerify(LONG iteration);
  790. virtual void EndPrep(LONG iteration);
  791. virtual void EndVerify(LONG iteration);
  792. virtual BOOL Next(void);
  793. };
  794. BOOL CTestCommit2::Init(void)
  795. {
  796. printf("SIFT IStorage::Commit\n");
  797. _mdf.Init();
  798. _mstg.Init();
  799. return(TRUE);
  800. }
  801. SCODE CTestCommit2::Prep(LONG iteration)
  802. {
  803. SCODE sc;
  804. ULONG cb = 1;
  805. char c = 'X';
  806. ULONG cbWritten;
  807. sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  808. if (SUCCEEDED(sc))
  809. {
  810. sc = DfGetScode(_pstg->CreateStorage(
  811. "TestFail Storage",
  812. _mstg.GetMode(),
  813. 0,
  814. 0,
  815. &_pstgChild));
  816. if (FAILED(sc))
  817. _pstg->Release();
  818. else
  819. {
  820. sc = DfGetScode(_pstgChild->CreateStream(
  821. "TestFail Stream",
  822. STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  823. 0,
  824. 0,
  825. &_pstmChild));
  826. if (FAILED(sc))
  827. {
  828. _pstgChild->Release();
  829. _pstg->Release();
  830. }
  831. else
  832. {
  833. sc = DfGetScode(_pstmChild->Write(&c, cb, &cbWritten));
  834. if (FAILED(sc))
  835. {
  836. _pstmChild->Release();
  837. _pstgChild->Release();
  838. _pstg->Release();
  839. }
  840. }
  841. }
  842. }
  843. return(sc);
  844. }
  845. SCODE CTestCommit2::Call(LONG iteration)
  846. {
  847. SCODE sc;
  848. if (iteration == 0)
  849. printf("Docfile Mode 0x%lX, Storage Mode 0x%lX\n",
  850. _mdf.GetMode(), _mstg.GetMode());
  851. sc = DfGetScode(_pstgChild->Commit(0));
  852. if (FAILED(sc))
  853. {
  854. if (sc == STG_E_MEDIUMFULL)
  855. printf("..Iteration %ld - STG_E_MEDIUMFULL\n", iteration);
  856. else
  857. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  858. iteration, sc);
  859. }
  860. return(sc);
  861. }
  862. void CTestCommit2::EndCall(LONG iteration)
  863. {
  864. }
  865. void CTestCommit2::CallVerify(LONG iteration)
  866. {
  867. }
  868. void CTestCommit2::EndPrep(LONG iteration)
  869. {
  870. _pstmChild->Release();
  871. _pstgChild->Release();
  872. _pstg->Release();
  873. }
  874. void CTestCommit2::EndVerify(LONG iteration)
  875. {
  876. VerifyClean(S_OK, _mdf.GetMode(), iteration);
  877. }
  878. BOOL CTestCommit2::Next(void)
  879. {
  880. if (!_mstg.Next())
  881. {
  882. _mstg.Init();
  883. if (!_mdf.Next())
  884. return(FALSE);
  885. }
  886. return(TRUE);
  887. }
  888. //+-------------------------------------------------------------------------
  889. //
  890. // Class: CTestCommit3
  891. //
  892. // Purpose: Test IStorage::Commit
  893. //
  894. // Interface: CTestCase
  895. //
  896. // History: 26-Jan-93 AlexT Created
  897. //
  898. // Notes:
  899. //
  900. //--------------------------------------------------------------------------
  901. class CTestCommit3 : public CTestCase
  902. {
  903. private:
  904. CModeDf _mdf;
  905. IStorage *_pstg;
  906. public:
  907. virtual BOOL Init(void);
  908. virtual SCODE Prep(LONG iteration);
  909. virtual SCODE Call(LONG iteration);
  910. virtual void EndCall(LONG iteration);
  911. virtual void CallVerify(LONG iteration);
  912. virtual void EndPrep(LONG iteration);
  913. virtual void EndVerify(LONG iteration);
  914. virtual BOOL Next(void);
  915. };
  916. BOOL CTestCommit3::Init(void)
  917. {
  918. printf("SIFT IStorage::Commit\n");
  919. _mdf.Init();
  920. return(TRUE);
  921. }
  922. SCODE CTestCommit3::Prep(LONG iteration)
  923. {
  924. SCODE sc;
  925. ULONG cb = 1;
  926. char c = 'X';
  927. sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  928. if (FAILED(sc))
  929. return(sc);
  930. IStream *pstm;
  931. sc = DfGetScode(_pstg->CreateStream(
  932. "PP40",
  933. STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  934. 0,
  935. 0,
  936. &pstm));
  937. pstm->Release();
  938. IStorage *pstgChild;
  939. sc = DfGetScode(_pstg->CreateStorage(
  940. "TestFail Storage",
  941. STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  942. 0,
  943. 0,
  944. &pstgChild));
  945. sc = DfGetScode(pstgChild->CreateStream(
  946. "One",
  947. STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  948. 0,
  949. 0,
  950. &pstm));
  951. pstm->Release();
  952. sc = DfGetScode(pstgChild->CreateStream(
  953. "Two",
  954. STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  955. 0,
  956. 0,
  957. &pstm));
  958. pstm->Release();
  959. sc = DfGetScode(pstgChild->CreateStream(
  960. "Three",
  961. STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE,
  962. 0,
  963. 0,
  964. &pstm));
  965. pstm->Release();
  966. sc = DfGetScode(pstgChild->Commit(0));
  967. pstgChild->Release();
  968. return(sc);
  969. }
  970. SCODE CTestCommit3::Call(LONG iteration)
  971. {
  972. SCODE sc;
  973. if (iteration == 0)
  974. printf("Docfile Mode 0x%lX\n",
  975. _mdf.GetMode());
  976. sc = DfGetScode(_pstg->Commit(0));
  977. if (FAILED(sc))
  978. {
  979. if (sc == STG_E_MEDIUMFULL)
  980. printf("..Iteration %ld - STG_E_MEDIUMFULL\n", iteration);
  981. else
  982. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  983. iteration, sc);
  984. }
  985. return(sc);
  986. }
  987. void CTestCommit3::EndCall(LONG iteration)
  988. {
  989. }
  990. void CTestCommit3::CallVerify(LONG iteration)
  991. {
  992. }
  993. void CTestCommit3::EndPrep(LONG iteration)
  994. {
  995. _pstg->Release();
  996. }
  997. void CTestCommit3::EndVerify(LONG iteration)
  998. {
  999. VerifyClean(S_OK, _mdf.GetMode(), iteration);
  1000. }
  1001. BOOL CTestCommit3::Next(void)
  1002. {
  1003. if (!_mdf.Next())
  1004. return(FALSE);
  1005. return(TRUE);
  1006. }
  1007. //+-------------------------------------------------------------------------
  1008. //
  1009. // Class: CTestCommit4
  1010. //
  1011. // Purpose: Test IStorage::Commit with resized streams
  1012. //
  1013. // Interface: CTestCase
  1014. //
  1015. // History: 08-Sep-93 DrewB Created
  1016. //
  1017. //--------------------------------------------------------------------------
  1018. class CTestCommit4 : public CTestCase
  1019. {
  1020. private:
  1021. CModeDf _mdf;
  1022. IStorage *_pstg;
  1023. public:
  1024. virtual BOOL Init(void);
  1025. virtual SCODE Prep(LONG iteration);
  1026. virtual SCODE Call(LONG iteration);
  1027. virtual void EndCall(LONG iteration);
  1028. virtual void CallVerify(LONG iteration);
  1029. virtual void EndPrep(LONG iteration);
  1030. virtual void EndVerify(LONG iteration);
  1031. virtual BOOL Next(void);
  1032. };
  1033. BOOL CTestCommit4::Init(void)
  1034. {
  1035. printf("SIFT IStorage::Commit\n");
  1036. _mdf.Init();
  1037. return(TRUE);
  1038. }
  1039. #define LARGE_SIZE 4097
  1040. #define SMALL_SIZE 4095
  1041. SCODE CTestCommit4::Prep(LONG iteration)
  1042. {
  1043. SCODE sc;
  1044. IStream *pstm;
  1045. ULARGE_INTEGER uli;
  1046. sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1047. if (FAILED(sc))
  1048. goto EH_Err;
  1049. sc = DfGetScode(_pstg->CreateStream("Test",
  1050. STGM_DIRECT | STGM_SHARE_EXCLUSIVE |
  1051. STGM_READWRITE, 0, 0, &pstm));
  1052. if (FAILED(sc))
  1053. goto EH_pstg;
  1054. uli.HighPart = 0;
  1055. uli.LowPart = LARGE_SIZE;
  1056. sc = DfGetScode(pstm->SetSize(uli));
  1057. if (FAILED(sc))
  1058. goto EH_pstm;
  1059. sc = DfGetScode(_pstg->Commit(0));
  1060. if (FAILED(sc))
  1061. goto EH_pstm;
  1062. uli.LowPart = SMALL_SIZE;
  1063. sc = DfGetScode(pstm->SetSize(uli));
  1064. if (FAILED(sc))
  1065. goto EH_pstm;
  1066. pstm->Release();
  1067. return sc;
  1068. EH_pstm:
  1069. pstm->Release();
  1070. EH_pstg:
  1071. _pstg->Release();
  1072. EH_Err:
  1073. return sc;
  1074. }
  1075. SCODE CTestCommit4::Call(LONG iteration)
  1076. {
  1077. SCODE sc;
  1078. if (iteration == 0)
  1079. printf("Docfile Mode 0x%lX\n",
  1080. _mdf.GetMode());
  1081. sc = DfGetScode(_pstg->Commit(0));
  1082. if (FAILED(sc))
  1083. {
  1084. if (sc == STG_E_MEDIUMFULL)
  1085. printf("..Iteration %ld - STG_E_MEDIUMFULL\n", iteration);
  1086. else
  1087. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  1088. iteration, sc);
  1089. }
  1090. return(sc);
  1091. }
  1092. void CTestCommit4::EndCall(LONG iteration)
  1093. {
  1094. }
  1095. void CTestCommit4::CallVerify(LONG iteration)
  1096. {
  1097. IStream *pstm;
  1098. SCODE sc;
  1099. STATSTG stat;
  1100. sc = DfGetScode(_pstg->OpenStream("Test", NULL, STGM_DIRECT |
  1101. STGM_SHARE_EXCLUSIVE, 0, &pstm));
  1102. if (FAILED(sc))
  1103. {
  1104. printf("Can't open stream - %lX\n", sc);
  1105. return;
  1106. }
  1107. sc = DfGetScode(pstm->Stat(&stat, STATFLAG_NONAME));
  1108. pstm->Release();
  1109. if (FAILED(sc))
  1110. {
  1111. printf("Can't stat stream - %lX\n", sc);
  1112. return;
  1113. }
  1114. if (stat.cbSize.LowPart != SMALL_SIZE)
  1115. {
  1116. printf("Stream length is %lu rather than %d\n",
  1117. stat.cbSize.LowPart, SMALL_SIZE);
  1118. return;
  1119. }
  1120. }
  1121. void CTestCommit4::EndPrep(LONG iteration)
  1122. {
  1123. _pstg->Release();
  1124. }
  1125. void CTestCommit4::EndVerify(LONG iteration)
  1126. {
  1127. VerifyClean(S_OK, _mdf.GetMode(), iteration);
  1128. }
  1129. BOOL CTestCommit4::Next(void)
  1130. {
  1131. if (!_mdf.Next())
  1132. return(FALSE);
  1133. return(TRUE);
  1134. }
  1135. //+-------------------------------------------------------------------------
  1136. //
  1137. // Class: CTestStgOpen
  1138. //
  1139. // Purpose: Test StgOpenStorage
  1140. //
  1141. // Interface: CTestCase
  1142. //
  1143. // History: 28-Jan-93 AlexT Created
  1144. //
  1145. // Notes:
  1146. //
  1147. //--------------------------------------------------------------------------
  1148. class CTestStgOpen : public CTestCase
  1149. {
  1150. private:
  1151. SCODE _sc;
  1152. CModeDf _mdf;
  1153. IStorage *_pstg;
  1154. public:
  1155. virtual BOOL Init(void);
  1156. virtual SCODE Prep(LONG iteration);
  1157. virtual SCODE Call(LONG iteration);
  1158. virtual void EndCall(LONG iteration);
  1159. virtual void CallVerify(LONG iteration);
  1160. virtual void EndPrep(LONG iteration);
  1161. virtual void EndVerify(LONG iteration);
  1162. virtual BOOL Next(void);
  1163. };
  1164. BOOL CTestStgOpen::Init(void)
  1165. {
  1166. printf("SIFT StgOpenStorage\n");
  1167. _mdf.Init();
  1168. return(TRUE);
  1169. }
  1170. SCODE CTestStgOpen::Prep(LONG iteration)
  1171. {
  1172. SCODE sc;
  1173. DWORD dwMode = STGM_DIRECT |
  1174. STGM_READWRITE |
  1175. STGM_SHARE_EXCLUSIVE |
  1176. STGM_FAILIFTHERE;
  1177. IStorage *pstg, *pstgChild;
  1178. IStream *pstmChild;
  1179. sc = CreateWorkingDocfile(dwMode, &pstg, 0);
  1180. if (SUCCEEDED(sc))
  1181. {
  1182. sc = DfGetScode(pstg->CreateStorage(
  1183. "TestFail Storage",
  1184. dwMode,
  1185. 0,
  1186. 0,
  1187. &pstgChild));
  1188. if (SUCCEEDED(sc))
  1189. {
  1190. sc = DfGetScode(pstgChild->CreateStream(
  1191. "TestFail Stream",
  1192. dwMode,
  1193. 0,
  1194. 0,
  1195. &pstmChild));
  1196. if (SUCCEEDED(sc))
  1197. pstmChild->Release();
  1198. pstgChild->Release();
  1199. }
  1200. pstg->Release();
  1201. }
  1202. return(sc);
  1203. }
  1204. SCODE CTestStgOpen::Call(LONG iteration)
  1205. {
  1206. if (iteration == 0)
  1207. printf("Docfile Mode 0x%lX\n", _mdf.GetMode());
  1208. _sc = DfGetScode(StgOpenStorage("c:\\testfail.dfl",
  1209. NULL,
  1210. _mdf.GetMode(),
  1211. NULL,
  1212. 0,
  1213. &_pstg));
  1214. if (FAILED(_sc))
  1215. {
  1216. if (iteration == 0 && _sc == STG_E_INVALIDFLAG)
  1217. {
  1218. printf("..STG_E_INVALIDFLAG\n");
  1219. // Must have been a bad combination of flags - we
  1220. // ignore these for now.
  1221. }
  1222. else if (iteration > 0 && _sc == STG_E_INSUFFICIENTMEMORY)
  1223. {
  1224. // Do nothing (expected failure)
  1225. }
  1226. else if (iteration > 0 && _sc == STG_E_MEDIUMFULL)
  1227. {
  1228. // Do nothing (expected failure)
  1229. }
  1230. else
  1231. printf("..Iteration %ld, call failed - sc = 0x%lX\n",
  1232. iteration, _sc);
  1233. }
  1234. return(_sc);
  1235. }
  1236. void CTestStgOpen::EndCall(LONG iteration)
  1237. {
  1238. _pstg->Release();
  1239. }
  1240. void CTestStgOpen::CallVerify(LONG iteration)
  1241. {
  1242. }
  1243. void CTestStgOpen::EndPrep(LONG iteration)
  1244. {
  1245. }
  1246. void CTestStgOpen::EndVerify(LONG iteration)
  1247. {
  1248. // If the call failed, the file should still exist.
  1249. // If the call succeeded
  1250. // If mode was delete on release,
  1251. // file should not exist
  1252. // else file should exist
  1253. VerifyDisk((SUCCEEDED(_sc) && (!(_mdf.GetMode() & STGM_DELETEONRELEASE))) ||
  1254. FAILED(_sc), iteration);
  1255. VerifyMemory(iteration);
  1256. }
  1257. BOOL CTestStgOpen::Next(void)
  1258. {
  1259. if (!_mdf.Next())
  1260. return(FALSE);
  1261. return(TRUE);
  1262. }
  1263. //+-------------------------------------------------------------------------
  1264. //
  1265. // Class: CTestWrite2
  1266. //
  1267. // Purpose: Test IStream::Write for largish writes
  1268. //
  1269. // Interface: CTestCase
  1270. //
  1271. // History: 16-Feb-93 PhilipLa Created.
  1272. //
  1273. // Notes:
  1274. //
  1275. //--------------------------------------------------------------------------
  1276. class CTestWrite2 : public CTestCase
  1277. {
  1278. private:
  1279. SCODE _sc;
  1280. BYTE *_pb;
  1281. CModeDf _mdf;
  1282. IStorage *_pstg;
  1283. CModeStm _mstm;
  1284. IStream *_pstmChild;
  1285. ULONG _cb;
  1286. ULONG _cBlock;
  1287. ULONG _cbSize;
  1288. public:
  1289. virtual BOOL Init(void);
  1290. virtual SCODE Prep(LONG iteration);
  1291. virtual SCODE Call(LONG iteration);
  1292. virtual void EndCall(LONG iteration);
  1293. virtual void CallVerify(LONG iteration);
  1294. virtual void EndPrep(LONG iteration);
  1295. virtual void EndVerify(LONG iteration);
  1296. virtual BOOL Next(void);
  1297. };
  1298. BOOL CTestWrite2::Init(void)
  1299. {
  1300. printf("SIFT IStream::Write2 - large writes without Setsize\n");
  1301. _mdf.Init();
  1302. _mstm.Init();
  1303. _cb = 8192;
  1304. _cBlock = 8;
  1305. _pb = NULL;
  1306. return(TRUE);
  1307. }
  1308. SCODE CTestWrite2::Prep(LONG iteration)
  1309. {
  1310. _pb = new BYTE[8192];
  1311. memset(_pb, 'X', 8192);
  1312. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1313. if (SUCCEEDED(_sc))
  1314. {
  1315. _sc = DfGetScode(_pstg->CreateStream(
  1316. "TestFail Stream",
  1317. _mstm.GetMode(),
  1318. 0,
  1319. 0,
  1320. &_pstmChild));
  1321. _cbSize = 0;
  1322. if (FAILED(_sc))
  1323. _pstg->Release();
  1324. }
  1325. return(_sc);
  1326. }
  1327. SCODE CTestWrite2::Call(LONG iteration)
  1328. {
  1329. SCODE sc;
  1330. ULONG cbWritten;
  1331. if (iteration == 0)
  1332. printf("Docfile Mode 0x%lX, Stream Mode 0x%lX, Write %ld bytes\n",
  1333. _mdf.GetMode(), _mstm.GetMode(), _cb * _cBlock);
  1334. for (ULONG i = 0; i < _cBlock; i++)
  1335. {
  1336. sc = DfGetScode(_pstmChild->Write(_pb, _cb, &cbWritten));
  1337. _cbSize += cbWritten;
  1338. if (FAILED(sc))
  1339. {
  1340. if (sc != STG_E_MEDIUMFULL)
  1341. printf("..Iteration %ld, block %lu - failed - sc = 0x%lX\n",
  1342. iteration, i + 1, sc);
  1343. break;
  1344. }
  1345. }
  1346. return(sc);
  1347. }
  1348. void CTestWrite2::EndCall(LONG iteration)
  1349. {
  1350. STATSTG stat;
  1351. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1352. if (ULIGetLow(stat.cbSize) != _cbSize)
  1353. {
  1354. printf("..Iteration %lu - Size of stream is %lu. Expected %lu\n",
  1355. iteration, ULIGetLow(stat.cbSize), _cbSize);
  1356. }
  1357. }
  1358. void CTestWrite2::CallVerify(LONG iteration)
  1359. {
  1360. STATSTG stat;
  1361. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1362. if (ULIGetLow(stat.cbSize) != _cbSize)
  1363. {
  1364. printf("..Iteration %lu - Size of stream is %lu. Expected %lu\n",
  1365. iteration, ULIGetLow(stat.cbSize), _cbSize);
  1366. }
  1367. }
  1368. void CTestWrite2::EndPrep(LONG iteration)
  1369. {
  1370. delete _pb;
  1371. _pb = NULL;
  1372. _pstmChild->Release();
  1373. _pstg->Release();
  1374. }
  1375. void CTestWrite2::EndVerify(LONG iteration)
  1376. {
  1377. VerifyClean(_sc, _mdf.GetMode(), iteration);
  1378. }
  1379. BOOL CTestWrite2::Next(void)
  1380. {
  1381. if (!_mstm.Next())
  1382. {
  1383. _mstm.Init();
  1384. if (!_mdf.Next())
  1385. return(FALSE);
  1386. }
  1387. return(TRUE);
  1388. }
  1389. //+-------------------------------------------------------------------------
  1390. //
  1391. // Class: CTestWrite3
  1392. //
  1393. // Purpose: Test IStream::Write for largish writes
  1394. //
  1395. // Interface: CTestCase
  1396. //
  1397. // History: 16-Feb-93 PhilipLa Created.
  1398. //
  1399. // Notes:
  1400. //
  1401. //--------------------------------------------------------------------------
  1402. class CTestWrite3 : public CTestCase
  1403. {
  1404. private:
  1405. SCODE _sc;
  1406. BYTE *_pb;
  1407. CModeDf _mdf;
  1408. IStorage *_pstg;
  1409. CModeStm _mstm;
  1410. IStream *_pstmChild;
  1411. ULONG _cb;
  1412. ULONG _cBlock;
  1413. public:
  1414. virtual BOOL Init(void);
  1415. virtual SCODE Prep(LONG iteration);
  1416. virtual SCODE Call(LONG iteration);
  1417. virtual void EndCall(LONG iteration);
  1418. virtual void CallVerify(LONG iteration);
  1419. virtual void EndPrep(LONG iteration);
  1420. virtual void EndVerify(LONG iteration);
  1421. virtual BOOL Next(void);
  1422. };
  1423. BOOL CTestWrite3::Init(void)
  1424. {
  1425. printf("SIFT IStream::Write3 - large writes with prior Setsize\n");
  1426. _mdf.Init();
  1427. _mstm.Init();
  1428. _cb = 8192;
  1429. _cBlock = 8;
  1430. _pb = NULL;
  1431. return(TRUE);
  1432. }
  1433. SCODE CTestWrite3::Prep(LONG iteration)
  1434. {
  1435. _pb = new BYTE[8192];
  1436. memset(_pb, 'X', 8192);
  1437. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1438. if (SUCCEEDED(_sc))
  1439. {
  1440. _sc = DfGetScode(_pstg->CreateStream(
  1441. "TestFail Stream",
  1442. _mstm.GetMode(),
  1443. 0,
  1444. 0,
  1445. &_pstmChild));
  1446. if (FAILED(_sc))
  1447. _pstg->Release();
  1448. else
  1449. {
  1450. ULARGE_INTEGER cbSize;
  1451. ULISet32(cbSize, _cb * _cBlock);
  1452. _sc = DfGetScode(_pstmChild->SetSize(cbSize));
  1453. if (FAILED(_sc))
  1454. {
  1455. _pstmChild->Release();
  1456. _pstg->Release();
  1457. }
  1458. }
  1459. }
  1460. return(_sc);
  1461. }
  1462. SCODE CTestWrite3::Call(LONG iteration)
  1463. {
  1464. SCODE sc;
  1465. ULONG cbWritten;
  1466. if (iteration == 0)
  1467. printf("Docfile Mode 0x%lX, Stream Mode 0x%lX, Write %ld bytes\n",
  1468. _mdf.GetMode(), _mstm.GetMode(), _cb * _cBlock);
  1469. else
  1470. printf("ERROR - shouldn't hit iteration %lu\n", iteration);
  1471. for (ULONG i = 0; i < _cBlock; i++)
  1472. {
  1473. sc = DfGetScode(_pstmChild->Write(_pb, _cb, &cbWritten));
  1474. if (FAILED(sc))
  1475. {
  1476. if (sc != STG_E_MEDIUMFULL)
  1477. printf("..Iteration %ld, block %lu - failed - sc = 0x%lX\n",
  1478. iteration, i + 1, sc);
  1479. break;
  1480. }
  1481. }
  1482. return(sc);
  1483. }
  1484. void CTestWrite3::EndCall(LONG iteration)
  1485. {
  1486. }
  1487. void CTestWrite3::CallVerify(LONG iteration)
  1488. {
  1489. }
  1490. void CTestWrite3::EndPrep(LONG iteration)
  1491. {
  1492. delete _pb;
  1493. _pb = NULL;
  1494. _pstmChild->Release();
  1495. _pstg->Release();
  1496. }
  1497. void CTestWrite3::EndVerify(LONG iteration)
  1498. {
  1499. VerifyClean(_sc, _mdf.GetMode(), iteration);
  1500. }
  1501. BOOL CTestWrite3::Next(void)
  1502. {
  1503. if (!_mstm.Next())
  1504. {
  1505. _mstm.Init();
  1506. if (!_mdf.Next())
  1507. return(FALSE);
  1508. }
  1509. return(TRUE);
  1510. }
  1511. //+-------------------------------------------------------------------------
  1512. //
  1513. // Class: CTestSetsize
  1514. //
  1515. // Purpose: Test IStream::Write for largish writes
  1516. //
  1517. // Interface: CTestCase
  1518. //
  1519. // History: 16-Feb-93 PhilipLa Created.
  1520. //
  1521. // Notes:
  1522. //
  1523. //--------------------------------------------------------------------------
  1524. class CTestSetsize : public CTestCase
  1525. {
  1526. private:
  1527. SCODE _sc;
  1528. BYTE *_pb;
  1529. CModeDf _mdf;
  1530. IStorage *_pstg;
  1531. CModeStm _mstm;
  1532. IStream *_pstmChild;
  1533. ULONG _cb;
  1534. ULONG _cBlock;
  1535. public:
  1536. virtual BOOL Init(void);
  1537. virtual SCODE Prep(LONG iteration);
  1538. virtual SCODE Call(LONG iteration);
  1539. virtual void EndCall(LONG iteration);
  1540. virtual void CallVerify(LONG iteration);
  1541. virtual void EndPrep(LONG iteration);
  1542. virtual void EndVerify(LONG iteration);
  1543. virtual BOOL Next(void);
  1544. };
  1545. BOOL CTestSetsize::Init(void)
  1546. {
  1547. printf("SIFT IStream::Setsize\n");
  1548. _mdf.Init();
  1549. _mstm.Init();
  1550. _cb = 8192;
  1551. _cBlock = 9;
  1552. _pb = NULL;
  1553. return(TRUE);
  1554. }
  1555. SCODE CTestSetsize::Prep(LONG iteration)
  1556. {
  1557. _pb = new BYTE[8192];
  1558. memset(_pb, 'X', 8192);
  1559. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1560. if (SUCCEEDED(_sc))
  1561. {
  1562. _sc = DfGetScode(_pstg->CreateStream(
  1563. "TestFail Stream",
  1564. _mstm.GetMode(),
  1565. 0,
  1566. 0,
  1567. &_pstmChild));
  1568. if (FAILED(_sc))
  1569. _pstg->Release();
  1570. }
  1571. return(_sc);
  1572. }
  1573. SCODE CTestSetsize::Call(LONG iteration)
  1574. {
  1575. SCODE sc;
  1576. ULONG cbWritten;
  1577. if (iteration == 0)
  1578. printf("Docfile Mode 0x%lX, Stream Mode 0x%lX, Write %ld bytes\n",
  1579. _mdf.GetMode(), _mstm.GetMode(), _cb * _cBlock);
  1580. ULARGE_INTEGER cbSize;
  1581. ULISet32(cbSize, _cb * _cBlock);
  1582. sc = DfGetScode(_pstmChild->SetSize(cbSize));
  1583. if (FAILED(sc))
  1584. {
  1585. if (sc != STG_E_MEDIUMFULL)
  1586. printf("..Iteration %ld - failed - sc = 0x%lX\n", iteration, sc);
  1587. }
  1588. else
  1589. {
  1590. for (ULONG i = 0; i < _cBlock; i++)
  1591. {
  1592. sc = DfGetScode(_pstmChild->Write(_pb, _cb, &cbWritten));
  1593. if (FAILED(sc))
  1594. {
  1595. printf("..Iteration %ld, Write %lu failed - sc == 0x%lX\n",
  1596. iteration, i + 1, sc);
  1597. break;
  1598. }
  1599. }
  1600. }
  1601. return(sc);
  1602. }
  1603. void CTestSetsize::EndCall(LONG iteration)
  1604. {
  1605. STATSTG stat;
  1606. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1607. if (ULIGetLow(stat.cbSize) != _cb * _cBlock)
  1608. {
  1609. printf("..Iteration %lu - Size of stream is %lu, expected %lu\n",
  1610. iteration, ULIGetLow(stat.cbSize), _cb * _cBlock);
  1611. }
  1612. }
  1613. void CTestSetsize::CallVerify(LONG iteration)
  1614. {
  1615. STATSTG stat;
  1616. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1617. if (ULIGetLow(stat.cbSize) != 0)
  1618. {
  1619. printf("..Iteration %lu - Size of stream is %lu, expected 0\n",
  1620. iteration, ULIGetLow(stat.cbSize));
  1621. }
  1622. }
  1623. void CTestSetsize::EndPrep(LONG iteration)
  1624. {
  1625. delete _pb;
  1626. _pb = NULL;
  1627. _pstmChild->Release();
  1628. _pstg->Release();
  1629. }
  1630. void CTestSetsize::EndVerify(LONG iteration)
  1631. {
  1632. VerifyClean(_sc, _mdf.GetMode(), iteration);
  1633. }
  1634. BOOL CTestSetsize::Next(void)
  1635. {
  1636. if (!_mstm.Next())
  1637. {
  1638. _mstm.Init();
  1639. if (!_mdf.Next())
  1640. return(FALSE);
  1641. }
  1642. return(TRUE);
  1643. }
  1644. //+-------------------------------------------------------------------------
  1645. //
  1646. // Class: CTestCreateStream2
  1647. //
  1648. // Purpose: Test IStorage::CreateStream2
  1649. //
  1650. // Interface: CTestCase
  1651. //
  1652. // History: 26-Jan-93 AlexT Created
  1653. //
  1654. // Notes:
  1655. //
  1656. //--------------------------------------------------------------------------
  1657. class CTestCreateStream2 : public CTestCase
  1658. {
  1659. private:
  1660. SCODE _sc;
  1661. CModeDf _mdf;
  1662. IStorage *_pstg;
  1663. CModeStm _mstm;
  1664. IStream *_pstmChild;
  1665. public:
  1666. virtual BOOL Init(void);
  1667. virtual SCODE Prep(LONG iteration);
  1668. virtual SCODE Call(LONG iteration);
  1669. virtual void EndCall(LONG iteration);
  1670. virtual void CallVerify(LONG iteration);
  1671. virtual void EndPrep(LONG iteration);
  1672. virtual void EndVerify(LONG iteration);
  1673. virtual BOOL Next(void);
  1674. };
  1675. BOOL CTestCreateStream2::Init(void)
  1676. {
  1677. printf("SIFT IStorage::CreateStream2\n");
  1678. _mdf.Init();
  1679. _mstm.Init();
  1680. return(TRUE);
  1681. }
  1682. SCODE CTestCreateStream2::Prep(LONG iteration)
  1683. {
  1684. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1685. return(_sc);
  1686. }
  1687. SCODE CTestCreateStream2::Call(LONG iteration)
  1688. {
  1689. SCODE sc;
  1690. ULONG cStream = 8;
  1691. char * pszName = "XTestFail Stream";
  1692. if (iteration == 0)
  1693. printf("Docfile Mode 0x%lX, Child Stream Mode 0x%lX\n",
  1694. _mdf.GetMode(), _mstm.GetMode());
  1695. for (ULONG i = 0; i < cStream; i++)
  1696. {
  1697. pszName[0] = ((char)i) + '0';
  1698. sc = DfGetScode(_pstg->CreateStream(
  1699. pszName,
  1700. _mstm.GetMode(),
  1701. 0,
  1702. 0,
  1703. &_pstmChild));
  1704. if (FAILED(sc))
  1705. {
  1706. if ((sc == STG_E_MEDIUMFULL) || (sc == STG_E_INSUFFICIENTMEMORY))
  1707. {
  1708. //Do nothing. We expected these.
  1709. }
  1710. else printf("..Iteration %ld, stream %lu - failed - sc = 0x%lX\n",
  1711. iteration, i + 1, sc);
  1712. break;
  1713. }
  1714. _pstmChild->Release();
  1715. }
  1716. return(sc);
  1717. }
  1718. void CTestCreateStream2::EndCall(LONG iteration)
  1719. {
  1720. }
  1721. void CTestCreateStream2::CallVerify(LONG iteration)
  1722. {
  1723. }
  1724. void CTestCreateStream2::EndPrep(LONG iteration)
  1725. {
  1726. _pstg->Release();
  1727. }
  1728. void CTestCreateStream2::EndVerify(LONG iteration)
  1729. {
  1730. VerifyClean(_sc, _mdf.GetMode(), iteration);
  1731. }
  1732. BOOL CTestCreateStream2::Next(void)
  1733. {
  1734. if (!_mstm.Next())
  1735. {
  1736. _mstm.Init();
  1737. if (!_mdf.Next())
  1738. return(FALSE);
  1739. }
  1740. return(TRUE);
  1741. }
  1742. //+-------------------------------------------------------------------------
  1743. //
  1744. // Class: CTestDestroyElement
  1745. //
  1746. // Purpose: Test IStorage::DestroyElement
  1747. //
  1748. // Interface: CTestCase
  1749. //
  1750. // History: 26-Jan-93 AlexT Created
  1751. //
  1752. // Notes:
  1753. //
  1754. //--------------------------------------------------------------------------
  1755. class CTestDestroyElement : public CTestCase
  1756. {
  1757. private:
  1758. SCODE _sc;
  1759. CModeDf _mdf;
  1760. IStorage *_pstg;
  1761. CModeStg _mstg;
  1762. IStorage *_pstgChild;
  1763. public:
  1764. virtual BOOL Init(void);
  1765. virtual SCODE Prep(LONG iteration);
  1766. virtual SCODE Call(LONG iteration);
  1767. virtual void EndCall(LONG iteration);
  1768. virtual void CallVerify(LONG iteration);
  1769. virtual void EndPrep(LONG iteration);
  1770. virtual void EndVerify(LONG iteration);
  1771. virtual BOOL Next(void);
  1772. };
  1773. BOOL CTestDestroyElement::Init(void)
  1774. {
  1775. printf("SIFT IStorage::DestroyElement\n");
  1776. _mdf.Init();
  1777. _mstg.Init();
  1778. return(TRUE);
  1779. }
  1780. SCODE CTestDestroyElement::Prep(LONG iteration)
  1781. {
  1782. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1783. if (SUCCEEDED(_sc))
  1784. {
  1785. _sc = DfGetScode(_pstg->CreateStorage(
  1786. "TestFail Storage",
  1787. _mstg.GetMode(),
  1788. 0,
  1789. 0,
  1790. &_pstgChild));
  1791. _pstgChild->Release();
  1792. }
  1793. return(_sc);
  1794. }
  1795. SCODE CTestDestroyElement::Call(LONG iteration)
  1796. {
  1797. SCODE sc;
  1798. if (iteration == 0)
  1799. printf("Docfile Mode 0x%lX, Child Storage Mode 0x%lX\n",
  1800. _mdf.GetMode(), _mstg.GetMode());
  1801. sc = DfGetScode(_pstg->DestroyElement("TestFail Storage"));
  1802. if (FAILED(sc))
  1803. {
  1804. if ((sc == STG_E_MEDIUMFULL) || (sc == STG_E_INSUFFICIENTMEMORY))
  1805. {
  1806. //We expected these - do nothing.
  1807. }
  1808. else
  1809. printf("..Iteration %ld - failed - sc = 0x%lX\n",
  1810. iteration, sc);
  1811. }
  1812. return(sc);
  1813. }
  1814. void CTestDestroyElement::EndCall(LONG iteration)
  1815. {
  1816. SCODE sc;
  1817. sc = DfGetScode(_pstg->OpenStorage(
  1818. "TestFail Storage",
  1819. 0,
  1820. _mstg.GetMode(),
  1821. 0,
  1822. 0,
  1823. &_pstgChild));
  1824. if (sc != STG_E_FILENOTFOUND)
  1825. {
  1826. printf("..Iteration %ld - open failed with 0x%lX, expected STG_E_FILENOTFOUND\n",
  1827. iteration,
  1828. sc);
  1829. }
  1830. if (SUCCEEDED(sc))
  1831. {
  1832. _pstgChild->Release();
  1833. }
  1834. }
  1835. void CTestDestroyElement::CallVerify(LONG iteration)
  1836. {
  1837. SCODE sc;
  1838. sc = DfGetScode(_pstg->OpenStorage(
  1839. "TestFail Storage",
  1840. 0,
  1841. _mstg.GetMode(),
  1842. 0,
  1843. 0,
  1844. &_pstgChild));
  1845. if (FAILED(sc))
  1846. {
  1847. printf("..Iteration %ld - open failed with 0x%lX, expected success.\n",
  1848. iteration,
  1849. sc);
  1850. }
  1851. else
  1852. {
  1853. _pstgChild->Release();
  1854. }
  1855. }
  1856. void CTestDestroyElement::EndPrep(LONG iteration)
  1857. {
  1858. _pstg->Release();
  1859. }
  1860. void CTestDestroyElement::EndVerify(LONG iteration)
  1861. {
  1862. VerifyClean(_sc, _mdf.GetMode(), iteration);
  1863. }
  1864. BOOL CTestDestroyElement::Next(void)
  1865. {
  1866. if (!_mstg.Next())
  1867. {
  1868. _mstg.Init();
  1869. if (!_mdf.Next())
  1870. return(FALSE);
  1871. }
  1872. return(TRUE);
  1873. }
  1874. //+-------------------------------------------------------------------------
  1875. //
  1876. // Class: CTestSetsize2
  1877. //
  1878. // Purpose: Test IStream::Write for largish writes
  1879. //
  1880. // Interface: CTestCase
  1881. //
  1882. // History: 16-Feb-93 PhilipLa Created.
  1883. //
  1884. // Notes:
  1885. //
  1886. //--------------------------------------------------------------------------
  1887. class CTestSetsize2 : public CTestCase
  1888. {
  1889. private:
  1890. SCODE _sc;
  1891. BYTE *_pb;
  1892. CModeDf _mdf;
  1893. IStorage *_pstg;
  1894. CModeStm _mstm;
  1895. IStream *_pstmChild;
  1896. ULONG _cb;
  1897. ULONG _cBlock;
  1898. public:
  1899. virtual BOOL Init(void);
  1900. virtual SCODE Prep(LONG iteration);
  1901. virtual SCODE Call(LONG iteration);
  1902. virtual void EndCall(LONG iteration);
  1903. virtual void CallVerify(LONG iteration);
  1904. virtual void EndPrep(LONG iteration);
  1905. virtual void EndVerify(LONG iteration);
  1906. virtual BOOL Next(void);
  1907. };
  1908. BOOL CTestSetsize2::Init(void)
  1909. {
  1910. printf("SIFT IStream::Setsize2\n");
  1911. _mdf.Init();
  1912. _mstm.Init();
  1913. _cb = 8192;
  1914. _cBlock = 9;
  1915. _pb = NULL;
  1916. return(TRUE);
  1917. }
  1918. SCODE CTestSetsize2::Prep(LONG iteration)
  1919. {
  1920. _pb = new BYTE[8192];
  1921. memset(_pb, 'X', 8192);
  1922. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  1923. if (SUCCEEDED(_sc))
  1924. {
  1925. _sc = DfGetScode(_pstg->CreateStream(
  1926. "TestFail Stream",
  1927. _mstm.GetMode(),
  1928. 0,
  1929. 0,
  1930. &_pstmChild));
  1931. if (FAILED(_sc))
  1932. _pstg->Release();
  1933. else
  1934. {
  1935. ULARGE_INTEGER ulSize;
  1936. ULISet32(ulSize, _cb * _cBlock);
  1937. _sc = DfGetScode(_pstmChild->SetSize(ulSize));
  1938. if (FAILED(_sc))
  1939. printf("Setsize failed in Prep()\n");
  1940. else
  1941. {
  1942. for (ULONG i = 0; i < _cBlock; i++)
  1943. {
  1944. ULONG cbWritten;
  1945. _sc = DfGetScode(_pstmChild->Write(_pb, _cb, &cbWritten));
  1946. if (FAILED(_sc))
  1947. break;
  1948. }
  1949. }
  1950. }
  1951. }
  1952. return(_sc);
  1953. }
  1954. SCODE CTestSetsize2::Call(LONG iteration)
  1955. {
  1956. SCODE sc;
  1957. ULARGE_INTEGER ulSize;
  1958. ULISet32(ulSize, 2048L);
  1959. sc = DfGetScode(_pstmChild->SetSize(ulSize));
  1960. return(sc);
  1961. }
  1962. void CTestSetsize2::EndCall(LONG iteration)
  1963. {
  1964. STATSTG stat;
  1965. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1966. if (ULIGetLow(stat.cbSize) != 2048L)
  1967. {
  1968. printf("..Iteration %lu - Size of stream is %lu, expected %lu\n",
  1969. iteration, ULIGetLow(stat.cbSize), 2048L);
  1970. }
  1971. LARGE_INTEGER newPos;
  1972. ULISet32(newPos, 0);
  1973. ULARGE_INTEGER dummy;
  1974. _pstmChild->Seek(newPos, STREAM_SEEK_SET, &dummy);
  1975. ULONG cbRead;
  1976. _pstmChild->Read(_pb, 2048, &cbRead);
  1977. if (cbRead != 2048)
  1978. {
  1979. printf("Unknown error - read %lu bytes, expected 2048\n");
  1980. }
  1981. else
  1982. {
  1983. for (ULONG i = 0; i < 2048; i ++)
  1984. {
  1985. if (_pb[i] != 'X')
  1986. {
  1987. printf("Error in buffer data.\n");
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. }
  1993. void CTestSetsize2::CallVerify(LONG iteration)
  1994. {
  1995. STATSTG stat;
  1996. _pstmChild->Stat(&stat, STATFLAG_NONAME);
  1997. if (ULIGetLow(stat.cbSize) != _cb * _cBlock)
  1998. {
  1999. printf("..Iteration %lu - Size of stream is %lu, expected %lu\n",
  2000. iteration, ULIGetLow(stat.cbSize), _cb * _cBlock);
  2001. }
  2002. else
  2003. {
  2004. LARGE_INTEGER newPos;
  2005. ULISet32(newPos, 0);
  2006. ULARGE_INTEGER dummy;
  2007. _pstmChild->Seek(newPos, STREAM_SEEK_SET, &dummy);
  2008. for (ULONG i = 0; i < _cBlock; i++)
  2009. {
  2010. ULONG cbRead;
  2011. _sc = DfGetScode(_pstmChild->Read(_pb, _cb, &cbRead));
  2012. if (FAILED(_sc))
  2013. {
  2014. printf("Read failed with %lX\n", _sc);
  2015. break;
  2016. }
  2017. if (cbRead != _cb)
  2018. {
  2019. printf("Read %lu bytes, expected %lu\n",cbRead,_cb);
  2020. break;
  2021. }
  2022. for (ULONG j = 0; j < _cb; j++)
  2023. {
  2024. if (_pb[j] != 'X')
  2025. {
  2026. printf("Data mismatch at byte %lu, block %lu\n",j,i);
  2027. break;
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. void CTestSetsize2::EndPrep(LONG iteration)
  2034. {
  2035. delete _pb;
  2036. _pb = NULL;
  2037. _pstmChild->Release();
  2038. _pstg->Release();
  2039. }
  2040. void CTestSetsize2::EndVerify(LONG iteration)
  2041. {
  2042. VerifyClean(_sc, _mdf.GetMode(), iteration);
  2043. }
  2044. BOOL CTestSetsize2::Next(void)
  2045. {
  2046. if (!_mstm.Next())
  2047. {
  2048. _mstm.Init();
  2049. if (!_mdf.Next())
  2050. return(FALSE);
  2051. }
  2052. return(TRUE);
  2053. }
  2054. //+-------------------------------------------------------------------------
  2055. //
  2056. // Class: CTestSwitchToFile
  2057. //
  2058. // Purpose: Test SwitchToFile
  2059. //
  2060. // Interface: CTestCase
  2061. //
  2062. // History: 18-Jun-93 PhilipLa Created.
  2063. //
  2064. // Notes:
  2065. //
  2066. //--------------------------------------------------------------------------
  2067. class CTestSwitchToFile : public CTestCase
  2068. {
  2069. private:
  2070. SCODE _sc;
  2071. CModeDf _mdf;
  2072. IStorage *_pstg;
  2073. public:
  2074. virtual BOOL Init(void);
  2075. virtual SCODE Prep(LONG iteration);
  2076. virtual SCODE Call(LONG iteration);
  2077. virtual void EndCall(LONG iteration);
  2078. virtual void CallVerify(LONG iteration);
  2079. virtual void EndPrep(LONG iteration);
  2080. virtual void EndVerify(LONG iteration);
  2081. virtual BOOL Next(void);
  2082. };
  2083. BOOL CTestSwitchToFile::Init(void)
  2084. {
  2085. printf("SIFT IStream::SwitchToFile\n");
  2086. _mdf.Init();
  2087. return(TRUE);
  2088. }
  2089. SCODE CTestSwitchToFile::Prep(LONG iteration)
  2090. {
  2091. IStream *pstm;
  2092. _unlink("c:\\tmp\\stf.dfl");
  2093. _sc = CreateWorkingDocfile(_mdf.GetMode(), &_pstg, 0);
  2094. if (SUCCEEDED(_sc))
  2095. {
  2096. _sc = DfGetScode(_pstg->CreateStream(
  2097. "TestFail Stream",
  2098. STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
  2099. 0,
  2100. 0,
  2101. &pstm));
  2102. if (FAILED(_sc))
  2103. _pstg->Release();
  2104. else
  2105. {
  2106. ULARGE_INTEGER ul;
  2107. ULISet32(ul, 80000);
  2108. _sc = DfGetScode(pstm->SetSize(ul));
  2109. pstm->Release();
  2110. if (FAILED(_sc))
  2111. {
  2112. _pstg->Release();
  2113. }
  2114. }
  2115. }
  2116. return(_sc);
  2117. }
  2118. SCODE CTestSwitchToFile::Call(LONG iteration)
  2119. {
  2120. SCODE sc;
  2121. IRootStorage *pstgRoot;
  2122. sc = DfGetScode(_pstg->QueryInterface(
  2123. IID_IRootStorage,
  2124. (void **)&pstgRoot));
  2125. if (FAILED(sc))
  2126. return sc;
  2127. sc = DfGetScode(pstgRoot->SwitchToFile("c:\\tmp\\stf.dfl"));
  2128. pstgRoot->Release();
  2129. if (FAILED(sc))
  2130. return sc;
  2131. sc = DfGetScode(_pstg->Commit(STGC_OVERWRITE));
  2132. if (FAILED(sc))
  2133. {
  2134. printf("... Commit with overwrite failed.\n");
  2135. }
  2136. else
  2137. {
  2138. printf("... Commit succeeded.\n");
  2139. }
  2140. return(sc);
  2141. }
  2142. void CTestSwitchToFile::EndCall(LONG iteration)
  2143. {
  2144. }
  2145. void CTestSwitchToFile::CallVerify(LONG iteration)
  2146. {
  2147. }
  2148. void CTestSwitchToFile::EndPrep(LONG iteration)
  2149. {
  2150. _pstg->Release();
  2151. _unlink("c:\\tmp\\stf.dfl");
  2152. }
  2153. void CTestSwitchToFile::EndVerify(LONG iteration)
  2154. {
  2155. VerifyClean(_sc, _mdf.GetMode(), iteration);
  2156. }
  2157. BOOL CTestSwitchToFile::Next(void)
  2158. {
  2159. do
  2160. {
  2161. if (!_mdf.Next())
  2162. return FALSE;
  2163. }
  2164. while (((_mdf.GetMode() & 0x70) == STGM_SHARE_DENY_READ) ||
  2165. (_mdf.GetMode() & 0x70) == STGM_SHARE_DENY_NONE);
  2166. return(TRUE);
  2167. }
  2168. //+-------------------------------------------------------------------------
  2169. //
  2170. // Function: TestCount, TestItem
  2171. //
  2172. // Synopsis:
  2173. //
  2174. // Effects:
  2175. //
  2176. // Arguments:
  2177. //
  2178. // Returns:
  2179. //
  2180. // History: 26-Jan-93 AlexT Created
  2181. //
  2182. // Notes:
  2183. //
  2184. //--------------------------------------------------------------------------
  2185. CTestStgCreate tstStgCreate;
  2186. CTestCreateStorage tstCreateStorage;
  2187. CTestCreateStream tstCreateStream;
  2188. CTestWrite tstWrite;
  2189. CTestOpenStorage tstOpenStorage;
  2190. CTestOpenStream tstOpenStream;
  2191. CTestCommit tstCommit;
  2192. CTestCommit2 tstCommit2;
  2193. CTestStgOpen tstStgOpen;
  2194. CTestWrite2 tstWrite2;
  2195. CTestWrite3 tstWrite3;
  2196. CTestSetsize tstSetsize;
  2197. CTestSetsize2 tstSetsize2;
  2198. CTestCreateStream2 tstCreateStream2;
  2199. CTestDestroyElement tstDestroyElement;
  2200. CTestSwitchToFile tstSwitchToFile;
  2201. CTestCommit3 tstCommit3;
  2202. CTestCommit4 tstCommit4;
  2203. CTestCase *atst[] =
  2204. {
  2205. #if defined(BREADTHTEST)
  2206. &tstStgCreate,
  2207. &tstStgOpen,
  2208. &tstCreateStorage,
  2209. &tstCreateStream,
  2210. &tstWrite,
  2211. &tstCommit,
  2212. &tstCommit2,
  2213. &tstOpenStream,
  2214. &tstOpenStorage,
  2215. &tstWrite2,
  2216. &tstWrite3,
  2217. &tstSetsize,
  2218. &tstCreateStream2,
  2219. &tstDestroyElement,
  2220. &tstSetsize2,
  2221. &tstSwitchToFile,
  2222. &tstCommit3,
  2223. #endif
  2224. &tstCommit4
  2225. };
  2226. int TestCount(void)
  2227. {
  2228. return(sizeof(atst)/sizeof(CTestCase *));
  2229. }
  2230. CTestCase *TestItem(int iTest)
  2231. {
  2232. return(atst[iTest]);
  2233. }