From f941c78f50cb138840c68c2756a583e8d8ceb105 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Wed, 20 Dec 2017 22:06:44 +0100 Subject: [PATCH] [ATL_APITEST] Show that CComObject's COM_MAP continues enumeration after a failing blind function. --- modules/rostests/apitests/atl/CComObject.cpp | 149 +++++++++++++++ modules/rostests/apitests/atl/CMakeLists.txt | 1 + .../rostests/apitests/atl/devenv/ATLTest.sln | 10 + .../apitests/atl/devenv/CComObject.vcxproj | 180 ++++++++++++++++++ .../apitests/atl/devenv/CImage.vcxproj | 2 +- modules/rostests/apitests/atl/testlist.c | 2 + 6 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 modules/rostests/apitests/atl/CComObject.cpp create mode 100644 modules/rostests/apitests/atl/devenv/CComObject.vcxproj diff --git a/modules/rostests/apitests/atl/CComObject.cpp b/modules/rostests/apitests/atl/CComObject.cpp new file mode 100644 index 00000000000..f7d16e1e69c --- /dev/null +++ b/modules/rostests/apitests/atl/CComObject.cpp @@ -0,0 +1,149 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Test for CComObject + * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) + */ + + +#include +#include + +#ifdef __REACTOS__ + #include +#else + #include + #include + #include + int g_tests_executed = 0; + int g_tests_failed = 0; + void ok_func(const char *file, int line, BOOL value, const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + if (!value) + { + printf("%s (%d): ", file, line); + vprintf(fmt, va); + g_tests_failed++; + } + g_tests_executed++; + va_end(va); + } + #undef ok + #define ok(value, ...) ok_func(__FILE__, __LINE__, value, __VA_ARGS__) + #define START_TEST(x) int main(void) +#endif + + +static LONG g_CTOR = 0; +static LONG g_DTOR = 0; +static LONG g_BLIND = 0; + +class CTestObject : + public CComObjectRootEx, + public IPersist, + public IStdMarshalInfo +{ +public: + CTestObject() + { + InterlockedIncrement(&g_CTOR); + } + ~CTestObject() + { + InterlockedIncrement(&g_DTOR); + } + + // *** IPersist methods *** + virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID) + { + return E_NOTIMPL; + } + + // *** IStdMarshalInfo methods *** + virtual HRESULT STDMETHODCALLTYPE GetClassForHandler(DWORD dwDestContext, void *pvDestContext, CLSID *pClsid) + { + return E_NOTIMPL; + } + + static HRESULT WINAPI FuncBlind(void* pv, REFIID riid, LPVOID* ppv, DWORD dw) + { + InterlockedIncrement(&g_BLIND); + return E_FAIL; + } + + DECLARE_NOT_AGGREGATABLE(CTestObject) + DECLARE_PROTECT_FINAL_CONSTRUCT() + + BEGIN_COM_MAP(CTestObject) + COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist) /* First entry has to be a simple entry, otherwise ATL asserts */ + COM_INTERFACE_ENTRY_FUNC_BLIND(0, FuncBlind) /* Showing that even after a Blind func, entryies can be found */ + COM_INTERFACE_ENTRY_IID(IID_IStdMarshalInfo, IStdMarshalInfo) + END_COM_MAP() +}; + + +class CDumExe: public CAtlExeModuleT +{ + +}; +CDumExe dum; + + +START_TEST(CComObject) +{ + g_CTOR = g_DTOR = g_BLIND = 0; + + CComObject* pTest; + HRESULT hr = CComObject::CreateInstance(&pTest); + + ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr); + + ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR); + ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR); + ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND); + + if (hr == S_OK) + { + ULONG ref = pTest->AddRef(); + ok(ref == 1, "Expected 1, got %lu\n", ref); + + { + CComPtr ppv; + hr = pTest->QueryInterface(IID_IUnknown, (void **) &ppv); + ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr); + ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR); + ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR); + ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND); + + CComPtr ppersist; + hr = pTest->QueryInterface(IID_IPersist, (void **)&ppersist); + ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr); + ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR); + ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR); + ok(g_BLIND == 0, "Expected 0, got %lu\n", g_BLIND); + + } + + { + CComPtr pstd; + hr = pTest->QueryInterface(IID_IStdMarshalInfo, (void **)&pstd); + ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr); + ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR); + ok(g_DTOR == 0, "Expected 0, got %lu\n", g_DTOR); + ok(g_BLIND == 1, "Expected 1, got %lu\n", g_BLIND); + } + + ref = pTest->Release(); + ok(ref == 0, "Expected 0, got %lu\n", ref); + ok(g_CTOR == 1, "Expected 1, got %lu\n", g_CTOR); + ok(g_DTOR == 1, "Expected 1, got %lu\n", g_DTOR); + ok(g_BLIND == 1, "Expected 1, got %lu\n", g_BLIND); + } + +#ifndef __REACTOS__ + printf("CImage: %i tests executed (0 marked as todo, %i failures), 0 skipped.\n", g_tests_executed, g_tests_failed); + return g_tests_failed; +#endif +} diff --git a/modules/rostests/apitests/atl/CMakeLists.txt b/modules/rostests/apitests/atl/CMakeLists.txt index 9c9ed6ddec7..fbc1420decf 100644 --- a/modules/rostests/apitests/atl/CMakeLists.txt +++ b/modules/rostests/apitests/atl/CMakeLists.txt @@ -8,6 +8,7 @@ list(APPEND SOURCE atltypes.cpp CComBSTR.cpp CComHeapPtr.cpp + CComObject.cpp CImage.cpp CRegKey.cpp CSimpleArray.cpp diff --git a/modules/rostests/apitests/atl/devenv/ATLTest.sln b/modules/rostests/apitests/atl/devenv/ATLTest.sln index 1384c080a6a..d9d18dddb67 100644 --- a/modules/rostests/apitests/atl/devenv/ATLTest.sln +++ b/modules/rostests/apitests/atl/devenv/ATLTest.sln @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSimpleMap", "CSimpleMap.vc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CString", "CString.vcxproj", "{FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CComObject", "CComObject.vcxproj", "{408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -51,6 +53,14 @@ Global {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x64.Build.0 = Release|x64 {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x86.ActiveCfg = Release|Win32 {FBA6DAE7-7996-4DE1-BD03-9E44F7DB4ABD}.Release|x86.Build.0 = Release|Win32 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x64.ActiveCfg = Debug|x64 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x64.Build.0 = Debug|x64 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x86.ActiveCfg = Debug|Win32 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Debug|x86.Build.0 = Debug|Win32 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x64.ActiveCfg = Release|x64 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x64.Build.0 = Release|x64 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.ActiveCfg = Release|Win32 + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/modules/rostests/apitests/atl/devenv/CComObject.vcxproj b/modules/rostests/apitests/atl/devenv/CComObject.vcxproj new file mode 100644 index 00000000000..ac525e52d9d --- /dev/null +++ b/modules/rostests/apitests/atl/devenv/CComObject.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {408AEF87-D169-4A2F-A9E3-FF3DD1D59E65} + 8.1 + AtlProj + + + + Application + true + v120_xp + Unicode + + + Application + false + v120_xp + Unicode + + + Application + true + Unicode + v120_xp + + + Application + false + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + true + + + true + false + + + true + false + + + + NotUsing + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + false + + + + + NotUsing + Level3 + Disabled + _WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Console + true + true + + + + + NotUsing + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Console + true + true + true + true + + + + + MultiThreaded + MultiThreaded + MultiThreadedDebug + MultiThreadedDebug + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + \ No newline at end of file diff --git a/modules/rostests/apitests/atl/devenv/CImage.vcxproj b/modules/rostests/apitests/atl/devenv/CImage.vcxproj index 427a8a371c0..5c77112862d 100644 --- a/modules/rostests/apitests/atl/devenv/CImage.vcxproj +++ b/modules/rostests/apitests/atl/devenv/CImage.vcxproj @@ -98,7 +98,7 @@ Console true - true + false diff --git a/modules/rostests/apitests/atl/testlist.c b/modules/rostests/apitests/atl/testlist.c index f154b0d06c7..0c40c3b140c 100644 --- a/modules/rostests/apitests/atl/testlist.c +++ b/modules/rostests/apitests/atl/testlist.c @@ -4,6 +4,7 @@ extern void func_atltypes(void); extern void func_CComBSTR(void); extern void func_CComHeapPtr(void); +extern void func_CComObject(void); extern void func_CComVariant(void); extern void func_CImage(void); extern void func_CRegKey(void); @@ -16,6 +17,7 @@ const struct test winetest_testlist[] = { "atltypes", func_atltypes }, { "CComBSTR", func_CComBSTR }, { "CComHeapPtr", func_CComHeapPtr }, + { "CComObject", func_CComObject }, { "CComVariant", func_CComVariant }, { "CImage", func_CImage }, { "CRegKey", func_CRegKey },