From ab9eecc53a6f87ccb6004e21c44d73b5f6e1ec1f Mon Sep 17 00:00:00 2001 From: Norbert Thiebaud Date: Thu, 21 Oct 2010 17:34:55 -0500 Subject: Finally, gut the vos module out of the build --- comphelper/prj/build.lst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'comphelper/prj/build.lst') diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index 9d44807c9cc3..a38f99985379 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -1,4 +1,4 @@ -ph comphelper : cppuhelper ucbhelper offuh vos salhelper NULL +ph comphelper : cppuhelper ucbhelper offuh salhelper NULL ph comphelper usr1 - all ph_mkout NULL ph comphelper\inc nmake - all ph_inc NULL ph comphelper\source\container nmake - all ph_container ph_inc NULL -- cgit v1.2.3 From c51592268380d7b8b1bae8358165f79e8540b496 Mon Sep 17 00:00:00 2001 From: Wilhelm Pflueger Date: Sat, 5 Feb 2011 22:56:20 +0100 Subject: Re-animated tests that were based on deprecated testshl. --- comphelper/prj/build.lst | 1 + comphelper/qa/makefile.mk | 10 +++------- comphelper/qa/test_string.cxx | 20 +++++++++++--------- comphelper/qa/test_weakbag.cxx | 8 +++++--- comphelper/qa/version.map | 3 +-- 5 files changed, 21 insertions(+), 21 deletions(-) (limited to 'comphelper/prj/build.lst') diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index a38f99985379..d5eced023c68 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -11,3 +11,4 @@ ph comphelper\source\compare nmake - all ph_compare ph_inc NULL ph comphelper\source\officeinstdir nmake - all ph_officeinstdir ph_inc NULL ph comphelper\source\xml nmake - all ph_xml NULL ph comphelper\util nmake - all ph_util ph_container ph_evtatmgr ph_misc ph_procfact ph_property ph_streaming ph_compare ph_officeinstdir ph_xml NULL +ph comphelper\qa nmake - all ph_complex NULL \ No newline at end of file diff --git a/comphelper/qa/makefile.mk b/comphelper/qa/makefile.mk index 0360d308529e..9d68caa549ee 100644 --- a/comphelper/qa/makefile.mk +++ b/comphelper/qa/makefile.mk @@ -40,8 +40,8 @@ DLLPRE = # no leading "lib" on .so files INCPRE += $(MISC)$/$(TARGET)$/inc SHL1TARGET = $(TARGET)_weakbag -SHL1OBJS = $(SLO)$/test_weakbag.obj -SHL1STDLIBS = $(CPPUHELPERLIB) $(CPPULIB) $(CPPUNITLIB) $(TESTSHL2LIB) $(SALLIB) +SHL1OBJS = $(SLO)$/test_weakbag.obj $(SLO)$/test_string.obj +SHL1STDLIBS = $(CPPUHELPERLIB) $(CPPULIB) $(CPPUNITLIB) $(TESTSHL2LIB) $(SALLIB) $(COMPHELPERLIB) SHL1VERSIONMAP = version.map SHL1IMPLIB = i$(SHL1TARGET) DEF1NAME = $(SHL1TARGET) @@ -49,8 +49,4 @@ DEF1NAME = $(SHL1TARGET) SLOFILES = $(SHL1OBJS) .INCLUDE: target.mk - -ALLTAR: test - -test .PHONY: $(SHL1TARGETN) - $(TESTSHL2) $(SHL1TARGETN) +.INCLUDE: _cppunit.mk diff --git a/comphelper/qa/test_string.cxx b/comphelper/qa/test_string.cxx index 9e355a5c9528..3a631d96790a 100644 --- a/comphelper/qa/test_string.cxx +++ b/comphelper/qa/test_string.cxx @@ -30,7 +30,9 @@ #include "sal/config.h" #include "comphelper/string.hxx" -#include "testshl/simpleheader.hxx" +#include +#include +#include #include "rtl/string.h" #include "rtl/ustring.h" #include "rtl/ustring.hxx" @@ -38,20 +40,20 @@ namespace { -class Test: public CppUnit::TestFixture { +class TestString: public CppUnit::TestFixture { public: void test(); - CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); }; -void Test::test() { +void TestString::test() { rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); sal_Int32 n1; rtl::OUString s2( - comphelper::string::searchAndReplace( + comphelper::string::searchAndReplaceAsciiL( s1, RTL_CONSTASCII_STRINGPARAM("bar"), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); CPPUNIT_ASSERT( @@ -59,7 +61,7 @@ void Test::test() { CPPUNIT_ASSERT(n1 == 3); sal_Int32 n2; rtl::OUString s3( - comphelper::string::searchAndReplace( + comphelper::string::searchAndReplaceAsciiL( s2, RTL_CONSTASCII_STRINGPARAM("bar"), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); @@ -68,7 +70,7 @@ void Test::test() { CPPUNIT_ASSERT(n2 == 7); sal_Int32 n3; rtl::OUString s4( - comphelper::string::searchAndReplace( + comphelper::string::searchAndReplaceAsciiL( s3, RTL_CONSTASCII_STRINGPARAM("bar"), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); @@ -76,10 +78,10 @@ void Test::test() { CPPUNIT_ASSERT(n3 == -1); } -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); +CPPUNIT_TEST_SUITE_REGISTRATION(TestString); } -NOADDITIONAL; +//NOADDITIONAL; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/test_weakbag.cxx b/comphelper/qa/test_weakbag.cxx index 9c60f11dd925..774260e104b9 100644 --- a/comphelper/qa/test_weakbag.cxx +++ b/comphelper/qa/test_weakbag.cxx @@ -33,7 +33,9 @@ #include "com/sun/star/uno/XInterface.hpp" #include "comphelper/weakbag.hxx" #include "cppuhelper/weak.hxx" -#include "testshl/simpleheader.hxx" +#include +#include +#include namespace { @@ -64,10 +66,10 @@ public: CPPUNIT_TEST_SUITE_END(); }; -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); +CPPUNIT_TEST_SUITE_REGISTRATION(Test); } -NOADDITIONAL; +CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/version.map b/comphelper/qa/version.map index 7321bbca16ad..5e95a1532f8a 100644 --- a/comphelper/qa/version.map +++ b/comphelper/qa/version.map @@ -27,8 +27,7 @@ UDK_3_0_0 { global: - registerAllTestFunction; - + cppunitTestPlugIn; local: *; }; -- cgit v1.2.3 From 783fb6dbf5d3cb4ba39830b555acc7f79e45dd8b Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Tue, 8 Feb 2011 01:35:32 +0100 Subject: Fix comphelper parallel build, so that the tests may run. --- comphelper/prj/build.lst | 2 +- comphelper/qa/makefile.mk | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'comphelper/prj/build.lst') diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index d5eced023c68..25aa17fed564 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -11,4 +11,4 @@ ph comphelper\source\compare nmake - all ph_compare ph_inc NULL ph comphelper\source\officeinstdir nmake - all ph_officeinstdir ph_inc NULL ph comphelper\source\xml nmake - all ph_xml NULL ph comphelper\util nmake - all ph_util ph_container ph_evtatmgr ph_misc ph_procfact ph_property ph_streaming ph_compare ph_officeinstdir ph_xml NULL -ph comphelper\qa nmake - all ph_complex NULL \ No newline at end of file +ph comphelper\qa nmake - all ph_complex ph_util NULL diff --git a/comphelper/qa/makefile.mk b/comphelper/qa/makefile.mk index 9c86c24a20bf..8d06d9b4a669 100644 --- a/comphelper/qa/makefile.mk +++ b/comphelper/qa/makefile.mk @@ -32,6 +32,7 @@ TARGET := qa ENABLE_EXCEPTIONS := TRUE .INCLUDE: settings.mk +.INCLUDE : $(PRJ)$/version.mk #building with stlport, but cppunit was not built with stlport .IF "$(USE_SYSTEM_STL)"!="YES" -- cgit v1.2.3 From ba00e8f403b0284e6dd28701975e0c91cf6d51ce Mon Sep 17 00:00:00 2001 From: Sébastien Le Ray Date: Wed, 16 Feb 2011 09:54:58 +0100 Subject: Cleanup in comphelper unit tests. --- comphelper/prj/build.lst | 3 +- comphelper/qa/makefile.mk | 53 ---- comphelper/qa/string/makefile.mk | 53 ++++ comphelper/qa/string/test_string.cxx | 287 +++++++++++++++++++++ comphelper/qa/string/test_string_noadditional.cxx | 33 +++ comphelper/qa/test_string.cxx | 287 --------------------- comphelper/qa/test_weakbag.cxx | 76 ------ comphelper/qa/weakbag/makefile.mk | 53 ++++ comphelper/qa/weakbag/test_weakbag.cxx | 74 ++++++ .../qa/weakbag/test_weakbag_noadditional.cxx | 33 +++ 10 files changed, 535 insertions(+), 417 deletions(-) delete mode 100644 comphelper/qa/makefile.mk create mode 100644 comphelper/qa/string/makefile.mk create mode 100644 comphelper/qa/string/test_string.cxx create mode 100644 comphelper/qa/string/test_string_noadditional.cxx delete mode 100644 comphelper/qa/test_string.cxx delete mode 100644 comphelper/qa/test_weakbag.cxx create mode 100644 comphelper/qa/weakbag/makefile.mk create mode 100644 comphelper/qa/weakbag/test_weakbag.cxx create mode 100644 comphelper/qa/weakbag/test_weakbag_noadditional.cxx (limited to 'comphelper/prj/build.lst') diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index 25aa17fed564..8a4f18ad2905 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -11,4 +11,5 @@ ph comphelper\source\compare nmake - all ph_compare ph_inc NULL ph comphelper\source\officeinstdir nmake - all ph_officeinstdir ph_inc NULL ph comphelper\source\xml nmake - all ph_xml NULL ph comphelper\util nmake - all ph_util ph_container ph_evtatmgr ph_misc ph_procfact ph_property ph_streaming ph_compare ph_officeinstdir ph_xml NULL -ph comphelper\qa nmake - all ph_complex ph_util NULL +ph comphelper\qa\weakbag nmake - all qa_weakbag ph_util NULL +ph comphelper\qa\string nmake - all qa_string ph_util NULL diff --git a/comphelper/qa/makefile.mk b/comphelper/qa/makefile.mk deleted file mode 100644 index e8c1d52a77d3..000000000000 --- a/comphelper/qa/makefile.mk +++ /dev/null @@ -1,53 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ := .. -PRJNAME := comphelper -TARGET := qa - -ENABLE_EXCEPTIONS := TRUE - -.INCLUDE: settings.mk -.INCLUDE : $(PRJ)$/version.mk - -CFLAGSCXX += $(CPPUNIT_CFLAGS) - -DLLPRE = # no leading "lib" on .so files - -INCPRE += $(MISC)$/$(TARGET)$/inc - -SHL1TARGET = $(TARGET)_weakbag -SHL1OBJS = $(SLO)$/test_weakbag.obj $(SLO)$/test_string.obj -SHL1STDLIBS = $(CPPUHELPERLIB) $(CPPULIB) $(CPPUNITLIB) $(SALLIB) $(COMPHELPERLIB) -SHL1VERSIONMAP = version.map -SHL1IMPLIB = i$(SHL1TARGET) -DEF1NAME = $(SHL1TARGET) - -SLOFILES = $(SHL1OBJS) - -.INCLUDE: target.mk -.INCLUDE: _cppunit.mk diff --git a/comphelper/qa/string/makefile.mk b/comphelper/qa/string/makefile.mk new file mode 100644 index 000000000000..7a74454c9212 --- /dev/null +++ b/comphelper/qa/string/makefile.mk @@ -0,0 +1,53 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := comphelper +TARGET := qa + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk +.INCLUDE : $(PRJ)$/version.mk + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +DLLPRE = # no leading "lib" on .so files + +INCPRE += $(MISC)$/$(TARGET)$/inc + +SHL1TARGET = $(TARGET)_string +SHL1OBJS = $(SLO)$/test_string.obj $(SLO)$/test_string_noadditional.obj +SHL1STDLIBS = $(CPPUHELPERLIB) $(CPPULIB) $(CPPUNITLIB) $(SALLIB) $(COMPHELPERLIB) +SHL1VERSIONMAP = ..$/version.map +SHL1IMPLIB = i$(SHL1TARGET) +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk +.INCLUDE: _cppunit.mk diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx new file mode 100644 index 000000000000..a5826ae3628d --- /dev/null +++ b/comphelper/qa/string/test_string.cxx @@ -0,0 +1,287 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_comphelper.hxx" +#include "sal/config.h" + +#include "comphelper/string.hxx" +#include +#include + +#include +#include +#include + +#include "rtl/string.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace { + +class TestString: public CppUnit::TestFixture +{ +public: + void test(); + void testNatural(); + + CPPUNIT_TEST_SUITE(TestString); + CPPUNIT_TEST(test); + CPPUNIT_TEST(testNatural); + CPPUNIT_TEST_SUITE_END(); +}; + +void TestString::test() +{ + rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); + sal_Int32 n1; + rtl::OUString s2( + comphelper::string::searchAndReplaceAsciiL( + s1, RTL_CONSTASCII_STRINGPARAM("bar"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); + CPPUNIT_ASSERT( + s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar"))); + CPPUNIT_ASSERT(n1 == 3); + sal_Int32 n2; + rtl::OUString s3( + comphelper::string::searchAndReplaceAsciiL( + s2, RTL_CONSTASCII_STRINGPARAM("bar"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), + n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); + CPPUNIT_ASSERT( + s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz"))); + CPPUNIT_ASSERT(n2 == 7); + sal_Int32 n3; + rtl::OUString s4( + comphelper::string::searchAndReplaceAsciiL( + s3, RTL_CONSTASCII_STRINGPARAM("bar"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), + n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); + CPPUNIT_ASSERT(s4 == s3); + CPPUNIT_ASSERT(n3 == -1); +} + +using namespace ::com::sun::star; + +class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > +{ +public: + virtual sal_Int32 SAL_CALL compareSubstring( + const rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1, + const rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(uno::RuntimeException) + { + return str1.copy(off1, len1).compareTo(str2.copy(off2, len2)); + } + virtual sal_Int32 SAL_CALL compareString( + const rtl::OUString& str1, + const rtl::OUString& str2) throw(uno::RuntimeException) + { + return str1.compareTo(str2); + } + virtual sal_Int32 SAL_CALL loadDefaultCollator(const lang::Locale&, sal_Int32) + throw(uno::RuntimeException) {return 0;} + virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(const rtl::OUString&, + const lang::Locale&, sal_Int32) throw(uno::RuntimeException) {return 0;} + virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption(const rtl::OUString&, + const lang::Locale&, const uno::Sequence< sal_Int32 >&) throw(uno::RuntimeException) {} + virtual uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms(const lang::Locale&) + throw(uno::RuntimeException) + { + return uno::Sequence< rtl::OUString >(); + } + virtual uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions(const rtl::OUString&) + throw(uno::RuntimeException) + { + return uno::Sequence< sal_Int32 >(); + } +}; + +#define IS_DIGIT(CHAR) (((CHAR) >= 48) && ((CHAR <= 57))) + +class testBreakIterator : public cppu::WeakImplHelper1< i18n::XBreakIterator > +{ +public: + virtual sal_Int32 SAL_CALL nextCharacters( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) + throw(uno::RuntimeException) {return -1;} + virtual sal_Int32 SAL_CALL previousCharacters( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) + throw(uno::RuntimeException) {return -1;} + + virtual i18n::Boundary SAL_CALL previousWord( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16) throw(uno::RuntimeException) + { return i18n::Boundary(); } + virtual i18n::Boundary SAL_CALL nextWord( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16) throw(uno::RuntimeException) + { return i18n::Boundary(); } + virtual i18n::Boundary SAL_CALL getWordBoundary( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16, sal_Bool ) + throw(uno::RuntimeException) + { return i18n::Boundary(); } + + virtual sal_Bool SAL_CALL isBeginWord( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) + { return false; } + virtual sal_Bool SAL_CALL isEndWord( const rtl::OUString&, sal_Int32, + const lang::Locale& , sal_Int16 ) throw(uno::RuntimeException) + { return false; } + virtual sal_Int16 SAL_CALL getWordType( const rtl::OUString&, sal_Int32, + const lang::Locale& ) throw(uno::RuntimeException) + { return 0; } + + virtual sal_Int32 SAL_CALL beginOfSentence( const rtl::OUString&, sal_Int32, + const lang::Locale& ) throw(uno::RuntimeException) + { return 0; } + virtual sal_Int32 SAL_CALL endOfSentence( const rtl::OUString& rText, sal_Int32, + const lang::Locale& ) throw(uno::RuntimeException) + { return rText.getLength(); } + + virtual i18n::LineBreakResults SAL_CALL getLineBreak( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int32, + const i18n::LineBreakHyphenationOptions&, + const i18n::LineBreakUserOptions&) + throw(uno::RuntimeException) + { + return i18n::LineBreakResults(); + } + + virtual sal_Int16 SAL_CALL getScriptType( const rtl::OUString&, sal_Int32 ) + throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL beginOfScript( const rtl::OUString&, sal_Int32, + sal_Int16 ) throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL endOfScript( const rtl::OUString&, sal_Int32, + sal_Int16 ) throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL previousScript( const rtl::OUString&, sal_Int32, + sal_Int16 ) throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL nextScript( const rtl::OUString&, sal_Int32, + sal_Int16 ) throw(uno::RuntimeException) { return -1; } + + virtual sal_Int32 SAL_CALL beginOfCharBlock( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL endOfCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos, + const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException) + { + const sal_Unicode *pStr = rText.getStr()+nStartPos; + for (sal_Int16 nI = nStartPos; nI < rText.getLength(); ++nI) + { + if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr)) + return nI; + else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr)) + return nI; + ++pStr; + } + return -1; + } + virtual sal_Int32 SAL_CALL previousCharBlock( const rtl::OUString&, sal_Int32, + const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; } + virtual sal_Int32 SAL_CALL nextCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos, + const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException) + { + const sal_Unicode *pStr = rText.getStr()+nStartPos; + for (sal_Int16 nI = nStartPos; nI < rText.getLength(); ++nI) + { + if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr)) + return nI; + else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr)) + return nI; + ++pStr; + } + return -1; + } +}; + +void TestString::testNatural() +{ + using namespace comphelper::string; + + uno::Reference< i18n::XCollator > xCollator(new testCollator); + uno::Reference< i18n::XBreakIterator > xBI(new testBreakIterator); + +// --- Some generic tests to ensure we do not alter original behavior +// outside what we want + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) == 0 + ); + // Case sensitivity + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), xCollator, xBI, lang::Locale()) < 0 + ); + // Reverse + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) > 0 + ); + // First shorter + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), xCollator, xBI, lang::Locale()) > 0 + ); + // Second shorter + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), xCollator, xBI, lang::Locale()) < 0 + ); +// -- Here we go on natural order, each one is followed by classic compare and the reverse comparison + // That's why we originally made the patch + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), xCollator, xBI, lang::Locale()) < 0 + ); + // Original behavior + CPPUNIT_ASSERT( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10")))) > 0 + ); + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), xCollator, xBI, lang::Locale()) > 0 + ); + // Harder + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), xCollator, xBI, lang::Locale()) < 0 + ); + CPPUNIT_ASSERT( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th")))) > 0 + ); + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), xCollator, xBI, lang::Locale()) > 0 + ); + // Hardest + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), xCollator, xBI, lang::Locale()) < 0 + ); + CPPUNIT_ASSERT( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010")))) > 0 + ); + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), xCollator, xBI, lang::Locale()) > 0 + ); + CPPUNIT_ASSERT( + compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), xCollator, xBI, lang::Locale()) == 0 + ); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TestString); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/string/test_string_noadditional.cxx b/comphelper/qa/string/test_string_noadditional.cxx new file mode 100644 index 000000000000..9f3bfe5061ab --- /dev/null +++ b/comphelper/qa/string/test_string_noadditional.cxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/test_string.cxx b/comphelper/qa/test_string.cxx deleted file mode 100644 index a5826ae3628d..000000000000 --- a/comphelper/qa/test_string.cxx +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "precompiled_comphelper.hxx" -#include "sal/config.h" - -#include "comphelper/string.hxx" -#include -#include - -#include -#include -#include - -#include "rtl/string.h" -#include "rtl/ustring.h" -#include "rtl/ustring.hxx" -#include "sal/types.h" - -namespace { - -class TestString: public CppUnit::TestFixture -{ -public: - void test(); - void testNatural(); - - CPPUNIT_TEST_SUITE(TestString); - CPPUNIT_TEST(test); - CPPUNIT_TEST(testNatural); - CPPUNIT_TEST_SUITE_END(); -}; - -void TestString::test() -{ - rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); - sal_Int32 n1; - rtl::OUString s2( - comphelper::string::searchAndReplaceAsciiL( - s1, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); - CPPUNIT_ASSERT( - s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar"))); - CPPUNIT_ASSERT(n1 == 3); - sal_Int32 n2; - rtl::OUString s3( - comphelper::string::searchAndReplaceAsciiL( - s2, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), - n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); - CPPUNIT_ASSERT( - s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz"))); - CPPUNIT_ASSERT(n2 == 7); - sal_Int32 n3; - rtl::OUString s4( - comphelper::string::searchAndReplaceAsciiL( - s3, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), - n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); - CPPUNIT_ASSERT(s4 == s3); - CPPUNIT_ASSERT(n3 == -1); -} - -using namespace ::com::sun::star; - -class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > -{ -public: - virtual sal_Int32 SAL_CALL compareSubstring( - const rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1, - const rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(uno::RuntimeException) - { - return str1.copy(off1, len1).compareTo(str2.copy(off2, len2)); - } - virtual sal_Int32 SAL_CALL compareString( - const rtl::OUString& str1, - const rtl::OUString& str2) throw(uno::RuntimeException) - { - return str1.compareTo(str2); - } - virtual sal_Int32 SAL_CALL loadDefaultCollator(const lang::Locale&, sal_Int32) - throw(uno::RuntimeException) {return 0;} - virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(const rtl::OUString&, - const lang::Locale&, sal_Int32) throw(uno::RuntimeException) {return 0;} - virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption(const rtl::OUString&, - const lang::Locale&, const uno::Sequence< sal_Int32 >&) throw(uno::RuntimeException) {} - virtual uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms(const lang::Locale&) - throw(uno::RuntimeException) - { - return uno::Sequence< rtl::OUString >(); - } - virtual uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions(const rtl::OUString&) - throw(uno::RuntimeException) - { - return uno::Sequence< sal_Int32 >(); - } -}; - -#define IS_DIGIT(CHAR) (((CHAR) >= 48) && ((CHAR <= 57))) - -class testBreakIterator : public cppu::WeakImplHelper1< i18n::XBreakIterator > -{ -public: - virtual sal_Int32 SAL_CALL nextCharacters( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) - throw(uno::RuntimeException) {return -1;} - virtual sal_Int32 SAL_CALL previousCharacters( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) - throw(uno::RuntimeException) {return -1;} - - virtual i18n::Boundary SAL_CALL previousWord( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16) throw(uno::RuntimeException) - { return i18n::Boundary(); } - virtual i18n::Boundary SAL_CALL nextWord( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16) throw(uno::RuntimeException) - { return i18n::Boundary(); } - virtual i18n::Boundary SAL_CALL getWordBoundary( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Bool ) - throw(uno::RuntimeException) - { return i18n::Boundary(); } - - virtual sal_Bool SAL_CALL isBeginWord( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) - { return false; } - virtual sal_Bool SAL_CALL isEndWord( const rtl::OUString&, sal_Int32, - const lang::Locale& , sal_Int16 ) throw(uno::RuntimeException) - { return false; } - virtual sal_Int16 SAL_CALL getWordType( const rtl::OUString&, sal_Int32, - const lang::Locale& ) throw(uno::RuntimeException) - { return 0; } - - virtual sal_Int32 SAL_CALL beginOfSentence( const rtl::OUString&, sal_Int32, - const lang::Locale& ) throw(uno::RuntimeException) - { return 0; } - virtual sal_Int32 SAL_CALL endOfSentence( const rtl::OUString& rText, sal_Int32, - const lang::Locale& ) throw(uno::RuntimeException) - { return rText.getLength(); } - - virtual i18n::LineBreakResults SAL_CALL getLineBreak( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int32, - const i18n::LineBreakHyphenationOptions&, - const i18n::LineBreakUserOptions&) - throw(uno::RuntimeException) - { - return i18n::LineBreakResults(); - } - - virtual sal_Int16 SAL_CALL getScriptType( const rtl::OUString&, sal_Int32 ) - throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL beginOfScript( const rtl::OUString&, sal_Int32, - sal_Int16 ) throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL endOfScript( const rtl::OUString&, sal_Int32, - sal_Int16 ) throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL previousScript( const rtl::OUString&, sal_Int32, - sal_Int16 ) throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL nextScript( const rtl::OUString&, sal_Int32, - sal_Int16 ) throw(uno::RuntimeException) { return -1; } - - virtual sal_Int32 SAL_CALL beginOfCharBlock( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL endOfCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos, - const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException) - { - const sal_Unicode *pStr = rText.getStr()+nStartPos; - for (sal_Int16 nI = nStartPos; nI < rText.getLength(); ++nI) - { - if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr)) - return nI; - else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr)) - return nI; - ++pStr; - } - return -1; - } - virtual sal_Int32 SAL_CALL previousCharBlock( const rtl::OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; } - virtual sal_Int32 SAL_CALL nextCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos, - const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException) - { - const sal_Unicode *pStr = rText.getStr()+nStartPos; - for (sal_Int16 nI = nStartPos; nI < rText.getLength(); ++nI) - { - if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr)) - return nI; - else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr)) - return nI; - ++pStr; - } - return -1; - } -}; - -void TestString::testNatural() -{ - using namespace comphelper::string; - - uno::Reference< i18n::XCollator > xCollator(new testCollator); - uno::Reference< i18n::XBreakIterator > xBI(new testBreakIterator); - -// --- Some generic tests to ensure we do not alter original behavior -// outside what we want - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) == 0 - ); - // Case sensitivity - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), xCollator, xBI, lang::Locale()) < 0 - ); - // Reverse - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) > 0 - ); - // First shorter - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), xCollator, xBI, lang::Locale()) > 0 - ); - // Second shorter - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), xCollator, xBI, lang::Locale()) < 0 - ); -// -- Here we go on natural order, each one is followed by classic compare and the reverse comparison - // That's why we originally made the patch - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), xCollator, xBI, lang::Locale()) < 0 - ); - // Original behavior - CPPUNIT_ASSERT( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10")))) > 0 - ); - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), xCollator, xBI, lang::Locale()) > 0 - ); - // Harder - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), xCollator, xBI, lang::Locale()) < 0 - ); - CPPUNIT_ASSERT( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th")))) > 0 - ); - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), xCollator, xBI, lang::Locale()) > 0 - ); - // Hardest - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), xCollator, xBI, lang::Locale()) < 0 - ); - CPPUNIT_ASSERT( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010")))) > 0 - ); - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), xCollator, xBI, lang::Locale()) > 0 - ); - CPPUNIT_ASSERT( - compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), xCollator, xBI, lang::Locale()) == 0 - ); -} - -CPPUNIT_TEST_SUITE_REGISTRATION(TestString); - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/test_weakbag.cxx b/comphelper/qa/test_weakbag.cxx deleted file mode 100644 index cc5373d5d6d6..000000000000 --- a/comphelper/qa/test_weakbag.cxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "precompiled_comphelper.hxx" -#include "sal/config.h" - -#include "com/sun/star/uno/Reference.hxx" -#include "com/sun/star/uno/XInterface.hpp" -#include "comphelper/weakbag.hxx" -#include "cppuhelper/weak.hxx" - -#include -#include -#include - -namespace { - -namespace css = com::sun::star; - -class Test: public CppUnit::TestFixture { -public: - void test() { - css::uno::Reference< css::uno::XInterface > ref1(new cppu::OWeakObject); - css::uno::Reference< css::uno::XInterface > ref2(new cppu::OWeakObject); - css::uno::Reference< css::uno::XInterface > ref3(new cppu::OWeakObject); - comphelper::WeakBag< css::uno::XInterface > bag; - bag.add(ref1); - bag.add(ref1); - bag.add(ref2); - bag.add(ref2); - ref1.clear(); - bag.add(ref3); - ref3.clear(); - CPPUNIT_ASSERT_MESSAGE("remove first ref2", bag.remove() == ref2); - CPPUNIT_ASSERT_MESSAGE("remove second ref2", bag.remove() == ref2); - CPPUNIT_ASSERT_MESSAGE("remove first null", !bag.remove().is()); - CPPUNIT_ASSERT_MESSAGE("remove second null", !bag.remove().is()); - } - - CPPUNIT_TEST_SUITE(Test); - CPPUNIT_TEST(test); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(Test); - -} - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/weakbag/makefile.mk b/comphelper/qa/weakbag/makefile.mk new file mode 100644 index 000000000000..606373c34b85 --- /dev/null +++ b/comphelper/qa/weakbag/makefile.mk @@ -0,0 +1,53 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := comphelper +TARGET := qa + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk +.INCLUDE : $(PRJ)$/version.mk + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +DLLPRE = # no leading "lib" on .so files + +INCPRE += $(MISC)$/$(TARGET)$/inc + +SHL1TARGET = $(TARGET)_weakbag +SHL1OBJS = $(SLO)$/test_weakbag.obj $(SLO)$/test_weakbag_noadditional.obj +SHL1STDLIBS = $(CPPUHELPERLIB) $(CPPULIB) $(CPPUNITLIB) $(SALLIB) $(COMPHELPERLIB) +SHL1VERSIONMAP = ..$/version.map +SHL1IMPLIB = i$(SHL1TARGET) +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk +.INCLUDE: _cppunit.mk diff --git a/comphelper/qa/weakbag/test_weakbag.cxx b/comphelper/qa/weakbag/test_weakbag.cxx new file mode 100644 index 000000000000..84767f0ede0e --- /dev/null +++ b/comphelper/qa/weakbag/test_weakbag.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_comphelper.hxx" +#include "sal/config.h" + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/XInterface.hpp" +#include "comphelper/weakbag.hxx" +#include "cppuhelper/weak.hxx" + +#include +#include +#include + +namespace { + +namespace css = com::sun::star; + +class Test: public CppUnit::TestFixture { +public: + void test() { + css::uno::Reference< css::uno::XInterface > ref1(new cppu::OWeakObject); + css::uno::Reference< css::uno::XInterface > ref2(new cppu::OWeakObject); + css::uno::Reference< css::uno::XInterface > ref3(new cppu::OWeakObject); + comphelper::WeakBag< css::uno::XInterface > bag; + bag.add(ref1); + bag.add(ref1); + bag.add(ref2); + bag.add(ref2); + ref1.clear(); + bag.add(ref3); + ref3.clear(); + CPPUNIT_ASSERT_MESSAGE("remove first ref2", bag.remove() == ref2); + CPPUNIT_ASSERT_MESSAGE("remove second ref2", bag.remove() == ref2); + CPPUNIT_ASSERT_MESSAGE("remove first null", !bag.remove().is()); + CPPUNIT_ASSERT_MESSAGE("remove second null", !bag.remove().is()); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/weakbag/test_weakbag_noadditional.cxx b/comphelper/qa/weakbag/test_weakbag_noadditional.cxx new file mode 100644 index 000000000000..9f3bfe5061ab --- /dev/null +++ b/comphelper/qa/weakbag/test_weakbag_noadditional.cxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3