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