4 * Copyright 2004 Kevin Koltzau
5 * Copyright 2004 Jacek Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/test.h"
32 #ifdef NONAMELESSUNION
38 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
39 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
41 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
42 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
43 static BOOL stopped_binding = FALSE;
45 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
48 IMoniker *mon1 = NULL;
49 IMoniker *mon2 = NULL;
51 hr = CreateURLMoniker(NULL, url1, &mon1);
52 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08lx\n", hr);
54 hr = CreateURLMoniker(mon1, url2, &mon2);
55 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08lx\n", hr);
57 if(mon1) IMoniker_Release(mon1);
58 if(mon2) IMoniker_Release(mon2);
61 static void test_create()
63 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
67 IBindStatusCallbackVtbl *lpVtbl;
73 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppvObject)
78 static ULONG WINAPI statusclb_AddRef(IBindStatusCallback *iface)
80 return InterlockedIncrement(&((statusclb*)iface)->ref);
83 static ULONG WINAPI statusclb_Release(IBindStatusCallback *iface)
85 statusclb *This = (statusclb*)iface;
87 ref = InterlockedDecrement(&This->ref);
89 HeapFree(GetProcessHeap(), 0, This);
93 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved, IBinding *pib)
95 statusclb *This = (statusclb*)iface;
98 ok(pib != NULL, "pib should not be NULL\n");
100 IBinding_AddRef(pib);
105 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
110 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
115 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallback *iface, ULONG ulProgress, ULONG ulProgressMax,
116 ULONG ulStatusCode, LPCWSTR szStatusText)
121 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
123 statusclb *This = (statusclb*)iface;
125 ok(SUCCEEDED(hresult), "Download failed: %08lx\n", hresult);
126 ok(szError == NULL, "szError should be NULL\n");
127 stopped_binding = TRUE;
128 IBinding_Release(This->pbind);
129 ok(This->pstr != NULL, "pstr should not be NULL here\n");
131 IStream_Release(This->pstr);
136 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
140 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
141 cbSize = pbindinfo->cbSize;
142 memset(pbindinfo, 0, cbSize);
143 pbindinfo->cbSize = cbSize;
148 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF, DWORD dwSize,
149 FORMATETC* pformatetc, STGMEDIUM* pstgmed)
151 statusclb *This = (statusclb*)iface;
156 ok(grfBSCF & BSCF_FIRSTDATANOTIFICATION, "pstr should be set when BSCF_FIRSTDATANOTIFICATION\n");
157 This->pstr = U(*pstgmed).pstm;
158 IStream_AddRef(This->pstr);
159 ok(This->pstr != NULL, "pstr should not be NULL here\n");
162 do hres = IStream_Read(This->pstr, buf, 512, &readed);
164 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08lx\n", hres);
169 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
174 static IBindStatusCallbackVtbl statusclbVtbl = {
175 statusclb_QueryInterface,
178 statusclb_OnStartBinding,
179 statusclb_GetPriority,
180 statusclb_OnLowResource,
181 statusclb_OnProgress,
182 statusclb_OnStopBinding,
183 statusclb_GetBindInfo,
184 statusclb_OnDataAvailable,
185 statusclb_OnObjectAvailable
188 static IBindStatusCallback* statusclb_create()
190 statusclb *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(statusclb));
191 ret->lpVtbl = &statusclbVtbl;
195 return (IBindStatusCallback*)ret;
198 static void test_CreateAsyncBindCtx()
200 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
204 IBindStatusCallback *bsc = statusclb_create();
206 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
207 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08lx\n", hres);
208 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
210 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
211 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08lx\n", hres);
213 hres = CreateAsyncBindCtx(0, bsc, NULL, &bctx);
214 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08lx\n", hres);
216 IBindStatusCallback_Release(bsc);
220 bindopts.cbStruct = 16;
221 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
222 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08lx\n", hres);
223 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
224 "bindopts.grfFlags = %08lx, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
225 ok(bindopts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
226 "bindopts.grfMode = %08lx, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n", bindopts.grfMode);
227 ok(bindopts.dwTickCountDeadline == 0,
228 "bindopts.dwTickCountDeadline = %08lx, expected: 0\n", bindopts.dwTickCountDeadline);
230 ref = IBindCtx_Release(bctx);
231 ok(ref == 0, "bctx should be destroyed here\n");
232 ref = IBindStatusCallback_Release(bsc);
233 ok(ref == 0, "bsc should be destroyed here\n");
236 static void test_BindToStorage()
240 LPOLESTR display_name;
243 IBindStatusCallback *previousclb, *sclb = statusclb_create();
244 IUnknown *unk = (IUnknown*)0x00ff00ff;
246 hres = CreateAsyncBindCtx(0, sclb, NULL, &bctx);
247 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08lx\n\n", hres);
249 IBindStatusCallback_Release(sclb);
253 hres = RegisterBindStatusCallback(bctx, sclb, &previousclb, 0);
254 ok(SUCCEEDED(hres), "RegisterBindStatusCallback failed: %08lx\n", hres);
255 ok(previousclb == sclb, "previousclb(%p) != sclb(%p)\n", previousclb, sclb);
257 IBindStatusCallback_Release(previousclb);
259 hres = CreateURLMoniker(NULL, WINE_ABOUT_URL, &mon);
260 ok(SUCCEEDED(hres), "failed to create moniker: %08lx\n", hres);
262 IBindStatusCallback_Release(sclb);
263 IBindCtx_Release(bctx);
267 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
268 ok(SUCCEEDED(hres), "GetDisplayName failed %08lx\n", hres);
269 ok(!lstrcmpW(display_name, WINE_ABOUT_URL), "GetDisplayName got wrong name\n");
271 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
272 ok(SUCCEEDED(hres), "IMoniker_BindToStorage failed: %08lx\n", hres);
274 ok(unk == NULL, "istr should be NULL\n");
277 IBindStatusCallback_Release(sclb);
278 IMoniker_Release(mon);
282 IUnknown_Release(unk);
284 while(!stopped_binding && GetMessage(&msg,NULL,0,0)) {
285 TranslateMessage(&msg);
286 DispatchMessage(&msg);
289 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
290 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
291 ok(IBindStatusCallback_Release(sclb) == 0, "scbl should be destroyed here\n");
297 test_CreateAsyncBindCtx();
298 test_BindToStorage();