Author: damjan Date: Tue Sep 1 04:57:52 2015 New Revision: 1700387 URL: http://svn.apache.org/r1700387 Log: #i125003# migrate main/sal/qa/rtl/alloc from cppunit to Google Test.
Modified: openoffice/trunk/main/sal/qa/rtl/alloc/makefile.mk openoffice/trunk/main/sal/qa/rtl/alloc/rtl_alloc.cxx Modified: openoffice/trunk/main/sal/qa/rtl/alloc/makefile.mk URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/alloc/makefile.mk?rev=1700387&r1=1700386&r2=1700387&view=diff ============================================================================== --- openoffice/trunk/main/sal/qa/rtl/alloc/makefile.mk (original) +++ openoffice/trunk/main/sal/qa/rtl/alloc/makefile.mk Tue Sep 1 04:57:52 2015 @@ -31,34 +31,29 @@ ENABLE_EXCEPTIONS=TRUE .INCLUDE : settings.mk +.IF "$(ENABLE_UNIT_TESTS)" != "YES" +all: + @echo unit tests are disabled. Nothing to do. + +.ELSE + CFLAGS+= $(LFS_CFLAGS) CXXFLAGS+= $(LFS_CFLAGS) -CFLAGSCXX += $(CPPUNIT_CFLAGS) - # BEGIN ---------------------------------------------------------------- # auto generated Target:jobfile by codegen.pl -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/rtl_alloc.obj -SHL1TARGET= rtl_Alloc -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME =$(SHL1TARGET) -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +APP1TARGET= rtl_Alloc +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled # auto generated Target:jobfile # END ------------------------------------------------------------------ -#------------------------------- All object files ------------------------------- -# do this here, so we get right dependencies -# SLOFILES=$(SHL1OBJS) - # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.INCLUDE : _cppunit.mk +.ENDIF # .IF "$(ENABLE_UNIT_TESTS)" != "YES" \ No newline at end of file Modified: openoffice/trunk/main/sal/qa/rtl/alloc/rtl_alloc.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/alloc/rtl_alloc.cxx?rev=1700387&r1=1700386&r2=1700387&view=diff ============================================================================== --- openoffice/trunk/main/sal/qa/rtl/alloc/rtl_alloc.cxx (original) +++ openoffice/trunk/main/sal/qa/rtl/alloc/rtl_alloc.cxx Tue Sep 1 04:57:52 2015 @@ -27,7 +27,7 @@ // autogenerated file with codegen.pl #include <rtl/alloc.h> -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" namespace rtl_alloc { @@ -48,8 +48,9 @@ namespace rtl_alloc return bOk; } -class Memory : public CppUnit::TestFixture +class Memory : public ::testing::Test { +protected: // for normal alloc functions char *m_pMemory; sal_uInt32 m_nSizeOfMemory; @@ -58,63 +59,45 @@ public: Memory() :m_pMemory(NULL), m_nSizeOfMemory(50 * 1024 * 1024) - { - } + { + } // initialise your test code values here. - void setUp() + void SetUp() { - t_print("allocate memory\n"); + printf("allocate memory\n"); m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory ); } - void tearDown() + void TearDown() { - t_print("free memory\n"); + printf("free memory\n"); rtl_freeMemory(m_pMemory); m_pMemory = NULL; } +}; // class test - // insert your test code here. - void rtl_allocateMemory_001() - { - // this is demonstration code - // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); - - CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL); - memset(m_pMemory, 1, m_nSizeOfMemory); - CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true); - } - - void rtl_reallocateMemory_001() - { - t_print("reallocate memory\n"); - sal_uInt32 nSize = 10 * 1024 * 1024; - m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize); - - CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL); - memset(m_pMemory, 2, nSize); - CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true); - } - - // void rtl_freeMemory_001() - // { - // // CPPUNIT_ASSERT_STUB(); - // } - - // 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. +TEST_F(Memory, rtl_allocateMemory_001) +{ + ASSERT_TRUE(m_pMemory != NULL) << "Can get zero memory."; + memset(m_pMemory, 1, m_nSizeOfMemory); + ASSERT_TRUE(checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true) << "memory contains wrong value."; +} - CPPUNIT_TEST_SUITE(Memory); - CPPUNIT_TEST(rtl_allocateMemory_001); - CPPUNIT_TEST(rtl_reallocateMemory_001); - // CPPUNIT_TEST(rtl_freeMemory_001); - CPPUNIT_TEST_SUITE_END(); -}; // class test +TEST_F(Memory, rtl_reallocateMemory_001) +{ + printf("reallocate memory\n"); + sal_uInt32 nSize = 10 * 1024 * 1024; + m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize); + + ASSERT_TRUE(m_pMemory != NULL) << "Can reallocate memory."; + memset(m_pMemory, 2, nSize); + ASSERT_TRUE(checkMemory(m_pMemory, nSize, 2) == true) << "memory contains wrong value."; +} -class ZeroMemory : public CppUnit::TestFixture +class ZeroMemory : public ::testing::Test { +protected: // for zero functions char *m_pZeroMemory; sal_uInt32 m_nSizeOfZeroMemory; @@ -123,53 +106,39 @@ public: ZeroMemory() :m_pZeroMemory(NULL), m_nSizeOfZeroMemory( 50 * 1024 * 1024 ) - { - } + { + } // initialise your test code values here. - void setUp() - { - t_print("allocate zero memory\n"); - m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory ); - } - - void tearDown() + void SetUp() { - t_print("free zero memory\n"); - rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory); - // LLA: no check possible, may GPF if there is something wrong. - // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL); + printf("allocate zero memory\n"); + m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory ); } - // insert your test code here. - - void rtl_allocateZeroMemory_001() + void TearDown() { - CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != NULL); - CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true); - - memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory); - CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true); + printf("free zero memory\n"); + rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory); + // LLA: no check possible, may GPF if there is something wrong. + // ASSERT_TRUE(pZeroMemory != NULL) << "Can get zero memory."; } - // 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(ZeroMemory); - CPPUNIT_TEST(rtl_allocateZeroMemory_001); - CPPUNIT_TEST_SUITE_END(); }; // class test -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::Memory, "rtl_alloc"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::ZeroMemory, "rtl_alloc"); -} // namespace rtl_alloc - +TEST_F(ZeroMemory, rtl_allocateZeroMemory_001) +{ + ASSERT_TRUE(m_pZeroMemory != NULL) << "Can get zero memory."; + ASSERT_TRUE(checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true) << "memory contains wrong value."; -// ----------------------------------------------------------------------------- + memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory); + ASSERT_TRUE(checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true) << "memory contains wrong value."; +} -// 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; +} // namespace rtl_alloc +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}