1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS api tests
3c2c66affSColin Finck * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4c2c66affSColin Finck * PURPOSE: Test for CMyComputer
5c2c66affSColin Finck * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6c2c66affSColin Finck */
7c2c66affSColin Finck
8c2c66affSColin Finck #include "shelltest.h"
9c2c66affSColin Finck
10c2c66affSColin Finck #define NDEBUG
11c2c66affSColin Finck #include <debug.h>
12e419195dSIoannis Adamopoulos #include <stdio.h>
13c2c66affSColin Finck #include <shellutils.h>
14c2c66affSColin Finck
15bb9a5f60STimo Kreuzer #define INVALID_POINTER ((PVOID)(ULONG_PTR)0xdeadbeefdeadbeefULL)
16bb9a5f60STimo Kreuzer
17c2c66affSColin Finck static
18c2c66affSColin Finck VOID
TestShellFolder(_In_ IShellFolder2 * psf2)19c2c66affSColin Finck TestShellFolder(
20c2c66affSColin Finck _In_ IShellFolder2 *psf2)
21c2c66affSColin Finck {
22c2c66affSColin Finck HRESULT hr;
23c2c66affSColin Finck CComPtr<IDropTarget> pdt;
24c2c66affSColin Finck CComPtr<IDropTarget> pdt_2;
25c2c66affSColin Finck CComPtr<IContextMenu> pcm;
26c2c66affSColin Finck CComPtr<IContextMenu> pcm_2;
27c2c66affSColin Finck CComPtr<IShellView> psv;
28c2c66affSColin Finck CComPtr<IShellView> psv_2;
29c2c66affSColin Finck
30c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
31c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
32c2c66affSColin Finck
33c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt_2));
34c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
35c2c66affSColin Finck ok(pdt != pdt_2, "Expected %p != %p\n", static_cast<PVOID>(pdt), static_cast<PVOID>(pdt_2));
36c2c66affSColin Finck
37c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
38c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
39c2c66affSColin Finck
40c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm_2));
41c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
42c2c66affSColin Finck ok(pcm != pcm_2, "Expected %p != %p\n", static_cast<PVOID>(pcm), static_cast<PVOID>(pcm_2));
43c2c66affSColin Finck
44c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
45c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
46c2c66affSColin Finck
47c2c66affSColin Finck hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv_2));
48c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
49c2c66affSColin Finck ok(psv != psv_2, "Expected %p != %p\n", static_cast<PVOID>(psv), static_cast<PVOID>(psv_2));
50c2c66affSColin Finck }
51c2c66affSColin Finck
TestInitialize(_In_ IShellFolder2 * psf2)52c2c66affSColin Finck VOID TestInitialize(_In_ IShellFolder2 *psf2)
53c2c66affSColin Finck {
54c2c66affSColin Finck CComPtr<IPersistFolder2> ppf2;
55c2c66affSColin Finck HRESULT hr = psf2->QueryInterface(IID_PPV_ARG(IPersistFolder2, &ppf2));
56c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
57c2c66affSColin Finck
58c2c66affSColin Finck hr = ppf2->Initialize(NULL);
59c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
60c2c66affSColin Finck
61bb9a5f60STimo Kreuzer hr = ppf2->Initialize((LPCITEMIDLIST)INVALID_POINTER);
62c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
63c2c66affSColin Finck
64c2c66affSColin Finck //crashes in xp
65c2c66affSColin Finck //hr = ppf2->GetCurFolder(NULL);
66c2c66affSColin Finck //ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
67c2c66affSColin Finck
68*cf2b918eSThomas Faber CComHeapPtr<ITEMIDLIST> pidl;
69c2c66affSColin Finck hr = ppf2->GetCurFolder(&pidl);
70c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
71c2c66affSColin Finck // 0 in win10, 14 in xp
72c2c66affSColin Finck ok(pidl->mkid.cb == 0x14, "expected empty pidl got cb = %x\n", pidl->mkid.cb);
73c2c66affSColin Finck }
74c2c66affSColin Finck
START_TEST(CMyComputer)75c2c66affSColin Finck START_TEST(CMyComputer)
76c2c66affSColin Finck {
77c2c66affSColin Finck HRESULT hr;
78c2c66affSColin Finck CComPtr<IShellFolder2> psf2;
79c2c66affSColin Finck CComPtr<IShellFolder2> psf2_2;
80c2c66affSColin Finck CComPtr<IShellFolder> psf;
81c2c66affSColin Finck
82c2c66affSColin Finck CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
83c2c66affSColin Finck
84c2c66affSColin Finck hr = CoCreateInstance(CLSID_MyComputer,
85c2c66affSColin Finck NULL,
86c2c66affSColin Finck CLSCTX_INPROC_SERVER,
87c2c66affSColin Finck IID_PPV_ARG(IShellFolder2, &psf2));
88c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
89c2c66affSColin Finck if (FAILED(hr))
90c2c66affSColin Finck {
91c2c66affSColin Finck skip("Could not instantiate CShellDesktop\n");
92c2c66affSColin Finck return;
93c2c66affSColin Finck }
94c2c66affSColin Finck
95c2c66affSColin Finck /* second create should give us a pointer to the same object */
96c2c66affSColin Finck hr = CoCreateInstance(CLSID_MyComputer,
97c2c66affSColin Finck NULL,
98c2c66affSColin Finck CLSCTX_INPROC_SERVER,
99c2c66affSColin Finck IID_PPV_ARG(IShellFolder2, &psf2_2));
100c2c66affSColin Finck ok(hr == S_OK, "hr = %lx\n", hr);
101c2c66affSColin Finck ok(psf2 == psf2_2, "Expected %p == %p\n", static_cast<PVOID>(psf2), static_cast<PVOID>(psf2_2));
102c2c66affSColin Finck
103c2c66affSColin Finck TestShellFolder(psf2);
104c2c66affSColin Finck TestInitialize(psf2);
105c2c66affSColin Finck }
106