Author: damjan Date: Tue Sep 1 05:33:02 2015 New Revision: 1700390 URL: http://svn.apache.org/r1700390 Log: #i125003# migrate main/sal/qa/rtl/crc32 from cppunit to Google Test.
Modified: openoffice/trunk/main/sal/qa/rtl/crc32/makefile.mk openoffice/trunk/main/sal/qa/rtl/crc32/rtl_crc32.cxx Modified: openoffice/trunk/main/sal/qa/rtl/crc32/makefile.mk URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/crc32/makefile.mk?rev=1700390&r1=1700389&r2=1700390&view=diff ============================================================================== --- openoffice/trunk/main/sal/qa/rtl/crc32/makefile.mk (original) +++ openoffice/trunk/main/sal/qa/rtl/crc32/makefile.mk Tue Sep 1 05:33:02 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_crc32.obj -SHL1TARGET= rtl_crc32 -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME =$(SHL1TARGET) -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +APP1TARGET= rtl_crc32 +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 # "$(ENABLE_UNIT_TESTS)" != "YES" Modified: openoffice/trunk/main/sal/qa/rtl/crc32/rtl_crc32.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/crc32/rtl_crc32.cxx?rev=1700390&r1=1700389&r2=1700390&view=diff ============================================================================== --- openoffice/trunk/main/sal/qa/rtl/crc32/rtl_crc32.cxx (original) +++ openoffice/trunk/main/sal/qa/rtl/crc32/rtl_crc32.cxx Tue Sep 1 05:33:02 2015 @@ -26,152 +26,129 @@ #include "precompiled_sal.hxx" // autogenerated file with codegen.pl -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" #include <rtl/crc.h> namespace rtl_CRC32 { -class test : public CppUnit::TestFixture +class test : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } +}; // class test +TEST_F(test, rtl_crc32_001) +{ + sal_uInt32 nCRC = 0; - // insert your test code here. - void rtl_crc32_001() - { - // this is demonstration code - // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); - - sal_uInt32 nCRC = 0; - - char buf[] = {0}; - int num = 0; - - nCRC = rtl_crc32(nCRC, buf, num); - - CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0); - } - - void rtl_crc32_002() - { - sal_uInt32 nCRC = 0; + char buf[] = {0}; + int num = 0; - char buf[] = {0,0}; - int num = sizeof(buf); + nCRC = rtl_crc32(nCRC, buf, num); - nCRC = rtl_crc32(nCRC, buf, num); + ASSERT_TRUE(nCRC == 0) << "empty crc buffer"; +} - CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0); - } +TEST_F(test, rtl_crc32_002) +{ + sal_uInt32 nCRC = 0; - void rtl_crc32_002_1() - { - sal_uInt32 nCRC = 0; + char buf[] = {0,0}; + int num = sizeof(buf); - char buf[] = {0,0,0}; - int num = sizeof(buf); + nCRC = rtl_crc32(nCRC, buf, num); - nCRC = rtl_crc32(nCRC, buf, num); + ASSERT_TRUE(nCRC != 0) << "buffer contain 2 empty bytes, crc is zero"; +} - CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0); - } +TEST_F(test, rtl_crc32_002_1) +{ + sal_uInt32 nCRC = 0; - /** - * crc32 check: - * Build checksum on two buffers with same size but different content, - * the result (crc32 checksum) must differ - */ + char buf[] = {0,0,0}; + int num = sizeof(buf); - void rtl_crc32_003() - { - sal_uInt32 nCRC1 = 0; - char buf1[] = {2}; - int num1 = sizeof(buf1); + nCRC = rtl_crc32(nCRC, buf, num); - nCRC1 = rtl_crc32(nCRC1, buf1, num1); + ASSERT_TRUE(nCRC != 0) << "buffer contain 3 empty bytes, crc is zero"; +} - sal_uInt32 nCRC2 = 0; - char buf2[] = {3}; - int num2 = sizeof(buf2); +/** + * crc32 check: + * Build checksum on two buffers with same size but different content, + * the result (crc32 checksum) must differ + */ - nCRC2 = rtl_crc32(nCRC2, buf2, num2); +TEST_F(test, rtl_crc32_003) +{ + sal_uInt32 nCRC1 = 0; + char buf1[] = {2}; + int num1 = sizeof(buf1); - CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2); - } + nCRC1 = rtl_crc32(nCRC1, buf1, num1); - /** check if the crc32 only use as much values, as given - * - */ - void rtl_crc32_003_1() - { - sal_uInt32 nCRC1 = 0; - char buf1[] = {2,1}; - int num1 = sizeof(buf1) - 1; + sal_uInt32 nCRC2 = 0; + char buf2[] = {3}; + int num2 = sizeof(buf2); - nCRC1 = rtl_crc32(nCRC1, buf1, num1); + nCRC2 = rtl_crc32(nCRC2, buf2, num2); - sal_uInt32 nCRC2 = 0; - char buf2[] = {2,2}; - int num2 = sizeof(buf2) - 1; + ASSERT_TRUE(nCRC1 != nCRC2) << "checksum should differ for buf1 and buf2"; +} - nCRC2 = rtl_crc32(nCRC2, buf2, num2); +/** check if the crc32 only use as much values, as given + * + */ +TEST_F(test, rtl_crc32_003_1) +{ + sal_uInt32 nCRC1 = 0; + char buf1[] = {2,1}; + int num1 = sizeof(buf1) - 1; - CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2); - } + nCRC1 = rtl_crc32(nCRC1, buf1, num1); - /** check if the crc32 differ at same content in reverse order - * - */ - void rtl_crc32_003_2() - { - sal_uInt32 nCRC1 = 0; - char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; - int num1 = sizeof(buf1); + sal_uInt32 nCRC2 = 0; + char buf2[] = {2,2}; + int num2 = sizeof(buf2) - 1; - nCRC1 = rtl_crc32(nCRC1, buf1, num1); + nCRC2 = rtl_crc32(nCRC2, buf2, num2); - sal_uInt32 nCRC2 = 0; - char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0}; - int num2 = sizeof(buf2); + ASSERT_TRUE(nCRC1 == nCRC2) << "checksum leave it's bounds"; +} - nCRC2 = rtl_crc32(nCRC2, buf2, num2); +/** check if the crc32 differ at same content in reverse order + * + */ +TEST_F(test, rtl_crc32_003_2) +{ + sal_uInt32 nCRC1 = 0; + char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + int num1 = sizeof(buf1); - CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2); - } + nCRC1 = rtl_crc32(nCRC1, buf1, num1); + sal_uInt32 nCRC2 = 0; + char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0}; + int num2 = sizeof(buf2); + nCRC2 = rtl_crc32(nCRC2, buf2, num2); - // 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); - CPPUNIT_TEST(rtl_crc32_001); - CPPUNIT_TEST(rtl_crc32_002); - CPPUNIT_TEST(rtl_crc32_002_1); - CPPUNIT_TEST(rtl_crc32_003); - CPPUNIT_TEST(rtl_crc32_003_1); - CPPUNIT_TEST(rtl_crc32_003_2); - CPPUNIT_TEST_SUITE_END(); -}; // class test + ASSERT_TRUE(nCRC1 != nCRC2) << "checksum should differ"; +} // ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_CRC32::test, "rtl_crc32"); } // namespace rtl_CRC32 - -// ----------------------------------------------------------------------------- - -// 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(); +}