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.

5560 lines
164 KiB

  1. /-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: apitests.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to API tests in general.
  9. //
  10. // Functions:
  11. //
  12. // History: 18-June-1996 NarindK Created.
  13. // 27-Mar-97 SCousens conversionified
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <dfheader.hxx>
  17. #pragma hdrstop
  18. #include <sys/stat.h>
  19. #include <share.h>
  20. #include "init.hxx"
  21. // undo the affects of the wrapper. We need to test the actual APIs here,
  22. // not what we think we should be calling to test docfile/nssfiles.
  23. #undef StgCreateDocfile
  24. #undef StgOpenStorage
  25. // CheckErrorTest macros.
  26. // These check the return value to an invalid api call.
  27. // These must remain as #defines as we change local variables.
  28. #define CheckErrorTest(err, msg, pstg) \
  29. DH_ASSERT (NULL == pstg); \
  30. hr = DH_HRERRORCHECK (hr, err, msg); \
  31. if ((S_OK != hr) || (NULL != pstg)) \
  32. { \
  33. fPass = FALSE; \
  34. hr = S_OK; \
  35. } \
  36. // release it if we accidentally got one \
  37. if (NULL != pstg) \
  38. { \
  39. pstg->Release (); \
  40. pstg = NULL; \
  41. }
  42. #define CheckErrorTest2(err, msg) \
  43. hr = DH_HRERRORCHECK (hr, err, msg); \
  44. if (S_OK != hr) \
  45. { \
  46. fPass = FALSE; \
  47. hr = S_OK; \
  48. }
  49. //----------------------------------------------------------------------------
  50. //
  51. // Test: APITEST_100
  52. //
  53. // Synopsis: This test attempts various operations on StgCreateDocFile, Stg
  54. // OpenStorage API's
  55. //
  56. // Arguments:[argc]
  57. // [argv]
  58. //
  59. // Returns: HRESULT
  60. //
  61. // Notes: This test runs in direct, transacted, and transacted deny write
  62. // modes
  63. //
  64. // History: 18-June-1996 NarindK Created.
  65. //
  66. // New Test Notes:
  67. // 1. Old File: IAPISTG.CXX
  68. // 2. Old name of test : IllegitAPIStg test
  69. // New Name of test : APITEST_100
  70. // 3. To run the test, do the following at command prompt.
  71. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-100
  72. // /dfRootMode:dirReadWriteShEx /dfname:APITEST.100 /labmode
  73. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-100
  74. // /dfRootMode:xactReadWriteShEx /dfname:APITEST.100 /labmode
  75. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-100
  76. // /dfRootMode:xactReadWriteShDenyW /dfname:APITEST.100 /labmode
  77. //
  78. // BUGNOTE: Conversion: APITEST-100 NO
  79. //
  80. //-----------------------------------------------------------------------------
  81. HRESULT APITEST_100(int argc, char *argv[])
  82. {
  83. HRESULT hr = S_OK;
  84. HRESULT hr2 = S_OK;
  85. ChanceDF *pTestChanceDF = NULL;
  86. VirtualDF *pTestVirtualDF = NULL;
  87. VirtualCtrNode *pVirtualDFRoot = NULL;
  88. LPTSTR pRootDocFileName = NULL;
  89. DWORD dwRootMode = NULL;
  90. LPSTORAGE pIStorage = NULL;
  91. LPSTORAGE pIStorageOpen = NULL;
  92. LPOLESTR pOleStrTemp = NULL;
  93. TCHAR tszTestName[10] = TEXT("NonExist");
  94. LPOLESTR pOleStrTest = NULL;
  95. SNB snbTest = NULL;
  96. SNB snbTemp = NULL;
  97. ULONG ulRef = 0;
  98. OLECHAR *ocsSNBChar = NULL;
  99. ULONG i = 0;
  100. BOOL fPass = TRUE;
  101. // Not for 2phase. Bail.
  102. if (DoingDistrib ())
  103. {
  104. return S_OK;
  105. }
  106. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_100"));
  107. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  108. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_100 started.")) );
  109. DH_TRACE((DH_LVL_TRACE1,
  110. TEXT("Attempt illegitimate ops on StgCreateDocFIle & StgOpenStorage.")));
  111. // Create the new ChanceDocFile tree that would consist of chance nodes.
  112. if (S_OK == hr)
  113. {
  114. pTestChanceDF = new ChanceDF();
  115. if(NULL == pTestChanceDF)
  116. {
  117. hr = E_OUTOFMEMORY;
  118. }
  119. DH_HRCHECK(hr, TEXT("new ChanceDF")) ;
  120. }
  121. if (S_OK == hr)
  122. {
  123. hr = pTestChanceDF->CreateFromParams(argc, argv);
  124. DH_HRCHECK(hr, TEXT("ChanceDF::CreateFromParams")) ;
  125. }
  126. if (S_OK == hr)
  127. {
  128. dwRootMode = pTestChanceDF->GetRootMode();
  129. DH_TRACE((
  130. DH_LVL_TRACE1,
  131. TEXT("Run Mode for APITEST_100, Access mode: %lx"),
  132. pTestChanceDF->GetRootMode()));
  133. }
  134. // Get RootDocFile name
  135. if (S_OK == hr)
  136. {
  137. if(NULL != pTestChanceDF->GetDocFileName())
  138. {
  139. pRootDocFileName =
  140. new TCHAR[_tcslen(pTestChanceDF->GetDocFileName())+1];
  141. if (pRootDocFileName == NULL)
  142. {
  143. hr = E_OUTOFMEMORY;
  144. }
  145. else
  146. {
  147. _tcscpy(pRootDocFileName, pTestChanceDF->GetDocFileName());
  148. }
  149. DH_HRCHECK(hr, TEXT("new TCHAR"));
  150. }
  151. DH_HRCHECK(hr, TEXT("ChanceDF::GetDocFileName")) ;
  152. }
  153. if(S_OK == hr)
  154. {
  155. // Convert RootDocFile name to OLECHAR
  156. hr = TStringToOleString(pRootDocFileName, &pOleStrTemp);
  157. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  158. }
  159. // Try calling StgCreateDocFile with mode STGM_CREATE|STGM_CONVERT
  160. if (S_OK == hr)
  161. {
  162. pIStorage = NULL;
  163. hr = StgCreateDocfile(
  164. pOleStrTemp,
  165. STGM_CREATE | STGM_CONVERT,
  166. 0,
  167. &pIStorage);
  168. CheckErrorTest(STG_E_INVALIDFLAG,
  169. TEXT ("StgCreateDocfile inv Flags"),
  170. pIStorage);
  171. }
  172. // Try calling StgCreateDocFile with mode equal to -1
  173. if (S_OK == hr)
  174. {
  175. pIStorage = NULL;
  176. hr = StgCreateDocfile(
  177. pOleStrTemp,
  178. (DWORD) -1,
  179. 0,
  180. &pIStorage);
  181. CheckErrorTest(STG_E_INVALIDFLAG,
  182. TEXT ("StgCreateDocfile inv mode"),
  183. pIStorage);
  184. }
  185. // Try calling StgCreateDocFile with nonzero reserved parameter
  186. if (S_OK == hr)
  187. {
  188. pIStorage = NULL;
  189. hr = StgCreateDocfile(
  190. pOleStrTemp,
  191. STGM_CREATE | dwRootMode,
  192. (DWORD)999,
  193. &pIStorage);
  194. CheckErrorTest(STG_E_INVALIDPARAMETER,
  195. TEXT ("StgCreateDocfile inv reserved"),
  196. pIStorage);
  197. }
  198. // Try calling StgCreateDocFile with NULL ppstgOpen parameter 4th
  199. if (S_OK == hr)
  200. {
  201. hr = StgCreateDocfile(
  202. pOleStrTemp,
  203. dwRootMode,
  204. 0,
  205. NULL);
  206. CheckErrorTest2(STG_E_INVALIDPOINTER,
  207. TEXT ("StgCreateDocfile inv ppstg bucket"));
  208. }
  209. // Now create a valid DocFile
  210. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  211. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  212. // and VirtualStmNodes.
  213. if (S_OK == hr)
  214. {
  215. pTestVirtualDF = new VirtualDF();
  216. if(NULL == pTestVirtualDF)
  217. {
  218. hr = E_OUTOFMEMORY;
  219. }
  220. DH_HRCHECK(hr, TEXT("new VirtualDF")) ;
  221. }
  222. if (S_OK == hr)
  223. {
  224. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  225. DH_HRCHECK(hr, TEXT("VirtualCtrNode::GenerateVirtualDF")) ;
  226. }
  227. // Now try commiting with grfCommitFlags = -1
  228. if (S_OK == hr)
  229. {
  230. hr = pVirtualDFRoot->Commit((DWORD) -1);
  231. CheckErrorTest2(STG_E_INVALIDFLAG,
  232. TEXT ("VirtualCtrNode::Commit inv flag"));
  233. }
  234. // Now do a valid commit
  235. if (S_OK == hr)
  236. {
  237. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  238. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  239. }
  240. // Close the root docfile
  241. if (NULL != pVirtualDFRoot)
  242. {
  243. hr2 = pVirtualDFRoot->Close();
  244. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  245. hr = FirstError (hr, hr2);
  246. }
  247. // Instantiate DocFile with grfMode=-1
  248. if (S_OK == hr)
  249. {
  250. pIStorageOpen = NULL;
  251. hr = StgOpenStorage(
  252. pOleStrTemp,
  253. NULL,
  254. (DWORD) -1,
  255. NULL,
  256. 0,
  257. &pIStorageOpen);
  258. CheckErrorTest(STG_E_INVALIDFLAG,
  259. TEXT ("StgOpenStorage inv mode"),
  260. pIStorageOpen);
  261. }
  262. // Instantiate DocFile with name as " "
  263. // NOTE: The old test checked the erro value to be STG_E_FILENOTFOUND in
  264. // this case. On NT, we get STG_E_PATHNOTFOUND and on Chicago, we get
  265. // STG_E_ACCESSDENIED, so let us check against S_OK itself.
  266. if (S_OK == hr)
  267. {
  268. pIStorageOpen = NULL;
  269. hr = StgOpenStorage(
  270. (OLECHAR *) " ",
  271. NULL,
  272. dwRootMode,
  273. NULL,
  274. 0,
  275. &pIStorageOpen);
  276. if (RunningOnNT())
  277. {
  278. CheckErrorTest(STG_E_PATHNOTFOUND,
  279. TEXT("StgOpenStorage inv name"),
  280. pIStorageOpen);
  281. }
  282. else
  283. {
  284. CheckErrorTest(STG_E_ACCESSDENIED,
  285. TEXT("StgOpenStorage inv name"),
  286. pIStorageOpen);
  287. }
  288. }
  289. // Instantiate DocFile with nonexisting file name
  290. if(S_OK == hr)
  291. {
  292. // Convert tszTestName to OLECHAR
  293. hr = TStringToOleString(tszTestName, &pOleStrTest);
  294. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  295. }
  296. if (S_OK == hr)
  297. {
  298. pIStorageOpen = NULL;
  299. hr = StgOpenStorage(
  300. pOleStrTest,
  301. NULL,
  302. dwRootMode,
  303. NULL,
  304. 0,
  305. &pIStorageOpen);
  306. CheckErrorTest(STG_E_FILENOTFOUND,
  307. TEXT ("StgOpenStorage inv name"),
  308. pIStorageOpen);
  309. }
  310. // Instantiate DocFile with NULL file name
  311. if (S_OK == hr)
  312. {
  313. pIStorageOpen = NULL;
  314. hr = StgOpenStorage(
  315. NULL,
  316. NULL,
  317. dwRootMode,
  318. NULL,
  319. 0,
  320. &pIStorageOpen);
  321. CheckErrorTest(STG_E_INVALIDNAME,
  322. TEXT ("StgOpenStorage NULL name"),
  323. pIStorageOpen);
  324. }
  325. // Instantiate DocFile with non zero dwReserved parameter
  326. if (S_OK == hr)
  327. {
  328. pIStorageOpen = NULL;
  329. hr = StgOpenStorage(
  330. pOleStrTemp,
  331. NULL,
  332. dwRootMode,
  333. NULL,
  334. 999,
  335. &pIStorageOpen);
  336. CheckErrorTest(STG_E_INVALIDPARAMETER,
  337. TEXT ("StgOpenStorage inv reserved"),
  338. pIStorageOpen);
  339. }
  340. // Instantiate DocFile with NULL ppstgOpen parameter (6th)
  341. if (S_OK == hr)
  342. {
  343. hr = StgOpenStorage(
  344. pOleStrTemp,
  345. NULL,
  346. dwRootMode,
  347. NULL,
  348. 0,
  349. NULL);
  350. CheckErrorTest2(STG_E_INVALIDPOINTER,
  351. TEXT ("StgOpenStorage NULL ppstg"));
  352. }
  353. // Instantiate DocFile with grfMode as dwRootMode|STGM_DELETEONRELEASE
  354. // NOTE: The doc says, erro code in this case to be STG_E_INVALIDFUNCTION,
  355. // but error STG_E_INVALIDFLAG returned.
  356. if (S_OK == hr)
  357. {
  358. pIStorageOpen = NULL;
  359. hr = StgOpenStorage(
  360. pOleStrTemp,
  361. NULL,
  362. dwRootMode | STGM_DELETEONRELEASE,
  363. NULL,
  364. 0,
  365. &pIStorageOpen);
  366. CheckErrorTest(STG_E_INVALIDFUNCTION,
  367. TEXT ("StgOpenStorage DELETEONRELEASE in mode"),
  368. pIStorageOpen);
  369. }
  370. // Create snbTest with spcae for two names and set name list to NULL i.e.
  371. // a vaild SNB with no name in the block
  372. if(S_OK == hr)
  373. {
  374. snbTest = (OLECHAR **) new OLECHAR [sizeof(OLECHAR *) * 2];
  375. if(NULL == snbTest)
  376. {
  377. hr = E_OUTOFMEMORY;
  378. }
  379. else
  380. {
  381. *snbTest = NULL;
  382. }
  383. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  384. }
  385. // Instantiate DocFile with above empty but valid SNB
  386. if (S_OK == hr)
  387. {
  388. pIStorageOpen = NULL;
  389. hr = StgOpenStorage(
  390. pOleStrTemp,
  391. NULL,
  392. dwRootMode,
  393. snbTest,
  394. 0,
  395. &pIStorageOpen);
  396. DH_HRCHECK(hr, TEXT("StgOpenStorage empty SNB")) ;
  397. // Release the pointer
  398. if(NULL != pIStorageOpen)
  399. {
  400. ulRef = pIStorageOpen->Release();
  401. DH_ASSERT (0 == ulRef);
  402. pIStorageOpen = NULL;
  403. }
  404. }
  405. // Allocate space for long name and fill name with
  406. // X's, make next SNB elment NULL, and make a call to StgOpenStorage API
  407. // with too long a name in SNB
  408. if(S_OK == hr)
  409. {
  410. *snbTest = (OLECHAR *) new OLECHAR [MAX_STG_NAME_LEN*12];
  411. if (NULL == *snbTest)
  412. {
  413. hr = E_OUTOFMEMORY;
  414. }
  415. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  416. }
  417. if(S_OK == hr)
  418. {
  419. snbTemp = snbTest;
  420. ocsSNBChar = *snbTemp;
  421. for (i=0; i<( MAX_STG_NAME_LEN*12 -1); i++)
  422. {
  423. ocsSNBChar[i] = 'X';
  424. }
  425. ocsSNBChar[i] = '\0';
  426. // Assign second element as NULL
  427. snbTemp++;
  428. *snbTemp = NULL;
  429. }
  430. // Instantiate DocFile with above SNB with too long a name in it.
  431. // NOTE: In the old test, this was supposed to fail. Doesn't fail
  432. // now... Confirmed with Philipla - No length verification of SNB
  433. // names done in ValidateSNB in OLE
  434. if (S_OK == hr)
  435. {
  436. pIStorageOpen = NULL;
  437. hr = StgOpenStorage(
  438. pOleStrTemp,
  439. NULL,
  440. dwRootMode,
  441. snbTest,
  442. 0,
  443. &pIStorageOpen);
  444. DH_HRCHECK (hr, TEXT("StgOpenStorage long SNB"));
  445. //Release storage pointer
  446. if(NULL != pIStorageOpen)
  447. {
  448. ulRef = pIStorageOpen->Release();
  449. DH_ASSERT (0 == ulRef);
  450. pIStorageOpen = NULL;
  451. }
  452. }
  453. // if something did no pass, mark test (hr) as E_FAIL
  454. if (FALSE == fPass)
  455. {
  456. hr = FirstError (hr, E_FAIL);
  457. }
  458. // if everything goes well, log test as passed else failed.
  459. if ((S_OK == hr) && (TRUE == fPass))
  460. {
  461. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_100 passed.")) );
  462. }
  463. else
  464. {
  465. DH_LOG((
  466. LOG_FAIL,
  467. TEXT("Test variation APITEST_100 failed; hr=%#lx; fPass=%d"),
  468. hr,
  469. fPass));
  470. }
  471. // Cleanup
  472. // Delete Chance docfile tree
  473. if(NULL != pTestChanceDF)
  474. {
  475. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  476. pTestChanceDF->GetChanceDFRoot());
  477. DH_HRCHECK(hr2, TEXT("ChanceDF::DeleteChanceFileDocTree")) ;
  478. delete pTestChanceDF;
  479. pTestChanceDF = NULL;
  480. }
  481. // Delete Virtual docfile tree
  482. if(NULL != pTestVirtualDF)
  483. {
  484. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  485. DH_HRCHECK(hr2, TEXT("VirtualDF::DeleteVirtualFileDocTree")) ;
  486. delete pTestVirtualDF;
  487. pTestVirtualDF = NULL;
  488. }
  489. // Delete the docfile on disk
  490. if((S_OK == hr) && (NULL != pRootDocFileName))
  491. {
  492. if(FALSE == DeleteFile(pRootDocFileName))
  493. {
  494. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  495. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  496. }
  497. }
  498. // Delete temp strings
  499. if(NULL != pOleStrTemp)
  500. {
  501. delete []pOleStrTemp;
  502. pOleStrTemp = NULL;
  503. }
  504. if(NULL != pOleStrTest)
  505. {
  506. delete []pOleStrTest;
  507. pOleStrTest = NULL;
  508. }
  509. if(NULL != pRootDocFileName)
  510. {
  511. delete []pRootDocFileName;
  512. pRootDocFileName = NULL;
  513. }
  514. // Free SNB
  515. if(NULL != snbTest)
  516. {
  517. if(NULL != *snbTest)
  518. {
  519. delete [] *snbTest;
  520. *snbTest = NULL;
  521. }
  522. delete [] snbTest;
  523. snbTest = NULL;
  524. }
  525. // Stop logging the test
  526. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_100 finished")) );
  527. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  528. return hr;
  529. }
  530. //----------------------------------------------------------------------------
  531. //
  532. // Test: APITEST_101
  533. //
  534. // Synopsis: The test attempts various illegitimate operations using names
  535. // greater than MAX_STG_NAME_LEN, it then attempts to create
  536. // several random named root docfiles. If the create is succesful,
  537. // then a random named child IStorage or IStream is also created.
  538. // Whether or not the root create was successful, we attempt to
  539. // open the root docfile (this is expected to fail, the point is
  540. // to check for asserts/GP faults rather than return codes). If
  541. // the instantiation is successful, the test also tries to
  542. // instantiate the child object. All objects are then released.
  543. //
  544. // Arguments:[argc]
  545. // [argv]
  546. //
  547. // Returns: HRESULT
  548. //
  549. // History: 18-June-1996 NarindK Created.
  550. //
  551. // Notes: This test runs in direct, transacted, and transacted deny write
  552. // modes
  553. //
  554. // New Test Notes:
  555. // 1. Old File: IANAMES.CXX
  556. // 2. Old name of test : IllegitAPINames test
  557. // New Name of test : APITEST_101
  558. // 3. To run the test, do the following at command prompt.
  559. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-101
  560. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  561. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-101
  562. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  563. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-101
  564. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  565. //
  566. // BUGNOTE: Conversion: APITEST-101 NO
  567. //
  568. //-----------------------------------------------------------------------------
  569. HRESULT APITEST_101(int argc, char *argv[])
  570. {
  571. #ifdef _MAC // Simple mode not ported yet; check with the developers
  572. // and remove this when ready
  573. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!!!APITEST-101 crashes.")) );
  574. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!!!To be investigated")) );
  575. return E_NOTIMPL;
  576. #else
  577. HRESULT hr = S_OK;
  578. HRESULT hr2 = S_OK;
  579. ChanceDF *pTestChanceDF = NULL;
  580. VirtualDF *pTestVirtualDF = NULL;
  581. VirtualCtrNode *pVirtualDFRoot = NULL;
  582. LPTSTR pFileName = NULL;
  583. LPOLESTR poszBadName = NULL;
  584. LPOLESTR poszBadNameStg = NULL;
  585. LPTSTR ptszBadNameStg = NULL;
  586. DWORD dwRootMode = 0;
  587. ULONG i = 0;
  588. LPSTORAGE pIStorage = NULL;
  589. LPSTORAGE pIStorageChild = NULL;
  590. LPSTREAM pIStreamChild = NULL;
  591. DG_STRING *pdgu = NULL;
  592. DG_INTEGER *pdgi = NULL;
  593. LPTSTR pRootNewChildStgName = NULL;
  594. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  595. BOOL fPass = TRUE;
  596. // Not for 2phase. Bail.
  597. if (DoingDistrib ())
  598. {
  599. return S_OK;
  600. }
  601. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_101"));
  602. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  603. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_101 started.")) );
  604. DH_TRACE((DH_LVL_TRACE1,
  605. TEXT("Call StgCreateDocFile/CreateStorage/CreateStream with too long names")));
  606. // Create the new ChanceDocFile tree that would consist of chance nodes.
  607. if (S_OK == hr)
  608. {
  609. pTestChanceDF = new ChanceDF();
  610. if(NULL == pTestChanceDF)
  611. {
  612. hr = E_OUTOFMEMORY;
  613. }
  614. DH_HRCHECK(hr, TEXT("new ChanceDF")) ;
  615. }
  616. if (S_OK == hr)
  617. {
  618. hr = pTestChanceDF->CreateFromParams(argc, argv);
  619. DH_HRCHECK(hr, TEXT("ChanceDF::CreateFromParams")) ;
  620. }
  621. if (S_OK == hr)
  622. {
  623. dwRootMode = pTestChanceDF->GetRootMode();
  624. DH_TRACE((
  625. DH_LVL_TRACE1,
  626. TEXT("Run Mode for APITEST_101, Access mode: %lx"),
  627. pTestChanceDF->GetRootMode()));
  628. }
  629. // Call StgCreateDocFile with too long a name for docfile.
  630. // NOTE: Old test to fail with MAX_STG_NAME_LEN*3, but not in new test,
  631. // fails with MAX_STG_NAME_LEN*4.
  632. // NOTE: Crashes in DfFromName in OLE if length is of MAX_STG_NAME_LEN*8
  633. // CHECK!!!
  634. if(S_OK == hr)
  635. {
  636. poszBadName = (OLECHAR *) new OLECHAR [MAX_STG_NAME_LEN*4];
  637. if (NULL == poszBadName)
  638. {
  639. hr = E_OUTOFMEMORY;
  640. }
  641. DH_HRCHECK(hr, TEXT("new OLECHAR")) ;
  642. }
  643. if(S_OK == hr)
  644. {
  645. for (i=0; i<( MAX_STG_NAME_LEN*4 -1); i++)
  646. {
  647. poszBadName[i] = i%20 + OLECHAR('A');
  648. }
  649. poszBadName[i] = OLECHAR('\0');
  650. }
  651. // Try calling StgCreateDocFile with the above long name pszBadName
  652. if (S_OK == hr)
  653. {
  654. pIStorage = NULL;
  655. DH_TRACE ((DH_LVL_TRACE4, TEXT("Filename:%s"), poszBadName)); //BUGBUG - work on chicago?
  656. hr = StgCreateDocfile(
  657. poszBadName,
  658. dwRootMode | STGM_CREATE,
  659. 0,
  660. &pIStorage);
  661. CheckErrorTest(STG_E_PATHNOTFOUND,
  662. TEXT ("StgCreateDocfile long name"),
  663. pIStorage);
  664. }
  665. // Now create a valid DocFile
  666. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  667. // the previous step.
  668. if (S_OK == hr)
  669. {
  670. pTestVirtualDF = new VirtualDF();
  671. if(NULL == pTestVirtualDF)
  672. {
  673. hr = E_OUTOFMEMORY;
  674. }
  675. DH_HRCHECK(hr, TEXT("new VirtualDF")) ;
  676. }
  677. if (S_OK == hr)
  678. {
  679. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  680. DH_HRCHECK(hr, TEXT("VirtualDF::GenerateVirtualDF")) ;
  681. }
  682. // Get IStorage pointer
  683. if (S_OK == hr)
  684. {
  685. pIStorage = pVirtualDFRoot->GetIStoragePointer();
  686. DH_ASSERT (NULL != pIStorage);
  687. if (NULL == pIStorage)
  688. {
  689. hr = E_FAIL;
  690. }
  691. }
  692. // Call CreateStorage with too long a name for docfile.
  693. if(S_OK == hr)
  694. {
  695. ptszBadNameStg = (TCHAR *) new TCHAR [MAX_STG_NAME_LEN*3];
  696. if (NULL == ptszBadNameStg)
  697. {
  698. hr = E_OUTOFMEMORY;
  699. }
  700. DH_HRCHECK(hr, TEXT("new TCHAR")) ;
  701. }
  702. if(S_OK == hr)
  703. {
  704. for (i=0; i<( MAX_STG_NAME_LEN*3 -1); i++)
  705. {
  706. ptszBadNameStg[i] = TEXT('Y');
  707. }
  708. ptszBadNameStg[i] = TEXT('\0');
  709. }
  710. if(S_OK == hr)
  711. {
  712. // Convert Bad storage name to OLECHAR
  713. hr = TStringToOleString(ptszBadNameStg, &poszBadNameStg);
  714. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  715. }
  716. // now call CreateStorage with too long a name...
  717. if (S_OK == hr)
  718. {
  719. hr = pIStorage->CreateStorage(
  720. poszBadNameStg,
  721. pTestChanceDF->GetStgMode(),
  722. 0,
  723. 0,
  724. &pIStorageChild);
  725. CheckErrorTest(STG_E_INVALIDNAME,
  726. TEXT ("IStorage::CreateStorage long name"),
  727. pIStorageChild);
  728. }
  729. // Now call CreateStream with too long a name...
  730. if (S_OK == hr)
  731. {
  732. hr = pIStorage->CreateStream(
  733. poszBadNameStg,
  734. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  735. 0,
  736. 0,
  737. &pIStreamChild);
  738. CheckErrorTest(STG_E_INVALIDNAME,
  739. TEXT ("IStorage::CreateStream long name"),
  740. pIStreamChild);
  741. }
  742. // Now add a Valid storage to root. Call AddStorage that in turns calls
  743. // CreateStorage
  744. if (S_OK == hr)
  745. {
  746. pdgu = pTestVirtualDF->GetDataGenUnicode();
  747. DH_ASSERT (NULL != pdgu);
  748. if (NULL == pdgu)
  749. {
  750. hr = E_FAIL;
  751. }
  752. }
  753. if(S_OK == hr)
  754. {
  755. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  756. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  757. }
  758. // Adds a new storage to the root storage.
  759. if(S_OK == hr)
  760. {
  761. hr = AddStorage(
  762. pTestVirtualDF,
  763. pVirtualDFRoot,
  764. pRootNewChildStgName,
  765. pTestChanceDF->GetStgMode() | STGM_CREATE | STGM_FAILIFTHERE,
  766. &pvcnRootNewChildStorage);
  767. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  768. }
  769. // Now try to rename this storage element to a bad name.
  770. if(S_OK == hr)
  771. {
  772. DH_EXPECTEDERROR (STG_E_INVALIDNAME);
  773. hr = pvcnRootNewChildStorage->Rename(ptszBadNameStg);
  774. DH_NOEXPECTEDERROR ();
  775. CheckErrorTest2(STG_E_INVALIDNAME,
  776. TEXT ("VirtualCtrNode::Rename long name"));
  777. }
  778. // Close the Storage pvcnRootNewChildStorage
  779. if (NULL != pvcnRootNewChildStorage)
  780. {
  781. hr2 = pvcnRootNewChildStorage->Close();
  782. DH_HRCHECK(hr2, TEXT("VirtualCtrNode::Close")) ;
  783. hr = FirstError (hr, hr2);
  784. }
  785. // Close the root docfile
  786. if (NULL != pVirtualDFRoot)
  787. {
  788. hr2 = pVirtualDFRoot->Close();
  789. DH_HRCHECK(hr2, TEXT("VirtualCtrNode::Close")) ;
  790. hr = FirstError (hr, hr2);
  791. }
  792. // Delete temp strings
  793. if(NULL != poszBadNameStg)
  794. {
  795. delete [] poszBadNameStg;
  796. poszBadNameStg = NULL;
  797. }
  798. if(NULL != poszBadName)
  799. {
  800. delete [] poszBadName;
  801. poszBadName = NULL;
  802. }
  803. if(NULL != ptszBadNameStg)
  804. {
  805. delete [] ptszBadNameStg;
  806. ptszBadNameStg = NULL;
  807. }
  808. if(NULL != pRootNewChildStgName)
  809. {
  810. delete [] pRootNewChildStgName;
  811. pRootNewChildStgName = NULL;
  812. }
  813. // In the following section of test:
  814. //make a random number of random length, random character root
  815. //docfiles. for this variation, we don't care if the operation
  816. //succeeds, looking for GP faults and asserts only. if the
  817. //StgCreateDocfile fails, we'll still attempt the open. of
  818. //course, the open in this case will be expected to fail, but
  819. //again, we won't be checking return codes... If the StgCreateDocfile
  820. //passes, we'll create a random name IStream or IStorage too.
  821. ULONG count = 0;
  822. ULONG cMinNum = 16;
  823. ULONG cMaxNum = 128;
  824. LPTSTR ptszRandomRootName = NULL;
  825. LPTSTR ptszRandomChildName = NULL;
  826. ULONG countFlag = 0;
  827. ULONG cMinFlag = 0;
  828. ULONG cMaxFlag = 100;
  829. ULONG nChildType = 0;
  830. LPSTORAGE pstgRoot = NULL;
  831. LPSTORAGE pstgChild = NULL;
  832. LPSTREAM pstmChild = NULL;
  833. LPOLESTR poszRandomRootName = NULL;
  834. LPOLESTR poszRandomChildName = NULL;
  835. ULONG ulRef = 0;
  836. if (S_OK == hr)
  837. {
  838. pdgi = pTestVirtualDF->GetDataGenInteger();
  839. DH_ASSERT (NULL != pdgi);
  840. if (NULL == pdgi)
  841. {
  842. hr = E_FAIL;
  843. }
  844. }
  845. if(S_OK == hr)
  846. {
  847. hr = pdgi->Generate(&count, cMinNum, cMaxNum);
  848. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  849. }
  850. while(count--)
  851. {
  852. if(S_OK == hr)
  853. {
  854. hr=GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszRandomRootName);
  855. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  856. }
  857. if(S_OK == hr)
  858. {
  859. // Convert name to OLECHAR
  860. hr = TStringToOleString(ptszRandomRootName, &poszRandomRootName);
  861. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  862. }
  863. if (S_OK == hr)
  864. {
  865. pstgRoot = NULL;
  866. hr = StgCreateDocfile(
  867. poszRandomRootName,
  868. dwRootMode | STGM_CREATE,
  869. 0,
  870. &pstgRoot);
  871. DH_HRCHECK(hr, TEXT("StgCreateDocfile")) ;
  872. }
  873. nChildType = NONE;
  874. if(S_OK == hr)
  875. {
  876. if(S_OK == hr)
  877. {
  878. hr=GenerateRandomName(
  879. pdgu,
  880. MINLENGTH,
  881. MAXLENGTH,
  882. &ptszRandomChildName);
  883. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  884. }
  885. if(S_OK == hr)
  886. {
  887. // Convert name to OLECHAR
  888. hr = TStringToOleString(
  889. ptszRandomChildName,
  890. &poszRandomChildName);
  891. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  892. }
  893. if(S_OK == hr)
  894. {
  895. hr = pdgi->Generate(&countFlag, cMinFlag, cMaxFlag);
  896. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  897. }
  898. if(countFlag > (cMaxFlag/2))
  899. {
  900. hr = pstgRoot->CreateStorage(
  901. poszRandomChildName,
  902. pTestChanceDF->GetStgMode(),
  903. 0,
  904. 0,
  905. &pstgChild);
  906. DH_HRCHECK(hr, TEXT("IStorage::CreateStorage")) ;
  907. if(S_OK == hr)
  908. {
  909. nChildType = STORAGE;
  910. hr = pstgRoot->Commit(STGC_DEFAULT);
  911. DH_HRCHECK(hr, TEXT("IStorage::Commit")) ;
  912. ulRef = pstgChild->Release();
  913. DH_ASSERT (0 == ulRef);
  914. pstgChild = NULL;
  915. }
  916. }
  917. else
  918. {
  919. hr = pstgRoot->CreateStream(
  920. poszRandomChildName,
  921. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  922. 0,
  923. 0,
  924. &pstmChild);
  925. DH_HRCHECK(hr, TEXT("IStorage::CreateStream")) ;
  926. if(S_OK == hr)
  927. {
  928. nChildType = STREAM;
  929. hr = pstgRoot->Commit(STGC_DEFAULT);
  930. DH_HRCHECK(hr, TEXT("IStorage::Commit")) ;
  931. ulRef = pstmChild->Release();
  932. DH_ASSERT (0 == ulRef);
  933. pstmChild = NULL;
  934. }
  935. }
  936. ulRef = pstgRoot->Release();
  937. DH_ASSERT (0 == ulRef);
  938. pstgRoot = NULL;
  939. }
  940. //Try to open Root Storage whetehr the creation was successful or not
  941. hr = StgOpenStorage(
  942. poszRandomRootName,
  943. NULL,
  944. pTestChanceDF->GetStgMode(),
  945. NULL,
  946. 0,
  947. &pstgRoot);
  948. DH_HRCHECK(hr, TEXT("StgOpenStorage")) ;
  949. if(S_OK == hr)
  950. {
  951. switch(nChildType)
  952. {
  953. case STORAGE:
  954. {
  955. hr = pstgRoot->OpenStorage(
  956. poszRandomChildName,
  957. NULL,
  958. pTestChanceDF->GetStgMode(),
  959. NULL,
  960. 0,
  961. &pstgChild);
  962. DH_HRCHECK(hr, TEXT("IStorage::OpenStorage")) ;
  963. if(S_OK == hr)
  964. {
  965. ulRef = pstgChild->Release();
  966. DH_ASSERT (0 == ulRef);
  967. pstgChild = NULL;
  968. }
  969. break;
  970. }
  971. case STREAM:
  972. {
  973. hr = pstgRoot->OpenStream(
  974. poszRandomChildName,
  975. NULL,
  976. STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
  977. 0,
  978. &pstmChild);
  979. DH_HRCHECK(hr, TEXT("IStorage::OpenStream")) ;
  980. if(S_OK == hr)
  981. {
  982. ulRef = pstmChild->Release();
  983. DH_ASSERT (0 == ulRef);
  984. pstmChild = NULL;
  985. }
  986. break;
  987. }
  988. }
  989. ulRef = pstgRoot->Release();
  990. DH_ASSERT (0 == ulRef);
  991. pstgRoot = NULL;
  992. }
  993. // Delete temp strings
  994. if(NULL != ptszRandomChildName)
  995. {
  996. delete [] ptszRandomChildName;
  997. ptszRandomChildName = NULL;
  998. }
  999. if(NULL != ptszRandomRootName)
  1000. {
  1001. if(FALSE == DeleteFile(ptszRandomRootName))
  1002. {
  1003. hr = HRESULT_FROM_WIN32(GetLastError()) ;
  1004. DH_HRCHECK(hr, TEXT("DeleteFile")) ;
  1005. }
  1006. delete [] ptszRandomRootName;
  1007. ptszRandomRootName = NULL;
  1008. }
  1009. if(NULL != poszRandomChildName)
  1010. {
  1011. delete [] poszRandomChildName;
  1012. poszRandomChildName = NULL;
  1013. }
  1014. if(NULL != poszRandomChildName)
  1015. {
  1016. delete [] poszRandomChildName;
  1017. poszRandomChildName = NULL;
  1018. }
  1019. }
  1020. // if something did no pass, mark test (hr) as E_FAIL
  1021. if (FALSE == fPass)
  1022. {
  1023. hr = FirstError (hr, E_FAIL);
  1024. }
  1025. // if everything goes well, log test as passed else failed.
  1026. if ((S_OK == hr) && (TRUE == fPass))
  1027. {
  1028. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_101 passed.")) );
  1029. }
  1030. else
  1031. {
  1032. DH_LOG((LOG_FAIL,
  1033. TEXT("Test variation APITEST_101 failed; hr=%#lx; fPass=%d"),
  1034. hr,
  1035. fPass));
  1036. }
  1037. // Cleanup
  1038. // Get the name of file, will be used later to delete the file
  1039. if(NULL != pTestVirtualDF)
  1040. {
  1041. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  1042. if (pFileName != NULL)
  1043. {
  1044. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  1045. }
  1046. }
  1047. // Delete Chance docfile tree
  1048. if(NULL != pTestChanceDF)
  1049. {
  1050. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1051. pTestChanceDF->GetChanceDFRoot());
  1052. DH_HRCHECK(hr2, TEXT("ChanceDF::DeleteChanceFileDocTree")) ;
  1053. delete pTestChanceDF;
  1054. pTestChanceDF = NULL;
  1055. }
  1056. // Delete Virtual docfile tree
  1057. if(NULL != pTestVirtualDF)
  1058. {
  1059. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1060. DH_HRCHECK(hr2, TEXT("VirtualDF::DeleteVirtualFileDocTree")) ;
  1061. delete pTestVirtualDF;
  1062. pTestVirtualDF = NULL;
  1063. }
  1064. // Delete the docfile on disk
  1065. if((S_OK == hr) && (NULL != pFileName))
  1066. {
  1067. if(FALSE == DeleteFile(pFileName))
  1068. {
  1069. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1070. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1071. }
  1072. }
  1073. // Delete temp strings
  1074. if(NULL != pFileName)
  1075. {
  1076. delete []pFileName;
  1077. pFileName = NULL;
  1078. }
  1079. // Stop logging the test
  1080. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_101 finished")) );
  1081. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1082. return hr;
  1083. #endif //_MAC
  1084. }
  1085. //----------------------------------------------------------------------------
  1086. //
  1087. // Test: APITEST_102
  1088. //
  1089. // Synopsis: Attempts various operations in obtaining enumerators, checking
  1090. // for proper error return. Then gets a valid enumerator, and
  1091. // attempts various illegitimate method calls on it. Verify
  1092. // proper return codes.
  1093. //
  1094. // Arguments:[argc]
  1095. // [argv]
  1096. //
  1097. // Returns: HRESULT
  1098. //
  1099. // History: 18-June-1996 NarindK Created.
  1100. //
  1101. // Notes: This test runs in direct, transacted, and transacted deny write
  1102. // modes
  1103. //
  1104. // New Test Notes:
  1105. // 1. Old File: IAENUM.CXX
  1106. // 2. Old name of test : IllegitAPIEnum test
  1107. // New Name of test : APITEST_102
  1108. // 3. To run the test, do the following at command prompt.
  1109. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-102
  1110. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /labmode
  1111. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-102
  1112. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /labmode
  1113. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-102
  1114. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /labmode
  1115. //
  1116. // BUGNOTE: Conversion: APITEST_102
  1117. //-----------------------------------------------------------------------------
  1118. HRESULT APITEST_102(int argc, char *argv[])
  1119. {
  1120. HRESULT hr = S_OK;
  1121. HRESULT hr2 = S_OK;
  1122. ChanceDF *pTestChanceDF = NULL;
  1123. VirtualDF *pTestVirtualDF = NULL;
  1124. VirtualCtrNode *pVirtualDFRoot = NULL;
  1125. LPTSTR pRootNewChildStgName = NULL;
  1126. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  1127. DG_STRING *pdgu = NULL;
  1128. DG_INTEGER *pdgi = NULL;
  1129. LPENUMSTATSTG penumWalk = NULL;
  1130. ULONG cMinNum = 1;
  1131. ULONG cMaxNum = 999;
  1132. DWORD dwReserved1 = 0;
  1133. DWORD dwReserved3 = 0;
  1134. LPTSTR pReserved2 = NULL;
  1135. ULONG ulRef = 0;
  1136. BOOL fPass = TRUE;
  1137. STATSTG statStg;
  1138. ULONG celtFetched = 0;
  1139. LPMALLOC pMalloc = NULL;
  1140. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_102"));
  1141. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1142. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_102 started.")) );
  1143. DH_TRACE((DH_LVL_TRACE1,
  1144. TEXT("Attempt different illegitimate opeations on IEnumSTATSTG. ")));
  1145. // Create our ChanceDF and VirtualDF
  1146. hr = CreateTestDocfile (argc,
  1147. argv,
  1148. &pVirtualDFRoot,
  1149. &pTestVirtualDF,
  1150. &pTestChanceDF);
  1151. // if creating the docfile - bail here
  1152. if (NULL != pTestChanceDF && DoingCreate ())
  1153. {
  1154. UINT ulSeed = pTestChanceDF->GetSeed ();
  1155. CleanupTestDocfile (&pVirtualDFRoot,
  1156. &pTestVirtualDF,
  1157. &pTestChanceDF,
  1158. FALSE);
  1159. return (HRESULT)ulSeed;
  1160. }
  1161. if (S_OK == hr)
  1162. {
  1163. DH_TRACE((
  1164. DH_LVL_TRACE1,
  1165. TEXT("Run Mode for APITEST_102, Access mode: %lx"),
  1166. pTestChanceDF->GetRootMode()));
  1167. }
  1168. // Adds a new storage to the root storage.
  1169. if (S_OK == hr)
  1170. {
  1171. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1172. DH_ASSERT (NULL != pdgu);
  1173. if (NULL == pdgu)
  1174. {
  1175. hr = E_FAIL;
  1176. }
  1177. }
  1178. if(S_OK == hr)
  1179. {
  1180. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  1181. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1182. }
  1183. if(S_OK == hr)
  1184. {
  1185. hr = AddStorage(
  1186. pTestVirtualDF,
  1187. pVirtualDFRoot,
  1188. pRootNewChildStgName,
  1189. pTestChanceDF->GetStgMode()|
  1190. STGM_CREATE |
  1191. STGM_FAILIFTHERE,
  1192. &pvcnRootNewChildStorage);
  1193. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  1194. }
  1195. // BUGBUG: Use Random commit modes...
  1196. if (S_OK == hr)
  1197. {
  1198. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1199. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  1200. }
  1201. // Close the Child storage
  1202. if (NULL != pvcnRootNewChildStorage)
  1203. {
  1204. hr2 = pvcnRootNewChildStorage->Close();
  1205. DH_HRCHECK(hr2, TEXT("VirtualCtrNode::Close")) ;
  1206. hr = FirstError (hr, hr2);
  1207. }
  1208. // Get the random number generator
  1209. if (S_OK == hr)
  1210. {
  1211. pdgi = pTestVirtualDF->GetDataGenInteger();
  1212. DH_ASSERT (NULL != pdgi);
  1213. if (NULL == pdgi)
  1214. {
  1215. hr = E_FAIL;
  1216. }
  1217. }
  1218. if(S_OK == hr)
  1219. {
  1220. hr = pdgi->Generate(&dwReserved1, cMinNum, cMaxNum);
  1221. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  1222. }
  1223. //Call EnumElements with invalid parameters
  1224. if(S_OK == hr)
  1225. {
  1226. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  1227. hr = pVirtualDFRoot->EnumElements(
  1228. dwReserved1,
  1229. pReserved2,
  1230. dwReserved3,
  1231. &penumWalk);
  1232. DH_NOEXPECTEDERROR ();
  1233. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1234. TEXT ("VirtualCtrNode::EnumElements inv dwReserved1"),
  1235. penumWalk);
  1236. }
  1237. if(S_OK == hr)
  1238. {
  1239. hr = pdgi->Generate(&dwReserved3, cMinNum, cMaxNum);
  1240. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  1241. }
  1242. if(S_OK == hr)
  1243. {
  1244. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  1245. hr = pVirtualDFRoot->EnumElements(
  1246. dwReserved1,
  1247. pReserved2,
  1248. dwReserved3,
  1249. &penumWalk);
  1250. DH_NOEXPECTEDERROR ();
  1251. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1252. TEXT ("VirtualCtrNode::EnumElements inv dwReserved3"),
  1253. penumWalk);
  1254. }
  1255. if(S_OK == hr)
  1256. {
  1257. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &pReserved2);
  1258. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1259. }
  1260. if(S_OK == hr)
  1261. {
  1262. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  1263. hr = pVirtualDFRoot->EnumElements(
  1264. dwReserved1,
  1265. pReserved2,
  1266. dwReserved3,
  1267. &penumWalk);
  1268. DH_NOEXPECTEDERROR ();
  1269. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1270. TEXT ("VirtualCtrNode::EnumElements inv pvReserved1"),
  1271. penumWalk);
  1272. }
  1273. // Now call EnumElements with NULL ppenm 4th parameter.
  1274. if(S_OK == hr)
  1275. {
  1276. DH_EXPECTEDERROR (STG_E_INVALIDPOINTER);
  1277. hr = pVirtualDFRoot->EnumElements( 0, NULL, 0, NULL);
  1278. DH_NOEXPECTEDERROR ();
  1279. CheckErrorTest2(STG_E_INVALIDPOINTER,
  1280. TEXT ("VirtualCtrNode::EnumElements NULL ppEnum"));
  1281. }
  1282. // Make a valid call to EnumElements now
  1283. if(S_OK == hr)
  1284. {
  1285. hr = pVirtualDFRoot->EnumElements( 0, NULL, 0, &penumWalk);
  1286. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  1287. DH_ASSERT (NULL != penumWalk);
  1288. }
  1289. // Now try the following skip calls - Attempt to skip 0 elements and
  1290. // attempt to skip MAX_ULONG elements.
  1291. // Attempt to Skip 0 elements.
  1292. if(S_OK == hr)
  1293. {
  1294. hr = penumWalk->Skip(0L);
  1295. DH_HRCHECK(hr, TEXT("IEnumSTATSTG::Skip")) ;
  1296. }
  1297. // Attempt to Skip ULONG_MAX elements.
  1298. // NOTE: In the old test, this was supposed to return S_OK, but it returns
  1299. // S_FALSE
  1300. if(S_OK == hr)
  1301. {
  1302. hr = penumWalk->Skip(ULONG_MAX);
  1303. CheckErrorTest2(S_FALSE,
  1304. TEXT ("IEnumSTATSTG::Skip ULONG_MAX"));
  1305. }
  1306. // Call Clone with NULL ppenum parameter (ist)
  1307. if(S_OK == hr)
  1308. {
  1309. hr = penumWalk->Clone(NULL);
  1310. CheckErrorTest2(STG_E_INVALIDPOINTER,
  1311. TEXT ("IEnumSTATSTG::Clone NULL ppEnum"));
  1312. }
  1313. if(S_OK == hr)
  1314. {
  1315. statStg.pwcsName = NULL;
  1316. // first get pmalloc that would be used to free up the name string from
  1317. // STATSTG.
  1318. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  1319. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  1320. }
  1321. // Reset the enumerator back to start and then test Next methods
  1322. if(S_OK == hr)
  1323. {
  1324. hr = penumWalk->Reset();
  1325. DH_HRCHECK(hr, TEXT("IEnumSTATSTG:Reset")) ;
  1326. }
  1327. // Call Next with celt equal to zero, but pceltFetched as not NULL
  1328. if(S_OK == hr)
  1329. {
  1330. hr = penumWalk->Next(0, &statStg, &celtFetched);
  1331. DH_HRCHECK(hr, TEXT("IEnumSTATSTG::Next celt 0")) ;
  1332. }
  1333. // Call Next with celt equal to 999 and celtFetched as NULL
  1334. if(S_OK == hr)
  1335. {
  1336. hr = penumWalk->Next(999, &statStg ,NULL);
  1337. CheckErrorTest2(STG_E_INVALIDPARAMETER,
  1338. TEXT ("IEnumSTATSTG::Next celt 999 and pceltFetched NULL"));
  1339. }
  1340. // Call Next with rgelt as NULL (2nd parameter). celtFetched may be NULL
  1341. // when celt asked is 1
  1342. if(S_OK == hr)
  1343. {
  1344. hr = penumWalk->Next(1, NULL, NULL);
  1345. CheckErrorTest2(STG_E_INVALIDPOINTER,
  1346. TEXT ("IEnumSTATSTG::Next rgelt NULL"));
  1347. }
  1348. // Call Next with celt as 1 and pceltFetched as NULL. Allowed as per spec
  1349. if(S_OK == hr)
  1350. {
  1351. hr = penumWalk->Next(1, &statStg, NULL);
  1352. DH_HRCHECK(hr, TEXT("IEnumSTATSTG::Next celt 1 and pceltFetched NULL"));
  1353. }
  1354. // Clean up
  1355. if(NULL != statStg.pwcsName)
  1356. {
  1357. pMalloc->Free(statStg.pwcsName);
  1358. statStg.pwcsName = NULL;
  1359. }
  1360. // Free LPENUMSTATSTG pointer
  1361. if(NULL != penumWalk)
  1362. {
  1363. ulRef = penumWalk->Release();
  1364. DH_ASSERT (0 == ulRef);
  1365. penumWalk = NULL;
  1366. }
  1367. // Close the root docfile
  1368. if (NULL != pVirtualDFRoot)
  1369. {
  1370. hr2 = pVirtualDFRoot->Close();
  1371. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  1372. hr = FirstError (hr, hr2);
  1373. }
  1374. // if something did no pass, mark test (hr) as E_FAIL
  1375. if (FALSE == fPass)
  1376. {
  1377. hr = FirstError (hr, E_FAIL);
  1378. }
  1379. // if everything goes well, log test as passed else failed.
  1380. if ((S_OK == hr) && (TRUE == fPass))
  1381. {
  1382. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_102 passed.")) );
  1383. }
  1384. else
  1385. {
  1386. DH_LOG((LOG_FAIL,
  1387. TEXT("Test variation APITEST_102 failed; hr=%#lx; fPass=%d"),
  1388. hr,
  1389. fPass));
  1390. }
  1391. // Cleanup
  1392. CleanupTestDocfile (&pVirtualDFRoot,
  1393. &pTestVirtualDF,
  1394. &pTestChanceDF,
  1395. S_OK == hr);
  1396. // free strings
  1397. if(NULL != pReserved2)
  1398. {
  1399. delete [] pReserved2;
  1400. pReserved2 = NULL;
  1401. }
  1402. if(NULL != pRootNewChildStgName)
  1403. {
  1404. delete [] pRootNewChildStgName;
  1405. pRootNewChildStgName = NULL;
  1406. }
  1407. // Stop logging the test
  1408. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_102 finished")) );
  1409. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1410. return hr;
  1411. }
  1412. //----------------------------------------------------------------------------
  1413. //
  1414. // Test: APITEST_103
  1415. //
  1416. // Synopsis: Attempts various illegit operations on the IStorage interface,
  1417. // verifies proper return codes.
  1418. //
  1419. // Arguments:[argc]
  1420. // [argv]
  1421. //
  1422. // Returns: HRESULT
  1423. //
  1424. // History: 18-June-1996 NarindK Created.
  1425. //
  1426. // Notes: This test runs in direct, transacted, and transacted deny write
  1427. // modes
  1428. //
  1429. // New Test Notes:
  1430. // 1. Old File: IASTORAG.CXX
  1431. // 2. Old name of test : IllegitAPIStorage test
  1432. // New Name of test : APITEST_103
  1433. // 3. To run the test, do the following at command prompt.
  1434. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-103
  1435. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1436. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-103
  1437. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1438. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-103
  1439. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1440. //
  1441. // BUGNOTE: Conversion: APITEST_103
  1442. //-----------------------------------------------------------------------------
  1443. HRESULT APITEST_103(int argc, char *argv[])
  1444. {
  1445. HRESULT hr = S_OK;
  1446. HRESULT hr2 = S_OK;
  1447. ChanceDF *pTestChanceDF = NULL;
  1448. VirtualDF *pTestVirtualDF = NULL;
  1449. VirtualCtrNode *pVirtualDFRoot = NULL;
  1450. LPTSTR ptszChildStgName = NULL;
  1451. LPOLESTR poszChildStgName = NULL;
  1452. LPSTORAGE pStgRoot = NULL;
  1453. LPSTORAGE pStgChild = NULL;
  1454. LPSTORAGE pStgChild2 = NULL;
  1455. LPSTREAM pStmChild = NULL;
  1456. DG_STRING *pdgu = NULL;
  1457. DG_INTEGER *pdgi = NULL;
  1458. ULONG cRandom = 0;
  1459. ULONG cMin = 1;
  1460. ULONG cMax = 999;
  1461. SNB snbTest = NULL;
  1462. SNB snbTemp = NULL;
  1463. OLECHAR *ocsSNBChar = NULL;
  1464. ULONG ulRef = 0;
  1465. ULONG i = 0;
  1466. BOOL fPass = TRUE;
  1467. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_103"));
  1468. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1469. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_103 started.")) );
  1470. DH_TRACE((DH_LVL_TRACE1,
  1471. TEXT("Attempt various illegitimate operations on IStorage interface")));
  1472. // Create our ChanceDF and VirtualDF
  1473. hr = CreateTestDocfile (argc,
  1474. argv,
  1475. &pVirtualDFRoot,
  1476. &pTestVirtualDF,
  1477. &pTestChanceDF);
  1478. // if creating the docfile - bail here
  1479. if (NULL != pTestChanceDF && DoingCreate ())
  1480. {
  1481. UINT ulSeed = pTestChanceDF->GetSeed ();
  1482. CleanupTestDocfile (&pVirtualDFRoot,
  1483. &pTestVirtualDF,
  1484. &pTestChanceDF,
  1485. FALSE);
  1486. return (HRESULT)ulSeed;
  1487. }
  1488. if (S_OK == hr)
  1489. {
  1490. DH_TRACE((
  1491. DH_LVL_TRACE1,
  1492. TEXT("Run Mode for APITEST_103, Access mode: %lx"),
  1493. pTestChanceDF->GetRootMode()));
  1494. }
  1495. // Get IStorage pointer
  1496. if (S_OK == hr)
  1497. {
  1498. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  1499. DH_ASSERT (NULL != pStgRoot);
  1500. if (NULL == pStgRoot)
  1501. {
  1502. hr = E_FAIL;
  1503. }
  1504. }
  1505. if (S_OK == hr)
  1506. {
  1507. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1508. DH_ASSERT (NULL != pdgu);
  1509. if (NULL == pdgu)
  1510. {
  1511. hr = E_FAIL;
  1512. }
  1513. }
  1514. if(S_OK == hr)
  1515. {
  1516. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszChildStgName);
  1517. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  1518. }
  1519. if(S_OK == hr)
  1520. {
  1521. // Convert name to OLECHAR
  1522. hr = TStringToOleString(ptszChildStgName, &poszChildStgName);
  1523. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  1524. }
  1525. // Call CreateStorage with grfmode=-1
  1526. if (S_OK == hr)
  1527. {
  1528. hr = pStgRoot->CreateStorage(
  1529. poszChildStgName,
  1530. (DWORD) -1,
  1531. 0,
  1532. 0,
  1533. &pStgChild);
  1534. CheckErrorTest(STG_E_INVALIDFLAG,
  1535. TEXT ("IStorage::CreateStorage inv mode"),
  1536. pStgChild);
  1537. }
  1538. if (S_OK == hr)
  1539. {
  1540. pdgi = pTestVirtualDF->GetDataGenInteger();
  1541. DH_ASSERT (NULL != pdgi);
  1542. if (NULL == pdgi)
  1543. {
  1544. hr = E_FAIL;
  1545. }
  1546. }
  1547. if (S_OK == hr)
  1548. {
  1549. hr = pdgi->Generate(&cRandom, cMin, cMax);
  1550. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  1551. }
  1552. // Call CreateStorage with random data in dwReserved1
  1553. if (S_OK == hr)
  1554. {
  1555. hr = pStgRoot->CreateStorage(
  1556. poszChildStgName,
  1557. pTestChanceDF->GetStgMode() | STGM_CREATE,
  1558. cRandom,
  1559. 0,
  1560. &pStgChild);
  1561. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1562. TEXT ("IStorage::CreateStorage inv dwReserved1"),
  1563. pStgChild);
  1564. }
  1565. // Call CreateStorage with random data in dwReserved2
  1566. if (S_OK == hr)
  1567. {
  1568. hr = pStgRoot->CreateStorage(
  1569. poszChildStgName,
  1570. pTestChanceDF->GetStgMode() | STGM_CREATE,
  1571. 0,
  1572. cRandom,
  1573. &pStgChild);
  1574. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1575. TEXT ("IStorage::CreateStorage inv dwReserved2"),
  1576. pStgChild);
  1577. }
  1578. // Call CreateStorage with NULL 5th ppstg parameter
  1579. if (S_OK == hr)
  1580. {
  1581. hr = pStgRoot->CreateStorage(
  1582. poszChildStgName,
  1583. pTestChanceDF->GetStgMode() | STGM_CREATE,
  1584. 0,
  1585. 0,
  1586. NULL);
  1587. CheckErrorTest2(STG_E_INVALIDPOINTER,
  1588. TEXT ("IStorage::CreateStorage NULL ppstg"));
  1589. }
  1590. // Create a stream with poszChildName and later on try to instantiate the
  1591. // child storage with that same name poszChildName
  1592. if (S_OK == hr)
  1593. {
  1594. hr = pStgRoot->CreateStream(
  1595. poszChildStgName,
  1596. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  1597. 0,
  1598. 0,
  1599. &pStmChild);
  1600. DH_HRCHECK (hr, TEXT("IStorage::CreateStream"));
  1601. }
  1602. // BUGBUG: Use Random commit modes...
  1603. if (S_OK == hr)
  1604. {
  1605. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1606. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  1607. }
  1608. // Close stream...
  1609. if (NULL != pStmChild)
  1610. {
  1611. ulRef = pStmChild->Release();
  1612. DH_ASSERT (0 == ulRef);
  1613. pStmChild = NULL;
  1614. }
  1615. // Now try opening storage with name with which above stream was created
  1616. // i.e. poszChildName
  1617. if (S_OK == hr)
  1618. {
  1619. pStgChild = NULL;
  1620. hr = pStgRoot->OpenStorage(
  1621. poszChildStgName,
  1622. NULL,
  1623. pTestChanceDF->GetStgMode(),
  1624. NULL,
  1625. 0,
  1626. &pStgChild);
  1627. CheckErrorTest(STG_E_FILENOTFOUND,
  1628. TEXT ("IStorage::OpenStorage inv name"),
  1629. pStgChild);
  1630. }
  1631. //Destroy the stream element of this root storage having name poszChildStg
  1632. //Name
  1633. if(S_OK == hr)
  1634. {
  1635. hr = pStgRoot->DestroyElement(poszChildStgName);
  1636. DH_HRCHECK(hr, TEXT("IStorage::DestroyElement")) ;
  1637. }
  1638. // Create a valid storage with name poszChildStgName
  1639. if (S_OK == hr)
  1640. {
  1641. pStgChild = NULL;
  1642. hr = pStgRoot->CreateStorage(
  1643. poszChildStgName,
  1644. pTestChanceDF->GetStgMode() | STGM_CREATE | STGM_FAILIFTHERE,
  1645. 0,
  1646. 0,
  1647. &pStgChild);
  1648. DH_HRCHECK(hr, TEXT("IStorage::CreateStorage")) ;
  1649. }
  1650. // Commit with grfCommitFlags = -1
  1651. if (S_OK == hr)
  1652. {
  1653. hr = pStgChild->Commit((DWORD) -1);
  1654. CheckErrorTest2(STG_E_INVALIDFLAG,
  1655. TEXT ("IStorage::Commit inv flag"));
  1656. }
  1657. // Commit the child. BUGBUG: Use random commit modes
  1658. if (S_OK == hr)
  1659. {
  1660. hr = pStgChild->Commit(STGC_DEFAULT);
  1661. DH_HRCHECK (hr, TEXT("IStorage::Commit"));
  1662. }
  1663. // Commit the root storage. BUGBUG: Use random commit modes
  1664. if (S_OK == hr)
  1665. {
  1666. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1667. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  1668. }
  1669. // Attempt second instantiation of pStgChild which is already open.
  1670. if (S_OK == hr)
  1671. {
  1672. hr = pStgRoot->OpenStorage(
  1673. poszChildStgName,
  1674. NULL,
  1675. pTestChanceDF->GetStgMode(),
  1676. NULL,
  1677. 0,
  1678. &pStgChild2);
  1679. CheckErrorTest(STG_E_ACCESSDENIED,
  1680. TEXT ("IStorage::OpenStorage 2nd time"),
  1681. pStgChild2);
  1682. }
  1683. // Release the child
  1684. if (NULL != pStgChild)
  1685. {
  1686. ulRef = pStgChild->Release();
  1687. DH_ASSERT (0 == ulRef);
  1688. pStgChild = NULL;
  1689. }
  1690. // Now try to open child IStorage, but with grfMode = -1
  1691. if (S_OK == hr)
  1692. {
  1693. pStgChild = NULL;
  1694. hr = pStgRoot->OpenStorage(
  1695. poszChildStgName,
  1696. NULL,
  1697. (DWORD) -1,
  1698. NULL,
  1699. 0,
  1700. &pStgChild);
  1701. CheckErrorTest(STG_E_INVALIDFLAG,
  1702. TEXT ("IStorage::OpenStorage inv mode"),
  1703. pStgChild);
  1704. }
  1705. // Attempt OpenStorage with name as "" of IStorage to be opened.
  1706. if (S_OK == hr)
  1707. {
  1708. pStgChild = NULL;
  1709. hr = pStgRoot->OpenStorage(
  1710. (OLECHAR *) " ",
  1711. NULL,
  1712. pTestChanceDF->GetStgMode(),
  1713. NULL,
  1714. 0,
  1715. &pStgChild);
  1716. CheckErrorTest(STG_E_FILENOTFOUND,
  1717. TEXT ("IStorage::OpenStorage inv name"),
  1718. pStgChild);
  1719. }
  1720. // Attempt OpenStorage with name as NULL of IStorage to be opened.
  1721. #ifdef _MAC
  1722. DH_TRACE((DH_LVL_TRACE1, TEXT("OpenStorage with NULL name skipped.")) );
  1723. #else
  1724. if (S_OK == hr)
  1725. {
  1726. pStgChild = NULL;
  1727. hr = pStgRoot->OpenStorage(
  1728. NULL,
  1729. NULL,
  1730. pTestChanceDF->GetStgMode(),
  1731. NULL,
  1732. 0,
  1733. &pStgChild);
  1734. CheckErrorTest(STG_E_INVALIDNAME,
  1735. TEXT ("IStorage::OpenStorage NULL name"),
  1736. pStgChild);
  1737. }
  1738. #endif //_MAC
  1739. // Attempt OpenStorage with name as NULL ppstg, 6th parameter.
  1740. if (S_OK == hr)
  1741. {
  1742. hr = pStgRoot->OpenStorage(
  1743. poszChildStgName,
  1744. NULL,
  1745. pTestChanceDF->GetStgMode(),
  1746. NULL,
  1747. 0,
  1748. NULL);
  1749. CheckErrorTest2(STG_E_INVALIDPOINTER,
  1750. TEXT ("IStorage::OpenStorage NULL ppstg"));
  1751. }
  1752. // Attempt OpenStorage with random data in dwReserved parameter
  1753. if (S_OK == hr && NULL != pdgi)
  1754. {
  1755. hr = pdgi->Generate(&cRandom, cMin, cMax);
  1756. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  1757. }
  1758. if (S_OK == hr)
  1759. {
  1760. pStgChild = NULL;
  1761. hr = pStgRoot->OpenStorage(
  1762. poszChildStgName,
  1763. NULL,
  1764. pTestChanceDF->GetStgMode(),
  1765. NULL,
  1766. cRandom,
  1767. &pStgChild);
  1768. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1769. TEXT ("IStorage::OpenStorage inv dwReserved"),
  1770. pStgChild);
  1771. }
  1772. // Attempt OpenStorage with uninitialized SNB, should fail, but no GP
  1773. // fault should occur.
  1774. if(S_OK == hr)
  1775. {
  1776. snbTest = (OLECHAR **) new OLECHAR [sizeof(OLECHAR *) * 2];
  1777. if(NULL == snbTest)
  1778. {
  1779. hr = E_OUTOFMEMORY;
  1780. }
  1781. else
  1782. { // bad pointer so SNB is not initialized
  1783. *snbTest = (OLECHAR*)0xBAADF00D;
  1784. }
  1785. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  1786. }
  1787. if (S_OK == hr)
  1788. {
  1789. pStgChild = NULL;
  1790. hr = pStgRoot->OpenStorage(
  1791. poszChildStgName,
  1792. NULL,
  1793. pTestChanceDF->GetStgMode(),
  1794. snbTest,
  1795. 0,
  1796. &pStgChild);
  1797. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1798. TEXT ("IStorage::OpenStorage uninitd SNB"),
  1799. pStgChild);
  1800. }
  1801. // Attempt OpenStorage with SNB with no name in block, although it has
  1802. // space for two names, set name list to NULL
  1803. if(S_OK == hr && NULL != snbTest)
  1804. {
  1805. *snbTest = NULL;
  1806. }
  1807. if (S_OK == hr)
  1808. {
  1809. pStgChild = NULL;
  1810. hr = pStgRoot->OpenStorage(
  1811. poszChildStgName,
  1812. NULL,
  1813. pTestChanceDF->GetStgMode(),
  1814. snbTest,
  1815. 0,
  1816. &pStgChild);
  1817. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1818. TEXT ("IStorage::OpenStorage empty SNB"),
  1819. pStgChild);
  1820. }
  1821. // Allocate space for long name and fill name with X's, make next SNB
  1822. // element NULL, and make a call to IStorage::OpenStorage with too long a
  1823. // name in SNB
  1824. if(S_OK == hr && NULL != snbTest)
  1825. {
  1826. *snbTest = (OLECHAR *) new OLECHAR [MAX_STG_NAME_LEN*4];
  1827. if (NULL == *snbTest)
  1828. {
  1829. hr = E_OUTOFMEMORY;
  1830. }
  1831. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  1832. }
  1833. if(S_OK == hr && NULL != snbTest)
  1834. {
  1835. snbTemp = snbTest;
  1836. ocsSNBChar = *snbTemp;
  1837. for (i=0; i<( MAX_STG_NAME_LEN*4 -1); i++)
  1838. {
  1839. ocsSNBChar[i] = 'X';
  1840. }
  1841. ocsSNBChar[i] = '\0';
  1842. // Assign second element as NULL
  1843. snbTemp++;
  1844. *snbTemp = NULL;
  1845. }
  1846. if (S_OK == hr)
  1847. {
  1848. pStgChild = NULL;
  1849. hr = pStgRoot->OpenStorage(
  1850. poszChildStgName,
  1851. NULL,
  1852. pTestChanceDF->GetStgMode(),
  1853. snbTest,
  1854. 0,
  1855. &pStgChild);
  1856. CheckErrorTest(STG_E_INVALIDPARAMETER,
  1857. TEXT ("IStorage::OpenStorage too long SNB"),
  1858. pStgChild);
  1859. }
  1860. // Close the root docfile
  1861. if (NULL != pVirtualDFRoot)
  1862. {
  1863. hr2 = pVirtualDFRoot->Close();
  1864. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  1865. hr = FirstError (hr, hr2);
  1866. }
  1867. // if something did no pass, mark test (hr) as E_FAIL
  1868. if (FALSE == fPass)
  1869. {
  1870. hr = FirstError (hr, E_FAIL);
  1871. }
  1872. // if everything goes well, log test as passed else failed.
  1873. if ((S_OK == hr) && (TRUE == fPass))
  1874. {
  1875. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_103 passed.")) );
  1876. }
  1877. else
  1878. {
  1879. DH_LOG((LOG_FAIL,
  1880. TEXT("Test variation APITEST_103 failed; hr=%#lx; fPass=%d"),
  1881. hr,
  1882. fPass));
  1883. }
  1884. // Cleanup
  1885. CleanupTestDocfile (&pVirtualDFRoot,
  1886. &pTestVirtualDF,
  1887. &pTestChanceDF,
  1888. S_OK == hr);
  1889. // Delete temp strings
  1890. if(NULL != ptszChildStgName)
  1891. {
  1892. delete ptszChildStgName;
  1893. ptszChildStgName = NULL;
  1894. }
  1895. if(NULL != poszChildStgName)
  1896. {
  1897. delete poszChildStgName;
  1898. poszChildStgName = NULL;
  1899. }
  1900. // Free SNB
  1901. if(NULL != snbTest)
  1902. {
  1903. if(NULL != *snbTest)
  1904. {
  1905. delete [] *snbTest;
  1906. *snbTest = NULL;
  1907. }
  1908. delete [] snbTest;
  1909. snbTest = NULL;
  1910. }
  1911. // Stop logging the test
  1912. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_103 finished")) );
  1913. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1914. return hr;
  1915. }
  1916. //----------------------------------------------------------------------------
  1917. //
  1918. // Test: APITEST_104
  1919. //
  1920. // Synopsis: Attempts various illegit operations on the IStream interface,
  1921. // verifies proper return codes.
  1922. //
  1923. // Arguments:[argc]
  1924. // [argv]
  1925. //
  1926. // Returns: HRESULT
  1927. //
  1928. // History: 18-June-1996 NarindK Created.
  1929. //
  1930. // Notes: This test runs in direct, transacted, and transacted deny write
  1931. // modes
  1932. //
  1933. // New Test Notes:
  1934. // 1. Old File: IASTREAM.CXX
  1935. // 2. Old name of test : IllegitAPIStream test
  1936. // New Name of test : APITEST_104
  1937. // 3. To run the test, do the following at command prompt.
  1938. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-104
  1939. // /dfRootMode:dirReadWriteShEx
  1940. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-104
  1941. // /dfRootMode:xactReadWriteShEx
  1942. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-104
  1943. // /dfRootMode:xactReadWriteShDenyW
  1944. //
  1945. // BUGNOTE: Conversion: APITEST_104
  1946. //-----------------------------------------------------------------------------
  1947. HRESULT APITEST_104(int argc, char *argv[])
  1948. {
  1949. HRESULT hr = S_OK;
  1950. HRESULT hr2 = S_OK;
  1951. ChanceDF *pTestChanceDF = NULL;
  1952. VirtualDF *pTestVirtualDF = NULL;
  1953. VirtualCtrNode *pVirtualDFRoot = NULL;
  1954. LPTSTR ptszChildStmName = NULL;
  1955. LPOLESTR poszChildStmName = NULL;
  1956. LPSTORAGE pStgRoot = NULL;
  1957. LPSTORAGE pStgChild = NULL;
  1958. LPSTREAM pStmChild = NULL;
  1959. LPSTREAM pStmChild2 = NULL;
  1960. ULONG ulRef = 0;
  1961. DG_STRING *pdgu = NULL;
  1962. DG_INTEGER *pdgi = NULL;
  1963. ULONG cRandom = 0;
  1964. ULONG cMin = 1;
  1965. ULONG cMax = 999;
  1966. BOOL fPass = TRUE;
  1967. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_104"));
  1968. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1969. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_104 started.")) );
  1970. DH_TRACE((DH_LVL_TRACE1,
  1971. TEXT("Attempt illegitimate operations on IStream interface. ")));
  1972. // Create our ChanceDF and VirtualDF
  1973. hr = CreateTestDocfile (argc,
  1974. argv,
  1975. &pVirtualDFRoot,
  1976. &pTestVirtualDF,
  1977. &pTestChanceDF);
  1978. // if creating the docfile - bail here
  1979. if (NULL != pTestChanceDF && DoingCreate ())
  1980. {
  1981. UINT ulSeed = pTestChanceDF->GetSeed ();
  1982. CleanupTestDocfile (&pVirtualDFRoot,
  1983. &pTestVirtualDF,
  1984. &pTestChanceDF,
  1985. FALSE);
  1986. return (HRESULT)ulSeed;
  1987. }
  1988. if (S_OK == hr)
  1989. {
  1990. DH_TRACE((
  1991. DH_LVL_TRACE1,
  1992. TEXT("Run Mode for APITEST_104, Access mode: %lx"),
  1993. pTestChanceDF->GetRootMode()));
  1994. }
  1995. // Get IStorage pointer
  1996. if (S_OK == hr)
  1997. {
  1998. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  1999. DH_ASSERT (NULL != pStgRoot);
  2000. if (NULL == pStgRoot)
  2001. {
  2002. hr = E_FAIL;
  2003. }
  2004. }
  2005. // Get DG_STRING pointer
  2006. if (S_OK == hr)
  2007. {
  2008. pdgu = pTestVirtualDF->GetDataGenUnicode();
  2009. DH_ASSERT (NULL != pdgu);
  2010. if (NULL == pdgu)
  2011. {
  2012. hr = E_FAIL;
  2013. }
  2014. }
  2015. // Generate random name for stream
  2016. if(S_OK == hr)
  2017. {
  2018. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &ptszChildStmName);
  2019. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2020. }
  2021. if(S_OK == hr)
  2022. {
  2023. // Convert name to OLECHAR
  2024. hr = TStringToOleString(ptszChildStmName, &poszChildStmName);
  2025. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2026. }
  2027. // Attempt CreateStream with grfmode=-1
  2028. if (S_OK == hr)
  2029. {
  2030. hr = pStgRoot->CreateStream(
  2031. poszChildStmName,
  2032. (DWORD) -1,
  2033. 0,
  2034. 0,
  2035. &pStmChild);
  2036. CheckErrorTest(STG_E_INVALIDFLAG,
  2037. TEXT ("IStorage::CreateStream inv grfMode"),
  2038. pStmChild);
  2039. }
  2040. // Get DG_INTEGER pointer
  2041. if (S_OK == hr)
  2042. {
  2043. pdgi = pTestVirtualDF->GetDataGenInteger();
  2044. DH_ASSERT (NULL != pdgi);
  2045. if (NULL == pdgi)
  2046. {
  2047. hr = E_FAIL;
  2048. }
  2049. }
  2050. if (S_OK == hr)
  2051. {
  2052. hr = pdgi->Generate(&cRandom, cMin, cMax);
  2053. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  2054. }
  2055. // Call CreateStorage with random data in dwReserved1
  2056. if (S_OK == hr)
  2057. {
  2058. hr = pStgRoot->CreateStream(
  2059. poszChildStmName,
  2060. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2061. cRandom,
  2062. 0,
  2063. &pStmChild);
  2064. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2065. TEXT ("IStorage::CreateStream inv dwReserved1"),
  2066. pStmChild);
  2067. }
  2068. // Call CreateStream with random data in dwReserved2
  2069. if (S_OK == hr)
  2070. {
  2071. hr = pStgRoot->CreateStream(
  2072. poszChildStmName,
  2073. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2074. 0,
  2075. cRandom,
  2076. &pStmChild);
  2077. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2078. TEXT ("IStorage::CreateStream inv dwReserved2"),
  2079. pStmChild);
  2080. }
  2081. // Call CreateStorage with NULL 5th ppstm parameter
  2082. if (S_OK == hr)
  2083. {
  2084. hr = pStgRoot->CreateStream(
  2085. poszChildStmName,
  2086. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2087. 0,
  2088. 0,
  2089. NULL);
  2090. CheckErrorTest2(STG_E_INVALIDPOINTER,
  2091. TEXT ("IStorage::CreateStream NULL ppstm"));
  2092. }
  2093. // Create a storage with poszChildStmName and later on try to instantiate
  2094. // child stream with that same name poszChildStmName
  2095. if (S_OK == hr)
  2096. {
  2097. hr = pStgRoot->CreateStorage(
  2098. poszChildStmName,
  2099. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  2100. 0,
  2101. 0,
  2102. &pStgChild);
  2103. DH_HRCHECK (hr, TEXT ("IStorage::CreateStream"));
  2104. DH_ASSERT (NULL != pStgChild);
  2105. }
  2106. // BUGBUG: Use Random commit modes...
  2107. if (S_OK == hr)
  2108. {
  2109. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2110. DH_HRCHECK (hr, TEXT ("VirtualCtrNode::Commit"));
  2111. }
  2112. // Close storage...
  2113. if (NULL != pStgChild)
  2114. {
  2115. ulRef = pStgChild->Release();
  2116. DH_ASSERT (0 == ulRef);
  2117. pStgChild = NULL;
  2118. }
  2119. // Now try opening storage with name with which above stream was created
  2120. // i.e. poszChildStmName
  2121. if (S_OK == hr)
  2122. {
  2123. pStmChild = NULL;
  2124. hr = pStgRoot->OpenStream(
  2125. poszChildStmName,
  2126. NULL,
  2127. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2128. 0,
  2129. &pStmChild);
  2130. CheckErrorTest(STG_E_FILENOTFOUND,
  2131. TEXT ("IStorage::CreateStream inv name"),
  2132. pStmChild);
  2133. }
  2134. //Destroy the storage element of this root storage having name poszChildStm
  2135. //Name
  2136. if(S_OK == hr)
  2137. {
  2138. hr = pStgRoot->DestroyElement(poszChildStmName);
  2139. DH_HRCHECK(hr, TEXT("IStorage::DestroyElement")) ;
  2140. }
  2141. // Create a valid stream with name poszChildStmName
  2142. if (S_OK == hr)
  2143. {
  2144. pStmChild = NULL;
  2145. hr = pStgRoot->CreateStream(
  2146. poszChildStmName,
  2147. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_FAILIFTHERE,
  2148. 0,
  2149. 0,
  2150. &pStmChild);
  2151. DH_HRCHECK (hr, TEXT("IStorage::CreateStream"));
  2152. }
  2153. // BUGBUG: Use Random commit modes...
  2154. if (S_OK == hr)
  2155. {
  2156. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2157. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  2158. }
  2159. // Attempt second instance of IStream to be instantiated.
  2160. if (S_OK == hr)
  2161. {
  2162. pStmChild2 = NULL;
  2163. hr = pStgRoot->OpenStream(
  2164. poszChildStmName,
  2165. NULL,
  2166. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2167. 0,
  2168. &pStmChild2);
  2169. CheckErrorTest(STG_E_ACCESSDENIED,
  2170. TEXT ("IStorage::OpenStream 2nd time"),
  2171. pStmChild2);
  2172. }
  2173. // Release the stream
  2174. if(NULL != pStmChild)
  2175. {
  2176. ulRef = pStmChild->Release();
  2177. DH_ASSERT (0 == ulRef);
  2178. pStmChild = NULL;
  2179. }
  2180. // Now attempt opening the stream with grfMode = -1
  2181. if (S_OK == hr)
  2182. {
  2183. pStmChild = NULL;
  2184. hr = pStgRoot->OpenStream(
  2185. poszChildStmName,
  2186. NULL,
  2187. (DWORD) -1,
  2188. 0,
  2189. &pStmChild);
  2190. CheckErrorTest(STG_E_INVALIDFLAG,
  2191. TEXT ("IStorage::OpenStream inv grfMode"),
  2192. pStmChild);
  2193. }
  2194. // Now attempt opening the stream with name as ""
  2195. if (S_OK == hr)
  2196. {
  2197. pStmChild = NULL;
  2198. hr = pStgRoot->OpenStream(
  2199. (OLECHAR *) " ",
  2200. NULL,
  2201. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2202. 0,
  2203. &pStmChild);
  2204. CheckErrorTest(STG_E_FILENOTFOUND,
  2205. TEXT ("IStorage::OpenStream inv name"),
  2206. pStmChild);
  2207. }
  2208. // Now attempt opening the stream with name as NULL
  2209. #ifdef _MAC
  2210. DH_TRACE((DH_LVL_TRACE1, TEXT("OpenStream with NULL name skipped.")) );
  2211. #else
  2212. if (S_OK == hr)
  2213. {
  2214. pStmChild = NULL;
  2215. hr = pStgRoot->OpenStream(
  2216. NULL,
  2217. NULL,
  2218. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2219. 0,
  2220. &pStmChild);
  2221. CheckErrorTest(STG_E_INVALIDNAME,
  2222. TEXT ("IStorage::OpenStream NULL name"),
  2223. pStmChild);
  2224. }
  2225. #endif // _MAC
  2226. // Now attempt opening the stream with random data in pReserved1 . For test
  2227. // we just put pStgRoot for pReserved1 variable.
  2228. if (S_OK == hr)
  2229. {
  2230. pStmChild = NULL;
  2231. hr = pStgRoot->OpenStream(
  2232. poszChildStmName,
  2233. pStgRoot,
  2234. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2235. 0,
  2236. &pStmChild);
  2237. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2238. TEXT ("IStorage::OpenStream inv pReserved1"),
  2239. pStmChild);
  2240. }
  2241. // Now attempt opening the stream with random data in dwReserved2
  2242. if (S_OK == hr)
  2243. {
  2244. pStmChild = NULL;
  2245. hr = pStgRoot->OpenStream(
  2246. poszChildStmName,
  2247. NULL,
  2248. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2249. cRandom,
  2250. &pStmChild);
  2251. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2252. TEXT ("IStorage::OpenStream inv dwReserved2"),
  2253. pStmChild);
  2254. }
  2255. // Now attempt opening the stream with NULL ppstm (5th parameter)
  2256. if (S_OK == hr)
  2257. {
  2258. hr = pStgRoot->OpenStream(
  2259. poszChildStmName,
  2260. NULL,
  2261. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2262. 0,
  2263. NULL);
  2264. CheckErrorTest2(STG_E_INVALIDPOINTER,
  2265. TEXT ("IStorage::OpenStream NULL ppstm"));
  2266. }
  2267. // Now attempt opening the stream normally
  2268. if (S_OK == hr)
  2269. {
  2270. pStmChild = NULL;
  2271. hr = pStgRoot->OpenStream(
  2272. poszChildStmName,
  2273. NULL,
  2274. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  2275. 0,
  2276. &pStmChild);
  2277. DH_HRCHECK (hr, TEXT("IStorage::OpenStream"));
  2278. // Release the stream
  2279. if(S_OK == hr)
  2280. {
  2281. ulRef = pStmChild->Release();
  2282. DH_ASSERT (0 == ulRef);
  2283. }
  2284. }
  2285. // Release the root docfile
  2286. if (NULL != pVirtualDFRoot)
  2287. {
  2288. hr2 = pVirtualDFRoot->Close();
  2289. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  2290. hr = FirstError (hr, hr2);
  2291. }
  2292. // if something did not pass, mark test (hr) as E_FAIL
  2293. if (FALSE == fPass)
  2294. {
  2295. hr = FirstError (hr, E_FAIL);
  2296. }
  2297. // if everything goes well, log test as passed else failed.
  2298. if ((S_OK == hr) && (TRUE == fPass))
  2299. {
  2300. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_104 passed.")) );
  2301. }
  2302. else
  2303. {
  2304. DH_LOG((LOG_FAIL,
  2305. TEXT("Test variation APITEST_104 failed; hr=%#lx; fPass=%d"),
  2306. hr,
  2307. fPass));
  2308. }
  2309. // Cleanup
  2310. CleanupTestDocfile (&pVirtualDFRoot,
  2311. &pTestVirtualDF,
  2312. &pTestChanceDF,
  2313. S_OK == hr);
  2314. // Delete temp string
  2315. if(NULL != ptszChildStmName)
  2316. {
  2317. delete []ptszChildStmName;
  2318. ptszChildStmName = NULL;
  2319. }
  2320. if(NULL != poszChildStmName)
  2321. {
  2322. delete []poszChildStmName;
  2323. poszChildStmName = NULL;
  2324. }
  2325. // Stop logging the test
  2326. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation APITEST_104 finished")) );
  2327. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2328. return hr;
  2329. }
  2330. // for non _OLE_NSS_, funcs are stubbed out below
  2331. #ifdef _OLE_NSS_
  2332. //----------------------------------------------------------------------------
  2333. //
  2334. // Test: APITEST_200
  2335. //
  2336. // Synopsis: This test attempts various operations on StgCreateStorageEx,
  2337. // StgOpenStorageEx API's
  2338. //
  2339. // Arguments:[argc]
  2340. // [argv]
  2341. //
  2342. // Returns: HRESULT
  2343. //
  2344. // Notes: This test runs in direct, transacted, and transacted deny write
  2345. // modes
  2346. //
  2347. // History: 18-June-1996 NarindK Created.
  2348. //
  2349. // New Test Notes:
  2350. // 1. Old File: IAPISTG.CXX
  2351. // 2. Old name of test : IllegitAPIStg test
  2352. // New Name of test : APITEST_200
  2353. // 3. To run the test, do the following at command prompt.
  2354. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-200
  2355. // /dfRootMode:dirReadWriteShEx /dfname:APITEST.200 /labmode
  2356. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-200
  2357. // /dfRootMode:xactReadWriteShEx /dfname:APITEST.200 /labmode
  2358. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-200
  2359. // /dfRootMode:xactReadWriteShDenyW /dfname:APITEST.200 /labmode
  2360. //
  2361. // BUGNOTE: Conversion: APITEST-200 NO
  2362. //
  2363. //-----------------------------------------------------------------------------
  2364. HRESULT APITEST_200(int argc, char *argv[])
  2365. {
  2366. HRESULT hr = S_OK;
  2367. HRESULT hr2 = S_OK;
  2368. ChanceDF *pTestChanceDF = NULL;
  2369. VirtualDF *pTestVirtualDF = NULL;
  2370. VirtualCtrNode *pVirtualDFRoot = NULL;
  2371. LPTSTR pRootDocFileName = NULL;
  2372. DWORD dwRootMode = NULL;
  2373. LPSTORAGE pIStorage = NULL;
  2374. LPSTORAGE pIStorageOpen = NULL;
  2375. LPOLESTR pOleStrTemp = NULL;
  2376. TCHAR tszTestName[10] = TEXT("NonExist");
  2377. LPOLESTR pOleStrTest = NULL;
  2378. SNB snbTest = NULL;
  2379. SNB snbTemp = NULL;
  2380. ULONG ulRef = 0;
  2381. OLECHAR *ocsSNBChar = NULL;
  2382. ULONG i = 0;
  2383. BOOL fPass = TRUE;
  2384. CLSID clsidBogus = {0xBAADF00D,
  2385. 0xBAAD,
  2386. 0xF00D,
  2387. {0xA0, 0xA0, 0xA0, 0xA0,
  2388. 0xA0, 0xA0, 0xA0, 0xA0}};
  2389. DWORD stgfmt = StorageIsFlat()?STGFMT_FILE:0;
  2390. // Not for 2phase. Bail.
  2391. if (DoingDistrib ())
  2392. {
  2393. return S_OK;
  2394. }
  2395. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_200"));
  2396. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_200 started.")) );
  2397. DH_TRACE((DH_LVL_ALWAYS,
  2398. TEXT("Attempt illegitimate ops on StgCreateStorageEx & ")
  2399. TEXT("StgOpenStorageEx.")));
  2400. // Create the new ChanceDocFile tree that would consist of chance nodes.
  2401. if (S_OK == hr)
  2402. {
  2403. pTestChanceDF = new ChanceDF();
  2404. if(NULL == pTestChanceDF)
  2405. {
  2406. hr = E_OUTOFMEMORY;
  2407. }
  2408. DH_HRCHECK (hr, TEXT("new ChanceDF"));
  2409. }
  2410. if (S_OK == hr)
  2411. {
  2412. hr = pTestChanceDF->CreateFromParams(argc, argv);
  2413. DH_HRCHECK(hr, TEXT("ChanceDF::CreateFromParams")) ;
  2414. }
  2415. if (S_OK == hr)
  2416. {
  2417. dwRootMode = pTestChanceDF->GetRootMode();
  2418. DH_TRACE((
  2419. DH_LVL_TRACE1,
  2420. TEXT("Run Mode for APITEST_200, Access mode: %lx"),
  2421. pTestChanceDF->GetRootMode()));
  2422. }
  2423. // Get RootDocFile name
  2424. if (S_OK == hr)
  2425. {
  2426. if(NULL != pTestChanceDF->GetDocFileName())
  2427. {
  2428. pRootDocFileName =
  2429. new TCHAR[_tcslen(pTestChanceDF->GetDocFileName())+1];
  2430. if (pRootDocFileName == NULL)
  2431. {
  2432. hr = E_OUTOFMEMORY;
  2433. }
  2434. else
  2435. {
  2436. _tcscpy(pRootDocFileName, pTestChanceDF->GetDocFileName());
  2437. }
  2438. DH_HRCHECK (hr, TEXT("new TCHAR"));
  2439. }
  2440. DH_HRCHECK(hr, TEXT("ChanceDF::GetDocFileName()")) ;
  2441. }
  2442. if(S_OK == hr)
  2443. {
  2444. // Convert RootDocFile name to OLECHAR
  2445. hr = TStringToOleString(pRootDocFileName, &pOleStrTemp);
  2446. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2447. }
  2448. // Try calling StgCreateStorageEx with mode STGM_CREATE|STGM_CONVERT
  2449. DH_TRACE ((DH_LVL_TRACE4,
  2450. TEXT("Try calling StgCreateStorageEx with mode STGM_CREATE|STGM_CONVERT")));
  2451. if (S_OK == hr)
  2452. {
  2453. pIStorage = NULL;
  2454. hr = StgCreateStorageEx(
  2455. pOleStrTemp,
  2456. STGM_CREATE | STGM_CONVERT,
  2457. stgfmt,
  2458. 0,
  2459. NULL,
  2460. NULL,
  2461. IID_IStorage,
  2462. (void**)&pIStorage);
  2463. CheckErrorTest(STG_E_INVALIDFLAG,
  2464. TEXT ("StgCreateStorageEx inv grfMode"),
  2465. pIStorage);
  2466. }
  2467. // Try calling StgCreateStorageEx with grfMode equal to -1
  2468. DH_TRACE ((DH_LVL_TRACE4,
  2469. TEXT ("Try calling StgCreateStorageEx with grfMode equal to -1")));
  2470. if (S_OK == hr)
  2471. {
  2472. pIStorage = NULL;
  2473. hr = StgCreateStorageEx(
  2474. pOleStrTemp,
  2475. (DWORD) -1,
  2476. stgfmt,
  2477. 0,
  2478. NULL,
  2479. NULL,
  2480. IID_IStorage,
  2481. (void**)&pIStorage);
  2482. CheckErrorTest(STG_E_INVALIDFLAG,
  2483. TEXT ("StgCreateStorageEx inv grfMode"),
  2484. pIStorage);
  2485. }
  2486. // Try calling StgCreateStorageEx with stgfmt equal to -1
  2487. DH_TRACE ((DH_LVL_TRACE4,
  2488. TEXT ("Try calling StgCreateStorageEx with stgfmt equal to -1")));
  2489. if (S_OK == hr)
  2490. {
  2491. pIStorage = NULL;
  2492. hr = StgCreateStorageEx(
  2493. pOleStrTemp,
  2494. dwRootMode,
  2495. (DWORD)-1,
  2496. 0,
  2497. NULL,
  2498. NULL,
  2499. IID_IStorage,
  2500. (void**)&pIStorage);
  2501. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2502. TEXT ("StgCreateStorageEx inv stgfmt"),
  2503. pIStorage);
  2504. }
  2505. // Try calling StgCreateStorageEx with gfrAttr equal to -1
  2506. DH_TRACE ((DH_LVL_TRACE4,
  2507. TEXT ("Try calling StgCreateStorageEx with gfrAttr equal to -1")));
  2508. if (S_OK == hr)
  2509. {
  2510. pIStorage = NULL;
  2511. hr = StgCreateStorageEx(
  2512. pOleStrTemp,
  2513. dwRootMode,
  2514. stgfmt,
  2515. (DWORD)-1,
  2516. NULL,
  2517. NULL,
  2518. IID_IStorage,
  2519. (void**)&pIStorage);
  2520. CheckErrorTest(STG_E_INVALIDFLAG,
  2521. TEXT ("StgCreateStorageEx inv grfAttr"),
  2522. pIStorage);
  2523. }
  2524. // Try calling StgCreateStorageEx with nonzero reserved1
  2525. DH_TRACE ((DH_LVL_TRACE4,
  2526. TEXT ("Try calling StgCreateStorageEx with nonzero reserved1")));
  2527. // With 1795 changes to "dwReserved" Parameter to -> version number,
  2528. // sector size (allowed is 512, 4096 only) and reserved parameter as
  2529. // typedef struct tagSTGOPTIONS
  2530. // {
  2531. // USHORT usVersion; // Version 1
  2532. // USHORT reserved; // must be 0 for padding
  2533. // ULONG ulSectorSize; // docfile header sector size (512)
  2534. // } STGOPTIONS;
  2535. STGOPTIONS stgOptions;
  2536. stgOptions.usVersion = 1;
  2537. stgOptions.reserved = 999;
  2538. stgOptions.ulSectorSize = 512;
  2539. if (S_OK == hr)
  2540. {
  2541. pIStorage = NULL;
  2542. hr = StgCreateStorageEx(
  2543. pOleStrTemp,
  2544. dwRootMode,
  2545. stgfmt,
  2546. 0,
  2547. &stgOptions,
  2548. NULL,
  2549. IID_IStorage,
  2550. (void**)&pIStorage);
  2551. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2552. TEXT ("StgCreateStorageEx inv STGOPTIONS dwreserved"),
  2553. pIStorage);
  2554. }
  2555. if (S_OK == hr)
  2556. {
  2557. stgOptions.reserved = 0;
  2558. stgOptions.ulSectorSize = 999; // Allowed is 512 and 4096 only
  2559. pIStorage = NULL;
  2560. hr = StgCreateStorageEx(
  2561. pOleStrTemp,
  2562. dwRootMode,
  2563. stgfmt,
  2564. 0,
  2565. &stgOptions,
  2566. NULL,
  2567. IID_IStorage,
  2568. (void**)&pIStorage);
  2569. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2570. TEXT ("StgCreateStorageEx inv STGOPTIONS ulSectorSize"),
  2571. pIStorage);
  2572. }
  2573. // Try calling StgCreateStorageEx with nonzero reserved2
  2574. DH_TRACE ((DH_LVL_TRACE4,
  2575. TEXT ("Try calling StgCreateStorageEx with nonzero reserved2")));
  2576. if (S_OK == hr)
  2577. {
  2578. stgOptions.ulSectorSize = 512; // Allowed is 512 and 4096 only
  2579. pIStorage = NULL;
  2580. hr = StgCreateStorageEx(
  2581. pOleStrTemp,
  2582. dwRootMode,
  2583. stgfmt,
  2584. 0,
  2585. &stgOptions,
  2586. (void*)999,
  2587. IID_IStorage,
  2588. (void**)&pIStorage);
  2589. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2590. TEXT ("StgCreateStorageEx inv reserved2"),
  2591. pIStorage);
  2592. }
  2593. // Try calling StgCreateStorageEx with invalid IID
  2594. DH_TRACE ((DH_LVL_TRACE4,
  2595. TEXT ("Try calling StgCreateStorageEx with invalid IID")));
  2596. if (S_OK == hr)
  2597. {
  2598. pIStorage = NULL;
  2599. hr = StgCreateStorageEx(
  2600. pOleStrTemp,
  2601. dwRootMode,
  2602. stgfmt,
  2603. 0,
  2604. &stgOptions,
  2605. NULL,
  2606. clsidBogus,
  2607. (void**)&pIStorage);
  2608. CheckErrorTest(E_NOINTERFACE,
  2609. TEXT ("StgCreateStorageEx inv riid"),
  2610. pIStorage);
  2611. }
  2612. // Try calling StgCreateStorageEx with NULL ppstgOpen parameter
  2613. DH_TRACE ((DH_LVL_TRACE4,
  2614. TEXT ("Try calling StgCreateStorageEx with NULL ppstgOpen parameter")));
  2615. if (S_OK == hr)
  2616. {
  2617. hr = StgCreateStorageEx(
  2618. pOleStrTemp,
  2619. dwRootMode,
  2620. stgfmt,
  2621. 0,
  2622. &stgOptions,
  2623. NULL,
  2624. IID_IStorage,
  2625. NULL);
  2626. CheckErrorTest2(STG_E_INVALIDPOINTER,
  2627. TEXT ("StgCreateStorageEx NULL ppstg"));
  2628. }
  2629. // Now create a valid DocFile
  2630. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  2631. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  2632. // and VirtualStmNodes.
  2633. if (S_OK == hr)
  2634. {
  2635. pTestVirtualDF = new VirtualDF(STGTYPE_NSSFILE);
  2636. if(NULL == pTestVirtualDF)
  2637. {
  2638. hr = E_OUTOFMEMORY;
  2639. }
  2640. DH_HRCHECK (hr, TEXT("new VirtualDF"));
  2641. }
  2642. if (S_OK == hr)
  2643. {
  2644. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  2645. DH_HRCHECK(hr, TEXT("VirtualDF::GenerateVirtualDF")) ;
  2646. }
  2647. // Try commiting with grfCommitFlags = -1
  2648. DH_TRACE ((DH_LVL_TRACE4,
  2649. TEXT ("Try commiting with grfCommitFlags = -1")));
  2650. if (S_OK == hr)
  2651. {
  2652. hr = pVirtualDFRoot->Commit((DWORD) -1);
  2653. CheckErrorTest2(STG_E_INVALIDFLAG,
  2654. TEXT("VirtualCtrNode::Commit inv flags"));
  2655. }
  2656. // Now do a valid commit
  2657. if (S_OK == hr)
  2658. {
  2659. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  2660. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  2661. }
  2662. // Close the root docfile
  2663. if (NULL != pVirtualDFRoot)
  2664. {
  2665. hr2 = pVirtualDFRoot->Close();
  2666. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  2667. hr = FirstError (hr, hr2);
  2668. }
  2669. // Instantiate DocFile with name as ""
  2670. // NOTE: The old test checked the erro value to be STG_E_FILENOTFOUND in
  2671. // this case. On NT, we get STG_E_PATHNOTFOUND and on Chicago, we get
  2672. // STG_E_ACCESSDENIED, so let us check against S_OK itself.
  2673. DH_TRACE ((DH_LVL_TRACE4,
  2674. TEXT ("Instantiate DocFile with name as ' '")));
  2675. if (S_OK == hr)
  2676. {
  2677. pIStorageOpen = NULL;
  2678. hr = StgOpenStorageEx(
  2679. (OLECHAR *) " ",
  2680. dwRootMode,
  2681. stgfmt,
  2682. 0,
  2683. NULL,
  2684. NULL,
  2685. IID_IStorage,
  2686. (void**)&pIStorageOpen);
  2687. //BUGBUG: what exactly are we expecting failure code?
  2688. if (RunningOnNT())
  2689. {
  2690. // HACKHACK: dont know exactly what the OS will return here.....
  2691. if (STG_E_PATHNOTFOUND == hr ||
  2692. STG_E_FILENOTFOUND == hr ||
  2693. STG_E_INVALIDNAME == hr)
  2694. {
  2695. DH_TRACE ((DH_LVL_TRACE2, TEXT("Actual return value:hr=%#x"), hr));
  2696. hr = STG_E_PATHNOTFOUND;
  2697. }
  2698. CheckErrorTest(STG_E_PATHNOTFOUND,
  2699. TEXT ("StgOpenStorageEx inv name"),
  2700. pIStorageOpen);
  2701. }
  2702. else
  2703. {
  2704. CheckErrorTest(STG_E_ACCESSDENIED,
  2705. TEXT ("StgOpenStorageEx inv name"),
  2706. pIStorageOpen);
  2707. }
  2708. }
  2709. // Instantiate DocFile with nonexisting file name
  2710. if(S_OK == hr)
  2711. {
  2712. // Convert tszTestName to OLECHAR
  2713. hr = TStringToOleString(tszTestName, &pOleStrTest);
  2714. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2715. }
  2716. DH_TRACE ((DH_LVL_TRACE4,
  2717. TEXT ("Instantiate DocFile with nonexisting file name")));
  2718. if (S_OK == hr)
  2719. {
  2720. pIStorageOpen = NULL;
  2721. hr = StgOpenStorageEx(
  2722. pOleStrTest,
  2723. dwRootMode,
  2724. stgfmt,
  2725. 0,
  2726. NULL,
  2727. NULL,
  2728. IID_IStorage,
  2729. (void**)&pIStorageOpen);
  2730. CheckErrorTest(STG_E_FILENOTFOUND,
  2731. TEXT ("StgOpenStorageEx bad name"),
  2732. pIStorageOpen);
  2733. }
  2734. // Instantiate DocFile with NULL file name
  2735. DH_TRACE ((DH_LVL_TRACE4,
  2736. TEXT ("Instantiate DocFile with NULL file name")));
  2737. if (S_OK == hr)
  2738. {
  2739. pIStorageOpen = NULL;
  2740. hr = StgOpenStorageEx(
  2741. NULL,
  2742. dwRootMode,
  2743. stgfmt,
  2744. 0,
  2745. NULL,
  2746. NULL,
  2747. IID_IStorage,
  2748. (void**)&pIStorageOpen);
  2749. CheckErrorTest(STG_E_INVALIDNAME,
  2750. TEXT ("StgOpenStorageEx NULL name"),
  2751. pIStorageOpen);
  2752. }
  2753. // Instantiate DocFile with grfMode=-1
  2754. DH_TRACE ((DH_LVL_TRACE4,
  2755. TEXT ("Instantiate DocFile with grfMode=-1")));
  2756. if (S_OK == hr)
  2757. {
  2758. pIStorageOpen = NULL;
  2759. hr = StgOpenStorageEx(
  2760. pOleStrTemp,
  2761. (DWORD) -1,
  2762. stgfmt,
  2763. 0,
  2764. NULL,
  2765. NULL,
  2766. IID_IStorage,
  2767. (void**)&pIStorageOpen);
  2768. CheckErrorTest(STG_E_INVALIDFLAG,
  2769. TEXT ("StgOpenStorageEx inv grfMode"),
  2770. pIStorageOpen);
  2771. }
  2772. // Instantiate DocFile with grfMode as dwRootMode|STGM_DELETEONRELEASE
  2773. // NOTE: The doc says, erro code in this case to be STG_E_INVALIDFUNCTION,
  2774. // but error STG_E_INVALIDFLAG returned.
  2775. DH_TRACE ((DH_LVL_TRACE4,
  2776. TEXT ("Instantiate DocFile with grfMode as dwRootMode|STGM_DELETEONRELEASE")));
  2777. if (S_OK == hr)
  2778. {
  2779. pIStorageOpen = NULL;
  2780. hr = StgOpenStorageEx(
  2781. pOleStrTemp,
  2782. dwRootMode | STGM_DELETEONRELEASE,
  2783. stgfmt,
  2784. 0,
  2785. NULL,
  2786. NULL,
  2787. IID_IStorage,
  2788. (void**)&pIStorageOpen);
  2789. CheckErrorTest(STG_E_INVALIDFUNCTION,
  2790. TEXT ("StgOpenStorageEx inv grfMode"),
  2791. pIStorageOpen);
  2792. }
  2793. // Instantiate DocFile with stgfmt=-1
  2794. DH_TRACE ((DH_LVL_TRACE4,
  2795. TEXT ("Instantiate DocFile with stgfmt=-1")));
  2796. if (S_OK == hr)
  2797. {
  2798. pIStorageOpen = NULL;
  2799. hr = StgOpenStorageEx(
  2800. pOleStrTemp,
  2801. dwRootMode,
  2802. (DWORD)-1,
  2803. 0,
  2804. NULL,
  2805. NULL,
  2806. IID_IStorage,
  2807. (void**)&pIStorageOpen);
  2808. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2809. TEXT ("StgOpenStorageEx inv stgfmt"),
  2810. pIStorageOpen);
  2811. }
  2812. // Instantiate docfile with grfAttr == -1
  2813. DH_TRACE ((DH_LVL_TRACE4,
  2814. TEXT ("Instantiate docfile with grfAttr == -1")));
  2815. if (S_OK == hr)
  2816. {
  2817. pIStorageOpen = NULL;
  2818. hr = StgOpenStorageEx(
  2819. pOleStrTemp,
  2820. dwRootMode,
  2821. stgfmt,
  2822. (DWORD)-1,
  2823. NULL,
  2824. NULL,
  2825. IID_IStorage,
  2826. (void**)&pIStorageOpen);
  2827. CheckErrorTest(STG_E_INVALIDFLAG,
  2828. TEXT ("StgOpenStorageEx inv grfAttr"),
  2829. pIStorageOpen);
  2830. }
  2831. // Instantiate docfile with pTransaction == -1
  2832. DH_TRACE ((DH_LVL_TRACE4,
  2833. TEXT ("Instantiate docfile with reserved1 (pTransaction) == -1")));
  2834. if (S_OK == hr)
  2835. {
  2836. stgOptions.reserved = (USHORT)(-1);
  2837. pIStorageOpen = NULL;
  2838. hr = StgOpenStorageEx(
  2839. pOleStrTemp,
  2840. dwRootMode,
  2841. stgfmt,
  2842. 0,
  2843. &stgOptions,
  2844. NULL,
  2845. IID_IStorage,
  2846. (void**)&pIStorageOpen);
  2847. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2848. TEXT ("StgOpenStorageEx inv reserved1"),
  2849. pIStorageOpen);
  2850. }
  2851. // Instantiate docfile with pSecurity == -1
  2852. DH_TRACE ((DH_LVL_TRACE4,
  2853. TEXT ("Instantiate docfile with reserved2 (pSecurity) == -1")));
  2854. if (S_OK == hr)
  2855. {
  2856. stgOptions.reserved = 0;
  2857. pIStorageOpen = NULL;
  2858. hr = StgOpenStorageEx(
  2859. pOleStrTemp,
  2860. dwRootMode,
  2861. stgfmt,
  2862. 0,
  2863. NULL,
  2864. (void*)-1,
  2865. IID_IStorage,
  2866. (void**)&pIStorageOpen);
  2867. CheckErrorTest(STG_E_INVALIDPARAMETER,
  2868. TEXT ("StgOpenStorageEx inv reserved2"),
  2869. pIStorageOpen);
  2870. }
  2871. // Instantiate docfile with bogus refiid
  2872. DH_TRACE ((DH_LVL_TRACE4,
  2873. TEXT ("Instantiate docfile with bogus refiid")));
  2874. if (S_OK == hr)
  2875. {
  2876. pIStorageOpen = NULL;
  2877. hr = StgOpenStorageEx(
  2878. pOleStrTemp,
  2879. dwRootMode,
  2880. stgfmt,
  2881. 0,
  2882. NULL,
  2883. NULL,
  2884. clsidBogus,
  2885. (void**)&pIStorageOpen);
  2886. // ----------- flatfile change ---------------
  2887. if(!StorageIsFlat())
  2888. {
  2889. // ----------- flatfile change ---------------
  2890. CheckErrorTest(E_NOINTERFACE,
  2891. TEXT ("StgOpenStorageEx inv riid"),
  2892. pIStorageOpen);
  2893. }
  2894. else
  2895. {
  2896. CheckErrorTest(STG_E_INVALIDFUNCTION,
  2897. TEXT ("StgOpenStorageEx of a docfile with inv riid"),
  2898. pIStorageOpen);
  2899. } // ----------- flatfile change ---------------
  2900. }
  2901. // Instantiate DocFile with NULL ppstgOpen parameter (8th)
  2902. DH_TRACE ((DH_LVL_TRACE4,
  2903. TEXT ("Instantiate DocFile with NULL ppstgOpen parameter")));
  2904. if (S_OK == hr)
  2905. {
  2906. hr = StgOpenStorageEx(
  2907. pOleStrTest,
  2908. dwRootMode,
  2909. stgfmt,
  2910. 0,
  2911. NULL,
  2912. NULL,
  2913. IID_IStorage,
  2914. NULL);
  2915. CheckErrorTest2(STG_E_INVALIDPOINTER,
  2916. TEXT ("StgOpenStorageEx NULL ppstg"));
  2917. }
  2918. // Instatiate correctly.
  2919. DH_TRACE ((DH_LVL_TRACE4,
  2920. TEXT ("Instantiate DocFile")));
  2921. if (S_OK == hr)
  2922. {
  2923. pIStorageOpen = NULL;
  2924. hr = StgOpenStorageEx(
  2925. pOleStrTemp,
  2926. dwRootMode,
  2927. stgfmt,
  2928. 0,
  2929. NULL,
  2930. NULL,
  2931. IID_IStorage,
  2932. (void**)&pIStorageOpen);
  2933. // ----------- flatfile change ---------------
  2934. if(StorageIsFlat())
  2935. {
  2936. CheckErrorTest(STG_E_INVALIDFUNCTION,
  2937. TEXT ("StgOpenStorageEx -opening docfile as flatfile"),
  2938. pIStorageOpen);
  2939. }
  2940. // ----------- flatfile change ---------------
  2941. DH_HRCHECK (hr, TEXT("StgOpenStorageEx"));
  2942. // close it.
  2943. if (NULL != pIStorageOpen)
  2944. {
  2945. ulRef = pIStorageOpen->Release();
  2946. DH_ASSERT (0 == ulRef);
  2947. pIStorageOpen = NULL;
  2948. }
  2949. }
  2950. // if something did not pass, mark test (hr) as E_FAIL
  2951. if (FALSE == fPass)
  2952. {
  2953. hr = FirstError (hr, E_FAIL);
  2954. }
  2955. // if everything goes well, log test as passed else failed.
  2956. if ((S_OK == hr) && (TRUE == fPass))
  2957. {
  2958. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_200 passed.")) );
  2959. }
  2960. else
  2961. {
  2962. DH_LOG((LOG_FAIL,
  2963. TEXT("Test variation APITEST_200 failed; hr=%#lx; fPass=%d."),
  2964. hr,
  2965. fPass));
  2966. }
  2967. // Cleanup
  2968. // Delete Chance docfile tree
  2969. if(NULL != pTestChanceDF)
  2970. {
  2971. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  2972. pTestChanceDF->GetChanceDFRoot());
  2973. DH_HRCHECK(hr2, TEXT("ChanceDF::DeleteChanceFileDocTree")) ;
  2974. delete pTestChanceDF;
  2975. pTestChanceDF = NULL;
  2976. }
  2977. // Delete Virtual docfile tree
  2978. if(NULL != pTestVirtualDF)
  2979. {
  2980. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  2981. DH_HRCHECK(hr2, TEXT("VirtualDF::DeleteVirtualFileDocTree")) ;
  2982. delete pTestVirtualDF;
  2983. pTestVirtualDF = NULL;
  2984. }
  2985. // Delete the docfile on disk
  2986. if((S_OK == hr) && (NULL != pRootDocFileName))
  2987. {
  2988. if(FALSE == DeleteFile(pRootDocFileName))
  2989. {
  2990. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2991. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2992. }
  2993. }
  2994. // Delete temp strings
  2995. if(NULL != pOleStrTemp)
  2996. {
  2997. delete []pOleStrTemp;
  2998. pOleStrTemp = NULL;
  2999. }
  3000. if(NULL != pOleStrTest)
  3001. {
  3002. delete []pOleStrTest;
  3003. pOleStrTest = NULL;
  3004. }
  3005. if(NULL != pRootDocFileName)
  3006. {
  3007. delete []pRootDocFileName;
  3008. pRootDocFileName = NULL;
  3009. }
  3010. // Stop logging the test
  3011. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_200 finished")) );
  3012. return hr;
  3013. }
  3014. //----------------------------------------------------------------------------
  3015. //
  3016. // Test: APITEST_201
  3017. //
  3018. // Synopsis: The test attempts various illegitimate operations using names
  3019. // greater than MAX_STG_NAME_LEN, it then attempts to create
  3020. // several random named root docfiles. If the create is succesful,
  3021. // then a random named child IStorage or IStream is also created.
  3022. // Whether or not the root create was successful, we attempt to
  3023. // open the root docfile (this is expected to fail, the point is
  3024. // to check for asserts/GP faults rather than return codes). If
  3025. // the instantiation is successful, the test also tries to
  3026. // instantiate the child object. All objects are then released.
  3027. //
  3028. // Arguments:[argc]
  3029. // [argv]
  3030. //
  3031. // Returns: HRESULT
  3032. //
  3033. // History: 18-June-1996 NarindK Created.
  3034. //
  3035. // Notes: This test runs in direct, transacted, and transacted deny write
  3036. // modes
  3037. //
  3038. // New Test Notes:
  3039. // 1. Old File: IANAMES.CXX
  3040. // 2. Old name of test : IllegitAPINames test
  3041. // New Name of test : APITEST_201
  3042. // 3. To run the test, do the following at command prompt.
  3043. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-201
  3044. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  3045. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-201
  3046. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3047. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-201
  3048. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3049. //
  3050. // BUGNOTE: Conversion: APITEST-201 NO
  3051. //
  3052. //-----------------------------------------------------------------------------
  3053. HRESULT APITEST_201(int argc, char *argv[])
  3054. {
  3055. HRESULT hr = S_OK;
  3056. HRESULT hr2 = S_OK;
  3057. ChanceDF *pTestChanceDF = NULL;
  3058. VirtualDF *pTestVirtualDF = NULL;
  3059. VirtualCtrNode *pVirtualDFRoot = NULL;
  3060. LPTSTR pFileName = NULL;
  3061. LPOLESTR poszBadName = NULL;
  3062. LPOLESTR poszBadNameStg = NULL;
  3063. LPTSTR ptszBadNameStg = NULL;
  3064. DWORD dwRootMode = 0;
  3065. ULONG i = 0;
  3066. LPSTORAGE pIStorage = NULL;
  3067. LPSTORAGE pIStorageChild = NULL;
  3068. LPSTREAM pIStreamChild = NULL;
  3069. DG_STRING *pdgu = NULL;
  3070. DG_INTEGER *pdgi = NULL;
  3071. LPTSTR pRootNewChildStgName = NULL;
  3072. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  3073. BOOL fPass = TRUE;
  3074. DWORD stgfmt = StorageIsFlat()?STGFMT_FILE:0;
  3075. // Not for 2phase. Bail.
  3076. if (DoingDistrib ())
  3077. {
  3078. return S_OK;
  3079. }
  3080. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_201"));
  3081. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_201 started.")) );
  3082. DH_TRACE((DH_LVL_ALWAYS,
  3083. TEXT("Call StgCreateDocFile/CreateStorage/CreateStream with ")
  3084. TEXT("too long names.")));
  3085. // Create the new ChanceDocFile tree that would consist of chance nodes.
  3086. if (S_OK == hr)
  3087. {
  3088. pTestChanceDF = new ChanceDF();
  3089. if(NULL == pTestChanceDF)
  3090. {
  3091. hr = E_OUTOFMEMORY;
  3092. }
  3093. DH_HRCHECK (hr, TEXT("new ChanceDF"));
  3094. }
  3095. if (S_OK == hr)
  3096. {
  3097. hr = pTestChanceDF->CreateFromParams(argc, argv);
  3098. DH_HRCHECK(hr, TEXT("ChanceDF::CreateFromParams")) ;
  3099. }
  3100. if (S_OK == hr)
  3101. {
  3102. dwRootMode = pTestChanceDF->GetRootMode();
  3103. DH_TRACE((
  3104. DH_LVL_TRACE1,
  3105. TEXT("Run Mode for APITEST_201, Access mode: %lx"),
  3106. pTestChanceDF->GetRootMode()));
  3107. }
  3108. // Call StgCreateDocFile with too long a name for docfile.
  3109. // NOTE: Old test to fail with MAX_STG_NAME_LEN*3, but not in new test,
  3110. // fails with MAX_STG_NAME_LEN*4.
  3111. // NOTE: Crashes in DfFromName in OLE if length is of MAX_STG_NAME_LEN*8
  3112. // CHECK!!!
  3113. if(S_OK == hr)
  3114. {
  3115. poszBadName = (OLECHAR *) new OLECHAR [MAX_STG_NAME_LEN*4];
  3116. if (NULL == poszBadName)
  3117. {
  3118. hr = E_OUTOFMEMORY;
  3119. }
  3120. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  3121. }
  3122. if(S_OK == hr)
  3123. {
  3124. for (i=0; i<( MAX_STG_NAME_LEN*4 -1); i++)
  3125. {
  3126. poszBadName[i] = 'X';
  3127. }
  3128. poszBadName[i] ='\0';
  3129. }
  3130. // Try calling StgCreateDocFile with the above long name pszBadName
  3131. if (S_OK == hr)
  3132. {
  3133. pIStorage = NULL;
  3134. hr = StgCreateStorageEx(
  3135. poszBadName,
  3136. dwRootMode | STGM_CREATE,
  3137. stgfmt,
  3138. 0,
  3139. NULL,
  3140. NULL,
  3141. IID_IStorage,
  3142. (void**)&pIStorage);
  3143. // HACKHACK: dont know exactly what the OS will return here.....
  3144. if (STG_E_PATHNOTFOUND == hr ||
  3145. STG_E_FILENOTFOUND == hr ||
  3146. STG_E_INVALIDNAME == hr)
  3147. {
  3148. DH_TRACE ((DH_LVL_TRACE2, TEXT("Actual return value:hr=%#x"), hr));
  3149. hr = STG_E_PATHNOTFOUND;
  3150. }
  3151. CheckErrorTest(STG_E_PATHNOTFOUND,
  3152. TEXT ("StgCreateStorageEx inv name"),
  3153. pIStorage);
  3154. }
  3155. // Now create a valid DocFile
  3156. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  3157. // the previous step.
  3158. if (S_OK == hr)
  3159. {
  3160. pTestVirtualDF = new VirtualDF(STGTYPE_NSSFILE);
  3161. if(NULL == pTestVirtualDF)
  3162. {
  3163. hr = E_OUTOFMEMORY;
  3164. }
  3165. DH_HRCHECK (hr, TEXT("new VirtualDF"));
  3166. }
  3167. if (S_OK == hr)
  3168. {
  3169. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  3170. DH_HRCHECK(hr, TEXT("VirtualDF::GenerateVirtualDF")) ;
  3171. }
  3172. // Get IStorage pointer
  3173. if (S_OK == hr)
  3174. {
  3175. pIStorage = pVirtualDFRoot->GetIStoragePointer();
  3176. DH_ASSERT (NULL != pIStorage);
  3177. if (NULL == pIStorage)
  3178. {
  3179. hr = E_FAIL;
  3180. }
  3181. }
  3182. // Call CreateStorage with too long a name for docfile.
  3183. if(S_OK == hr)
  3184. {
  3185. ptszBadNameStg = (TCHAR *) new TCHAR [MAX_STG_NAME_LEN*3];
  3186. if (NULL == ptszBadNameStg)
  3187. {
  3188. hr = E_OUTOFMEMORY;
  3189. }
  3190. DH_HRCHECK (hr, TEXT("new TCHAR"));
  3191. }
  3192. if(S_OK == hr)
  3193. {
  3194. for (i=0; i<( MAX_STG_NAME_LEN*3 -1); i++)
  3195. {
  3196. ptszBadNameStg[i] = 'X';
  3197. }
  3198. ptszBadNameStg[i] ='\0';
  3199. }
  3200. if(S_OK == hr)
  3201. {
  3202. // Convert Bad storage name to OLECHAR
  3203. hr = TStringToOleString(ptszBadNameStg, &poszBadNameStg);
  3204. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3205. }
  3206. // ----------- flatfile change ---------------
  3207. if(!StorageIsFlat())
  3208. {
  3209. // ----------- flatfile change ---------------
  3210. // now call CreateStorage with too long a name...
  3211. if (S_OK == hr)
  3212. {
  3213. hr = pIStorage->CreateStorage(
  3214. poszBadNameStg,
  3215. pTestChanceDF->GetStgMode(),
  3216. 0,
  3217. 0,
  3218. &pIStorageChild);
  3219. CheckErrorTest(STG_E_INVALIDNAME,
  3220. TEXT ("IStorage::CreateStorage long name"),
  3221. pIStorageChild);
  3222. }
  3223. // ----------- flatfile change ---------------
  3224. }
  3225. // ----------- flatfile change ---------------
  3226. // Now call CreateStream with too long a name...
  3227. if (S_OK == hr)
  3228. {
  3229. hr = pIStorage->CreateStream(
  3230. poszBadNameStg,
  3231. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3232. 0,
  3233. 0,
  3234. &pIStreamChild);
  3235. CheckErrorTest(STG_E_INVALIDNAME,
  3236. TEXT ("IStorage::CreateStream long name"),
  3237. pIStreamChild);
  3238. }
  3239. // Now add a Valid storage to root. Call AddStorage that in turns calls
  3240. // CreateStorage
  3241. if (S_OK == hr)
  3242. {
  3243. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3244. DH_ASSERT (NULL != pdgu);
  3245. if (NULL == pdgu)
  3246. {
  3247. hr = E_FAIL;
  3248. }
  3249. }
  3250. // ----------- flatfile change ---------------
  3251. if(!StorageIsFlat())
  3252. {
  3253. // ----------- flatfile change ---------------
  3254. if(S_OK == hr)
  3255. {
  3256. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  3257. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3258. }
  3259. // Adds a new storage to the root storage.
  3260. if(S_OK == hr)
  3261. {
  3262. hr = AddStorage(
  3263. pTestVirtualDF,
  3264. pVirtualDFRoot,
  3265. pRootNewChildStgName,
  3266. pTestChanceDF->GetStgMode() | STGM_CREATE | STGM_FAILIFTHERE,
  3267. &pvcnRootNewChildStorage);
  3268. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  3269. }
  3270. // Now try to rename this storage element to a bad name.
  3271. if(S_OK == hr)
  3272. {
  3273. DH_EXPECTEDERROR (STG_E_INVALIDNAME);
  3274. hr = pvcnRootNewChildStorage->Rename(ptszBadNameStg);
  3275. DH_NOEXPECTEDERROR ();
  3276. CheckErrorTest2(STG_E_INVALIDNAME,
  3277. TEXT ("VirtualCtrNode::Rename inv name"));
  3278. }
  3279. // Close the Storage pvcnRootNewChildStorage
  3280. if (S_OK == hr)
  3281. {
  3282. hr = pvcnRootNewChildStorage->Close();
  3283. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Close"));
  3284. }
  3285. // ----------- flatfile change ---------------
  3286. }
  3287. // ----------- flatfile change ---------------
  3288. // Close the root docfile
  3289. if (NULL != pVirtualDFRoot)
  3290. {
  3291. hr = pVirtualDFRoot->Close();
  3292. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Close"));
  3293. }
  3294. // Delete temp strings
  3295. if(NULL != poszBadNameStg)
  3296. {
  3297. delete [] poszBadNameStg;
  3298. poszBadNameStg = NULL;
  3299. }
  3300. if(NULL != poszBadName)
  3301. {
  3302. delete [] poszBadName;
  3303. poszBadName = NULL;
  3304. }
  3305. if(NULL != ptszBadNameStg)
  3306. {
  3307. delete [] ptszBadNameStg;
  3308. ptszBadNameStg = NULL;
  3309. }
  3310. if(NULL != pRootNewChildStgName)
  3311. {
  3312. delete [] pRootNewChildStgName;
  3313. pRootNewChildStgName = NULL;
  3314. }
  3315. // In the following section of test:
  3316. //make a random number of random length, random character root
  3317. //docfiles. for this variation, we don't care if the operation
  3318. //succeeds, looking for GP faults and asserts only. if the
  3319. //StgCreateDocfile fails, we'll still attempt the open. of
  3320. //course, the open in this case will be expected to fail, but
  3321. //again, we won't be checking return codes... If the StgCreateDocfile
  3322. //passes, we'll create a random name IStream or IStorage too.
  3323. ULONG count = 0;
  3324. ULONG cMinNum = 16;
  3325. ULONG cMaxNum = 128;
  3326. LPTSTR ptszRandomRootName = NULL;
  3327. LPTSTR ptszRandomChildName = NULL;
  3328. ULONG countFlag = 0;
  3329. ULONG cMinFlag = 0;
  3330. ULONG cMaxFlag = 100;
  3331. ULONG nChildType = 0;
  3332. LPSTORAGE pstgRoot = NULL;
  3333. LPSTORAGE pstgChild = NULL;
  3334. LPSTREAM pstmChild = NULL;
  3335. LPOLESTR poszRandomRootName = NULL;
  3336. LPOLESTR poszRandomChildName = NULL;
  3337. ULONG ulRef = 0;
  3338. if (S_OK == hr)
  3339. {
  3340. pdgi = pTestVirtualDF->GetDataGenInteger();
  3341. DH_ASSERT (NULL != pdgi);
  3342. if (NULL == pdgi)
  3343. {
  3344. hr = E_FAIL;
  3345. }
  3346. }
  3347. if(S_OK == hr)
  3348. {
  3349. hr = pdgi->Generate(&count, cMinNum, cMaxNum);
  3350. DH_HRCHECK(hr, TEXT("pdgi::Generate")) ;
  3351. }
  3352. while(count--)
  3353. {
  3354. if(S_OK == hr)
  3355. {
  3356. hr=GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszRandomRootName);
  3357. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3358. }
  3359. if(S_OK == hr)
  3360. {
  3361. // Convert name to OLECHAR
  3362. hr = TStringToOleString(ptszRandomRootName, &poszRandomRootName);
  3363. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3364. }
  3365. if (S_OK == hr)
  3366. {
  3367. pstgRoot = NULL;
  3368. hr = StgCreateStorageEx(
  3369. poszRandomRootName,
  3370. dwRootMode | STGM_CREATE,
  3371. stgfmt,
  3372. 0,
  3373. NULL,
  3374. NULL,
  3375. IID_IStorage,
  3376. (void**)&pstgRoot);
  3377. DH_HRCHECK (hr, TEXT("StgCreateStorageEx"));
  3378. }
  3379. nChildType = NONE;
  3380. if(S_OK == hr)
  3381. {
  3382. if(S_OK == hr)
  3383. {
  3384. hr=GenerateRandomName(
  3385. pdgu,
  3386. MINLENGTH,
  3387. MAXLENGTH,
  3388. &ptszRandomChildName);
  3389. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3390. }
  3391. if(S_OK == hr)
  3392. {
  3393. // Convert name to OLECHAR
  3394. hr = TStringToOleString(
  3395. ptszRandomChildName,
  3396. &poszRandomChildName);
  3397. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  3398. }
  3399. if(S_OK == hr)
  3400. {
  3401. hr = pdgi->Generate(&countFlag, cMinFlag, cMaxFlag);
  3402. DH_HRCHECK(hr, TEXT("pdgi::Generate")) ;
  3403. }
  3404. if(!StorageIsFlat() && countFlag > (cMaxFlag/2))
  3405. {
  3406. hr = pstgRoot->CreateStorage(
  3407. poszRandomChildName,
  3408. pTestChanceDF->GetStgMode(),
  3409. 0,
  3410. 0,
  3411. &pstgChild);
  3412. DH_HRCHECK(hr, TEXT("IStorage::CreateStorage"));
  3413. if(S_OK == hr)
  3414. {
  3415. nChildType = STORAGE;
  3416. hr = pstgRoot->Commit(STGC_DEFAULT);
  3417. DH_HRCHECK(hr, TEXT("IStorage::Commit"));
  3418. ulRef = pstgChild->Release();
  3419. DH_ASSERT (0 == ulRef);
  3420. pstgChild = NULL;
  3421. }
  3422. }
  3423. else
  3424. {
  3425. hr = pstgRoot->CreateStream(
  3426. poszRandomChildName,
  3427. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  3428. 0,
  3429. 0,
  3430. &pstmChild);
  3431. DH_HRCHECK(hr, TEXT("IStorage::CreateStream"));
  3432. if(S_OK == hr)
  3433. {
  3434. nChildType = STREAM;
  3435. hr = pstgRoot->Commit(STGC_DEFAULT);
  3436. DH_HRCHECK(hr, TEXT("IStorage::Commit"));
  3437. ulRef = pstmChild->Release();
  3438. DH_ASSERT (0 == ulRef);
  3439. pstmChild = NULL;
  3440. }
  3441. }
  3442. ulRef = pstgRoot->Release();
  3443. DH_ASSERT (0 == ulRef);
  3444. pstgRoot = NULL;
  3445. }
  3446. //Try to open Root Storage whetehr the creation was successful or not
  3447. hr = StgOpenStorageEx(
  3448. poszRandomRootName,
  3449. pTestChanceDF->GetStgMode(),
  3450. stgfmt,
  3451. 0,
  3452. NULL,
  3453. NULL,
  3454. IID_IStorage,
  3455. (void**)&pstgRoot);
  3456. DH_HRCHECK (hr, TEXT("StgOpenStorageEx"));
  3457. if(S_OK == hr)
  3458. {
  3459. switch(nChildType)
  3460. {
  3461. case STORAGE:
  3462. {
  3463. hr = pstgRoot->OpenStorage(
  3464. poszRandomChildName,
  3465. NULL,
  3466. pTestChanceDF->GetStgMode(),
  3467. NULL,
  3468. 0,
  3469. &pstgChild);
  3470. DH_HRCHECK(hr, TEXT("IStorage::OpenStorage"));
  3471. if(S_OK == hr)
  3472. {
  3473. ulRef = pstgChild->Release();
  3474. DH_ASSERT (0 == ulRef);
  3475. pstgChild = NULL;
  3476. }
  3477. }
  3478. break;
  3479. case STREAM:
  3480. {
  3481. hr = pstgRoot->OpenStream(
  3482. poszRandomChildName,
  3483. NULL,
  3484. STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
  3485. 0,
  3486. &pstmChild);
  3487. DH_HRCHECK(hr, TEXT("IStorage::OpenStream"));
  3488. if(S_OK == hr)
  3489. {
  3490. ulRef = pstmChild->Release();
  3491. DH_ASSERT (0 == ulRef);
  3492. pstmChild = NULL;
  3493. }
  3494. }
  3495. break;
  3496. } /* switch */
  3497. ulRef = pstgRoot->Release();
  3498. DH_ASSERT (0 == ulRef);
  3499. pstgRoot = NULL;
  3500. }
  3501. // Delete temp strings
  3502. if(NULL != ptszRandomChildName)
  3503. {
  3504. delete [] ptszRandomChildName;
  3505. ptszRandomChildName = NULL;
  3506. }
  3507. if(NULL != ptszRandomRootName)
  3508. {
  3509. if(FALSE == DeleteFile(ptszRandomRootName))
  3510. {
  3511. hr = HRESULT_FROM_WIN32(GetLastError()) ;
  3512. DH_HRCHECK(hr, TEXT("DeleteFile")) ;
  3513. }
  3514. delete [] ptszRandomRootName;
  3515. ptszRandomRootName = NULL;
  3516. }
  3517. if(NULL != poszRandomChildName)
  3518. {
  3519. delete [] poszRandomChildName;
  3520. poszRandomChildName = NULL;
  3521. }
  3522. if(NULL != poszRandomChildName)
  3523. {
  3524. delete [] poszRandomChildName;
  3525. poszRandomChildName = NULL;
  3526. }
  3527. }
  3528. // if something did not pass, mark test (hr) as E_FAIL
  3529. if (FALSE == fPass)
  3530. {
  3531. hr = FirstError (hr, E_FAIL);
  3532. }
  3533. // if everything goes well, log test as passed else failed.
  3534. if ((S_OK == hr) && (TRUE == fPass))
  3535. {
  3536. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_201 passed.")) );
  3537. }
  3538. else
  3539. {
  3540. DH_LOG((LOG_FAIL,
  3541. TEXT("Test variation APITEST_201 failed; hr=%#lx; fPass=%d."),
  3542. hr,
  3543. fPass));
  3544. }
  3545. // Cleanup
  3546. // Get the name of file, will be used later to delete the file
  3547. if(NULL != pTestVirtualDF)
  3548. {
  3549. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  3550. if (pFileName != NULL)
  3551. {
  3552. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  3553. }
  3554. }
  3555. // Delete Chance docfile tree
  3556. if(NULL != pTestChanceDF)
  3557. {
  3558. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  3559. pTestChanceDF->GetChanceDFRoot());
  3560. DH_HRCHECK(hr2, TEXT("ChanceDF::DeleteChanceFileDocTree")) ;
  3561. delete pTestChanceDF;
  3562. pTestChanceDF = NULL;
  3563. }
  3564. // Delete Virtual docfile tree
  3565. if(NULL != pTestVirtualDF)
  3566. {
  3567. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  3568. DH_HRCHECK(hr2, TEXT("VirtualDF::DeleteVirtualFileDocTree")) ;
  3569. delete pTestVirtualDF;
  3570. pTestVirtualDF = NULL;
  3571. }
  3572. // Delete the docfile on disk
  3573. if((S_OK == hr) && (NULL != pFileName))
  3574. {
  3575. if(FALSE == DeleteFile(pFileName))
  3576. {
  3577. hr = HRESULT_FROM_WIN32(GetLastError()) ;
  3578. DH_HRCHECK(hr, TEXT("DeleteFile")) ;
  3579. }
  3580. }
  3581. // Delete temp strings
  3582. if(NULL != pFileName)
  3583. {
  3584. delete []pFileName;
  3585. pFileName = NULL;
  3586. }
  3587. // Stop logging the test
  3588. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_201 finished")) );
  3589. return hr;
  3590. }
  3591. //----------------------------------------------------------------------------
  3592. //
  3593. // Test: APITEST_202
  3594. //
  3595. // Synopsis: Attempts various operations in obtaining enumerators, checking
  3596. // for proper error return. Then gets a valid enumerator, and
  3597. // attempts various illegitimate method calls on it. Verify
  3598. // proper return codes.
  3599. //
  3600. // Arguments:[argc]
  3601. // [argv]
  3602. //
  3603. // Returns: HRESULT
  3604. //
  3605. // History: 18-June-1996 NarindK Created.
  3606. //
  3607. // Notes: This test runs in direct, transacted, and transacted deny write
  3608. // modes
  3609. //
  3610. // New Test Notes:
  3611. // 1. Old File: IAENUM.CXX
  3612. // 2. Old name of test : IllegitAPIEnum test
  3613. // New Name of test : APITEST_202
  3614. // 3. To run the test, do the following at command prompt.
  3615. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-202
  3616. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /labmode
  3617. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-202
  3618. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /labmode
  3619. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-202
  3620. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx /labmode
  3621. //
  3622. // BUGNOTE: Conversion: APITEST_202
  3623. //-----------------------------------------------------------------------------
  3624. HRESULT APITEST_202(int argc, char *argv[])
  3625. {
  3626. HRESULT hr = S_OK;
  3627. HRESULT hr2 = S_OK;
  3628. ChanceDF *pTestChanceDF = NULL;
  3629. VirtualDF *pTestVirtualDF = NULL;
  3630. VirtualCtrNode *pVirtualDFRoot = NULL;
  3631. LPTSTR pRootNewChildStgName = NULL;
  3632. VirtualCtrNode *pvcnRootNewChildStorage= NULL;
  3633. DG_STRING *pdgu = NULL;
  3634. DG_INTEGER *pdgi = NULL;
  3635. LPENUMSTATSTG penumWalk = NULL;
  3636. ULONG cMinNum = 1;
  3637. ULONG cMaxNum = 999;
  3638. DWORD dwReserved1 = 0;
  3639. DWORD dwReserved3 = 0;
  3640. LPTSTR pReserved2 = NULL;
  3641. ULONG ulRef = 0;
  3642. BOOL fPass = TRUE;
  3643. ULONG celtFetched = 0;
  3644. STATSTG statStg;
  3645. LPMALLOC pMalloc = NULL;
  3646. STATSTG *pStatStg = NULL;
  3647. INT cAskMoreThanPresent = 2; // Set to 2 since only 1 substg // added in test
  3648. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_202"));
  3649. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_202 started")) );
  3650. DH_TRACE((DH_LVL_ALWAYS,
  3651. TEXT("Attempt different illegitimate opeations on IEnumSTATSTG")));
  3652. // Create our ChanceDF and VirtualDF
  3653. hr = CreateTestDocfile (argc,
  3654. argv,
  3655. &pVirtualDFRoot,
  3656. &pTestVirtualDF,
  3657. &pTestChanceDF);
  3658. // if creating the docfile - bail here
  3659. if (NULL != pTestChanceDF && DoingCreate ())
  3660. {
  3661. UINT ulSeed = pTestChanceDF->GetSeed ();
  3662. CleanupTestDocfile (&pVirtualDFRoot,
  3663. &pTestVirtualDF,
  3664. &pTestChanceDF,
  3665. FALSE);
  3666. return (HRESULT)ulSeed;
  3667. }
  3668. if (S_OK == hr)
  3669. {
  3670. DH_TRACE((DH_LVL_TRACE1,
  3671. TEXT("Run Mode for APITEST_202, Access mode: %lx"),
  3672. pTestChanceDF->GetRootMode()));
  3673. }
  3674. // Adds a new storage to the root storage.
  3675. if (S_OK == hr)
  3676. {
  3677. pdgu = pTestVirtualDF->GetDataGenUnicode();
  3678. DH_ASSERT (NULL != pdgu);
  3679. if (NULL == pdgu)
  3680. {
  3681. hr = E_FAIL;
  3682. }
  3683. }
  3684. if(S_OK == hr)
  3685. {
  3686. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&pRootNewChildStgName);
  3687. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3688. }
  3689. // ----------- flatfile change ---------------
  3690. if(!StorageIsFlat())
  3691. {
  3692. // ----------- flatfile change ---------------
  3693. if(S_OK == hr)
  3694. {
  3695. hr = AddStorage(
  3696. pTestVirtualDF,
  3697. pVirtualDFRoot,
  3698. pRootNewChildStgName,
  3699. pTestChanceDF->GetStgMode()|
  3700. STGM_CREATE |
  3701. STGM_FAILIFTHERE,
  3702. &pvcnRootNewChildStorage);
  3703. DH_HRCHECK(hr, TEXT("AddStorage")) ;
  3704. }
  3705. // ----------- flatfile change ---------------
  3706. }
  3707. // ----------- flatfile change ---------------
  3708. // BUGBUG: Use Random commit modes...
  3709. if (S_OK == hr)
  3710. {
  3711. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  3712. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  3713. }
  3714. // ----------- flatfile change ---------------
  3715. if(!StorageIsFlat())
  3716. {
  3717. // ----------- flatfile change ---------------
  3718. // Close the Child storage
  3719. if (S_OK == hr)
  3720. {
  3721. hr = pvcnRootNewChildStorage->Close();
  3722. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  3723. }
  3724. // ----------- flatfile change ---------------
  3725. }
  3726. // ----------- flatfile change ---------------
  3727. // Get the random number generator
  3728. if (S_OK == hr)
  3729. {
  3730. pdgi = pTestVirtualDF->GetDataGenInteger();
  3731. DH_ASSERT (NULL != pdgi);
  3732. if (NULL == pdgi)
  3733. {
  3734. hr = E_FAIL;
  3735. }
  3736. }
  3737. if(S_OK == hr)
  3738. {
  3739. hr = pdgi->Generate(&dwReserved1, cMinNum, cMaxNum);
  3740. DH_HRCHECK(hr, TEXT("pdgi::Generate")) ;
  3741. }
  3742. if(S_OK == hr)
  3743. {
  3744. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  3745. hr = pVirtualDFRoot->EnumElements(
  3746. dwReserved1,
  3747. pReserved2,
  3748. dwReserved3,
  3749. &penumWalk);
  3750. DH_NOEXPECTEDERROR ();
  3751. CheckErrorTest(STG_E_INVALIDPARAMETER,
  3752. TEXT ("VirtualCtrNode::EnumElements inv dwReserved1"),
  3753. penumWalk);
  3754. }
  3755. if(S_OK == hr)
  3756. {
  3757. hr = pdgi->Generate(&dwReserved3, cMinNum, cMaxNum);
  3758. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  3759. }
  3760. if(S_OK == hr)
  3761. {
  3762. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  3763. hr = pVirtualDFRoot->EnumElements(
  3764. dwReserved1,
  3765. pReserved2,
  3766. dwReserved3,
  3767. &penumWalk);
  3768. DH_NOEXPECTEDERROR ();
  3769. CheckErrorTest(STG_E_INVALIDPARAMETER,
  3770. TEXT ("VirtualCtrNode::EnumElements inv dwReserved3"),
  3771. penumWalk);
  3772. }
  3773. if(S_OK == hr)
  3774. {
  3775. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &pReserved2);
  3776. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  3777. }
  3778. if(S_OK == hr)
  3779. {
  3780. DH_EXPECTEDERROR (STG_E_INVALIDPARAMETER);
  3781. hr = pVirtualDFRoot->EnumElements(
  3782. dwReserved1,
  3783. pReserved2,
  3784. dwReserved3,
  3785. &penumWalk);
  3786. DH_NOEXPECTEDERROR ();
  3787. CheckErrorTest(STG_E_INVALIDPARAMETER,
  3788. TEXT ("VirtualCtrNode::EnumElements inv pReserved2"),
  3789. penumWalk);
  3790. }
  3791. // Now call EnumElements with NULL ppenm 4th parameter.
  3792. if(S_OK == hr)
  3793. {
  3794. DH_EXPECTEDERROR (STG_E_INVALIDPOINTER);
  3795. hr = pVirtualDFRoot->EnumElements( 0, NULL, 0, NULL);
  3796. DH_NOEXPECTEDERROR ();
  3797. CheckErrorTest2(STG_E_INVALIDPOINTER,
  3798. TEXT ("VirtualCtrNode::EnumElements NULL penum"));
  3799. }
  3800. // Make a valid call to EnumElements now
  3801. if(S_OK == hr)
  3802. {
  3803. hr = pVirtualDFRoot->EnumElements( 0, NULL, 0, &penumWalk);
  3804. DH_HRCHECK(hr, TEXT("VirtualCtrNode::EnumElements")) ;
  3805. }
  3806. // Now try the following skip calls - Attempt to skip 0 elements and
  3807. // attempt to skip MAX_ULONG elements.
  3808. // Attempt to Skip 0 elements.
  3809. if(S_OK == hr)
  3810. {
  3811. hr = penumWalk->Skip(0L);
  3812. DH_HRCHECK(hr, TEXT("IEnumSTATSTG::Skip")) ;
  3813. }
  3814. // Attempt to Skip ULONG_MAX elements.
  3815. // NOTE: In the old test, this was supposed to return S_OK, but it returns
  3816. // S_FALSE
  3817. if(S_OK == hr)
  3818. {
  3819. hr = penumWalk->Skip(ULONG_MAX);
  3820. CheckErrorTest2(S_FALSE,
  3821. TEXT ("IEnumSTATSTG::Skip ULONG_MAX"));
  3822. }
  3823. // Call Clone with NULL ppenum parameter (ist)
  3824. if(S_OK == hr)
  3825. {
  3826. hr = penumWalk->Clone(NULL);
  3827. CheckErrorTest2(STG_E_INVALIDPOINTER,
  3828. TEXT ("IEnumSTATSTG::Clone NULL ppEnum"));
  3829. }
  3830. if(S_OK == hr)
  3831. {
  3832. statStg.pwcsName = NULL;
  3833. // first get pmalloc that would be used to free up the name string from
  3834. // STATSTG.
  3835. hr = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  3836. DH_HRCHECK(hr, TEXT("CoGetMalloc")) ;
  3837. }
  3838. // Reset the enumerator back to start and then test Next methods
  3839. if(S_OK == hr)
  3840. {
  3841. hr = penumWalk->Reset();
  3842. DH_HRCHECK(hr, TEXT("IEnumSTATSTG:Reset")) ;
  3843. }
  3844. // Call Next with celt equal to zero, but pceltFetched as not NULL.
  3845. if(S_OK == hr)
  3846. {
  3847. hr = penumWalk->Next(0, &statStg ,&celtFetched);
  3848. DH_TRACE((DH_LVL_TRACE4,
  3849. TEXT("celt given 0, celtFetched is %lu, hr is %lx\n"),
  3850. celtFetched, hr));
  3851. DH_HRCHECK (hr, TEXT("IEnumSTATSTG::Next celt 0"));
  3852. }
  3853. // Call Next with celt equal to 999, but celtFetched set to NULL
  3854. if(S_OK == hr)
  3855. {
  3856. hr = penumWalk->Next(999, &statStg ,NULL);
  3857. CheckErrorTest2(STG_E_INVALIDPARAMETER,
  3858. TEXT ("IEnumSTATSTG::Next celt 999 and pceltFetched NULL"));
  3859. }
  3860. // Call Next with rgelt as NULL (2nd parameter). celtFetched may be NULL
  3861. // when celt asked is 1
  3862. if(S_OK == hr)
  3863. {
  3864. hr = penumWalk->Next(1, NULL, NULL);
  3865. CheckErrorTest2(STG_E_INVALIDPOINTER,
  3866. TEXT ("IEnumSTATSTG::Next rgelt NULL"));
  3867. }
  3868. // Call Next with celt as 1 and pceltFetched as NULL. Allowed as per spec
  3869. // For docfile/nssfile, it will pass since it has a substorage added as
  3870. // above. For flatfile, it will pass since it has CONTENTS stream always
  3871. if(S_OK == hr)
  3872. {
  3873. hr = penumWalk->Next(1, &statStg, NULL);
  3874. DH_TRACE((DH_LVL_TRACE4,
  3875. TEXT("Name of element fetched is %s\n"),
  3876. statStg.pwcsName));
  3877. DH_HRCHECK(hr, TEXT("IEnumSTATSTG::Next celt 1 and pceltFetched NULL"));
  3878. }
  3879. // Clean up
  3880. if(NULL != statStg.pwcsName)
  3881. {
  3882. pMalloc->Free(statStg.pwcsName);
  3883. statStg.pwcsName = NULL;
  3884. }
  3885. // Call Next with celt more than elements in stg & celtFetched as not NULL
  3886. if(S_OK == hr)
  3887. {
  3888. hr = penumWalk->Reset();
  3889. DH_HRCHECK(hr, TEXT("IEnumSTATSTG:Reset")) ;
  3890. }
  3891. if(S_OK == hr)
  3892. {
  3893. pStatStg = new STATSTG[cAskMoreThanPresent];
  3894. if(NULL == pStatStg)
  3895. {
  3896. hr = E_OUTOFMEMORY;
  3897. }
  3898. }
  3899. if(S_OK == hr)
  3900. {
  3901. hr = penumWalk->Next(cAskMoreThanPresent, pStatStg ,&celtFetched);
  3902. DH_TRACE((DH_LVL_TRACE4,
  3903. TEXT("IEnumSTATSTG celt more, hr %lx, celtFetched %lu\n"),
  3904. hr, celtFetched));
  3905. CheckErrorTest2(S_FALSE,
  3906. TEXT ("IEnumSTATSTG::Next celt more number of elements"));
  3907. }
  3908. if(NULL != pStatStg)
  3909. {
  3910. delete [] pStatStg;
  3911. pStatStg= NULL;
  3912. }
  3913. // Free LPENUMSTATSTG pointer
  3914. if(NULL != penumWalk)
  3915. {
  3916. ulRef = penumWalk->Release();
  3917. DH_ASSERT (0 == ulRef);
  3918. penumWalk = NULL;
  3919. }
  3920. // Close the root docfile
  3921. if (NULL != pVirtualDFRoot)
  3922. {
  3923. hr2 = pVirtualDFRoot->Close();
  3924. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  3925. hr = FirstError (hr, hr2);
  3926. }
  3927. // if something did not pass, mark test (hr) as E_FAIL
  3928. if (FALSE == fPass)
  3929. {
  3930. hr = FirstError (hr, E_FAIL);
  3931. }
  3932. // if everything goes well, log test as passed else failed.
  3933. if ((S_OK == hr) && (TRUE == fPass))
  3934. {
  3935. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_202 passed.")) );
  3936. }
  3937. else
  3938. {
  3939. DH_LOG((LOG_FAIL,
  3940. TEXT("Test variation APITEST_202 failed; hr=%#lx; fPass=%d."),
  3941. hr,
  3942. fPass));
  3943. }
  3944. // Cleanup
  3945. CleanupTestDocfile (&pVirtualDFRoot,
  3946. &pTestVirtualDF,
  3947. &pTestChanceDF,
  3948. S_OK == hr);
  3949. // free strings
  3950. if(NULL != pReserved2)
  3951. {
  3952. delete [] pReserved2;
  3953. pReserved2 = NULL;
  3954. }
  3955. if(NULL != pRootNewChildStgName)
  3956. {
  3957. delete [] pRootNewChildStgName;
  3958. pRootNewChildStgName = NULL;
  3959. }
  3960. // Stop logging the test
  3961. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_202 finished")) );
  3962. return hr;
  3963. }
  3964. //----------------------------------------------------------------------------
  3965. //
  3966. // Test: APITEST_203
  3967. //
  3968. // Synopsis: Attempts various illegit operations on the IStorage interface,
  3969. // verifies proper return codes.
  3970. //
  3971. // Arguments:[argc]
  3972. // [argv]
  3973. //
  3974. // Returns: HRESULT
  3975. //
  3976. // History: 18-June-1996 NarindK Created.
  3977. //
  3978. // Notes: This test runs in direct, transacted, and transacted deny write
  3979. // modes
  3980. //
  3981. // New Test Notes:
  3982. // 1. Old File: IASTORAG.CXX
  3983. // 2. Old name of test : IllegitAPIStorage test
  3984. // New Name of test : APITEST_203
  3985. // 3. To run the test, do the following at command prompt.
  3986. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-203
  3987. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  3988. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-203
  3989. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  3990. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-203
  3991. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  3992. //
  3993. // BUGNOTE: Conversion: APITEST_203
  3994. //-----------------------------------------------------------------------------
  3995. HRESULT APITEST_203(int argc, char *argv[])
  3996. {
  3997. HRESULT hr = S_OK;
  3998. HRESULT hrExpected = E_NOTIMPL; // Flatfile change
  3999. HRESULT hr2 = S_OK;
  4000. ChanceDF *pTestChanceDF = NULL;
  4001. VirtualDF *pTestVirtualDF = NULL;
  4002. VirtualCtrNode *pVirtualDFRoot = NULL;
  4003. LPTSTR ptszChildStgName = NULL;
  4004. LPOLESTR poszChildStgName = NULL;
  4005. LPSTORAGE pStgRoot = NULL;
  4006. LPSTORAGE pStgChild = NULL;
  4007. LPSTORAGE pStgChild2 = NULL;
  4008. LPSTREAM pStmChild = NULL;
  4009. DG_STRING *pdgu = NULL;
  4010. DG_INTEGER *pdgi = NULL;
  4011. ULONG cRandom = 0;
  4012. ULONG cMin = 1;
  4013. ULONG cMax = 999;
  4014. SNB snbTest = NULL;
  4015. SNB snbTemp = NULL;
  4016. OLECHAR *ocsSNBChar = NULL;
  4017. ULONG ulRef = 0;
  4018. ULONG i = 0;
  4019. BOOL fPass = TRUE;
  4020. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_203"));
  4021. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_203 started.")) );
  4022. DH_TRACE((DH_LVL_ALWAYS,
  4023. TEXT("Attempt various illegitimate operations on IStorage interface")));
  4024. // Create our ChanceDF and VirtualDF
  4025. hr = CreateTestDocfile (argc,
  4026. argv,
  4027. &pVirtualDFRoot,
  4028. &pTestVirtualDF,
  4029. &pTestChanceDF);
  4030. // if creating the docfile - bail here
  4031. if (NULL != pTestChanceDF && DoingCreate ())
  4032. {
  4033. UINT ulSeed = pTestChanceDF->GetSeed ();
  4034. CleanupTestDocfile (&pVirtualDFRoot,
  4035. &pTestVirtualDF,
  4036. &pTestChanceDF,
  4037. FALSE);
  4038. return (HRESULT)ulSeed;
  4039. }
  4040. if (S_OK == hr)
  4041. {
  4042. DH_TRACE((DH_LVL_TRACE1,
  4043. TEXT("Run Mode for APITEST_203, Access mode: %lx"),
  4044. pTestChanceDF->GetRootMode()));
  4045. }
  4046. // Get IStorage pointer
  4047. if (S_OK == hr)
  4048. {
  4049. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  4050. DH_ASSERT (NULL != pStgRoot);
  4051. if (NULL == pStgRoot)
  4052. {
  4053. hr = E_FAIL;
  4054. }
  4055. }
  4056. if (S_OK == hr)
  4057. {
  4058. pdgu = pTestVirtualDF->GetDataGenUnicode();
  4059. DH_ASSERT (NULL != pdgu);
  4060. if (NULL == pdgu)
  4061. {
  4062. hr = E_FAIL;
  4063. }
  4064. }
  4065. if(S_OK == hr)
  4066. {
  4067. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH,&ptszChildStgName);
  4068. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4069. }
  4070. if(S_OK == hr)
  4071. {
  4072. // Convert name to OLECHAR
  4073. hr = TStringToOleString(ptszChildStgName, &poszChildStgName);
  4074. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  4075. }
  4076. // Call CreateStorage with grfmode=-1
  4077. if (S_OK == hr)
  4078. {
  4079. hr = pStgRoot->CreateStorage(
  4080. poszChildStgName,
  4081. (DWORD) -1,
  4082. 0,
  4083. 0,
  4084. &pStgChild);
  4085. // ----------- flatfile change ---------------
  4086. hrExpected = StorageIsFlat() ? E_NOTIMPL : STG_E_INVALIDFLAG;
  4087. // ----------- flatfile change ---------------
  4088. CheckErrorTest(hrExpected,
  4089. TEXT ("IStorage::CreateStorage inv grfMode"),
  4090. pStgChild);
  4091. }
  4092. if (S_OK == hr)
  4093. {
  4094. pdgi = pTestVirtualDF->GetDataGenInteger();
  4095. DH_ASSERT (NULL != pdgi);
  4096. if (NULL == pdgi)
  4097. {
  4098. hr = E_FAIL;
  4099. }
  4100. }
  4101. if (S_OK == hr)
  4102. {
  4103. hr = pdgi->Generate(&cRandom, cMin, cMax);
  4104. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  4105. }
  4106. // Call CreateStorage with random data in dwReserved1
  4107. if (S_OK == hr)
  4108. {
  4109. hr = pStgRoot->CreateStorage(
  4110. poszChildStgName,
  4111. pTestChanceDF->GetStgMode() | STGM_CREATE,
  4112. cRandom,
  4113. 0,
  4114. &pStgChild);
  4115. // ----------- flatfile change ---------------
  4116. hrExpected = StorageIsFlat() ? E_NOTIMPL : STG_E_INVALIDPARAMETER;
  4117. // ----------- flatfile change ---------------
  4118. CheckErrorTest(hrExpected,
  4119. TEXT ("IStorage::CreateStorage inv dwReserved1"),
  4120. pStgChild);
  4121. }
  4122. // Call CreateStorage with random data in dwReserved2
  4123. if (S_OK == hr)
  4124. {
  4125. hr = pStgRoot->CreateStorage(
  4126. poszChildStgName,
  4127. pTestChanceDF->GetStgMode() | STGM_CREATE,
  4128. 0,
  4129. cRandom,
  4130. &pStgChild);
  4131. // ----------- flatfile change ---------------
  4132. hrExpected = StorageIsFlat() ? E_NOTIMPL : STG_E_INVALIDPARAMETER;
  4133. // ----------- flatfile change ---------------
  4134. CheckErrorTest(hrExpected,
  4135. TEXT ("IStorage::CreateStorage inv dwReserved2"),
  4136. pStgChild);
  4137. }
  4138. // Call CreateStorage with NULL 5th ppstg parameter
  4139. if (S_OK == hr)
  4140. {
  4141. hr = pStgRoot->CreateStorage(
  4142. poszChildStgName,
  4143. pTestChanceDF->GetStgMode() | STGM_CREATE,
  4144. 0,
  4145. 0,
  4146. NULL);
  4147. // ----------- flatfile change ---------------
  4148. hrExpected = StorageIsFlat() ? E_NOTIMPL : STG_E_INVALIDPOINTER;
  4149. // ----------- flatfile change ---------------
  4150. CheckErrorTest2(hrExpected,
  4151. TEXT ("IStorage::CreateStorage NULL ppstg"));
  4152. }
  4153. // Create a stream with poszChildName and later on try to instantiate the
  4154. // child storage with that same name poszChildName
  4155. if (S_OK == hr)
  4156. {
  4157. hr = pStgRoot->CreateStream(
  4158. poszChildStgName,
  4159. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4160. 0,
  4161. 0,
  4162. &pStmChild);
  4163. DH_HRCHECK (hr, TEXT("IStorage::CreateStream"));
  4164. }
  4165. // BUGBUG: Use Random commit modes...
  4166. if (S_OK == hr)
  4167. {
  4168. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4169. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  4170. }
  4171. // Close stream...
  4172. if (NULL != pStmChild)
  4173. {
  4174. ulRef = pStmChild->Release();
  4175. DH_ASSERT (0 == ulRef);
  4176. }
  4177. // Now try opening storage with name with which above stream was created
  4178. // i.e. poszChildName
  4179. if (S_OK == hr)
  4180. {
  4181. pStgChild = NULL;
  4182. hr = pStgRoot->OpenStorage(
  4183. poszChildStgName,
  4184. NULL,
  4185. pTestChanceDF->GetStgMode(),
  4186. NULL,
  4187. 0,
  4188. &pStgChild);
  4189. // ----------- flatfile change ---------------
  4190. hrExpected = StorageIsFlat() ? E_NOTIMPL : STG_E_FILENOTFOUND;
  4191. // ----------- flatfile change ---------------
  4192. CheckErrorTest(hrExpected,
  4193. TEXT ("IStorage::OpenStorage inv name"),
  4194. pStgChild);
  4195. }
  4196. //Destroy the stream element of this root storage having name poszChildStg
  4197. //Name
  4198. if(S_OK == hr)
  4199. {
  4200. hr = pStgRoot->DestroyElement(poszChildStgName);
  4201. DH_HRCHECK(hr, TEXT("IStorage::DestroyElement")) ;
  4202. }
  4203. // ----------- flatfile change ---------------
  4204. if(!StorageIsFlat())
  4205. // ----------- flatfile change ---------------
  4206. {
  4207. // Create a valid storage with name poszChildStgName
  4208. if (S_OK == hr)
  4209. {
  4210. pStgChild = NULL;
  4211. hr = pStgRoot->CreateStorage(
  4212. poszChildStgName,
  4213. pTestChanceDF->GetStgMode() | STGM_CREATE | STGM_FAILIFTHERE,
  4214. 0,
  4215. 0,
  4216. &pStgChild);
  4217. DH_HRCHECK (hr, TEXT("IStorage::CreateStorage"));
  4218. }
  4219. // Commit with grfCommitFlags = -1
  4220. if (S_OK == hr)
  4221. {
  4222. hr = pStgChild->Commit((DWORD) -1);
  4223. CheckErrorTest2(STG_E_INVALIDFLAG,
  4224. TEXT("IStorage::Commit inv flag"));
  4225. }
  4226. // Commit the child. BUGBUG: Use random commit modes
  4227. if (S_OK == hr)
  4228. {
  4229. hr = pStgChild->Commit(STGC_DEFAULT);
  4230. DH_HRCHECK (hr, TEXT("IStorage::Commit"));
  4231. }
  4232. // Commit the root storage. BUGBUG: Use random commit modes
  4233. if (S_OK == hr)
  4234. {
  4235. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4236. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  4237. }
  4238. // Attempt second instantiation of pStgChild which is already open.
  4239. if (S_OK == hr)
  4240. {
  4241. hr = pStgRoot->OpenStorage(
  4242. poszChildStgName,
  4243. NULL,
  4244. pTestChanceDF->GetStgMode(),
  4245. NULL,
  4246. 0,
  4247. &pStgChild2);
  4248. CheckErrorTest(STG_E_ACCESSDENIED,
  4249. TEXT ("IStorage::OpenStorage 2nd time"),
  4250. pStgChild2);
  4251. }
  4252. if (S_OK == hr)
  4253. {
  4254. ulRef = pStgChild->Release();
  4255. DH_ASSERT (0 == ulRef);
  4256. }
  4257. // Now try to open child IStorage, but with grfMode = -1
  4258. if (S_OK == hr)
  4259. {
  4260. pStgChild = NULL;
  4261. hr = pStgRoot->OpenStorage(
  4262. poszChildStgName,
  4263. NULL,
  4264. (DWORD) -1,
  4265. NULL,
  4266. 0,
  4267. &pStgChild);
  4268. CheckErrorTest(STG_E_INVALIDFLAG,
  4269. TEXT ("IStorage::OpenStorage inv grfMode"),
  4270. pStgChild);
  4271. }
  4272. // Attempt OpenStorage with name as " " of IStorage to be opened.
  4273. if (S_OK == hr)
  4274. {
  4275. pStgChild = NULL;
  4276. hr = pStgRoot->OpenStorage(
  4277. (OLECHAR *) " ",
  4278. NULL,
  4279. pTestChanceDF->GetStgMode(),
  4280. NULL,
  4281. 0,
  4282. &pStgChild);
  4283. CheckErrorTest(STG_E_FILENOTFOUND,
  4284. TEXT ("IStorage::OpenStorage inv name"),
  4285. pStgChild);
  4286. }
  4287. // Attempt OpenStorage with name as NULL of IStorage to be opened.
  4288. if (S_OK == hr)
  4289. {
  4290. pStgChild = NULL;
  4291. hr = pStgRoot->OpenStorage(
  4292. NULL,
  4293. NULL,
  4294. pTestChanceDF->GetStgMode(),
  4295. NULL,
  4296. 0,
  4297. &pStgChild);
  4298. CheckErrorTest(STG_E_INVALIDNAME,
  4299. TEXT ("IStorage::OpenStorage NULL name"),
  4300. pStgChild);
  4301. }
  4302. // Attempt OpenStorage with name as NULL ppstg, 6th parameter.
  4303. if (S_OK == hr)
  4304. {
  4305. hr = pStgRoot->OpenStorage(
  4306. poszChildStgName,
  4307. NULL,
  4308. pTestChanceDF->GetStgMode(),
  4309. NULL,
  4310. 0,
  4311. NULL);
  4312. CheckErrorTest2(STG_E_INVALIDPOINTER,
  4313. TEXT ("IStorage::OpenStorage NULL ppstg"));
  4314. }
  4315. // Attempt OpenStorage with random data in dwReserved parameter
  4316. if (S_OK == hr)
  4317. {
  4318. hr = pdgi->Generate(&cRandom, cMin, cMax);
  4319. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  4320. }
  4321. if (S_OK == hr)
  4322. {
  4323. pStgChild = NULL;
  4324. hr = pStgRoot->OpenStorage(
  4325. poszChildStgName,
  4326. NULL,
  4327. pTestChanceDF->GetStgMode(),
  4328. NULL,
  4329. cRandom,
  4330. &pStgChild);
  4331. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4332. TEXT ("IStorage::OpenStorage inv dwReserved"),
  4333. pStgChild);
  4334. }
  4335. // Attempt OpenStorage with uninitialized SNB, should fail, but no GP
  4336. // fault should occur.
  4337. if(S_OK == hr)
  4338. {
  4339. snbTest = (OLECHAR **) new OLECHAR [sizeof(OLECHAR *) * 2];
  4340. if(NULL == snbTest)
  4341. {
  4342. hr = E_OUTOFMEMORY;
  4343. }
  4344. else
  4345. {
  4346. *snbTest = (OLECHAR*)0xBAADF00D;
  4347. }
  4348. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  4349. }
  4350. if (S_OK == hr)
  4351. {
  4352. pStgChild = NULL;
  4353. hr = pStgRoot->OpenStorage(
  4354. poszChildStgName,
  4355. NULL,
  4356. pTestChanceDF->GetStgMode(),
  4357. snbTest,
  4358. 0,
  4359. &pStgChild);
  4360. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4361. TEXT ("IStorage::OpenStorage inv snb"),
  4362. pStgChild);
  4363. }
  4364. // Attempt OpenStorage with SNB with no name in block, although it has
  4365. // space for two names, set name list to NULL
  4366. if(S_OK == hr)
  4367. {
  4368. *snbTest = NULL;
  4369. }
  4370. if (S_OK == hr)
  4371. {
  4372. pStgChild = NULL;
  4373. hr = pStgRoot->OpenStorage(
  4374. poszChildStgName,
  4375. NULL,
  4376. pTestChanceDF->GetStgMode(),
  4377. snbTest,
  4378. 0,
  4379. &pStgChild);
  4380. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4381. TEXT ("IStorage::OpenStorage empty snb"),
  4382. pStgChild);
  4383. }
  4384. // Allocate space for long name and fill name with X's, make next SNB
  4385. // element NULL, and make a call to IStorage::OpenStorage with too long a
  4386. // name in SNB
  4387. if(S_OK == hr && NULL != snbTest)
  4388. {
  4389. *snbTest = (OLECHAR *) new OLECHAR [MAX_STG_NAME_LEN*4];
  4390. if (NULL == *snbTest)
  4391. {
  4392. hr = E_OUTOFMEMORY;
  4393. }
  4394. DH_HRCHECK (hr, TEXT("new OLECHAR"));
  4395. }
  4396. if(S_OK == hr && NULL != snbTest)
  4397. {
  4398. snbTemp = snbTest;
  4399. ocsSNBChar = *snbTemp;
  4400. for (i=0; i<( MAX_STG_NAME_LEN*4 -1); i++)
  4401. {
  4402. ocsSNBChar[i] = 'X';
  4403. }
  4404. ocsSNBChar[i] = '\0';
  4405. // Assign second element as NULL
  4406. snbTemp++;
  4407. *snbTemp = NULL;
  4408. }
  4409. if (S_OK == hr)
  4410. {
  4411. pStgChild = NULL;
  4412. hr = pStgRoot->OpenStorage(
  4413. poszChildStgName,
  4414. NULL,
  4415. pTestChanceDF->GetStgMode(),
  4416. snbTest,
  4417. 0,
  4418. &pStgChild);
  4419. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4420. TEXT ("IStorage::OpenStorage long snb"),
  4421. pStgChild);
  4422. }
  4423. // ----------- flatfile change ---------------
  4424. }
  4425. // ----------- flatfile change ---------------
  4426. // Close the root docfile
  4427. if (NULL != pVirtualDFRoot)
  4428. {
  4429. hr2 = pVirtualDFRoot->Close();
  4430. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  4431. hr = FirstError (hr, hr2);
  4432. }
  4433. // if something did not pass, mark test (hr) as E_FAIL
  4434. if (FALSE == fPass)
  4435. {
  4436. hr = FirstError (hr, E_FAIL);
  4437. }
  4438. // if everything goes well, log test as passed else failed.
  4439. if ((S_OK == hr) && (TRUE == fPass))
  4440. {
  4441. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_203 passed.")) );
  4442. }
  4443. else
  4444. {
  4445. DH_LOG((
  4446. LOG_FAIL,
  4447. TEXT("Test variation APITEST_203 failed; hr=%#lx; fPass=%d."),
  4448. hr,
  4449. fPass));
  4450. }
  4451. // Cleanup
  4452. CleanupTestDocfile (&pVirtualDFRoot,
  4453. &pTestVirtualDF,
  4454. &pTestChanceDF,
  4455. S_OK == hr);
  4456. // Delete temp strings
  4457. if(NULL != ptszChildStgName)
  4458. {
  4459. delete []ptszChildStgName;
  4460. ptszChildStgName = NULL;
  4461. }
  4462. if(NULL != poszChildStgName)
  4463. {
  4464. delete []poszChildStgName;
  4465. poszChildStgName = NULL;
  4466. }
  4467. // Free SNB
  4468. if(NULL != snbTest)
  4469. {
  4470. if(NULL != *snbTest)
  4471. {
  4472. delete [] *snbTest;
  4473. *snbTest = NULL;
  4474. }
  4475. delete [] snbTest;
  4476. snbTest = NULL;
  4477. }
  4478. // Stop logging the test
  4479. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_203 finished")) );
  4480. return hr;
  4481. }
  4482. //----------------------------------------------------------------------------
  4483. //
  4484. // Test: APITEST_204
  4485. //
  4486. // Synopsis: Attempts various illegit operations on the IStream interface,
  4487. // verifies proper return codes.
  4488. //
  4489. // Arguments:[argc]
  4490. // [argv]
  4491. //
  4492. // Returns: HRESULT
  4493. //
  4494. // History: 18-June-1996 NarindK Created.
  4495. //
  4496. // Notes: This test runs in direct, transacted, and transacted deny write
  4497. // modes
  4498. //
  4499. // New Test Notes:
  4500. // 1. Old File: IASTREAM.CXX
  4501. // 2. Old name of test : IllegitAPIStream test
  4502. // New Name of test : APITEST_204
  4503. // 3. To run the test, do the following at command prompt.
  4504. // a. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-204
  4505. // /dfRootMode:dirReadWriteShEx
  4506. // b. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-204
  4507. // /dfRootMode:xactReadWriteShEx
  4508. // c. stgbase /seed:2 /dfdepth:0-0 /dfstg:0-0 /dfstm:0-0 /t:APITEST-204
  4509. // /dfRootMode:xactReadWriteShDenyW
  4510. //
  4511. // BUGNOTE: Conversion: APITEST_204
  4512. //-----------------------------------------------------------------------------
  4513. HRESULT APITEST_204(int argc, char *argv[])
  4514. {
  4515. HRESULT hr = S_OK;
  4516. HRESULT hr2 = S_OK;
  4517. ChanceDF *pTestChanceDF = NULL;
  4518. VirtualDF *pTestVirtualDF = NULL;
  4519. VirtualCtrNode *pVirtualDFRoot = NULL;
  4520. LPTSTR ptszChildStmName = NULL;
  4521. LPOLESTR poszChildStmName = NULL;
  4522. LPSTORAGE pStgRoot = NULL;
  4523. LPSTORAGE pStgChild = NULL;
  4524. LPSTREAM pStmChild = NULL;
  4525. LPSTREAM pStmChild2 = NULL;
  4526. ULONG ulRef = 0;
  4527. DG_STRING *pdgu = NULL;
  4528. DG_INTEGER *pdgi = NULL;
  4529. ULONG cRandom = 0;
  4530. ULONG cMin = 1;
  4531. ULONG cMax = 999;
  4532. BOOL fPass = TRUE;
  4533. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("APITEST_204"));
  4534. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_204 started.")) );
  4535. DH_TRACE((DH_LVL_ALWAYS,
  4536. TEXT("Attempt illegitimate operations on IStream interface.")));
  4537. // Create our ChanceDF and VirtualDF
  4538. hr = CreateTestDocfile (argc,
  4539. argv,
  4540. &pVirtualDFRoot,
  4541. &pTestVirtualDF,
  4542. &pTestChanceDF);
  4543. // if creating the docfile - bail here
  4544. if (NULL != pTestChanceDF && DoingCreate ())
  4545. {
  4546. UINT ulSeed = pTestChanceDF->GetSeed ();
  4547. CleanupTestDocfile (&pVirtualDFRoot,
  4548. &pTestVirtualDF,
  4549. &pTestChanceDF,
  4550. FALSE);
  4551. return (HRESULT)ulSeed;
  4552. }
  4553. if (S_OK == hr)
  4554. {
  4555. DH_TRACE((DH_LVL_TRACE1,
  4556. TEXT("Run Mode for APITEST_204, Access mode: %lx"),
  4557. pTestChanceDF->GetRootMode()));
  4558. }
  4559. // Get IStorage pointer
  4560. if (S_OK == hr)
  4561. {
  4562. pStgRoot = pVirtualDFRoot->GetIStoragePointer();
  4563. DH_ASSERT (NULL != pStgRoot);
  4564. if (NULL == pStgRoot)
  4565. {
  4566. hr = E_FAIL;
  4567. }
  4568. }
  4569. // Get DG_STRING pointer
  4570. if (S_OK == hr)
  4571. {
  4572. pdgu = pTestVirtualDF->GetDataGenUnicode();
  4573. DH_ASSERT (NULL != pdgu);
  4574. if (NULL == pdgu)
  4575. {
  4576. hr = E_FAIL;
  4577. }
  4578. }
  4579. // Generate random name for stream
  4580. if(S_OK == hr)
  4581. {
  4582. hr = GenerateRandomName(pdgu,MINLENGTH,MAXLENGTH, &ptszChildStmName);
  4583. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  4584. }
  4585. if(S_OK == hr)
  4586. {
  4587. // Convert name to OLECHAR
  4588. hr = TStringToOleString(ptszChildStmName, &poszChildStmName);
  4589. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  4590. }
  4591. // Attempt CreateStream with grfmode=-1
  4592. if (S_OK == hr)
  4593. {
  4594. hr = pStgRoot->CreateStream(
  4595. poszChildStmName,
  4596. (DWORD) -1,
  4597. 0,
  4598. 0,
  4599. &pStmChild);
  4600. CheckErrorTest(STG_E_INVALIDFLAG,
  4601. TEXT ("IStorage::CreateStream inv grfMode"),
  4602. pStmChild);
  4603. }
  4604. // Get DG_INTEGER pointer
  4605. if (S_OK == hr)
  4606. {
  4607. pdgi = pTestVirtualDF->GetDataGenInteger();
  4608. DH_ASSERT (NULL != pdgi);
  4609. if (NULL == pdgi)
  4610. {
  4611. hr = E_FAIL;
  4612. }
  4613. }
  4614. if (S_OK == hr)
  4615. {
  4616. hr = pdgi->Generate(&cRandom, cMin, cMax);
  4617. DH_HRCHECK(hr, TEXT("dgi::Generate")) ;
  4618. }
  4619. // Call CreateStorage with random data in dwReserved1
  4620. if (S_OK == hr)
  4621. {
  4622. hr = pStgRoot->CreateStream(
  4623. poszChildStmName,
  4624. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4625. cRandom,
  4626. 0,
  4627. &pStmChild);
  4628. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4629. TEXT ("IStorage::CreateStream inv dwReserved1"),
  4630. pStmChild);
  4631. }
  4632. // Call CreateStream with random data in dwReserved2
  4633. if (S_OK == hr)
  4634. {
  4635. hr = pStgRoot->CreateStream(
  4636. poszChildStmName,
  4637. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4638. 0,
  4639. cRandom,
  4640. &pStmChild);
  4641. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4642. TEXT ("IStorage::CreateStream inv dwReserved2"),
  4643. pStmChild);
  4644. }
  4645. // Call CreateStorage with NULL 5th ppstm parameter
  4646. if (S_OK == hr)
  4647. {
  4648. hr = pStgRoot->CreateStream(
  4649. poszChildStmName,
  4650. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4651. 0,
  4652. 0,
  4653. NULL);
  4654. CheckErrorTest2(STG_E_INVALIDPOINTER,
  4655. TEXT ("IStorage::CreateStream NULL ppstm"));
  4656. }
  4657. // ----------- flatfile change ---------------
  4658. if(!StorageIsFlat())
  4659. {
  4660. // ----------- flatfile change ---------------
  4661. // Create a storage with poszChildStmName and later on try to instantiate
  4662. // child stream with that same name poszChildStmName
  4663. if (S_OK == hr)
  4664. {
  4665. hr = pStgRoot->CreateStorage(
  4666. poszChildStmName,
  4667. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  4668. 0,
  4669. 0,
  4670. &pStgChild);
  4671. DH_HRCHECK (hr, TEXT("IStorage::CreateStorage"));
  4672. DH_ASSERT (NULL != pStgChild);
  4673. }
  4674. // BUGBUG: Use Random commit modes...
  4675. if (S_OK == hr)
  4676. {
  4677. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4678. DH_HRCHECK (hr, TEXT("VirtualCtrNode::Commit"));
  4679. }
  4680. // Close storage...
  4681. if (NULL != pStgChild)
  4682. {
  4683. ulRef = pStgChild->Release();
  4684. DH_ASSERT (0 == ulRef);
  4685. }
  4686. // ----------- flatfile change ---------------
  4687. }
  4688. // ----------- flatfile change ---------------
  4689. // Now try opening storage with name with which above storage was created
  4690. // i.e. poszChildStmName
  4691. if (S_OK == hr)
  4692. {
  4693. pStmChild = NULL;
  4694. hr = pStgRoot->OpenStream(
  4695. poszChildStmName,
  4696. NULL,
  4697. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4698. 0,
  4699. &pStmChild);
  4700. CheckErrorTest(STG_E_FILENOTFOUND,
  4701. TEXT ("IStorage::CreateStream inv name"),
  4702. pStmChild);
  4703. }
  4704. // ----------- flatfile change ---------------
  4705. if(!StorageIsFlat())
  4706. {
  4707. // ----------- flatfile change ---------------
  4708. //Destroy the storage element of this root storage having name poszChildStm
  4709. //Name
  4710. if(S_OK == hr)
  4711. {
  4712. hr = pStgRoot->DestroyElement(poszChildStmName);
  4713. DH_HRCHECK(hr, TEXT("IStorage::DestroyElement")) ;
  4714. }
  4715. // ----------- flatfile change ---------------
  4716. }
  4717. // ----------- flatfile change ---------------
  4718. // Create a valid stream with name poszChildStmName
  4719. if (S_OK == hr)
  4720. {
  4721. pStmChild = NULL;
  4722. hr = pStgRoot->CreateStream(
  4723. poszChildStmName,
  4724. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_FAILIFTHERE,
  4725. 0,
  4726. 0,
  4727. &pStmChild);
  4728. DH_HRCHECK (hr, TEXT("IStorage::CreateStream"));
  4729. DH_ASSERT (NULL != pStmChild);
  4730. }
  4731. // BUGBUG: Use Random commit modes...
  4732. if (S_OK == hr)
  4733. {
  4734. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  4735. DH_HRCHECK (hr, TEXT("IStorage::Commit"));
  4736. }
  4737. // Attempt second instance of IStream to be instantiated.
  4738. if (S_OK == hr)
  4739. {
  4740. pStmChild2 = NULL;
  4741. hr = pStgRoot->OpenStream(
  4742. poszChildStmName,
  4743. NULL,
  4744. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4745. 0,
  4746. &pStmChild2);
  4747. CheckErrorTest(STG_E_ACCESSDENIED,
  4748. TEXT ("IStorage::OpenStream 2nd time"),
  4749. pStmChild2);
  4750. }
  4751. // Release the stream
  4752. if(NULL != pStmChild)
  4753. {
  4754. ulRef = pStmChild->Release();
  4755. DH_ASSERT (0 == ulRef);
  4756. }
  4757. // Now attempt opening the stream with grfMode = -1
  4758. if (S_OK == hr)
  4759. {
  4760. pStmChild = NULL;
  4761. hr = pStgRoot->OpenStream(
  4762. poszChildStmName,
  4763. NULL,
  4764. (DWORD) -1,
  4765. 0,
  4766. &pStmChild);
  4767. CheckErrorTest(STG_E_INVALIDFLAG,
  4768. TEXT ("IStorage::OpenStream inv grfMode"),
  4769. pStmChild);
  4770. }
  4771. // Now attempt opening the stream with name as ""
  4772. if (S_OK == hr)
  4773. {
  4774. pStmChild = NULL;
  4775. hr = pStgRoot->OpenStream(
  4776. (OLECHAR *) " ",
  4777. NULL,
  4778. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4779. 0,
  4780. &pStmChild);
  4781. CheckErrorTest(STG_E_FILENOTFOUND,
  4782. TEXT ("IStorage::OpenStream inv name"),
  4783. pStmChild);
  4784. }
  4785. // Now attempt opening the stream with name as NULL
  4786. if (S_OK == hr)
  4787. {
  4788. pStmChild = NULL;
  4789. hr = pStgRoot->OpenStream(
  4790. NULL,
  4791. NULL,
  4792. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4793. 0,
  4794. &pStmChild);
  4795. CheckErrorTest(STG_E_INVALIDNAME,
  4796. TEXT ("IStorage::OpenStream NULL name"),
  4797. pStmChild);
  4798. }
  4799. // Now attempt opening the stream with random data in pReserved1 . For test
  4800. // we just put pStgRoot for pReserved1 variable.
  4801. if (S_OK == hr)
  4802. {
  4803. pStmChild = NULL;
  4804. hr = pStgRoot->OpenStream(
  4805. poszChildStmName,
  4806. pStgRoot,
  4807. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4808. 0,
  4809. &pStmChild);
  4810. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4811. TEXT ("IStorage::OpenStream inv dwReserved1"),
  4812. pStmChild);
  4813. }
  4814. // Now attempt opening the stream with random data in dwReserved2
  4815. if (S_OK == hr)
  4816. {
  4817. pStmChild = NULL;
  4818. hr = pStgRoot->OpenStream(
  4819. poszChildStmName,
  4820. NULL,
  4821. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4822. cRandom,
  4823. &pStmChild);
  4824. CheckErrorTest(STG_E_INVALIDPARAMETER,
  4825. TEXT ("IStorage::OpenStream inv dwReserved2"),
  4826. pStmChild);
  4827. }
  4828. // Now attempt opening the stream with NULL ppstm (5th parameter)
  4829. if (S_OK == hr)
  4830. {
  4831. hr = pStgRoot->OpenStream(
  4832. poszChildStmName,
  4833. NULL,
  4834. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4835. 0,
  4836. NULL);
  4837. CheckErrorTest2(STG_E_INVALIDPOINTER,
  4838. TEXT ("IStorage::OpenStream NULL ppstm"));
  4839. }
  4840. // Now attempt opening the stream normally
  4841. if (S_OK == hr)
  4842. {
  4843. pStmChild = NULL;
  4844. hr = pStgRoot->OpenStream(
  4845. poszChildStmName,
  4846. NULL,
  4847. STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
  4848. 0,
  4849. &pStmChild);
  4850. DH_HRCHECK (hr, TEXT("IStorage::OpenStream"));
  4851. DH_ASSERT (NULL != pStmChild);
  4852. }
  4853. // Release the stream
  4854. if(NULL != pStmChild)
  4855. {
  4856. ulRef = pStmChild->Release();
  4857. DH_ASSERT (0 == ulRef);
  4858. pStmChild = NULL;
  4859. }
  4860. // Release the root docfile
  4861. // Close the root docfile
  4862. if (NULL != pVirtualDFRoot)
  4863. {
  4864. hr2 = pVirtualDFRoot->Close();
  4865. DH_HRCHECK (hr2, TEXT("VirtualCtrNode::Close"));
  4866. hr = FirstError (hr, hr2);
  4867. }
  4868. // if something did not pass, mark test (hr) as E_FAIL
  4869. if (FALSE == fPass)
  4870. {
  4871. hr = FirstError (hr, E_FAIL);
  4872. }
  4873. // if everything goes well, log test as passed else failed.
  4874. if ((S_OK == hr) && (TRUE == fPass))
  4875. {
  4876. DH_LOG((LOG_PASS, TEXT("Test variation APITEST_204 passed.")) );
  4877. }
  4878. else
  4879. {
  4880. DH_LOG((LOG_FAIL,
  4881. TEXT("Test variation APITEST_204 failed; hr=%#lx; fPass=%d."),
  4882. hr,
  4883. fPass));
  4884. }
  4885. // Cleanup
  4886. CleanupTestDocfile (&pVirtualDFRoot,
  4887. &pTestVirtualDF,
  4888. &pTestChanceDF,
  4889. S_OK == hr);
  4890. // Delete temp string
  4891. if(NULL != ptszChildStmName)
  4892. {
  4893. delete []ptszChildStmName;
  4894. ptszChildStmName = NULL;
  4895. }
  4896. if(NULL != poszChildStmName)
  4897. {
  4898. delete []poszChildStmName;
  4899. poszChildStmName = NULL;
  4900. }
  4901. // Stop logging the test
  4902. DH_TRACE((DH_LVL_ALWAYS, TEXT("Test variation APITEST_204 finished")) );
  4903. return hr;
  4904. }
  4905. #else
  4906. // Stub out calls to these.
  4907. HRESULT APITEST_200(int argc, char *argv[]) {return E_NOTIMPL;}
  4908. HRESULT APITEST_201(int argc, char *argv[]) {return E_NOTIMPL;}
  4909. HRESULT APITEST_202(int argc, char *argv[]) {return E_NOTIMPL;}
  4910. HRESULT APITEST_203(int argc, char *argv[]) {return E_NOTIMPL;}
  4911. HRESULT APITEST_204(int argc, char *argv[]) {return E_NOTIMPL;}
  4912. #endif // _OLE_NSS_