diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-09-08 22:18:05 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-09 09:23:09 +0100 |
commit | ebe0549d2688a4d44b6527993c7f6a1fc58c64cc (patch) | |
tree | da690f1c7360d6c5f0dab1e79a363bf9fed124fa | |
parent | 54f82edbc31ab2844140cd7126b688decd6df862 (diff) |
Add cppunit test for SwScanner that would have caught fdo#40449
Move SwScanner so it can be tested easily and add a unit test that would have
detected fdo#40449 in advance
-rw-r--r-- | sw/inc/swscanner.hxx | 81 | ||||
-rw-r--r-- | sw/qa/core/swdoc-test.cxx | 40 | ||||
-rw-r--r-- | sw/source/core/inc/scriptinfo.hxx | 47 |
3 files changed, 121 insertions, 47 deletions
diff --git a/sw/inc/swscanner.hxx b/sw/inc/swscanner.hxx new file mode 100644 index 000000000000..d1c6fe91e10f --- /dev/null +++ b/sw/inc/swscanner.hxx @@ -0,0 +1,81 @@ +/* -*- 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 + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _SWSCANNER_HXX +#define _SWSCANNER_HXX + +#include <i18npool/lang.h> +#include <modeltoviewhelper.hxx> + +class SwTxtNode; + +/************************************************************************* + * class SwScanner + * Hilfsklasse, die beim Spellen die Worte im gewuenschten Bereich + * nacheinander zur Verfuegung stellt. + *************************************************************************/ + +class SwScanner +{ + rtl::OUString aWord; + const SwTxtNode& rNode; + const rtl::OUString aText; + const LanguageType* pLanguage; + const ModelToViewHelper::ConversionMap* pConversionMap; + sal_Int32 nStartPos; + sal_Int32 nEndPos; + sal_Int32 nBegin; + sal_Int32 nLen; + LanguageType aCurrLang; + sal_uInt16 nWordType; + sal_Bool bClip; + +public: + SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt, + const LanguageType* pLang, + const ModelToViewHelper::ConversionMap* pConvMap, + sal_uInt16 nWordType, + sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClip = sal_False ); + + + // This next word function tries to find the language for the next word + // It should currently _not_ be used for spell checking, and works only for + // ! bReverse + sal_Bool NextWord(); + + const rtl::OUString& GetWord() const { return aWord; } + + sal_Int32 GetBegin() const { return nBegin; } + sal_Int32 GetEnd() const { return nBegin + nLen; } + sal_Int32 GetLen() const { return nLen; } + + LanguageType GetCurrentLanguage() const {return aCurrLang;} +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx index 2e53d2654e88..f87a2c239d67 100644 --- a/sw/qa/core/swdoc-test.cxx +++ b/sw/qa/core/swdoc-test.cxx @@ -57,9 +57,11 @@ #include "swtypes.hxx" #include "docstat.hxx" #include "doc.hxx" +#include "ndtxt.hxx" #include "docsh.hxx" #include "shellres.hxx" #include "docufld.hxx" +#include "swscanner.hxx" #include "swcrsr.hxx" #include "swmodule.hxx" @@ -83,12 +85,14 @@ public: void testPageDescName(); void testFileNameFields(); void testDocStat(); + void testSwScanner(); CPPUNIT_TEST_SUITE(SwDocTest); CPPUNIT_TEST(randomTest); CPPUNIT_TEST(testPageDescName); CPPUNIT_TEST(testFileNameFields); CPPUNIT_TEST(testDocStat); + CPPUNIT_TEST(testSwScanner); CPPUNIT_TEST_SUITE_END(); private: @@ -175,6 +179,9 @@ void SwDocTest::testFileNameFields() m_xDocShRef->DoInitNew(0); } +//See http://lists.freedesktop.org/archives/libreoffice/2011-August/016666.html +//Remove unnecessary parameter to IDocumentStatistics::UpdateDocStat for +//motivation void SwDocTest::testDocStat() { CPPUNIT_ASSERT_MESSAGE("Expected initial 0 count", m_pDoc->GetDocStat().nChar == 0); @@ -195,6 +202,36 @@ void SwDocTest::testDocStat() CPPUNIT_ASSERT_MESSAGE("And cache is updated too", m_pDoc->GetDocStat().nChar == nLen); } +//See https://bugs.freedesktop.org/show_bug.cgi?id=40449 for motivation +void SwDocTest::testSwScanner() +{ + SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1); + SwPaM aPaM(aIdx); + + const SwTxtNode* pTxtNode = aPaM.GetNode()->GetTxtNode(); + + CPPUNIT_ASSERT_MESSAGE("Has Text Node", pTxtNode); + + //Use a temporary rtl::OUString as the arg, as that's the trouble behind + //fdo#40449 and fdo#39365 + SwScanner aScanner(*pTxtNode, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello World")), + 0, 0, i18n::WordType::DICTIONARY_WORD, 0, + RTL_CONSTASCII_LENGTH("Hello World")); + + bool bFirstOk = aScanner.NextWord(); + CPPUNIT_ASSERT_MESSAGE("First Token", bFirstOk); + const rtl::OUString &rHello = aScanner.GetWord(); + CPPUNIT_ASSERT_MESSAGE("Should be Hello", + rHello.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Hello"))); + + bool bSecondOk = aScanner.NextWord(); + CPPUNIT_ASSERT_MESSAGE("Second Token", bSecondOk); + const rtl::OUString &rWorld = aScanner.GetWord(); + CPPUNIT_ASSERT_MESSAGE("Should be World", + rWorld.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("World"))); +} + static int getRand(int modulus) { @@ -206,7 +243,8 @@ getRand(int modulus) static rtl::OUString getRandString() { - static rtl::OUString aText( rtl::OUString::createFromAscii("AAAAA BBBB CCC DD E \n")); + static rtl::OUString aText(RTL_CONSTASCII_USTRINGPARAM( + "AAAAA BBBB CCC DD E \n")); int s = getRand(aText.getLength()); int j = getRand(aText.getLength() - s); rtl::OUString aRet(aText + s, j); diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx index f55c77ef733d..7dd98272e9b5 100644 --- a/sw/source/core/inc/scriptinfo.hxx +++ b/sw/source/core/inc/scriptinfo.hxx @@ -32,10 +32,8 @@ #define _SVSTDARR_XUB_STRLEN #include <svl/svstdarr.hxx> #endif -#include <i18npool/lang.h> #include <list> -#include <modeltoviewhelper.hxx> - +#include "swscanner.hxx" class SwTxtNode; class Point; @@ -46,49 +44,6 @@ typedef std::list< xub_StrLen > PositionList; #define SPACING_PRECISION_FACTOR 100 /************************************************************************* - * class SwScanner - * Hilfsklasse, die beim Spellen die Worte im gewuenschten Bereich - * nacheinander zur Verfuegung stellt. - *************************************************************************/ - -class SwScanner -{ - rtl::OUString aWord; - const SwTxtNode& rNode; - const rtl::OUString aText; - const LanguageType* pLanguage; - const ModelToViewHelper::ConversionMap* pConversionMap; - sal_Int32 nStartPos; - sal_Int32 nEndPos; - sal_Int32 nBegin; - sal_Int32 nLen; - LanguageType aCurrLang; - sal_uInt16 nWordType; - sal_Bool bClip; - -public: - SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt, - const LanguageType* pLang, - const ModelToViewHelper::ConversionMap* pConvMap, - sal_uInt16 nWordType, - sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClip = sal_False ); - - - // This next word function tries to find the language for the next word - // It should currently _not_ be used for spell checking, and works only for - // ! bReverse - sal_Bool NextWord(); - - const rtl::OUString& GetWord() const { return aWord; } - - sal_Int32 GetBegin() const { return nBegin; } - sal_Int32 GetEnd() const { return nBegin + nLen; } - sal_Int32 GetLen() const { return nLen; } - - LanguageType GetCurrentLanguage() const {return aCurrLang;} -}; - -/************************************************************************* * class SwScriptInfo * * encapsultes information about script changes |