8a017d25a6
The scenarios are: 1. Calling sequence's begin() and end() in pairs to pass to algorithms (both calls use getArray(), which does the COW checks) 2. In addition to #1, calling end() again when checking result of find algorithms, and/or begin() to calculate result's distance 3. Using non-const sequences in range-based for loops, which internally do #1 4. Assigning sequence to another sequence variable, and then modifying one of them In many cases, the sequences could be made const, or treated as const for the purposes of the algorithms (using std::as_const, std::cbegin, and std::cend). Where algorithm modifies the sequence, it was changed to only call getArray() once. For that, css::uno::toNonConstRange was introduced, which returns a struct (sublclass of std::pair) with two iterators [begin, end], that are calculated using one call to begin() and one call to getLength(). To handle #4, css::uno::Sequence::swap was introduced, that swaps the internal pointer to uno_Sequence. So when a local Sequence variable should be assigned to another variable, and the latter will be modified further, it's now possible to use swap instead, so the two sequences are kept independent. The modified places were found by temporarily removing non-const end(). Change-Id: I8fe2787f200eecb70744e8b77fbdf7a49653f628 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123542 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
86 lines
2.6 KiB
C++
86 lines
2.6 KiB
C++
/* -*- 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/.
|
|
*/
|
|
#include <algorithm>
|
|
#include <com/sun/star/i18n/XOrdinalSuffix.hpp>
|
|
#include <com/sun/star/lang/Locale.hpp>
|
|
#include <unotest/bootstrapfixturebase.hxx>
|
|
|
|
using namespace com::sun::star;
|
|
|
|
class TestOrdinalSuffix : public test::BootstrapFixtureBase
|
|
{
|
|
private:
|
|
uno::Reference<i18n::XOrdinalSuffix> m_xOrdinal;
|
|
|
|
public:
|
|
virtual void setUp() override;
|
|
virtual void tearDown() override;
|
|
|
|
void testFrench();
|
|
void testEnglish();
|
|
|
|
CPPUNIT_TEST_SUITE(TestOrdinalSuffix);
|
|
CPPUNIT_TEST(testFrench);
|
|
CPPUNIT_TEST(testEnglish);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
};
|
|
|
|
void TestOrdinalSuffix::setUp()
|
|
{
|
|
BootstrapFixtureBase::setUp();
|
|
m_xOrdinal.set(m_xSFactory->createInstance("com.sun.star.i18n.OrdinalSuffix"), uno::UNO_QUERY_THROW);
|
|
}
|
|
|
|
void TestOrdinalSuffix::tearDown()
|
|
{
|
|
m_xOrdinal.clear();
|
|
BootstrapFixtureBase::tearDown();
|
|
}
|
|
|
|
void TestOrdinalSuffix::testFrench()
|
|
{
|
|
lang::Locale aLocale("fr", "LU", "");
|
|
|
|
//1er
|
|
uno::Sequence<OUString> aSuffixes = m_xOrdinal->getOrdinalSuffix(1, aLocale);
|
|
const OUString* pFind = std::find(std::cbegin(aSuffixes), std::cend(aSuffixes), OUString("er"));
|
|
CPPUNIT_ASSERT(pFind != std::cend(aSuffixes));
|
|
|
|
//2e, 3e, etc.
|
|
aSuffixes = m_xOrdinal->getOrdinalSuffix(2, aLocale);
|
|
pFind = std::find(std::cbegin(aSuffixes), std::cend(aSuffixes), OUString("e"));
|
|
CPPUNIT_ASSERT(pFind != std::cend(aSuffixes));
|
|
}
|
|
|
|
void TestOrdinalSuffix::testEnglish()
|
|
{
|
|
lang::Locale aLocale("en", "US", "");
|
|
|
|
//1st
|
|
uno::Sequence<OUString> aSuffixes = m_xOrdinal->getOrdinalSuffix(1, aLocale);
|
|
const OUString* pFind = std::find(std::cbegin(aSuffixes), std::cend(aSuffixes), OUString("st"));
|
|
CPPUNIT_ASSERT(pFind != std::cend(aSuffixes));
|
|
|
|
//2nd
|
|
aSuffixes = m_xOrdinal->getOrdinalSuffix(2, aLocale);
|
|
pFind = std::find(std::cbegin(aSuffixes), std::cend(aSuffixes), OUString("nd"));
|
|
CPPUNIT_ASSERT(pFind != std::cend(aSuffixes));
|
|
|
|
//3rd
|
|
aSuffixes = m_xOrdinal->getOrdinalSuffix(3, aLocale);
|
|
pFind = std::find(std::cbegin(aSuffixes), std::cend(aSuffixes), OUString("rd"));
|
|
CPPUNIT_ASSERT(pFind != std::cend(aSuffixes));
|
|
}
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestOrdinalSuffix );
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|