2 * Copyright 2014 Andrew Eikum for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 DEFINE_GUID(CLSID_Package
, 0xf20da720, 0xc02f, 0x11ce, 0x92,0x7b, 0x08,0x00,0x09,0x5a,0xe3,0x40);
27 DEFINE_GUID(CLSID_Package_Alt
, 0x0003000C, 0x0000, 0x0000, 0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
29 static HRESULT WINAPI
ole10native_stream_QueryInterface(IStream
* This
, REFIID riid
,
32 ok(0, "queryinterface\n");
36 static ULONG WINAPI
ole10native_stream_AddRef(IStream
* This
)
41 static ULONG WINAPI
ole10native_stream_Release(IStream
* This
)
48 static HRESULT WINAPI
ole10native_stream_Read(IStream
* This
, void *pv
, ULONG cb
,
53 static BYTE data
[] = {
54 0xa5, 0x00, 0x00, 0x00, /* total size */
56 'l','a','b','e','l','.','t','x','t',0, /* label? */
57 'f','i','l','e','n','a','m','e','.','t','x','t',0, /* original filename? */
60 0x10, 0x00, 0x00, 0x00, /* ASCIIZ filename size */
61 'C',':','\\','f','i','l','e','n','a','m','e','2','.','t','x','t', /* ASCIIZ filename */
62 0x0a, 0x00, 0x00, 0x00, /* payload size */
63 's','o','m','e',' ','t','e','x','t','\n', /* payload */
64 0x10, 0x00, 0x00, 0x00, /* WCHAR filename size */
65 'C',0,':',0,'\\',0,'f',0,'i',0,'l',0,'e',0,'n',0,'a',0,'m',0,'e',0,'3',0,'.',0,'t',0,'x',0,'t',0, /* WCHAR filename */
66 0x0d, 0x00, 0x00, 0x00, /* another filename size */
67 'f',0,'i',0,'l',0,'e',0,'n',0,'a',0,'m',0,'e',0,'4',0,'.',0,'t',0,'x',0,'t',0, /* another filename */
68 0x10, 0x00, 0x00, 0x00, /* another filename size */
69 'C',0,':',0,'\\',0,'f',0,'i',0,'l',0,'e',0,'n',0,'a',0,'m',0,'e',0,'5',0,'.',0,'t',0,'x',0,'t',0, /* another filename */
72 to_read
= min(sizeof(data
) - offs
, cb
);
74 memcpy(pv
, data
+ offs
, to_read
);
80 return cb
== to_read
? S_OK
: S_FALSE
;
83 static HRESULT WINAPI
ole10native_stream_Write(IStream
* This
, const void *pv
,
84 ULONG cb
, ULONG
*pcbWritten
)
90 static HRESULT WINAPI
ole10native_stream_Seek(IStream
* This
, LARGE_INTEGER dlibMove
,
91 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
93 if(dwOrigin
== STREAM_SEEK_CUR
)
94 offs
+= dlibMove
.u
.LowPart
;
95 else if(dwOrigin
== STREAM_SEEK_SET
)
96 offs
= dlibMove
.u
.LowPart
;
99 plibNewPosition
->u
.HighPart
= 0;
100 plibNewPosition
->u
.LowPart
= offs
;
106 static HRESULT WINAPI
ole10native_stream_SetSize(IStream
* This
,
107 ULARGE_INTEGER libNewSize
)
113 static HRESULT WINAPI
ole10native_stream_CopyTo(IStream
* This
, IStream
*pstm
,
114 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
120 static HRESULT WINAPI
ole10native_stream_Commit(IStream
* This
, DWORD grfCommitFlags
)
126 static HRESULT WINAPI
ole10native_stream_Revert(IStream
* This
)
132 static HRESULT WINAPI
ole10native_stream_LockRegion(IStream
* This
,
133 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
135 ok(0, "lockregion\n");
139 static HRESULT WINAPI
ole10native_stream_UnlockRegion(IStream
* This
,
140 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
142 ok(0, "unlockregion\n");
146 static HRESULT WINAPI
ole10native_stream_Stat(IStream
* This
, STATSTG
*pstatstg
,
153 static HRESULT WINAPI
ole10native_stream_Clone(IStream
* This
, IStream
**ppstm
)
159 static IStreamVtbl ole10native_stream_vtbl
= {
160 ole10native_stream_QueryInterface
,
161 ole10native_stream_AddRef
,
162 ole10native_stream_Release
,
163 ole10native_stream_Read
,
164 ole10native_stream_Write
,
165 ole10native_stream_Seek
,
166 ole10native_stream_SetSize
,
167 ole10native_stream_CopyTo
,
168 ole10native_stream_Commit
,
169 ole10native_stream_Revert
,
170 ole10native_stream_LockRegion
,
171 ole10native_stream_UnlockRegion
,
172 ole10native_stream_Stat
,
173 ole10native_stream_Clone
176 static IStream ole10native_stream
= {
177 &ole10native_stream_vtbl
180 static HRESULT WINAPI
stg_QueryInterface(IStorage
* This
, REFIID riid
,
183 ok(0, "queryinterface: %s\n", wine_dbgstr_guid(riid
));
185 if(IsEqualIID(riid
, &IID_IUnknown
) ||
186 IsEqualIID(riid
, &IID_IStorage
)){
191 return E_NOINTERFACE
;
194 static ULONG WINAPI
stg_AddRef(IStorage
* This
)
199 static ULONG WINAPI
stg_Release(IStorage
* This
)
204 static HRESULT WINAPI
stg_CreateStream(IStorage
* This
, LPCOLESTR pwcsName
,
205 DWORD grfMode
, DWORD reserved1
, DWORD reserved2
, IStream
**ppstm
)
210 static HRESULT WINAPI
stg_OpenStream(IStorage
* This
, LPCOLESTR pwcsName
,
211 void *reserved1
, DWORD grfMode
, DWORD reserved2
, IStream
**ppstm
)
213 static const WCHAR ole10NativeW
[] = {1,'O','l','e','1','0','N','a','t','i','v','e',0};
215 if(lstrcmpW(pwcsName
, ole10NativeW
))
216 return STG_E_FILENOTFOUND
;
218 *ppstm
= &ole10native_stream
;
223 static HRESULT WINAPI
stg_CreateStorage(IStorage
* This
, LPCOLESTR pwcsName
,
224 DWORD grfMode
, DWORD dwStgFmt
, DWORD reserved2
, IStorage
**ppstg
)
226 ok(0, "createstorage\n");
230 static HRESULT WINAPI
stg_OpenStorage(IStorage
* This
, LPCOLESTR pwcsName
,
231 IStorage
*pstgPriority
, DWORD grfMode
, SNB snbExclude
, DWORD reserved
,
234 ok(0, "openstorage: %s\n", wine_dbgstr_w(pwcsName
));
238 static HRESULT WINAPI
stg_CopyTo(IStorage
* This
, DWORD ciidExclude
,
239 const IID
*rgiidExclude
, SNB snbExclude
, IStorage
*pstgDest
)
245 static HRESULT WINAPI
stg_MoveElementTo(IStorage
* This
, LPCOLESTR pwcsName
,
246 IStorage
*pstgDest
, LPCOLESTR pwcsNewName
, DWORD grfFlags
)
252 static HRESULT WINAPI
stg_Commit(IStorage
* This
, DWORD grfCommitFlags
)
258 static HRESULT WINAPI
stg_Revert(IStorage
* This
)
264 static HRESULT WINAPI
stg_EnumElements(IStorage
* This
, DWORD reserved1
,
265 void *reserved2
, DWORD reserved3
, IEnumSTATSTG
**ppenum
)
271 static HRESULT WINAPI
stg_DestroyElement(IStorage
* This
, LPCOLESTR pwcsName
)
273 ok(0, "destroyelem\n");
277 static HRESULT WINAPI
stg_RenameElement(IStorage
* This
, LPCOLESTR pwcsOldName
,
278 LPCOLESTR pwcsNewName
)
280 ok(0, "renamelem\n");
284 static HRESULT WINAPI
stg_SetElementTimes(IStorage
* This
, LPCOLESTR pwcsName
,
285 const FILETIME
*pctime
, const FILETIME
*patime
, const FILETIME
*pmtime
)
291 static HRESULT WINAPI
stg_SetClass(IStorage
* This
, REFCLSID clsid
)
297 static HRESULT WINAPI
stg_SetStateBits(IStorage
* This
, DWORD grfStateBits
,
304 static HRESULT WINAPI
stg_Stat(IStorage
* This
, STATSTG
*pstatstg
, DWORD grfStatFlag
)
306 memset(pstatstg
, 0, sizeof(*pstatstg
));
307 pstatstg
->clsid
= CLSID_Package
;
308 pstatstg
->type
= STGTY_STORAGE
;
312 static IStorageVtbl stg_vtbl
= {
333 static IStorage stg
= {
337 static HRESULT WINAPI
clientsite_QueryInterface(IOleClientSite
* This
,
338 REFIID riid
, void **ppvObject
)
340 ok(0, "query interface\n");
341 return E_NOINTERFACE
;
344 static ULONG WINAPI
clientsite_AddRef(IOleClientSite
* This
)
349 static ULONG WINAPI
clientsite_Release(IOleClientSite
* This
)
354 static HRESULT WINAPI
clientsite_SaveObject(IOleClientSite
* This
)
356 ok(0, "saveobject\n");
360 static HRESULT WINAPI
clientsite_GetMoniker(IOleClientSite
* This
,
361 DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
**ppmk
)
363 ok(0, "getmoniker\n");
367 static HRESULT WINAPI
clientsite_GetContainer(IOleClientSite
* This
,
368 IOleContainer
**ppContainer
)
370 ok(0, "getcontainer\n");
374 static HRESULT WINAPI
clientsite_ShowObject(IOleClientSite
* This
)
376 ok(0, "showobject\n");
380 static HRESULT WINAPI
clientsite_OnShowWindow(IOleClientSite
* This
,
383 ok(0, "onshowwindow\n");
387 static HRESULT WINAPI
clientsite_RequestNewObjectLayout(IOleClientSite
* This
)
389 ok(0, "requestnewobjectlayout\n");
393 static IOleClientSiteVtbl clientsite_vtbl
= {
394 clientsite_QueryInterface
,
397 clientsite_SaveObject
,
398 clientsite_GetMoniker
,
399 clientsite_GetContainer
,
400 clientsite_ShowObject
,
401 clientsite_OnShowWindow
,
402 clientsite_RequestNewObjectLayout
405 static IOleClientSite clientsite
= {
409 static void test_packager(void)
412 IPersistStorage
*persist
;
413 DWORD len
, bytes_read
, status
;
416 WCHAR filename
[MAX_PATH
];
418 BOOL br
, extended
= FALSE
;
420 static const WCHAR filename3W
[] = {'f','i','l','e','n','a','m','e','3','.','t','x','t',0};
422 hr
= CoCreateInstance(&CLSID_Package
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
423 &IID_IOleObject
, (void**)&oleobj
);
425 hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance(CLSID_Package) failed: %08x\n", hr
);
427 IOleObject_Release(oleobj
);
428 /* older OSes store temporary files in obscure locations, so don't run
429 * the full tests on them */
432 win_skip("Older OS doesn't support modern packager\n");
434 hr
= CoCreateInstance(&CLSID_Package_Alt
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
435 &IID_IOleObject
, (void**)&oleobj
);
436 ok(hr
== S_OK
, "CoCreateInstance(CLSID_Package_Alt) failed: %08x\n", hr
);
438 hr
= IOleObject_SetClientSite(oleobj
, NULL
);
439 ok(hr
== S_OK
, "SetClientSite failed: %08x\n", hr
);
441 hr
= IOleObject_SetClientSite(oleobj
, &clientsite
);
442 ok(hr
== S_OK
, "SetClientSite failed: %08x\n", hr
);
444 hr
= IOleObject_GetMiscStatus(oleobj
, DVASPECT_CONTENT
, NULL
);
445 ok(hr
== E_INVALIDARG
, "GetMiscStatus failed: %08x\n", hr
);
447 hr
= IOleObject_GetMiscStatus(oleobj
, DVASPECT_CONTENT
, &status
);
448 ok(hr
== S_OK
, "GetMiscStatus failed: %08x\n", hr
);
449 ok(status
== OLEMISC_ONLYICONIC
||
450 status
== OLEMISC_CANTLINKINSIDE
/* winxp */,
451 "Got wrong DVASPECT_CONTENT status: 0x%x\n", status
);
453 hr
= IOleObject_QueryInterface(oleobj
, &IID_IPersistStorage
, (void**)&persist
);
454 ok(hr
== S_OK
, "QueryInterface(IPersistStorage) failed: %08x\n", hr
);
456 hr
= IPersistStorage_Load(persist
, &stg
);
457 ok(hr
== S_OK
, "Load failed: %08x\n", hr
);
460 len
= GetTempPathW(sizeof(filename
) / sizeof(*filename
), filename
);
461 lstrcpyW(filename
+ len
, filename3W
);
463 file
= CreateFileW(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
464 FILE_ATTRIBUTE_NORMAL
, NULL
);
465 ok(file
!= INVALID_HANDLE_VALUE
, "Couldn't find temporary file %s: %u\n",
466 wine_dbgstr_w(filename
), GetLastError());
468 br
= ReadFile(file
, contents
, sizeof(contents
), &bytes_read
, NULL
);
469 ok(br
== TRUE
, "ReadFile failed\n");
470 ok(bytes_read
== 10, "Got wrong file size: %u\n", bytes_read
);
471 ok(!memcmp(contents
, "some text\n", 10), "Got wrong file contents\n");
476 hr
= IOleObject_Close(oleobj
, OLECLOSE_NOSAVE
);
477 ok(hr
== S_OK
, "Close failed: %08x\n", hr
);
480 file
= CreateFileW(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
481 FILE_ATTRIBUTE_NORMAL
, NULL
);
482 ok(file
!= INVALID_HANDLE_VALUE
, "Temporary file shouldn't be deleted\n");
486 IPersistStorage_Release(persist
);
487 IOleObject_Release(oleobj
);
490 file
= CreateFileW(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
491 FILE_ATTRIBUTE_NORMAL
, NULL
);
492 ok(file
== INVALID_HANDLE_VALUE
, "Temporary file should be deleted\n");