4 * Copyright 2004 Robert Shearman
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/test.h"
33 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", hr)
35 static void test_MkParseDisplayName()
37 IBindCtx
* pbc
= NULL
;
39 IMoniker
* pmk
= NULL
;
40 IMoniker
* pmk1
= NULL
;
41 IMoniker
* pmk2
= NULL
;
42 IMoniker
* ppmk
= NULL
;
46 IUnknown
* object
= NULL
;
50 IEnumMoniker
*spEM1
= NULL
;
51 IEnumMoniker
*spEM2
= NULL
;
52 IEnumMoniker
*spEM3
= NULL
;
57 IRunningObjectTable
* pprot
=NULL
;
59 /* CLSID of My Computer */
60 static const WCHAR wszDisplayName
[] = {'c','l','s','i','d',':',
61 '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
62 static const WCHAR wszFileName1
[] = {'c',':','\\','w','i','n','d','o','w','s','\\','t','e','s','t','1','.','d','o','c',0};
63 static const WCHAR wszFileName2
[] = {'c',':','\\','w','i','n','d','o','w','s','\\','t','e','s','t','2','.','d','o','c',0};
66 hr
= CreateBindCtx(0, &pbc
);
67 ok_ole_success(hr
, CreateBindCtx
);
69 hr
= MkParseDisplayName(pbc
, wszDisplayName
, &eaten
, &pmk
);
70 todo_wine
{ ok_ole_success(hr
, MkParseDisplayName
); }
74 hr
= IMoniker_BindToObject(pmk
, pbc
, NULL
, &IID_IUnknown
, (LPVOID
*)&object
);
75 ok_ole_success(hr
, IMoniker_BindToObject
);
77 IUnknown_Release(object
);
79 IBindCtx_Release(pbc
);
81 /* Test the EnumMoniker interface */
82 hr
= CreateBindCtx(0, &pbc
);
83 ok_ole_success(hr
, CreateBindCtx
);
85 hr
= CreateFileMoniker(wszFileName1
, &pmk1
);
86 ok(hr
==0, "CreateFileMoniker for file hr=%08lx\n", hr
);
87 hr
= CreateFileMoniker(wszFileName2
, &pmk2
);
88 ok(hr
==0, "CreateFileMoniker for file hr=%08lx\n", hr
);
89 hr
= IBindCtx_GetRunningObjectTable(pbc
, &pprot
);
90 ok(hr
==0, "IBindCtx_GetRunningObjectTable hr=%08lx\n", hr
);
92 /* Check EnumMoniker before registering */
93 hr
= IRunningObjectTable_EnumRunning(pprot
, &spEM1
);
94 ok(hr
==0, "IRunningObjectTable_EnumRunning hr=%08lx\n", hr
);
95 hr
= IEnumMoniker_QueryInterface(spEM1
, &IID_IUnknown
, (void*) &lpEM1
);
96 /* Register a couple of Monikers and check is ok */
97 ok(hr
==0, "IEnumMoniker_QueryInterface hr %08lx %p\n", hr
, lpEM1
);
100 while ((IEnumMoniker_Next(spEM1
, 1, &spMoniker
, NULL
)==S_OK
) &&
105 hr
=IMoniker_GetDisplayName(spMoniker
, pbc
, NULL
,
106 (LPOLESTR
*) &szDisplayn
);
107 /* szDisplayn needs to be freed by
108 * IMalloc_Free hence the use of
112 CoTaskMemFree(szDisplayn
);
115 ok(monCnt
==0, "Number of monikers should be equal to 0 not %i\n", monCnt
); grflags
= grflags
| ROTFLAGS_REGISTRATIONKEEPSALIVE
;
116 hr
= IRunningObjectTable_Register(pprot
, grflags
, lpEM1
, pmk1
, &pdwReg1
);
117 ok(hr
==0, "IRunningObjectTable_Register hr=%08lx %p %08lx %p %p %ld\n",
118 hr
, pprot
, grflags
, lpEM1
, pmk1
, pdwReg1
);
121 grflags
= grflags
| ROTFLAGS_REGISTRATIONKEEPSALIVE
;
122 hr
= IRunningObjectTable_Register(pprot
, grflags
, lpEM1
, pmk2
, &pdwReg2
);
123 ok(hr
==0, "IRunningObjectTable_Register hr=%08lx %p %08lx %p %p %ld\n", hr
,
124 pprot
, grflags
, lpEM1
, pmk2
, pdwReg2
);
126 hr
= IRunningObjectTable_EnumRunning(pprot
, &spEM2
);
127 ok(hr
==0, "IRunningObjectTable_EnumRunning hr=%08lx\n", hr
);
130 while ((IEnumMoniker_Next(spEM2
, 1, &spMoniker
, NULL
)==S_OK
) &&
133 WCHAR
*szDisplayn
=NULL
;
135 hr
=IMoniker_GetDisplayName(spMoniker
, pbc
, NULL
,
136 (LPOLESTR
*) &szDisplayn
);
137 /* szDisplayn needs to be freed by
138 * IMalloc_Free hence the use of
142 CoTaskMemFree(szDisplayn
);
145 ok(monCnt
==2, "Number of monikers should be equal to 2 not %i\n", monCnt
);
147 IEnumMoniker_Clone(spEM2
, &spEM3
);
149 while ((IEnumMoniker_Next(spEM3
, 1, &spMoniker
, NULL
)==S_OK
) &&
152 WCHAR
*szDisplayn
=NULL
;
154 hr
=IMoniker_GetDisplayName(spMoniker
, pbc
, NULL
,
155 (LPOLESTR
*) &szDisplayn
);
156 /* szDisplayn needs to be freed by
157 * IMalloc_Free hence the use of
161 CoTaskMemFree(szDisplayn
);
164 ok(monCnt
==2, "Number of monikers should be equal to 2 not %i\n", monCnt
);
165 IRunningObjectTable_Revoke(pprot
,pdwReg1
);
166 IRunningObjectTable_Revoke(pprot
,pdwReg2
);
167 IEnumMoniker_Release(spEM1
);
168 IEnumMoniker_Release(spEM1
);
169 IEnumMoniker_Release(spEM2
);
170 IEnumMoniker_Release(spEM3
);
171 IMoniker_Release(pmk1
);
172 IMoniker_Release(pmk2
);
173 IRunningObjectTable_Release(pprot
);
175 IBindCtx_Release(pbc
);
176 /* Finished testing EnumMoniker */
179 static const BYTE expected_moniker_data
[] =
181 0x4d,0x45,0x4f,0x57,0x04,0x00,0x00,0x00,
182 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
183 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
184 0x1a,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
185 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
186 0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,
187 0x05,0xe0,0x02,0x00,0x00,0x00,0x00,0x00,
188 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
192 static const LARGE_INTEGER llZero
;
194 static void test_class_moniker()
205 hr
= CreateClassMoniker(&CLSID_StdComponentCategoriesMgr
, &moniker
);
206 todo_wine
{ ok_ole_success(hr
, CreateClassMoniker
); }
208 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
210 hr
= CoMarshalInterface(stream
, &IID_IMoniker
, (IUnknown
*)moniker
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
211 todo_wine
{ ok_ole_success(hr
, CoMarshalInterface
); }
213 hr
= GetHGlobalFromStream(stream
, &hglobal
);
214 ok_ole_success(hr
, GetHGlobalFromStream
);
216 moniker_size
= GlobalSize(hglobal
);
218 moniker_data
= GlobalLock(hglobal
);
220 /* first check we have the right amount of data */
222 ok(moniker_size
== sizeof(expected_moniker_data
),
223 "Size of marshaled data differs (expected %d, actual %ld)\n",
224 sizeof(expected_moniker_data
), moniker_size
);
227 /* then do a byte-by-byte comparison */
228 for (i
= 0; i
< min(moniker_size
, sizeof(expected_moniker_data
)); i
++)
230 if (expected_moniker_data
[i
] != moniker_data
[i
])
237 ok(same
, "Marshaled data differs\n");
240 trace("Dumping marshaled moniker data:\n");
241 for (i
= 0; i
< moniker_size
; i
++)
243 trace("0x%02x,", moniker_data
[i
]);
244 if (i
% 8 == 7) trace("\n");
245 if (i
% 8 == 0) trace(" ");
249 GlobalUnlock(hglobal
);
251 IStream_Seek(stream
, llZero
, STREAM_SEEK_SET
, NULL
);
252 hr
= CoReleaseMarshalData(stream
);
253 todo_wine
{ ok_ole_success(hr
, CoReleaseMarshalData
); }
255 IStream_Release(stream
);
256 if (moniker
) IMoniker_Release(moniker
);
261 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
263 test_MkParseDisplayName();
264 test_class_moniker();
265 /* FIXME: test moniker creation funcs and parsing other moniker formats */