1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Test for OBJECT_ENTRY_AUTO
5 * COPYRIGHT: Copyright 2023 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8 #ifdef HAVE_APITEST
9 #include <apitest.h>
10 #else
11 #include "atltest.h"
12 #endif
13
14 #include <atlbase.h>
15 #include <atlcom.h>
16
17 class CAtlObjMapModule : public ATL::CAtlExeModuleT<CAtlObjMapModule>
18 {
19
20 } _Module;
21
22 CLSID CLSID_ObjMapTestObject = {0xeae5616c, 0x1e7f, 0x4a00, {0x92, 0x27, 0x1a, 0xad, 0xad, 0x66, 0xbb, 0x85}};
23
24 static LONG g_Created = 0;
25 static LONG g_Destroyed = 0;
26
27
START_TEST(AtlObjMap)28 START_TEST(AtlObjMap)
29 {
30 HRESULT hr = CoInitialize(NULL);
31 ok_hex(hr, S_OK);
32
33 {
34 CComPtr<IUnknown> spTestObject;
35 hr = CoCreateInstance(CLSID_ObjMapTestObject, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (LPVOID*)&spTestObject);
36 ok_hex(hr, REGDB_E_CLASSNOTREG);
37 }
38
39 ok_int(g_Created, 0);
40 ok_int(g_Destroyed, 0);
41
42 // Register the com objects added to the auto-map in _AtlComModule
43 hr = _Module.RegisterClassObjects(CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE);
44 ok_hex(hr, S_OK);
45
46 ok_int(g_Created, 0);
47 ok_int(g_Destroyed, 0);
48
49 {
50 CComPtr<IUnknown> spTestObject;
51 hr = CoCreateInstance(CLSID_ObjMapTestObject, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (LPVOID *)&spTestObject);
52 ok_hex(hr, S_OK);
53 ok_int(g_Created, 1);
54 ok_int(g_Destroyed, 0);
55 }
56 ok_int(g_Created, 1);
57 ok_int(g_Destroyed, 1);
58 }
59
60
61
62 struct CObjMapTestObject : public CComObjectRootEx<CComSingleThreadModel>,
63 public CComCoClass<CObjMapTestObject, &CLSID_ObjMapTestObject>,
64 public IUnknown
65 {
CObjMapTestObjectCObjMapTestObject66 CObjMapTestObject()
67 {
68 InterlockedIncrement(&g_Created);
69 }
~CObjMapTestObjectCObjMapTestObject70 ~CObjMapTestObject()
71 {
72 InterlockedIncrement(&g_Destroyed);
73 }
74
75
76 DECLARE_PROTECT_FINAL_CONSTRUCT();
77 DECLARE_NO_REGISTRY();
78 DECLARE_NOT_AGGREGATABLE(CObjMapTestObject)
79
80 BEGIN_COM_MAP(CObjMapTestObject)
81 COM_INTERFACE_ENTRY_IID(IID_IUnknown, IUnknown)
82 END_COM_MAP()
83 };
84
85 OBJECT_ENTRY_AUTO(CLSID_ObjMapTestObject, CObjMapTestObject)
86
87