Reverse the order for deleting the items in resetcontent to correctly
[wine] / dlls / ole32 / tests / moniker.c
1 /*
2  * Moniker Tests
3  *
4  * Copyright 2004 Robert Shearman
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #define _WIN32_DCOM
22 #define COBJMACROS
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "comcat.h"
30
31 #include "wine/test.h"
32
33 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", hr)
34
35 static void test_MkParseDisplayName()
36 {
37     IBindCtx * pbc = NULL;
38     HRESULT hr;
39     IMoniker * pmk = NULL;
40     ULONG eaten;
41     IUnknown * object = NULL;
42     /* CLSID of My Computer */
43     static const WCHAR wszDisplayName[] = {'c','l','s','i','d',':',
44         '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};
45
46     hr = CreateBindCtx(0, &pbc);
47     ok_ole_success(hr, CreateBindCtx);
48
49     hr = MkParseDisplayName(pbc, wszDisplayName, &eaten, &pmk);
50     todo_wine { ok_ole_success(hr, MkParseDisplayName); }
51
52     if (object)
53     {
54         hr = IMoniker_BindToObject(pmk, pbc, NULL, &IID_IUnknown, (LPVOID*)&object);
55         ok_ole_success(hr, IMoniker_BindToObject);
56
57         IUnknown_Release(object);
58     }
59     IBindCtx_Release(pbc);
60 }
61
62 static const BYTE expected_moniker_data[] =
63 {
64         0x4d,0x45,0x4f,0x57,0x04,0x00,0x00,0x00,
65         0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
66         0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
67         0x1a,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
68         0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
69         0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,
70         0x05,0xe0,0x02,0x00,0x00,0x00,0x00,0x00,
71         0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,
72         0x00,0x00,0x00,0x00,
73 };
74
75 static const LARGE_INTEGER llZero;
76
77 static void test_class_moniker()
78 {
79     IStream * stream;
80     IMoniker * moniker;
81     HRESULT hr;
82     HGLOBAL hglobal;
83     LPBYTE moniker_data;
84     DWORD moniker_size;
85     DWORD i;
86     BOOL same = TRUE;
87
88     hr = CreateClassMoniker(&CLSID_StdComponentCategoriesMgr, &moniker);
89     todo_wine { ok_ole_success(hr, CreateClassMoniker); }
90
91     hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
92
93     hr = CoMarshalInterface(stream, &IID_IMoniker, (IUnknown *)moniker, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
94     todo_wine { ok_ole_success(hr, CoMarshalInterface); }
95
96     hr = GetHGlobalFromStream(stream, &hglobal);
97     ok_ole_success(hr, GetHGlobalFromStream);
98
99     moniker_size = GlobalSize(hglobal);
100
101     moniker_data = GlobalLock(hglobal);
102
103     /* first check we have the right amount of data */
104     todo_wine {
105     ok(moniker_size == sizeof(expected_moniker_data),
106         "Size of marshaled data differs (expected %d, actual %ld)\n",
107         sizeof(expected_moniker_data), moniker_size);
108     }
109
110     /* then do a byte-by-byte comparison */
111     for (i = 0; i < min(moniker_size, sizeof(expected_moniker_data)); i++)
112     {
113         if (expected_moniker_data[i] != moniker_data[i])
114         {
115             same = FALSE;
116             break;
117         }
118     }
119
120     ok(same, "Marshaled data differs\n");
121     if (!same)
122     {
123         trace("Dumping marshaled moniker data:\n");
124         for (i = 0; i < moniker_size; i++)
125         {
126             trace("0x%02x,", moniker_data[i]);
127             if (i % 8 == 7) trace("\n");
128             if (i % 8 == 0) trace("     ");
129         }
130     }
131
132     GlobalUnlock(hglobal);
133
134     IStream_Seek(stream, llZero, STREAM_SEEK_SET, NULL);
135     hr = CoReleaseMarshalData(stream);
136     todo_wine { ok_ole_success(hr, CoReleaseMarshalData); }
137
138     IStream_Release(stream);
139     if (moniker) IMoniker_Release(moniker);
140 }
141
142 START_TEST(moniker)
143 {
144     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
145
146     test_MkParseDisplayName();
147     test_class_moniker();
148     /* FIXME: test moniker creation funcs and parsing other moniker formats */
149
150     CoUninitialize();
151 }