Kaydet (Commit) f2e9a481 authored tarafından Damjan Jovanovic's avatar Damjan Jovanovic

#i125003# migrate main/sal/qa/systools from cppunit to Google Test.

üst eb802549
...@@ -33,6 +33,12 @@ ENABLE_EXCEPTIONS=TRUE ...@@ -33,6 +33,12 @@ ENABLE_EXCEPTIONS=TRUE
.INCLUDE : settings.mk .INCLUDE : settings.mk
.IF "$(ENABLE_UNIT_TESTS)" != "YES"
all:
@echo unit tests are disabled. Nothing to do.
.ELSE
CFLAGS+= $(LFS_CFLAGS) CFLAGS+= $(LFS_CFLAGS)
CXXFLAGS+= $(LFS_CFLAGS) CXXFLAGS+= $(LFS_CFLAGS)
...@@ -40,27 +46,19 @@ CFLAGS+=/Ob0 ...@@ -40,27 +46,19 @@ CFLAGS+=/Ob0
# BEGIN ---------------------------------------------------------------- # BEGIN ----------------------------------------------------------------
# auto generated Target:joblist by codegen.pl # auto generated Target:joblist by codegen.pl
SHL1OBJS= \ APP1OBJS= \
$(SLO)$/test_comtools.obj $(SLO)$/test_comtools.obj
SHL1TARGET= test_comtools APP1TARGET= test_comtools
SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) uuid.lib APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) uuid.lib
APP1RPATH = NONE
SHL1IMPLIB= i$(SHL1TARGET) APP1TEST = enabled
# SHL1DEF= $(MISC)$/$(SHL1TARGET).def
DEF1NAME =$(SHL1TARGET)
# DEF1EXPORTFILE= export.exp
SHL1VERSIONMAP= $(PRJ)$/qa$/export.map
# auto generated Target:joblist # auto generated Target:joblist
# END ------------------------------------------------------------------ # END ------------------------------------------------------------------
#------------------------------- All object files -------------------------------
# do this here, so we get right dependencies
# SLOFILES=$(SHL1OBJS)
# --- Targets ------------------------------------------------------ # --- Targets ------------------------------------------------------
.INCLUDE : target.mk .INCLUDE : target.mk
.INCLUDE : _cppunit.mk
.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "precompiled_sal.hxx" #include "precompiled_sal.hxx"
// autogenerated file with codegen.pl // autogenerated file with codegen.pl
#include <testshl/simpleheader.hxx> #include "gtest/gtest.h"
#include <systools/win32/comtools.hxx> #include <systools/win32/comtools.hxx>
class COMObject : public IUnknown class COMObject : public IUnknown
...@@ -99,148 +99,124 @@ void comObjectSource2(LPVOID* ppv) ...@@ -99,148 +99,124 @@ void comObjectSource2(LPVOID* ppv)
namespace test_comtools namespace test_comtools
{ {
class test_COMReference : public CppUnit::TestFixture class test_COMReference : public ::testing::Test
{ {
};
public: /// test of COMReference<IUnknown> r;
/// test of COMReference<IUnknown> r; TEST_F(test_COMReference, default_ctor)
void default_ctor() {
{ sal::systools::COMReference<IUnknown> r;
sal::systools::COMReference<IUnknown> r; ASSERT_TRUE(r.get() == NULL) << "COMReference should be empty";
CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() == NULL); }
}
void test_ctor_manual_AddRef() TEST_F(test_COMReference, test_ctor_manual_AddRef)
{ {
COMObject* p = new COMObject; COMObject* p = new COMObject;
p->AddRef(); p->AddRef();
sal::systools::COMReference<IUnknown> r(p, false); sal::systools::COMReference<IUnknown> r(p, false);
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
} }
void test_copy_ctor() TEST_F(test_COMReference, test_copy_ctor)
{ {
sal::systools::COMReference<IUnknown> r(comObjectSource()); sal::systools::COMReference<IUnknown> r(comObjectSource());
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
} }
void test_copy_assignment() TEST_F(test_COMReference, test_copy_assignment)
{ {
sal::systools::COMReference<IUnknown> r; sal::systools::COMReference<IUnknown> r;
CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() == NULL); ASSERT_TRUE(r.get() == NULL) << "COMReference should be empty";
r = comObjectSource(); r = comObjectSource();
CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() != NULL); ASSERT_TRUE(r.get() != NULL) << "COMReference should be empty";
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
} }
void test_ref_to_ref_assignment() TEST_F(test_COMReference, test_ref_to_ref_assignment)
{ {
sal::systools::COMReference<IUnknown> r1 = comObjectSource(); sal::systools::COMReference<IUnknown> r1 = comObjectSource();
sal::systools::COMReference<IUnknown> r2 = r1; sal::systools::COMReference<IUnknown> r2 = r1;
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2); ASSERT_TRUE(reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2) << "Wrong reference count 2 is expected";
} }
void test_pointer_to_ref_assignment() TEST_F(test_COMReference, test_pointer_to_ref_assignment)
{ {
sal::systools::COMReference<IUnknown> r; sal::systools::COMReference<IUnknown> r;
r = new COMObject; r = new COMObject;
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
} }
void test_pointer_to_ref_assignment2() TEST_F(test_COMReference, test_pointer_to_ref_assignment2)
{ {
sal::systools::COMReference<IUnknown> r = comObjectSource(); sal::systools::COMReference<IUnknown> r = comObjectSource();
r = new COMObject; r = new COMObject;
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
} }
void test_source_sink() TEST_F(test_COMReference, test_source_sink)
{ {
CPPUNIT_ASSERT_MESSAGE("Wrong reference count, 0 is expected", comObjectSink(comObjectSource(), 0)); ASSERT_TRUE(comObjectSink(comObjectSource(), 0)) << "Wrong reference count, 0 is expected";
} }
void test_address_operator() TEST_F(test_COMReference, test_address_operator)
{ {
sal::systools::COMReference<IUnknown> r; sal::systools::COMReference<IUnknown> r;
comObjectSource2(reinterpret_cast<LPVOID*>(&r)); comObjectSource2(reinterpret_cast<LPVOID*>(&r));
CPPUNIT_ASSERT_MESSAGE("Wrong reference count, 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count, 1 is expected";
} }
TEST_F(test_COMReference, test_address_operator2)
{
sal::systools::COMReference<IUnknown> r1 = comObjectSource();
sal::systools::COMReference<IUnknown> r2 = r1;
ASSERT_TRUE(reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2) << "Wrong reference count 2 is expected";
comObjectSource2(reinterpret_cast<LPVOID*>(&r1));
ASSERT_TRUE(reinterpret_cast<COMObject*>(r1.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
ASSERT_TRUE(reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
}
TEST_F(test_COMReference, test_clear)
{
sal::systools::COMReference<IUnknown> r = comObjectSource();
ASSERT_TRUE(reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1) << "Wrong reference count 1 is expected";
r.clear();
ASSERT_TRUE(!r.is()) << "Expect reference to be empty";
}
void test_address_operator2() TEST_F(test_COMReference, test_query_interface)
{
try
{ {
sal::systools::COMReference<IUnknown> r1 = comObjectSource(); sal::systools::COMReference<IUnknown> r1 = comObjectSource();
sal::systools::COMReference<IUnknown> r2 = r1; sal::systools::COMReference<IUnknown> r2 = r1.QueryInterface<IUnknown>(IID_IUnknown);
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2); ASSERT_TRUE(reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2) << "Wrong reference count, 2 is expected";
comObjectSource2(reinterpret_cast<LPVOID*>(&r1));
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r1.get())->GetRefCount() == 1);
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 1);
} }
catch(sal::systools::ComError& ex)
void test_clear()
{ {
sal::systools::COMReference<IUnknown> r = comObjectSource(); ASSERT_TRUE(false) << "Exception should not have been thrown";
CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1);
r.clear();
CPPUNIT_ASSERT_MESSAGE("Expect reference to be empty", !r.is());
} }
}
void test_query_interface() TEST_F(test_COMReference, test_query_interface_throw)
{
try
{ {
try sal::systools::COMReference<IUnknown> r1 = comObjectSource();
{ sal::systools::COMReference<IPersistFile> r2 = r1.QueryInterface<IPersistFile>(IID_IPersistFile);
sal::systools::COMReference<IUnknown> r1 = comObjectSource();
sal::systools::COMReference<IUnknown> r2 = r1.QueryInterface<IUnknown>(IID_IUnknown);
CPPUNIT_ASSERT_MESSAGE("Wrong reference count, 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2);
}
catch(sal::systools::ComError& ex)
{
CPPUNIT_ASSERT_MESSAGE("Exception should not have been thrown", false);
}
} }
catch(sal::systools::ComError& ex)
void test_query_interface_throw()
{ {
try return;
{
sal::systools::COMReference<IUnknown> r1 = comObjectSource();
sal::systools::COMReference<IPersistFile> r2 = r1.QueryInterface<IPersistFile>(IID_IPersistFile);
}
catch(sal::systools::ComError& ex)
{
return;
}
CPPUNIT_ASSERT_MESSAGE("Exception should have been thrown", false);
} }
ASSERT_TRUE(false) << "Exception should have been thrown";
// Change the following lines only, if you add, remove or rename }
// member functions of the current class,
// because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(test_COMReference);
CPPUNIT_TEST(default_ctor);
CPPUNIT_TEST(test_ctor_manual_AddRef);
CPPUNIT_TEST(test_copy_ctor);
CPPUNIT_TEST(test_copy_assignment);
CPPUNIT_TEST(test_ref_to_ref_assignment);
CPPUNIT_TEST(test_pointer_to_ref_assignment);
CPPUNIT_TEST(test_pointer_to_ref_assignment2);
CPPUNIT_TEST(test_source_sink);
CPPUNIT_TEST(test_address_operator);
CPPUNIT_TEST(test_address_operator2);
CPPUNIT_TEST(test_clear);
CPPUNIT_TEST(test_query_interface);
CPPUNIT_TEST(test_query_interface_throw);
CPPUNIT_TEST_SUITE_END();
};
// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_comtools::test_COMReference, "test_comtools");
} // namespace rtl_OUString } // namespace rtl_OUString
int main(int argc, char **argv)
// this macro creates an empty function, which will called by the RegisterAllFunctions() {
// to let the user the possibility to also register some functions by hand. ::testing::InitGoogleTest(&argc, argv);
NOADDITIONAL; return RUN_ALL_TESTS();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment