summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sal/CppunitTest_sal_comtools.mk4
-rw-r--r--sal/qa/systools/test_comtools.cxx44
2 files changed, 30 insertions, 18 deletions
diff --git a/sal/CppunitTest_sal_comtools.mk b/sal/CppunitTest_sal_comtools.mk
index f26f4f8dffa1..1f9c24a0c812 100644
--- a/sal/CppunitTest_sal_comtools.mk
+++ b/sal/CppunitTest_sal_comtools.mk
@@ -17,4 +17,8 @@ $(eval $(call gb_CppunitTest_use_libraries,sal_comtools,\
sal \
))
+$(eval $(call gb_CppunitTest_use_system_win32_libs,sal_comtools,\
+ ole32 \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/sal/qa/systools/test_comtools.cxx b/sal/qa/systools/test_comtools.cxx
index 096851c9e989..e0fc2d3e47e5 100644
--- a/sal/qa/systools/test_comtools.cxx
+++ b/sal/qa/systools/test_comtools.cxx
@@ -20,6 +20,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <systools/win32/comtools.hxx>
+#include <shobjidl.h>
class COMObject : public IUnknown
{
@@ -179,30 +180,36 @@ namespace test_comtools
void test_query_interface()
{
- try
- {
- sal::systools::COMReference<IUnknown> r1 = comObjectSource();
- sal::systools::COMReference<IUnknown> r2 = r1.QueryInterface<IUnknown>(IID_IUnknown);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count, 2 is expected", ULONG(2), reinterpret_cast<COMObject*>(r2.get())->GetRefCount());
- }
- catch(const sal::systools::ComError&)
- {
- CPPUNIT_ASSERT_MESSAGE("Exception should not have been thrown", false);
- }
+ sal::systools::COMReference<IUnknown> r1 = comObjectSource();
+ sal::systools::COMReference<IUnknown> r2;
+ CPPUNIT_ASSERT_NO_THROW_MESSAGE(
+ "Exception should not have been thrown",
+ r2 = r1.QueryInterface<IUnknown>(sal::systools::COM_QUERY_THROW));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count, 2 is expected", ULONG(2),
+ reinterpret_cast<COMObject*>(r2.get())->GetRefCount());
}
void test_query_interface_throw()
{
- try
- {
- sal::systools::COMReference<IUnknown> r1 = comObjectSource();
- sal::systools::COMReference<IPersistFile> r2 = r1.QueryInterface<IPersistFile>(IID_IPersistFile);
- }
- catch(const sal::systools::ComError&)
- {
+ sal::systools::COMReference<IUnknown> r1 = comObjectSource();
+ CPPUNIT_ASSERT_THROW_MESSAGE("Exception should have been thrown",
+ auto r2 = r1.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW),
+ sal::systools::ComError);
+ }
+
+ void test_CoCreateInstance()
+ {
+ if (FAILED(CoInitialize(nullptr)))
return;
+ {
+ // Use scope to destroy the reference before calling CoUninitialize
+ sal::systools::COMReference<IFileOpenDialog> r;
+ CPPUNIT_ASSERT_NO_THROW(r.CoCreateInstance(__uuidof(FileOpenDialog)));
+ // Immediately after CoCreateInstance, refcount must be 1; increasing once gives 2
+ CPPUNIT_ASSERT_EQUAL(ULONG(2), r->AddRef());
+ r->Release();
}
- CPPUNIT_ASSERT_MESSAGE("Exception should have been thrown", false);
+ CoUninitialize();
}
// Change the following lines only, if you add, remove or rename
@@ -223,6 +230,7 @@ namespace test_comtools
CPPUNIT_TEST(test_clear);
CPPUNIT_TEST(test_query_interface);
CPPUNIT_TEST(test_query_interface_throw);
+ CPPUNIT_TEST(test_CoCreateInstance);
CPPUNIT_TEST_SUITE_END();
};