From f37e5c0cbd3fd6f2d3e9be00f568a06210c116db Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Wed, 14 Oct 2015 18:02:32 +0000 Subject: #i125003# migrate main/uno/test from cppunit to Google Test. Doesn't link due to missing static libraries (pre-gbuild migration era?) but isn't run during the buid. --- unoxml/test/domtest.cxx | 182 ++++++++++++++++++++---------------------------- unoxml/test/makefile.mk | 43 +++++++----- 2 files changed, 99 insertions(+), 126 deletions(-) (limited to 'unoxml/test') diff --git a/unoxml/test/domtest.cxx b/unoxml/test/domtest.cxx index dcd46684e6fd..52c6b908d5fe 100644 --- a/unoxml/test/domtest.cxx +++ b/unoxml/test/domtest.cxx @@ -23,7 +23,7 @@ // autogenerated file with codegen.pl -#include +#include "gtest/gtest.h" #include #include @@ -38,6 +38,8 @@ #include #include +#include + #include "../source/dom/documentbuilder.hxx" @@ -173,15 +175,13 @@ struct TokenHandler { virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException) { - CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getToken() unexpected call", - false ); + EXPECT_TRUE( false ) << "TokenHandler::getToken() unexpected call"; return -1; } virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException) { - CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getIdentifier() unexpected call", - false ); + EXPECT_TRUE( false ) << "TokenHandler::getIdentifier() unexpected call"; return rtl::OUString(); } @@ -193,13 +193,12 @@ struct TokenHandler virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException) { - CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getUTF8Identifier() unexpected call", - false ); + EXPECT_TRUE( false) << "TokenHandler::getUTF8Identifier() unexpected call"; return uno::Sequence(); } }; -struct BasicTest : public CppUnit::TestFixture +struct BasicTest : public ::testing::Test { rtl::Reference mxDomBuilder; rtl::Reference mxErrHandler; @@ -208,7 +207,7 @@ struct BasicTest : public CppUnit::TestFixture rtl::Reference mxErrorInStream; rtl::Reference mxFatalInStream; - void setUp() + void SetUp() { // luckily, DOM builder doesn't use service fac, so we need // not bootstrap uno here @@ -224,59 +223,45 @@ struct BasicTest : public CppUnit::TestFixture sizeof(fatalTestFile)/sizeof(*fatalTestFile))) ); mxDomBuilder->setErrorHandler(mxErrHandler.get()); } +}; - void validInputTest() - { - CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #1", - mxDomBuilder->parse( - uno::Reference( - mxValidInStream.get())).is() ); - CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors", - mxErrHandler->noErrors() ); - } +TEST_F(BasicTest, validInputTest) +{ + ASSERT_TRUE( mxDomBuilder->parse( + uno::Reference( + mxValidInStream.get())).is() ) << "Valid input file did not result in XDocument #1"; + ASSERT_TRUE( mxErrHandler->noErrors() ) << "Valid input file resulted in parse errors"; +} - void warningInputTest() - { - CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #2", - mxDomBuilder->parse( - uno::Reference( - mxWarningInStream.get())).is() ); - CPPUNIT_ASSERT_MESSAGE( "No parse warnings in unclean input file", - mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount ); - } +TEST_F(BasicTest, warningInputTest) +{ + ASSERT_TRUE( mxDomBuilder->parse( + uno::Reference( + mxWarningInStream.get())).is() ) << "Valid input file did not result in XDocument #2"; + ASSERT_TRUE( mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount ) + << "No parse warnings in unclean input file"; +} - void errorInputTest() - { - CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #3", - mxDomBuilder->parse( - uno::Reference( - mxErrorInStream.get())).is() ); - CPPUNIT_ASSERT_MESSAGE( "No parse errors in unclean input file", - !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount ); - } +TEST_F(BasicTest, errorInputTest) +{ + ASSERT_TRUE( mxDomBuilder->parse( + uno::Reference( + mxErrorInStream.get())).is() ) << "Valid input file did not result in XDocument #3"; + ASSERT_TRUE( !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount ) + << "No parse errors in unclean input file"; +} - void fatalInputTest() - { - CPPUNIT_ASSERT_MESSAGE( "Broken input file resulted in XDocument", - !mxDomBuilder->parse( - uno::Reference( - mxFatalInStream.get())).is() ); - CPPUNIT_ASSERT_MESSAGE( "No fatal parse errors in unclean input file", - !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount ); - }; - - // 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(BasicTest); - CPPUNIT_TEST(validInputTest); - CPPUNIT_TEST(warningInputTest); - CPPUNIT_TEST(errorInputTest); - CPPUNIT_TEST(fatalInputTest); - CPPUNIT_TEST_SUITE_END(); +TEST_F(BasicTest, fatalInputTest) +{ + ASSERT_TRUE( !mxDomBuilder->parse( + uno::Reference( + mxFatalInStream.get())).is() ) << "Broken input file resulted in XDocument"; + ASSERT_TRUE( !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount ) + << "No fatal parse errors in unclean input file"; }; -struct SerializerTest : public CppUnit::TestFixture + +struct SerializerTest : public ::testing::Test { SerializerTest() : mbUnoInitialized(false) {} @@ -289,13 +274,13 @@ struct SerializerTest : public CppUnit::TestFixture uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces; bool mbUnoInitialized; - void setUp() + void SetUp() { // need working typelib, bootstrap UNO now if( !mbUnoInitialized ) { - const char* pArgs( getForwardString() ); - CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs); + const char* pArgs( getenv("UNOXML_DOMTEST_FORWARD") ); + ASSERT_TRUE(pArgs) << "Test file parameter"; const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs); @@ -303,18 +288,17 @@ struct SerializerTest : public CppUnit::TestFixture try { ::rtl::OUString aIniUrl; - CPPUNIT_ASSERT_MESSAGE( - "Converting ini file to URL", + ASSERT_TRUE( osl_getFileURLFromSystemPath( (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData, - &aIniUrl.pData ) == osl_File_E_None ); + &aIniUrl.pData ) == osl_File_E_None ) << "Converting ini file to URL"; mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl); - CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is()); + ASSERT_TRUE(mxCtx.is()) << "Getting component context"; } catch( uno::Exception& ) { - CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false); + ASSERT_TRUE(false) << "Bootstrapping UNO"; } mbUnoInitialized = true; @@ -344,52 +328,36 @@ struct SerializerTest : public CppUnit::TestFixture "http://www.w3.org/1999/xlink") ), 2*xml::sax::FastToken::NAMESPACE); } - - void serializerTest () - { - uno::Reference< xml::dom::XDocument > xDoc= - mxDomBuilder->parse( - uno::Reference( - mxInStream.get())); - CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument", - xDoc.is() ); - CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors", - mxErrHandler->noErrors() ); - - uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer( - xDoc, uno::UNO_QUERY); - CPPUNIT_ASSERT_MESSAGE( "XSAXSerializable not supported", - xSaxSerializer.is() ); - - uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer( - xDoc, uno::UNO_QUERY); - CPPUNIT_ASSERT_MESSAGE( "XFastSAXSerializable not supported", - xSaxSerializer.is() ); - - xFastSaxSerializer->fastSerialize( mxHandler.get(), - mxTokHandler.get(), - uno::Sequence< beans::StringPair >(), - maRegisteredNamespaces ); - } - - // 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(SerializerTest); - CPPUNIT_TEST(serializerTest); - CPPUNIT_TEST_SUITE_END(); }; -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SerializerTest, "SerializerTest"); +TEST_F(SerializerTest, serializerTest) +{ + uno::Reference< xml::dom::XDocument > xDoc= + mxDomBuilder->parse( + uno::Reference( + mxInStream.get())); + ASSERT_TRUE( xDoc.is() ) << "Valid input file did not result in XDocument"; + ASSERT_TRUE( mxErrHandler->noErrors() ) << "Valid input file resulted in parse errors"; + + uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer( + xDoc, uno::UNO_QUERY); + ASSERT_TRUE( xSaxSerializer.is() ) << "XSAXSerializable not supported"; + + uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer( + xDoc, uno::UNO_QUERY); + ASSERT_TRUE( xSaxSerializer.is() ) << "XFastSAXSerializable not supported"; + + xFastSaxSerializer->fastSerialize( mxHandler.get(), + mxTokHandler.get(), + uno::Sequence< beans::StringPair >(), + maRegisteredNamespaces ); } +} -// ----------------------------------------------------------------------------- - -// 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. -NOADDITIONAL; +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unoxml/test/makefile.mk b/unoxml/test/makefile.mk index 9e6e9b8fca76..950ab010eabb 100644 --- a/unoxml/test/makefile.mk +++ b/unoxml/test/makefile.mk @@ -25,7 +25,6 @@ PRJ=.. PRJNAME=unoxml TARGET=tests -TARGETTYPE=GUI ENABLE_EXCEPTIONS=TRUE @@ -33,54 +32,56 @@ ENABLE_EXCEPTIONS=TRUE .INCLUDE : settings.mk -CFLAGSCXX += $(CPPUNIT_CFLAGS) +.IF "$(ENABLE_UNIT_TESTS)" != "YES" +all: + @echo unit tests are disabled. Nothing to do. + +.ELSE # --- Common ---------------------------------------------------------- # BEGIN ---------------------------------------------------------------- # auto generated Target:tests by codegen.pl -SHL1OBJS= \ - $(SLO)$/domtest.obj +APP1OBJS= \ + $(SLO)$/domtest.obj $(SLO)$/documentbuilder.obj # the following three libs are a bit of a hack: cannot link against # unoxml here, because not yet delivered (and does not export # ~anything). Need the functionality to test, so we're linking it in # statically. Need to keep this in sync with # source/services/makefile.mk -SHL1LIBS= \ - $(SLB)$/domimpl.lib \ - $(SLB)$/xpathimpl.lib \ - $(SLB)$/eventsimpl.lib +#APP1LIBS= \ + #$(SLB)$/domimpl.lib \ + #$(SLB)$/xpathimpl.lib \ + #$(SLB)$/eventsimpl.lib -SHL1TARGET= tests -SHL1STDLIBS= \ +APP1TARGET= tests +APP1STDLIBS= \ $(UCBHELPERLIB) \ $(LIBXML2LIB) \ $(TOOLSLIB) \ $(COMPHELPERLIB) \ $(CPPUHELPERLIB) \ - $(CPPUNITLIB) \ + $(GTESTLIB) \ $(TESTSHL2LIB) \ $(CPPULIB) \ $(SAXLIB) \ $(SALLIB)\ - $(EXPATASCII3RDLIB) + $(EXPATASCII3RDLIB) \ + -lunoxml -SHL1IMPLIB= i$(SHL1TARGET) - -DEF1NAME =$(SHL1TARGET) -SHL1VERSIONMAP = export.map +APP1RPATH = NONE +APP1TEST = disabled # END ------------------------------------------------------------------ #------------------------------- All object files ------------------------------- # do this here, so we get right dependencies -SLOFILES=$(SHL1OBJS) +SLOFILES=$(APP1OBJS) # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.INCLUDE : _cppunit.mk # --- Fake uno bootstrap ------------------------ @@ -95,7 +96,11 @@ $(MISC)$/unoxml_unittest_succeeded : $(SHL1TARGETN) $(BIN)$/unoxml_unittest_test @echo ---------------------------------------------------------- @echo - start unit test on library $(SHL1TARGETN) @echo ---------------------------------------------------------- - $(TESTSHL2) -forward $(BIN)$/ -sf $(mktmp ) $(SHL1TARGETN) + $(COMMAND_ECHO) $(AUGMENT_LIBRARY_PATH_LOCAL) \ + UNOXML_DOMTEST_FORWARD=$(BIN)$/ \ + $(APP1TARGETN) --gtest_output="xml:$(BIN)/$(APP1TARGET)_result.xml" $(TOUCH) $@ ALLTAR : $(MISC)$/unoxml_unittest_succeeded + +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" -- cgit