Release 1.4.1.
[wine] / dlls / wshom.ocx / tests / wshom.c
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <initguid.h>
23 #include <ole2.h>
24 #include <dispex.h>
25
26 #include "wshom.h"
27 #include "wine/test.h"
28
29 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
30
31 #define EXPECT_HR(hr,hr_exp) \
32     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
33
34 static void test_wshshell(void)
35 {
36     static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
37     static const WCHAR lnk1W[] = {'f','i','l','e','.','l','n','k',0};
38     IWshShell3 *sh3;
39     IDispatchEx *dispex;
40     IWshCollection *coll;
41     IDispatch *disp, *shortcut;
42     IUnknown *shell, *unk;
43     IFolderCollection *folders;
44     ITypeInfo *ti;
45     HRESULT hr;
46     TYPEATTR *tattr;
47     DISPPARAMS dp;
48     EXCEPINFO ei;
49     VARIANT arg, res;
50     BSTR str;
51     UINT err;
52
53     hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
54             &IID_IDispatch, (void**)&disp);
55     if(FAILED(hr)) {
56         win_skip("Could not create WshShell object: %08x\n", hr);
57         return;
58     }
59
60     hr = IDispatch_QueryInterface(disp, &IID_IWshShell3, (void**)&shell);
61     EXPECT_HR(hr, S_OK);
62     IDispatch_Release(disp);
63
64     hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
65     EXPECT_HR(hr, E_NOINTERFACE);
66
67     hr = IDispatch_QueryInterface(shell, &IID_IWshShell3, (void**)&sh3);
68     EXPECT_HR(hr, S_OK);
69
70     hr = IWshShell3_get_SpecialFolders(sh3, &coll);
71     EXPECT_HR(hr, S_OK);
72
73     hr = IWshCollection_QueryInterface(coll, &IID_IFolderCollection, (void**)&folders);
74     EXPECT_HR(hr, E_NOINTERFACE);
75
76     hr = IWshCollection_QueryInterface(coll, &IID_IDispatch, (void**)&disp);
77     EXPECT_HR(hr, S_OK);
78
79     hr = IDispatch_GetTypeInfo(disp, 0, 0, &ti);
80     EXPECT_HR(hr, S_OK);
81
82     hr = ITypeInfo_GetTypeAttr(ti, &tattr);
83     EXPECT_HR(hr, S_OK);
84     ok(IsEqualIID(&tattr->guid, &IID_IWshCollection), "got wrong type guid\n");
85     ITypeInfo_ReleaseTypeAttr(ti, tattr);
86
87     /* try to call Item() with normal IDispatch procedure */
88     str = SysAllocString(desktopW);
89     V_VT(&arg) = VT_BSTR;
90     V_BSTR(&arg) = str;
91     dp.rgvarg = &arg;
92     dp.rgdispidNamedArgs = NULL;
93     dp.cArgs = 1;
94     dp.cNamedArgs = 0;
95     hr = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 1033, DISPATCH_PROPERTYGET, &dp, &res, &ei, &err);
96     EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
97
98     /* try Item() directly, it returns directory path apparently */
99     V_VT(&res) = VT_EMPTY;
100     hr = IWshCollection_Item(coll, &arg, &res);
101     EXPECT_HR(hr, S_OK);
102     ok(V_VT(&res) == VT_BSTR, "got res type %d\n", V_VT(&res));
103     SysFreeString(str);
104     VariantClear(&res);
105
106     /* CreateShortcut() */
107     str = SysAllocString(lnk1W);
108     hr = IWshShell3_CreateShortcut(sh3, str, &shortcut);
109     EXPECT_HR(hr, S_OK);
110     SysFreeString(str);
111     hr = IDispatch_QueryInterface(shortcut, &IID_IWshShortcut, (void**)&unk);
112     EXPECT_HR(hr, S_OK);
113     IUnknown_Release(unk);
114     IDispatch_Release(shortcut);
115
116     IWshCollection_Release(coll);
117     IDispatch_Release(disp);
118     IWshShell3_Release(sh3);
119     IUnknown_Release(shell);
120 }
121
122 START_TEST(wshom)
123 {
124     CoInitialize(NULL);
125
126     test_wshshell();
127
128     CoUninitialize();
129 }