Kaydet (Commit) ebe0549d authored tarafından Caolán McNamara's avatar Caolán McNamara

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
üst 54f82edb
/* -*- 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: */
......@@ -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);
......
......@@ -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;
......@@ -45,49 +43,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
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment