diff options
Diffstat (limited to 'comphelper/qa')
-rw-r--r-- | comphelper/qa/complex/comphelper/Map.java | 12 | ||||
-rw-r--r-- | comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java | 132 | ||||
-rw-r--r-- | comphelper/qa/complex/comphelper_all.sce | 1 | ||||
-rw-r--r-- | comphelper/qa/container/comphelper_ifcontainer.cxx | 2 | ||||
-rw-r--r-- | comphelper/qa/python/test_sequence_output_stream.py | 84 | ||||
-rw-r--r-- | comphelper/qa/string/NaturalStringSortTest.cxx | 100 | ||||
-rw-r--r-- | comphelper/qa/string/test_string.cxx | 285 | ||||
-rw-r--r-- | comphelper/qa/unit/base64_test.cxx | 12 | ||||
-rw-r--r-- | comphelper/qa/unit/propertyvalue.cxx | 77 | ||||
-rw-r--r-- | comphelper/qa/unit/syntaxhighlighttest.cxx | 12 | ||||
-rw-r--r-- | comphelper/qa/unit/test_guards.cxx | 56 | ||||
-rw-r--r-- | comphelper/qa/unit/test_hash.cxx | 4 | ||||
-rw-r--r-- | comphelper/qa/unit/threadpooltest.cxx | 5 | ||||
-rw-r--r-- | comphelper/qa/unit/types_test.cxx | 14 | ||||
-rw-r--r-- | comphelper/qa/unit/variadictemplates.cxx | 26 | ||||
-rw-r--r-- | comphelper/qa/weakbag/makefile.mk | 44 | ||||
-rw-r--r-- | comphelper/qa/weakbag/test_weakbag.cxx | 16 | ||||
-rw-r--r-- | comphelper/qa/weakbag/test_weakbag_noadditional.cxx | 25 |
18 files changed, 418 insertions, 489 deletions
diff --git a/comphelper/qa/complex/comphelper/Map.java b/comphelper/qa/complex/comphelper/Map.java index d01d1bef362b..51f731732071 100644 --- a/comphelper/qa/complex/comphelper/Map.java +++ b/comphelper/qa/complex/comphelper/Map.java @@ -461,23 +461,23 @@ public class Map @Test public void testSpecialValues() throws com.sun.star.uno.Exception { - final Double[] keys = new Double[] { new Double( 0 ), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }; - final Double[] values = new Double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, new Double( 0 ) }; + final Double[] keys = new Double[] { Double.valueOf( 0 ), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }; + final Double[] values = new Double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.valueOf( 0 ) }; XEnumerableMap map = com.sun.star.container.EnumerableMap.create( connection.getComponentContext(), new Type( Double.class ), new Type( Double.class ) ); impl_putAll( map, keys, values ); assertTrue( "containsKey( Double.+INF failed", map.containsKey( Double.POSITIVE_INFINITY ) ); assertTrue( "containsKey( Double.-INF failed", map.containsKey( Double.NEGATIVE_INFINITY ) ); - assertTrue( "containsKey( 0 ) failed", map.containsKey( new Double( 0 ) ) ); + assertTrue( "containsKey( 0 ) failed", map.containsKey( Double.valueOf( 0 ) ) ); assertTrue( "containsValue( Double.+INF ) failed", map.containsValue( Double.POSITIVE_INFINITY ) ); assertTrue( "containsValue( Double.-INF ) failed", map.containsValue( Double.NEGATIVE_INFINITY ) ); - assertTrue( "containsValue( 0 ) failed", map.containsValue( new Double( 0 ) ) ); + assertTrue( "containsValue( 0 ) failed", map.containsValue( Double.valueOf( 0 ) ) ); // put and containsKey should reject Double.NaN as key //? assureException( "Double.NaN should not be allowed as key in a call to 'put'", map, "put", -//? new Class[] { Object.class, Object.class }, new Object[] { Double.NaN, new Double( 0 ) }, +//? new Class[] { Object.class, Object.class }, new Object[] { Double.NaN, Double.valueOf( 0 ) }, //? com.sun.star.lang.IllegalArgumentException.class ); //? assureException( "Double.NaN should not be allowed as key in a call to 'containsKey'", map, "containsKey", //? new Class[] { Object.class }, new Object[] { Double.NaN }, @@ -485,7 +485,7 @@ public class Map // ditto for put and containsValue //? assureException( "Double.NaN should not be allowed as value in a call to 'put'", map, "put", -//? new Class[] { Object.class, Object.class }, new Object[] { new Double( 0 ), Double.NaN }, +//? new Class[] { Object.class, Object.class }, new Object[] { Double.valueOf( 0 ), Double.NaN }, //? com.sun.star.lang.IllegalArgumentException.class ); //? assureException( "Double.NaN should not be allowed as key in a call to 'containsValue'", map, "containsValue", //? new Class[] { Object.class }, new Object[] { Double.NaN }, diff --git a/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java b/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java deleted file mode 100644 index 03906134b9f7..000000000000 --- a/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.comphelper; - -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.uno.UnoRuntime; - -import com.sun.star.io.XSequenceOutputStream; -import com.sun.star.io.XSeekableInputStream; - -import java.util.Random; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openoffice.test.OfficeConnection; -import static org.junit.Assert.*; - -/* Document. - */ - -public class SequenceOutputStreamUnitTest -{ - private XMultiServiceFactory m_xMSF = null; - - @Before public void before() { - try { - m_xMSF = getMSF(); - } catch (Exception e) { - fail ("Cannot create service factory!"); - } - if (m_xMSF==null) { - fail ("Cannot create service factory!"); - } - } - - @After public void after() { - m_xMSF = null; - } - - @Test public void test () { - try { - final int nBytesCnt = 20; - - //create SequenceOutputStream - Object oSequenceOutputStream = m_xMSF.createInstance ( - "com.sun.star.io.SequenceOutputStream" ); - XSequenceOutputStream xSeqOutStream = - UnoRuntime.queryInterface ( - XSequenceOutputStream.class, oSequenceOutputStream ); - - //write something to the stream - byte pBytesOriginal[] = new byte [nBytesCnt]; - Random oRandom = new Random(); - oRandom.nextBytes (pBytesOriginal); - xSeqOutStream.writeBytes (pBytesOriginal); - - // Append the same content once again - xSeqOutStream.writeBytes (pBytesOriginal); - - byte pBytesWritten[] = xSeqOutStream.getWrittenBytes (); - assertTrue( "SequenceOutputStream::getWrittenBytes() - wrong amount of bytes returned", - pBytesWritten.length == nBytesCnt * 2 ); - - //create SequenceInputstream - Object pArgs[] = new Object[1]; - pArgs[0] = pBytesWritten; - Object oSequenceInputStream = m_xMSF.createInstanceWithArguments ( - "com.sun.star.io.SequenceInputStream", pArgs ); - XSeekableInputStream xSeekableInStream = - UnoRuntime.queryInterface ( - XSeekableInputStream.class, oSequenceInputStream ); - - //read from the stream - byte pBytesRead[][] = new byte [1][nBytesCnt*2]; - int nBytesCountRead = xSeekableInStream.readBytes ( pBytesRead, pBytesRead[0].length + 1 ); - - assertTrue( "SequenceInputStream::readBytes() - wrong amount of bytes returned " + pBytesRead[0].length + " vs " + (nBytesCountRead), - pBytesRead[0].length == nBytesCountRead); - - //close the streams - xSeqOutStream.closeOutput (); - xSeekableInStream.closeInput (); - - //compare the original, written and read arrays - for ( int i = 0; i < nBytesCnt * 2; ++i ) { - assertTrue( "Written array not identical to original array. Position: " + i, - pBytesOriginal[i % nBytesCnt] == pBytesWritten[i] ); - assertTrue( "Read array not identical to original array. Position: " + i, - pBytesOriginal[i % nBytesCnt] == pBytesRead[0][i] ); - } - } catch ( Exception e ) { - fail ( "Exception: " + e ); - } - } - - private static XMultiServiceFactory getMSF() - { - return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); - } - - // setup and close connections - @BeforeClass public static void setUpConnection() throws Exception { - System.out.println("setUpConnection()"); - connection.setUp(); - } - - @AfterClass public static void tearDownConnection() - throws InterruptedException, com.sun.star.uno.Exception - { - System.out.println("tearDownConnection()"); - connection.tearDown(); - } - - private static final OfficeConnection connection = new OfficeConnection(); -} diff --git a/comphelper/qa/complex/comphelper_all.sce b/comphelper/qa/complex/comphelper_all.sce index 5ee5f941f94a..656850ab0712 100644 --- a/comphelper/qa/complex/comphelper_all.sce +++ b/comphelper/qa/complex/comphelper_all.sce @@ -15,5 +15,4 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # --o complex.comphelper.SequenceOutputStreamUnitTest -o complex.comphelper.Map diff --git a/comphelper/qa/container/comphelper_ifcontainer.cxx b/comphelper/qa/container/comphelper_ifcontainer.cxx index ed92aa692f4e..db904e2fbaf6 100644 --- a/comphelper/qa/container/comphelper_ifcontainer.cxx +++ b/comphelper/qa/container/comphelper_ifcontainer.cxx @@ -114,7 +114,7 @@ namespace comphelper_ifcontainer CPPUNIT_ASSERT_EQUAL_MESSAGE("query contents", nTests, static_cast<int>(aElements.size())); - if (static_cast<int>(aElements.size()) == nTests) + if (aElements.size() == nTests) { for (i = 0; i < nTests; i++) { diff --git a/comphelper/qa/python/test_sequence_output_stream.py b/comphelper/qa/python/test_sequence_output_stream.py new file mode 100644 index 000000000000..6f1294960e29 --- /dev/null +++ b/comphelper/qa/python/test_sequence_output_stream.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +import unittest +import uno + +from org.libreoffice.unotest import UnoInProcess + + +class TestSequenceOutputStream(unittest.TestCase): + """Test com.sun.star.io.SequenceOutputStream""" + + @classmethod + def setUpClass(cls): + cls._uno = UnoInProcess() + cls._uno.setUp() + + @classmethod + def tearDownClass(cls): + cls._uno.tearDown() + + def setUp(self): + self.data = uno.ByteSequence(b"some data") + try: + self.service_manager = self._uno.getContext().getServiceManager() + except: + raise RuntimeError("Cannot create service factory!") + if self.service_manager is None: + raise RuntimeError("Cannot create service factory!") + + def test_stream(self): + try: + seq_output_stream = self.service_manager.createInstance( + "com.sun.star.io.SequenceOutputStream" + ) + seq_output_stream.writeBytes(self.data) + + # Append the same content once again + seq_output_stream.writeBytes(self.data) + + written_bytes = seq_output_stream.getWrittenBytes() + + self.assertEqual( + len(self.data) * 2, + len(written_bytes), + "SequenceOutputStream::getWrittenBytes() - wrong amount of bytes returned", + ) + + # create SequenceInputstream + seq_input_stream = self.service_manager.createInstanceWithArguments( + "com.sun.star.io.SequenceInputStream", (written_bytes,) + ) + + # read from the stream + nbytes_read, read_bytes = seq_input_stream.readBytes(None, len(self.data) * 2 + 1) + self.assertEqual( + len(self.data) * 2, + nbytes_read, + "SequenceInputStream::readBytes() - " + f"wrong amount of bytes returned {len(self.data) * 2} vs {nbytes_read}", + ) + + # close the streams + seq_output_stream.closeOutput() + seq_input_stream.closeInput() + + expected = uno.ByteSequence(self.data.value * 2) + self.assertEqual(expected, written_bytes, "Written array not identical to original.") + self.assertEqual(expected, read_bytes, "Read array not identical to original.") + except Exception as e: + self.fail(f"Exception: {e}") + + +if __name__ == "__main__": + unittest.main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/comphelper/qa/string/NaturalStringSortTest.cxx b/comphelper/qa/string/NaturalStringSortTest.cxx new file mode 100644 index 000000000000..32519d7534e6 --- /dev/null +++ b/comphelper/qa/string/NaturalStringSortTest.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <comphelper/string.hxx> +#include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/i18n/CharType.hpp> +#include <com/sun/star/i18n/XBreakIterator.hpp> +#include <com/sun/star/i18n/XCollator.hpp> + +#include <unotest/bootstrapfixturebase.hxx> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <rtl/ustring.hxx> + +using namespace css; + +namespace +{ +class TestStringNaturalCompare : public test::BootstrapFixtureBase +{ +public: + void testNatural() + { + lang::Locale aLocale; + aLocale.Language = "en"; + aLocale.Country = "US"; + + comphelper::string::NaturalStringSorter aSorter(comphelper::getProcessComponentContext(), + aLocale); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(+0), aSorter.compare(u"ABC"_ustr, u"ABC"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"ABC"_ustr, u"abc"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"abc"_ustr, u"ABC"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), + aSorter.compare(u"alongstring"_ustr, u"alongerstring"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), + aSorter.compare(u"alongerstring"_ustr, u"alongstring"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"Heading 9"_ustr, u"Heading 10"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"Heading 10"_ustr, u"Heading 9"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), + aSorter.compare(u"July, the 4th"_ustr, u"July, the 10th"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), + aSorter.compare(u"July, the 10th"_ustr, u"July, the 4th"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"abc08"_ustr, u"abc010"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"abc010"_ustr, u"abc08"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+0), + aSorter.compare(u"apple10apple"_ustr, u"apple10apple"_ustr)); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"KA1"_ustr, u"KA0"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+0), aSorter.compare(u"KA1"_ustr, u"KA1"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"KA1"_ustr, u"KA2"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"KA50"_ustr, u"KA5"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"KA50"_ustr, u"KA100"_ustr)); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"1"_ustr, u"0"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+0), aSorter.compare(u"1"_ustr, u"1"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"1"_ustr, u"2"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"11"_ustr, u"1"_ustr)); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"50"_ustr, u"100"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"0"_ustr, u"100000"_ustr)); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"0"_ustr, u"A"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"A"_ustr, u"0"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"A"_ustr, u"99"_ustr)); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"00ABC2"_ustr, u"00ABC1"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"00ABC1"_ustr, u"00ABC2"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare(u"00ABC11"_ustr, u"00ABC2"_ustr)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare(u"00ABC2"_ustr, u"00ABC11"_ustr)); + } + + CPPUNIT_TEST_SUITE(TestStringNaturalCompare); + CPPUNIT_TEST(testNatural); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(TestStringNaturalCompare); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index 0619b873e0fb..93d2965941c9 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <iterator> + #include <comphelper/string.hxx> #include <cppuhelper/implbase.hxx> #include <com/sun/star/i18n/CharType.hpp> @@ -35,7 +39,6 @@ namespace { class TestString: public CppUnit::TestFixture { public: - void testNatural(); void testStripStart(); void testStripEnd(); void testStrip(); @@ -44,11 +47,11 @@ public: void testDecimalStringToNumber(); void testIsdigitAsciiString(); void testReverseString(); + void testReverseCodePoints(); void testSplit(); void testRemoveAny(); CPPUNIT_TEST_SUITE(TestString); - CPPUNIT_TEST(testNatural); CPPUNIT_TEST(testStripStart); CPPUNIT_TEST(testStripEnd); CPPUNIT_TEST(testStrip); @@ -57,6 +60,7 @@ public: CPPUNIT_TEST(testDecimalStringToNumber); CPPUNIT_TEST(testIsdigitAsciiString); CPPUNIT_TEST(testReverseString); + CPPUNIT_TEST(testReverseCodePoints); CPPUNIT_TEST(testSplit); CPPUNIT_TEST(testRemoveAny); CPPUNIT_TEST_SUITE_END(); @@ -64,12 +68,12 @@ public: void TestString::testDecimalStringToNumber() { - OUString s1("1234"); + OUString s1(u"1234"_ustr); CPPUNIT_ASSERT_EQUAL(sal_uInt32(1234), comphelper::string::decimalStringToNumber(s1)); s1 += u"\u07C6"; CPPUNIT_ASSERT_EQUAL(sal_uInt32(12346), comphelper::string::decimalStringToNumber(s1)); // Codepoints on 2 16bits words - s1 = u"\U0001D7FE\U0001D7F7"; // MATHEMATICAL MONOSPACE DIGIT EIGHT and ONE + s1 = u"\U0001D7FE\U0001D7F7"_ustr; // MATHEMATICAL MONOSPACE DIGIT EIGHT and ONE CPPUNIT_ASSERT_EQUAL(sal_uInt32(81), comphelper::string::decimalStringToNumber(s1)); } @@ -82,268 +86,82 @@ void TestString::testIsdigitAsciiString() CPPUNIT_ASSERT_EQUAL(true, comphelper::string::isdigitAsciiString("")); } -using namespace ::com::sun::star; - -class testCollator : public cppu::WeakImplHelper< i18n::XCollator > -{ -public: - virtual sal_Int32 SAL_CALL compareSubstring( - const OUString& str1, sal_Int32 off1, sal_Int32 len1, - const OUString& str2, sal_Int32 off2, sal_Int32 len2) override - { - return str1.copy(off1, len1).compareTo(str2.subView(off2, len2)); - } - virtual sal_Int32 SAL_CALL compareString( - const OUString& str1, - const OUString& str2) override - { - return str1.compareTo(str2); - } - virtual sal_Int32 SAL_CALL loadDefaultCollator(const lang::Locale&, sal_Int32) override {return 0;} - virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(const OUString&, - const lang::Locale&, sal_Int32) override {return 0;} - virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption(const OUString&, - const lang::Locale&, const uno::Sequence< sal_Int32 >&) override {} - virtual uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms(const lang::Locale&) override - { - return uno::Sequence< OUString >(); - } - virtual uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions(const OUString&) override - { - return uno::Sequence< sal_Int32 >(); - } -}; - -#define IS_DIGIT(CHAR) (((CHAR) >= 48) && ((CHAR <= 57))) - -class testBreakIterator : public cppu::WeakImplHelper< i18n::XBreakIterator > -{ -public: - virtual sal_Int32 SAL_CALL nextCharacters( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) override {return -1;} - virtual sal_Int32 SAL_CALL previousCharacters( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& ) override {return -1;} - - virtual i18n::Boundary SAL_CALL previousWord( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16) override - { return i18n::Boundary(); } - virtual i18n::Boundary SAL_CALL nextWord( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16) override - { return i18n::Boundary(); } - virtual i18n::Boundary SAL_CALL getWordBoundary( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16, sal_Bool ) override - { return i18n::Boundary(); } - - virtual sal_Bool SAL_CALL isBeginWord( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) override - { return false; } - virtual sal_Bool SAL_CALL isEndWord( const OUString&, sal_Int32, - const lang::Locale& , sal_Int16 ) override - { return false; } - virtual sal_Int16 SAL_CALL getWordType( const OUString&, sal_Int32, - const lang::Locale& ) override - { return 0; } - - virtual sal_Int32 SAL_CALL beginOfSentence( const OUString&, sal_Int32, - const lang::Locale& ) override - { return 0; } - virtual sal_Int32 SAL_CALL endOfSentence( const OUString& rText, sal_Int32, - const lang::Locale& ) override - { return rText.getLength(); } - - virtual i18n::LineBreakResults SAL_CALL getLineBreak( const OUString&, sal_Int32, - const lang::Locale&, sal_Int32, - const i18n::LineBreakHyphenationOptions&, - const i18n::LineBreakUserOptions&) override - { - return i18n::LineBreakResults(); - } - - virtual sal_Int16 SAL_CALL getScriptType( const OUString&, sal_Int32 ) override { return -1; } - virtual sal_Int32 SAL_CALL beginOfScript( const OUString&, sal_Int32, - sal_Int16 ) override { return -1; } - virtual sal_Int32 SAL_CALL endOfScript( const OUString&, sal_Int32, - sal_Int16 ) override { return -1; } - virtual sal_Int32 SAL_CALL previousScript( const OUString&, sal_Int32, - sal_Int16 ) override { return -1; } - virtual sal_Int32 SAL_CALL nextScript( const OUString&, sal_Int32, - sal_Int16 ) override { return -1; } - - virtual sal_Int32 SAL_CALL beginOfCharBlock( const OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) override { return -1; } - virtual sal_Int32 SAL_CALL endOfCharBlock( const OUString& rText, sal_Int32 nStartPos, - const lang::Locale&, sal_Int16 CharType ) override - { - const sal_Unicode *pStr = rText.getStr()+nStartPos; - for (sal_Int32 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 OUString&, sal_Int32, - const lang::Locale&, sal_Int16 ) override { return -1; } - virtual sal_Int32 SAL_CALL nextCharBlock( const OUString& rText, sal_Int32 nStartPos, - const lang::Locale&, sal_Int16 CharType ) override - { - const sal_Unicode *pStr = rText.getStr()+nStartPos; - for (sal_Int32 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_EQUAL( - static_cast<sal_Int32>(0), compareNatural("ABC", "ABC", xCollator, xBI, lang::Locale()) - ); - // Case sensitivity - CPPUNIT_ASSERT( - compareNatural("ABC", "abc", xCollator, xBI, lang::Locale()) < 0 - ); - // Reverse - CPPUNIT_ASSERT( - compareNatural("abc", "ABC", xCollator, xBI, lang::Locale()) > 0 - ); - // First shorter - CPPUNIT_ASSERT( - compareNatural("alongstring", "alongerstring", xCollator, xBI, lang::Locale()) > 0 - ); - // Second shorter - CPPUNIT_ASSERT( - compareNatural("alongerstring", "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("Heading 9", "Heading 10", xCollator, xBI, lang::Locale()) < 0 - ); - // Original behavior - CPPUNIT_ASSERT( - OUString("Heading 9").compareTo(u"Heading 10") > 0 - ); - CPPUNIT_ASSERT( - compareNatural("Heading 10", "Heading 9", xCollator, xBI, lang::Locale()) > 0 - ); - // Harder - CPPUNIT_ASSERT( - compareNatural("July, the 4th", "July, the 10th", xCollator, xBI, lang::Locale()) < 0 - ); - CPPUNIT_ASSERT( - OUString("July, the 4th").compareTo(u"July, the 10th") > 0 - ); - CPPUNIT_ASSERT( - compareNatural("July, the 10th", "July, the 4th", xCollator, xBI, lang::Locale()) > 0 - ); - // Hardest - CPPUNIT_ASSERT( - compareNatural("abc08", "abc010", xCollator, xBI, lang::Locale()) < 0 - ); - CPPUNIT_ASSERT( - OUString("abc08").compareTo(u"abc010") > 0 - ); - CPPUNIT_ASSERT( - compareNatural("abc010", "abc08", xCollator, xBI, lang::Locale()) > 0 - ); - CPPUNIT_ASSERT_EQUAL( - static_cast<sal_Int32>(0), compareNatural("apple10apple", "apple10apple", xCollator, xBI, lang::Locale()) - ); -} - void TestString::testStripStart() { - OString aIn("abc"); + OString aIn("abc"_ostr); OString aOut; aOut = ::comphelper::string::stripStart(aIn, 'b'); - CPPUNIT_ASSERT_EQUAL(OString("abc"), aOut); + CPPUNIT_ASSERT_EQUAL("abc"_ostr, aOut); aOut = ::comphelper::string::stripStart(aIn, 'a'); - CPPUNIT_ASSERT_EQUAL(OString("bc"), aOut); + CPPUNIT_ASSERT_EQUAL("bc"_ostr, aOut); - aIn = "aaa"; + aIn = "aaa"_ostr; aOut = ::comphelper::string::stripStart(aIn, 'a'); CPPUNIT_ASSERT(aOut.isEmpty()); - aIn = "aba"; + aIn = "aba"_ostr; aOut = ::comphelper::string::stripStart(aIn, 'a'); - CPPUNIT_ASSERT_EQUAL(OString("ba"), aOut); + CPPUNIT_ASSERT_EQUAL("ba"_ostr, aOut); } void TestString::testStripEnd() { - OString aIn("abc"); + OString aIn("abc"_ostr); OString aOut; aOut = ::comphelper::string::stripEnd(aIn, 'b'); - CPPUNIT_ASSERT_EQUAL(OString("abc"), aOut); + CPPUNIT_ASSERT_EQUAL("abc"_ostr, aOut); aOut = ::comphelper::string::stripEnd(aIn, 'c'); - CPPUNIT_ASSERT_EQUAL(OString("ab"), aOut); + CPPUNIT_ASSERT_EQUAL("ab"_ostr, aOut); - aIn = "aaa"; + aIn = "aaa"_ostr; aOut = ::comphelper::string::stripEnd(aIn, 'a'); CPPUNIT_ASSERT(aOut.isEmpty()); - aIn = "aba"; + aIn = "aba"_ostr; aOut = ::comphelper::string::stripEnd(aIn, 'a'); - CPPUNIT_ASSERT_EQUAL(OString("ab"), aOut); + CPPUNIT_ASSERT_EQUAL("ab"_ostr, aOut); } void TestString::testStrip() { - OString aIn("abc"); + OString aIn("abc"_ostr); OString aOut; aOut = ::comphelper::string::strip(aIn, 'b'); - CPPUNIT_ASSERT_EQUAL(OString("abc"), aOut); + CPPUNIT_ASSERT_EQUAL("abc"_ostr, aOut); aOut = ::comphelper::string::strip(aIn, 'c'); - CPPUNIT_ASSERT_EQUAL(OString("ab"), aOut); + CPPUNIT_ASSERT_EQUAL("ab"_ostr, aOut); - aIn = "aaa"; + aIn = "aaa"_ostr; aOut = ::comphelper::string::strip(aIn, 'a'); CPPUNIT_ASSERT(aOut.isEmpty()); - aIn = "aba"; + aIn = "aba"_ostr; aOut = ::comphelper::string::strip(aIn, 'a'); - CPPUNIT_ASSERT_EQUAL(OString("b"), aOut); + CPPUNIT_ASSERT_EQUAL("b"_ostr, aOut); } void TestString::testToken() { - OString aIn("10.11.12"); + OString aIn("10.11.12"_ostr); OString aOut; aOut = aIn.getToken(-1, '.'); CPPUNIT_ASSERT(aOut.isEmpty()); aOut = aIn.getToken(0, '.'); - CPPUNIT_ASSERT_EQUAL(OString("10"), aOut); + CPPUNIT_ASSERT_EQUAL("10"_ostr, aOut); aOut = aIn.getToken(1, '.'); - CPPUNIT_ASSERT_EQUAL(OString("11"), aOut); + CPPUNIT_ASSERT_EQUAL("11"_ostr, aOut); aOut = aIn.getToken(2, '.'); - CPPUNIT_ASSERT_EQUAL(OString("12"), aOut); + CPPUNIT_ASSERT_EQUAL("12"_ostr, aOut); aOut = aIn.getToken(3, '.'); CPPUNIT_ASSERT(aOut.isEmpty()); @@ -351,7 +169,7 @@ void TestString::testToken() void TestString::testTokenCount() { - OString aIn("10.11.12"); + OString aIn("10.11.12"_ostr); sal_Int32 nOut; nOut = ::comphelper::string::getTokenCount(aIn, '.'); @@ -366,34 +184,53 @@ void TestString::testTokenCount() void TestString::testReverseString() { - OString aOut = ::comphelper::string::reverseString("ABC"); + CPPUNIT_ASSERT_EQUAL(OUString(), comphelper::string::reverseString(u"")); + CPPUNIT_ASSERT_EQUAL(u"cba"_ustr, comphelper::string::reverseString(u"abc")); + static sal_Unicode const rev[] = {'w', 0xDFFF, 0xDBFF, 'v', 0xDC00, 0xD800, 'u'}; + CPPUNIT_ASSERT_EQUAL( + OUString(rev, std::size(rev)), + comphelper::string::reverseString(u"u\U00010000v\U0010FFFFw")); + static sal_Unicode const malformed[] = {0xDC00, 0xD800}; + CPPUNIT_ASSERT_EQUAL( + u"\U00010000"_ustr, + comphelper::string::reverseString(std::u16string_view(malformed, std::size(malformed)))); +} - CPPUNIT_ASSERT_EQUAL(OString("CBA"), aOut); +void TestString::testReverseCodePoints() { + CPPUNIT_ASSERT_EQUAL(OUString(), comphelper::string::reverseCodePoints(u"")); + CPPUNIT_ASSERT_EQUAL(u"cba"_ustr, comphelper::string::reverseCodePoints(u"abc")); + CPPUNIT_ASSERT_EQUAL( + u"w\U0010FFFFv\U00010000u"_ustr, + comphelper::string::reverseCodePoints(u"u\U00010000v\U0010FFFFw")); + static sal_Unicode const malformed[] = {0xDC00, 0xD800}; + CPPUNIT_ASSERT_EQUAL( + u"\U00010000"_ustr, + comphelper::string::reverseCodePoints(std::u16string_view(malformed, std::size(malformed)))); } void TestString::testSplit() { - std::vector<OUString> aRet = ::comphelper::string::split("CTRL+ALT+F1", '+'); + std::vector<OUString> aRet = ::comphelper::string::split(u"CTRL+ALT+F1", '+'); CPPUNIT_ASSERT_EQUAL(size_t(3), aRet.size()); - CPPUNIT_ASSERT_EQUAL(OUString("CTRL"), aRet[0]); - CPPUNIT_ASSERT_EQUAL(OUString("ALT"), aRet[1]); - CPPUNIT_ASSERT_EQUAL(OUString("F1"), aRet[2]); + CPPUNIT_ASSERT_EQUAL(u"CTRL"_ustr, aRet[0]); + CPPUNIT_ASSERT_EQUAL(u"ALT"_ustr, aRet[1]); + CPPUNIT_ASSERT_EQUAL(u"F1"_ustr, aRet[2]); } void TestString::testRemoveAny() { using namespace ::comphelper::string; - OUString in("abcAAAbbC"); + OUString in(u"abcAAAbbC"_ustr); sal_Unicode const test1 [] = { 'a', 0 }; - CPPUNIT_ASSERT_EQUAL(OUString("bcAAAbbC"), removeAny(in, test1)); + CPPUNIT_ASSERT_EQUAL(u"bcAAAbbC"_ustr, removeAny(in, test1)); sal_Unicode const test2 [] = { 0 }; CPPUNIT_ASSERT_EQUAL(in, removeAny(in, test2)); sal_Unicode const test3 [] = { 'A', 0 }; - CPPUNIT_ASSERT_EQUAL(OUString("abcbbC"), removeAny(in, test3)); + CPPUNIT_ASSERT_EQUAL(u"abcbbC"_ustr, removeAny(in, test3)); sal_Unicode const test4 [] = { 'A', 'a', 0 }; - CPPUNIT_ASSERT_EQUAL(OUString("bcbbC"), removeAny(in, test4)); + CPPUNIT_ASSERT_EQUAL(u"bcbbC"_ustr, removeAny(in, test4)); sal_Unicode const test5 [] = { 'C', 0 }; - CPPUNIT_ASSERT_EQUAL(OUString("abcAAAbb"), removeAny(in, test5)); + CPPUNIT_ASSERT_EQUAL(u"abcAAAbb"_ustr, removeAny(in, test5)); sal_Unicode const test6 [] = { 'X', 0 }; CPPUNIT_ASSERT_EQUAL(in, removeAny(in, test6)); sal_Unicode const test7 [] = { 'A', 'B', 'C', 'a', 'b', 'c', 0 }; diff --git a/comphelper/qa/unit/base64_test.cxx b/comphelper/qa/unit/base64_test.cxx index a1cd5d0006be..f589e1809dd0 100644 --- a/comphelper/qa/unit/base64_test.cxx +++ b/comphelper/qa/unit/base64_test.cxx @@ -53,17 +53,17 @@ void Base64Test::testBase64Encode() inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OUString("AAAAAAABAgM="), aBuffer.toString()); + CPPUNIT_ASSERT_EQUAL(u"AAAAAAABAgM="_ustr, aBuffer.toString()); aBuffer.setLength(0); inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OUString("BQIDAAABAgM="), aBuffer.toString()); + CPPUNIT_ASSERT_EQUAL(u"BQIDAAABAgM="_ustr, aBuffer.toString()); aBuffer.setLength(0); inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OUString("yB9NbwABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL(u"yB9NbwABAgM="_ustr, aBuffer.makeStringAndClear()); } void Base64Test::testBase64Decode() @@ -93,17 +93,17 @@ void Base64Test::testBase64EncodeForOStringBuffer() inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OString("AAAAAAABAgM="), aBuffer.toString()); + CPPUNIT_ASSERT_EQUAL("AAAAAAABAgM="_ostr, aBuffer.toString()); aBuffer.setLength(0); inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OString("BQIDAAABAgM="), aBuffer.toString()); + CPPUNIT_ASSERT_EQUAL("BQIDAAABAgM="_ostr, aBuffer.toString()); aBuffer.setLength(0); inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 }; comphelper::Base64::encode(aBuffer, inputSequence); - CPPUNIT_ASSERT_EQUAL(OString("yB9NbwABAgM="), aBuffer.makeStringAndClear()); + CPPUNIT_ASSERT_EQUAL("yB9NbwABAgM="_ostr, aBuffer.makeStringAndClear()); } CPPUNIT_TEST_SUITE_REGISTRATION(Base64Test); diff --git a/comphelper/qa/unit/propertyvalue.cxx b/comphelper/qa/unit/propertyvalue.cxx index 40f60bb0463d..877a964478ac 100644 --- a/comphelper/qa/unit/propertyvalue.cxx +++ b/comphelper/qa/unit/propertyvalue.cxx @@ -14,9 +14,12 @@ #include <cppunit/extensions/HelperMacros.h> #include <comphelper/propertyvalue.hxx> +#include <comphelper/propertysequence.hxx> #include <cppu/unotype.hxx> #include <o3tl/any.hxx> +using namespace com::sun::star; + namespace { class MakePropertyValueTest : public CppUnit::TestFixture @@ -25,19 +28,20 @@ class MakePropertyValueTest : public CppUnit::TestFixture CPPUNIT_TEST(testLvalue); CPPUNIT_TEST(testRvalue); CPPUNIT_TEST(testBitField); + CPPUNIT_TEST(testJson); CPPUNIT_TEST_SUITE_END(); void testLvalue() { sal_Int32 const i = 123; - auto const v = comphelper::makePropertyValue("test", i); + auto const v = comphelper::makePropertyValue(u"test"_ustr, i); CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), v.Value.getValueType()); CPPUNIT_ASSERT_EQUAL(sal_Int32(123), *o3tl::doAccess<sal_Int32>(v.Value)); } void testRvalue() { - auto const v = comphelper::makePropertyValue("test", sal_Int32(456)); + auto const v = comphelper::makePropertyValue(u"test"_ustr, sal_Int32(456)); CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), v.Value.getValueType()); CPPUNIT_ASSERT_EQUAL(sal_Int32(456), *o3tl::doAccess<sal_Int32>(v.Value)); } @@ -48,10 +52,77 @@ class MakePropertyValueTest : public CppUnit::TestFixture { bool b : 1; } s = { false }; - auto const v = comphelper::makePropertyValue("test", s.b); + auto const v = comphelper::makePropertyValue(u"test"_ustr, s.b); CPPUNIT_ASSERT_EQUAL(cppu::UnoType<bool>::get(), v.Value.getValueType()); CPPUNIT_ASSERT_EQUAL(false, *o3tl::doAccess<bool>(v.Value)); } + + void testJson() + { + std::vector<beans::PropertyValue> aRet = comphelper::JsonToPropertyValues(R"json( +{ + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommandPrefix": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM" + }, + "Fields": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommand": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM new command 1" + }, + "Fields": { + "type": "string", + "value": "new result 1" + } + }, + { + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommandPrefix": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM new command 2" + }, + "Fields": { + "type": "string", + "value": "new result 2" + } + } + ] + } +} +)json"_ostr); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aRet.size()); + beans::PropertyValue aFirst = aRet[0]; + CPPUNIT_ASSERT_EQUAL(u"FieldType"_ustr, aFirst.Name); + CPPUNIT_ASSERT_EQUAL(u"vnd.oasis.opendocument.field.UNHANDLED"_ustr, + aFirst.Value.get<OUString>()); + beans::PropertyValue aSecond = aRet[1]; + CPPUNIT_ASSERT_EQUAL(u"FieldCommandPrefix"_ustr, aSecond.Name); + CPPUNIT_ASSERT_EQUAL(u"ADDIN ZOTERO_ITEM"_ustr, aSecond.Value.get<OUString>()); + beans::PropertyValue aThird = aRet[2]; + CPPUNIT_ASSERT_EQUAL(u"Fields"_ustr, aThird.Name); + uno::Sequence<uno::Sequence<beans::PropertyValue>> aSeqs; + aThird.Value >>= aSeqs; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeqs.getLength()); + uno::Sequence<beans::PropertyValue> aFirstSeq = aSeqs[0]; + CPPUNIT_ASSERT_EQUAL(u"FieldType"_ustr, aFirstSeq[0].Name); + CPPUNIT_ASSERT_EQUAL(u"FieldCommand"_ustr, aFirstSeq[1].Name); + CPPUNIT_ASSERT_EQUAL(u"ADDIN ZOTERO_ITEM new command 1"_ustr, + aFirstSeq[1].Value.get<OUString>()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest); diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx index c28941339085..e838c0c9886d 100644 --- a/comphelper/qa/unit/syntaxhighlighttest.cxx +++ b/comphelper/qa/unit/syntaxhighlighttest.cxx @@ -38,7 +38,7 @@ public: void SyntaxHighlightTest::testBasicString() { std::vector<HighlightPortion> ps; - SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions("\"foo\"", ps); + SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"\"foo\"", ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); @@ -48,7 +48,7 @@ void SyntaxHighlightTest::testBasicString() { void SyntaxHighlightTest::testBasicComment() { std::vector<HighlightPortion> ps; - SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions("' foo", ps); + SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"' foo", ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); @@ -58,7 +58,7 @@ void SyntaxHighlightTest::testBasicComment() { void SyntaxHighlightTest::testBasicCommentNewline() { std::vector<HighlightPortion> ps; - SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions("' foo\n", ps); + SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"' foo\n", ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); @@ -71,7 +71,7 @@ void SyntaxHighlightTest::testBasicCommentNewline() { void SyntaxHighlightTest::testBasicEmptyComment() { std::vector<HighlightPortion> ps; - SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions("'", ps); + SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"'", ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); @@ -81,7 +81,7 @@ void SyntaxHighlightTest::testBasicEmptyComment() { void SyntaxHighlightTest::testBasicEmptyCommentNewline() { std::vector<HighlightPortion> ps; - SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions("'\n", ps); + SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions(u"'\n", ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); @@ -94,7 +94,7 @@ void SyntaxHighlightTest::testBasicEmptyCommentNewline() { void SyntaxHighlightTest::testBasic() { - OUString aBasicString(" if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '"); + OUString aBasicString(u" if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '"_ustr); std::vector<HighlightPortion> aPortions; SyntaxHighlighter(HighlighterLanguage::Basic).getHighlightPortions( diff --git a/comphelper/qa/unit/test_guards.cxx b/comphelper/qa/unit/test_guards.cxx index 02daffaa521b..83034a2dcc6a 100644 --- a/comphelper/qa/unit/test_guards.cxx +++ b/comphelper/qa/unit/test_guards.cxx @@ -10,42 +10,50 @@ #include <comphelper/flagguard.hxx> #include <unotest/bootstrapfixturebase.hxx> -CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, test_comphelperGuards) +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testScopeGuard) { + // Test that comphelper::ScopeGuard executes its parameter on destruction + + // initial value "true", out-of-scope ScopeGuard function executes and changes the value to "false" bool bFlag = true; { - // Test that comphelper::ScopeGuard executes its parameter on destruction comphelper::ScopeGuard aGuard([&bFlag] { bFlag = false; }); CPPUNIT_ASSERT(bFlag); } CPPUNIT_ASSERT(!bFlag); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testFlagGuard) +{ + // Test that comphelper::FlagGuard properly sets and resets the flag + // initial value "false", change to "true", out-of-scope change to "false" + bool bFlag = false; { - // Test that comphelper::FlagGuard properly sets and resets the flag comphelper::FlagGuard aGuard(bFlag); CPPUNIT_ASSERT(bFlag); } + // comphelper::FlagGuard must reset flag to false on destruction unconditionally CPPUNIT_ASSERT(!bFlag); + // initial value "true", retain the value at "true", out-of-scope change to "false" bFlag = true; { - // Test that comphelper::FlagGuard properly sets and resets the flag comphelper::FlagGuard aGuard(bFlag); CPPUNIT_ASSERT(bFlag); } // comphelper::FlagGuard must reset flag to false on destruction unconditionally CPPUNIT_ASSERT(!bFlag); +} - { - // Test that comphelper::FlagRestorationGuard properly sets and resets the flag - comphelper::FlagRestorationGuard aGuard(bFlag, true); - CPPUNIT_ASSERT(bFlag); - } - CPPUNIT_ASSERT(!bFlag); +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testFlagRestorationGuard) +{ + // Test that comphelper::FlagRestorationGuard properly sets and resets the flag - bFlag = true; + // initial value "true", change to "false", out-of-scope change to "true" + + bool bFlag = true; { - // Test that comphelper::FlagRestorationGuard properly sets and resets the flag comphelper::FlagRestorationGuard aGuard(bFlag, false); CPPUNIT_ASSERT(!bFlag); } @@ -53,4 +61,28 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, test_comphelperGuards) CPPUNIT_ASSERT(bFlag); } +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testValueRestorationGuard) +{ + // Test that comphelper::ValueRestorationGuard properly sets and resets the (int) value + + int value = 199; + + // set value and restore after scope ends + { + CPPUNIT_ASSERT_EQUAL(199, value); + comphelper::ValueRestorationGuard aGuard(value, 100); + CPPUNIT_ASSERT_EQUAL(100, value); + } + CPPUNIT_ASSERT_EQUAL(199, value); + + // set value, manually setto another value and restore after scope ends + { + CPPUNIT_ASSERT_EQUAL(199, value); + comphelper::ValueRestorationGuard aGuard(value, 100); + CPPUNIT_ASSERT_EQUAL(100, value); + value = 200; + } + CPPUNIT_ASSERT_EQUAL(199, value); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx index 64815ee56dc8..dc96a03318ef 100644 --- a/comphelper/qa/unit/test_hash.cxx +++ b/comphelper/qa/unit/test_hash.cxx @@ -120,9 +120,9 @@ void TestHash::testSHA512_NoSaltNoSpin() // tdf#104250 https://bugs.documentfoundation.org/attachment.cgi?id=129104 void TestHash::testSHA512_saltspin() { - const OUString aHash = comphelper::DocPasswordHelper::GetOoxHashAsBase64( "pwd", u"876MLoKTq42+/DLp415iZQ==", 100000, + const OUString aHash = comphelper::DocPasswordHelper::GetOoxHashAsBase64( u"pwd"_ustr, u"876MLoKTq42+/DLp415iZQ==", 100000, comphelper::Hash::IterCount::APPEND, u"SHA-512"); - CPPUNIT_ASSERT_EQUAL(OUString("5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="), aHash); + CPPUNIT_ASSERT_EQUAL(u"5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="_ustr, aHash); } CPPUNIT_TEST_SUITE_REGISTRATION(TestHash); diff --git a/comphelper/qa/unit/threadpooltest.cxx b/comphelper/qa/unit/threadpooltest.cxx index 14da59988ef4..13eaf210a18b 100644 --- a/comphelper/qa/unit/threadpooltest.cxx +++ b/comphelper/qa/unit/threadpooltest.cxx @@ -17,6 +17,7 @@ #include <stdlib.h> #include <atomic> +#include <cstddef> #include <thread> #include <mutex> @@ -42,7 +43,7 @@ void ThreadPoolTest::testPreferredConcurrency() { // Check default. auto nThreads = comphelper::ThreadPool::getPreferredConcurrency(); - sal_Int32 nExpected = 4; // UTs are capped to 4. + std::size_t nExpected = 4; // UTs are capped to 4. CPPUNIT_ASSERT_MESSAGE("Expected no more than 4 threads", nExpected >= nThreads); #ifndef _WIN32 @@ -51,7 +52,7 @@ void ThreadPoolTest::testPreferredConcurrency() setenv("MAX_CONCURRENCY", std::to_string(nThreads).c_str(), true); nThreads = comphelper::ThreadPool::getPreferredConcurrency(); CPPUNIT_ASSERT_MESSAGE("Expected no more than hardware threads", - nThreads <= static_cast<sal_Int32>(std::thread::hardware_concurrency())); + nThreads <= std::thread::hardware_concurrency()); // Revert and check. Again, nothing should change. unsetenv("MAX_CONCURRENCY"); diff --git a/comphelper/qa/unit/types_test.cxx b/comphelper/qa/unit/types_test.cxx index a0f136a5f49f..d647748e06be 100644 --- a/comphelper/qa/unit/types_test.cxx +++ b/comphelper/qa/unit/types_test.cxx @@ -42,7 +42,7 @@ public: void TypesTest::testGetINT64() { - CPPUNIT_ASSERT_EQUAL(sal_Int64(1337), ::comphelper::getINT64(uno::makeAny(sal_Int64(1337)))); + CPPUNIT_ASSERT_EQUAL(sal_Int64(1337), ::comphelper::getINT64(uno::Any(sal_Int64(1337)))); uno::Any aValue; CPPUNIT_ASSERT_EQUAL(sal_Int64(0), ::comphelper::getINT64(aValue)); @@ -50,7 +50,7 @@ void TypesTest::testGetINT64() void TypesTest::testGetINT32() { - CPPUNIT_ASSERT_EQUAL(sal_Int32(1337), ::comphelper::getINT32(uno::makeAny(sal_Int32(1337)))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1337), ::comphelper::getINT32(uno::Any(sal_Int32(1337)))); uno::Any aValue; CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ::comphelper::getINT32(aValue)); @@ -58,7 +58,7 @@ void TypesTest::testGetINT32() void TypesTest::testGetINT16() { - CPPUNIT_ASSERT_EQUAL(sal_Int16(1337), ::comphelper::getINT16(uno::makeAny(sal_Int16(1337)))); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1337), ::comphelper::getINT16(uno::Any(sal_Int16(1337)))); uno::Any aValue; CPPUNIT_ASSERT_EQUAL(sal_Int16(0), ::comphelper::getINT16(aValue)); @@ -66,7 +66,7 @@ void TypesTest::testGetINT16() void TypesTest::testGetDouble() { - CPPUNIT_ASSERT_EQUAL(1337.1337, ::comphelper::getDouble(uno::makeAny(1337.1337))); + CPPUNIT_ASSERT_EQUAL(1337.1337, ::comphelper::getDouble(uno::Any(1337.1337))); uno::Any aValue; CPPUNIT_ASSERT_EQUAL(0.0, ::comphelper::getDouble(aValue)); @@ -75,7 +75,7 @@ void TypesTest::testGetDouble() void TypesTest::testGetFloat() { CPPUNIT_ASSERT_EQUAL(static_cast<float>(1337.0), - ::comphelper::getFloat(uno::makeAny(static_cast<float>(1337.0)))); + ::comphelper::getFloat(uno::Any(static_cast<float>(1337.0)))); uno::Any aValue; CPPUNIT_ASSERT_EQUAL(static_cast<float>(0.0), ::comphelper::getFloat(aValue)); @@ -83,10 +83,10 @@ void TypesTest::testGetFloat() void TypesTest::testGetString() { - CPPUNIT_ASSERT_EQUAL(OUString("1337"), ::comphelper::getString(uno::makeAny(OUString("1337")))); + CPPUNIT_ASSERT_EQUAL(u"1337"_ustr, ::comphelper::getString(uno::Any(u"1337"_ustr))); uno::Any aValue; - CPPUNIT_ASSERT_EQUAL(OUString(""), ::comphelper::getString(aValue)); + CPPUNIT_ASSERT_EQUAL(u""_ustr, ::comphelper::getString(aValue)); } CPPUNIT_TEST_SUITE_REGISTRATION(TypesTest); diff --git a/comphelper/qa/unit/variadictemplates.cxx b/comphelper/qa/unit/variadictemplates.cxx index e729d76b24ed..48ed59faab78 100644 --- a/comphelper/qa/unit/variadictemplates.cxx +++ b/comphelper/qa/unit/variadictemplates.cxx @@ -40,7 +40,7 @@ void extract( { if (nArg >= seq.getLength()) { throw ::com::sun::star::lang::IllegalArgumentException( - "No such argument available!", + u"No such argument available!"_ustr, xErrorContext, static_cast<sal_Int16>(nArg) ); } if (! fromAny(seq[nArg], &v)) { @@ -87,26 +87,26 @@ void unwrapArgsBaseline( } void VariadicTemplatesTest::testUnwrapArgs() { - OUString tmp1 = "Test1"; + OUString tmp1 = u"Test1"_ustr; sal_Int32 tmp2 = 42; sal_uInt32 tmp3 = 42; ::com::sun::star::uno::Any tmp6( - ::com::sun::star::uno::makeAny( tmp1 ) + tmp1 ); ::com::sun::star::uno::Any tmp7( - ::com::sun::star::uno::makeAny( tmp2 ) + tmp2 ); ::com::sun::star::uno::Any tmp8( - ::com::sun::star::uno::makeAny( tmp3 ) + tmp3 ); ::com::sun::star::uno::Any tmp9( - ::com::sun::star::uno::makeAny( OUString("Test2") ) + u"Test2"_ustr ); ::std::optional< ::com::sun::star::uno::Any > tmp10( - ::com::sun::star::uno::makeAny( OUString("Test3") ) + u"Test3"_ustr ); ::std::optional< ::com::sun::star::uno::Any > tmp11( - ::com::sun::star::uno::makeAny( tmp1 ) + tmp1 ); // test equality with the baseline and template specialization with @@ -147,11 +147,11 @@ void VariadicTemplatesTest::testUnwrapArgs() { CPPUNIT_ASSERT_EQUAL( static_cast< short >( 5 ), err.ArgumentPosition ); } - OUString test1( "Test2" ); - OUString test2( "Test2" ); - OUString test3( "Test3" ); - OUString test4( "Test4" ); - OUString test5( "Test5" ); + OUString test1( u"Test2"_ustr ); + OUString test2( u"Test2"_ustr ); + OUString test3( u"Test3"_ustr ); + OUString test4( u"Test4"_ustr ); + OUString test5( u"Test5"_ustr ); try { ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > seq( diff --git a/comphelper/qa/weakbag/makefile.mk b/comphelper/qa/weakbag/makefile.mk deleted file mode 100644 index 495c68f5063d..000000000000 --- a/comphelper/qa/weakbag/makefile.mk +++ /dev/null @@ -1,44 +0,0 @@ -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This file incorporates work covered by the following license notice: -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed -# with this work for additional information regarding copyright -# ownership. The ASF licenses this file to you under the Apache -# License, Version 2.0 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 . -# - -PRJ := ..$/.. -PRJNAME := comphelper -TARGET := qa_weakbag - -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 index b646ca7aef42..10e10cd7da85 100644 --- a/comphelper/qa/weakbag/test_weakbag.cxx +++ b/comphelper/qa/weakbag/test_weakbag.cxx @@ -28,7 +28,8 @@ namespace { -class Test : public CppUnit::TestFixture +// Tests the behaviour of comphelper::WeakBag +class WeakBagTest : public CppUnit::TestFixture { public: void test() @@ -36,7 +37,9 @@ public: 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); @@ -44,18 +47,21 @@ public: 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_EQUAL_MESSAGE("remove first ref2", bag.remove(), ref2); + CPPUNIT_ASSERT_EQUAL_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_SUITE(WeakBagTest); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(Test); +CPPUNIT_TEST_SUITE_REGISTRATION(WeakBagTest); } +CPPUNIT_PLUGIN_IMPLEMENT(); + /* 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 deleted file mode 100644 index d2d66a61ea93..000000000000 --- a/comphelper/qa/weakbag/test_weakbag_noadditional.cxx +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> -#include <cppunit/plugin/TestPlugIn.h> - -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |