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.

1058 lines
30 KiB

  1. //+=================================================================
  2. //
  3. // File: PropTest.hxx
  4. //
  5. // Description: This file provides macros and constants
  6. // for the Property Test DRT.
  7. //
  8. //+=================================================================
  9. #ifndef _PROPTEST_HXX_
  10. #define _PROPTEST_HXX_
  11. #include "propapi.h"
  12. //+----------------------------------------------------------------------------
  13. //
  14. // M a c r o s
  15. //
  16. //+----------------------------------------------------------------------------
  17. // ------------------------------------------------------------
  18. // PropTest_* macros to abstract OLE2ANSI and _UNICODE handling
  19. // ------------------------------------------------------------
  20. #ifdef _MAC
  21. # define PROPTEST_FILE_HANDLE FILE*
  22. # define PropTest_CreateFile(name) fopen(name, "w+")
  23. # define PropTest_WriteFile(hFile,buf,cbBuf,pcbWritten) \
  24. *pcbWritten = fwrite(buf,1,cbBuf,hFile)
  25. # define PropTest_CloseHandle(handle) fclose(handle)
  26. #else
  27. # define PROPTEST_FILE_HANDLE HANDLE
  28. # define PropTest_CreateDirectory CreateDirectoryA
  29. # define PropTest_CreateFile(name) CreateFileA( name, \
  30. GENERIC_READ|GENERIC_WRITE, \
  31. 0, NULL, CREATE_ALWAYS, \
  32. FILE_ATTRIBUTE_NORMAL, \
  33. NULL )
  34. # define PropTest_WriteFile(hFile,buf,cbBuf,pcbWritten) \
  35. WriteFile(hFile, buf, cbBuf, pcbWritten, NULL)
  36. # define PropTest_CloseHandle(handle) CloseHandle(handle)
  37. #endif
  38. #ifndef ELEMENTS
  39. #define ELEMENTS(x) (sizeof(x)/sizeof(x[0]))
  40. #endif
  41. // CodePage macros:
  42. // We'll set the "good" codepage to 4e5, which is available on
  43. // NT and installable on Win95. But on the Mac, only 4e4 is
  44. // available, so this is what we'll use.
  45. #define CODEPAGE_DEFAULT 0x04e4 // US English
  46. #define CODEPAGE_BAD 0x9999 // Non-existent code page
  47. #ifdef _MAC
  48. #define CODEPAGE_GOOD 0x04e4
  49. #else
  50. #define CODEPAGE_GOOD 0x04e5
  51. #endif
  52. // Defines used by test_CodePage
  53. #define CODEPAGE_TEST_NAMED_PROPERTY OLESTR("Named Property")
  54. #define CODEPAGE_TEST_UNNAMED_BSTR_PROPID 3
  55. #define CODEPAGE_TEST_UNNAMED_I4_PROPID 4
  56. #define CODEPAGE_TEST_VBSTR_PROPID 7
  57. #define CODEPAGE_TEST_VPROPVAR_BSTR_PROPID 9
  58. // --------
  59. // Typedefs
  60. // --------
  61. typedef enum tagOSENUM
  62. {
  63. osenumUnknown, osenumWin95, osenumDCOM95,
  64. osenumNT3, osenumNT4, osenumMac
  65. } OSENUM;
  66. typedef struct tagSYSTEMINFO
  67. {
  68. OSENUM osenum;
  69. BOOL fIPropMarshaling;
  70. } SYSTEMINFO;
  71. //-----------------------------------------------------------------------------
  72. //
  73. // P r o t o t y p e s
  74. //
  75. //-----------------------------------------------------------------------------
  76. HRESULT OpenDir(
  77. WCHAR *path,
  78. BOOL fCreate,
  79. IStorage **ppistg);
  80. HRESULT OpenFile(
  81. WCHAR *path,
  82. BOOL fCreate,
  83. IStorage **ppistg);
  84. HRESULT OpenJP(
  85. WCHAR *path,
  86. BOOL fCreate,
  87. IStorage **ppistg);
  88. HRESULT OpenSC(
  89. WCHAR *path,
  90. BOOL fCreate,
  91. IStorage **ppistg);
  92. HRESULT OpenStg(
  93. WCHAR *path,
  94. BOOL fCreate,
  95. IStorage **ppistg);
  96. FILETIME operator - ( const FILETIME &ft1, const FILETIME &ft2 );
  97. FILETIME operator -= ( FILETIME &ft1, const FILETIME &ft2 );
  98. void DeleteBagExProperties( IPropertyBagEx *pbag, const OLECHAR *poszPrefix );
  99. void CheckTime(const FILETIME &ftStart, const FILETIME &ftPropSet);
  100. void CheckStat( IPropertyStorage *pPropSet, REFFMTID fmtid,
  101. REFCLSID clsid, ULONG PropSetFlag,
  102. const FILETIME & ftStart, DWORD dwOSVersion );
  103. BOOL IsEqualSTATPROPSTG(const STATPROPSTG *p1, const STATPROPSTG *p2);
  104. void CreateCodePageTestFile( LPOLESTR poszFileName, IStorage **ppStg );
  105. void SeekToProperty( IStream *pStm, PROPID propidSearch );
  106. void ModifyPropSetCodePage( IStorage *pStg, const FMTID &fmtid, USHORT usCodePage );
  107. void ModifyPropertyType( IStorage *pStg, const FMTID &fmtid, PROPID propid, VARTYPE vt );
  108. void ModifyOSVersion( IStorage* pStg, DWORD dwOSVersion );
  109. void _Check(HRESULT hrExpected, HRESULT hrActual, LPCSTR szFile, int line);
  110. OLECHAR * GetNextTest();
  111. VOID CleanStat(ULONG celt, STATPROPSTG *psps);
  112. HRESULT PopulateRGPropVar( CPropVariant rgcpropvar[],
  113. CPropSpec rgcpropspec[],
  114. const OLECHAR *rgoszpropnameAll[],
  115. IStorage *pstg );
  116. BOOLEAN PROPSYSAPI PROPAPI
  117. PropTestCompareVariants(
  118. USHORT CodePage,
  119. PROPVARIANT const *pvar1,
  120. PROPVARIANT const *pvar2);
  121. HRESULT ResetRGPropVar( CPropVariant rgcpropvar[] );
  122. void CheckFormatVersion( IPropertyStorage *ppropstg, WORD wExpected );
  123. void CheckLockCount( IUnknown *punk, LONG lExpected );
  124. NTSTATUS GetProcessInfo( PSYSTEM_PROCESS_INFORMATION pspi );
  125. VOID DumpOleStorage( IStorage *pstg, IPropertySetStorage *pIPropStg ,LPOLESTR aocpath );
  126. VOID Status( char *szMessage );
  127. VOID CalcSafeArrayIndices( LONG iLinear, LONG rgIndices[], const SAFEARRAYBOUND rgsaBounds[], ULONG cDims );
  128. ULONG CalcSafeArrayElementCount( const SAFEARRAY *psa );
  129. VOID CompareSafeArrays( SAFEARRAY *psa1, SAFEARRAY *psa2 );
  130. void test_PropsetOnEmptyFile( OLECHAR *poszDir );
  131. void test_ReadOnlyReservedProperties( IStorage *pStg );
  132. void test_PropsetOnHGlobal();
  133. void test_SettingLocalization( IStorage *pstg );
  134. void test_PidIllegal( IStorage *pstg );
  135. void test_StgOnHandle( OLECHAR *poszDir );
  136. void test_IPropertyBag( IStorage *pstg );
  137. void test_BagVtUnknown( IStorage *pstg );
  138. void test_StgOpenOnHandle( LPOLESTR ocsDir );
  139. void test_PropertyLengthAsVariant( );
  140. void test_SafeArray( IStorage *pstg );
  141. void test_ByRef( IStorage *pstg );
  142. void test_ExtendedTypes( IStorage *pstg );
  143. void test_LowMemory( IStorage *pstg );
  144. void test_BagInterfaceTypes( IStorage *pstg );
  145. void test_MultipleReader( LPOLESTR ocsDir );
  146. void test_Robustness(OLECHAR *poszDir);
  147. void test_EmptyBag( OLECHAR *poszDir );
  148. void test_VersionOneNames( IStorage *pstg );
  149. void test_BagOpenMethod( IStorage *pstg );
  150. void test_WriteReadAllProperties( LPOLESTR ocsDir ); // **
  151. void test_BagDelete( IStorage *pstg );
  152. void test_BagEnum( IStorage *pstg );
  153. void test_BagCoercion( IStorage *pstg );
  154. void test_StandaloneAPIs( LPOLESTR ocsDir );
  155. void test_IPropertySetStorage_IUnknown(IStorage *pStorage);
  156. void test_PropVariantValidation( IStorage *pStg );
  157. void test_ParameterValidation(IStorage *pStg);
  158. void test_IPropertySetStorage_CreateOpenDelete(IStorage *pStorage);
  159. void test_IPropertySetStorage_SummaryInformation(IStorage *pStorage);
  160. void test_IPropertySetStorage_FailIfThere(IStorage *pStorage);
  161. void test_IPropertySetStorage_BadThis(IStorage *pIgnored);
  162. void test_IPropertySetStorage_TransactedMode(IStorage *pStorage);
  163. void test_IPropertySetStorage_TransactedMode2(IStorage *pStorage);
  164. void test_IPropertySetStorage_SubPropertySet(IStorage *pStorage);
  165. void test_IPropertySetStorage_CommitAtRoot(IStorage *pStorage);
  166. void test_IPropertySetStorage(IStorage *pStorage);
  167. void test_IEnumSTATPROPSETSTG(IStorage *pStorage);
  168. void test_IPropertyStorage_Access(IStorage *pStorage);
  169. void test_IPropertyStorage_Create(IStorage *pStorage);
  170. void test_IPropertyStorage_Stat(IStorage *pStorage);
  171. void test_IPropertyStorage_ReadMultiple_Normal(IStorage *pStorage);
  172. void test_UnsupportedProperties( IStorage *pStg );
  173. void test_IPropertyStorage_ReadMultiple_Cleanup(IStorage *pStorage);
  174. void test_IPropertyStorage_ReadMultiple_Inconsistent(IStorage *pStorage);
  175. void test_IPropertyStorage_ReadMultiple(IStorage *pStorage);
  176. void test_IPropertyStorage_WriteMultiple_Overwrite1(IStorage *pStgBase);
  177. void test_IPropertyStorage_WriteMultiple_Overwrite2(IStorage *pStorage);
  178. void test_IPropertyStorage_WriteMultiple_Overwrite3(IStorage *pStorage);
  179. void test_IPropertyStorage_Commit(IStorage *pStorage);
  180. void test_IPropertyStorage_WriteMultiple(IStorage *pStorage);
  181. void test_IPropertyStorage_DeleteMultiple(IStorage *pStorage);
  182. void test_IPropertyStorage(IStorage *pStorage);
  183. void test_Word6(IStorage *pStorage, CHAR *szTemporaryDirectory); // **
  184. void test_SimpleLeaks( LPOLESTR poszDir ); // **
  185. void test_IEnumSTATPROPSTG(IStorage *pstgTemp); // **
  186. void test_MaxPropertyName(IStorage *pstgTemp); // **
  187. void test_CodePages( LPOLESTR poszDirectory ); // **
  188. void test_PropertyInterfaces(IStorage *pstgTemp); // **
  189. void test_CopyTo(IStorage *pstgSource, // Source of the CopyTo
  190. IStorage *pstgDestination, // Destination of the CopyTo
  191. ULONG ulBaseStgTransaction, // Transaction bit for the base storage.
  192. ULONG ulPropSetTransaction, // Transaction bit for the property sets.
  193. LPOLESTR oszBaseStorageName );
  194. void test_OLESpecTickerExample( IStorage* pstg );
  195. void test_Office( LPOLESTR wszTestFile ); // **
  196. void test_Office2(IStorage *pStorage);
  197. void test_PropVariantCopy( );
  198. void test_SimpleDocFile(LPOLESTR ocsDir);
  199. void test_ex_api(LPOLESTR ocsDir);
  200. void test_Performance( IStorage *pStg );
  201. void test_CoFileTimeNow();
  202. void test_PROPSETFLAG_UNBUFFERED( IStorage *pStg );
  203. void test_PropStgNameConversion( IStorage *pStg );
  204. void test_PropStgNameConversion2();
  205. void test_LargePropertySet( IStorage *pstg );
  206. extern OLECHAR g_aocMap[];
  207. extern BOOL g_fVerbose;
  208. extern BOOL g_fRegisterLocalServer;
  209. extern CPropVariant g_rgcpropvarAll[];
  210. extern CPropSpec g_rgcpropspecAll[];
  211. extern const OLECHAR *g_rgoszpropnameAll[];
  212. extern char g_szPropHeader[];
  213. extern char g_szEmpty[];
  214. extern LARGE_INTEGER g_li0;
  215. extern IStorage *_pstgTemp;
  216. extern IStorage *_pstgTempCopyTo;
  217. extern SYSTEMINFO g_SystemInfo;
  218. extern BOOL g_stgmDumpFlags;
  219. #ifdef _MAC
  220. extern CDisplay *g_pcDisplay;
  221. #endif
  222. //+----------------------------------------------------------------------------
  223. //
  224. // M a c r o s
  225. //
  226. //+----------------------------------------------------------------------------
  227. #define Check(x,y) _Check((HRESULT)(x),(HRESULT) (y), __FILE__, __LINE__)
  228. // PropTest_towcs: Either copies or converts zero-terminated LPOLESTR
  229. // to an LPWSTR.
  230. #ifndef OLE2ANSI
  231. //#define PropTest_mbstoocs(ocsDest,szSource) mbstowcs(ocsDest, szSource, strlen(szSource)+1)
  232. inline void
  233. PropTest_mbstoocs( OLECHAR *poszDest, ULONG cbDest, CHAR *pszSource )
  234. {
  235. Check( TRUE, 0 != MultiByteToWideChar( GetACP(), 0, pszSource, -1, poszDest, cbDest ));
  236. }
  237. #else
  238. #define PropTest_mbstoocs(ocsDest,szSource) strcpy( ocsDest, szSource)
  239. #endif
  240. #define CCH_MAP (1 << CBIT_CHARMASK) // 32
  241. #define CHARMASK (CCH_MAP - 1) // 0x1f
  242. #define CALPHACHARS ('z' - 'a' + 1)
  243. #define CPROPERTIES 5
  244. // The following macros are used for printf. Both printf
  245. // and oprintf macros are given (oprintf is assumes that
  246. // strings are OLECHARs). And for each, there is a normal
  247. // version, and an "ASYNC" version. The ASYNC version tells the
  248. // receiver that the string need not be displayed immediately
  249. // (this improves performance on the Mac).
  250. //
  251. // On the Mac, we pass the string to the CDisplay object.
  252. // On NT, we simple call the corresponding CRT routine.
  253. #ifdef _MAC
  254. # define PRINTF g_pcDisplay->printf
  255. # define OPRINTF g_pcDisplay->printf
  256. # define ASYNC_PRINTF g_pcDisplay->async_printf
  257. # define ASYNC_OPRINTF g_pcDisplay->async_printf
  258. #else
  259. # define PRINTF printf
  260. # define ASYNC_PRINTF printf
  261. # define OPRINTF oprintf
  262. # define ASYNC_OPRINTF oprintf
  263. #endif
  264. // -------
  265. // Globals
  266. // -------
  267. extern const OLECHAR oszSummaryInformation[];
  268. extern ULONG cboszSummaryInformation;
  269. extern const OLECHAR oszDocSummaryInformation[];
  270. extern ULONG cboszDocSummaryInformation;
  271. extern const OLECHAR oszGlobalInfo[];
  272. extern ULONG cboszGlobalInfo;
  273. extern const OLECHAR oszImageContents[];
  274. extern ULONG cboszImageContents;
  275. extern const OLECHAR oszImageInfo[];
  276. extern ULONG cboszImageInfo;
  277. extern int g_nIndent;
  278. extern const GUID fmtidGlobalInfo;
  279. extern const FMTID fmtidImageContents;
  280. extern const FMTID fmtidImageInfo;
  281. // ---------
  282. // Constants
  283. // ---------
  284. #define NUM_WELL_KNOWN_PROPSETS 6
  285. // Property Id's for Summary Info, as defined in OLE 2 Prog. Ref.
  286. #define PID_TITLE 0x00000002L
  287. #define PID_SUBJECT 0x00000003L
  288. #define PID_AUTHOR 0x00000004L
  289. #define PID_KEYWORDS 0x00000005L
  290. #define PID_COMMENTS 0x00000006L
  291. #define PID_TEMPLATE 0x00000007L
  292. #define PID_LASTAUTHOR 0x00000008L
  293. #define PID_REVNUMBER 0x00000009L
  294. #define PID_EDITTIME 0x0000000aL
  295. #define PID_LASTPRINTED 0x0000000bL
  296. #define PID_CREATE_DTM 0x0000000cL
  297. #define PID_LASTSAVE_DTM 0x0000000dL
  298. #define PID_PAGECOUNT 0x0000000eL
  299. #define PID_WORDCOUNT 0x0000000fL
  300. #define PID_CHARCOUNT 0x00000010L
  301. #define PID_THUMBNAIL 0x00000011L
  302. #define PID_APPNAME 0x00000012L
  303. #define PID_DOC_SECURITY 0x00000013L
  304. // Property Id's for Document Summary Info, as define in OLE Property Exchange spec.
  305. #define PID_CATEGORY 0x00000002L
  306. #define PID_PRESFORMAT 0x00000003L
  307. #define PID_BYTECOUNT 0x00000004L
  308. #define PID_LINECOUNT 0x00000005L
  309. #define PID_PARACOUNT 0x00000006L
  310. #define PID_SLIDECOUNT 0x00000007L
  311. #define PID_NOTECOUNT 0x00000008L
  312. #define PID_HIDDENCOUNT 0x00000009L
  313. #define PID_MMCLIPCOUNT 0x0000000aL
  314. #define PID_SCALE 0x0000000bL
  315. #define PID_HEADINGPAIR 0x0000000cL
  316. #define PID_DOCPARTS 0x0000000dL
  317. #define PID_MANAGER 0x0000000eL
  318. #define PID_COMPANY 0x0000000fL
  319. #define PID_LINKSDIRTY 0x00000010L
  320. #define CPROPERTIES_ALL 38//36
  321. #define CPROPERTIES_ALL_SIMPLE 33
  322. #define TEST_STANDARD 0x02
  323. #define TEST_WORD6 0x04
  324. #define TEST_MARSHALING 0x08
  325. #define TEST_COFILETIMENOW 0x10
  326. #define TEST_PERFORMANCE 0x20
  327. #define TEST_SIMPLE_LEAKS 0x40
  328. //=======================================================
  329. //
  330. // TSafeStorage
  331. //
  332. // This template creates a "safe pointer" to an IStorage,
  333. // IStream, IPropertySetStorage, or IPropertyStorage.
  334. // One constructor receives an IStorage*, which is used
  335. // when creating a pointer to an IPropertySetStorage.
  336. //
  337. // For example:
  338. //
  339. // TSafeStorage<IStorage> pstg;
  340. // StgCreateDocFile( L"Foo", STGM_ ..., 0L, &pstg );
  341. // TSafeStorage<IPropertySetStorage> psetstg( pstg );
  342. // pstg->Release();
  343. // pstg = NULL;
  344. // pssetstg->Open ...
  345. //
  346. //=======================================================
  347. template<class STGTYPE> class TSafeStorage
  348. {
  349. public:
  350. TSafeStorage()
  351. {
  352. _pstg = NULL;
  353. }
  354. // Special case: Receive an IStorage and query for
  355. // an IPropertySetStorage.
  356. TSafeStorage(IStorage *pstg)
  357. {
  358. Check( S_OK, StgToPropSetStg( pstg, (IPropertySetStorage**) &_pstg ));
  359. }
  360. ~TSafeStorage()
  361. {
  362. if (_pstg != NULL)
  363. {
  364. _pstg->Release();
  365. }
  366. }
  367. STGTYPE * operator -> ()
  368. {
  369. Check(TRUE, _pstg != NULL);
  370. return(_pstg);
  371. }
  372. STGTYPE** operator & ()
  373. {
  374. return(&_pstg);
  375. }
  376. STGTYPE* operator=( STGTYPE *pstg )
  377. {
  378. _pstg = pstg;
  379. return _pstg;
  380. }
  381. operator STGTYPE *()
  382. {
  383. return _pstg;
  384. }
  385. private:
  386. STGTYPE *_pstg;
  387. };
  388. //+----------------------------------------------------------------------------
  389. //
  390. // IStream Wrapper
  391. // (Makes a stream read-only)
  392. //
  393. //+----------------------------------------------------------------------------
  394. class CReadOnlyStream : public IStream
  395. {
  396. public:
  397. HRESULT STDMETHODCALLTYPE QueryInterface(
  398. /* [in] */ REFIID riid,
  399. /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  400. {
  401. if( IID_IStream != riid )
  402. {
  403. *ppvObject = NULL;
  404. return( E_NOINTERFACE );
  405. }
  406. _pstm->AddRef();
  407. *ppvObject = this;
  408. return( S_OK );
  409. }
  410. ULONG STDMETHODCALLTYPE AddRef( void)
  411. {
  412. return( _pstm->AddRef() );
  413. }
  414. ULONG STDMETHODCALLTYPE Release( void)
  415. {
  416. return( _pstm->Release() );
  417. }
  418. public:
  419. /* [local] */ HRESULT STDMETHODCALLTYPE Read(
  420. /* [length_is][size_is][out] */ void __RPC_FAR *pv,
  421. /* [in] */ ULONG cb,
  422. /* [out] */ ULONG __RPC_FAR *pcbRead)
  423. {
  424. return( _pstm->Read( pv, cb, pcbRead ));
  425. }
  426. /* [local] */ HRESULT STDMETHODCALLTYPE Write(
  427. /* [size_is][in] */ const void __RPC_FAR *pv,
  428. /* [in] */ ULONG cb,
  429. /* [out] */ ULONG __RPC_FAR *pcbWritten)
  430. {
  431. return( STG_E_ACCESSDENIED );
  432. }
  433. /* [local] */ HRESULT STDMETHODCALLTYPE Seek(
  434. /* [in] */ LARGE_INTEGER dlibMove,
  435. /* [in] */ DWORD dwOrigin,
  436. /* [out] */ ULARGE_INTEGER __RPC_FAR *plibNewPosition)
  437. {
  438. return( _pstm->Seek( dlibMove, dwOrigin, plibNewPosition ));
  439. }
  440. HRESULT STDMETHODCALLTYPE SetSize(
  441. /* [in] */ ULARGE_INTEGER libNewSize)
  442. {
  443. return( STG_E_ACCESSDENIED );
  444. }
  445. /* [local] */ HRESULT STDMETHODCALLTYPE CopyTo(
  446. /* [unique][in] */ IStream __RPC_FAR *pstm,
  447. /* [in] */ ULARGE_INTEGER cb,
  448. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbRead,
  449. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbWritten)
  450. {
  451. return( _pstm->CopyTo( pstm, cb, pcbRead, pcbWritten ));
  452. }
  453. HRESULT STDMETHODCALLTYPE Commit(
  454. /* [in] */ DWORD grfCommitFlags)
  455. {
  456. return( STG_E_ACCESSDENIED );
  457. }
  458. HRESULT STDMETHODCALLTYPE Revert( void)
  459. {
  460. return( STG_E_ACCESSDENIED );
  461. }
  462. HRESULT STDMETHODCALLTYPE LockRegion(
  463. /* [in] */ ULARGE_INTEGER libOffset,
  464. /* [in] */ ULARGE_INTEGER cb,
  465. /* [in] */ DWORD dwLockType)
  466. {
  467. return( _pstm->LockRegion( libOffset, cb, dwLockType ));
  468. }
  469. HRESULT STDMETHODCALLTYPE UnlockRegion(
  470. /* [in] */ ULARGE_INTEGER libOffset,
  471. /* [in] */ ULARGE_INTEGER cb,
  472. /* [in] */ DWORD dwLockType)
  473. {
  474. return( _pstm->UnlockRegion( libOffset, cb, dwLockType ));
  475. }
  476. HRESULT STDMETHODCALLTYPE Stat(
  477. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  478. /* [in] */ DWORD grfStatFlag)
  479. {
  480. HRESULT hr = _pstm->Stat( pstatstg, grfStatFlag );
  481. if( SUCCEEDED(hr) )
  482. pstatstg->grfMode &= STGM_RDWR_MASK;
  483. return( hr );
  484. }
  485. HRESULT STDMETHODCALLTYPE Clone(
  486. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm)
  487. {
  488. return( _pstm->Clone( ppstm ));
  489. }
  490. public:
  491. CReadOnlyStream( IStream *pstm )
  492. {
  493. _pstm = pstm;
  494. }
  495. private:
  496. IStream *_pstm;
  497. };
  498. //+----------------------------------------------------------------------------
  499. //
  500. // CFlatStorage
  501. //
  502. //+----------------------------------------------------------------------------
  503. class CFlatStorage : public IStorage, public IPropertySetStorage
  504. {
  505. private:
  506. ULONG _cRefs;
  507. WCHAR _wszPath[ MAX_PATH + 1 ];
  508. IPropertySetStorage *_pPropSetStg;
  509. IStorage *_pStg;
  510. HANDLE _hFile;
  511. public:
  512. CFlatStorage()
  513. {
  514. _cRefs = 1;
  515. _pPropSetStg = NULL;
  516. _pStg = NULL;
  517. _hFile = INVALID_HANDLE_VALUE;
  518. }
  519. public:
  520. HRESULT Create( const WCHAR *pwszFile );
  521. HRESULT Open( const WCHAR *pwszFile );
  522. HRESULT STDMETHODCALLTYPE QueryInterface(
  523. /* [in] */ REFIID riid,
  524. /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
  525. ULONG STDMETHODCALLTYPE AddRef( void );
  526. ULONG STDMETHODCALLTYPE Release( void);
  527. HRESULT STDMETHODCALLTYPE Create(
  528. /* [in] */ REFFMTID rfmtid,
  529. /* [unique][in] */ const CLSID *pclsid,
  530. /* [in] */ DWORD grfFlags,
  531. /* [in] */ DWORD grfMode,
  532. /* [out] */ IPropertyStorage **ppprstg)
  533. {
  534. return _pPropSetStg->Create( rfmtid, pclsid, grfFlags, grfMode, ppprstg );
  535. }
  536. HRESULT STDMETHODCALLTYPE Open(
  537. /* [in] */ REFFMTID rfmtid,
  538. /* [in] */ DWORD grfMode,
  539. /* [out] */ IPropertyStorage **ppprstg)
  540. {
  541. return( _pPropSetStg->Open( rfmtid, grfMode, ppprstg ));
  542. }
  543. HRESULT STDMETHODCALLTYPE Delete(
  544. /* [in] */ REFFMTID rfmtid)
  545. {
  546. return( _pPropSetStg->Delete( rfmtid ));
  547. }
  548. HRESULT STDMETHODCALLTYPE Enum(
  549. /* [out] */ IEnumSTATPROPSETSTG **ppenum)
  550. {
  551. return _pPropSetStg->Enum( ppenum );
  552. }
  553. HRESULT STDMETHODCALLTYPE CreateStream(
  554. /* [string][in] */ const OLECHAR *pwcsName,
  555. /* [in] */ DWORD grfMode,
  556. /* [in] */ DWORD reserved1,
  557. /* [in] */ DWORD reserved2,
  558. /* [out] */ IStream **ppstm)
  559. {
  560. return _pStg->CreateStream( pwcsName, grfMode, reserved1, reserved2, ppstm );
  561. }
  562. /* [local] */ HRESULT STDMETHODCALLTYPE OpenStream(
  563. /* [string][in] */ const OLECHAR *pwcsName,
  564. /* [unique][in] */ void *reserved1,
  565. /* [in] */ DWORD grfMode,
  566. /* [in] */ DWORD reserved2,
  567. /* [out] */ IStream **ppstm)
  568. {
  569. return _pStg->OpenStream( pwcsName, reserved1, grfMode, reserved2, ppstm );
  570. }
  571. HRESULT STDMETHODCALLTYPE CreateStorage(
  572. /* [string][in] */ const OLECHAR *pwcsName,
  573. /* [in] */ DWORD grfMode,
  574. /* [in] */ DWORD reserved1,
  575. /* [in] */ DWORD reserved2,
  576. /* [out] */ IStorage **ppstg)
  577. {
  578. return _pStg->CreateStorage( pwcsName, grfMode, reserved1, reserved2, ppstg );
  579. }
  580. HRESULT STDMETHODCALLTYPE OpenStorage(
  581. /* [string][unique][in] */ const OLECHAR *pwcsName,
  582. /* [unique][in] */ IStorage *pstgPriority,
  583. /* [in] */ DWORD grfMode,
  584. /* [unique][in] */ SNB snbExclude,
  585. /* [in] */ DWORD reserved,
  586. /* [out] */ IStorage **ppstg)
  587. {
  588. return _pStg->OpenStorage( pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstg );
  589. }
  590. HRESULT STDMETHODCALLTYPE CopyTo(
  591. /* [in] */ DWORD ciidExclude,
  592. /* [size_is][unique][in] */ const IID *rgiidExclude,
  593. /* [unique][in] */ SNB snbExclude,
  594. /* [unique][in] */ IStorage *pstgDest)
  595. {
  596. return _pStg->CopyTo( ciidExclude, rgiidExclude, snbExclude, pstgDest );
  597. }
  598. HRESULT STDMETHODCALLTYPE MoveElementTo(
  599. /* [string][in] */ const OLECHAR *pwcsName,
  600. /* [unique][in] */ IStorage *pstgDest,
  601. /* [string][in] */ const OLECHAR *pwcsNewName,
  602. /* [in] */ DWORD grfFlags)
  603. {
  604. return _pStg->MoveElementTo( pwcsName, pstgDest, pwcsNewName, grfFlags );
  605. }
  606. HRESULT STDMETHODCALLTYPE Commit(
  607. /* [in] */ DWORD grfCommitFlags)
  608. {
  609. return _pStg->Commit( grfCommitFlags );
  610. }
  611. HRESULT STDMETHODCALLTYPE Revert( void)
  612. {
  613. return _pStg->Revert();
  614. }
  615. /* [local] */ HRESULT STDMETHODCALLTYPE EnumElements(
  616. /* [in] */ DWORD reserved1,
  617. /* [size_is][unique][in] */ void *reserved2,
  618. /* [in] */ DWORD reserved3,
  619. /* [out] */ IEnumSTATSTG **ppenum)
  620. {
  621. return _pStg->EnumElements( reserved1, reserved2, reserved3, ppenum );
  622. }
  623. HRESULT STDMETHODCALLTYPE DestroyElement(
  624. /* [string][in] */ const OLECHAR *pwcsName)
  625. {
  626. return _pStg->DestroyElement( pwcsName );
  627. }
  628. HRESULT STDMETHODCALLTYPE RenameElement(
  629. /* [string][in] */ const OLECHAR *pwcsOldName,
  630. /* [string][in] */ const OLECHAR *pwcsNewName)
  631. {
  632. return _pStg->RenameElement( pwcsOldName, pwcsNewName );
  633. }
  634. HRESULT STDMETHODCALLTYPE SetElementTimes(
  635. /* [string][unique][in] */ const OLECHAR *pwcsName,
  636. /* [unique][in] */ const FILETIME *pctime,
  637. /* [unique][in] */ const FILETIME *patime,
  638. /* [unique][in] */ const FILETIME *pmtime)
  639. {
  640. return _pStg->SetElementTimes( pwcsName, pctime, patime, pmtime );
  641. }
  642. HRESULT STDMETHODCALLTYPE SetClass(
  643. /* [in] */ REFCLSID clsid)
  644. {
  645. return _pStg->SetClass( clsid );
  646. }
  647. HRESULT STDMETHODCALLTYPE SetStateBits(
  648. /* [in] */ DWORD grfStateBits,
  649. /* [in] */ DWORD grfMask)
  650. {
  651. return _pStg->SetStateBits( grfStateBits, grfMask );
  652. }
  653. HRESULT STDMETHODCALLTYPE Stat(
  654. /* [out] */ STATSTG *pstatstg,
  655. /* [in] */ DWORD grfStatFlag)
  656. {
  657. return _pStg->Stat( pstatstg, grfStatFlag );
  658. }
  659. };
  660. //+----------------------------------------------------------------------------
  661. //
  662. // I n l i n e s
  663. //
  664. //+----------------------------------------------------------------------------
  665. __inline OLECHAR
  666. MapChar(IN ULONG i)
  667. {
  668. return((OLECHAR) g_aocMap[i & CHARMASK]);
  669. }
  670. inline BOOL operator == ( const FILETIME &ft1, const FILETIME &ft2 )
  671. {
  672. return( ft1.dwHighDateTime == ft2.dwHighDateTime
  673. &&
  674. ft1.dwLowDateTime == ft2.dwLowDateTime );
  675. }
  676. inline BOOL operator != ( const FILETIME &ft1, const FILETIME &ft2 )
  677. {
  678. return( ft1.dwHighDateTime != ft2.dwHighDateTime
  679. ||
  680. ft1.dwLowDateTime != ft2.dwLowDateTime );
  681. }
  682. inline BOOL operator > ( const FILETIME &ft1, const FILETIME &ft2 )
  683. {
  684. return( ft1.dwHighDateTime > ft2.dwHighDateTime
  685. ||
  686. ft1.dwHighDateTime == ft2.dwHighDateTime
  687. &&
  688. ft1.dwLowDateTime > ft2.dwLowDateTime );
  689. }
  690. inline BOOL operator < ( const FILETIME &ft1, const FILETIME &ft2 )
  691. {
  692. return( ft1.dwHighDateTime < ft2.dwHighDateTime
  693. ||
  694. ft1.dwHighDateTime == ft2.dwHighDateTime
  695. &&
  696. ft1.dwLowDateTime < ft2.dwLowDateTime );
  697. }
  698. inline BOOL operator >= ( const FILETIME &ft1, const FILETIME &ft2 )
  699. {
  700. return( ft1 > ft2
  701. ||
  702. ft1 == ft2 );
  703. }
  704. inline BOOL operator <= ( const FILETIME &ft1, const FILETIME &ft2 )
  705. {
  706. return( ft1 < ft2
  707. ||
  708. ft1 == ft2 );
  709. }
  710. //+----------------------------------------------------------------------------
  711. //
  712. // C l a s s e s
  713. //
  714. //+----------------------------------------------------------------------------
  715. enum CreateOpen
  716. {
  717. coCreate, coOpen
  718. };
  719. class CTempStorage
  720. {
  721. public:
  722. CTempStorage(DWORD grfMode = STGM_DIRECT | STGM_CREATE)
  723. {
  724. Check(S_OK, (_pstgTemp->CreateStorage(GetNextTest(), grfMode |
  725. STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0,
  726. &_pstg)));
  727. }
  728. CTempStorage(CreateOpen co, IStorage *pstgParent, OLECHAR *pocsChild, DWORD grfMode = STGM_DIRECT)
  729. {
  730. if (co == coCreate)
  731. Check(S_OK, pstgParent->CreateStorage(pocsChild,
  732. grfMode | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0,
  733. &_pstg));
  734. else
  735. Check(S_OK, pstgParent->OpenStorage(pocsChild, NULL,
  736. grfMode | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0,
  737. &_pstg));
  738. }
  739. ~CTempStorage()
  740. {
  741. if (_pstg != NULL)
  742. _pstg->Release();
  743. }
  744. IStorage * operator -> ()
  745. {
  746. return(_pstg);
  747. }
  748. operator IStorage * ()
  749. {
  750. return(_pstg);
  751. }
  752. void Release()
  753. {
  754. if (_pstg != NULL)
  755. {
  756. _pstg->Release();
  757. _pstg = NULL;
  758. }
  759. }
  760. private:
  761. static unsigned int _iName;
  762. IStorage * _pstg;
  763. };
  764. class CGenProps
  765. {
  766. public:
  767. CGenProps() : _vt((VARENUM)2) {}
  768. PROPVARIANT * GetNext(int HowMany, int *pActual, BOOL fWrapOk = FALSE, BOOL fNoNonSimple = TRUE);
  769. private:
  770. BOOL _GetNext(PROPVARIANT *pVar, BOOL fWrapOk, BOOL fNoNonSimple);
  771. VARENUM _vt;
  772. };
  773. class CObjectWithPersistStorage : public IPersistStorage
  774. {
  775. private:
  776. BOOL _fDirty:1;
  777. LONG _cRefs;
  778. OLECHAR *_poszData;
  779. static CLSID _clsid;
  780. public:
  781. CObjectWithPersistStorage( const OLECHAR *posz );
  782. CObjectWithPersistStorage();
  783. ~CObjectWithPersistStorage();
  784. public:
  785. BOOL operator==( const CObjectWithPersistStorage & Other );
  786. CLSID GetClassID() { return _clsid; }
  787. public:
  788. HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, void** ppvObject );
  789. ULONG STDMETHODCALLTYPE AddRef();
  790. ULONG STDMETHODCALLTYPE Release();
  791. public:
  792. HRESULT STDMETHODCALLTYPE GetClassID(
  793. /* [out] */ CLSID __RPC_FAR *pClassID);
  794. HRESULT STDMETHODCALLTYPE IsDirty( void);
  795. HRESULT STDMETHODCALLTYPE InitNew(
  796. /* [unique][in] */ IStorage __RPC_FAR *pStg);
  797. HRESULT STDMETHODCALLTYPE Load(
  798. /* [unique][in] */ IStorage __RPC_FAR *pStg);
  799. HRESULT STDMETHODCALLTYPE Save(
  800. /* [unique][in] */ IStorage __RPC_FAR *pStgSave,
  801. /* [in] */ BOOL fSameAsLoad);
  802. HRESULT STDMETHODCALLTYPE SaveCompleted(
  803. /* [unique][in] */ IStorage __RPC_FAR *pStgNew);
  804. HRESULT STDMETHODCALLTYPE HandsOffStorage( void);
  805. }; // class CObjectWithPersistStorage
  806. class CObjectWithPersistStream : public IPersistStream
  807. {
  808. private:
  809. BOOL _fDirty:1;
  810. LONG _cRefs;
  811. OLECHAR *_poszData;
  812. static CLSID _clsid;
  813. public:
  814. CObjectWithPersistStream( const OLECHAR *posz );
  815. CObjectWithPersistStream();
  816. ~CObjectWithPersistStream();
  817. public:
  818. BOOL operator==( const CObjectWithPersistStream & Other );
  819. CLSID GetClassID() { return _clsid; }
  820. public:
  821. HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, void** ppvObject );
  822. ULONG STDMETHODCALLTYPE AddRef();
  823. ULONG STDMETHODCALLTYPE Release();
  824. public:
  825. HRESULT STDMETHODCALLTYPE GetClassID(
  826. /* [out] */ CLSID __RPC_FAR *pClassID);
  827. HRESULT STDMETHODCALLTYPE IsDirty( void);
  828. HRESULT STDMETHODCALLTYPE Load(
  829. /* [unique][in] */ IStream __RPC_FAR *pStm);
  830. HRESULT STDMETHODCALLTYPE Save(
  831. /* [unique][in] */ IStream __RPC_FAR *pStm,
  832. /* [in] */ BOOL fClearDirty);
  833. HRESULT STDMETHODCALLTYPE GetSizeMax(
  834. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbSize);
  835. }; // class CObjectWithPersistStream
  836. class PropTestMemoryAllocator : public PMemoryAllocator
  837. {
  838. void *Allocate(ULONG cbSize)
  839. {
  840. return( CoTaskMemAlloc( cbSize ));
  841. }
  842. void Free(void *pv)
  843. {
  844. CoTaskMemFree( pv );
  845. }
  846. };
  847. #include "instant.hxx" // Instantiation support
  848. #endif // !_PROPTEST_HXX_