sal/qa/rtl/locale/makefile.mk | 29 - sal/qa/rtl/locale/rtl_locale.cxx | 336 ++++++++-------------- sal/qa/rtl/logfile/makefile.mk | 27 - sal/qa/rtl/logfile/rtl_logfile.cxx | 160 ++++------ sal/qa/rtl/oustringbuffer/makefile.mk | 29 - sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx | 80 ++--- 6 files changed, 278 insertions(+), 383 deletions(-)
New commits: commit 567a559e5d06863de27851c3704d1adc0993c685 Author: Damjan Jovanovic <dam...@apache.org> Date: Tue Sep 1 18:43:09 2015 +0000 #i125003# migrate main/sal/qa/rtl/oustringbuffer from cppunit to Google Test. diff --git a/sal/qa/rtl/oustringbuffer/makefile.mk b/sal/qa/rtl/oustringbuffer/makefile.mk index e164aec..b419ff4 100644 --- a/sal/qa/rtl/oustringbuffer/makefile.mk +++ b/sal/qa/rtl/oustringbuffer/makefile.mk @@ -33,34 +33,31 @@ 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:joblist by codegen.pl -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/rtl_OUStringBuffer2.obj -SHL1TARGET= rtl_OUStringBuffer2 -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def +APP1TARGET= rtl_OUStringBuffer2 +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled -DEF1NAME =$(SHL1TARGET) -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP= $(PRJ)$/qa$/export.map # auto generated Target:joblist # 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" diff --git a/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx b/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx index 93fb31c..8af4b60 100644 --- a/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx +++ b/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx @@ -24,7 +24,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" #include "stringhelper.hxx" #include <rtl/ustrbuf.hxx> #include <rtl/uri.hxx> @@ -33,65 +33,59 @@ namespace rtl_OUStringBuffer { -class insertUtf32 : public CppUnit::TestFixture +class insertUtf32 : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } +}; // class getToken - void insertUtf32_001() - { - ::rtl::OUStringBuffer aUStrBuf(4); - aUStrBuf.insertUtf32(0,0x10ffff); - - rtl::OUString suStr = aUStrBuf.makeStringAndClear(); - rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); +// ----------------------------------------------------------------------------- - rtl::OString sStr; - sStr <<= suStr2; - t_print("%s\n", sStr.getStr()); +TEST_F(insertUtf32, insertUtf32_001) +{ + ::rtl::OUStringBuffer aUStrBuf(4); + aUStrBuf.insertUtf32(0,0x10ffff); - CPPUNIT_ASSERT_MESSAGE("Strings must be '%F4%8F%BF%BF'", sStr.equals(rtl::OString("%F4%8F%BF%BF")) == sal_True); - } + rtl::OUString suStr = aUStrBuf.makeStringAndClear(); + rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); - void insertUtf32_002() - { - ::rtl::OUStringBuffer aUStrBuf(4); - aUStrBuf.insertUtf32(0,0x41); - aUStrBuf.insertUtf32(1,0x42); - aUStrBuf.insertUtf32(2,0x43); + rtl::OString sStr; + sStr <<= suStr2; + printf("%s\n", sStr.getStr()); - rtl::OUString suStr = aUStrBuf.makeStringAndClear(); - rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + ASSERT_TRUE(sStr.equals(rtl::OString("%F4%8F%BF%BF")) == sal_True) + << "Strings must be '%F4%8F%BF%BF'"; +} - rtl::OString sStr; - sStr <<= suStr2; - t_print("%s\n", sStr.getStr()); +TEST_F(insertUtf32, insertUtf32_002) +{ + ::rtl::OUStringBuffer aUStrBuf(4); + aUStrBuf.insertUtf32(0,0x41); + aUStrBuf.insertUtf32(1,0x42); + aUStrBuf.insertUtf32(2,0x43); - CPPUNIT_ASSERT_MESSAGE("Strings must be 'ABC'", sStr.equals(rtl::OString("ABC")) == sal_True); - } + rtl::OUString suStr = aUStrBuf.makeStringAndClear(); + rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); - CPPUNIT_TEST_SUITE(insertUtf32); - CPPUNIT_TEST(insertUtf32_001); - CPPUNIT_TEST(insertUtf32_002); - CPPUNIT_TEST_SUITE_END(); -}; // class getToken + rtl::OString sStr; + sStr <<= suStr2; + printf("%s\n", sStr.getStr()); -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUStringBuffer::insertUtf32, "rtl_OUStringBuffer"); + ASSERT_TRUE(sStr.equals(rtl::OString("ABC")) == sal_True) + << "Strings must be 'ABC'"; +} } // namespace rtl_OUStringBuffer - -// ----------------------------------------------------------------------------- - -// 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(); +} commit 5dfdde409d856a6cc0e6144792c47be1db169157 Author: Damjan Jovanovic <dam...@apache.org> Date: Tue Sep 1 18:40:50 2015 +0000 #i125003# migrate main/sal/qa/rtl/locale from cppunit to Google Test. diff --git a/sal/qa/rtl/locale/makefile.mk b/sal/qa/rtl/locale/makefile.mk index 1d916ac..8f549d6 100644 --- a/sal/qa/rtl/locale/makefile.mk +++ b/sal/qa/rtl/locale/makefile.mk @@ -31,35 +31,32 @@ 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:locale by codegen.pl -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/rtl_locale.obj -SHL1TARGET= rtl_locale -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def +APP1TARGET= rtl_locale +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled -DEF1NAME =$(SHL1TARGET) -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP= $(PRJ)$/qa$/export.map # auto generated Target:locale # 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" diff --git a/sal/qa/rtl/locale/rtl_locale.cxx b/sal/qa/rtl/locale/rtl_locale.cxx index e42fb1a..73130d9 100644 --- a/sal/qa/rtl/locale/rtl_locale.cxx +++ b/sal/qa/rtl/locale/rtl_locale.cxx @@ -26,7 +26,7 @@ #include "precompiled_sal.hxx" // autogenerated file with codegen.pl -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" #include <rtl/locale.hxx> #include <osl/thread.h> @@ -38,302 +38,222 @@ namespace rtl_locale rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), /* rtl::OUString() */ rtl::OUString::createFromAscii("hochdeutsch") ); } -class getDefault : public CppUnit::TestFixture +class getDefault : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } +}; // class getDefault - // insert your test code here. - void getDefault_000() - { - // this is demonstration code - // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); - - // due to the fact, we set the default locale at first, this test is no longer possible - // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL); - - } - - void getDefault_001() - { - // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString()); - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); - } - - // 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(getDefault, getDefault_000) +{ + // this is demonstration code + // ASSERT_TRUE(1 == 1) << "a message"; - CPPUNIT_TEST_SUITE(getDefault); - CPPUNIT_TEST(getDefault_000); - CPPUNIT_TEST(getDefault_001); - CPPUNIT_TEST_SUITE_END(); -}; // class getDefault + // due to the fact, we set the default locale at first, this test is no longer possible + // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + // ASSERT_TRUE(aLocale.getData() == NULL) << "locale must be null"; +} +TEST_F(getDefault, getDefault_001) +{ + // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString()); + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + ASSERT_TRUE(aLocale.getData() != NULL) << "locale must not be null"; +} -class setDefault : public CppUnit::TestFixture +class setDefault : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { setDefaultLocale(); } +}; // class setDefault - // insert your test code here. - void setDefault_001() - { - rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); - - // be sure to not GPF - } - - // 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(setDefault, setDefault_001) +{ + rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + ASSERT_TRUE(aLocale.getData() != NULL) << "locale must not null"; - CPPUNIT_TEST_SUITE(setDefault); - CPPUNIT_TEST(setDefault_001); - CPPUNIT_TEST_SUITE_END(); -}; // class setDefault + // be sure to not GPF +} -class getLanguage : public CppUnit::TestFixture +class getLanguage : public ::testing::Test { public: - // initialise your test code values here. - void setUp() - { - } - - void tearDown() + void SetUp() { } - // insert your test code here. - void getLanguage_001() - { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suLanguage = aLocale.getLanguage(); - t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de"))); - } - void getLanguage_002() + void TearDown() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData()); - t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de"))); } +}; // class getLanguage - // 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(getLanguage, getLanguage_001) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suLanguage = aLocale.getLanguage(); + printf("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suLanguage.equals(rtl::OUString::createFromAscii("de"))) << "locale language must be 'de'"; +} - CPPUNIT_TEST_SUITE(getLanguage); - CPPUNIT_TEST(getLanguage_001); - CPPUNIT_TEST(getLanguage_002); - CPPUNIT_TEST_SUITE_END(); -}; // class getLanguage +TEST_F(getLanguage, getLanguage_002) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData()); + printf("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suLanguage.equals(rtl::OUString::createFromAscii("de"))) << "locale language must be 'de'"; +} -class getCountry : public CppUnit::TestFixture +class getCountry : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() - { - } - - // insert your test code here. - void getCountry_001() - { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suCountry = aLocale.getCountry(); - t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE"))); - } - void getCountry_002() + void TearDown() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData()); - t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE"))); } - - // 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(getCountry); - CPPUNIT_TEST(getCountry_001); - CPPUNIT_TEST(getCountry_002); - CPPUNIT_TEST_SUITE_END(); }; // class getCountry +TEST_F(getCountry, getCountry_001) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suCountry = aLocale.getCountry(); + printf("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suCountry.equals(rtl::OUString::createFromAscii("DE"))) << "locale country must be 'DE'"; +} -class getVariant : public CppUnit::TestFixture +TEST_F(getCountry, getCountry_002) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData()); + printf("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suCountry.equals(rtl::OUString::createFromAscii("DE"))) << "locale country must be 'DE'"; +} + +class getVariant : public ::testing::Test { public: // initialise your test code values here. - void setUp() - { - } - - void tearDown() + void SetUp() { } - // insert your test code here. - void getVariant_001() + void TearDown() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suVariant = aLocale.getVariant(); - t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))); } - void getVariant_002() - { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData()); - t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); - CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))); - } - - // 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(getVariant); - CPPUNIT_TEST(getVariant_001); - CPPUNIT_TEST(getVariant_002); - CPPUNIT_TEST_SUITE_END(); }; // class getVariant +TEST_F(getVariant, getVariant_001) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suVariant = aLocale.getVariant(); + printf("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))) << "locale variant must be 'hochdeutsch'"; +} -class hashCode : public CppUnit::TestFixture +TEST_F(getVariant, getVariant_002) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData()); + printf("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); + ASSERT_TRUE(suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))) << "locale variant must be 'hochdeutsch'"; +} + +class hashCode : public ::testing::Test { public: // initialise your test code values here. - void setUp() - { - } - - void tearDown() + void SetUp() { } - // insert your test code here. - void hashCode_001() + void TearDown() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - sal_Int32 nHashCode = aLocale.hashCode(); - t_print("Hashcode: %d\n", nHashCode); - CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); } - void hashCode_002() - { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData()); - t_print("Hashcode: %d\n", nHashCode); - CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); - } - - // 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(hashCode); - CPPUNIT_TEST(hashCode_001); - CPPUNIT_TEST(hashCode_002); - CPPUNIT_TEST_SUITE_END(); }; // class hashCode +TEST_F(hashCode, hashCode_001) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + sal_Int32 nHashCode = aLocale.hashCode(); + printf("Hashcode: %d\n", nHashCode); + ASSERT_TRUE(nHashCode != 0) << "locale hashcode must be 3831"; +} + +TEST_F(hashCode, hashCode_002) +{ + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData()); + printf("Hashcode: %d\n", nHashCode); + ASSERT_TRUE(nHashCode != 0) << "locale hashcode must be 3831"; +} -class equals : public CppUnit::TestFixture +class equals : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } +}; // class equals - // insert your test code here. - void equals_001() - { - rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); - rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); - - sal_Bool bLocaleAreEqual = sal_False; - bLocaleAreEqual = (aLocale1 == aLocale2); - - CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True); - } +TEST_F(equals, equals_001) +{ + rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); - void equals_002() - { - rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); - rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); + sal_Bool bLocaleAreEqual = sal_False; + bLocaleAreEqual = (aLocale1 == aLocale2); - sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData()); - t_print("rtl_locale_equals() result: %d\n", nEqual); - CPPUNIT_ASSERT(nEqual != 0); - } + ASSERT_TRUE(bLocaleAreEqual == sal_True) << "check operator ==()"; +} - // 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(equals, equals_002) +{ + rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); - CPPUNIT_TEST_SUITE(equals); - CPPUNIT_TEST(equals_001); - CPPUNIT_TEST(equals_002); - CPPUNIT_TEST_SUITE_END(); -}; // class equals + sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData()); + printf("rtl_locale_equals() result: %d\n", nEqual); + ASSERT_TRUE(nEqual != 0); +} -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getDefault, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::setDefault, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getLanguage, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getCountry, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getVariant, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::hashCode, "rtl_locale"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::equals, "rtl_locale"); } // namespace rtl_locale // ----------------------------------------------------------------------------- -// 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; - -void RegisterAdditionalFunctions(FktRegFuncPtr) +int main(int argc, char **argv) { // start message - t_print("Initializing ...\n" ); + printf("Initializing ...\n" ); rtl_locale::setDefaultLocale(); - t_print("Initialization Done.\n" ); + printf("Initialization Done.\n" ); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } commit 89784e374749716aa717a9c45992981cdbab4eaf Author: Damjan Jovanovic <dam...@apache.org> Date: Tue Sep 1 18:38:35 2015 +0000 #i125003# migrate main/sal/qa/rtl/logfile from cppunit to Google Test. Also fix a test that was failing on non-Solaris non-Windows non-Linux OSes. diff --git a/sal/qa/rtl/logfile/makefile.mk b/sal/qa/rtl/logfile/makefile.mk index 843e414..cdda3ba 100644 --- a/sal/qa/rtl/logfile/makefile.mk +++ b/sal/qa/rtl/logfile/makefile.mk @@ -32,28 +32,27 @@ 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 -------------------------------------------------------- -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/rtl_logfile.obj -SHL1TARGET= rtl_logfile -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) -DEF1NAME =$(SHL1TARGET) -SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +APP1TARGET= rtl_logfile +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled # 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" diff --git a/sal/qa/rtl/logfile/rtl_logfile.cxx b/sal/qa/rtl/logfile/rtl_logfile.cxx index 3999d68..4ef2b66 100644 --- a/sal/qa/rtl/logfile/rtl_logfile.cxx +++ b/sal/qa/rtl/logfile/rtl_logfile.cxx @@ -39,7 +39,7 @@ #endif #include <rtl/logfile.hxx> -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" // #ifndef _OSL_MODULE_HXX_ // #include <osl/module.hxx> @@ -61,11 +61,11 @@ inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" if (strlen(msg) > 0) { - t_print("%s: ", msg ); + printf("%s: ", msg ); } rtl::OString aString; aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); - t_print("%s\n", (char *)aString.getStr( ) ); + printf("%s\n", (char *)aString.getStr( ) ); } /** get the absolute source file URL "file:///.../sal/qa/rtl/logfile/" @@ -119,105 +119,94 @@ inline ::rtl::OUString getCurrentPID( ) */ namespace rtl_logfile { - class logfile : public CppUnit::TestFixture + class logfile : public ::testing::Test { - public: + }; - //directly call rtl_logfile_trace - void logfile_001() - { + //directly call rtl_logfile_trace + TEST_F(logfile, logfile_001) + { #ifdef SOLARIS - putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1")); -#endif -#ifdef WNT - putenv("RTL_LOGFILE=c:\\temp\\logfile1"); -#endif -#ifdef LINUX - setenv("RTL_LOGFILE", "/tmp/logfile1", 0); + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1")); +#elif WNT + putenv("RTL_LOGFILE=c:\\temp\\logfile1"); +#else + setenv("RTL_LOGFILE", "/tmp/logfile1", 0); #endif - rtl_logfile_trace("trace %d\n", 2 ); - rtl_logfile_trace("trace %d %d\n" , 1,2 ); - rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 ); - - rtl::OUString suFilePath = getTempPath(); - suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); - suFilePath += rtl::OUString::createFromAscii(".log"); - - ::osl::FileBase::RC nError1; - ::osl::File aTestFile( suFilePath ); - printUString( suFilePath ); - nError1 = aTestFile.open ( OpenFlag_Read ); - CPPUNIT_ASSERT_MESSAGE("create the log file: but the logfile does not exist", - ( ::osl::FileBase::E_NOENT != nError1 ) && - ( ::osl::FileBase::E_ACCES != nError1 ) ); - sal_Char buffer_read[400]; - sal_uInt64 nCount_read; - nError1 = aTestFile.read( buffer_read, 400, nCount_read ); - //t_print("buffer is %s\n", buffer_read ); - CPPUNIT_ASSERT_MESSAGE("write right logs", strstr( buffer_read, "trace 1 2 3") != NULL ); - aTestFile.sync(); - aTestFile.close(); - /*// delete logfile on the disk + rtl_logfile_trace("trace %d\n", 2 ); + rtl_logfile_trace("trace %d %d\n" , 1,2 ); + rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 ); + for (int i = 0; i < 1024; i++) + rtl_logfile_trace("rubbish to flush the log\n"); + + rtl::OUString suFilePath = getTempPath(); + suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); + suFilePath += rtl::OUString::createFromAscii(".log"); + + ::osl::FileBase::RC nError1; + ::osl::File aTestFile( suFilePath ); + printUString( suFilePath ); + nError1 = aTestFile.open ( OpenFlag_Read ); + ASSERT_TRUE(( ::osl::FileBase::E_NOENT != nError1 ) && + ( ::osl::FileBase::E_ACCES != nError1 ) ) << "create the log file: but the logfile does not exist"; + sal_Char buffer_read[400]; + sal_uInt64 nCount_read; + nError1 = aTestFile.read( buffer_read, 400, nCount_read ); + //print("buffer is %s\n", buffer_read ); + ASSERT_TRUE( strstr( buffer_read, "trace 1 2 3") != NULL ) << "write right logs"; + aTestFile.sync(); + aTestFile.close(); + /*// delete logfile on the disk + + nError1 = osl::File::remove( suFilePath ); + printError( nError1 ); + CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) ); + */ + } - nError1 = osl::File::remove( suFilePath ); - printError( nError1 ); - CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) ); - */ - } - //Profiling output should only be generated for a special product version of OpenOffice - // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, the symbol not defined - void logfile_002() - { + //Profiling output should only be generated for a special product version of OpenOffice + // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, the symbol not defined + TEST_F(logfile, logfile_002) + { #ifdef SOLARIS - putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); #endif #ifdef WNT - putenv("RTL_LOGFILE=c:\\temp\\logfile2"); + putenv("RTL_LOGFILE=c:\\temp\\logfile2"); #endif #ifdef LINUX - setenv("RTL_LOGFILE", "/tmp/logfile2", 0); + setenv("RTL_LOGFILE", "/tmp/logfile2", 0); #endif - RTL_LOGFILE_TRACE( "trace the log" ); - RTL_LOGFILE_TRACE1( "trace %d" , 1 ); - RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 ); - RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 ); + RTL_LOGFILE_TRACE( "trace the log" ); + RTL_LOGFILE_TRACE1( "trace %d" , 1 ); + RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 ); + RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 ); // TODO: assertion test! - } + } - void logfile_003() - { + TEST_F(logfile, logfile_003) + { #ifdef SOLARIS - putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); #endif #ifdef WNT - putenv("RTL_LOGFILE=c:\\temp\\logfile2"); + putenv("RTL_LOGFILE=c:\\temp\\logfile2"); #endif #ifdef LINUX - setenv("RTL_LOGFILE", "/tmp/logfile2", 0); + setenv("RTL_LOGFILE", "/tmp/logfile2", 0); #endif - RTL_LOGFILE_CONTEXT ( foo , "foo-function" ); - RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" ); - RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 ); - RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 ); - RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3); + RTL_LOGFILE_CONTEXT ( foo , "foo-function" ); + RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" ); + RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 ); + RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 ); + RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3); // TODO: assertion test! - } - - - CPPUNIT_TEST_SUITE( logfile ); - CPPUNIT_TEST( logfile_001 ); - CPPUNIT_TEST( logfile_002 ); - CPPUNIT_TEST( logfile_003 ); - CPPUNIT_TEST_SUITE_END( ); - }; + } } // namespace rtl_logfile -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_logfile::logfile, "rtl_logfile" ); // ----------------------------------------------------------------------------- -NOADDITIONAL; //~ do some clean up work after all test completed. class GlobalObject @@ -227,7 +216,7 @@ public: { try { - t_print( "\n#Do some clean-ups ... only delete logfile1_*.log here!\n" ); + printf( "\n#Do some clean-ups ... only delete logfile1_*.log here!\n" ); rtl::OUString suFilePath = getTempPath(); suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); suFilePath += rtl::OUString::createFromAscii(".log"); @@ -236,21 +225,20 @@ public: ::osl::FileBase::RC nError1; nError1 = osl::File::remove( suFilePath ); #ifdef WNT - t_print("Please remove logfile* manully! Error is Permision denied!"); + printf("Please remove logfile* manully! Error is Permision denied!"); #endif } - catch (CppUnit::Exception &e) - { - t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber()); - } catch (...) { - t_print("Exception caught (...) in GlobalObject dtor()\n"); + printf("Exception caught (...) in GlobalObject dtor()\n"); } } }; GlobalObject theGlobalObject; - - +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits