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.

2010 lines
54 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: snbtests.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to String Name
  9. // Block (SNB) and STGM_PRIORITY mode.
  10. //
  11. // Functions:
  12. //
  13. // History: 26-July-1996 Jiminli Created.
  14. // 27-Mar-97 SCousens Conversionified
  15. //
  16. // BUGBUG: right now no snb params for nss apis.
  17. //--------------------------------------------------------------------------
  18. #include <dfheader.hxx>
  19. #pragma hdrstop
  20. #include "init.hxx"
  21. //----------------------------------------------------------------------------
  22. //
  23. // Test: SNBTEST_100
  24. //
  25. // Synopsis: The created root docfile is instantiated and traversed and the
  26. // child objects found are selected at random for inclusion in an
  27. // snbExclude structure. The docfile is commit and released. Then
  28. // the docfile is now re-instantiated with the just built SNB passed
  29. // in, indicating that the objects found in the SNB should be
  30. // returned as empty IStorages or zero length IStreams. The root
  31. // docfile is then traversed and each object returned that matches
  32. // a name in the SNB is verified to determine that it's empty or
  33. // zero length.
  34. //
  35. // Arguments:[argc]
  36. // [argv]
  37. //
  38. // Returns: HRESULT
  39. //
  40. // History: 1-Aug-1996 JiminLi Created.
  41. //
  42. // Notes: This test runs in direct, transacted, and transacted deny write
  43. // modes
  44. //
  45. // New Test Notes:
  46. // 1. Old File: LLNORM.CXX
  47. // 2. Old name of test : LegitLimitedInstNormal Test
  48. // New Name of test : SNBTEST_100
  49. // 3. To run the test, do the following at command prompt.
  50. // a. stgbase /seed:0 /dfdepth:1-2 /dfstg:1-3 /dfstm:0-3 /t:SNBTEST-100
  51. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /logloc:2
  52. // /traceloc:2 /labmode
  53. // b. stgbase /seed:0 /dfdepth:1-2 /dfstg:3-5 /dfstm:8-10 /t:SNBTEST-100
  54. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx /logloc:2
  55. // /traceloc:2 /labmode
  56. // c. stgbase /seed:0 /dfdepth:1-2 /dfstg:1-3 /dfstm:6-9 /t:SNBTEST-100
  57. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  58. // /logloc:2 /traceloc:2 /labmode
  59. //
  60. // BUGNOTE: Conversion: SNBTEST-100 NO - not supported in nss
  61. //
  62. //-----------------------------------------------------------------------------
  63. HRESULT SNBTEST_100(int argc, char *argv[])
  64. {
  65. HRESULT hr = S_OK;
  66. HRESULT hr2 = S_OK;
  67. ChanceDF *pTestChanceDF = NULL;
  68. VirtualDF *pTestVirtualDF = NULL;
  69. VirtualCtrNode *pVirtualDFRoot = NULL;
  70. DG_STRING *pdgu = NULL;
  71. DG_INTEGER *pdgi = NULL;
  72. USHORT usErr = 0;
  73. LPTSTR pRootDocFileName = NULL;
  74. DWORD dwRootMode = 0;
  75. DWORD dwStgMode = 0;
  76. SNB snbNamesToExclude = NULL;
  77. SNB snbDelIndex = NULL;
  78. // Not for 2phase. Bail.
  79. if (DoingDistrib ())
  80. {
  81. return S_OK;
  82. }
  83. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("SNBTEST_100"));
  84. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  85. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_100 started.")) );
  86. DH_TRACE((DH_LVL_TRACE1,TEXT("Attempt legitimate SNB tests on a docfile")));
  87. // Create the new ChanceDocFile tree that would consist of chance nodes.
  88. if (S_OK == hr)
  89. {
  90. pTestChanceDF = new ChanceDF();
  91. if(NULL == pTestChanceDF)
  92. {
  93. hr = E_OUTOFMEMORY;
  94. }
  95. }
  96. if (S_OK == hr)
  97. {
  98. hr = pTestChanceDF->CreateFromParams(argc, argv);
  99. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  100. }
  101. if (S_OK == hr)
  102. {
  103. dwRootMode = pTestChanceDF->GetRootMode();
  104. dwStgMode = pTestChanceDF->GetStgMode();
  105. DH_TRACE((
  106. DH_LVL_TRACE1,
  107. TEXT("Run Mode for SNBTEST_100, Access mode: %lx"),
  108. dwRootMode));
  109. }
  110. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  111. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  112. // and VirtualStmNodes.
  113. if (S_OK == hr)
  114. {
  115. pTestVirtualDF = new VirtualDF();
  116. if(NULL == pTestVirtualDF)
  117. {
  118. hr = E_OUTOFMEMORY;
  119. }
  120. }
  121. if (S_OK == hr)
  122. {
  123. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  124. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  125. }
  126. if (S_OK == hr)
  127. {
  128. DH_TRACE((
  129. DH_LVL_TRACE1,
  130. TEXT("DocFile - CreateFromParams - successfully created.")));
  131. }
  132. else
  133. {
  134. DH_TRACE((
  135. DH_LVL_TRACE1,
  136. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  137. hr));
  138. }
  139. // Get DG_STRING object pointer
  140. if (S_OK == hr)
  141. {
  142. pdgu = pTestVirtualDF->GetDataGenUnicode();
  143. DH_ASSERT(NULL != pdgu) ;
  144. }
  145. // Get DG_INTEGER object pointer
  146. if (S_OK == hr)
  147. {
  148. pdgi = pTestVirtualDF->GetDataGenInteger();
  149. DH_ASSERT(NULL != pdgi) ;
  150. }
  151. if (S_OK == hr)
  152. {
  153. hr = ParseVirtualDFAndCommitAllOpenStgs(
  154. pVirtualDFRoot,
  155. STGC_DEFAULT,
  156. NODE_EXC_TOPSTG);
  157. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  158. }
  159. // Commit root.
  160. if (S_OK == hr)
  161. {
  162. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  163. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  164. }
  165. if (S_OK == hr)
  166. {
  167. DH_TRACE((
  168. DH_LVL_TRACE1,
  169. TEXT("VirtualCtrNode::Commit completed successfully.")));
  170. }
  171. else
  172. {
  173. DH_TRACE((
  174. DH_LVL_TRACE1,
  175. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  176. hr));
  177. }
  178. // Release root and all open IStorages/IStreams pointers under it
  179. if (S_OK == hr)
  180. {
  181. hr = ParseVirtualDFAndCloseOpenStgsStms(
  182. pVirtualDFRoot,
  183. NODE_INC_TOPSTG);
  184. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  185. }
  186. if (S_OK == hr)
  187. {
  188. DH_TRACE((
  189. DH_LVL_TRACE1,
  190. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  191. }
  192. else
  193. {
  194. DH_TRACE((
  195. DH_LVL_TRACE1,
  196. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  197. hr));
  198. }
  199. // instantiate root docfile with snbExclude param = NULL
  200. if (S_OK == hr)
  201. {
  202. hr = pVirtualDFRoot->OpenRoot(
  203. NULL,
  204. dwRootMode,
  205. NULL,
  206. 0);
  207. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  208. }
  209. // exclude up to MAX_NAMES_TO_EXCLUDE names
  210. if (S_OK == hr)
  211. {
  212. snbNamesToExclude = (OLECHAR **) new OLECHAR[sizeof(OLECHAR *) *
  213. MAX_NAMES_TO_EXCLUDE];
  214. if (NULL == snbNamesToExclude)
  215. {
  216. hr = E_OUTOFMEMORY;
  217. }
  218. else
  219. {
  220. *snbNamesToExclude = NULL;
  221. }
  222. }
  223. // Traverse docfile(one level) and randomly select names to exclude upon
  224. // re-instantiation
  225. if (S_OK == hr)
  226. {
  227. hr = TraverseDocfileAndWriteOrReadSNB(
  228. pVirtualDFRoot,
  229. pdgi,
  230. pdgu,
  231. dwStgMode,
  232. snbNamesToExclude,
  233. FALSE,
  234. TRUE);
  235. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  236. }
  237. // Since no actual operations on child storages and streams, only need
  238. // commit and release root storage.
  239. // Commit root.
  240. if (S_OK == hr)
  241. {
  242. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  243. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  244. }
  245. if (S_OK == hr)
  246. {
  247. DH_TRACE((
  248. DH_LVL_TRACE1,
  249. TEXT("VirtualCtrNode::Commit completed successfully.")));
  250. }
  251. else
  252. {
  253. DH_TRACE((
  254. DH_LVL_TRACE1,
  255. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  256. hr));
  257. }
  258. // Release root
  259. if (S_OK == hr)
  260. {
  261. hr = pVirtualDFRoot->Close();
  262. }
  263. if (S_OK == hr)
  264. {
  265. DH_TRACE((
  266. DH_LVL_TRACE1,
  267. TEXT("VirtualCtrNode::Close completed successfully.")));
  268. }
  269. else
  270. {
  271. DH_TRACE((
  272. DH_LVL_TRACE1,
  273. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  274. hr));
  275. }
  276. // instantiate root docfile with snbExclude set to our SNB of names
  277. // to exclude
  278. if (S_OK == hr)
  279. {
  280. hr = pVirtualDFRoot->Open(NULL, dwRootMode, snbNamesToExclude, 0);
  281. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  282. }
  283. // Traverse docfile(one level) and check names returned against names
  284. // in exclude block
  285. if ((S_OK == hr) && (NULL != *snbNamesToExclude))
  286. {
  287. hr = TraverseDocfileAndWriteOrReadSNB(
  288. pVirtualDFRoot,
  289. pdgi,
  290. pdgu,
  291. dwStgMode,
  292. snbNamesToExclude,
  293. FALSE,
  294. FALSE);
  295. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  296. }
  297. if (S_OK == hr)
  298. {
  299. hr = ParseVirtualDFAndCommitAllOpenStgs(
  300. pVirtualDFRoot,
  301. STGC_DEFAULT,
  302. NODE_EXC_TOPSTG);
  303. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  304. }
  305. // Commit root.
  306. if (S_OK == hr)
  307. {
  308. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  309. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  310. }
  311. if (S_OK == hr)
  312. {
  313. DH_TRACE((
  314. DH_LVL_TRACE1,
  315. TEXT("VirtualCtrNode::Commit completed successfully.")));
  316. }
  317. else
  318. {
  319. DH_TRACE((
  320. DH_LVL_TRACE1,
  321. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  322. hr));
  323. }
  324. // Release root and all open IStorages/IStreams pointers under it
  325. if (S_OK == hr)
  326. {
  327. hr = ParseVirtualDFAndCloseOpenStgsStms(
  328. pVirtualDFRoot,
  329. NODE_INC_TOPSTG);
  330. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  331. }
  332. if (S_OK == hr)
  333. {
  334. DH_TRACE((
  335. DH_LVL_TRACE1,
  336. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  337. }
  338. else
  339. {
  340. DH_TRACE((
  341. DH_LVL_TRACE1,
  342. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  343. hr));
  344. }
  345. // if everything goes well, log test as passed else failed.
  346. if (S_OK == hr)
  347. {
  348. DH_LOG((LOG_PASS, TEXT("Test variation SNBTEST_100 passed.")) );
  349. }
  350. else
  351. {
  352. DH_LOG((LOG_FAIL,
  353. TEXT("Test variation SNBTEST_100 failed, hr = 0x%lx."),
  354. hr) );
  355. }
  356. // Cleanup
  357. // Get the name of file, will be used later to delete the file
  358. if(NULL != pVirtualDFRoot)
  359. {
  360. pRootDocFileName= new TCHAR[_tcslen(
  361. pTestVirtualDF->GetDocFileName())+1];
  362. if (NULL != pRootDocFileName)
  363. {
  364. _tcscpy(pRootDocFileName, pTestVirtualDF->GetDocFileName());
  365. }
  366. }
  367. // Delete Chance docfile tree
  368. if(NULL != pTestChanceDF)
  369. {
  370. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  371. pTestChanceDF->GetChanceDFRoot());
  372. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  373. delete pTestChanceDF;
  374. pTestChanceDF = NULL;
  375. }
  376. // Delete Virtual docfile tree
  377. if(NULL != pTestVirtualDF)
  378. {
  379. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  380. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  381. delete pTestVirtualDF;
  382. pTestVirtualDF = NULL;
  383. }
  384. // Free SNB
  385. if (NULL != snbNamesToExclude)
  386. {
  387. snbDelIndex = snbNamesToExclude;
  388. while (NULL != *snbDelIndex)
  389. {
  390. delete [] *snbDelIndex;
  391. *snbDelIndex = NULL;
  392. snbDelIndex++;
  393. }
  394. delete [] snbNamesToExclude;
  395. snbNamesToExclude = NULL;
  396. }
  397. // Delete the docfile on disk
  398. if((S_OK == hr) && (NULL != pRootDocFileName))
  399. {
  400. if(FALSE == DeleteFile(pRootDocFileName))
  401. {
  402. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  403. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  404. }
  405. }
  406. // Delete temp strings
  407. if(NULL != pRootDocFileName)
  408. {
  409. delete pRootDocFileName;
  410. pRootDocFileName = NULL;
  411. }
  412. // Stop logging the test
  413. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_100 finished")) );
  414. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  415. return hr;
  416. }
  417. //----------------------------------------------------------------------------
  418. //
  419. // Test: SNBTEST_101
  420. //
  421. // Synopsis: The created root docfile is instantiated and traversed and the
  422. // child objects found are selected at random for inclusion in an
  423. // snbExclude structure. 50% of the time, a bogus name is placed in
  424. // the snbExclude block instead. The test should verify that the
  425. // valid names were properly zeroed out, and that the bogus names in
  426. // the SNB block are ignored, i.e. don't cause an error.
  427. //
  428. // Arguments:[argc]
  429. // [argv]
  430. //
  431. // Returns: HRESULT
  432. //
  433. // History: 30-July-1996 JiminLi Created.
  434. //
  435. // Notes: This test runs in direct, transacted, and transacted deny write
  436. // modes
  437. //
  438. // New Test Notes:
  439. // 1. Old File: ILNORM.CXX
  440. // 2. Old name of test : IllegitLimitedInstNormal Test
  441. // New Name of test : SNBTEST_101
  442. // 3. To run the test, do the following at command prompt.
  443. // a. stgbase /seed:0 /dfdepth:1-2 /dfstg:1-3 /dfstm:0-3 /t:SNBTEST-101
  444. // /dfRootMode:dirReadWriteShEx /logloc:2 /traceloc:2 /labmode
  445. // b. stgbase /seed:0 /dfdepth:1-2 /dfstg:3-5 /dfstm:8-10 /t:SNBTEST-101
  446. // /dfRootMode:xactReadWriteShEx /logloc:2 /traceloc:2 /labmode
  447. // c. stgbase /seed:0 /dfdepth:1-2 /dfstg:1-3 /dfstm:6-9 /t:SNBTEST-101
  448. // /dfRootMode:xactReadWriteShDenyW /logloc:2 /traceloc:2 /labmode
  449. //
  450. // BUGNOTE: Conversion: SNBTEST-101 NO - not supported in nss
  451. //
  452. //-----------------------------------------------------------------------------
  453. HRESULT SNBTEST_101(int argc, char *argv[])
  454. {
  455. HRESULT hr = S_OK;
  456. HRESULT hr2 = S_OK;
  457. ChanceDF *pTestChanceDF = NULL;
  458. VirtualDF *pTestVirtualDF = NULL;
  459. VirtualCtrNode *pVirtualDFRoot = NULL;
  460. DG_STRING *pdgu = NULL;
  461. DG_INTEGER *pdgi = NULL;
  462. USHORT usErr = 0;
  463. LPTSTR pRootDocFileName = NULL;
  464. DWORD dwRootMode = 0;
  465. DWORD dwStgMode = 0;
  466. SNB snbNamesToExclude = NULL;
  467. SNB snbDelIndex = NULL;
  468. // Not for 2phase. Bail.
  469. if (DoingDistrib ())
  470. {
  471. return S_OK;
  472. }
  473. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("SNBTEST_101"));
  474. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  475. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_101 started.")) );
  476. DH_TRACE((DH_LVL_TRACE1,TEXT("Attempt illegitimate SNB tests on a docfile")));
  477. // Create the new ChanceDocFile tree that would consist of chance nodes.
  478. if (S_OK == hr)
  479. {
  480. pTestChanceDF = new ChanceDF();
  481. if(NULL == pTestChanceDF)
  482. {
  483. hr = E_OUTOFMEMORY;
  484. }
  485. }
  486. if (S_OK == hr)
  487. {
  488. hr = pTestChanceDF->CreateFromParams(argc, argv);
  489. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  490. }
  491. if (S_OK == hr)
  492. {
  493. dwRootMode = pTestChanceDF->GetRootMode();
  494. dwStgMode = pTestChanceDF->GetStgMode();
  495. DH_TRACE((
  496. DH_LVL_TRACE1,
  497. TEXT("Run Mode for SNBTEST_101, Access mode: %lx"),
  498. dwRootMode));
  499. }
  500. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  501. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  502. // and VirtualStmNodes.
  503. if (S_OK == hr)
  504. {
  505. pTestVirtualDF = new VirtualDF();
  506. if(NULL == pTestVirtualDF)
  507. {
  508. hr = E_OUTOFMEMORY;
  509. }
  510. }
  511. if (S_OK == hr)
  512. {
  513. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  514. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  515. }
  516. if (S_OK == hr)
  517. {
  518. DH_TRACE((
  519. DH_LVL_TRACE1,
  520. TEXT("DocFile - CreateFromParams - successfully created.")));
  521. }
  522. else
  523. {
  524. DH_TRACE((
  525. DH_LVL_TRACE1,
  526. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  527. hr));
  528. }
  529. // Get DG_STRING object pointer
  530. if (S_OK == hr)
  531. {
  532. pdgu = pTestVirtualDF->GetDataGenUnicode();
  533. DH_ASSERT(NULL != pdgu) ;
  534. }
  535. // Get DG_INTEGER object pointer
  536. if (S_OK == hr)
  537. {
  538. pdgi = pTestVirtualDF->GetDataGenInteger();
  539. DH_ASSERT(NULL != pdgi) ;
  540. }
  541. if (S_OK == hr)
  542. {
  543. hr = ParseVirtualDFAndCommitAllOpenStgs(
  544. pVirtualDFRoot,
  545. STGC_DEFAULT,
  546. NODE_EXC_TOPSTG);
  547. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  548. }
  549. // Commit root.
  550. if (S_OK == hr)
  551. {
  552. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  553. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  554. }
  555. if (S_OK == hr)
  556. {
  557. DH_TRACE((
  558. DH_LVL_TRACE1,
  559. TEXT("VirtualCtrNode::Commit completed successfully.")));
  560. }
  561. else
  562. {
  563. DH_TRACE((
  564. DH_LVL_TRACE1,
  565. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  566. hr));
  567. }
  568. // Release root and all open IStorages/IStreams pointers under it
  569. if (S_OK == hr)
  570. {
  571. hr = ParseVirtualDFAndCloseOpenStgsStms(
  572. pVirtualDFRoot,
  573. NODE_INC_TOPSTG);
  574. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  575. }
  576. if (S_OK == hr)
  577. {
  578. DH_TRACE((
  579. DH_LVL_TRACE1,
  580. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  581. }
  582. else
  583. {
  584. DH_TRACE((
  585. DH_LVL_TRACE1,
  586. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  587. hr));
  588. }
  589. // instantiate root docfile with snbExclude param = NULL
  590. if (S_OK == hr)
  591. {
  592. hr = pVirtualDFRoot->OpenRoot(
  593. NULL,
  594. dwRootMode,
  595. NULL,
  596. 0);
  597. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  598. }
  599. // exclude up to MAX_NAMES_TO_EXCLUDE names
  600. if (S_OK == hr)
  601. {
  602. snbNamesToExclude = (OLECHAR **) new OLECHAR[sizeof(OLECHAR *) *
  603. MAX_NAMES_TO_EXCLUDE];
  604. if (NULL == snbNamesToExclude)
  605. {
  606. hr = E_OUTOFMEMORY;
  607. }
  608. else
  609. {
  610. *snbNamesToExclude = NULL;
  611. }
  612. }
  613. // Traverse docfile(one level) and randomly select names to exclude upon
  614. // re-instantiation
  615. if (S_OK == hr)
  616. {
  617. hr = TraverseDocfileAndWriteOrReadSNB(
  618. pVirtualDFRoot,
  619. pdgi,
  620. pdgu,
  621. dwStgMode,
  622. snbNamesToExclude,
  623. TRUE,
  624. TRUE);
  625. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  626. }
  627. // Since no actual operations on child storages and streams, only need
  628. // commit and release root storage.
  629. // Commit root.
  630. if (S_OK == hr)
  631. {
  632. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  633. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  634. }
  635. if (S_OK == hr)
  636. {
  637. DH_TRACE((
  638. DH_LVL_TRACE1,
  639. TEXT("VirtualCtrNode::Commit completed successfully.")));
  640. }
  641. else
  642. {
  643. DH_TRACE((
  644. DH_LVL_TRACE1,
  645. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  646. hr));
  647. }
  648. // Release root
  649. if (S_OK == hr)
  650. {
  651. hr = pVirtualDFRoot->Close();
  652. }
  653. if (S_OK == hr)
  654. {
  655. DH_TRACE((
  656. DH_LVL_TRACE1,
  657. TEXT("VirtualCtrNode::Close completed successfully.")));
  658. }
  659. else
  660. {
  661. DH_TRACE((
  662. DH_LVL_TRACE1,
  663. TEXT("VirtualCtrNode::Close unsuccessful, hr=0x%lx."),
  664. hr));
  665. }
  666. // instantiate root docfile with snbExclude set to our SNB of names
  667. // to exclude
  668. if (S_OK == hr)
  669. {
  670. hr = pVirtualDFRoot->Open(NULL, dwRootMode, snbNamesToExclude, 0);
  671. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  672. }
  673. // Traverse docfile(one level) and check names returned against names
  674. // in exclude block
  675. if ((S_OK == hr) && (NULL != *snbNamesToExclude))
  676. {
  677. hr = TraverseDocfileAndWriteOrReadSNB(
  678. pVirtualDFRoot,
  679. pdgi,
  680. pdgu,
  681. dwStgMode,
  682. snbNamesToExclude,
  683. TRUE,
  684. FALSE);
  685. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  686. }
  687. if (S_OK == hr)
  688. {
  689. hr = ParseVirtualDFAndCommitAllOpenStgs(
  690. pVirtualDFRoot,
  691. STGC_DEFAULT,
  692. NODE_EXC_TOPSTG);
  693. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCommitAllOpenStgs")) ;
  694. }
  695. // Commit root.
  696. if (S_OK == hr)
  697. {
  698. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  699. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Commit")) ;
  700. }
  701. if (S_OK == hr)
  702. {
  703. DH_TRACE((
  704. DH_LVL_TRACE1,
  705. TEXT("VirtualCtrNode::Commit completed successfully.")));
  706. }
  707. else
  708. {
  709. DH_TRACE((
  710. DH_LVL_TRACE1,
  711. TEXT("VirtualCtrNode::Commit unsuccessful, hr=0x%lx."),
  712. hr));
  713. }
  714. // Release root and all open IStorages/IStreams pointers under it
  715. if (S_OK == hr)
  716. {
  717. hr = ParseVirtualDFAndCloseOpenStgsStms(
  718. pVirtualDFRoot,
  719. NODE_INC_TOPSTG);
  720. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  721. }
  722. if (S_OK == hr)
  723. {
  724. DH_TRACE((
  725. DH_LVL_TRACE1,
  726. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  727. }
  728. else
  729. {
  730. DH_TRACE((
  731. DH_LVL_TRACE1,
  732. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  733. hr));
  734. }
  735. // if everything goes well, log test as passed else failed.
  736. if (S_OK == hr)
  737. {
  738. DH_LOG((LOG_PASS, TEXT("Test variation SNBTEST_101 passed.")) );
  739. }
  740. else
  741. {
  742. DH_LOG((LOG_FAIL,
  743. TEXT("Test variation SNBTEST_101 failed, hr = 0x%lx."),
  744. hr) );
  745. }
  746. // Cleanup
  747. // Get the name of file, will be used later to delete the file
  748. if(NULL != pVirtualDFRoot)
  749. {
  750. pRootDocFileName= new TCHAR[_tcslen(
  751. pTestVirtualDF->GetDocFileName())+1];
  752. if (NULL != pRootDocFileName)
  753. {
  754. _tcscpy(pRootDocFileName, pTestVirtualDF->GetDocFileName());
  755. }
  756. }
  757. // Delete Chance docfile tree
  758. if(NULL != pTestChanceDF)
  759. {
  760. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  761. pTestChanceDF->GetChanceDFRoot());
  762. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  763. delete pTestChanceDF;
  764. pTestChanceDF = NULL;
  765. }
  766. // Delete Virtual docfile tree
  767. if(NULL != pTestVirtualDF)
  768. {
  769. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  770. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  771. delete pTestVirtualDF;
  772. pTestVirtualDF = NULL;
  773. }
  774. // Free SNB
  775. if (NULL != snbNamesToExclude)
  776. {
  777. snbDelIndex = snbNamesToExclude;
  778. while (NULL != *snbDelIndex)
  779. {
  780. delete [] *snbDelIndex;
  781. *snbDelIndex = NULL;
  782. snbDelIndex++;
  783. }
  784. delete [] snbNamesToExclude;
  785. snbNamesToExclude = NULL;
  786. }
  787. // Delete the docfile on disk
  788. if((S_OK == hr) && (NULL != pRootDocFileName))
  789. {
  790. if(FALSE == DeleteFile(pRootDocFileName))
  791. {
  792. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  793. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  794. }
  795. }
  796. // Delete temp strings
  797. if(NULL != pRootDocFileName)
  798. {
  799. delete pRootDocFileName;
  800. pRootDocFileName = NULL;
  801. }
  802. // Stop logging the test
  803. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_101 finished")) );
  804. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  805. return hr;
  806. }
  807. //----------------------------------------------------------------------------
  808. //
  809. // Test: SNBTEST_102
  810. //
  811. // Synopsis: The created root docfile is instantiated with STGM_PRIORITY
  812. // specified and then it is traversed and the child objects found
  813. // are selected at random for inclusion in an snbExclude structure.
  814. // Then the docfile is now re-instantiated using the just built SNB
  815. // and the original root IStorage passed as pstgPriority parameter.
  816. // This effectively removes the PRIORITY classification of this
  817. // docfile while excluding the possibility of an opening of the root
  818. // docfile by another process. The SNB that was passed in indicates
  819. // that the objects found in the SNB should be returned as empty
  820. // IStorages or zero length IStreams. The root docfile is then
  821. // traversed and each object returned that matches a name in the SNB
  822. // is verified to determine that it's empty or zero length.
  823. //
  824. // Arguments:[argc]
  825. // [argv]
  826. //
  827. // Returns: HRESULT
  828. //
  829. // History: 1-Aug-1996 JiminLi Created.
  830. //
  831. // Notes: This test runs in DIRECT mode only since DIRECT is the only
  832. // valid mode for a root instantiation with STGM_PRIORITY specified.
  833. //
  834. // New Test Notes:
  835. // 1. Old File: LLPRIOR.CXX
  836. // 2. Old name of test : LegitLimitedInstPriority Test
  837. // New Name of test : SNBTEST_102
  838. // 3. To run the test, do the following at command prompt.
  839. // a. stgbase /seed:0 /dfdepth:1-2 /dfstg:3-5 /dfstm:6-8 /t:SNBTEST-102
  840. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /logloc:2
  841. // /traceloc:2 /labmode
  842. //
  843. // BUGNOTE: Conversion: SNBTEST-102 NO - not supported in nss
  844. //
  845. //-----------------------------------------------------------------------------
  846. HRESULT SNBTEST_102(int argc, char* argv[])
  847. {
  848. HRESULT hr = S_OK;
  849. HRESULT hr2 = S_OK;
  850. ChanceDF *pTestChanceDF = NULL;
  851. VirtualDF *pTestVirtualDF = NULL;
  852. VirtualDF *pTestVirtualCopyDF = NULL;
  853. VirtualCtrNode *pVirtualDFRoot = NULL;
  854. VirtualCtrNode *pVirtualCopyDFRoot = NULL;
  855. DG_STRING *pdgu = NULL;
  856. DG_INTEGER *pdgi = NULL;
  857. USHORT usErr = 0;
  858. LPTSTR pRootDocFileName = NULL;
  859. LPTSTR pRootCopyDocFileName = NULL;
  860. LPSTORAGE pStgRootDF = NULL;
  861. LPSTORAGE pStgRootCopyDF = NULL;
  862. DWORD dwRootMode = 0;
  863. DWORD dwStgMode = 0;
  864. SNB snbNamesToExclude = NULL;
  865. SNB snbDelIndex = NULL;
  866. // Not for 2phase. Bail.
  867. if (DoingDistrib ())
  868. {
  869. return S_OK;
  870. }
  871. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("SNBTEST_102"));
  872. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  873. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_102 started.")) );
  874. DH_TRACE((DH_LVL_TRACE1,TEXT("Attempt legitimate SNB tests on a docfile")));
  875. // Create the new ChanceDocFile tree that would consist of chance nodes.
  876. if (S_OK == hr)
  877. {
  878. pTestChanceDF = new ChanceDF();
  879. if(NULL == pTestChanceDF)
  880. {
  881. hr = E_OUTOFMEMORY;
  882. }
  883. }
  884. if (S_OK == hr)
  885. {
  886. hr = pTestChanceDF->CreateFromParams(argc, argv);
  887. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  888. }
  889. if (S_OK == hr)
  890. {
  891. dwRootMode = pTestChanceDF->GetRootMode();
  892. dwStgMode = pTestChanceDF->GetStgMode();
  893. DH_TRACE((
  894. DH_LVL_TRACE1,
  895. TEXT("Run Mode for SNBTEST_102, Access mode: %lx"),
  896. dwRootMode));
  897. }
  898. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  899. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  900. // and VirtualStmNodes.
  901. if (S_OK == hr)
  902. {
  903. pTestVirtualDF = new VirtualDF();
  904. if(NULL == pTestVirtualDF)
  905. {
  906. hr = E_OUTOFMEMORY;
  907. }
  908. }
  909. if (S_OK == hr)
  910. {
  911. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  912. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  913. }
  914. if (S_OK == hr)
  915. {
  916. DH_TRACE((
  917. DH_LVL_TRACE1,
  918. TEXT("DocFile - CreateFromParams - successfully created.")));
  919. }
  920. else
  921. {
  922. DH_TRACE((
  923. DH_LVL_TRACE1,
  924. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  925. hr));
  926. }
  927. // Get the name of file, will be used later to delete the file
  928. if(NULL != pVirtualDFRoot)
  929. {
  930. pRootDocFileName = new TCHAR[_tcslen(pTestVirtualDF
  931. ->GetDocFileName())+1];
  932. if (NULL != pRootDocFileName)
  933. {
  934. _tcscpy(pRootDocFileName, pTestVirtualDF->GetDocFileName());
  935. }
  936. }
  937. // Get DG_STRING object pointer
  938. if (S_OK == hr)
  939. {
  940. pdgu = pTestVirtualDF->GetDataGenUnicode();
  941. DH_ASSERT(NULL != pdgu) ;
  942. }
  943. // Get DG_INTEGER object pointer
  944. if (S_OK == hr)
  945. {
  946. pdgi = pTestVirtualDF->GetDataGenInteger();
  947. DH_ASSERT(NULL != pdgi) ;
  948. }
  949. // Release root and all open IStorages/IStreams pointers under it
  950. if (S_OK == hr)
  951. {
  952. hr = ParseVirtualDFAndCloseOpenStgsStms(
  953. pVirtualDFRoot,
  954. NODE_INC_TOPSTG);
  955. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  956. }
  957. if (S_OK == hr)
  958. {
  959. DH_TRACE((
  960. DH_LVL_TRACE1,
  961. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  962. }
  963. else
  964. {
  965. DH_TRACE((
  966. DH_LVL_TRACE1,
  967. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  968. hr));
  969. }
  970. // instantiate root docfile with snbExclude param = NULL
  971. if (S_OK == hr)
  972. {
  973. hr = pVirtualDFRoot->Open(
  974. NULL,
  975. STGM_READ | STGM_DIRECT | STGM_PRIORITY,
  976. NULL,
  977. 0);
  978. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  979. }
  980. if (S_OK == hr)
  981. {
  982. pStgRootDF = pVirtualDFRoot->GetIStoragePointer();
  983. DH_ASSERT(NULL != pStgRootDF);
  984. }
  985. // exclude up to MAX_NAMES_TO_EXCLUDE names
  986. if (S_OK == hr)
  987. {
  988. snbNamesToExclude = (OLECHAR **) new OLECHAR[sizeof(OLECHAR *) *
  989. MAX_NAMES_TO_EXCLUDE];
  990. if (NULL == snbNamesToExclude)
  991. {
  992. hr = E_OUTOFMEMORY;
  993. }
  994. *snbNamesToExclude = NULL;
  995. }
  996. // Traverse docfile(one level) and randomly select names to exclude upon
  997. // re-instantiation
  998. if (S_OK == hr)
  999. {
  1000. hr = TraverseDocfileAndWriteOrReadSNB(
  1001. pVirtualDFRoot,
  1002. pdgi,
  1003. pdgu,
  1004. dwStgMode,
  1005. snbNamesToExclude,
  1006. FALSE,
  1007. TRUE);
  1008. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  1009. }
  1010. // Generate a copy of the original docfile
  1011. if (S_OK == hr)
  1012. {
  1013. hr = pTestVirtualDF->CopyVirtualDocFileTree(
  1014. pVirtualDFRoot,
  1015. NEW_STGSTM,
  1016. &pVirtualCopyDFRoot);
  1017. DH_ASSERT(NULL != pVirtualCopyDFRoot);
  1018. DH_HRCHECK(hr, TEXT("VirtualDF::CopyVirtualDocFileTree"));
  1019. }
  1020. // Create a new VirtualDF tree
  1021. if (S_OK == hr)
  1022. {
  1023. pTestVirtualCopyDF = new VirtualDF();
  1024. if(NULL == pTestVirtualCopyDF)
  1025. {
  1026. hr = E_OUTOFMEMORY;
  1027. }
  1028. }
  1029. // instantiate root docfile with snbExclude set to our SNB of names
  1030. // to exclude and also pass in previous opening of this root docfile
  1031. // as parameter pstgPriority.
  1032. // The reason of AddRefCount is Ole code just release pStgRootDF once,
  1033. // and it's user's responsibility to release all references to it and
  1034. // finally set it to NULL.
  1035. if (S_OK == hr)
  1036. {
  1037. hr = pVirtualDFRoot->AddRefCount();
  1038. DH_HRCHECK(hr, TEXT("VirtualCtrNode::AddRefCount"));
  1039. }
  1040. if (S_OK == hr)
  1041. {
  1042. hr = pVirtualCopyDFRoot->Open(
  1043. pStgRootDF,
  1044. STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_DENY_NONE,
  1045. snbNamesToExclude,
  1046. 0);
  1047. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  1048. }
  1049. if (S_OK == hr)
  1050. {
  1051. hr = pVirtualDFRoot->Close();
  1052. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  1053. }
  1054. if (S_OK == hr)
  1055. {
  1056. pStgRootCopyDF = pVirtualCopyDFRoot->GetIStoragePointer();
  1057. DH_ASSERT(NULL != pStgRootCopyDF);
  1058. }
  1059. // Assocaies a VirtualDF tree with a VirtualCtrNode and its _pstg
  1060. // The purpose it later on we can delete the related space taken
  1061. // by the copied docfile.
  1062. if (S_OK == hr)
  1063. {
  1064. hr = pTestVirtualCopyDF->Associate(pVirtualCopyDFRoot, pStgRootCopyDF);
  1065. DH_HRCHECK(hr, TEXT("pTestVirtualCopyDF::Associate"));
  1066. }
  1067. // Traverse docfile(one level) and check names returned against names
  1068. // in exclude block
  1069. if ((S_OK == hr) && (NULL != *snbNamesToExclude))
  1070. {
  1071. hr = TraverseDocfileAndWriteOrReadSNB(
  1072. pVirtualCopyDFRoot,
  1073. pdgi,
  1074. pdgu,
  1075. dwStgMode,
  1076. snbNamesToExclude,
  1077. FALSE,
  1078. FALSE);
  1079. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  1080. }
  1081. // Release the copied root and all open IStorages/IStreams
  1082. // pointers under it. Note: now the original VirtualDFRoot is
  1083. // not valid any more.
  1084. if (S_OK == hr)
  1085. {
  1086. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1087. pVirtualCopyDFRoot,
  1088. NODE_INC_TOPSTG);
  1089. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1090. }
  1091. if (S_OK == hr)
  1092. {
  1093. DH_TRACE((
  1094. DH_LVL_TRACE1,
  1095. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  1096. }
  1097. else
  1098. {
  1099. DH_TRACE((
  1100. DH_LVL_TRACE1,
  1101. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  1102. hr));
  1103. }
  1104. // if everything goes well, log test as passed else failed.
  1105. if (S_OK == hr)
  1106. {
  1107. DH_LOG((LOG_PASS, TEXT("Test variation SNBTEST_102 passed.")) );
  1108. }
  1109. else
  1110. {
  1111. DH_LOG((LOG_FAIL,
  1112. TEXT("Test variation SNBTEST_102 failed, hr = 0x%lx."),
  1113. hr) );
  1114. }
  1115. // Cleanup
  1116. // Get the name of file, will be used later to delete the file
  1117. if(NULL != pVirtualCopyDFRoot && pTestVirtualCopyDF->GetDocFileName())
  1118. {
  1119. pRootCopyDocFileName = new TCHAR[_tcslen(pTestVirtualCopyDF
  1120. ->GetDocFileName())+1];
  1121. if (NULL != pRootCopyDocFileName)
  1122. {
  1123. _tcscpy(pRootCopyDocFileName, pTestVirtualCopyDF->GetDocFileName());
  1124. }
  1125. }
  1126. // Delete Chance docfile tree
  1127. if(NULL != pTestChanceDF)
  1128. {
  1129. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1130. pTestChanceDF->GetChanceDFRoot());
  1131. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1132. delete pTestChanceDF;
  1133. pTestChanceDF = NULL;
  1134. }
  1135. // Delete Virtual docfile tree
  1136. if(NULL != pTestVirtualDF)
  1137. {
  1138. hr = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1139. DH_HRCHECK(hr, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  1140. delete pTestVirtualDF;
  1141. pTestVirtualDF = NULL;
  1142. }
  1143. if(NULL != pTestVirtualCopyDF)
  1144. {
  1145. hr2 = pTestVirtualCopyDF->DeleteVirtualDocFileTree(pVirtualCopyDFRoot);
  1146. DH_HRCHECK(hr2, TEXT("pTestVirtualCopyDF->DeleteVirtualFileDocTree")) ;
  1147. delete pTestVirtualCopyDF;
  1148. pTestVirtualCopyDF = NULL;
  1149. }
  1150. // Free SNB
  1151. if (NULL != snbNamesToExclude)
  1152. {
  1153. snbDelIndex = snbNamesToExclude;
  1154. while (NULL != *snbDelIndex)
  1155. {
  1156. delete [] *snbDelIndex;
  1157. *snbDelIndex = NULL;
  1158. snbDelIndex++;
  1159. }
  1160. delete [] snbNamesToExclude;
  1161. snbNamesToExclude = NULL;
  1162. }
  1163. // Delete the docfile on disk
  1164. if ((S_OK == hr) && (NULL != pRootDocFileName))
  1165. {
  1166. if(FALSE == DeleteFile(pRootDocFileName))
  1167. {
  1168. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1169. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1170. }
  1171. }
  1172. // Delete temp strings
  1173. if (NULL != pRootDocFileName)
  1174. {
  1175. delete pRootDocFileName;
  1176. pRootDocFileName = NULL;
  1177. }
  1178. if (NULL != pRootCopyDocFileName)
  1179. {
  1180. delete pRootCopyDocFileName;
  1181. pRootCopyDocFileName = NULL;
  1182. }
  1183. // Stop logging the test
  1184. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_102 finished")) );
  1185. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1186. return hr;
  1187. }
  1188. //----------------------------------------------------------------------------
  1189. //
  1190. // Test: SNBTEST_103
  1191. //
  1192. // Synopsis: The created root docfile is instantiated with STGM_PRIORITY
  1193. // specified and then it is traversed and the child objects found
  1194. // are selected at random for inclusion in an snbExclude structure.
  1195. // 50% of the time, a bogus name is placed in the snbExclude block
  1196. // instead. The docfile is then re-instantiated using the just built
  1197. // SNB and the original root IStorage passed as pstgPriority
  1198. // parameter. The root docfile is then traversed and the test should
  1199. // verify that the valid names were properly zeroed out, and that
  1200. // the bogus names in the SNB block are ignored, i.e. do not cause
  1201. // an error.
  1202. //
  1203. // Arguments:[argc]
  1204. // [argv]
  1205. //
  1206. // Returns: HRESULT
  1207. //
  1208. // History: 3-Aug-1996 JiminLi Created.
  1209. //
  1210. // Notes: This test runs in DIRECT mode only since DIRECT is the only
  1211. // valid mode for a root instantiation with STGM_PRIORITY specified.
  1212. //
  1213. // New Test Notes:
  1214. // 1. Old File: ILPRIOR.CXX
  1215. // 2. Old name of test : IllegitLimitedInstPriority Test
  1216. // New Name of test : SNBTEST_103
  1217. // 3. To run the test, do the following at command prompt.
  1218. // a. stgbase /seed:0 /dfdepth:1-2 /dfstg:3-5 /dfstm:6-8 /t:SNBTEST-103
  1219. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx /logloc:2
  1220. // /traceloc:2 /labmode
  1221. //
  1222. // BUGNOTE: Conversion: SNBTEST-103 NO - not supported in nss
  1223. //
  1224. //-----------------------------------------------------------------------------
  1225. HRESULT SNBTEST_103(int argc, char* argv[])
  1226. {
  1227. HRESULT hr = S_OK;
  1228. HRESULT hr2 = S_OK;
  1229. ChanceDF *pTestChanceDF = NULL;
  1230. VirtualDF *pTestVirtualDF = NULL;
  1231. VirtualDF *pTestVirtualCopyDF = NULL;
  1232. VirtualCtrNode *pVirtualDFRoot = NULL;
  1233. VirtualCtrNode *pVirtualCopyDFRoot = NULL;
  1234. VirtualCtrNode *pVirtualChildStg = NULL;
  1235. DG_STRING *pdgu = NULL;
  1236. DG_INTEGER *pdgi = NULL;
  1237. USHORT usErr = 0;
  1238. LPTSTR pRootDocFileName = NULL;
  1239. LPTSTR pRootCopyDocFileName = NULL;
  1240. LPSTORAGE pStgRootDF = NULL;
  1241. LPSTORAGE pStgChild = NULL;
  1242. LPSTORAGE pStgRootCopyDF = NULL;
  1243. DWORD dwRootMode = 0;
  1244. DWORD dwStgMode = 0;
  1245. SNB snbNamesToExclude = NULL;
  1246. SNB snbDelIndex = NULL;
  1247. // Not for 2phase. Bail.
  1248. if (DoingDistrib ())
  1249. {
  1250. return S_OK;
  1251. }
  1252. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("SNBTEST_103"));
  1253. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1254. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_103 started.")) );
  1255. DH_TRACE((
  1256. DH_LVL_TRACE1,
  1257. TEXT("Attempt legitimate STGM_PRIORITY related test on a docfile")));
  1258. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1259. if (S_OK == hr)
  1260. {
  1261. pTestChanceDF = new ChanceDF();
  1262. if(NULL == pTestChanceDF)
  1263. {
  1264. hr = E_OUTOFMEMORY;
  1265. }
  1266. }
  1267. if (S_OK == hr)
  1268. {
  1269. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1270. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1271. }
  1272. if (S_OK == hr)
  1273. {
  1274. dwRootMode = pTestChanceDF->GetRootMode();
  1275. dwStgMode = pTestChanceDF->GetStgMode();
  1276. DH_TRACE((
  1277. DH_LVL_TRACE1,
  1278. TEXT("Run Mode for SNBTEST_103, Access mode: %lx"),
  1279. dwRootMode));
  1280. }
  1281. // Create the VirtualDocFile tree from the ChanceDocFile tree created in
  1282. // the previous step. The VirtualDocFile tree consists of VirtualCtrNodes
  1283. // and VirtualStmNodes.
  1284. if (S_OK == hr)
  1285. {
  1286. pTestVirtualDF = new VirtualDF();
  1287. if(NULL == pTestVirtualDF)
  1288. {
  1289. hr = E_OUTOFMEMORY;
  1290. }
  1291. }
  1292. if (S_OK == hr)
  1293. {
  1294. hr = pTestVirtualDF->GenerateVirtualDF(pTestChanceDF, &pVirtualDFRoot);
  1295. DH_HRCHECK(hr, TEXT("pTestVirtualDF->GenerateVirtualDF")) ;
  1296. }
  1297. if (S_OK == hr)
  1298. {
  1299. DH_TRACE((
  1300. DH_LVL_TRACE1,
  1301. TEXT("DocFile - CreateFromParams - successfully created.")));
  1302. }
  1303. else
  1304. {
  1305. DH_TRACE((
  1306. DH_LVL_TRACE1,
  1307. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  1308. hr));
  1309. }
  1310. // Get the name of file, will be used later to delete the file
  1311. if(NULL != pVirtualDFRoot)
  1312. {
  1313. pRootDocFileName = new TCHAR[_tcslen(
  1314. pTestVirtualDF->GetDocFileName())+1];
  1315. if (NULL != pRootDocFileName)
  1316. {
  1317. _tcscpy(pRootDocFileName, pTestVirtualDF->GetDocFileName());
  1318. }
  1319. }
  1320. // Get DG_STRING object pointer
  1321. if (S_OK == hr)
  1322. {
  1323. pdgu = pTestVirtualDF->GetDataGenUnicode();
  1324. DH_ASSERT(NULL != pdgu) ;
  1325. }
  1326. // Get DG_INTEGER object pointer
  1327. if (S_OK == hr)
  1328. {
  1329. pdgi = pTestVirtualDF->GetDataGenInteger();
  1330. DH_ASSERT(NULL != pdgi) ;
  1331. }
  1332. // Get the first child storage pointer for later illegitmate test,
  1333. if (S_OK == hr)
  1334. {
  1335. pVirtualChildStg = pVirtualDFRoot->GetFirstChildVirtualCtrNode();
  1336. DH_ASSERT(NULL != pVirtualChildStg);
  1337. pStgChild = pVirtualChildStg->GetIStoragePointer();
  1338. DH_ASSERT(NULL != pStgChild);
  1339. }
  1340. // Release root and all open IStorages/IStreams pointers under it
  1341. if (S_OK == hr)
  1342. {
  1343. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1344. pVirtualDFRoot,
  1345. NODE_INC_TOPSTG);
  1346. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1347. }
  1348. if (S_OK == hr)
  1349. {
  1350. DH_TRACE((
  1351. DH_LVL_TRACE1,
  1352. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  1353. }
  1354. else
  1355. {
  1356. DH_TRACE((
  1357. DH_LVL_TRACE1,
  1358. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  1359. hr));
  1360. }
  1361. // instantiate root docfile with snbExclude param = NULL, and also
  1362. // STGM_PRIORITY is set in grfMode.
  1363. if (S_OK == hr)
  1364. {
  1365. hr = pVirtualDFRoot->OpenRoot(
  1366. NULL,
  1367. STGM_READ | STGM_DIRECT | STGM_PRIORITY,
  1368. NULL,
  1369. 0);
  1370. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  1371. }
  1372. if (S_OK == hr)
  1373. {
  1374. pStgRootDF = pVirtualDFRoot->GetIStoragePointer();
  1375. DH_ASSERT(NULL != pStgRootDF);
  1376. }
  1377. // exclude up to MAX_NAMES_TO_EXCLUDE names
  1378. if (S_OK == hr)
  1379. {
  1380. snbNamesToExclude = (OLECHAR **) new OLECHAR[sizeof(OLECHAR *) *
  1381. MAX_NAMES_TO_EXCLUDE];
  1382. if (NULL == snbNamesToExclude)
  1383. {
  1384. hr = E_OUTOFMEMORY;
  1385. }
  1386. else
  1387. {
  1388. *snbNamesToExclude = NULL;
  1389. }
  1390. }
  1391. // Traverse docfile(one level) and randomly select names to exclude upon
  1392. // re-instantiation. The sixth param == TRUE shows that this is an
  1393. // illegit test, i.e. 50% chance we will add bogus names into SNB.
  1394. if (S_OK == hr)
  1395. {
  1396. hr = TraverseDocfileAndWriteOrReadSNB(
  1397. pVirtualDFRoot,
  1398. pdgi,
  1399. pdgu,
  1400. dwStgMode,
  1401. snbNamesToExclude,
  1402. TRUE,
  1403. TRUE);
  1404. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  1405. }
  1406. // Generate a copy of the original docfile
  1407. if (S_OK == hr)
  1408. {
  1409. hr = pTestVirtualDF->CopyVirtualDocFileTree(
  1410. pVirtualDFRoot,
  1411. NEW_STGSTM,
  1412. &pVirtualCopyDFRoot);
  1413. DH_ASSERT(NULL != pVirtualCopyDFRoot);
  1414. DH_HRCHECK(hr, TEXT("VirtualDF::CopyVirtualDocFileTree"));
  1415. }
  1416. // Create a new VirtualDF tree
  1417. if (S_OK == hr)
  1418. {
  1419. pTestVirtualCopyDF = new VirtualDF();
  1420. if(NULL == pTestVirtualCopyDF)
  1421. {
  1422. hr = E_OUTOFMEMORY;
  1423. }
  1424. }
  1425. // instantiate root docfile with snbExclude set to our SNB of names
  1426. // to exclude and also pass in previous opening of this root docfile
  1427. // as parameter pstgPriority.
  1428. // First we passed in the substorage pointer as pstgPriority parameter,
  1429. // it is closed, so it should fail.
  1430. #ifdef _MAC
  1431. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!Opening a VirtualCtrNode with invalid substorage ptr. skipped")) );
  1432. #else
  1433. if (S_OK == hr)
  1434. {
  1435. hr = pVirtualDFRoot->Open(
  1436. pStgChild,
  1437. dwRootMode,
  1438. snbNamesToExclude,
  1439. 0);
  1440. if (S_OK != hr)
  1441. {
  1442. DH_TRACE((
  1443. DH_LVL_TRACE1,
  1444. TEXT("VirtualCtrNode::Open failed as expected, hr=0x%lx."),
  1445. hr));
  1446. hr = S_OK;
  1447. }
  1448. else
  1449. {
  1450. DH_TRACE((
  1451. DH_LVL_TRACE1,
  1452. TEXT("VirtualCtrNode::Open should have failed.")));
  1453. hr = E_FAIL;
  1454. }
  1455. }
  1456. #endif //_MAC
  1457. // Now we passed in correct storage pointer and have illegimate
  1458. // SNB test. The reason of AddRefCount is Ole code just release
  1459. // pStgRootDF once, and it's user's responsibility to release all
  1460. // references to it and finally set it to NULL.
  1461. if (S_OK == hr)
  1462. {
  1463. hr = pVirtualDFRoot->AddRefCount();
  1464. DH_HRCHECK(hr, TEXT("VirtualCtrNode::AddRefCount"));
  1465. }
  1466. if (S_OK == hr)
  1467. {
  1468. hr = pVirtualCopyDFRoot->Open(
  1469. pStgRootDF,
  1470. STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_DENY_NONE,
  1471. snbNamesToExclude,
  1472. 0);
  1473. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Open"));
  1474. }
  1475. if (S_OK == hr)
  1476. {
  1477. hr = pVirtualDFRoot->Close();
  1478. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  1479. }
  1480. if (S_OK == hr)
  1481. {
  1482. pStgRootCopyDF = pVirtualCopyDFRoot->GetIStoragePointer();
  1483. DH_ASSERT(NULL != pStgRootCopyDF);
  1484. }
  1485. // Assocaies a VirtualDF tree with a VirtualCtrNode and its _pstg
  1486. // The purpose it later on we can delete the related space taken
  1487. // by the copied docfile.
  1488. if (S_OK == hr)
  1489. {
  1490. hr = pTestVirtualCopyDF->Associate(pVirtualCopyDFRoot, pStgRootCopyDF);
  1491. DH_HRCHECK(hr, TEXT("pTestVirtualCopyDF::Associate"));
  1492. }
  1493. // Traverse docfile(one level) and check names returned against names
  1494. // in exclude block
  1495. if ((S_OK == hr) && (NULL != *snbNamesToExclude))
  1496. {
  1497. hr = TraverseDocfileAndWriteOrReadSNB(
  1498. pVirtualCopyDFRoot,
  1499. pdgi,
  1500. pdgu,
  1501. dwStgMode,
  1502. snbNamesToExclude,
  1503. FALSE,
  1504. FALSE);
  1505. DH_HRCHECK(hr, TEXT("TraverseDocfileAndWriteOrReadSNB"));
  1506. }
  1507. // Release the copied root and all open IStorages/IStreams
  1508. // pointers under it. Note: now the original VirtualDFRoot is
  1509. // not valid any more.
  1510. if (S_OK == hr)
  1511. {
  1512. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1513. pVirtualCopyDFRoot,
  1514. NODE_INC_TOPSTG);
  1515. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1516. }
  1517. if (S_OK == hr)
  1518. {
  1519. DH_TRACE((
  1520. DH_LVL_TRACE1,
  1521. TEXT("ParseVirtualDFAndCloseOpenStgsStms completed Ok.")));
  1522. }
  1523. else
  1524. {
  1525. DH_TRACE((
  1526. DH_LVL_TRACE1,
  1527. TEXT("ParseVirtualDFAndCloseOpenStgsStms not Ok, hr=0x%lx."),
  1528. hr));
  1529. }
  1530. // if everything goes well, log test as passed else failed.
  1531. if (S_OK == hr)
  1532. {
  1533. DH_LOG((LOG_PASS, TEXT("Test variation SNBTEST_103 passed.")) );
  1534. }
  1535. else
  1536. {
  1537. DH_LOG((LOG_FAIL,
  1538. TEXT("Test variation SNBTEST_103 failed, hr = 0x%lx."),
  1539. hr) );
  1540. }
  1541. // Cleanup
  1542. // Get the name of file, will be used later to delete the file
  1543. if ((S_OK == hr) && (NULL != pVirtualCopyDFRoot))
  1544. {
  1545. pRootCopyDocFileName = new TCHAR[_tcslen(pTestVirtualCopyDF
  1546. ->GetDocFileName())+1];
  1547. if (NULL != pRootCopyDocFileName)
  1548. {
  1549. _tcscpy(pRootCopyDocFileName, pTestVirtualCopyDF->GetDocFileName());
  1550. }
  1551. }
  1552. // Delete Chance docfile tree
  1553. if(NULL != pTestChanceDF)
  1554. {
  1555. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1556. pTestChanceDF->GetChanceDFRoot());
  1557. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1558. delete pTestChanceDF;
  1559. pTestChanceDF = NULL;
  1560. }
  1561. // Delete Virtual docfile tree
  1562. if(NULL != pTestVirtualDF)
  1563. {
  1564. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1565. DH_HRCHECK(hr2, TEXT("pTestVirtualDF->DeleteVirtualFileDocTree")) ;
  1566. delete pTestVirtualDF;
  1567. pTestVirtualDF = NULL;
  1568. }
  1569. if ((S_OK == hr) && (NULL != pTestVirtualCopyDF))
  1570. {
  1571. hr2 = pTestVirtualCopyDF->DeleteVirtualDocFileTree(pVirtualCopyDFRoot);
  1572. DH_HRCHECK(hr2, TEXT("pTestVirtualCopyDF->DeleteVirtualFileDocTree")) ;
  1573. delete pTestVirtualCopyDF;
  1574. pTestVirtualCopyDF = NULL;
  1575. }
  1576. // Free SNB
  1577. if (NULL != snbNamesToExclude)
  1578. {
  1579. snbDelIndex = snbNamesToExclude;
  1580. while (NULL != *snbDelIndex)
  1581. {
  1582. delete [] *snbDelIndex;
  1583. *snbDelIndex = NULL;
  1584. snbDelIndex++;
  1585. }
  1586. delete [] snbNamesToExclude;
  1587. snbNamesToExclude = NULL;
  1588. }
  1589. // Delete the docfile on disk
  1590. if ((S_OK == hr) && (NULL != pRootDocFileName))
  1591. {
  1592. if(FALSE == DeleteFile(pRootDocFileName))
  1593. {
  1594. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1595. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1596. }
  1597. }
  1598. // Delete temp strings
  1599. if (NULL != pRootDocFileName)
  1600. {
  1601. delete pRootDocFileName;
  1602. pRootDocFileName = NULL;
  1603. }
  1604. if (NULL != pRootCopyDocFileName)
  1605. {
  1606. delete pRootCopyDocFileName;
  1607. pRootCopyDocFileName = NULL;
  1608. }
  1609. // Stop logging the test
  1610. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation SNBTEST_103 finished")) );
  1611. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1612. return hr;
  1613. }