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.

3346 lines
87 KiB

  1. -------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: ilkbtsts.cxx
  7. //
  8. // Contents: storage base tests basically pertaining to ILockBytes
  9. //
  10. // Functions:
  11. //
  12. // History: 31-July-1996 NarindK Created.
  13. // 27-Mar-97 SCousens Conversionified
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <dfheader.hxx>
  17. #pragma hdrstop
  18. #include "init.hxx"
  19. #include "ilkbhdr.hxx"
  20. //----------------------------------------------------------------------------
  21. //
  22. // Test: ILKBTEST_100
  23. //
  24. // synopsis: The test first creates an ILockBytes instance and then uses this
  25. // ILockBytes instead of OLE provided ILockBytes file in the under
  26. // lying file system. Thus the root DocFile is created upon a
  27. // ILockBytes instead of a file system file, therby exercising the
  28. // ILockBytes functionality.
  29. //
  30. // Arguments:[argc]
  31. // [argv]
  32. //
  33. // Returns: HRESULT
  34. //
  35. // History: 31-July-1996 NarindK Created.
  36. //
  37. // Notes: This test runs in direct, transacted, and transacted deny write
  38. // modes
  39. //
  40. // New Test Notes:
  41. // 1. Old File: DFLIB.CXX
  42. // 2. Old name of test : DfSetUpOnILockBytes Test
  43. // New Name of test : ILKBTEST_100
  44. // 3. To run the test, do the following at command prompt.
  45. // a. stgbase /seed:0 /t:ILKBTEST-100 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  46. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  47. // b. stgbase /seed:0 /t:ILKBTEST-100 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  48. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  49. // c. stgbase /seed:0 /t:ILKBTEST-100 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  50. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  51. //
  52. // BUGNOTE: Conversion: ILKBTEST-100 NO - not supported in nss
  53. //
  54. //-----------------------------------------------------------------------------
  55. HRESULT ILKBTEST_100(int argc, char *argv[])
  56. {
  57. HRESULT hr = S_OK;
  58. HRESULT hr2 = S_OK;
  59. ChanceDF *pTestChanceDF = NULL;
  60. ILockBytesDF *pTestILockBytesDF = NULL;
  61. VirtualCtrNode *pVirtualDFRoot = NULL;
  62. DWORD dwRootMode = 0;
  63. DWORD dwStgMode = 0;
  64. LPTSTR pFileName = NULL;
  65. ULONG ulRef = 0;
  66. DWORD dwCRC1 = 0;
  67. DWORD dwCRC2 = 0;
  68. LPSTORAGE pStgRoot1 = NULL;
  69. LPSTORAGE pStgRootOnILockBytes = NULL;
  70. CFileBytes *pCFileBytes = NULL;
  71. // Not for 2phase. Bail.
  72. if (DoingDistrib ())
  73. {
  74. return S_OK;
  75. }
  76. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_100"));
  77. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  78. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_100 started.")) );
  79. DH_TRACE((
  80. DH_LVL_TRACE1,
  81. TEXT("ILockBytes test - Creating DocFile on ILockBytes")));
  82. // Create the new ChanceDocFile tree that would consist of chance nodes.
  83. if (S_OK == hr)
  84. {
  85. pTestChanceDF = new ChanceDF();
  86. if(NULL == pTestChanceDF)
  87. {
  88. hr = E_OUTOFMEMORY;
  89. }
  90. }
  91. if (S_OK == hr)
  92. {
  93. hr = pTestChanceDF->CreateFromParams(argc, argv);
  94. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  95. }
  96. if (S_OK == hr)
  97. {
  98. dwRootMode = pTestChanceDF->GetRootMode();
  99. dwStgMode = pTestChanceDF->GetStgMode();
  100. DH_TRACE((
  101. DH_LVL_TRACE1,
  102. TEXT("Run Mode for ILKBTEST_100, Access mode: %lx"),
  103. dwRootMode));
  104. }
  105. // Create the DocFile tree based on ChanceDocFile tree created in
  106. // previous step
  107. if (S_OK == hr)
  108. {
  109. pTestILockBytesDF = new ILockBytesDF();
  110. if(NULL == pTestILockBytesDF)
  111. {
  112. hr = E_OUTOFMEMORY;
  113. }
  114. }
  115. if (S_OK == hr)
  116. {
  117. hr = pTestILockBytesDF->GenerateVirtualDF(
  118. pTestChanceDF,
  119. &pVirtualDFRoot);
  120. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  121. }
  122. if(S_OK == hr)
  123. {
  124. DH_TRACE((
  125. DH_LVL_TRACE1,
  126. TEXT("StgCreateDocFileOnILockBytes passed as exp.")));
  127. DH_TRACE((
  128. DH_LVL_TRACE1,
  129. TEXT("DocFile - CreateFromParams - successfully created.")));
  130. }
  131. else
  132. {
  133. DH_TRACE((
  134. DH_LVL_TRACE1,
  135. TEXT("StgCreateDocFileOnILockBytes failed unexp, hr = 0x%lx."),
  136. hr));
  137. DH_TRACE((
  138. DH_LVL_TRACE1,
  139. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  140. hr));
  141. }
  142. // Commit all storages/streams
  143. if (S_OK == hr)
  144. {
  145. hr = ParseVirtualDFAndCommitAllOpenStgs(
  146. pVirtualDFRoot,
  147. STGC_DEFAULT,
  148. NODE_INC_TOPSTG);
  149. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  150. }
  151. if(S_OK == hr)
  152. {
  153. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  154. }
  155. else
  156. {
  157. DH_TRACE((
  158. DH_LVL_TRACE1,
  159. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  160. hr));
  161. }
  162. // Release all substorages/streams too
  163. if (S_OK == hr)
  164. {
  165. hr = ParseVirtualDFAndCloseOpenStgsStms(
  166. pVirtualDFRoot,
  167. NODE_EXC_TOPSTG);
  168. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  169. }
  170. if(S_OK == hr)
  171. {
  172. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  173. }
  174. else
  175. {
  176. DH_TRACE((
  177. DH_LVL_TRACE1,
  178. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  179. hr));
  180. }
  181. // Get the original CRC of docfile
  182. if(S_OK == hr)
  183. {
  184. pStgRoot1 = pVirtualDFRoot->GetIStoragePointer();
  185. DH_ASSERT(NULL != pStgRoot1);
  186. hr = CalculateCRCForDocFile(pStgRoot1,VERIFY_INC_TOPSTG_NAME,&dwCRC1);
  187. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  188. }
  189. // Close the Root
  190. if(S_OK == hr)
  191. {
  192. hr = pVirtualDFRoot->Close();
  193. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  194. pStgRoot1 = NULL;
  195. }
  196. if(S_OK == hr)
  197. {
  198. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  199. }
  200. else
  201. {
  202. DH_TRACE((
  203. DH_LVL_TRACE1,
  204. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  205. hr));
  206. }
  207. // ReOpen the root using StgOpenStorageOnILockBytes call.
  208. if(S_OK == hr)
  209. {
  210. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  211. hr = pVirtualDFRoot->OpenRootOnCustomILockBytes(
  212. NULL,
  213. dwRootMode,
  214. NULL,
  215. 0,
  216. pCFileBytes);
  217. DH_HRCHECK(hr, TEXT("StgOpenStorageOnILockBytes"));
  218. }
  219. if(S_OK == hr)
  220. {
  221. DH_TRACE((
  222. DH_LVL_TRACE1,
  223. TEXT("StgOpenStorageOnILockBytes passed as exp.")));
  224. }
  225. else
  226. {
  227. DH_TRACE((
  228. DH_LVL_TRACE1,
  229. TEXT("StgOpenStorageOnILockBytes failed unexp, hr = 0x%lx."),
  230. hr));
  231. }
  232. // Get the CRC of docfile now after opening on custom ILockBytes
  233. if(S_OK == hr)
  234. {
  235. pStgRootOnILockBytes = pVirtualDFRoot->GetIStoragePointer();
  236. DH_ASSERT(NULL != pStgRootOnILockBytes);
  237. hr = CalculateCRCForDocFile(
  238. pStgRootOnILockBytes,
  239. VERIFY_INC_TOPSTG_NAME,
  240. &dwCRC2);
  241. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  242. }
  243. // Release the pointer
  244. // Close the Root
  245. if(S_OK == hr)
  246. {
  247. hr = pVirtualDFRoot->Close();
  248. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  249. pStgRootOnILockBytes = NULL;
  250. }
  251. if(S_OK == hr)
  252. {
  253. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  254. }
  255. else
  256. {
  257. DH_TRACE((
  258. DH_LVL_TRACE1,
  259. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  260. hr));
  261. }
  262. // if everything goes well, log test as passed else failed.
  263. if (S_OK == hr)
  264. {
  265. if(dwCRC1 == dwCRC2)
  266. {
  267. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's match")));
  268. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_100 passed.")) );
  269. }
  270. else
  271. {
  272. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's don't match")));
  273. DH_LOG((LOG_FAIL, TEXT("Test variation ILKBTEST_100 failed.")) );
  274. hr = E_FAIL;
  275. }
  276. }
  277. else
  278. {
  279. DH_LOG((LOG_FAIL,
  280. TEXT("Test variation ILKBTEST_100 failed, hr=0x%lx."),
  281. hr) );
  282. }
  283. //BUGBUG: This may cause a leak. We may want to be releasing pTestILockBytesDF->_pCFileBytes
  284. if(NULL != pCFileBytes)
  285. {
  286. // Release would destroy pCFileBytes object when RefCount reaches zero.
  287. ulRef = pCFileBytes->Release();
  288. DH_ASSERT(0 == ulRef);
  289. }
  290. // Cleanup
  291. // Get the name of file, will be used later to delete the file
  292. if(NULL != pVirtualDFRoot)
  293. {
  294. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  295. if (pFileName != NULL)
  296. {
  297. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  298. }
  299. }
  300. // Delete the docfile on disk
  301. if((S_OK == hr) && (NULL != pFileName))
  302. {
  303. if(FALSE == DeleteFile(pFileName))
  304. {
  305. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  306. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  307. }
  308. }
  309. // Delete Chance docfile tree
  310. if(NULL != pTestChanceDF)
  311. {
  312. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  313. pTestChanceDF->GetChanceDFRoot());
  314. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  315. delete pTestChanceDF;
  316. pTestChanceDF = NULL;
  317. }
  318. // Delete Virtual docfile tree
  319. if (NULL != pTestILockBytesDF)
  320. {
  321. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  322. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  323. delete pTestILockBytesDF;
  324. pTestILockBytesDF = NULL;
  325. }
  326. if(NULL != pFileName)
  327. {
  328. delete pFileName;
  329. pFileName = NULL;
  330. }
  331. // Stop logging the test
  332. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_100 finished")) );
  333. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  334. return hr;
  335. }
  336. //----------------------------------------------------------------------------
  337. //
  338. // Test: ILKBTEST_101
  339. //
  340. // synopsis: The test first creates an ILockBytes instance and then uses this
  341. // ILockBytes instead of OLE provided ILockBytes file in the under
  342. // lying file system. Thus the root DocFile is created upon a
  343. // ILockBytes instead of a file system file, therby exercising the
  344. // ILockBytes functionality. This test opens the Asynchronous
  345. // docfile on ILockBytes
  346. //
  347. // This test uses ASYNCHRONOUS API's to open the custom ILockBytes
  348. // by getting the IFillLockBytes based on custom ILockBytes and
  349. // then using appropraiet API calls.
  350. //
  351. // Arguments:[argc]
  352. // [argv]
  353. //
  354. // Returns: HRESULT
  355. //
  356. // History: 5-Aug-1996 NarindK Created.
  357. //
  358. // Notes: This test runs in direct, transacted, and transacted deny write
  359. // modes
  360. //
  361. // New Test Notes:
  362. // 1. Old File: ADFLIB.CXX
  363. // 2. Old name of test : DfSetUpOnILockBytes Test
  364. // New Name of test : ILKBTEST_101
  365. // 3. To run the test, do the following at command prompt.
  366. // a. stgbase /seed:0 /t:ILKBTEST-101 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  367. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  368. // b. stgbase /seed:0 /t:ILKBTEST-101 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  369. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  370. // c. stgbase /seed:0 /t:ILKBTEST-101 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  371. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  372. //
  373. // BUGNOTE: Conversion: ILKBTEST-101 NO - not supported in nss
  374. //
  375. //-----------------------------------------------------------------------------
  376. HRESULT ILKBTEST_101(int argc, char *argv[])
  377. {
  378. #ifdef _MAC
  379. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!!!!!!ILKBTEST_101 crashes")) );
  380. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!!!!!!To be investigateds")) );
  381. return E_NOTIMPL;
  382. #else
  383. HRESULT hr = S_OK;
  384. HRESULT hr2 = S_OK;
  385. ChanceDF *pTestChanceDF = NULL;
  386. ILockBytesDF *pTestILockBytesDF = NULL;
  387. VirtualCtrNode *pVirtualDFRoot = NULL;
  388. DWORD dwRootMode = 0;
  389. DWORD dwStgMode = 0;
  390. LPTSTR pFileName = NULL;
  391. ULONG ulRef = 0;
  392. CFileBytes *pCFileBytes = NULL;
  393. LPSTORAGE pStgRoot1 = NULL;
  394. LPSTORAGE pStgAsyncDocFile = NULL;
  395. DWORD dwCRC1 = 0;
  396. DWORD dwCRC2 = 0;
  397. IFillLockBytes *pIFillLockBytes = NULL;
  398. CFileBytes *pCFileBytesEmpty = NULL;
  399. LPBYTE pBuffer = NULL;
  400. ULONG cbRead = 0;
  401. ULONG cbWritten = 0;
  402. ULARGE_INTEGER uli;
  403. ULARGE_INTEGER uliOffset;
  404. // Not for 2phase. Bail.
  405. if (DoingDistrib ())
  406. {
  407. return S_OK;
  408. }
  409. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_101"));
  410. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  411. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_101 started.")) );
  412. DH_TRACE((
  413. DH_LVL_TRACE1,
  414. TEXT("ILockBytes test - Opening Async DocFile on ILockBytes")));
  415. // Create the new ChanceDocFile tree that would consist of chance nodes.
  416. if (S_OK == hr)
  417. {
  418. pTestChanceDF = new ChanceDF();
  419. if(NULL == pTestChanceDF)
  420. {
  421. hr = E_OUTOFMEMORY;
  422. }
  423. }
  424. if (S_OK == hr)
  425. {
  426. hr = pTestChanceDF->CreateFromParams(argc, argv);
  427. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  428. }
  429. if (S_OK == hr)
  430. {
  431. dwRootMode = pTestChanceDF->GetRootMode();
  432. dwStgMode = pTestChanceDF->GetStgMode();
  433. DH_TRACE((
  434. DH_LVL_TRACE1,
  435. TEXT("Run Mode for ILKBTEST_101, Access mode: %lx"),
  436. dwRootMode));
  437. }
  438. // Create the DocFile tree based on ChanceDocFile tree created in
  439. // previous step
  440. if (S_OK == hr)
  441. {
  442. pTestILockBytesDF = new ILockBytesDF();
  443. if(NULL == pTestILockBytesDF)
  444. {
  445. hr = E_OUTOFMEMORY;
  446. }
  447. }
  448. if (S_OK == hr)
  449. {
  450. hr = pTestILockBytesDF->GenerateVirtualDF(
  451. pTestChanceDF,
  452. &pVirtualDFRoot);
  453. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  454. }
  455. if (S_OK == hr)
  456. {
  457. DH_TRACE((
  458. DH_LVL_TRACE1,
  459. TEXT("DocFile - CreateFromParams - successfully created.")));
  460. }
  461. else
  462. {
  463. DH_TRACE((
  464. DH_LVL_TRACE1,
  465. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  466. hr));
  467. }
  468. // Commit all storages/streams
  469. if (S_OK == hr)
  470. {
  471. hr = ParseVirtualDFAndCommitAllOpenStgs(
  472. pVirtualDFRoot,
  473. STGC_DEFAULT,
  474. NODE_INC_TOPSTG);
  475. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  476. }
  477. if(S_OK == hr)
  478. {
  479. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  480. }
  481. else
  482. {
  483. DH_TRACE((
  484. DH_LVL_TRACE1,
  485. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  486. hr));
  487. }
  488. // Release all substorages/streams too
  489. if (S_OK == hr)
  490. {
  491. hr = ParseVirtualDFAndCloseOpenStgsStms(
  492. pVirtualDFRoot,
  493. NODE_EXC_TOPSTG);
  494. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  495. }
  496. if(S_OK == hr)
  497. {
  498. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  499. }
  500. else
  501. {
  502. DH_TRACE((
  503. DH_LVL_TRACE1,
  504. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  505. hr));
  506. }
  507. // Get the original CRC of docfile
  508. if(S_OK == hr)
  509. {
  510. pStgRoot1 = pVirtualDFRoot->GetIStoragePointer();
  511. DH_ASSERT(NULL != pStgRoot1);
  512. hr = CalculateCRCForDocFile(pStgRoot1,VERIFY_INC_TOPSTG_NAME,&dwCRC1);
  513. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  514. }
  515. // Close the Root
  516. if(S_OK == hr)
  517. {
  518. hr = pVirtualDFRoot->Close();
  519. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  520. pStgRoot1 = NULL;
  521. }
  522. if(S_OK == hr)
  523. {
  524. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  525. }
  526. else
  527. {
  528. DH_TRACE((
  529. DH_LVL_TRACE1,
  530. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  531. hr));
  532. }
  533. // Now open this docfile on Async docfile API calls.
  534. // Get an empty ILockBytes
  535. if(S_OK == hr)
  536. {
  537. pCFileBytesEmpty = new CFileBytes;
  538. if(NULL == pCFileBytesEmpty)
  539. {
  540. hr = E_OUTOFMEMORY;
  541. }
  542. }
  543. // StgGetIFillLockBytesOnILockBytes expects an empty ILockBytes passed
  544. // to it.
  545. if(S_OK == hr)
  546. {
  547. hr = StgGetIFillLockBytesOnILockBytes(
  548. pCFileBytesEmpty,
  549. &pIFillLockBytes);
  550. }
  551. if(S_OK == hr)
  552. {
  553. DH_TRACE((DH_LVL_TRACE1, TEXT("StgGetIFillLockBytesOnILockBytes passed ")));
  554. }
  555. else
  556. {
  557. DH_TRACE((
  558. DH_LVL_TRACE1,
  559. TEXT("StgGetIFillLockBytesOnILockBytes failed unexp, hr=0x%lx "),
  560. hr));
  561. }
  562. // Now copy from original ILockBytes into pIFillBytes
  563. if(S_OK == hr)
  564. {
  565. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  566. uli = pCFileBytes->GetSize();
  567. DH_ASSERT(0xFFFFFFFF != uli.LowPart);
  568. pBuffer = new BYTE [uli.LowPart];
  569. if(NULL == pBuffer)
  570. {
  571. hr = E_OUTOFMEMORY;
  572. }
  573. if(S_OK == hr)
  574. {
  575. memset(&uliOffset, 0, sizeof(ULARGE_INTEGER));
  576. hr = pCFileBytes->ReadAt(
  577. uliOffset,
  578. (void *) pBuffer,
  579. uli.LowPart,
  580. &cbRead);
  581. }
  582. if(S_OK == hr)
  583. {
  584. DH_TRACE((
  585. DH_LVL_TRACE1,
  586. TEXT("ILockBytes::ReadAt passed as exp. ")));
  587. }
  588. else
  589. {
  590. DH_TRACE((
  591. DH_LVL_TRACE1,
  592. TEXT("ILockBytes::ReadAt failed unexp, hr=0x%lx "),
  593. hr));
  594. }
  595. if(S_OK == hr)
  596. {
  597. hr = pCFileBytesEmpty->Init(
  598. pVirtualDFRoot->GetVirtualCtrNodeName(),
  599. OF_READWRITE);
  600. DH_HRCHECK(hr, TEXT("CFileBytes::Init")) ;
  601. }
  602. if(S_OK == hr)
  603. {
  604. hr = pIFillLockBytes->FillAppend(
  605. (void *)pBuffer,
  606. cbRead,
  607. &cbWritten);
  608. }
  609. if(S_OK == hr)
  610. {
  611. DH_TRACE((
  612. DH_LVL_TRACE1,
  613. TEXT("IFillLockBytes::FillAppend passed as exp. ")));
  614. }
  615. else
  616. {
  617. DH_TRACE((
  618. DH_LVL_TRACE1,
  619. TEXT("IFillLockBytes::FillAppend failed unexp, hr=0x%lx "),
  620. hr));
  621. }
  622. if(S_OK == hr)
  623. {
  624. // notify ILockBytes that all data is copied down
  625. hr = pIFillLockBytes->Terminate(FALSE);
  626. }
  627. if(S_OK == hr)
  628. {
  629. DH_TRACE((
  630. DH_LVL_TRACE1,
  631. TEXT("IFillLockBytes::Terminate passed as exp. ")));
  632. }
  633. else
  634. {
  635. DH_TRACE((
  636. DH_LVL_TRACE1,
  637. TEXT("IFillLockBytes::Terminate failed unexp, hr=0x%lx "),
  638. hr));
  639. }
  640. }
  641. do
  642. {
  643. if(S_OK == hr)
  644. {
  645. hr = StgOpenAsyncDocfileOnIFillLockBytes(
  646. pIFillLockBytes,
  647. STGM_READ | STGM_SHARE_EXCLUSIVE,
  648. 0,
  649. &pStgAsyncDocFile);
  650. }
  651. if(E_PENDING == hr)
  652. {
  653. DH_TRACE((DH_LVL_TRACE1, TEXT("E_PENDING")));
  654. Sleep(1000);
  655. }
  656. } while(E_PENDING == hr);
  657. if(S_OK == hr)
  658. {
  659. DH_TRACE((DH_LVL_TRACE1,TEXT("StgOpenAsyncDocfileOnIFillLockBytes passed")));
  660. }
  661. else
  662. {
  663. DH_TRACE((
  664. DH_LVL_TRACE1,
  665. TEXT("StgOpenAsyncDocfileOnIFillLockBytes failed unexp,hr=0x%lx"),
  666. hr));
  667. }
  668. // Get the CRC of docfile now after opening on custom ILockBytes asynch-
  669. // ronously
  670. if(S_OK == hr)
  671. {
  672. hr = CalculateCRCForDocFile(
  673. pStgAsyncDocFile,
  674. VERIFY_INC_TOPSTG_NAME,
  675. &dwCRC2);
  676. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  677. }
  678. // Release the pointer
  679. if(NULL != pStgAsyncDocFile)
  680. {
  681. ulRef = pStgAsyncDocFile->Release();
  682. DH_ASSERT(0 == ulRef);
  683. pStgAsyncDocFile = NULL;
  684. }
  685. // if everything goes well, log test as passed else failed.
  686. if (S_OK == hr)
  687. {
  688. if(dwCRC1 == dwCRC2)
  689. {
  690. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's match")));
  691. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_101 passed.")) );
  692. }
  693. else
  694. {
  695. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's don't match")));
  696. DH_LOG((LOG_FAIL, TEXT("Test variation ILKBTEST_101 failed.")) );
  697. hr = E_FAIL;
  698. }
  699. }
  700. else
  701. {
  702. DH_LOG((LOG_FAIL,
  703. TEXT("Test variation ILKBTEST_101 failed, hr=0x%lx."),
  704. hr) );
  705. }
  706. // Release pIFillLockBytes. This also releases and deletes the underlying
  707. // pCFileBytesEmpty. Check if behaiour expected.
  708. if(NULL != pIFillLockBytes)
  709. {
  710. pIFillLockBytes->Release();
  711. DH_ASSERT(0 == ulRef);
  712. pIFillLockBytes = NULL;
  713. }
  714. if(NULL != pCFileBytes)
  715. {
  716. // Release would destroy pCFileBytes object when RefCount reaches zero.
  717. ulRef = pCFileBytes->Release();
  718. DH_ASSERT(0 == ulRef);
  719. pCFileBytes = NULL;
  720. }
  721. // Delete pBuffer
  722. if(NULL != pBuffer)
  723. {
  724. delete []pBuffer;
  725. pBuffer = NULL;
  726. }
  727. // Cleanup
  728. // Get the name of file, will be used later to delete the file
  729. if(NULL != pVirtualDFRoot)
  730. {
  731. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  732. if (pFileName != NULL)
  733. {
  734. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  735. }
  736. }
  737. // Delete the docfile on disk
  738. if((S_OK == hr) && (NULL != pFileName))
  739. {
  740. if(FALSE == DeleteFile(pFileName))
  741. {
  742. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  743. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  744. }
  745. }
  746. // Delete Chance docfile tree
  747. if(NULL != pTestChanceDF)
  748. {
  749. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  750. pTestChanceDF->GetChanceDFRoot());
  751. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  752. delete pTestChanceDF;
  753. pTestChanceDF = NULL;
  754. }
  755. // Delete Virtual docfile tree
  756. if (NULL != pTestILockBytesDF)
  757. {
  758. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  759. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  760. delete pTestILockBytesDF;
  761. pTestILockBytesDF = NULL;
  762. }
  763. if(NULL != pFileName)
  764. {
  765. delete pFileName;
  766. pFileName = NULL;
  767. }
  768. // Stop logging the test
  769. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_101 finished")) );
  770. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  771. return hr;
  772. #endif //_MAC
  773. }
  774. //----------------------------------------------------------------------------
  775. //
  776. // Test: ILKBTEST_102
  777. //
  778. // Synopsis: The test first creates a normal docfile on OLE provided lockbytes
  779. // and CRC's it.
  780. // The root docfile is opened upon a special ILockBytes that contains
  781. // a method allowing the test to simulate write failure during commit.
  782. // The docfile is modified, simulated write failure is turned on, and
  783. // the docfile is committed. The root docfile is then released,
  784. // reinstantiated, and CRC'd. The CRCs should match which verifies
  785. // that no changed were made to the effective docfile contents
  786. // when the commit failed.
  787. //
  788. // Arguments:[argc]
  789. // [argv]
  790. //
  791. // Returns: HRESULT
  792. //
  793. // History: 31-July-1996 NarindK Created.
  794. //
  795. // Notes: This test runs in trannsacted and transacted deny write mode
  796. //
  797. // New Test Notes:
  798. // 1. Old File: LTCMFAIL.CXX
  799. // 2. Old name of test : LegitTransactedCommitFail Test
  800. // New Name of test : ILKBTEST_102
  801. // 3. To run the test, do the following at command prompt.
  802. // a. stgbase /seed:0 /t:ILKBTEST-102 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  803. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  804. // b. stgbase /seed:0 /t:ILKBTEST-102 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  805. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  806. //
  807. // BUGNOTE: Conversion: ILKBTEST-102 NO - not supported in nss
  808. //
  809. //-----------------------------------------------------------------------------
  810. HRESULT ILKBTEST_102(int argc, char *argv[])
  811. {
  812. HRESULT hr = S_OK;
  813. HRESULT hr2 = S_OK;
  814. ChanceDF *pTestChanceDF = NULL;
  815. VirtualDF *pTestVirtualDF = NULL;
  816. VirtualCtrNode *pVirtualDFRoot = NULL;
  817. DWORD dwRootMode = 0;
  818. DWORD dwStgMode = 0;
  819. LPTSTR pFileName = NULL;
  820. ULONG ulRef = 0;
  821. DWORD dwCRCOrg = 0;
  822. DWORD dwCRCAct = 0;
  823. CFileBytes *pCFileBytes = NULL;
  824. // Not for 2phase. Bail.
  825. if (DoingDistrib ())
  826. {
  827. return S_OK;
  828. }
  829. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_102"));
  830. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  831. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_102 started.")) );
  832. DH_TRACE((
  833. DH_LVL_TRACE1,
  834. TEXT("ILockBytes test - DocFile Commit fail test ")));
  835. // Create the new ChanceDocFile tree that would consist of chance nodes.
  836. if (S_OK == hr)
  837. {
  838. pTestChanceDF = new ChanceDF();
  839. if(NULL == pTestChanceDF)
  840. {
  841. hr = E_OUTOFMEMORY;
  842. }
  843. }
  844. if (S_OK == hr)
  845. {
  846. hr = pTestChanceDF->CreateFromParams(argc, argv);
  847. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  848. }
  849. if (S_OK == hr)
  850. {
  851. dwRootMode = pTestChanceDF->GetRootMode();
  852. dwStgMode = pTestChanceDF->GetStgMode();
  853. DH_TRACE((
  854. DH_LVL_TRACE1,
  855. TEXT("Run Mode for ILKBTEST_102, Access mode: %lx"),
  856. dwRootMode));
  857. }
  858. // Create the DocFile tree based on ChanceDocFile tree created in
  859. // previous step
  860. if (S_OK == hr)
  861. {
  862. pTestVirtualDF = new VirtualDF();
  863. if(NULL == pTestVirtualDF)
  864. {
  865. hr = E_OUTOFMEMORY;
  866. }
  867. }
  868. if (S_OK == hr)
  869. {
  870. hr = pTestVirtualDF->GenerateVirtualDF(
  871. pTestChanceDF,
  872. &pVirtualDFRoot);
  873. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  874. }
  875. if(S_OK == hr)
  876. {
  877. DH_TRACE((
  878. DH_LVL_TRACE1,
  879. TEXT("DocFile - CreateFromParams - successfully created.")));
  880. }
  881. else
  882. {
  883. DH_TRACE((
  884. DH_LVL_TRACE1,
  885. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  886. hr));
  887. }
  888. // Commit all storages/streams
  889. if (S_OK == hr)
  890. {
  891. hr = ParseVirtualDFAndCommitAllOpenStgs(
  892. pVirtualDFRoot,
  893. STGC_DEFAULT,
  894. NODE_INC_TOPSTG);
  895. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  896. }
  897. if(S_OK == hr)
  898. {
  899. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  900. }
  901. else
  902. {
  903. DH_TRACE((
  904. DH_LVL_TRACE1,
  905. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  906. hr));
  907. }
  908. if (S_OK == hr)
  909. {
  910. hr = ParseVirtualDFAndCloseOpenStgsStms(
  911. pVirtualDFRoot,
  912. NODE_EXC_TOPSTG);
  913. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  914. }
  915. if(S_OK == hr)
  916. {
  917. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  918. }
  919. else
  920. {
  921. DH_TRACE((
  922. DH_LVL_TRACE1,
  923. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  924. hr));
  925. }
  926. // Calulcate CRC on this DocFile
  927. if(S_OK == hr)
  928. {
  929. hr = CalculateCRCForDocFile(
  930. pVirtualDFRoot->GetIStoragePointer(),
  931. VERIFY_INC_TOPSTG_NAME,
  932. &dwCRCOrg);
  933. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  934. }
  935. // Release root
  936. if (S_OK == hr)
  937. {
  938. hr = pVirtualDFRoot->Close();
  939. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close"));
  940. }
  941. if(S_OK == hr)
  942. {
  943. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  944. }
  945. else
  946. {
  947. DH_TRACE((
  948. DH_LVL_TRACE1,
  949. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  950. hr));
  951. }
  952. // Make new ILockBytes
  953. if (S_OK == hr)
  954. {
  955. pCFileBytes = new CFileBytes();
  956. if(NULL == pCFileBytes)
  957. {
  958. hr = E_OUTOFMEMORY;
  959. }
  960. }
  961. // Initialize new ILockBytes
  962. if (S_OK == hr)
  963. {
  964. hr = pCFileBytes->Init(
  965. pVirtualDFRoot->GetVirtualCtrNodeName(),
  966. OF_READWRITE);
  967. DH_HRCHECK(hr, TEXT("CFileBytes::Init")) ;
  968. }
  969. if(S_OK == hr)
  970. {
  971. DH_TRACE((DH_LVL_TRACE1, TEXT("Custom ILockBytes create/init passed ")));
  972. }
  973. else
  974. {
  975. DH_TRACE((
  976. DH_LVL_TRACE1,
  977. TEXT("Custom ILockBytes create/init failed unexp, hr=0x%lx "),
  978. hr));
  979. }
  980. // ReOpen the root using StgOpenStorageOnILockBytes call.
  981. if(S_OK == hr)
  982. {
  983. hr = pVirtualDFRoot->OpenRootOnCustomILockBytes(
  984. NULL,
  985. dwRootMode,
  986. NULL,
  987. 0,
  988. pCFileBytes);
  989. DH_HRCHECK(hr, TEXT("StgOpenStorageOnILockBytes"));
  990. }
  991. if(S_OK == hr)
  992. {
  993. DH_TRACE((
  994. DH_LVL_TRACE1,
  995. TEXT("StgOpenStorageOnILockBytes passed as exp.")));
  996. }
  997. else
  998. {
  999. DH_TRACE((
  1000. DH_LVL_TRACE1,
  1001. TEXT("StgOpenStorageOnILockBytes failed unexp, hr = 0x%lx."),
  1002. hr));
  1003. }
  1004. // Modify the DocFile
  1005. if(S_OK == hr)
  1006. {
  1007. hr = ModifyDocFile(
  1008. pTestVirtualDF,
  1009. pVirtualDFRoot,
  1010. pTestVirtualDF->GetDataGenInteger(),
  1011. pTestVirtualDF->GetDataGenUnicode(),
  1012. dwStgMode,
  1013. FALSE);
  1014. }
  1015. if(S_OK == hr)
  1016. {
  1017. DH_TRACE((DH_LVL_TRACE1, TEXT("ModifyDocFile passed ")));
  1018. }
  1019. else
  1020. {
  1021. DH_TRACE((
  1022. DH_LVL_TRACE1,
  1023. TEXT("ModifyDocFile failed unexp, hr=0x%lx "),
  1024. hr));
  1025. }
  1026. if(S_OK == hr)
  1027. {
  1028. pCFileBytes->FailWrite0(1);
  1029. DH_TRACE((
  1030. DH_LVL_TRACE1,
  1031. TEXT("Simulated failure during Commit in ILockBytes")));
  1032. }
  1033. // Commit
  1034. if(S_OK == hr)
  1035. {
  1036. hr = pVirtualDFRoot->Commit(STGC_DEFAULT);
  1037. }
  1038. if(STG_E_WRITEFAULT == hr)
  1039. {
  1040. DH_TRACE((
  1041. DH_LVL_TRACE1,
  1042. TEXT("VirtualCtrNode::Commit failed as exp, hr=0x%lx "),
  1043. hr));
  1044. hr = S_OK;
  1045. }
  1046. else
  1047. {
  1048. DH_TRACE((
  1049. DH_LVL_TRACE1,
  1050. TEXT("VirtualCtrNode::Commit return unexp hr, hr=0x%lx "),
  1051. hr));
  1052. }
  1053. // Close the Root
  1054. if(S_OK == hr)
  1055. {
  1056. hr = pVirtualDFRoot->Close();
  1057. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1058. }
  1059. if(S_OK == hr)
  1060. {
  1061. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  1062. }
  1063. else
  1064. {
  1065. DH_TRACE((
  1066. DH_LVL_TRACE1,
  1067. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  1068. hr));
  1069. }
  1070. if(NULL != pCFileBytes)
  1071. {
  1072. // Release would destroy pCFileBytes object when RefCount reaches zero.
  1073. ulRef = pCFileBytes->Release();
  1074. DH_ASSERT(0 == ulRef);
  1075. }
  1076. // Open root agian
  1077. if(S_OK == hr)
  1078. {
  1079. hr = pVirtualDFRoot->Open(NULL, dwRootMode, NULL, 0);
  1080. }
  1081. if(S_OK == hr)
  1082. {
  1083. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Open passed as exp. ")));
  1084. }
  1085. else
  1086. {
  1087. DH_TRACE((
  1088. DH_LVL_TRACE1,
  1089. TEXT("VirtualCtrNode::Open failed unexp, hr=0x%lx "),
  1090. hr));
  1091. }
  1092. // Calulcate CRC on this DocFile
  1093. if(S_OK == hr)
  1094. {
  1095. hr = CalculateCRCForDocFile(
  1096. pVirtualDFRoot->GetIStoragePointer(),
  1097. VERIFY_INC_TOPSTG_NAME,
  1098. &dwCRCAct);
  1099. DH_HRCHECK(hr, TEXT("CalculateCRCForDocFile")) ;
  1100. }
  1101. // Close the Root
  1102. if(S_OK == hr)
  1103. {
  1104. hr = pVirtualDFRoot->Close();
  1105. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1106. }
  1107. if(S_OK == hr)
  1108. {
  1109. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  1110. }
  1111. else
  1112. {
  1113. DH_TRACE((
  1114. DH_LVL_TRACE1,
  1115. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  1116. hr));
  1117. }
  1118. // if everything goes well, log test as passed else failed.
  1119. if (S_OK == hr)
  1120. {
  1121. if(dwCRCAct == dwCRCOrg)
  1122. {
  1123. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's match. ")));
  1124. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_102 passed.")) );
  1125. }
  1126. else
  1127. {
  1128. DH_TRACE((DH_LVL_TRACE1, TEXT("CRC's don't match. ")));
  1129. DH_LOG((LOG_FAIL, TEXT("Test variation ILKBTEST_102 failed.")) );
  1130. hr = E_FAIL;
  1131. }
  1132. }
  1133. else
  1134. {
  1135. DH_LOG((LOG_FAIL,
  1136. TEXT("Test variation ILKBTEST_102 failed, hr=0x%lx."),
  1137. hr) );
  1138. }
  1139. // Cleanup
  1140. // Get the name of file, will be used later to delete the file
  1141. if(NULL != pVirtualDFRoot)
  1142. {
  1143. pFileName= new TCHAR[_tcslen(pTestVirtualDF->GetDocFileName())+1];
  1144. if (pFileName != NULL)
  1145. {
  1146. _tcscpy(pFileName, pTestVirtualDF->GetDocFileName());
  1147. }
  1148. }
  1149. // Delete the docfile on disk
  1150. if((S_OK == hr) && (NULL != pFileName))
  1151. {
  1152. if(FALSE == DeleteFile(pFileName))
  1153. {
  1154. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1155. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1156. }
  1157. }
  1158. // Delete Chance docfile tree
  1159. if(NULL != pTestChanceDF)
  1160. {
  1161. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1162. pTestChanceDF->GetChanceDFRoot());
  1163. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1164. delete pTestChanceDF;
  1165. pTestChanceDF = NULL;
  1166. }
  1167. // Delete Virtual docfile tree
  1168. if (NULL != pTestVirtualDF)
  1169. {
  1170. hr2 = pTestVirtualDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1171. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  1172. delete pTestVirtualDF;
  1173. pTestVirtualDF = NULL;
  1174. }
  1175. if(NULL != pFileName)
  1176. {
  1177. delete pFileName;
  1178. pFileName = NULL;
  1179. }
  1180. // Stop logging the test
  1181. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_102 finished")) );
  1182. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1183. return hr;
  1184. }
  1185. //----------------------------------------------------------------------------
  1186. //
  1187. // Test: ILKBTEST_103
  1188. //
  1189. // synopsis: The test first creates an ILockBytes instance and then uses this
  1190. // ILockBytes instead of OLE provided ILockBytes file in the under
  1191. // lying file system. Thus the root DocFile is created upon a
  1192. // ILockBytes instead of a file system file, therby exercising the
  1193. // ILockBytes functionality. This tests attempts illegal opeartion
  1194. // on custom ILockBytes based docfile. It creates the custom Ilock
  1195. // Bytes based docfile, then destroys the custom ILOckBytes and
  1196. // thereafter attempts to commit the DocFile
  1197. //
  1198. // Arguments:[argc]
  1199. // [argv]
  1200. //
  1201. // Returns: HRESULT
  1202. //
  1203. // History: 3-Aug-1996 NarindK Created.
  1204. //
  1205. // Notes: This test runs in direct, transacted, and transacted deny write
  1206. // modes
  1207. //
  1208. // THIS TEST CAUSES GPF IN OLE32.DLL, HENCE NOT PART OF AUTOMATED TEST RUN
  1209. // BUG: 52216
  1210. //
  1211. // New Test Notes:
  1212. // 1. Old File:i -none-
  1213. // 2. Old name of test : -none-
  1214. // New Name of test : ILKBTEST_103
  1215. // 3. To run the test, do the following at command prompt.
  1216. // a. stgbase /seed:0 /t:ILKBTEST-103 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1217. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1218. // b. stgbase /seed:0 /t:ILKBTEST-103 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1219. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1220. // c. stgbase /seed:0 /t:ILKBTEST-103 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1221. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1222. //
  1223. // BUGNOTE: Conversion: ILKBTEST-103 NO - not supported in nss
  1224. //
  1225. //-----------------------------------------------------------------------------
  1226. HRESULT ILKBTEST_103(int argc, char *argv[])
  1227. {
  1228. HRESULT hr = S_OK;
  1229. HRESULT hr2 = S_OK;
  1230. ChanceDF *pTestChanceDF = NULL;
  1231. ILockBytesDF *pTestILockBytesDF = NULL;
  1232. VirtualCtrNode *pVirtualDFRoot = NULL;
  1233. DWORD dwRootMode = 0;
  1234. DWORD dwStgMode = 0;
  1235. LPTSTR pFileName = NULL;
  1236. ULONG ulRef = 0;
  1237. CFileBytes *pCFileBytes = NULL;
  1238. // Not for 2phase. Bail.
  1239. if (DoingDistrib ())
  1240. {
  1241. return S_OK;
  1242. }
  1243. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_103"));
  1244. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1245. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_103 started.")) );
  1246. DH_TRACE((
  1247. DH_LVL_TRACE1,
  1248. TEXT("ILockBytes test - Creating DocFile on ILockBytes")));
  1249. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1250. if (S_OK == hr)
  1251. {
  1252. pTestChanceDF = new ChanceDF();
  1253. if(NULL == pTestChanceDF)
  1254. {
  1255. hr = E_OUTOFMEMORY;
  1256. }
  1257. }
  1258. if (S_OK == hr)
  1259. {
  1260. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1261. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1262. }
  1263. if (S_OK == hr)
  1264. {
  1265. dwRootMode = pTestChanceDF->GetRootMode();
  1266. dwStgMode = pTestChanceDF->GetStgMode();
  1267. DH_TRACE((
  1268. DH_LVL_TRACE1,
  1269. TEXT("Run Mode for ILKBTEST_103, Access mode: %lx"),
  1270. dwRootMode));
  1271. }
  1272. // Create the DocFile tree based on ChanceDocFile tree created in
  1273. // previous step
  1274. if (S_OK == hr)
  1275. {
  1276. pTestILockBytesDF = new ILockBytesDF();
  1277. if(NULL == pTestILockBytesDF)
  1278. {
  1279. hr = E_OUTOFMEMORY;
  1280. }
  1281. }
  1282. if (S_OK == hr)
  1283. {
  1284. hr = pTestILockBytesDF->GenerateVirtualDF(
  1285. pTestChanceDF,
  1286. &pVirtualDFRoot);
  1287. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  1288. }
  1289. if (S_OK == hr)
  1290. {
  1291. DH_TRACE((
  1292. DH_LVL_TRACE1,
  1293. TEXT("StgCreateDocFileOnILockBytes passed as exp.")));
  1294. DH_TRACE((
  1295. DH_LVL_TRACE1,
  1296. TEXT("DocFile - CreateFromParams - successfully created.")));
  1297. }
  1298. else
  1299. {
  1300. DH_TRACE((
  1301. DH_LVL_TRACE1,
  1302. TEXT("StgCreateDocFileOnILockBytes failed unexp."),
  1303. hr));
  1304. DH_TRACE((
  1305. DH_LVL_TRACE1,
  1306. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  1307. hr));
  1308. }
  1309. if(NULL != pTestILockBytesDF->_pCFileBytes)
  1310. {
  1311. // Release would destroy pCFileBytes object when RefCount reaches zero.
  1312. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  1313. ulRef = pCFileBytes->Release();
  1314. DH_ASSERT(0 == ulRef);
  1315. DH_TRACE((DH_LVL_TRACE1, TEXT("Destoryed custom ILockBytes")));
  1316. }
  1317. // Commit all storages/streams
  1318. if (S_OK == hr)
  1319. {
  1320. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1321. pVirtualDFRoot,
  1322. STGC_DEFAULT,
  1323. NODE_INC_TOPSTG);
  1324. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1325. }
  1326. if(S_OK == hr)
  1327. {
  1328. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  1329. }
  1330. else
  1331. {
  1332. DH_TRACE((
  1333. DH_LVL_TRACE1,
  1334. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  1335. hr));
  1336. }
  1337. // Release root and all substorages/streams too
  1338. if (S_OK == hr)
  1339. {
  1340. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1341. pVirtualDFRoot,
  1342. NODE_INC_TOPSTG);
  1343. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1344. }
  1345. if(S_OK == hr)
  1346. {
  1347. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  1348. }
  1349. else
  1350. {
  1351. DH_TRACE((
  1352. DH_LVL_TRACE1,
  1353. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  1354. hr));
  1355. }
  1356. // if everything goes well, log test as passed else failed.
  1357. if (S_OK == hr)
  1358. {
  1359. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_103 passed.")) );
  1360. }
  1361. else
  1362. {
  1363. DH_LOG((LOG_FAIL,
  1364. TEXT("Test variation ILKBTEST_103 failed, hr=0x%lx."),
  1365. hr) );
  1366. }
  1367. // Cleanup
  1368. // Get the name of file, will be used later to delete the file
  1369. if(NULL != pVirtualDFRoot)
  1370. {
  1371. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  1372. if (pFileName != NULL)
  1373. {
  1374. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  1375. }
  1376. }
  1377. // Delete the docfile on disk
  1378. if((S_OK == hr) && (NULL != pFileName))
  1379. {
  1380. if(FALSE == DeleteFile(pFileName))
  1381. {
  1382. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1383. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1384. }
  1385. }
  1386. // Delete Chance docfile tree
  1387. if(NULL != pTestChanceDF)
  1388. {
  1389. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1390. pTestChanceDF->GetChanceDFRoot());
  1391. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1392. delete pTestChanceDF;
  1393. pTestChanceDF = NULL;
  1394. }
  1395. // Delete Virtual docfile tree
  1396. if (NULL != pTestILockBytesDF)
  1397. {
  1398. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1399. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  1400. delete pTestILockBytesDF;
  1401. pTestILockBytesDF = NULL;
  1402. }
  1403. if(NULL != pFileName)
  1404. {
  1405. delete pFileName;
  1406. pFileName = NULL;
  1407. }
  1408. // Stop logging the test
  1409. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_103 finished")) );
  1410. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1411. return hr;
  1412. }
  1413. //----------------------------------------------------------------------------
  1414. //
  1415. // Test: ILKBTEST_104
  1416. //
  1417. // synopsis: The test first creates an ILockBytes instance and then uses this
  1418. // ILockBytes instead of OLE provided ILockBytes file in the under
  1419. // lying file system. Thus the root DocFile is created upon a
  1420. // ILockBytes instead of a file system file, therby exercising the
  1421. // ILockBytes functionality. This tests attempts illegal opeartion
  1422. // while tring to open asynchronously the docfile based on custom
  1423. // ILockBytes
  1424. //
  1425. // Arguments:[argc]
  1426. // [argv]
  1427. //
  1428. // Returns: HRESULT
  1429. //
  1430. // History: 3-Aug-1996 NarindK Created.
  1431. //
  1432. // Notes: This test runs in direct, transacted, and transacted deny write
  1433. // modes
  1434. //
  1435. // THIS TEST CAUSES GPF IN OLE32.DLL, HENCE NOT PART OF AUTOMATED TEST RUN
  1436. // BUG: 52279
  1437. //
  1438. // New Test Notes:
  1439. // 1. Old File: -none-
  1440. // 2. Old name of test : -none-
  1441. // New Name of test : ILKBTEST_104
  1442. // 3. To run the test, do the following at command prompt.
  1443. // a. stgbase /seed:0 /t:ILKBTEST-104 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1444. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1445. // b. stgbase /seed:0 /t:ILKBTEST-104 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1446. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1447. // c. stgbase /seed:0 /t:ILKBTEST-104 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1448. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1449. //
  1450. // BUGNOTE: Conversion: ILKBTEST-104 NO - not supported in nss
  1451. //
  1452. //-----------------------------------------------------------------------------
  1453. HRESULT ILKBTEST_104(int argc, char *argv[])
  1454. {
  1455. #ifdef _MAC
  1456. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!ILKBTEST_104 crashes")) );
  1457. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!!To be investigated")) );
  1458. return E_NOTIMPL;
  1459. #else
  1460. HRESULT hr = S_OK;
  1461. HRESULT hr2 = S_OK;
  1462. ChanceDF *pTestChanceDF = NULL;
  1463. ILockBytesDF *pTestILockBytesDF = NULL;
  1464. VirtualCtrNode *pVirtualDFRoot = NULL;
  1465. DWORD dwRootMode = 0;
  1466. DWORD dwStgMode = 0;
  1467. LPSTORAGE pStgAsyncDocFile = NULL;
  1468. LPTSTR pFileName = NULL;
  1469. ULONG ulRef = 0;
  1470. CFileBytes *pCFileBytes = NULL;
  1471. // Not for 2phase. Bail.
  1472. if (DoingDistrib ())
  1473. {
  1474. return S_OK;
  1475. }
  1476. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_104"));
  1477. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1478. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_104 started.")) );
  1479. DH_TRACE((
  1480. DH_LVL_TRACE1,
  1481. TEXT("ILockBytes test - Creating DocFile on ILockBytes")));
  1482. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1483. if (S_OK == hr)
  1484. {
  1485. pTestChanceDF = new ChanceDF();
  1486. if(NULL == pTestChanceDF)
  1487. {
  1488. hr = E_OUTOFMEMORY;
  1489. }
  1490. }
  1491. if (S_OK == hr)
  1492. {
  1493. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1494. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1495. }
  1496. if (S_OK == hr)
  1497. {
  1498. dwRootMode = pTestChanceDF->GetRootMode();
  1499. dwStgMode = pTestChanceDF->GetStgMode();
  1500. DH_TRACE((
  1501. DH_LVL_TRACE1,
  1502. TEXT("Run Mode for ILKBTEST_104, Access mode: %lx"),
  1503. dwRootMode));
  1504. }
  1505. // Create the DocFile tree based on ChanceDocFile tree created in
  1506. // previous step
  1507. if (S_OK == hr)
  1508. {
  1509. pTestILockBytesDF = new ILockBytesDF();
  1510. if(NULL == pTestILockBytesDF)
  1511. {
  1512. hr = E_OUTOFMEMORY;
  1513. }
  1514. }
  1515. if (S_OK == hr)
  1516. {
  1517. hr = pTestILockBytesDF->GenerateVirtualDF(
  1518. pTestChanceDF,
  1519. &pVirtualDFRoot);
  1520. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  1521. }
  1522. if (S_OK == hr)
  1523. {
  1524. DH_TRACE((
  1525. DH_LVL_TRACE1,
  1526. TEXT("StgCreateDocFileOnILockBytes passed as exp.")));
  1527. DH_TRACE((
  1528. DH_LVL_TRACE1,
  1529. TEXT("DocFile - CreateFromParams - successfully created.")));
  1530. }
  1531. else
  1532. {
  1533. DH_TRACE((
  1534. DH_LVL_TRACE1,
  1535. TEXT("StgCreateDocFileOnILockBytes failed unexp."),
  1536. hr));
  1537. DH_TRACE((
  1538. DH_LVL_TRACE1,
  1539. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  1540. hr));
  1541. }
  1542. // Commit all storages/streams
  1543. if (S_OK == hr)
  1544. {
  1545. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1546. pVirtualDFRoot,
  1547. STGC_DEFAULT,
  1548. NODE_INC_TOPSTG);
  1549. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1550. }
  1551. if(S_OK == hr)
  1552. {
  1553. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  1554. }
  1555. else
  1556. {
  1557. DH_TRACE((
  1558. DH_LVL_TRACE1,
  1559. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  1560. hr));
  1561. }
  1562. // Release root and all substorages/streams too
  1563. if (S_OK == hr)
  1564. {
  1565. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1566. pVirtualDFRoot,
  1567. NODE_INC_TOPSTG);
  1568. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1569. }
  1570. if(S_OK == hr)
  1571. {
  1572. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  1573. }
  1574. else
  1575. {
  1576. DH_TRACE((
  1577. DH_LVL_TRACE1,
  1578. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  1579. hr));
  1580. }
  1581. // Pass a invalid pointer in first parameter IFillLockBytes pointer. For
  1582. // test case, we are passing NULL pointer.
  1583. if(S_OK == hr)
  1584. {
  1585. hr = StgOpenAsyncDocfileOnIFillLockBytes(
  1586. NULL,
  1587. STGM_READ | STGM_SHARE_EXCLUSIVE,
  1588. 0,
  1589. &pStgAsyncDocFile);
  1590. }
  1591. if(STG_E_INVALIDPOINTER == hr)
  1592. {
  1593. DH_TRACE((
  1594. DH_LVL_TRACE1,
  1595. TEXT("StgOpenAsyncDocfileOnIFillLockBytes failed exp, hr=0x%lx"),
  1596. hr));
  1597. }
  1598. else
  1599. {
  1600. DH_TRACE((
  1601. DH_LVL_TRACE1,
  1602. TEXT("StgOpenAsyncDocfileOnIFillLockBytes returned unexp hr=0x%lx"),
  1603. hr));
  1604. }
  1605. // Release the pointer
  1606. if(NULL != pStgAsyncDocFile)
  1607. {
  1608. ulRef = pStgAsyncDocFile->Release();
  1609. DH_ASSERT(0 == ulRef);
  1610. pStgAsyncDocFile = NULL;
  1611. }
  1612. // if everything goes well, log test as passed else failed.
  1613. if (S_OK == hr)
  1614. {
  1615. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_104 passed.")) );
  1616. }
  1617. else
  1618. {
  1619. DH_LOG((LOG_FAIL,
  1620. TEXT("Test variation ILKBTEST_104 failed, hr=0x%lx."),
  1621. hr) );
  1622. }
  1623. // Cleanup
  1624. if(NULL != pTestILockBytesDF->_pCFileBytes)
  1625. {
  1626. // Release would destroy pCFileBytes object when RefCount reaches zero.
  1627. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  1628. ulRef = pCFileBytes->Release();
  1629. DH_ASSERT(0 == ulRef);
  1630. }
  1631. // Get the name of file, will be used later to delete the file
  1632. if(NULL != pVirtualDFRoot)
  1633. {
  1634. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  1635. if (pFileName != NULL)
  1636. {
  1637. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  1638. }
  1639. }
  1640. // Delete the docfile on disk
  1641. if((S_OK == hr) && (NULL != pFileName))
  1642. {
  1643. if(FALSE == DeleteFile(pFileName))
  1644. {
  1645. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1646. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1647. }
  1648. }
  1649. // Delete Chance docfile tree
  1650. if(NULL != pTestChanceDF)
  1651. {
  1652. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1653. pTestChanceDF->GetChanceDFRoot());
  1654. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1655. delete pTestChanceDF;
  1656. pTestChanceDF = NULL;
  1657. }
  1658. // Delete Virtual docfile tree
  1659. if (NULL != pTestILockBytesDF)
  1660. {
  1661. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1662. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  1663. delete pTestILockBytesDF;
  1664. pTestILockBytesDF = NULL;
  1665. }
  1666. if(NULL != pFileName)
  1667. {
  1668. delete pFileName;
  1669. pFileName = NULL;
  1670. }
  1671. // Stop logging the test
  1672. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_104 finished")) );
  1673. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1674. return hr;
  1675. #endif //_MAC
  1676. }
  1677. //----------------------------------------------------------------------------
  1678. //
  1679. // Test: ILKBTEST_105
  1680. //
  1681. // synopsis: The test first creates an ILockBytes instance and then uses this
  1682. // ILockBytes instead of OLE provided ILockBytes file in the under
  1683. // lying file system. Thus the root DocFile is created upon a
  1684. // ILockBytes instead of a file system file, therby exercising the
  1685. // ILockBytes functionality. This test opens the Asynchronous
  1686. // docfile on ILockBytes
  1687. //
  1688. // This test attempts illegal operation on StgGetIFillBytesOnILock
  1689. // Bytes api call.
  1690. //
  1691. // Arguments:[argc]
  1692. // [argv]
  1693. //
  1694. // Returns: HRESULT
  1695. //
  1696. // History: 6-Aug-1996 NarindK Created.
  1697. //
  1698. // THIS TEST CAUSES GPF IN OLE32.DLL, HENCE NOT PART OF AUTOMATED TEST RUN
  1699. // BUG: 52513
  1700. // Notes: This test runs in direct, transacted, and transacted deny write
  1701. // modes
  1702. //
  1703. // New Test Notes:
  1704. // 1. Old File: - none -
  1705. // 2. Old name of test : -none-
  1706. // New Name of test : ILKBTEST_105
  1707. // 3. To run the test, do the following at command prompt.
  1708. // a. stgbase /seed:0 /t:ILKBTEST-105 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1709. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1710. // b. stgbase /seed:0 /t:ILKBTEST-105 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1711. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1712. // c. stgbase /seed:0 /t:ILKBTEST-105 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1713. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1714. //
  1715. // BUGNOTE: Conversion: ILKBTEST-105 NO - not supported in nss
  1716. //
  1717. //-----------------------------------------------------------------------------
  1718. HRESULT ILKBTEST_105(int argc, char *argv[])
  1719. {
  1720. #ifdef _MAC
  1721. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!ILKBTEST_105 crashes")) );
  1722. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!To be investigated")) );
  1723. return E_NOTIMPL;
  1724. #else
  1725. HRESULT hr = S_OK;
  1726. HRESULT hr2 = S_OK;
  1727. ChanceDF *pTestChanceDF = NULL;
  1728. ILockBytesDF *pTestILockBytesDF = NULL;
  1729. VirtualCtrNode *pVirtualDFRoot = NULL;
  1730. DWORD dwRootMode = 0;
  1731. DWORD dwStgMode = 0;
  1732. LPTSTR pFileName = NULL;
  1733. ULONG ulRef = 0;
  1734. CFileBytes *pCFileBytes = NULL;
  1735. IFillLockBytes *pIFillLockBytes = NULL;
  1736. // Not for 2phase. Bail.
  1737. if (DoingDistrib ())
  1738. {
  1739. return S_OK;
  1740. }
  1741. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_105"));
  1742. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1743. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_105 started.")) );
  1744. DH_TRACE((
  1745. DH_LVL_TRACE1,
  1746. TEXT("ILockBytes-Attempt illegal ops StgGetIFillBytesOnILOckBytes")));
  1747. // Create the new ChanceDocFile tree that would consist of chance nodes.
  1748. if (S_OK == hr)
  1749. {
  1750. pTestChanceDF = new ChanceDF();
  1751. if(NULL == pTestChanceDF)
  1752. {
  1753. hr = E_OUTOFMEMORY;
  1754. }
  1755. }
  1756. if (S_OK == hr)
  1757. {
  1758. hr = pTestChanceDF->CreateFromParams(argc, argv);
  1759. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  1760. }
  1761. if (S_OK == hr)
  1762. {
  1763. dwRootMode = pTestChanceDF->GetRootMode();
  1764. dwStgMode = pTestChanceDF->GetStgMode();
  1765. DH_TRACE((
  1766. DH_LVL_TRACE1,
  1767. TEXT("Run Mode for ILKBTEST_105, Access mode: %lx"),
  1768. dwRootMode));
  1769. }
  1770. // Create the DocFile tree based on ChanceDocFile tree created in
  1771. // previous step
  1772. if (S_OK == hr)
  1773. {
  1774. pTestILockBytesDF = new ILockBytesDF();
  1775. if(NULL == pTestILockBytesDF)
  1776. {
  1777. hr = E_OUTOFMEMORY;
  1778. }
  1779. }
  1780. if (S_OK == hr)
  1781. {
  1782. hr = pTestILockBytesDF->GenerateVirtualDF(
  1783. pTestChanceDF,
  1784. &pVirtualDFRoot);
  1785. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  1786. }
  1787. if (S_OK == hr)
  1788. {
  1789. DH_TRACE((
  1790. DH_LVL_TRACE1,
  1791. TEXT("DocFile - CreateFromParams - successfully created.")));
  1792. }
  1793. else
  1794. {
  1795. DH_TRACE((
  1796. DH_LVL_TRACE1,
  1797. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  1798. hr));
  1799. }
  1800. // Commit all storages/streams
  1801. if (S_OK == hr)
  1802. {
  1803. hr = ParseVirtualDFAndCommitAllOpenStgs(
  1804. pVirtualDFRoot,
  1805. STGC_DEFAULT,
  1806. NODE_INC_TOPSTG);
  1807. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1808. }
  1809. if(S_OK == hr)
  1810. {
  1811. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  1812. }
  1813. else
  1814. {
  1815. DH_TRACE((
  1816. DH_LVL_TRACE1,
  1817. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  1818. hr));
  1819. }
  1820. // Release all substorages/streams too
  1821. if (S_OK == hr)
  1822. {
  1823. hr = ParseVirtualDFAndCloseOpenStgsStms(
  1824. pVirtualDFRoot,
  1825. NODE_EXC_TOPSTG);
  1826. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  1827. }
  1828. if(S_OK == hr)
  1829. {
  1830. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  1831. }
  1832. else
  1833. {
  1834. DH_TRACE((
  1835. DH_LVL_TRACE1,
  1836. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  1837. hr));
  1838. }
  1839. // Close the Root
  1840. if(S_OK == hr)
  1841. {
  1842. hr = pVirtualDFRoot->Close();
  1843. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  1844. }
  1845. if(S_OK == hr)
  1846. {
  1847. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  1848. }
  1849. else
  1850. {
  1851. DH_TRACE((
  1852. DH_LVL_TRACE1,
  1853. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  1854. hr));
  1855. }
  1856. // Now open this docfile on Async docfile API calls.
  1857. if(S_OK == hr)
  1858. {
  1859. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  1860. hr = StgGetIFillLockBytesOnILockBytes(pCFileBytes, NULL);
  1861. }
  1862. if(S_OK != hr)
  1863. {
  1864. DH_TRACE((
  1865. DH_LVL_TRACE1,
  1866. TEXT("StgGetIFillLockBytesOnILockBytes failed as exp hr = 0x%lx"),
  1867. hr));
  1868. hr = S_OK;
  1869. }
  1870. else
  1871. {
  1872. DH_TRACE((
  1873. DH_LVL_TRACE1,
  1874. TEXT("StgGetIFillLockBytesOnILockBytes passed unexp, hr=0x%lx "),
  1875. hr));
  1876. }
  1877. // if everything goes well, log test as passed else failed.
  1878. if (S_OK == hr)
  1879. {
  1880. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_105 passed.")) );
  1881. }
  1882. else
  1883. {
  1884. DH_LOG((LOG_FAIL,
  1885. TEXT("Test variation ILKBTEST_105 failed, hr=0x%lx."),
  1886. hr) );
  1887. }
  1888. // Release ILockBytes
  1889. if(NULL != pCFileBytes)
  1890. {
  1891. // Release would destroy pCFileBytes object when RefCount reaches zero.
  1892. ulRef = pCFileBytes->Release();
  1893. DH_ASSERT(0 == ulRef);
  1894. }
  1895. // Cleanup
  1896. // Get the name of file, will be used later to delete the file
  1897. if(NULL != pVirtualDFRoot)
  1898. {
  1899. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  1900. if (pFileName != NULL)
  1901. {
  1902. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  1903. }
  1904. }
  1905. // Delete the docfile on disk
  1906. if((S_OK == hr) && (NULL != pFileName))
  1907. {
  1908. if(FALSE == DeleteFile(pFileName))
  1909. {
  1910. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  1911. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  1912. }
  1913. }
  1914. // Delete Chance docfile tree
  1915. if(NULL != pTestChanceDF)
  1916. {
  1917. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  1918. pTestChanceDF->GetChanceDFRoot());
  1919. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  1920. delete pTestChanceDF;
  1921. pTestChanceDF = NULL;
  1922. }
  1923. // Delete Virtual docfile tree
  1924. if (NULL != pTestILockBytesDF)
  1925. {
  1926. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  1927. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  1928. delete pTestILockBytesDF;
  1929. pTestILockBytesDF = NULL;
  1930. }
  1931. if(NULL != pFileName)
  1932. {
  1933. delete pFileName;
  1934. pFileName = NULL;
  1935. }
  1936. // Stop logging the test
  1937. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_105 finished")) );
  1938. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  1939. return hr;
  1940. #endif //_MAC
  1941. }
  1942. //----------------------------------------------------------------------------
  1943. //
  1944. // Test: ILKBTEST_106
  1945. //
  1946. // synopsis: The test first creates an ILockBytes instance and then uses this
  1947. // ILockBytes instead of OLE provided ILockBytes file in the under
  1948. // lying file system. Thus the root DocFile is created upon a
  1949. // ILockBytes instead of a file system file, therby exercising the
  1950. // ILockBytes functionality. This test opens the Asynchronous
  1951. // docfile on ILockBytes
  1952. //
  1953. // This test attempts illegal operation on StgGetIFillBytesOnILock
  1954. // Bytes api call. Test needs to be integrated with ILKBTEST_105
  1955. // once the bugs are fixed.
  1956. //
  1957. // Arguments:[argc]
  1958. // [argv]
  1959. //
  1960. // Returns: HRESULT
  1961. //
  1962. // History: 6-Aug-1996 NarindK Created.
  1963. //
  1964. // Notes: This test runs in direct, transacted, and transacted deny write
  1965. // modes
  1966. //
  1967. // THIS TEST CAUSES GPF IN OLE32.DLL, HENCE NOT PART OF AUTOMATED TEST RUN
  1968. // BUG: 52522
  1969. //
  1970. // New Test Notes:
  1971. // 1. Old File: - none -
  1972. // 2. Old name of test : -none-
  1973. // New Name of test : ILKBTEST_106
  1974. // 3. To run the test, do the following at command prompt.
  1975. // a. stgbase /seed:0 /t:ILKBTEST-106 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1976. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  1977. // b. stgbase /seed:0 /t:ILKBTEST-106 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1978. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  1979. // c. stgbase /seed:0 /t:ILKBTEST-106 /dfdepth:1-2 /dfstg:1-3 /dfstm:1-3
  1980. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  1981. //
  1982. // BUGNOTE: Conversion: ILKBTEST-106 NO - not supported in nss
  1983. //
  1984. //-----------------------------------------------------------------------------
  1985. HRESULT ILKBTEST_106(int argc, char *argv[])
  1986. {
  1987. #ifdef _MAC
  1988. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!ILKBTEST_106 crashes")) );
  1989. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!To be investigated")) );
  1990. return E_NOTIMPL;
  1991. #else
  1992. HRESULT hr = S_OK;
  1993. HRESULT hr2 = S_OK;
  1994. ChanceDF *pTestChanceDF = NULL;
  1995. ILockBytesDF *pTestILockBytesDF = NULL;
  1996. VirtualCtrNode *pVirtualDFRoot = NULL;
  1997. DWORD dwRootMode = 0;
  1998. DWORD dwStgMode = 0;
  1999. LPTSTR pFileName = NULL;
  2000. ULONG ulRef = 0;
  2001. CFileBytes *pCFileBytes = NULL;
  2002. IFillLockBytes *pIFillLockBytes = NULL;
  2003. // Not for 2phase. Bail.
  2004. if (DoingDistrib ())
  2005. {
  2006. return S_OK;
  2007. }
  2008. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_106"));
  2009. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2010. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_106 started.")) );
  2011. DH_TRACE((
  2012. DH_LVL_TRACE1,
  2013. TEXT("ILockBytes-Attempt illegal ops StgGetIFillBytesOnILOckBytes")));
  2014. // Create the new ChanceDocFile tree that would consist of chance nodes.
  2015. if (S_OK == hr)
  2016. {
  2017. pTestChanceDF = new ChanceDF();
  2018. if(NULL == pTestChanceDF)
  2019. {
  2020. hr = E_OUTOFMEMORY;
  2021. }
  2022. }
  2023. if (S_OK == hr)
  2024. {
  2025. hr = pTestChanceDF->CreateFromParams(argc, argv);
  2026. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  2027. }
  2028. if (S_OK == hr)
  2029. {
  2030. dwRootMode = pTestChanceDF->GetRootMode();
  2031. dwStgMode = pTestChanceDF->GetStgMode();
  2032. DH_TRACE((
  2033. DH_LVL_TRACE1,
  2034. TEXT("Run Mode for ILKBTEST_106, Access mode: %lx"),
  2035. dwRootMode));
  2036. }
  2037. // Create the DocFile tree based on ChanceDocFile tree created in
  2038. // previous step
  2039. if (S_OK == hr)
  2040. {
  2041. pTestILockBytesDF = new ILockBytesDF();
  2042. if(NULL == pTestILockBytesDF)
  2043. {
  2044. hr = E_OUTOFMEMORY;
  2045. }
  2046. }
  2047. if (S_OK == hr)
  2048. {
  2049. hr = pTestILockBytesDF->GenerateVirtualDF(
  2050. pTestChanceDF,
  2051. &pVirtualDFRoot);
  2052. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  2053. }
  2054. if (S_OK == hr)
  2055. {
  2056. DH_TRACE((
  2057. DH_LVL_TRACE1,
  2058. TEXT("DocFile - CreateFromParams - successfully created.")));
  2059. }
  2060. else
  2061. {
  2062. DH_TRACE((
  2063. DH_LVL_TRACE1,
  2064. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  2065. hr));
  2066. }
  2067. // Commit all storages/streams
  2068. if (S_OK == hr)
  2069. {
  2070. hr = ParseVirtualDFAndCommitAllOpenStgs(
  2071. pVirtualDFRoot,
  2072. STGC_DEFAULT,
  2073. NODE_INC_TOPSTG);
  2074. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2075. }
  2076. if(S_OK == hr)
  2077. {
  2078. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  2079. }
  2080. else
  2081. {
  2082. DH_TRACE((
  2083. DH_LVL_TRACE1,
  2084. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  2085. hr));
  2086. }
  2087. // Release all substorages/streams too
  2088. if (S_OK == hr)
  2089. {
  2090. hr = ParseVirtualDFAndCloseOpenStgsStms(
  2091. pVirtualDFRoot,
  2092. NODE_EXC_TOPSTG);
  2093. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2094. }
  2095. if(S_OK == hr)
  2096. {
  2097. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  2098. }
  2099. else
  2100. {
  2101. DH_TRACE((
  2102. DH_LVL_TRACE1,
  2103. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  2104. hr));
  2105. }
  2106. // Close the Root
  2107. if(S_OK == hr)
  2108. {
  2109. hr = pVirtualDFRoot->Close();
  2110. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2111. }
  2112. if(S_OK == hr)
  2113. {
  2114. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  2115. }
  2116. else
  2117. {
  2118. DH_TRACE((
  2119. DH_LVL_TRACE1,
  2120. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  2121. hr));
  2122. }
  2123. // Now get IFillLockBytes.
  2124. if(S_OK == hr)
  2125. {
  2126. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  2127. hr = StgGetIFillLockBytesOnILockBytes(NULL, &pIFillLockBytes);
  2128. }
  2129. /* Commented out becuase OLE passes this
  2130. if(S_OK != hr)
  2131. {
  2132. DH_TRACE((
  2133. DH_LVL_TRACE1,
  2134. TEXT("StgGetIFillLockBytesOnILockBytes failed as exp hr = 0x%lx"),
  2135. hr));
  2136. hr = S_OK;
  2137. }
  2138. else
  2139. {
  2140. DH_TRACE((
  2141. DH_LVL_TRACE1,
  2142. TEXT("StgGetIFillLockBytesOnILockBytes passed unexp, hr=0x%lx "),
  2143. hr));
  2144. }
  2145. */
  2146. if(S_OK == hr)
  2147. {
  2148. ulRef = pIFillLockBytes->AddRef();
  2149. }
  2150. if(S_OK == hr)
  2151. {
  2152. ulRef = pIFillLockBytes->Release();
  2153. }
  2154. // if everything goes well, log test as passed else failed.
  2155. if (S_OK == hr)
  2156. {
  2157. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_106 passed.")) );
  2158. }
  2159. else
  2160. {
  2161. DH_LOG((LOG_FAIL,
  2162. TEXT("Test variation ILKBTEST_106 failed, hr=0x%lx."),
  2163. hr) );
  2164. }
  2165. // Release ILockBytes
  2166. if(NULL != pCFileBytes)
  2167. {
  2168. // Release would destroy pCFileBytes object when RefCount reaches zero.
  2169. ulRef = pCFileBytes->Release();
  2170. DH_ASSERT(0 == ulRef);
  2171. }
  2172. // Cleanup
  2173. // Get the name of file, will be used later to delete the file
  2174. if(NULL != pVirtualDFRoot)
  2175. {
  2176. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  2177. if (pFileName != NULL)
  2178. {
  2179. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  2180. }
  2181. }
  2182. // Delete the docfile on disk
  2183. if((S_OK == hr) && (NULL != pFileName))
  2184. {
  2185. if(FALSE == DeleteFile(pFileName))
  2186. {
  2187. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2188. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2189. }
  2190. }
  2191. // Delete Chance docfile tree
  2192. if(NULL != pTestChanceDF)
  2193. {
  2194. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  2195. pTestChanceDF->GetChanceDFRoot());
  2196. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  2197. delete pTestChanceDF;
  2198. pTestChanceDF = NULL;
  2199. }
  2200. // Delete Virtual docfile tree
  2201. if (NULL != pTestILockBytesDF)
  2202. {
  2203. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  2204. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  2205. delete pTestILockBytesDF;
  2206. pTestILockBytesDF = NULL;
  2207. }
  2208. if(NULL != pFileName)
  2209. {
  2210. delete pFileName;
  2211. pFileName = NULL;
  2212. }
  2213. // Stop logging the test
  2214. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_106 finished")) );
  2215. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2216. return hr;
  2217. #endif //_MAC
  2218. }
  2219. //----------------------------------------------------------------------------
  2220. //
  2221. // Test: ILKBTEST_107
  2222. //
  2223. // synopsis: The test first creates an ILockBytes instance and then uses this
  2224. // ILockBytes instead of OLE provided ILockBytes file in the under
  2225. // lying file system. Thus the root DocFile is created upon a
  2226. // ILockBytes instead of a file system file, therby exercising the
  2227. // ILockBytes functionality. This test calls StgIstorageILockBytes
  2228. // API and tests it that ILockBytes array contains a storage object.
  2229. // Also attempts illegal operations with StgIstorageILockBytes API.
  2230. //
  2231. // Arguments:[argc]
  2232. // [argv]
  2233. //
  2234. // Returns: HRESULT
  2235. //
  2236. // History: 15-Aug-1996 NarindK Created.
  2237. //
  2238. // Notes: This test runs in direct, transacted, and transacted deny write
  2239. // modes
  2240. //
  2241. // New Test Notes:
  2242. // 1. Old File: - none -
  2243. // 2. Old name of test : -none-
  2244. // New Name of test : ILKBTEST_107
  2245. // 3. To run the test, do the following at command prompt.
  2246. // a. stgbase /seed:0 /t:ILKBTEST-107 /dfdepth:0-1 /dfstg:0-1 /dfstm:0-1
  2247. // /dfRootMode:dirReadWriteShEx /dfStgMode:dirReadWriteShEx
  2248. // b. stgbase /seed:0 /t:ILKBTEST-107 /dfdepth:0-1 /dfstg:0-1 /dfstm:0-1
  2249. // /dfRootMode:xactReadWriteShEx /dfStgMode:xactReadWriteShEx
  2250. // c. stgbase /seed:0 /t:ILKBTEST-107 /dfdepth:0-1 /dfstg:0-1 /dfstm:0-1
  2251. // /dfRootMode:xactReadWriteShDenyW /dfStgMode:xactReadWriteShEx
  2252. //
  2253. // BUGNOTE: Conversion: ILKBTEST-107 NO - not supported in nss
  2254. //
  2255. //-----------------------------------------------------------------------------
  2256. HRESULT ILKBTEST_107(int argc, char *argv[])
  2257. {
  2258. HRESULT hr = S_OK;
  2259. HRESULT hr2 = S_OK;
  2260. ChanceDF *pTestChanceDF = NULL;
  2261. ILockBytesDF *pTestILockBytesDF = NULL;
  2262. VirtualCtrNode *pVirtualDFRoot = NULL;
  2263. DWORD dwRootMode = 0;
  2264. DWORD dwStgMode = 0;
  2265. LPTSTR pFileName = NULL;
  2266. ULONG ulRef = 0;
  2267. CFileBytes *pCFileBytes = NULL;
  2268. // Not for 2phase. Bail.
  2269. if (DoingDistrib ())
  2270. {
  2271. return S_OK;
  2272. }
  2273. DH_FUNCENTRY(&hr, DH_LVL_DFLIB, _TEXT("ILKBTEST_107"));
  2274. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2275. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_107 started.")) );
  2276. DH_TRACE((
  2277. DH_LVL_TRACE1,
  2278. TEXT("ILockBytes-Attempt StgIsStorageILockBytes ")));
  2279. // Create the new ChanceDocFile tree that would consist of chance nodes.
  2280. if (S_OK == hr)
  2281. {
  2282. pTestChanceDF = new ChanceDF();
  2283. if(NULL == pTestChanceDF)
  2284. {
  2285. hr = E_OUTOFMEMORY;
  2286. }
  2287. }
  2288. if (S_OK == hr)
  2289. {
  2290. hr = pTestChanceDF->CreateFromParams(argc, argv);
  2291. DH_HRCHECK(hr, TEXT("pTestChanceDF->CreateFromParams")) ;
  2292. }
  2293. if (S_OK == hr)
  2294. {
  2295. dwRootMode = pTestChanceDF->GetRootMode();
  2296. dwStgMode = pTestChanceDF->GetStgMode();
  2297. DH_TRACE((
  2298. DH_LVL_TRACE1,
  2299. TEXT("Run Mode for ILKBTEST_107, Access mode: %lx"),
  2300. dwRootMode));
  2301. }
  2302. // Create the DocFile tree based on ChanceDocFile tree created in
  2303. // previous step
  2304. if (S_OK == hr)
  2305. {
  2306. pTestILockBytesDF = new ILockBytesDF();
  2307. if(NULL == pTestILockBytesDF)
  2308. {
  2309. hr = E_OUTOFMEMORY;
  2310. }
  2311. }
  2312. if (S_OK == hr)
  2313. {
  2314. hr = pTestILockBytesDF->GenerateVirtualDF(
  2315. pTestChanceDF,
  2316. &pVirtualDFRoot);
  2317. DH_HRCHECK(hr, TEXT("pTestILockBytesDF->GenerateVirtualDF")) ;
  2318. }
  2319. if (S_OK == hr)
  2320. {
  2321. DH_TRACE((
  2322. DH_LVL_TRACE1,
  2323. TEXT("DocFile - CreateFromParams - successfully created.")));
  2324. }
  2325. else
  2326. {
  2327. DH_TRACE((
  2328. DH_LVL_TRACE1,
  2329. TEXT("DocFile - CreateFromParams - failed, hr=0x%lx."),
  2330. hr));
  2331. }
  2332. // Commit all storages/streams
  2333. if (S_OK == hr)
  2334. {
  2335. hr = ParseVirtualDFAndCommitAllOpenStgs(
  2336. pVirtualDFRoot,
  2337. STGC_DEFAULT,
  2338. NODE_INC_TOPSTG);
  2339. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2340. }
  2341. if(S_OK == hr)
  2342. {
  2343. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCommitAllOpenStgs passed")));
  2344. }
  2345. else
  2346. {
  2347. DH_TRACE((
  2348. DH_LVL_TRACE1,
  2349. TEXT("ParseVirtualDFAndCommitAllOpenStgs failed unexp,hr=0x%lx "),
  2350. hr));
  2351. }
  2352. // Release all substorages/streams too
  2353. if (S_OK == hr)
  2354. {
  2355. hr = ParseVirtualDFAndCloseOpenStgsStms(
  2356. pVirtualDFRoot,
  2357. NODE_EXC_TOPSTG);
  2358. DH_HRCHECK(hr, TEXT("ParseVirtualDFAndCloseOpenStgsStms"));
  2359. }
  2360. if(S_OK == hr)
  2361. {
  2362. DH_TRACE((DH_LVL_TRACE1, TEXT("ParseVirtualDFAndCloseAllOpenStgs passed")));
  2363. }
  2364. else
  2365. {
  2366. DH_TRACE((
  2367. DH_LVL_TRACE1,
  2368. TEXT("ParseVirtualDFAndCloseAllOpenStgs failed unexp,hr=0x%lx "),
  2369. hr));
  2370. }
  2371. // Call StgIsStorageILockBytes API
  2372. if(S_OK == hr)
  2373. {
  2374. pCFileBytes = pTestILockBytesDF->_pCFileBytes;
  2375. DH_ASSERT(NULL != pCFileBytes);
  2376. hr = StgIsStorageILockBytes(pCFileBytes);
  2377. DH_HRCHECK(hr, TEXT("StgIsStorageILockBytes"));
  2378. }
  2379. if(S_OK == hr)
  2380. {
  2381. DH_TRACE((DH_LVL_TRACE1, TEXT("StgIsStorageILockBytes passed as exp. ")));
  2382. }
  2383. else
  2384. {
  2385. DH_TRACE((
  2386. DH_LVL_TRACE1,
  2387. TEXT("StgIsStorageILockBytes failed unexp, hr=0x%lx "),
  2388. hr));
  2389. }
  2390. // Call StgIsStorageILockBytes API with NULL parameter
  2391. if(S_OK == hr)
  2392. {
  2393. hr = StgIsStorageILockBytes(NULL);
  2394. }
  2395. if(STG_E_INVALIDPOINTER == hr)
  2396. {
  2397. DH_TRACE((
  2398. DH_LVL_TRACE1,
  2399. TEXT("StgIsStorageILockBytes failed as exp, hr=0x%lx. "),
  2400. hr));
  2401. hr = S_OK;
  2402. }
  2403. else
  2404. {
  2405. DH_TRACE((
  2406. DH_LVL_TRACE1,
  2407. TEXT("StgIsStorageILockBytes didn't failed as exp, hr=0x%lx "),
  2408. hr));
  2409. hr = E_FAIL;
  2410. }
  2411. // Close the Root
  2412. if(S_OK == hr)
  2413. {
  2414. hr = pVirtualDFRoot->Close();
  2415. DH_HRCHECK(hr, TEXT("VirtualCtrNode::Close")) ;
  2416. }
  2417. if(S_OK == hr)
  2418. {
  2419. DH_TRACE((DH_LVL_TRACE1, TEXT("VirtualCtrNode::Close passed as exp. ")));
  2420. }
  2421. else
  2422. {
  2423. DH_TRACE((
  2424. DH_LVL_TRACE1,
  2425. TEXT("VirtualCtrNode::Close failed unexp, hr=0x%lx "),
  2426. hr));
  2427. }
  2428. // if everything goes well, log test as passed else failed.
  2429. if (S_OK == hr)
  2430. {
  2431. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_107 passed.")) );
  2432. }
  2433. else
  2434. {
  2435. DH_LOG((LOG_FAIL,
  2436. TEXT("Test variation ILKBTEST_107 failed, hr=0x%lx."),
  2437. hr) );
  2438. }
  2439. // Release ILockBytes
  2440. if(NULL != pCFileBytes)
  2441. {
  2442. // Release would destroy pCFileBytes object when RefCount reaches zero.
  2443. ulRef = pCFileBytes->Release();
  2444. DH_ASSERT(0 == ulRef);
  2445. }
  2446. // Cleanup
  2447. // Get the name of file, will be used later to delete the file
  2448. if(NULL != pVirtualDFRoot)
  2449. {
  2450. pFileName= new TCHAR[_tcslen(pTestILockBytesDF->GetDocFileName())+1];
  2451. if (pFileName != NULL)
  2452. {
  2453. _tcscpy(pFileName, pTestILockBytesDF->GetDocFileName());
  2454. }
  2455. }
  2456. // Delete the docfile on disk
  2457. if((S_OK == hr) && (NULL != pFileName))
  2458. {
  2459. if(FALSE == DeleteFile(pFileName))
  2460. {
  2461. hr2 = HRESULT_FROM_WIN32(GetLastError()) ;
  2462. DH_HRCHECK(hr2, TEXT("DeleteFile")) ;
  2463. }
  2464. }
  2465. // Delete Chance docfile tree
  2466. if(NULL != pTestChanceDF)
  2467. {
  2468. hr2 = pTestChanceDF->DeleteChanceDocFileTree(
  2469. pTestChanceDF->GetChanceDFRoot());
  2470. DH_HRCHECK(hr2, TEXT("pTestChanceDF->DeleteChanceFileDocTree")) ;
  2471. delete pTestChanceDF;
  2472. pTestChanceDF = NULL;
  2473. }
  2474. // Delete Virtual docfile tree
  2475. if (NULL != pTestILockBytesDF)
  2476. {
  2477. hr2 = pTestILockBytesDF->DeleteVirtualDocFileTree(pVirtualDFRoot);
  2478. DH_HRCHECK(hr2, TEXT("pTestILockBytesDF->DeleteVirtualFileDocTree")) ;
  2479. delete pTestILockBytesDF;
  2480. pTestILockBytesDF = NULL;
  2481. }
  2482. if(NULL != pFileName)
  2483. {
  2484. delete pFileName;
  2485. pFileName = NULL;
  2486. }
  2487. // Stop logging the test
  2488. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_107 finished")) );
  2489. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2490. return hr;
  2491. }
  2492. //----------------------------------------------------------------------------
  2493. //
  2494. // Test: ILKBTEST_108
  2495. //
  2496. // Synopsis: Legit/illegit Tests for StgGetIFillLockBytesOnFile OLE API.
  2497. //
  2498. // Arguments:[ulSeed]
  2499. //
  2500. // Returns: HRESULT
  2501. //
  2502. // History: 16-Aug-1996 NarindK Created.
  2503. //
  2504. // Notes:
  2505. //
  2506. // THIS TEST CAUSES GPF IN OLE32.DLL, HENCE NOT PART OF AUTOMATED TEST RUN
  2507. // OLE BUG: 53647
  2508. //
  2509. // New Test Notes:
  2510. // 1. Old File: -none-
  2511. // 2. Old name of test : -none-
  2512. // New Name of test : ILKBTEST_108
  2513. // 3. To run the test, do the following at command prompt.
  2514. // a. stgbase /seed:2 /t:ILKBTEST-108
  2515. //
  2516. // BUGNOTE: Conversion: ILKBTEST-108 NO - not supported in nss
  2517. //
  2518. //-----------------------------------------------------------------------------
  2519. HRESULT ILKBTEST_108(ULONG ulSeed)
  2520. {
  2521. #ifdef _MAC
  2522. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!ILKBTEST_108 crashes")) );
  2523. DH_TRACE((DH_LVL_TRACE1, TEXT("!!!!!!!!!!!!To be investigated")) );
  2524. return E_NOTIMPL;
  2525. #else
  2526. HRESULT hr = S_OK;
  2527. IFillLockBytes *pIFillLockBytes = NULL;
  2528. DG_STRING *pdgu = NULL;
  2529. USHORT usErr = NULL;
  2530. LPTSTR ptszRootDocFileName = NULL;
  2531. LPOLESTR poszRootDocFileName = NULL;
  2532. ULONG ulRef = 0;
  2533. // Not for 2phase. Bail.
  2534. if (DoingDistrib ())
  2535. {
  2536. return S_OK;
  2537. }
  2538. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("ILKBTEST_108"));
  2539. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2540. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_108 started.")) );
  2541. DH_TRACE((DH_LVL_TRACE1,
  2542. TEXT("Attempt legit/illegit tests StgGetIFillLockBytesOnFile API")));
  2543. if(S_OK == hr)
  2544. {
  2545. // Create a new DataGen object to create random UNICODE strings.
  2546. pdgu = new(NullOnFail) DG_STRING(ulSeed);
  2547. if (NULL == pdgu)
  2548. {
  2549. hr = E_OUTOFMEMORY;
  2550. }
  2551. }
  2552. if(S_OK == hr)
  2553. {
  2554. // Log the seed value
  2555. usErr = pdgu->GetSeed(&ulSeed);
  2556. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  2557. DH_TRACE((DH_LVL_TRACE1, TEXT("ILKBTEST_108 Seed: %lu"), ulSeed));
  2558. }
  2559. // StgGetIFillLockBytesOnFile called with null file name
  2560. if(S_OK == hr)
  2561. {
  2562. hr = StgGetIFillLockBytesOnFile(NULL, &pIFillLockBytes);
  2563. }
  2564. // OLE creates a temp file name and will pass this call. Shuld return S_OK.
  2565. if(S_OK == hr)
  2566. {
  2567. DH_TRACE((
  2568. DH_LVL_TRACE1,
  2569. TEXT("StgGetIFillLockBytesOnFile passed as exp ")));
  2570. }
  2571. else
  2572. {
  2573. DH_TRACE((
  2574. DH_LVL_TRACE1,
  2575. TEXT("StgGetIFillLockBytesOnFile failed as exp hr = 0x%lx"),
  2576. hr));
  2577. }
  2578. if(S_OK == hr)
  2579. {
  2580. ulRef = pIFillLockBytes->AddRef();
  2581. ulRef = pIFillLockBytes->Release();
  2582. }
  2583. // Release the pointer
  2584. if(NULL != pIFillLockBytes)
  2585. {
  2586. ulRef = pIFillLockBytes->Release();
  2587. DH_ASSERT(0 == ulRef);
  2588. pIFillLockBytes = NULL;
  2589. }
  2590. // Generate a new RootDocFile name
  2591. if(S_OK == hr)
  2592. {
  2593. hr = GenerateRandomName(pdgu, MINLENGTH,MAXLENGTH,&ptszRootDocFileName);
  2594. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2595. }
  2596. if(S_OK == hr)
  2597. {
  2598. // Convert RootDocFile name to OLECHAR
  2599. hr = TStringToOleString(ptszRootDocFileName, &poszRootDocFileName);
  2600. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2601. }
  2602. // StgGetIFillLockBytesOnFile called with non empty file name parameter
  2603. // and valid out parameter.
  2604. if(S_OK == hr)
  2605. {
  2606. hr = StgGetIFillLockBytesOnFile( poszRootDocFileName, &pIFillLockBytes);
  2607. }
  2608. if(S_OK == hr)
  2609. {
  2610. DH_TRACE((
  2611. DH_LVL_TRACE1,
  2612. TEXT("StgGetIFillLockBytesOnFile passed as exp ")));
  2613. }
  2614. else
  2615. {
  2616. DH_TRACE((
  2617. DH_LVL_TRACE1,
  2618. TEXT("StgGetIFillLockBytesOnFile failed unexp, hr=0x%lx"),
  2619. hr));
  2620. }
  2621. // Release the pointer
  2622. if(NULL != pIFillLockBytes)
  2623. {
  2624. ulRef = pIFillLockBytes->Release();
  2625. DH_ASSERT(0 == ulRef);
  2626. pIFillLockBytes = NULL;
  2627. }
  2628. // Delete string
  2629. if(NULL != ptszRootDocFileName)
  2630. {
  2631. delete ptszRootDocFileName;
  2632. ptszRootDocFileName = NULL;
  2633. }
  2634. if(NULL != poszRootDocFileName)
  2635. {
  2636. delete poszRootDocFileName;
  2637. poszRootDocFileName = NULL;
  2638. }
  2639. // StgGetIFillLockBytesOnFile called with NULL second out parameter
  2640. // This should fail
  2641. // Generate a new RootDocFile name
  2642. if(S_OK == hr)
  2643. {
  2644. hr = GenerateRandomName(pdgu, MINLENGTH,MAXLENGTH,&ptszRootDocFileName);
  2645. DH_HRCHECK(hr, TEXT("GenerateRandomName")) ;
  2646. }
  2647. if(S_OK == hr)
  2648. {
  2649. // Convert RootDocFile name to OLECHAR
  2650. hr = TStringToOleString(ptszRootDocFileName, &poszRootDocFileName);
  2651. DH_HRCHECK(hr, TEXT("TStringToOleString")) ;
  2652. }
  2653. if(S_OK == hr)
  2654. {
  2655. hr = StgGetIFillLockBytesOnFile( poszRootDocFileName, NULL);
  2656. }
  2657. if(STG_E_INVALIDPOINTER == hr)
  2658. {
  2659. DH_TRACE((
  2660. DH_LVL_TRACE1,
  2661. TEXT("StgGetIFillLockBytesOnFile fail as exp, hr=0x%lx "),
  2662. hr));
  2663. hr = S_OK;
  2664. }
  2665. else
  2666. {
  2667. DH_TRACE((
  2668. DH_LVL_TRACE1,
  2669. TEXT("StgGetIFillLockBytesOnFile didn't failed as exp,hr=0x%lx"),
  2670. hr));
  2671. hr = E_FAIL;
  2672. }
  2673. // if everything goes well, log test as passed else failed.
  2674. if (S_OK == hr)
  2675. {
  2676. DH_LOG((LOG_PASS, TEXT("Test variation ILKBTEST_108 passed.")) );
  2677. }
  2678. else
  2679. {
  2680. DH_LOG((LOG_FAIL,
  2681. TEXT("Test variation ILKBTEST_108 failed, hr = 0x%lx."),
  2682. hr) );
  2683. }
  2684. // Cleanup
  2685. // Delete string
  2686. if(NULL != ptszRootDocFileName)
  2687. {
  2688. delete ptszRootDocFileName;
  2689. ptszRootDocFileName = NULL;
  2690. }
  2691. if(NULL != poszRootDocFileName)
  2692. {
  2693. delete poszRootDocFileName;
  2694. poszRootDocFileName = NULL;
  2695. }
  2696. // Delete datagen object
  2697. if(NULL != pdgu)
  2698. {
  2699. delete pdgu;
  2700. pdgu = NULL;
  2701. }
  2702. // Stop logging the test
  2703. DH_TRACE((DH_LVL_TRACE1, TEXT("Test variation ILKBTEST_108 finished")) );
  2704. DH_TRACE((DH_LVL_TRACE1, TEXT("--------------------------------------------")) );
  2705. return hr;
  2706. #endif //_MAC
  2707. }