diff options
author | Damjan Jovanovic <damjan@apache.org> | 2015-09-20 15:35:09 +0000 |
---|---|---|
committer | Damjan Jovanovic <damjan@apache.org> | 2015-09-20 15:35:09 +0000 |
commit | d7b7943aa73e3d39f3e6c7b594ec16145aa96494 (patch) | |
tree | 9acd4536afd0536de23577c2f706ddaa322bd101 | |
parent | faff774b727508f7eb088a18a8d3b46f4a51a6af (diff) |
#i125003# migrate main/configmgr/qa/unit from cppunit to Google Test. All tests fail
and on Windows it doesn't start running, but these look like problems from before
and at least it doesn't run during the build.
Notes
Notes:
ignore: googletest
-rw-r--r-- | configmgr/qa/unit/makefile.mk | 40 | ||||
-rw-r--r-- | configmgr/qa/unit/test.cxx | 113 |
2 files changed, 68 insertions, 85 deletions
diff --git a/configmgr/qa/unit/makefile.mk b/configmgr/qa/unit/makefile.mk index ea24171961c8..3b2c78615d67 100644 --- a/configmgr/qa/unit/makefile.mk +++ b/configmgr/qa/unit/makefile.mk @@ -29,20 +29,25 @@ ENABLE_EXCEPTIONS = TRUE .INCLUDE: settings.mk -CFLAGSCXX += $(CPPUNIT_CFLAGS) +.IF "$(ENABLE_UNIT_TESTS)" != "YES" +all: + @echo unit tests are disabled. Nothing to do. + +.ELSE SLOFILES = $(SLO)/test.obj -SHL1OBJS = $(SLOFILES) -SHL1STDLIBS = \ +APP1OBJS = $(SLOFILES) +APP1STDLIBS = \ $(CPPUHELPERLIB) \ $(CPPULIB) \ - $(CPPUNITLIB) \ + $(GTESTLIB) \ $(SALLIB) \ $(TESTSHL2LIB) -SHL1TARGET = unit -SHL1VERSIONMAP = version.map -DEF1NAME = $(SHL1TARGET) +APP1TARGET = unit +APP1RPATH = NONE +# this is a custom test, can't use APP1TARGET_run so disable it here: +APP1TEST = disabled .INCLUDE: target.mk @@ -54,11 +59,13 @@ MY_INI = .ini MY_INI = rc .ENDIF +DLLPRE = # no leading "lib" on .so files + $(MISC)/unit.rdb .ERRREMOVE: cp $(SOLARBINDIR)/types.rdb $@ - $(REGCOMP) -register -r $@ -c $(DLLDEST)/$(DLLPRE)configmgr$(DLLPOST) + $(REGCOMP) -register -r $@ -c $(DLLDEST)/$(DLLPRE)configmgr.uno$(DLLPOST) -TEST .PHONY: $(SHL1TARGETN) $(MISC)/unit.rdb +TEST .PHONY: $(APP1TARGETN) $(MISC)/unit.rdb rm -rf $(MISC)/unitdata mkdir $(MISC)/unitdata cp urebootstrap.ini $(MISC)/unitdata @@ -78,12 +85,9 @@ TEST .PHONY: $(SHL1TARGETN) $(MISC)/unit.rdb echo '[Bootstrap]' > $(MISC)/unitdata/brand/program/bootstrap$(MY_INI) echo 'UserInstallation = $$ORIGIN/../../user' \ >> $(MISC)/unitdata/brand/program/bootstrap$(MY_INI) -.IF "$(USE_SHELL)" == "bash" - export \ - URE_BOOTSTRAP=vnd.sun.star.pathname:$(MISC)/unitdata/urebootstrap.ini \ - && $(TESTSHL2) $(SHL1TARGETN) -forward $(MISC)/unit.rdb -.ELSE - setenv \ - URE_BOOTSTRAP vnd.sun.star.pathname:$(MISC)/unitdata/urebootstrap.ini \ - && $(TESTSHL2) $(SHL1TARGETN) -forward $(MISC)/unit.rdb -.ENDIF + $(COMMAND_ECHO) $(AUGMENT_LIBRARY_PATH_LOCAL) \ + URE_BOOTSTRAP=vnd.sun.star.pathname:$(MISC)/unitdata/urebootstrap.ini \ + CONFIGMGR_UNIT_FORWARD_STRING=$(MISC)/unit.rdb \ + $(APP1TARGETN) --gtest_output="xml:$(BIN)/$(APP1TARGET)_result.xml" + +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" diff --git a/configmgr/qa/unit/test.cxx b/configmgr/qa/unit/test.cxx index 0d53cdf50caa..292d9e0f0149 100644 --- a/configmgr/qa/unit/test.cxx +++ b/configmgr/qa/unit/test.cxx @@ -25,6 +25,7 @@ #include "sal/config.h" #include <cstddef> +#include <cstdlib> #include "com/sun/star/beans/NamedValue.hpp" #include "com/sun/star/beans/PropertyChangeEvent.hpp" @@ -47,6 +48,7 @@ #include "cppuhelper/implbase1.hxx" #include "cppuhelper/servicefactory.hxx" #include "osl/conditn.hxx" +#include "osl/process.h" #include "osl/thread.h" #include "osl/thread.hxx" #include "osl/time.h" @@ -57,7 +59,7 @@ #include "rtl/ustring.h" #include "rtl/ustring.hxx" #include "sal/types.h" -#include "testshl/simpleheader.hxx" +#include "gtest/gtest.h" namespace { @@ -80,27 +82,11 @@ void normalize( } } -class Test: public CppUnit::TestFixture { +class Test: public ::testing::Test { public: - virtual void setUp(); + virtual void SetUp(); - virtual void tearDown(); - - void testKeyFetch(); - - void testKeySet(); - - void testKeyReset(); - - void testSetSetMemberName(); - - void testReadCommands(); - - void testThreads(); - - void testRecursive(); - - void testCrossThreads(); + virtual void TearDown(); css::uno::Any getKey( rtl::OUString const & path, rtl::OUString const & relative) const; @@ -117,17 +103,6 @@ public: css::uno::Reference< css::uno::XInterface > createUpdateAccess( rtl::OUString const & path) const; - CPPUNIT_TEST_SUITE(Test); - CPPUNIT_TEST(testKeyFetch); - CPPUNIT_TEST(testKeySet); - CPPUNIT_TEST(testKeyReset); - CPPUNIT_TEST(testSetSetMemberName); - CPPUNIT_TEST(testReadCommands); - CPPUNIT_TEST(testThreads); - CPPUNIT_TEST(testRecursive); - CPPUNIT_TEST(testCrossThreads); - CPPUNIT_TEST_SUITE_END(); - private: css::uno::Reference< css::uno::XComponentContext > context_; css::uno::Reference< css::lang::XMultiServiceFactory > provider_; @@ -275,7 +250,7 @@ void RecursiveTest::test() { properties_->addPropertyChangeListener( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label")), this); step(); - CPPUNIT_ASSERT(count_ == 0); + ASSERT_TRUE(count_ == 0); css::uno::Reference< css::lang::XComponent >( properties_, css::uno::UNO_QUERY_THROW)->dispose(); } @@ -287,14 +262,14 @@ RecursiveTest::~RecursiveTest() { void RecursiveTest::disposing(css::lang::EventObject const & Source) throw (css::uno::RuntimeException) { - CPPUNIT_ASSERT(properties_.is() && Source.Source == properties_); + ASSERT_TRUE(properties_.is() && Source.Source == properties_); properties_.clear(); } void RecursiveTest::propertyChange(css::beans::PropertyChangeEvent const & evt) throw (css::uno::RuntimeException) { - CPPUNIT_ASSERT( + ASSERT_TRUE( evt.Source == properties_ && evt.PropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Label"))); if (count_ > 0) { @@ -357,10 +332,10 @@ void CrossThreadTest::step() const { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))); } -void Test::setUp() { - char const * forward = getForwardString(); +void Test::SetUp() { + char const * forward = getenv("CONFIGMGR_UNIT_FORWARD_STRING"); rtl_uString * registry = 0; - CPPUNIT_ASSERT( + ASSERT_TRUE( rtl_convertStringToUString( ®istry, forward, rtl_str_getLength(forward), osl_getThreadTextEncoding(), @@ -374,7 +349,7 @@ void Test::setUp() { css::uno::UNO_QUERY_THROW)->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext"))), css::uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT( + ASSERT_TRUE( context_->getValueByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( @@ -383,61 +358,61 @@ void Test::setUp() { provider_); } -void Test::tearDown() { +void Test::TearDown() { css::uno::Reference< css::lang::XComponent >( context_, css::uno::UNO_QUERY_THROW)->dispose(); } -void Test::testKeyFetch() { +TEST_F(Test, testKeyFetch) { rtl::OUString s; - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale"))) >>= s); - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test/AString"))) >>= s); } -void Test::testKeySet() { +TEST_F(Test, testKeySet) { setKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString")), css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baa")))); rtl::OUString s; - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString"))) >>= s); - CPPUNIT_ASSERT(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("baa"))); + ASSERT_TRUE(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("baa"))); } -void Test::testKeyReset() { +TEST_F(Test, testKeyReset) { if (resetKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString")))) { rtl::OUString s; - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString"))) >>= s); - CPPUNIT_ASSERT(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Foo"))); + ASSERT_TRUE(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Foo"))); } } -void Test::testSetSetMemberName() { +TEST_F(Test, testSetSetMemberName) { rtl::OUString s; - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( @@ -445,7 +420,7 @@ void Test::testSetSetMemberName() { ".uno:FontworkShapeType")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))) >>= s); - CPPUNIT_ASSERT( + ASSERT_TRUE( s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Fontwork Shape"))); css::uno::Reference< css::container::XNameAccess > access( @@ -460,7 +435,7 @@ void Test::testSetSetMemberName() { rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:FontworkGalleryFloater"))) >>= member; - CPPUNIT_ASSERT(member.is()); + ASSERT_TRUE(member.is()); member->setName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:FontworkShapeType"))); @@ -469,7 +444,7 @@ void Test::testSetSetMemberName() { css::uno::Reference< css::lang::XComponent >( access, css::uno::UNO_QUERY_THROW)->dispose(); - CPPUNIT_ASSERT( + ASSERT_TRUE( getKey( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( @@ -477,11 +452,11 @@ void Test::testSetSetMemberName() { ".uno:FontworkShapeType")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))) >>= s); - CPPUNIT_ASSERT( + ASSERT_TRUE( s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Fontwork Gallery"))); } -void Test::testReadCommands() { +TEST_F(Test, testReadCommands) { css::uno::Reference< css::container::XNameAccess > access( createViewAccess( rtl::OUString( @@ -490,14 +465,14 @@ void Test::testReadCommands() { "Commands"))), css::uno::UNO_QUERY_THROW); css::uno::Sequence< rtl::OUString > names(access->getElementNames()); - CPPUNIT_ASSERT(names.getLength() == 695); + ASSERT_TRUE(names.getLength() == 695); // testSetSetMemberName() already removed ".uno:FontworkGalleryFloater" sal_uInt32 n = osl_getGlobalTimer(); for (int i = 0; i < 8; ++i) { for (sal_Int32 j = 0; j < names.getLength(); ++j) { css::uno::Reference< css::container::XNameAccess > child; if (access->getByName(names[j]) >>= child) { - CPPUNIT_ASSERT(child.is()); + ASSERT_TRUE(child.is()); child->getByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))); child->getByName( @@ -508,12 +483,12 @@ void Test::testReadCommands() { } } n = osl_getGlobalTimer() - n; - t_print("Reading elements took %" SAL_PRIuUINT32 " ms\n", n); + printf("Reading elements took %" SAL_PRIuUINT32 " ms\n", n); css::uno::Reference< css::lang::XComponent >( access, css::uno::UNO_QUERY_THROW)->dispose(); } -void Test::testThreads() { +TEST_F(Test, testThreads) { struct Entry { rtl::OUString path; rtl::OUString relative; }; Entry list[] = { { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")), @@ -549,7 +524,7 @@ void Test::testThreads() { WriterThread * writers[numWriters]; osl::Condition stop; for (std::size_t i = 0; i < numReaders; ++i) { - CPPUNIT_ASSERT(getKey(list[i].path, list[i].relative).hasValue()); + ASSERT_TRUE(getKey(list[i].path, list[i].relative).hasValue()); readers[i] = new ReaderThread( stop, *this, list[i].path, list[i].relative); } @@ -578,21 +553,21 @@ void Test::testThreads() { success = success && writers[i]->getSuccess(); delete writers[i]; } - CPPUNIT_ASSERT(success); + ASSERT_TRUE(success); } -void Test::testRecursive() { +TEST_F(Test, testRecursive) { bool destroyed = false; rtl::Reference< RecursiveTest >( new SimpleRecursiveTest(*this, 100, &destroyed))->test(); - CPPUNIT_ASSERT(destroyed); + ASSERT_TRUE(destroyed); } -void Test::testCrossThreads() { +TEST_F(Test, testCrossThreads) { bool destroyed = false; rtl::Reference< RecursiveTest >( new SimpleRecursiveTest(*this, 10, &destroyed))->test(); - CPPUNIT_ASSERT(destroyed); + ASSERT_TRUE(destroyed); } css::uno::Any Test::getKey( @@ -667,8 +642,12 @@ css::uno::Reference< css::uno::XInterface > Test::createUpdateAccess( css::uno::Sequence< css::uno::Any >(&arg, 1)); } -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltest"); } -NOADDITIONAL; +int main(int argc, char **argv) +{ + osl_setCommandArgs(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} |