[SHELL32_APITEST] -Add some tests for SHParseDisplayName for CORE-12882.
[reactos.git] / rostests / apitests / shell32 / CMyComputer.cpp
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 #include <atlbase.h>
10 #include <atlcom.h>
11 #include <strsafe.h>
12
13 #define NDEBUG
14 #include <debug.h>
15 #include <shellutils.h>
16
17 static
18 VOID
19 TestShellFolder(
20 _In_ IShellFolder2 *psf2)
21 {
22 HRESULT hr;
23 CComPtr<IDropTarget> pdt;
24 CComPtr<IDropTarget> pdt_2;
25 CComPtr<IContextMenu> pcm;
26 CComPtr<IContextMenu> pcm_2;
27 CComPtr<IShellView> psv;
28 CComPtr<IShellView> psv_2;
29
30 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
31 ok(hr == S_OK, "hr = %lx\n", hr);
32
33 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt_2));
34 ok(hr == S_OK, "hr = %lx\n", hr);
35 ok(pdt != pdt_2, "Expected %p != %p\n", static_cast<PVOID>(pdt), static_cast<PVOID>(pdt_2));
36
37 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
38 ok(hr == S_OK, "hr = %lx\n", hr);
39
40 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm_2));
41 ok(hr == S_OK, "hr = %lx\n", hr);
42 ok(pcm != pcm_2, "Expected %p != %p\n", static_cast<PVOID>(pcm), static_cast<PVOID>(pcm_2));
43
44 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
45 ok(hr == S_OK, "hr = %lx\n", hr);
46
47 hr = psf2->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv_2));
48 ok(hr == S_OK, "hr = %lx\n", hr);
49 ok(psv != psv_2, "Expected %p != %p\n", static_cast<PVOID>(psv), static_cast<PVOID>(psv_2));
50 }
51
52 VOID TestInitialize(_In_ IShellFolder2 *psf2)
53 {
54 CComPtr<IPersistFolder2> ppf2;
55 HRESULT hr = psf2->QueryInterface(IID_PPV_ARG(IPersistFolder2, &ppf2));
56 ok(hr == S_OK, "hr = %lx\n", hr);
57
58 hr = ppf2->Initialize(NULL);
59 ok(hr == S_OK, "hr = %lx\n", hr);
60
61 hr = ppf2->Initialize((LPCITEMIDLIST)0xdeaddead);
62 ok(hr == S_OK, "hr = %lx\n", hr);
63
64 //crashes in xp
65 //hr = ppf2->GetCurFolder(NULL);
66 //ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
67
68 LPITEMIDLIST pidl;
69 hr = ppf2->GetCurFolder(&pidl);
70 ok(hr == S_OK, "hr = %lx\n", hr);
71 // 0 in win10, 14 in xp
72 ok(pidl->mkid.cb == 0x14, "expected empty pidl got cb = %x\n", pidl->mkid.cb);
73 }
74
75 START_TEST(CMyComputer)
76 {
77 HRESULT hr;
78 CComPtr<IShellFolder2> psf2;
79 CComPtr<IShellFolder2> psf2_2;
80 CComPtr<IShellFolder> psf;
81
82 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
83
84 hr = CoCreateInstance(CLSID_MyComputer,
85 NULL,
86 CLSCTX_INPROC_SERVER,
87 IID_PPV_ARG(IShellFolder2, &psf2));
88 ok(hr == S_OK, "hr = %lx\n", hr);
89 if (FAILED(hr))
90 {
91 skip("Could not instantiate CShellDesktop\n");
92 return;
93 }
94
95 /* second create should give us a pointer to the same object */
96 hr = CoCreateInstance(CLSID_MyComputer,
97 NULL,
98 CLSCTX_INPROC_SERVER,
99 IID_PPV_ARG(IShellFolder2, &psf2_2));
100 ok(hr == S_OK, "hr = %lx\n", hr);
101 ok(psf2 == psf2_2, "Expected %p == %p\n", static_cast<PVOID>(psf2), static_cast<PVOID>(psf2_2));
102
103 TestShellFolder(psf2);
104 TestInitialize(psf2);
105 }