mstask: Implement GetTargetComputer.
[wine] / dlls / scrrun / tests / filesystem.c
1 /*
2  *
3  * Copyright 2012 Alistair Leslie-Hughes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #define COBJMACROS
21 #include <stdio.h>
22
23 #include "windows.h"
24 #include "ole2.h"
25 #include "olectl.h"
26 #include "oleauto.h"
27 #include "dispex.h"
28
29 #include "wine/test.h"
30
31 #include "initguid.h"
32 #include "scrrun.h"
33
34 static void test_interfaces(void)
35 {
36     static const WCHAR nonexistent_dirW[] = {
37         'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', 0};
38     static const WCHAR pathW[] = {'p','a','t','h',0};
39     static const WCHAR file_kernel32W[] = {
40         '\\', 'k', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', 0};
41     HRESULT hr;
42     IDispatch *disp;
43     IDispatchEx *dispex;
44     IFileSystem3 *fs3;
45     IObjectWithSite *site;
46     VARIANT_BOOL b;
47     BSTR path;
48     WCHAR windows_path[MAX_PATH];
49     WCHAR file_path[MAX_PATH];
50
51     hr = CoCreateInstance(&CLSID_FileSystemObject, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
52             &IID_IDispatch, (void**)&disp);
53     if(FAILED(hr)) {
54         win_skip("Could not create FileSystem object: %08x\n", hr);
55         return;
56     }
57
58     GetSystemDirectoryW(windows_path, MAX_PATH);
59     lstrcpyW(file_path, windows_path);
60     lstrcatW(file_path, file_kernel32W);
61
62     hr = IDispatch_QueryInterface(disp, &IID_IFileSystem3, (void**)&fs3);
63     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
64
65     hr = IDispatch_QueryInterface(disp, &IID_IObjectWithSite, (void**)&site);
66     ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
67
68     hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
69     ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
70
71     b = VARIANT_TRUE;
72     hr = IFileSystem3_FileExists(fs3, NULL, &b);
73     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
74     ok(b == VARIANT_FALSE, "got %x\n", b);
75
76     hr = IFileSystem3_FileExists(fs3, NULL, NULL);
77     ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
78
79     path = SysAllocString(pathW);
80     b = VARIANT_TRUE;
81     hr = IFileSystem3_FileExists(fs3, path, &b);
82     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
83     ok(b == VARIANT_FALSE, "got %x\n", b);
84     SysFreeString(path);
85
86     path = SysAllocString(file_path);
87     b = VARIANT_FALSE;
88     hr = IFileSystem3_FileExists(fs3, path, &b);
89     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
90     ok(b == VARIANT_TRUE, "got %x\n", b);
91     SysFreeString(path);
92
93     path = SysAllocString(windows_path);
94     b = VARIANT_TRUE;
95     hr = IFileSystem3_FileExists(fs3, path, &b);
96     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
97     ok(b == VARIANT_FALSE, "got %x\n", b);
98     SysFreeString(path);
99
100     /* Folder Exists */
101     hr = IFileSystem3_FolderExists(fs3, NULL, NULL);
102     ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
103
104     path = SysAllocString(windows_path);
105     hr = IFileSystem3_FolderExists(fs3, path, &b);
106     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
107     ok(b == VARIANT_TRUE, "Folder doesn't exists\n");
108     SysFreeString(path);
109
110     path = SysAllocString(nonexistent_dirW);
111     hr = IFileSystem3_FolderExists(fs3, path, &b);
112     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
113     ok(b == VARIANT_FALSE, "Folder exists\n");
114     SysFreeString(path);
115
116     path = SysAllocString(file_path);
117     hr = IFileSystem3_FolderExists(fs3, path, &b);
118     ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
119     ok(b == VARIANT_FALSE, "Folder exists\n");
120     SysFreeString(path);
121
122     IFileSystem3_Release(fs3);
123     IDispatch_Release(disp);
124 }
125
126 static void test_createfolder(void)
127 {
128     IFileSystem3 *fs3;
129     HRESULT hr;
130     WCHAR pathW[MAX_PATH];
131     BSTR path;
132     IFolder *folder;
133
134     hr = CoCreateInstance(&CLSID_FileSystemObject, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
135             &IID_IFileSystem3, (void**)&fs3);
136     if(FAILED(hr)) {
137         win_skip("Could not create FileSystem object: %08x\n", hr);
138         return;
139     }
140
141     /* create existing directory */
142     GetCurrentDirectoryW(sizeof(pathW)/sizeof(WCHAR), pathW);
143     path = SysAllocString(pathW);
144     folder = (void*)0xdeabeef;
145     hr = IFileSystem3_CreateFolder(fs3, path, &folder);
146     ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr);
147     ok(folder == NULL, "got %p\n", folder);
148     SysFreeString(path);
149
150     IFileSystem3_Release(fs3);
151 }
152
153 START_TEST(filesystem)
154 {
155     CoInitialize(NULL);
156
157     test_interfaces();
158     test_createfolder();
159
160     CoUninitialize();
161 }