[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / shell32 / CShellDesktop.cpp
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for CShellDesktop
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 START_TEST(CShellDesktop)
53 {
54 HRESULT hr;
55 CComPtr<IShellFolder2> psf2;
56 CComPtr<IShellFolder2> psf2_2;
57 CComPtr<IShellFolder> psf;
58
59 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
60
61 hr = CoCreateInstance(CLSID_ShellDesktop,
62 NULL,
63 CLSCTX_INPROC_SERVER,
64 IID_PPV_ARG(IShellFolder2, &psf2));
65 ok(hr == S_OK, "hr = %lx\n", hr);
66 if (FAILED(hr))
67 {
68 skip("Could not instantiate CShellDesktop\n");
69 return;
70 }
71
72 /* second create should give us a pointer to the same object */
73 hr = CoCreateInstance(CLSID_ShellDesktop,
74 NULL,
75 CLSCTX_INPROC_SERVER,
76 IID_PPV_ARG(IShellFolder2, &psf2_2));
77 ok(hr == S_OK, "hr = %lx\n", hr);
78 ok(psf2 == psf2_2, "Expected %p == %p\n", static_cast<PVOID>(psf2), static_cast<PVOID>(psf2_2));
79
80 /* SHGetDesktopFolder should also give us the same pointer */
81 hr = SHGetDesktopFolder(&psf);
82 ok(hr == S_OK, "hr = %lx\n", hr);
83 ok(psf == static_cast<IShellFolder *>(psf2), "Expected %p == %p\n", static_cast<PVOID>(psf), static_cast<PVOID>(psf2));
84
85 TestShellFolder(psf2);
86 }