urlmon: Implemented IUriBuilder_RemoveProperties.
[wine] / dlls / ole32 / tests / defaulthandler.c
1 /*
2  * Default Handler Tests
3  *
4  * Copyright 2008 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22 #define CONST_VTABLE
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29
30 #include "wine/test.h"
31
32
33 static HRESULT create_storage(IStorage **stg)
34 {
35     HRESULT hr;
36     ILockBytes *lock_bytes;
37
38     hr = CreateILockBytesOnHGlobal(NULL, TRUE, &lock_bytes);
39     if(SUCCEEDED(hr))
40     {
41         hr = StgCreateDocfileOnILockBytes(lock_bytes,
42                   STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, stg);
43         ILockBytes_Release(lock_bytes);
44     }
45     return hr;
46 }
47
48 typedef struct
49 {
50     DWORD version;
51     DWORD flags;
52     DWORD link_update_opt;
53     DWORD res;
54     DWORD moniker_size;
55 } ole_stream_header_t;
56
57 static void test_olestream(void)
58 {
59     HRESULT hr;
60     const CLSID non_existent_class = {0xa5f1772f, 0x3772, 0x490f, {0x9e, 0xc6, 0x77, 0x13, 0xe8, 0xb3, 0x4b, 0x5d}};
61     IOleObject *ole_obj;
62     IPersistStorage *persist;
63     IStorage *stg;
64     IStream *stm;
65     static const WCHAR olestream[] = {1,'O','l','e',0};
66     ULONG read;
67     ole_stream_header_t header;
68
69     hr = create_storage(&stg);
70     ok(hr == S_OK, "got %08x\n", hr);
71
72     hr = IStorage_OpenStream(stg, olestream, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stm);
73     ok(hr == STG_E_FILENOTFOUND, "got %08x\n", hr);
74
75     hr = OleCreateDefaultHandler(&non_existent_class, 0, &IID_IOleObject, (void**)&ole_obj);
76     ok(hr == S_OK, "got %08x\n", hr);
77
78     hr = IOleObject_QueryInterface(ole_obj, &IID_IPersistStorage, (void**)&persist);
79     ok(hr == S_OK, "got %08x\n", hr);
80
81     hr = IPersistStorage_InitNew(persist, stg);
82     ok(hr == S_OK, "got %08x\n", hr);
83
84     hr = IStorage_OpenStream(stg, olestream, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stm);
85     ok(hr == S_OK, "got %08x\n", hr);
86     hr = IStream_Read(stm, &header, sizeof(header), &read);
87     ok(hr == S_OK, "got %08x\n", hr);
88     ok(read == sizeof(header), "read %d\n", read);
89     ok(header.version == 0x02000001, "got version %08x\n", header.version);
90     ok(header.flags == 0x0, "got flags %08x\n", header.flags);
91     ok(header.link_update_opt == 0x0, "got link update option %08x\n", header.link_update_opt);
92     ok(header.res == 0x0, "got reserved %08x\n", header.res);
93     ok(header.moniker_size == 0x0, "got moniker size %08x\n", header.moniker_size);
94
95     IStream_Release(stm);
96
97     IPersistStorage_Release(persist);
98     IOleObject_Release(ole_obj);
99
100     IStorage_Release(stg);
101 }
102
103 START_TEST(defaulthandler)
104 {
105     OleInitialize(NULL);
106
107     test_olestream();
108
109     OleUninitialize();
110 }