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.

1940 lines
55 KiB

  1. /********************************************************************/
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: hglbtest.cxx
  7. //
  8. // Contents: HGlobal Test Cases
  9. //
  10. // Functions: HGLOBALTEST_100
  11. // HGLOBALTEST_110
  12. // HGLOBALTEST_120
  13. // HGLOBALTEST_130
  14. // HGLOBALTEST_140
  15. // HGLOBALTEST_150
  16. //
  17. // Classes: None
  18. //
  19. // History: 31-JULY-1996 T-ScottG Created
  20. // 27-Mar-97 SCousens Conversionified
  21. //
  22. /********************************************************************/
  23. #include <dfheader.hxx>
  24. #pragma hdrstop
  25. #include <debdlg.h>
  26. #include "init.hxx"
  27. /********************************************************************/
  28. //
  29. // Function: HGLOBALTEST_100
  30. //
  31. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  32. // an ILockByte Interface on top of the HGlobal (set so
  33. // that the ILockBytes will not delete the HGlobal on Release).
  34. // Next, the test writes and reads a specified number of data
  35. // bytes to the ILockBytes interface, and then releases it.
  36. //
  37. // The Test repeats the above sequence (always using the same
  38. // HGlobal) a random number of times. Finally, the HGlobal is
  39. // deleted and the test exits.
  40. //
  41. // Arguments: [ulSeed] - Randomizer Seed
  42. //
  43. // Returns: HRESULT
  44. //
  45. // History: Heavily Modified T-Scottg 7/30/96
  46. // Created Venkatesan Viswanathan
  47. //
  48. // BUGNOTE: Conversion: HGLOBALTEST-100 NO - not supported in nss
  49. //
  50. /********************************************************************/
  51. HRESULT HGLOBALTEST_100 (ULONG ulSeed)
  52. {
  53. HRESULT hr = S_OK;
  54. HANDLE hGlobMem = NULL;
  55. OleHandle hOleGlobMem = NULL;
  56. OleHandle hOleTempMem = NULL;
  57. ILockBytes * pILockBytes = NULL;
  58. ULONG uRet = 0;
  59. DWORD dwSize = 0;
  60. DWORD dwNumIterations = 0;
  61. USHORT usErr = 0;
  62. ULARGE_INTEGER li;
  63. DG_INTEGER dgi(ulSeed);
  64. // Not for 2phase. Bail.
  65. if (DoingDistrib ())
  66. {
  67. return S_OK;
  68. }
  69. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_100"));
  70. // Print Seed to Log
  71. usErr = dgi.GetSeed(&ulSeed);
  72. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  73. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_100 Seed: %d"), ulSeed));
  74. // Randomly calculate ILockBytes length
  75. if (S_OK == hr)
  76. {
  77. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS, MAX_HGLOBAL_PACKETS))
  78. {
  79. hr = S_FALSE;
  80. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  81. }
  82. else
  83. {
  84. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  85. }
  86. }
  87. // Randomly calculate the number of ILockBytes iterations on HGLOBAL
  88. if (S_OK == hr)
  89. {
  90. if (0 != dgi.Generate( &dwNumIterations,
  91. MIN_HGLOBAL_ITERATIONS,
  92. MAX_HGLOBAL_ITERATIONS ))
  93. {
  94. hr = S_FALSE;
  95. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  96. }
  97. }
  98. // Allocate HGLOBAL memory
  99. if (S_OK == hr)
  100. {
  101. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  102. GMEM_MOVEABLE,
  103. dwSize );
  104. if (NULL == hGlobMem)
  105. {
  106. hr = HRESULT_FROM_WIN32(GetLastError());
  107. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  108. }
  109. }
  110. // Repeat the specified number of times
  111. if (S_OK == hr)
  112. {
  113. for (DWORD dwIndex = 0; dwIndex < dwNumIterations; dwIndex++)
  114. {
  115. // Create ILockBytes on HGLOBAL. (Note: HGLOBAL will not be
  116. // deleted when ILockBytes is released)
  117. // Mac porting: CreateILockBytesOnHGlobal does not accept HGLOBAL,
  118. // only OleHandle
  119. if (S_OK == hr)
  120. {
  121. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  122. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  123. }
  124. if (S_OK == hr)
  125. {
  126. hr = CreateILockBytesOnHGlobal( hOleGlobMem,
  127. FALSE,
  128. &pILockBytes );
  129. DH_HRCHECK(hr, TEXT("CreateILockBytesOnHGlobal Failed"));
  130. }
  131. // Obtain HGlobal pointer from ILockBytes
  132. if (S_OK == hr)
  133. {
  134. hr = GetHGlobalFromILockBytes( pILockBytes,
  135. &hOleTempMem );
  136. DH_HRCHECK(hr, TEXT("GetHGlobalFromILockBytes Failed"));
  137. }
  138. // Verify that the memory location that GetHGlobalFromILockBytes
  139. // returned is the same as the memory location passed to
  140. // CreateILockBytesOnHGlobal.
  141. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  142. {
  143. hr = S_FALSE;
  144. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  145. }
  146. // Set the size of the ILockBytes Interface
  147. if (S_OK == hr)
  148. {
  149. DH_ASSERT(NULL != pILockBytes);
  150. // Assign 1/2 of the ILockBytes final size to Large Integer
  151. // Structure. (Note: this is so that the ILockBytes will still
  152. // have to automatically increase its size during WriteAt
  153. // operations in which its size is overflowed)
  154. ULISet32(li, (dwSize/2));
  155. hr = pILockBytes->SetSize(li);
  156. DH_HRCHECK(hr, TEXT("pILockBytes->SetSize Failed"));
  157. }
  158. // Call the ILockBytesWriteTest Test
  159. if (S_OK == hr)
  160. {
  161. hr = ILockBytesWriteTest(pILockBytes, ulSeed, dwSize);
  162. DH_HRCHECK(hr, TEXT("ILockBytesWriteTest Failed"));
  163. }
  164. // Call the ILockBytesReadTest Test
  165. if (S_OK == hr)
  166. {
  167. hr = ILockBytesReadTest(pILockBytes, dwSize);
  168. DH_HRCHECK(hr, TEXT("ILockBytesReadTest Failed"));
  169. }
  170. // Release ILockBytes
  171. if (NULL != pILockBytes)
  172. {
  173. uRet = pILockBytes->Release();
  174. DH_ASSERT(0 == uRet);
  175. pILockBytes = NULL;
  176. }
  177. // If error occurs, break out of loop
  178. if (S_OK != hr)
  179. {
  180. break;
  181. }
  182. }
  183. }
  184. // Free HGLOBAL From memory
  185. if (S_OK == hr)
  186. {
  187. DH_ASSERT(NULL != hGlobMem);
  188. if (NULL != GlobalFree(hGlobMem))
  189. {
  190. hr = HRESULT_FROM_WIN32(GetLastError());
  191. DH_HRCHECK(hr, TEXT("GlobalFree Failed"));
  192. }
  193. else
  194. {
  195. hGlobMem = NULL;
  196. }
  197. }
  198. // Write result to log
  199. if (S_OK == hr)
  200. {
  201. DH_LOG((LOG_PASS, TEXT("HGLOBALTEST_100 Succeeded")));
  202. }
  203. else
  204. {
  205. DH_LOG((LOG_FAIL, TEXT("HGLOBALTEST_100 Failed, hr = 0x%Lx"), hr));
  206. }
  207. return hr;
  208. }
  209. /********************************************************************/
  210. //
  211. // Function: HGLOBALTEST_110
  212. //
  213. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  214. // an ILockBytes Interface on top of the HGlobal (set so
  215. // that the IStream will delete the HGlobal on Release).
  216. // Next, the test writes and reads a specified number of data
  217. // bytes to the ILockBytes interface, and then releases it.
  218. //
  219. // The Test repeats the above sequence a random number of
  220. // times.
  221. //
  222. // Note: This test differs from HGLOBAL_100 in that the
  223. // HGLOBAL is freed by the ILockBytes Interface when it is
  224. // released. It does not re-use the same HGLOBAL when
  225. // multiple ILockBytes are created.
  226. //
  227. // Arguments: [dwSize] - Num of Bytes to Write to ILockBytes
  228. // [dwNumIterations] - Num of ILockBytes Interfaces to
  229. // be created on the same HGlobal
  230. //
  231. // Returns: HRESULT
  232. //
  233. // History: Heavily Modified T-Scottg 7/30/96
  234. // Created Venkatesan Viswanathan
  235. //
  236. // BUGNOTE: Conversion: HGLOBALTEST-110 NO - not supported in nss
  237. //
  238. /********************************************************************/
  239. HRESULT HGLOBALTEST_110 (ULONG ulSeed)
  240. {
  241. HRESULT hr = S_OK;
  242. HGLOBAL hGlobMem = NULL;
  243. OleHandle hOleGlobMem = NULL;
  244. OleHandle hOleTempMem = NULL;
  245. ILockBytes * pILockBytes = NULL;
  246. ULONG uRet = 0;
  247. DWORD dwSize = 0;
  248. DWORD dwNumIterations = 0;
  249. ULARGE_INTEGER li;
  250. USHORT usErr = 0;
  251. DG_INTEGER dgi(ulSeed);
  252. // Not for 2phase. Bail.
  253. if (DoingDistrib ())
  254. {
  255. return S_OK;
  256. }
  257. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_110"));
  258. // Print Seed to Log
  259. usErr = dgi.GetSeed(&ulSeed);
  260. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  261. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_110 Seed: %d"), ulSeed));
  262. // Randomly calculate ILockBytes length
  263. if (S_OK == hr)
  264. {
  265. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS, MAX_HGLOBAL_PACKETS))
  266. {
  267. hr = S_FALSE;
  268. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  269. }
  270. else
  271. {
  272. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  273. }
  274. }
  275. // Randomly calculate the number of ILockBytes iterations on HGLOBAL
  276. if (S_OK == hr)
  277. {
  278. if (0 != dgi.Generate( &dwNumIterations,
  279. MIN_HGLOBAL_ITERATIONS,
  280. MAX_HGLOBAL_ITERATIONS ))
  281. {
  282. hr = S_FALSE;
  283. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  284. }
  285. }
  286. // Repeat the specified number of times
  287. if (S_OK == hr)
  288. {
  289. for (DWORD dwIndex = 0; dwIndex < dwNumIterations; dwIndex++)
  290. {
  291. // Allocate HGLOBAL memory
  292. if (S_OK == hr)
  293. {
  294. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  295. GMEM_MOVEABLE,
  296. dwSize );
  297. if (NULL == hGlobMem)
  298. {
  299. hr = HRESULT_FROM_WIN32(GetLastError());
  300. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  301. }
  302. }
  303. // Create ILockBytes on HGLOBAL. (Note: HGLOBAL will not be
  304. // deleted when ILockBytes is released)
  305. // Mac porting: CreateILockBytesOnHGlobal does not accept HGLOBAL,
  306. // only OleHandle, so first convert the handle
  307. if (S_OK == hr)
  308. {
  309. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  310. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  311. }
  312. if (S_OK == hr)
  313. {
  314. hr = CreateILockBytesOnHGlobal( hOleGlobMem,
  315. TRUE,
  316. &pILockBytes );
  317. DH_HRCHECK(hr, TEXT("CreateILockBytesOnHGlobal Failed"));
  318. }
  319. // Obtain HGlobal pointer from ILockBytes
  320. if (S_OK == hr)
  321. {
  322. hr = GetHGlobalFromILockBytes( pILockBytes,
  323. &hOleTempMem );
  324. DH_HRCHECK(hr, TEXT("GetHGlobalFromILockBytes Failed"));
  325. }
  326. // Verify that the memory location that GetHGlobalFromILockBytes
  327. // returned is the same as the memory location passed to
  328. // CreateILockBytesOnHGlobal.
  329. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  330. {
  331. hr = S_FALSE;
  332. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  333. }
  334. // Set the size of the ILockBytes Interface
  335. if (S_OK == hr)
  336. {
  337. DH_ASSERT(NULL != pILockBytes);
  338. // Assign 1/2 of the ILockBytes final size to Large Integer
  339. // Structure. (Note: this is so that the ILockBytes will still
  340. // have to automatically increase its size during WriteAt
  341. // operations in which its size is overflowed)
  342. ULISet32(li, (dwSize/2));
  343. hr = pILockBytes->SetSize(li);
  344. DH_HRCHECK(hr, TEXT("pILockBytes->SetSize Failed"));
  345. }
  346. // Call the ILockBytesWriteTest Test
  347. if (S_OK == hr)
  348. {
  349. hr = ILockBytesWriteTest(pILockBytes, ulSeed, dwSize);
  350. DH_HRCHECK(hr, TEXT("ILockBytesWriteTest Failed"));
  351. }
  352. // Call the ILockBytesReadTest Test
  353. if (S_OK == hr)
  354. {
  355. hr = ILockBytesReadTest(pILockBytes, dwSize);
  356. DH_HRCHECK(hr, TEXT("ILockBytesReadTest Failed"));
  357. }
  358. // Release ILockBytes
  359. if (NULL != pILockBytes)
  360. {
  361. uRet = pILockBytes->Release();
  362. DH_ASSERT(0 == uRet);
  363. pILockBytes = NULL;
  364. }
  365. // Set hGlobMem to NULL (Note: the memory was freed when ILockBytes
  366. // was released
  367. hGlobMem = NULL;
  368. // If error occurs, break out of loop
  369. if (S_OK != hr)
  370. {
  371. break;
  372. }
  373. }
  374. }
  375. // Write result to log
  376. if (S_OK == hr)
  377. {
  378. DH_LOG((LOG_PASS, TEXT("HGLOBALTEST_110 Succeeded")));
  379. }
  380. else
  381. {
  382. DH_LOG((LOG_FAIL, TEXT("HGLOBALTEST_110 Failed, hr = 0x%Lx"), hr));
  383. }
  384. return hr;
  385. }
  386. /********************************************************************/
  387. //
  388. // Function: HGLOBALTEST_120
  389. //
  390. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  391. // an IStream Interface on top of the HGlobal (set so
  392. // that the IStream will not delete the HGlobal on Release).
  393. // Next, the test writes and reads a specified number of data
  394. // bytes to the IStream interface, and then releases it.
  395. //
  396. // The test repeats the above sequence (always using the same
  397. // HGlobal) a random number of times. Finally, the HGlobal
  398. // is deleted and the test exits.
  399. //
  400. // Arguments: [dwSize] - Num of Bytes to Write to IStream
  401. // [dwNumIterations] - Num of IStream Interfaces to
  402. // be created on the same HGlobal
  403. //
  404. // Returns: HRESULT
  405. //
  406. // History: Heavily Modified T-Scottg 7/30/96
  407. // Created Venkatesan Viswanathan
  408. //
  409. // BUGNOTE: Conversion: HGLOBALTEST-120 NO - not supported in nss
  410. //
  411. /********************************************************************/
  412. HRESULT HGLOBALTEST_120 (ULONG ulSeed)
  413. {
  414. HRESULT hr = S_OK;
  415. HGLOBAL hGlobMem = NULL;
  416. OleHandle hOleGlobMem = NULL;
  417. OleHandle hOleTempMem = NULL;
  418. IStream * pIStream = NULL;
  419. ULONG uRet = 0;
  420. DWORD dwSize = 0;
  421. DWORD dwNumIterations = 0;
  422. ULARGE_INTEGER li;
  423. USHORT usErr = 0;
  424. DG_INTEGER dgi(ulSeed);
  425. // Not for 2phase. Bail.
  426. if (DoingDistrib ())
  427. {
  428. return S_OK;
  429. }
  430. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_120"));
  431. // Print Seed to Log
  432. usErr = dgi.GetSeed(&ulSeed);
  433. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  434. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_120 Seed: %d"), ulSeed));
  435. // Randomly calculate IStream length
  436. if (S_OK == hr)
  437. {
  438. if (0 != dgi.Generate( &dwSize,
  439. MIN_HGLOBAL_PACKETS,
  440. MAX_HGLOBAL_PACKETS))
  441. {
  442. hr = S_FALSE;
  443. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  444. }
  445. else
  446. {
  447. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  448. }
  449. }
  450. // Randomly calculate the number of IStream iterations on HGLOBAL
  451. if (S_OK == hr)
  452. {
  453. if (0 != dgi.Generate( &dwNumIterations,
  454. MIN_HGLOBAL_ITERATIONS,
  455. MAX_HGLOBAL_ITERATIONS ))
  456. {
  457. hr = S_FALSE;
  458. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  459. }
  460. }
  461. // Allocate HGLOBAL memory
  462. if (S_OK == hr)
  463. {
  464. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  465. GMEM_MOVEABLE,
  466. dwSize );
  467. if (NULL == hGlobMem)
  468. {
  469. hr = HRESULT_FROM_WIN32(GetLastError());
  470. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  471. }
  472. }
  473. // Repeat the specified number of times
  474. if (S_OK == hr)
  475. {
  476. for (DWORD dwIndex = 0; dwIndex < dwNumIterations; dwIndex++)
  477. {
  478. // Create IStream on HGLOBAL. (Note: HGLOBAL will not be
  479. // deleted when IStream is released)
  480. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  481. // only OleHandle, so first convert the handle
  482. if (S_OK == hr)
  483. {
  484. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  485. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  486. }
  487. if (S_OK == hr)
  488. {
  489. hr = CreateStreamOnHGlobal( hOleGlobMem,
  490. FALSE,
  491. &pIStream );
  492. DH_HRCHECK(hr, TEXT("CreateStreamOnHGlobal Failed"));
  493. }
  494. // Obtain HGlobal pointer from IStream
  495. if (S_OK == hr)
  496. {
  497. hr = GetHGlobalFromStream( pIStream,
  498. &hOleTempMem );
  499. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  500. }
  501. // Verify that the memory location that GetHGlobalFromStream
  502. // returned is the same as the memory location passed to
  503. // CreateStreamOnHGlobal.
  504. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  505. {
  506. hr = S_FALSE;
  507. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  508. }
  509. // Set the size of the IStream Interface
  510. if (S_OK == hr)
  511. {
  512. DH_ASSERT(NULL != pIStream);
  513. // Assign 1/2 of the IStream final size to Large Integer
  514. // Structure. (Note: this is so that the IStream will still
  515. // have to automatically increase its size during Write
  516. // operations in which its size is overflowed)
  517. ULISet32(li, (dwSize/2));
  518. hr = pIStream->SetSize(li);
  519. DH_HRCHECK(hr, TEXT("pIStream->SetSize Failed"));
  520. }
  521. // Call IStreamWriteTest
  522. if (S_OK == hr)
  523. {
  524. hr = IStreamWriteTest(pIStream, ulSeed, dwSize);
  525. DH_HRCHECK(hr, TEXT("IStreamWriteTest Failed"));
  526. }
  527. // Call the Test
  528. if (S_OK == hr)
  529. {
  530. hr = IStreamReadTest(pIStream, dwSize);
  531. DH_HRCHECK(hr, TEXT("IStreamReadTest Failed"));
  532. }
  533. // Release IStream
  534. if (NULL != pIStream)
  535. {
  536. uRet = pIStream->Release();
  537. DH_ASSERT(0 == uRet);
  538. pIStream = NULL;
  539. }
  540. // If error occurs, break out of loop
  541. if (S_OK != hr)
  542. {
  543. break;
  544. }
  545. }
  546. }
  547. // Free HGLOBAL From memory
  548. if (S_OK == hr)
  549. {
  550. DH_ASSERT(NULL != hGlobMem);
  551. if (NULL != GlobalFree(hGlobMem))
  552. {
  553. hr = HRESULT_FROM_WIN32(GetLastError());
  554. DH_HRCHECK(hr, TEXT("GlobalFree Failed"));
  555. }
  556. else
  557. {
  558. hGlobMem = NULL;
  559. }
  560. }
  561. // Write result to log
  562. if (S_OK == hr)
  563. {
  564. DH_LOG((LOG_PASS, TEXT("HGLOBALTEST_120 Succeeded")));
  565. }
  566. else
  567. {
  568. DH_LOG((LOG_FAIL, TEXT("HGLOBALTEST_120 Failed, hr = 0x%Lx"), hr));
  569. }
  570. return hr;
  571. }
  572. /********************************************************************/
  573. //
  574. // Function: HGLOBALTEST_130
  575. //
  576. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  577. // an IStream Interface on top of the HGlobal (set so
  578. // that the IStream will delete the HGlobal on Release).
  579. // Next, the test writes and reads a specified number of data
  580. // bytes to the IStream interface, and then releases it.
  581. //
  582. // The Test repeats the above sequence a random number of
  583. // times.
  584. //
  585. // Note: This test differs from HGLOBAL_120 in that the
  586. // HGLOBAL is freed by the IStream Interface when it is
  587. // released. It does not re-use the same HGLOBAL when
  588. // multiple IStreams are created.
  589. //
  590. // Arguments: [dwSize] - Num of Bytes to Write to IStream
  591. // [dwNumIterations] - Num of IStream Interfaces to
  592. // be created on the same HGlobal
  593. //
  594. // Returns: HRESULT
  595. //
  596. // History: Heavily Modified T-Scottg 7/30/96
  597. // Created Venkatesan Viswanathan
  598. //
  599. // BUGNOTE: Conversion: HGLOBALTEST-130 NO - not supported in nss
  600. //
  601. /********************************************************************/
  602. HRESULT HGLOBALTEST_130 (ULONG ulSeed)
  603. {
  604. HRESULT hr = S_OK;
  605. HGLOBAL hGlobMem = NULL;
  606. OleHandle hOleGlobMem = NULL;
  607. OleHandle hOleTempMem = NULL;
  608. IStream * pIStream = NULL;
  609. ULONG uRet = 0;
  610. DWORD dwSize = 0;
  611. DWORD dwNumIterations = 0;
  612. ULARGE_INTEGER li;
  613. USHORT usErr = 0;
  614. DG_INTEGER dgi(ulSeed);
  615. // Not for 2phase. Bail.
  616. if (DoingDistrib ())
  617. {
  618. return S_OK;
  619. }
  620. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_130"));
  621. // Print Seed to Log
  622. usErr = dgi.GetSeed(&ulSeed);
  623. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  624. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_130 Seed: %d"), ulSeed));
  625. // Randomly calculate ILockBytes length
  626. if (S_OK == hr)
  627. {
  628. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS, MAX_HGLOBAL_PACKETS))
  629. {
  630. hr = S_FALSE;
  631. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  632. }
  633. else
  634. {
  635. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  636. }
  637. }
  638. // Randomly calculate the number of IStream iterations on HGLOBAL
  639. if (S_OK == hr)
  640. {
  641. if (0 != dgi.Generate( &dwNumIterations,
  642. MIN_HGLOBAL_ITERATIONS,
  643. MAX_HGLOBAL_ITERATIONS ))
  644. {
  645. hr = S_FALSE;
  646. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  647. }
  648. }
  649. // Repeat the specified number of times
  650. if (S_OK == hr)
  651. {
  652. for (DWORD dwIndex = 0; dwIndex < dwNumIterations; dwIndex++)
  653. {
  654. // Allocate HGLOBAL memory
  655. if (S_OK == hr)
  656. {
  657. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  658. GMEM_MOVEABLE,
  659. dwSize );
  660. if (NULL == hGlobMem)
  661. {
  662. hr = HRESULT_FROM_WIN32(GetLastError());
  663. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  664. }
  665. }
  666. // Create IStream on HGLOBAL. (Note: HGLOBAL will be
  667. // deleted when IStream is released)
  668. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  669. // only OleHandle, so first convert the handle
  670. if (S_OK == hr)
  671. {
  672. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  673. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  674. }
  675. if (S_OK == hr)
  676. {
  677. hr = CreateStreamOnHGlobal( hOleGlobMem,
  678. TRUE,
  679. &pIStream );
  680. DH_HRCHECK(hr, TEXT("CreateStreamOnHGlobal Failed"));
  681. }
  682. // Obtain HGlobal pointer from IStream
  683. if (S_OK == hr)
  684. {
  685. hr = GetHGlobalFromStream( pIStream,
  686. &hOleTempMem );
  687. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  688. }
  689. // Verify that the memory location that GetHGlobalFromStream
  690. // returned is the same as the memory location passed to
  691. // CreateStreamOnHGlobal.
  692. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  693. {
  694. hr = S_FALSE;
  695. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  696. }
  697. // Set the size of the IStream Interface
  698. if (S_OK == hr)
  699. {
  700. DH_ASSERT(NULL != pIStream);
  701. // Assign 1/2 of the IStream final size to Large Integer
  702. // Structure. (Note: this is so that the IStream will still
  703. // have to automatically increase its size during Write
  704. // operations in which its size is overflowed)
  705. ULISet32(li, (dwSize/2));
  706. hr = pIStream->SetSize(li);
  707. DH_HRCHECK(hr, TEXT("pIStream->SetSize Failed"));
  708. }
  709. // Call IStreamWriteTest
  710. if (S_OK == hr)
  711. {
  712. hr = IStreamWriteTest(pIStream, ulSeed, dwSize);
  713. DH_HRCHECK(hr, TEXT("IStreamWriteTest Failed"));
  714. }
  715. // Call IStreamReadTest
  716. if (S_OK == hr)
  717. {
  718. hr = IStreamReadTest(pIStream, dwSize);
  719. DH_HRCHECK(hr, TEXT("IStreamReadTest Failed"));
  720. }
  721. // Release IStream. (Note: HGlobal will be deleted with
  722. // this call)
  723. if (NULL != pIStream)
  724. {
  725. uRet = pIStream->Release();
  726. DH_ASSERT(0 == uRet);
  727. pIStream = NULL;
  728. }
  729. // If error occurs, break out of loop
  730. if (S_OK != hr)
  731. {
  732. break;
  733. }
  734. }
  735. }
  736. // Write result to log
  737. if (S_OK == hr)
  738. {
  739. DH_LOG((LOG_PASS,
  740. TEXT("HGLOBALTEST_130 Succeeded")));
  741. }
  742. else
  743. {
  744. DH_LOG((LOG_FAIL,
  745. TEXT("HGLOBALTEST_130 Failed, hr = 0x%Lx"), hr));
  746. }
  747. return hr;
  748. }
  749. /********************************************************************/
  750. //
  751. // Function: HGLOBALTEST_140
  752. //
  753. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  754. // an IStream Interface on top of the HGlobal (set so
  755. // that the IStream will delete the HGlobal on Release).
  756. // Next, the test writes a specified number of data
  757. // bytes to the IStream interface, and then clones it --
  758. // verifying that the new IStream interface contains the
  759. // same data as the origional.
  760. //
  761. // Arguments: [dwSize] - Num of Bytes to Write to IStream
  762. //
  763. // Returns: HRESULT
  764. //
  765. // History: Created T-ScottG 7/30/96
  766. //
  767. // BUGNOTE: Conversion: HGLOBALTEST-140 NO - not supported in nss
  768. //
  769. /********************************************************************/
  770. HRESULT HGLOBALTEST_140 (ULONG ulSeed)
  771. {
  772. HRESULT hr = S_OK;
  773. HGLOBAL hGlobMem = NULL;
  774. OleHandle hOleGlobMem = NULL;
  775. OleHandle hOleTempMem = NULL;
  776. IStream * pIStream = NULL;
  777. IStream * pIClone = NULL;
  778. ULONG uRet = 0;
  779. DWORD dwSize = 0;
  780. ULARGE_INTEGER ulSize;
  781. LARGE_INTEGER liSeek;
  782. USHORT usErr = 0;
  783. DG_INTEGER dgi(ulSeed);
  784. // Not for 2phase. Bail.
  785. if (DoingDistrib ())
  786. {
  787. return S_OK;
  788. }
  789. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_140"));
  790. // Print Seed to Log
  791. usErr = dgi.GetSeed(&ulSeed);
  792. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  793. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_140 Seed: %d"), ulSeed));
  794. // Randomly calculate IStream length
  795. if (S_OK == hr)
  796. {
  797. if (0 != dgi.Generate( &dwSize,
  798. MIN_HGLOBAL_PACKETS,
  799. MAX_HGLOBAL_PACKETS ))
  800. {
  801. hr = S_FALSE;
  802. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  803. }
  804. else
  805. {
  806. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  807. }
  808. }
  809. // Allocate HGLOBAL memory
  810. if (S_OK == hr)
  811. {
  812. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  813. GMEM_MOVEABLE,
  814. dwSize );
  815. if (NULL == hGlobMem)
  816. {
  817. hr = HRESULT_FROM_WIN32(GetLastError());
  818. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  819. }
  820. }
  821. // Create IStream on HGLOBAL. (Note: HGLOBAL will be
  822. // deleted when IStream is released)
  823. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  824. // only OleHandle, so first convert the handle
  825. if (S_OK == hr)
  826. {
  827. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  828. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  829. }
  830. if (S_OK == hr)
  831. {
  832. hr = CreateStreamOnHGlobal( hOleGlobMem,
  833. TRUE,
  834. &pIStream );
  835. DH_HRCHECK(hr, TEXT("CreateStreamOnHGlobal Failed"));
  836. }
  837. // Obtain HGlobal pointer from IStream
  838. if (S_OK == hr)
  839. {
  840. hr = GetHGlobalFromStream( pIStream,
  841. &hOleTempMem );
  842. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  843. }
  844. // Verify that the memory location that GetHGlobalFromStream
  845. // returned is the same as the memory location passed to
  846. // CreateStreamOnHGlobal.
  847. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  848. {
  849. hr = S_FALSE;
  850. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  851. }
  852. // Set the size of the IStream Interface
  853. if (S_OK == hr)
  854. {
  855. DH_ASSERT(NULL != pIStream);
  856. // Assign 1/2 of the IStream final size to Large Integer
  857. // Structure. (Note: this is so that the IStream will still
  858. // have to automatically increase its size during Write
  859. // operations in which its size is overflowed)
  860. ULISet32(ulSize, (dwSize/2));
  861. hr = pIStream->SetSize(ulSize);
  862. DH_HRCHECK(hr, TEXT("pIStream->SetSize Failed"));
  863. }
  864. // Call IStreamWriteTest to fill Stream with data
  865. if (S_OK == hr)
  866. {
  867. hr = IStreamWriteTest(pIStream, ulSeed, dwSize);
  868. DH_HRCHECK(hr, TEXT("IStreamWriteTest Failed"));
  869. }
  870. // Set Seek pointer back to beginning of stream
  871. if (S_OK == hr)
  872. {
  873. ULISet32(liSeek, 0);
  874. hr = pIStream->Seek(liSeek, STREAM_SEEK_SET, NULL);
  875. DH_HRCHECK(hr, TEXT("IStream::Seek Failed"));
  876. }
  877. // Obtain clone of pIStream
  878. if (S_OK == hr)
  879. {
  880. hr = pIStream->Clone(&pIClone);
  881. DH_HRCHECK(hr, TEXT("IStream::Clone Failed"));
  882. }
  883. // Verify that the clone and the origional contain the same data
  884. if (S_OK == hr)
  885. {
  886. hr = IsEqualStream(pIStream, pIClone);
  887. DH_HRCHECK(hr, TEXT("IsEqualStream Failed"));
  888. }
  889. // Release IStream. (Note: HGlobal will be deleted with
  890. // this call)
  891. if (NULL != pIStream)
  892. {
  893. uRet = pIStream->Release();
  894. DH_ASSERT(0 == uRet);
  895. pIStream = NULL;
  896. }
  897. // Write result to log
  898. if (S_OK == hr)
  899. {
  900. DH_LOG((LOG_PASS,
  901. TEXT("HGLOBALTEST_140 Succeeded")));
  902. }
  903. else
  904. {
  905. DH_LOG((LOG_FAIL,
  906. TEXT("HGLOBALTEST_140 Failed, hr = 0x%Lx"), hr));
  907. }
  908. return hr;
  909. }
  910. /********************************************************************/
  911. //
  912. // Function: HGLOBALTEST_150
  913. //
  914. // Synopsis: Test which creates an HGLOBAL memory block, then creates
  915. // an IStream Interface on top of the HGlobal (set so
  916. // that the IStream will delete the HGlobal on Release).
  917. // Next, the test writes a specified number of data
  918. // bytes to the IStream interface, and then Copies it
  919. // to a new IStream (also created using an HGLOBAL),
  920. // and verified that the new IStream interface contains
  921. // the same data as the origional.
  922. //
  923. // Arguments: [dwSize] - Num of Bytes to Write to IStream
  924. //
  925. // Returns: HRESULT
  926. //
  927. // History: Created T-ScottG 7/30/96
  928. //
  929. // BUGNOTE: Conversion: HGLOBALTEST-150 NO - not supported in nss
  930. //
  931. /********************************************************************/
  932. HRESULT HGLOBALTEST_150 (ULONG ulSeed)
  933. {
  934. HRESULT hr = S_OK;
  935. HGLOBAL hGlobOrigionalMem = NULL;
  936. HGLOBAL hGlobCopyMem = NULL;
  937. OleHandle hOleGlobOrigionalMem= NULL;
  938. OleHandle hOleGlobCopyMem = NULL;
  939. OleHandle hOleTempMem = NULL;
  940. IStream * pIStream = NULL;
  941. IStream * pICopy = NULL;
  942. ULONG uRet = 0;
  943. DWORD dwSize = 0;
  944. ULARGE_INTEGER ulSize;
  945. LARGE_INTEGER liSeek;
  946. USHORT usErr = 0;
  947. DG_INTEGER dgi(ulSeed);
  948. // Not for 2phase. Bail.
  949. if (DoingDistrib ())
  950. {
  951. return S_OK;
  952. }
  953. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_150"));
  954. // Print Seed to Log
  955. usErr = dgi.GetSeed(&ulSeed);
  956. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  957. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_150 Seed: %d"), ulSeed));
  958. // Randomly calculate IStream length
  959. if (S_OK == hr)
  960. {
  961. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS, MAX_HGLOBAL_PACKETS))
  962. {
  963. hr = S_FALSE;
  964. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  965. }
  966. else
  967. {
  968. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  969. }
  970. }
  971. // Allocate HGLOBAL memory for Origional Stream
  972. if (S_OK == hr)
  973. {
  974. hGlobOrigionalMem = GlobalAlloc ( GMEM_NODISCARD |
  975. GMEM_MOVEABLE,
  976. dwSize );
  977. if (NULL == hGlobOrigionalMem)
  978. {
  979. hr = HRESULT_FROM_WIN32(GetLastError());
  980. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  981. }
  982. }
  983. // Allocate HGLOBAL memory for the Copy of the Origional Stream
  984. if (S_OK == hr)
  985. {
  986. hGlobCopyMem = GlobalAlloc ( GMEM_NODISCARD |
  987. GMEM_MOVEABLE,
  988. dwSize );
  989. if (NULL == hGlobCopyMem)
  990. {
  991. hr = HRESULT_FROM_WIN32(GetLastError());
  992. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  993. }
  994. }
  995. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  996. // only OleHandle, so first convert the handle
  997. if (S_OK == hr)
  998. {
  999. hr = ConvertHGLOBALToOleHandle(hGlobOrigionalMem, &hOleGlobOrigionalMem);
  1000. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  1001. }
  1002. // Create Origional IStream on HGLOBAL. (Note: HGLOBAL will be
  1003. // deleted when IStream is released)
  1004. if (S_OK == hr)
  1005. {
  1006. hr = CreateStreamOnHGlobal( hOleGlobOrigionalMem,
  1007. TRUE,
  1008. &pIStream );
  1009. DH_HRCHECK(hr, TEXT("CreateStreamOnHGlobal Failed"));
  1010. }
  1011. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  1012. // only OleHandle, so first convert the handle
  1013. if (S_OK == hr)
  1014. {
  1015. hr = ConvertHGLOBALToOleHandle(hGlobCopyMem, &hOleGlobCopyMem);
  1016. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  1017. }
  1018. // Create Copied IStream on HGLOBAL. (Note: HGLOBAL will be
  1019. // deleted when IStream is released)
  1020. if (S_OK == hr)
  1021. {
  1022. hr = CreateStreamOnHGlobal( hOleGlobCopyMem,
  1023. TRUE,
  1024. &pICopy );
  1025. DH_HRCHECK(hr, TEXT("CreateStreamOnHGlobal Failed"));
  1026. }
  1027. // Obtain HGlobal pointer from Origional IStream
  1028. if (S_OK == hr)
  1029. {
  1030. hr = GetHGlobalFromStream( pIStream,
  1031. &hOleTempMem );
  1032. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  1033. }
  1034. // Verify that the memory location that GetHGlobalFromStream
  1035. // returned is the same as the memory location passed to
  1036. // CreateStreamOnHGlobal.
  1037. if ((S_OK == hr) && (hOleTempMem != hOleGlobOrigionalMem))
  1038. {
  1039. hr = S_FALSE;
  1040. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  1041. }
  1042. // Obtain HGlobal pointer from Copied IStream
  1043. if (S_OK == hr)
  1044. {
  1045. hr = GetHGlobalFromStream( pICopy,
  1046. &hOleTempMem );
  1047. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  1048. }
  1049. // Verify that the memory location that GetHGlobalFromStream
  1050. // returned is the same as the memory location passed to
  1051. // CreateStreamOnHGlobal.
  1052. if ((S_OK == hr) && (hOleTempMem != hOleGlobCopyMem))
  1053. {
  1054. hr = S_FALSE;
  1055. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  1056. }
  1057. // Set the size of the Origional IStream Interface
  1058. if (S_OK == hr)
  1059. {
  1060. DH_ASSERT(NULL != pIStream);
  1061. // Assign 1/2 of the IStream final size to Large Integer
  1062. // Structure. (Note: this is so that the IStream will still
  1063. // have to automatically increase its size during Write
  1064. // operations in which its size is overflowed)
  1065. ULISet32(ulSize, (dwSize/2));
  1066. hr = pIStream->SetSize(ulSize);
  1067. DH_HRCHECK(hr, TEXT("pIStream->SetSize Failed"));
  1068. }
  1069. // Call IStreamWriteTest to fill Stream with data
  1070. if (S_OK == hr)
  1071. {
  1072. hr = IStreamWriteTest(pIStream, ulSeed, dwSize);
  1073. DH_HRCHECK(hr, TEXT("IStreamWriteTest Failed"));
  1074. }
  1075. // Set Seek pointer back to beginning of stream
  1076. if (S_OK == hr)
  1077. {
  1078. ULISet32(liSeek, 0);
  1079. hr = pIStream->Seek(liSeek, STREAM_SEEK_SET, NULL);
  1080. DH_HRCHECK(hr, TEXT("IStream::Seek Failed"));
  1081. }
  1082. // Copy Origional Stream to Copied Stream
  1083. if (S_OK == hr)
  1084. {
  1085. ULISet32(ulSize, dwSize);
  1086. hr = pIStream->CopyTo(pICopy, ulSize, NULL, NULL);
  1087. DH_HRCHECK(hr, TEXT("IStream::Clone Failed"));
  1088. }
  1089. // Verify that the clone and the origional contain the same data
  1090. if (S_OK == hr)
  1091. {
  1092. hr = IsEqualStream(pIStream, pICopy);
  1093. DH_HRCHECK(hr, TEXT("IsEqualStream Failed"));
  1094. }
  1095. // Release IStream. (Note: HGLOBAL will be deleted with
  1096. // this call)
  1097. if (NULL != pIStream)
  1098. {
  1099. uRet = pIStream->Release();
  1100. DH_ASSERT(0 == uRet);
  1101. pIStream = NULL;
  1102. }
  1103. // Release pICopy. (Note: HGLOBAL will be deleted with this call)
  1104. if (NULL != pICopy)
  1105. {
  1106. uRet = pICopy->Release();
  1107. DH_ASSERT(0 == uRet);
  1108. pICopy = NULL;
  1109. }
  1110. // Write result to log
  1111. if (S_OK == hr)
  1112. {
  1113. DH_LOG((LOG_PASS,
  1114. TEXT("HGLOBALTEST_150 Succeeded")));
  1115. }
  1116. else
  1117. {
  1118. DH_LOG((LOG_FAIL,
  1119. TEXT("HGLOBALTEST_150 Failed, hr = 0x%Lx"), hr));
  1120. }
  1121. return hr;
  1122. }
  1123. /********************************************************************/
  1124. //
  1125. // Function: HGLOBALTEST_101
  1126. //
  1127. // Synopsis: Test which tries illegit tests on API's - CreateILockBytesOn
  1128. // HGlobal and GetHGlobalFromILockBytes.
  1129. //
  1130. // Arguments: [ulSeed] - Randomizer Seed
  1131. //
  1132. // Returns: HRESULT
  1133. //
  1134. // History: Created Narindk 8/21/96
  1135. //
  1136. // Notes: OLE BUGS: 54009, 54024. Not in Automated run yet.
  1137. //
  1138. // BUGNOTE: Conversion: HGLOBALTEST-101 NO - not supported in nss
  1139. //
  1140. /********************************************************************/
  1141. HRESULT HGLOBALTEST_101 (ULONG ulSeed)
  1142. {
  1143. HRESULT hr = S_OK;
  1144. HGLOBAL hGlobMem = NULL;
  1145. OleHandle hOleGlobMem = NULL;
  1146. OleHandle hOleTempMem = NULL;
  1147. ILockBytes * pILockBytes = NULL;
  1148. ULONG uRet = 0;
  1149. DWORD dwSize = 0;
  1150. USHORT usErr = 0;
  1151. ULARGE_INTEGER li;
  1152. DG_INTEGER dgi(ulSeed);
  1153. // Not for 2phase. Bail.
  1154. if (DoingDistrib ())
  1155. {
  1156. return S_OK;
  1157. }
  1158. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_101"));
  1159. // Print Seed to Log
  1160. usErr = dgi.GetSeed(&ulSeed);
  1161. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  1162. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_101 Seed: %d"), ulSeed));
  1163. // Randomly calculate ILockBytes length
  1164. if (S_OK == hr)
  1165. {
  1166. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS,MAX_HGLOBAL_PACKETS))
  1167. {
  1168. hr = S_FALSE;
  1169. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  1170. }
  1171. else
  1172. {
  1173. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  1174. }
  1175. }
  1176. // Allocate HGLOBAL memory
  1177. if (S_OK == hr)
  1178. {
  1179. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  1180. GMEM_MOVEABLE,
  1181. dwSize );
  1182. if (NULL == hGlobMem)
  1183. {
  1184. hr = HRESULT_FROM_WIN32(GetLastError());
  1185. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  1186. }
  1187. }
  1188. // Mac porting: the next functions do not accept HGLOBAL,
  1189. // only OleHandle, so first convert the handle
  1190. if (S_OK == hr)
  1191. {
  1192. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  1193. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  1194. }
  1195. if (S_OK == hr)
  1196. {
  1197. // Create ILockBytes on HGLOBAL. (Note: HGLOBAL will be
  1198. // deleted when ILockBytes is released)
  1199. // Attempt illehgal out parameter for pILockBytes out param.
  1200. hr = CreateILockBytesOnHGlobal( hOleGlobMem,
  1201. TRUE,
  1202. NULL );
  1203. if(E_INVALIDARG == hr)
  1204. {
  1205. DH_TRACE((
  1206. DH_LVL_TRACE1,
  1207. TEXT("CreateILockBytesOnHGlobal failed as exp, hr=0x%lx"),
  1208. hr));
  1209. hr = S_OK;
  1210. }
  1211. else
  1212. {
  1213. DH_TRACE((
  1214. DH_LVL_TRACE1,
  1215. TEXT("CreateILockBytesOnHGlobal didn't fail as exp,hr=0x%lx"),
  1216. hr));
  1217. hr = E_FAIL;
  1218. }
  1219. }
  1220. // attempt valid operation
  1221. if (S_OK == hr)
  1222. {
  1223. // Create ILockBytes on HGLOBAL. (Note: HGLOBAL will be
  1224. // deleted when ILockBytes is released)
  1225. hr = CreateILockBytesOnHGlobal( hOleGlobMem,
  1226. TRUE,
  1227. &pILockBytes );
  1228. }
  1229. // Obtain HGlobal pointer from ILockBytes
  1230. if (S_OK == hr)
  1231. {
  1232. // Attempt illegal value for out Hglobal.
  1233. hr = GetHGlobalFromILockBytes( pILockBytes,
  1234. NULL );
  1235. if(E_INVALIDARG == hr)
  1236. {
  1237. DH_TRACE((
  1238. DH_LVL_TRACE1,
  1239. TEXT("GetHGlobalFromILockBytes failed as exp, hr=0x%lx"),
  1240. hr));
  1241. hr = S_OK;
  1242. }
  1243. else
  1244. {
  1245. DH_TRACE((
  1246. DH_LVL_TRACE1,
  1247. TEXT("GetHGlobalFromILockBytes didn't fail exp, hr=0x%lx"),
  1248. hr));
  1249. hr = E_FAIL;
  1250. }
  1251. }
  1252. // attempt valid operation
  1253. if (S_OK == hr)
  1254. {
  1255. hr = GetHGlobalFromILockBytes( pILockBytes,
  1256. &hOleTempMem );
  1257. DH_HRCHECK(hr, TEXT("GetHGlobalFromILockBytes Failed"));
  1258. }
  1259. // Verify that the memory location that GetHGlobalFromILockBytes
  1260. // returned is the same as the memory location passed to
  1261. // CreateILockBytesOnHGlobal.
  1262. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  1263. {
  1264. hr = S_FALSE;
  1265. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  1266. }
  1267. // Set the size of the ILockBytes Interface
  1268. if (S_OK == hr)
  1269. {
  1270. DH_ASSERT(NULL != pILockBytes);
  1271. // Assign 1/2 of the ILockBytes final size to Large Integer
  1272. // Structure. (Note: this is so that the ILockBytes will still
  1273. // have to automatically increase its size during WriteAt
  1274. // operations in which its size is overflowed)
  1275. ULISet32(li, (dwSize/2));
  1276. hr = pILockBytes->SetSize(li);
  1277. DH_HRCHECK(hr, TEXT("pILockBytes->SetSize Failed"));
  1278. }
  1279. // Release ILockBytes
  1280. if (NULL != pILockBytes)
  1281. {
  1282. uRet = pILockBytes->Release();
  1283. DH_ASSERT(0 == uRet);
  1284. pILockBytes = NULL;
  1285. }
  1286. // Write result to log
  1287. if (S_OK == hr)
  1288. {
  1289. DH_LOG((LOG_PASS, TEXT("HGLOBALTEST_101 Succeeded")));
  1290. }
  1291. else
  1292. {
  1293. DH_LOG((LOG_FAIL, TEXT("HGLOBALTEST_101 Failed, hr = 0x%Lx"), hr));
  1294. }
  1295. return hr;
  1296. }
  1297. /********************************************************************/
  1298. //
  1299. // Function: HGLOBALTEST_121
  1300. //
  1301. // Synopsis: Test which tries illegit tests on API's - CreateStreamOn
  1302. // HGlobal and GetHGlobalFromStream.
  1303. //
  1304. // Arguments: [ulSeed] - Randomizer Seed
  1305. //
  1306. // Returns: HRESULT
  1307. //
  1308. // History: Created Narindk 8/21/96
  1309. //
  1310. // Notes: OLE BUGS: 54053, 54051. Not in Automated run yet.
  1311. //
  1312. // BUGNOTE: Conversion: HGLOBALTEST-121 NO - not supported in nss
  1313. //
  1314. /********************************************************************/
  1315. HRESULT HGLOBALTEST_121 (ULONG ulSeed)
  1316. {
  1317. HRESULT hr = S_OK;
  1318. HGLOBAL hGlobMem = NULL;
  1319. OleHandle hOleGlobMem = NULL;
  1320. OleHandle hOleTempMem = NULL;
  1321. IStream * pIStream = NULL;
  1322. ULONG uRet = 0;
  1323. DWORD dwSize = 0;
  1324. USHORT usErr = 0;
  1325. ULARGE_INTEGER uliSize;
  1326. DG_INTEGER dgi(ulSeed);
  1327. // Not for 2phase. Bail.
  1328. if (DoingDistrib ())
  1329. {
  1330. return S_OK;
  1331. }
  1332. DH_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("HGLOBALTEST_121"));
  1333. // Print Seed to Log
  1334. usErr = dgi.GetSeed(&ulSeed);
  1335. DH_ASSERT(DG_RC_BAD_NUMBER_PTR != usErr);
  1336. DH_TRACE((DH_LVL_TRACE1, TEXT("HGLOBALTEST_121 Seed: %d"), ulSeed));
  1337. // Randomly calculate Stream length
  1338. if (S_OK == hr)
  1339. {
  1340. if (0 != dgi.Generate(&dwSize, MIN_HGLOBAL_PACKETS,MAX_HGLOBAL_PACKETS))
  1341. {
  1342. hr = S_FALSE;
  1343. DH_HRCHECK(hr, TEXT("dgi.Generate Failed"));
  1344. }
  1345. else
  1346. {
  1347. dwSize = dwSize * HGLOBAL_PACKET_SIZE;
  1348. }
  1349. }
  1350. // Allocate HGLOBAL memory
  1351. if (S_OK == hr)
  1352. {
  1353. hGlobMem = GlobalAlloc ( GMEM_NODISCARD |
  1354. GMEM_MOVEABLE,
  1355. dwSize );
  1356. if (NULL == hGlobMem)
  1357. {
  1358. hr = HRESULT_FROM_WIN32(GetLastError());
  1359. DH_HRCHECK(hr, TEXT("GlobalAlloc Failed"));
  1360. }
  1361. }
  1362. // Mac porting: CreateStreamOnHGlobal does not accept HGLOBAL,
  1363. // only OleHandle, so first convert the handle
  1364. if (S_OK == hr)
  1365. {
  1366. hr = ConvertHGLOBALToOleHandle(hGlobMem, &hOleGlobMem);
  1367. DH_HRCHECK(hr, TEXT("ConvertHGLOBALToOleHandle failed"));
  1368. }
  1369. if (S_OK == hr)
  1370. {
  1371. // Create Stream on HGLOBAL.
  1372. // Attempt illegal out parameter for pIStream out param.
  1373. hr = CreateStreamOnHGlobal( hOleGlobMem,
  1374. TRUE,
  1375. NULL );
  1376. if(E_INVALIDARG == hr)
  1377. {
  1378. DH_TRACE((
  1379. DH_LVL_TRACE1,
  1380. TEXT("CreateStreamOnHGlobal failed as exp, hr=0x%lx"),
  1381. hr));
  1382. hr = S_OK;
  1383. }
  1384. else
  1385. {
  1386. DH_TRACE((
  1387. DH_LVL_TRACE1,
  1388. TEXT("CreateStreamOnHGlobal didn't fail exp, hr=0x%lx"),
  1389. hr));
  1390. hr = E_FAIL;
  1391. }
  1392. }
  1393. // attempt valid operation
  1394. if (S_OK == hr)
  1395. {
  1396. // Create ILockBytes on HGLOBAL. (Note: HGLOBAL will be
  1397. // deleted when IStream is released)
  1398. hr = CreateStreamOnHGlobal( hOleGlobMem,
  1399. TRUE,
  1400. &pIStream );
  1401. }
  1402. // Obtain HGlobal pointer from IStream
  1403. if (S_OK == hr)
  1404. {
  1405. // Attempt illegal value for out Hglobal.
  1406. hr = GetHGlobalFromStream(pIStream, NULL );
  1407. if(E_INVALIDARG == hr)
  1408. {
  1409. DH_TRACE((
  1410. DH_LVL_TRACE1,
  1411. TEXT("GetHGlobalFromStream failed as exp, hr=0x%lx"),
  1412. hr));
  1413. hr = S_OK;
  1414. }
  1415. else
  1416. {
  1417. DH_TRACE((
  1418. DH_LVL_TRACE1,
  1419. TEXT("GetHGlobalFromStream didn't fail exp, hr=0x%lx"),
  1420. hr));
  1421. hr = E_FAIL;
  1422. }
  1423. }
  1424. // attempt valid operation
  1425. if (S_OK == hr)
  1426. {
  1427. hr = GetHGlobalFromStream( pIStream, &hOleTempMem );
  1428. DH_HRCHECK(hr, TEXT("GetHGlobalFromStream Failed"));
  1429. }
  1430. // Verify that the memory location that GetHGlobalFromILockBytes
  1431. // returned is the same as the memory location passed to
  1432. // CreateILockBytesOnHGlobal.
  1433. if ((S_OK == hr) && (hOleTempMem != hOleGlobMem))
  1434. {
  1435. hr = S_FALSE;
  1436. DH_HRCHECK(hr, TEXT("HGlobal addresses are not the same"));
  1437. }
  1438. // Set the size of the IStream Interface
  1439. if (S_OK == hr)
  1440. {
  1441. DH_ASSERT(NULL != pIStream);
  1442. // Assign 1/2 of the IStream final size to Large Integer
  1443. // Structure. (Note: this is so that the IStream will still
  1444. // have to automatically increase its size during Write
  1445. // operations in which its size is overflowed)
  1446. ULISet32(uliSize, (dwSize/2));
  1447. hr = pIStream->SetSize(uliSize);
  1448. DH_HRCHECK(hr, TEXT("pIStream->SetSize Failed"));
  1449. }
  1450. // Release Stream
  1451. if (NULL != pIStream)
  1452. {
  1453. uRet = pIStream->Release();
  1454. DH_ASSERT(0 == uRet);
  1455. pIStream = NULL;
  1456. }
  1457. // Write result to log
  1458. if (S_OK == hr)
  1459. {
  1460. DH_LOG((LOG_PASS, TEXT("HGLOBALTEST_121 Succeeded")));
  1461. }
  1462. else
  1463. {
  1464. DH_LOG((LOG_FAIL, TEXT("HGLOBALTEST_121 Failed, hr = 0x%Lx"), hr));
  1465. }
  1466. return hr;
  1467. }