LCOV - code coverage report
Current view: top level - libreoffice/sw/qa/core - swdoc-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 456 458 99.6 %
Date: 2012-12-17 Functions: 29 30 96.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       Thorsten Behrens <tbehrens@novell.com>
      17             :  * Portions created by the Initial Developer are Copyright (C) 2011 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s):
      21             :  *   Thorsten Behrens <tbehrens@novell.com>
      22             :  *   Caolán McNamara <caolanm@redhat.com>
      23             :  *
      24             :  * Alternatively, the contents of this file may be used under the terms of
      25             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      26             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      27             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      28             :  * instead of those above.
      29             :  */
      30             : 
      31             : #include <sal/config.h>
      32             : #include <test/bootstrapfixture.hxx>
      33             : 
      34             : #include <rtl/strbuf.hxx>
      35             : #include <osl/file.hxx>
      36             : 
      37             : #include <tools/urlobj.hxx>
      38             : #include <unotools/tempfile.hxx>
      39             : 
      40             : #include <editeng/langitem.hxx>
      41             : #include <editeng/charhiddenitem.hxx>
      42             : 
      43             : #include <sfx2/app.hxx>
      44             : #include <sfx2/docfilt.hxx>
      45             : #include <sfx2/docfile.hxx>
      46             : #include <sfx2/sfxmodelfactory.hxx>
      47             : 
      48             : #include "breakit.hxx"
      49             : #include "doc.hxx"
      50             : #include "docsh.hxx"
      51             : #include "docstat.hxx"
      52             : #include "docufld.hxx"
      53             : #include "fmtanchr.hxx"
      54             : #include "init.hxx"
      55             : #include "ndtxt.hxx"
      56             : #include "shellio.hxx"
      57             : #include "shellres.hxx"
      58             : #include "swcrsr.hxx"
      59             : #include "swscanner.hxx"
      60             : #include "swmodule.hxx"
      61             : #include "swtypes.hxx"
      62             : #include "fmtftn.hxx"
      63             : #include "fmtrfmrk.hxx"
      64             : #include "fmtfld.hxx"
      65             : #include "redline.hxx"
      66             : #include "docary.hxx"
      67             : #include "modeltoviewhelper.hxx"
      68             : #include "scriptinfo.hxx"
      69             : 
      70          40 : SV_DECL_REF(SwDocShell)
      71          96 : SV_IMPL_REF(SwDocShell)
      72             : 
      73             : using namespace ::com::sun::star;
      74             : 
      75             : /* Implementation of Swdoc-Test class */
      76             : 
      77          48 : class SwDocTest : public test::BootstrapFixture
      78             : {
      79             : public:
      80             :     virtual void setUp();
      81             :     virtual void tearDown();
      82             : 
      83             :     void randomTest();
      84             :     void testPageDescName();
      85             :     void testFileNameFields();
      86             :     void testDocStat();
      87             :     void testModelToViewHelper();
      88             :     void testSwScanner();
      89             :     void testUserPerceivedCharCount();
      90             :     void testGraphicAnchorDeletion();
      91             : 
      92           4 :     CPPUNIT_TEST_SUITE(SwDocTest);
      93           2 :     CPPUNIT_TEST(randomTest);
      94           2 :     CPPUNIT_TEST(testPageDescName);
      95           2 :     CPPUNIT_TEST(testFileNameFields);
      96           2 :     CPPUNIT_TEST(testDocStat);
      97           2 :     CPPUNIT_TEST(testModelToViewHelper);
      98           2 :     CPPUNIT_TEST(testSwScanner);
      99           2 :     CPPUNIT_TEST(testUserPerceivedCharCount);
     100           2 :     CPPUNIT_TEST(testGraphicAnchorDeletion);
     101           4 :     CPPUNIT_TEST_SUITE_END();
     102             : 
     103             : private:
     104             :     SwDoc *m_pDoc;
     105             :     SwDocShellRef m_xDocShRef;
     106             : };
     107             : 
     108           2 : void SwDocTest::testPageDescName()
     109             : {
     110           2 :     ShellResource aShellResources;
     111             : 
     112           2 :     std::vector<rtl::OUString> aResults;
     113             : 
     114             :     //These names must be unique for each different combination, otherwise
     115             :     //duplicate page description names may exist, which will causes lookup
     116             :     //by name to be incorrect, and so the corresponding export to .odt
     117           2 :     aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::NORMAL_PAGE));
     118           2 :     aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FIRST_PAGE));
     119           2 :     aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FOLLOW_PAGE));
     120             : 
     121           2 :     std::sort(aResults.begin(), aResults.end());
     122           2 :     aResults.erase(std::unique(aResults.begin(), aResults.end()), aResults.end());
     123             : 
     124           2 :     CPPUNIT_ASSERT_MESSAGE("GetPageDescName results must be unique", aResults.size() == 3);
     125           2 : }
     126             : 
     127             : //See https://bugs.freedesktop.org/show_bug.cgi?id=32463
     128           2 : void SwDocTest::testFileNameFields()
     129             : {
     130             :     //Here's a file name with some chars in it that will be %% encoded, when expanding
     131             :     //SwFileNameFields we want to restore the original readable filename
     132           2 :     utl::TempFile aTempFile(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("demo [name]")));
     133           2 :     aTempFile.EnableKillingFile();
     134             : 
     135           2 :     INetURLObject aTempFileURL(aTempFile.GetURL());
     136           2 :     String sFileURL = aTempFileURL.GetMainURL(INetURLObject::NO_DECODE);
     137           2 :     SfxMedium aDstMed(sFileURL, STREAM_STD_READWRITE);
     138             : 
     139             :     SfxFilter aFilter(
     140             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text")),
     141             :         rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
     142           2 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TEXT")), rtl::OUString() );
     143           2 :     aDstMed.SetFilter(&aFilter);
     144             : 
     145           2 :     m_xDocShRef->DoSaveAs(aDstMed);
     146           2 :     m_xDocShRef->DoSaveCompleted(&aDstMed);
     147             : 
     148           2 :     const INetURLObject &rUrlObj = m_xDocShRef->GetMedium()->GetURLObject();
     149             : 
     150           2 :     SwFileNameFieldType aNameField(m_pDoc);
     151             : 
     152             :     {
     153           2 :         rtl::OUString sResult(aNameField.Expand(FF_NAME));
     154             :         rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
     155           2 :             true,INetURLObject::DECODE_WITH_CHARSET));
     156           2 :         CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
     157             :     }
     158             : 
     159             :     {
     160           2 :         rtl::OUString sResult(aNameField.Expand(FF_PATHNAME));
     161           2 :         rtl::OUString sExpected(rUrlObj.GetFull());
     162           2 :         CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
     163             :     }
     164             : 
     165             :     {
     166           2 :         rtl::OUString sResult(aNameField.Expand(FF_PATH));
     167           2 :         INetURLObject aTemp(rUrlObj);
     168           2 :         aTemp.removeSegment();
     169           2 :         rtl::OUString sExpected(aTemp.PathToFileName());
     170           2 :         CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
     171             :     }
     172             : 
     173             :     {
     174           2 :         rtl::OUString sResult(aNameField.Expand(FF_NAME_NOEXT));
     175             :         rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
     176           2 :             true,INetURLObject::DECODE_WITH_CHARSET));
     177             :         //Chop off .tmp
     178           2 :         sExpected = sExpected.copy(0, sExpected.getLength() - 4);
     179           2 :         CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
     180             :     }
     181             : 
     182           2 :     m_xDocShRef->DoInitNew(0);
     183           2 : }
     184             : 
     185             : //See http://lists.freedesktop.org/archives/libreoffice/2011-August/016666.html
     186             : //Remove unnecessary parameter to IDocumentStatistics::UpdateDocStat for
     187             : //motivation
     188           2 : void SwDocTest::testDocStat()
     189             : {
     190           2 :     CPPUNIT_ASSERT_MESSAGE("Expected initial 0 count", m_pDoc->GetDocStat().nChar == 0);
     191             : 
     192           2 :     SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1);
     193           2 :     SwPaM aPaM(aIdx);
     194             : 
     195           2 :     rtl::OUString sText(RTL_CONSTASCII_USTRINGPARAM("Hello World"));
     196           2 :     m_pDoc->InsertString(aPaM, sText);
     197             : 
     198           2 :     CPPUNIT_ASSERT_MESSAGE("Should still be non-updated 0 count", m_pDoc->GetDocStat().nChar == 0);
     199             : 
     200           2 :     SwDocStat aDocStat = m_pDoc->GetUpdatedDocStat();
     201           2 :     sal_uLong nLen = static_cast<sal_uLong>(sText.getLength());
     202             : 
     203           2 :     CPPUNIT_ASSERT_MESSAGE("Should now have updated count", aDocStat.nChar == nLen);
     204             : 
     205           2 :     CPPUNIT_ASSERT_MESSAGE("And cache is updated too", m_pDoc->GetDocStat().nChar == nLen);
     206           2 : }
     207             : 
     208             : //For UI character counts we should follow UAX#29 and display the user
     209             : //perceived characters, not the number of codepoints, nor the number of code
     210             : //units http://unicode.org/reports/tr29/
     211           2 : void SwDocTest::testUserPerceivedCharCount()
     212             : {
     213           2 :     SwBreakIt *pBreakIter = SwBreakIt::Get();
     214             : 
     215             :     //Grapheme example, two different unicode code-points perceived by the user as a single
     216             :     //glyph
     217           2 :     const sal_Unicode ALEF_QAMATS [] = { 0x05D0, 0x05B8 };
     218           2 :     ::rtl::OUString sALEF_QAMATS(ALEF_QAMATS, SAL_N_ELEMENTS(ALEF_QAMATS));
     219           2 :     sal_Int32 nGraphemeCount = pBreakIter->getGraphemeCount(sALEF_QAMATS);
     220           2 :     CPPUNIT_ASSERT_MESSAGE("Grapheme Count should be 1", nGraphemeCount == 1);
     221             : 
     222             :     //Surrogate pair example, one single unicode code-point (U+1D11E)
     223             :     //represented as two code units in UTF-16
     224           2 :     const sal_Unicode GCLEF[] = { 0xD834, 0xDD1E };
     225           2 :     ::rtl::OUString sGCLEF(GCLEF, SAL_N_ELEMENTS(GCLEF));
     226           2 :     sal_Int32 nCount = pBreakIter->getGraphemeCount(sGCLEF);
     227           2 :     CPPUNIT_ASSERT_MESSAGE("Surrogate Pair should be counted as single character", nCount == 1);
     228           2 : }
     229             : 
     230           2 : void SwDocTest::testModelToViewHelper()
     231             : {
     232           2 :     SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1);
     233           2 :     SwPaM aPaM(aIdx);
     234             : 
     235             :     {
     236           2 :         SwFmtFtn aFtn;
     237           2 :         aFtn.SetNumStr(rtl::OUString("foo"));
     238             : 
     239           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     240           2 :         m_pDoc->InsertString(aPaM, rtl::OUString("AAAAA BBBBB "));
     241           2 :         SwTxtNode* pTxtNode = aPaM.GetNode()->GetTxtNode();
     242           2 :         xub_StrLen nPos = aPaM.GetPoint()->nContent.GetIndex();
     243           2 :         pTxtNode->InsertItem(aFtn, nPos, nPos);
     244           2 :         m_pDoc->InsertString(aPaM, rtl::OUString(" CCCCC "));
     245           2 :         nPos = aPaM.GetPoint()->nContent.GetIndex();
     246           2 :         pTxtNode->InsertItem(aFtn, nPos, nPos);
     247           2 :         m_pDoc->InsertString(aPaM, rtl::OUString(" DDDDD"));
     248           2 :         CPPUNIT_ASSERT(pTxtNode->GetTxt().Len() == (4*5) + 5 + 2);
     249             : 
     250             :         //set start of selection to first B
     251           2 :         aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 6);
     252           2 :         aPaM.SetMark();
     253             :         //set end of selection to last C
     254           2 :         aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 14);
     255             :         //set character attribute hidden on range
     256           2 :         SvxCharHiddenItem aHidden(true, RES_CHRATR_HIDDEN);
     257           2 :         m_pDoc->InsertPoolItem(aPaM, aHidden, 0 );
     258             : 
     259             :         //turn on red-lining and show changes
     260           2 :         m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_DELETE|nsRedlineMode_t::REDLINE_SHOW_INSERT);
     261           2 :         CPPUNIT_ASSERT_MESSAGE("redlining should be on", m_pDoc->IsRedlineOn());
     262           2 :         CPPUNIT_ASSERT_MESSAGE("redlines should be visible", IDocumentRedlineAccess::IsShowChanges(m_pDoc->GetRedlineMode()));
     263             : 
     264             :         //set start of selection to last A
     265           2 :         aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 4);
     266           2 :         aPaM.SetMark();
     267             :         //set end of selection to second last B
     268           2 :         aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 9);
     269           2 :         m_pDoc->DeleteAndJoin(aPaM);    //redline-aware deletion api
     270             : 
     271             :         {
     272           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, PASSTHROUGH);
     273           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     274           2 :             rtl::OUString sModelText = pTxtNode->GetTxt();
     275           2 :             CPPUNIT_ASSERT(sViewText == sModelText);
     276             :         }
     277             : 
     278             :         {
     279           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS);
     280           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     281           2 :             CPPUNIT_ASSERT(sViewText == "AAAAA BBBBB foo CCCCC foo DDDDD");
     282             :         }
     283             : 
     284             :         {
     285           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE);
     286           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     287           2 :             rtl::OUStringBuffer aBuffer;
     288           2 :             aBuffer.append("AAAAA CCCCC ");
     289           2 :             aBuffer.append(CH_TXTATR_BREAKWORD);
     290           2 :             aBuffer.append(" DDDDD");
     291           2 :             CPPUNIT_ASSERT(sViewText == aBuffer.makeStringAndClear());
     292             :         }
     293             : 
     294             :         {
     295           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEREDLINED);
     296           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     297           2 :             rtl::OUStringBuffer aBuffer;
     298           2 :             aBuffer.append("AAAABB ");
     299           2 :             aBuffer.append(CH_TXTATR_BREAKWORD);
     300           2 :             aBuffer.append(" CCCCC ");
     301           2 :             aBuffer.append(CH_TXTATR_BREAKWORD);
     302           2 :             aBuffer.append(" DDDDD");
     303           2 :             CPPUNIT_ASSERT(sViewText == aBuffer.makeStringAndClear());
     304             :         }
     305             : 
     306             :         {
     307           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEINVISIBLE);
     308           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     309           2 :             CPPUNIT_ASSERT(sViewText == "AAAAA CCCCC foo DDDDD");
     310             :         }
     311             : 
     312             :         {
     313           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEREDLINED);
     314           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     315           2 :             CPPUNIT_ASSERT(sViewText == "AAAABB foo CCCCC foo DDDDD");
     316             :         }
     317             : 
     318             :         {
     319           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE | HIDEREDLINED);
     320           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     321           2 :             rtl::OUStringBuffer aBuffer;
     322           2 :             aBuffer.append("AAAACCCCC ");
     323           2 :             aBuffer.append(CH_TXTATR_BREAKWORD);
     324           2 :             aBuffer.append(" DDDDD");
     325           2 :             CPPUNIT_ASSERT(sViewText == aBuffer.makeStringAndClear());
     326             :         }
     327             : 
     328             :         {
     329           2 :             ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEINVISIBLE | HIDEREDLINED);
     330           2 :             rtl::OUString sViewText = aModelToViewHelper.getViewText();
     331           2 :             CPPUNIT_ASSERT(sViewText == "AAAACCCCC foo DDDDD");
     332           2 :         }
     333           2 :     }
     334           2 : }
     335             : 
     336           2 : void SwDocTest::testSwScanner()
     337             : {
     338           2 :     SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1);
     339           2 :     SwPaM aPaM(aIdx);
     340             : 
     341           2 :     SwTxtNode* pTxtNode = aPaM.GetNode()->GetTxtNode();
     342             : 
     343           2 :     CPPUNIT_ASSERT_MESSAGE("Has Text Node", pTxtNode);
     344             : 
     345             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=40449
     346             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=39365
     347             :     //Use a temporary rtl::OUString as the arg, as that's the trouble behind
     348             :     //fdo#40449 and fdo#39365
     349             :     {
     350             :         SwScanner aScanner(*pTxtNode,
     351             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello World")),
     352             :             0, ModelToViewHelper(), i18n::WordType::DICTIONARY_WORD, 0,
     353           2 :             RTL_CONSTASCII_LENGTH("Hello World"));
     354             : 
     355           2 :         bool bFirstOk = aScanner.NextWord();
     356           2 :         CPPUNIT_ASSERT_MESSAGE("First Token", bFirstOk);
     357           2 :         const rtl::OUString &rHello = aScanner.GetWord();
     358           4 :         CPPUNIT_ASSERT_MESSAGE("Should be Hello",
     359           2 :             rHello.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Hello")));
     360             : 
     361           2 :         bool bSecondOk = aScanner.NextWord();
     362           2 :         CPPUNIT_ASSERT_MESSAGE("Second Token", bSecondOk);
     363           2 :         const rtl::OUString &rWorld = aScanner.GetWord();
     364           4 :         CPPUNIT_ASSERT_MESSAGE("Should be World",
     365           4 :             rWorld.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("World")));
     366             :     }
     367             : 
     368             :     //See https://www.libreoffice.org/bugzilla/show_bug.cgi?id=45271
     369             :     {
     370           2 :         const sal_Unicode IDEOGRAPHICFULLSTOP_D[] = { 0x3002, 'D' };
     371             : 
     372             :         m_pDoc->InsertString(aPaM, rtl::OUString(IDEOGRAPHICFULLSTOP_D,
     373           2 :             SAL_N_ELEMENTS(IDEOGRAPHICFULLSTOP_D)));
     374             : 
     375           2 :         SvxLanguageItem aCJKLangItem( LANGUAGE_CHINESE_SIMPLIFIED, RES_CHRATR_CJK_LANGUAGE );
     376           2 :         SvxLanguageItem aWestLangItem( LANGUAGE_ENGLISH_US, RES_CHRATR_LANGUAGE );
     377           2 :         m_pDoc->InsertPoolItem(aPaM, aCJKLangItem, 0 );
     378           2 :         m_pDoc->InsertPoolItem(aPaM, aWestLangItem, 0 );
     379             : 
     380           2 :         SwDocStat aDocStat;
     381           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     382           2 :         pTxtNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(IDEOGRAPHICFULLSTOP_D));
     383             : 
     384           2 :         CPPUNIT_ASSERT_MESSAGE("Should be 2", aDocStat.nChar == 2);
     385           2 :         CPPUNIT_ASSERT_MESSAGE("Should be 2", aDocStat.nCharExcludingSpaces == 2);
     386             :     }
     387             :     {
     388             :         const sal_Unicode test[] =
     389             :         {
     390             :             0x3053, 0x306E, 0x65E5, 0x672C, 0x8A9E, 0x306F, 0x6B63, 0x3057,
     391             :             0x304F, 0x6570, 0x3048, 0x3089, 0x308C, 0x308B, 0x3067, 0x3057,
     392             :             0x3087, 0x3046, 0x304B, 0x3002, 0x0041, 0x006E, 0x0064, 0x0020,
     393             :             0x006C, 0x0065, 0x0074, 0x0027, 0x0073, 0x0020, 0x0074, 0x0068,
     394             :             0x0072, 0x006F, 0x0077, 0x0020, 0x0073, 0x006F, 0x006D, 0x0065,
     395             :             0x0020, 0x0045, 0x006E, 0x0067, 0x006C, 0x0069, 0x0073, 0x0068,
     396             :             0x0020, 0x0069, 0x006E, 0x0020, 0x0074, 0x006F, 0x0020, 0x006D,
     397             :             0x0061, 0x006B, 0x0065, 0x0020, 0x0069, 0x0074, 0x0020, 0x0069,
     398             :             0x006E, 0x0074, 0x0065, 0x0072, 0x0065, 0x0073, 0x0074, 0x0069,
     399             :             0x006E, 0x0067, 0x002E, 0x0020, 0x0020, 0x305D, 0x3057, 0x3066,
     400             :             0x3001, 0x307E, 0x305F, 0x65E5, 0x672C, 0x8A9E, 0x3000, 0x3000,
     401             :             0x3067, 0x3082, 0x4ECA, 0x56DE, 0x306F, 0x7A7A, 0x767D, 0x3092,
     402             :             0x3000, 0x3000, 0x5165, 0x308C, 0x307E, 0x3057, 0x305F, 0x3002,
     403             :             0x0020, 0x0020, 0x0053, 0x006F, 0x0020, 0x0068, 0x006F, 0x0077,
     404             :             0x0020, 0x0064, 0x006F, 0x0065, 0x0073, 0x0020, 0x0074, 0x0068,
     405             :             0x0069, 0x0073, 0x0020, 0x0064, 0x006F, 0x003F, 0x0020, 0x0020
     406           2 :         };
     407           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     408             :         m_pDoc->InsertString(aPaM, rtl::OUString(test,
     409           2 :             SAL_N_ELEMENTS(test)));
     410             : 
     411           2 :         SvxLanguageItem aCJKLangItem( LANGUAGE_JAPANESE, RES_CHRATR_CJK_LANGUAGE );
     412           2 :         SvxLanguageItem aWestLangItem( LANGUAGE_ENGLISH_US, RES_CHRATR_LANGUAGE );
     413           2 :         m_pDoc->InsertPoolItem(aPaM, aCJKLangItem, 0 );
     414           2 :         m_pDoc->InsertPoolItem(aPaM, aWestLangItem, 0 );
     415             : 
     416           2 :         SwDocStat aDocStat;
     417           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     418           2 :         pTxtNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(test));
     419           2 :         CPPUNIT_ASSERT_MESSAGE("58 words", aDocStat.nWord == 58);
     420           2 :         CPPUNIT_ASSERT_MESSAGE("43 Asian characters and Korean syllables", aDocStat.nAsianWord == 43);
     421           2 :         CPPUNIT_ASSERT_MESSAGE("105 non-whitespace chars", aDocStat.nCharExcludingSpaces == 105);
     422           2 :         CPPUNIT_ASSERT_MESSAGE("128 characters", aDocStat.nChar == 128);
     423             :     }
     424             : 
     425             :     //See https://issues.apache.org/ooo/show_bug.cgi?id=89042
     426             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=53399
     427             :     {
     428           2 :         SwDocStat aDocStat;
     429             : 
     430             :         const sal_Unicode aShouldBeThree[] = {
     431             :             0x0053, 0x0068, 0x006F, 0x0075, 0x006C, 0x0064, 0x0020,
     432             :             0x2018, 0x0062, 0x0065, 0x0020, 0x0074, 0x0068, 0x0072,
     433             :             0x0065, 0x0065, 0x2019
     434           2 :         };
     435             : 
     436           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     437           2 :         m_pDoc->InsertString(aPaM, rtl::OUString(aShouldBeThree, SAL_N_ELEMENTS(aShouldBeThree)));
     438           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     439           2 :         pTxtNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(aShouldBeThree));
     440           2 :         CPPUNIT_ASSERT_MESSAGE("Should be 3", aDocStat.nWord == 3);
     441             : 
     442             :         const sal_Unicode aShouldBeFive[] = {
     443             :             // f    r       e       n       c       h       space
     444             :             0x0046, 0x0072, 0x0065, 0x006E, 0x0063, 0x0068, 0x0020,
     445             :             // <<   nbsp    s       a       v       o       i
     446             :             0x00AB, 0x00A0, 0x0073, 0x0061, 0x0076, 0x006F, 0x0069,
     447             :             // r    nnbsp   c       a       l       c       u
     448             :             0x0072, 0x202f, 0x0063, 0x0061, 0x006C, 0x0063, 0x0075,
     449             :             // l    e       r       idspace >>
     450             :             0x006C, 0x0065, 0x0072, 0x3000, 0x00BB
     451           2 :         };
     452             : 
     453           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     454           2 :         m_pDoc->InsertString(aPaM, rtl::OUString(aShouldBeFive, SAL_N_ELEMENTS(aShouldBeFive)));
     455           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     456           2 :         aDocStat.Reset();
     457           2 :         pTxtNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(aShouldBeFive));
     458           2 :         CPPUNIT_ASSERT_MESSAGE("Should be 5", aDocStat.nWord == 5);
     459             :     }
     460             : 
     461             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=49629
     462             :     {
     463           2 :         SwDocStat aDocStat;
     464             : 
     465           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     466           2 :         m_pDoc->InsertString(aPaM, rtl::OUString("Apple"));
     467           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     468           2 :         xub_StrLen nPos = aPaM.GetPoint()->nContent.GetIndex();
     469           2 :         SwFmtFtn aFtn;
     470           2 :         aFtn.SetNumStr(rtl::OUString("banana"));
     471           2 :         SwTxtAttr* pTA = pTxtNode->InsertItem(aFtn, nPos, nPos);
     472           2 :         CPPUNIT_ASSERT(pTA);
     473           2 :         CPPUNIT_ASSERT(pTxtNode->Len() == 6); //Apple + 0x02
     474           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     475           2 :         CPPUNIT_ASSERT(aDocStat.nWord == 1);
     476           2 :         CPPUNIT_ASSERT_MESSAGE("footnote should be expanded", aDocStat.nChar == 11);
     477             : 
     478           2 :         xub_StrLen nNextPos = aPaM.GetPoint()->nContent.GetIndex();
     479           2 :         CPPUNIT_ASSERT(nNextPos == nPos+1);
     480           2 :         SwFmtRefMark aRef(rtl::OUString("refmark"));
     481           2 :         pTA = pTxtNode->InsertItem(aRef, nNextPos, nNextPos);
     482           2 :         CPPUNIT_ASSERT(pTA);
     483             : 
     484           2 :         aDocStat.Reset();
     485           2 :         pTxtNode->SetWordCountDirty(true);
     486           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     487           2 :         CPPUNIT_ASSERT(aDocStat.nWord == 1);
     488           2 :         CPPUNIT_ASSERT_MESSAGE("refmark anchor should not be counted", aDocStat.nChar == 11);
     489             : 
     490           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     491           2 :         m_pDoc->InsertString(aPaM, rtl::OUString("Apple"));
     492             : 
     493           2 :         DateTime aDate(DateTime::SYSTEM);
     494             :         SwPostItField aPostIt(
     495           2 :             (SwPostItFieldType*)m_pDoc->GetSysFldType(RES_POSTITFLD), rtl::OUString("An Author"),
     496           4 :             rtl::OUString("Some Text"), rtl::OUString("Initials"), OUString("Name"), aDate );
     497           2 :         m_pDoc->InsertPoolItem(aPaM, SwFmtFld(aPostIt), 0);
     498             : 
     499           2 :         m_pDoc->InsertString(aPaM, rtl::OUString("Apple"));
     500           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     501           2 :         aDocStat.Reset();
     502           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     503           2 :         CPPUNIT_ASSERT(aDocStat.nWord == 1);
     504           2 :         CPPUNIT_ASSERT_MESSAGE("postit anchor should effectively not exist", aDocStat.nChar == 10);
     505           2 :         CPPUNIT_ASSERT(pTxtNode->Len() == 11);
     506             : 
     507           2 :         aDocStat.Reset();
     508             :     }
     509             : 
     510             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=46757
     511             :     {
     512           2 :         SwDocStat aDocStat;
     513             : 
     514           2 :         const char aString[] = "Lorem ipsum";
     515           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     516           2 :         m_pDoc->InsertString(aPaM, rtl::OUString(aString));
     517           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     518           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     519           2 :         CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(2));
     520             : 
     521             :         //turn on red-lining and show changes
     522           2 :         m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_DELETE|nsRedlineMode_t::REDLINE_SHOW_INSERT);
     523           2 :         CPPUNIT_ASSERT_MESSAGE("redlining should be on", m_pDoc->IsRedlineOn());
     524           2 :         CPPUNIT_ASSERT_MESSAGE("redlines should be visible", IDocumentRedlineAccess::IsShowChanges(m_pDoc->GetRedlineMode()));
     525             : 
     526             :         //delete everything except the first word
     527           2 :         aPaM.SetMark(); //set start of selection to current pos
     528           2 :         aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 5);   //set end of selection to fifth char of current node
     529           2 :         m_pDoc->DeleteAndJoin(aPaM);    //redline-aware deletion api
     530           2 :         CPPUNIT_ASSERT_MESSAGE("real underlying text should be the same", pTxtNode->GetTxt().EqualsAscii(aString));
     531             : 
     532           2 :         aDocStat.Reset();
     533           2 :         pTxtNode->SetWordCountDirty(true);
     534           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //but word-counting the text should only count the non-deleted text
     535           2 :         CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(1));
     536             : 
     537           2 :         pTxtNode->SetWordCountDirty(true);
     538             : 
     539             :         //keep red-lining on but hide changes
     540           2 :         m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON);
     541           2 :         CPPUNIT_ASSERT_MESSAGE("redlining should be still on", m_pDoc->IsRedlineOn());
     542           2 :         CPPUNIT_ASSERT_MESSAGE("redlines should be invisible", !IDocumentRedlineAccess::IsShowChanges(m_pDoc->GetRedlineMode()));
     543             : 
     544           2 :         aDocStat.Reset();
     545           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //but word-counting the text should only count the non-deleted text
     546           2 :         CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(1));
     547             : 
     548           2 :         rtl::OUString sLorem = pTxtNode->GetTxt();
     549           2 :         CPPUNIT_ASSERT(sLorem == "Lorem");
     550             : 
     551           2 :         const SwRedlineTbl& rTbl = m_pDoc->GetRedlineTbl();
     552             : 
     553           2 :         SwNodes& rNds = m_pDoc->GetNodes();
     554           2 :         CPPUNIT_ASSERT(rTbl.size() == 1);
     555             : 
     556           2 :         SwNodeIndex* pNodeIdx = rTbl[0]->GetContentIdx();
     557           2 :         CPPUNIT_ASSERT(pNodeIdx);
     558             : 
     559           2 :         pTxtNode = rNds[ pNodeIdx->GetIndex() + 1 ]->GetTxtNode();        //first deleted txtnode
     560           2 :         CPPUNIT_ASSERT(pTxtNode);
     561             : 
     562           2 :         rtl::OUString sIpsum = pTxtNode->GetTxt();
     563           2 :         CPPUNIT_ASSERT(sIpsum == " ipsum");
     564             : 
     565           2 :         aDocStat.Reset();
     566           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //word-counting the text should only count the non-deleted text, and this whole chunk should be ignored
     567           2 :         CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(0));
     568           2 :         CPPUNIT_ASSERT_EQUAL(aDocStat.nChar, static_cast<sal_uLong>(0));
     569             :     }
     570             : 
     571             :     //See https://bugs.freedesktop.org/show_bug.cgi?id=38983
     572             :     {
     573           2 :         SwDocStat aDocStat;
     574             : 
     575           2 :         rtl::OUString sTemplate("ThisXis a test.");
     576             : 
     577           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     578           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', ' '));
     579           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     580           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     581           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 4 &&
     582             :                        aDocStat.nCharExcludingSpaces == 12 &&
     583           2 :                        aDocStat.nChar == 15);
     584           2 :         aDocStat.Reset();
     585             : 
     586           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     587           2 :         m_pDoc->InsertString(aPaM, sTemplate.replaceAll(rtl::OUString('X'), rtl::OUString(" = ")));
     588           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     589           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     590           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 5 &&
     591             :                        aDocStat.nCharExcludingSpaces == 13 &&
     592           2 :                        aDocStat.nChar == 17);
     593           2 :         aDocStat.Reset();
     594             : 
     595           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     596           2 :         m_pDoc->InsertString(aPaM, sTemplate.replaceAll(rtl::OUString('X'), rtl::OUString(" _ ")));
     597           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     598           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     599           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 5 &&
     600             :                        aDocStat.nCharExcludingSpaces == 13 &&
     601           2 :                        aDocStat.nChar == 17);
     602           2 :         aDocStat.Reset();
     603             : 
     604           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     605           2 :         m_pDoc->InsertString(aPaM, sTemplate.replaceAll(rtl::OUString('X'), rtl::OUString(" -- ")));
     606           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     607           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     608           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 5 &&
     609             :                        aDocStat.nCharExcludingSpaces == 14 &&
     610           2 :                        aDocStat.nChar == 18);
     611           2 :         aDocStat.Reset();
     612             : 
     613           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     614           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', '_'));
     615           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     616           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     617           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 3 &&
     618             :                        aDocStat.nCharExcludingSpaces == 13 &&
     619           2 :                        aDocStat.nChar == 15);
     620           2 :         aDocStat.Reset();
     621             : 
     622           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     623           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', '-'));
     624           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     625           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     626           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 3 &&
     627             :                        aDocStat.nCharExcludingSpaces == 13 &&
     628           2 :                        aDocStat.nChar == 15);
     629           2 :         aDocStat.Reset();
     630             : 
     631           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     632           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', 0x2012));
     633           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     634           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     635           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 3 &&
     636             :                        aDocStat.nCharExcludingSpaces == 13 &&
     637           2 :                        aDocStat.nChar == 15);
     638           2 :         aDocStat.Reset();
     639             : 
     640           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     641           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', 0x2015));
     642           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     643           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     644           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 3 &&
     645             :                        aDocStat.nCharExcludingSpaces == 13 &&
     646           2 :                        aDocStat.nChar == 15);
     647           2 :         aDocStat.Reset();
     648             : 
     649             :         //But default configuration should, msword-alike treak emdash
     650             :         //and endash as word seperators for word-counting
     651           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     652           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', 0x2013));
     653           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     654           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     655           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 4 &&
     656             :                        aDocStat.nCharExcludingSpaces == 13 &&
     657           2 :                        aDocStat.nChar == 15);
     658           2 :         aDocStat.Reset();
     659             : 
     660           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     661           2 :         m_pDoc->InsertString(aPaM, sTemplate.replace('X', 0x2014));
     662           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     663           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     664           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 4 &&
     665             :                        aDocStat.nCharExcludingSpaces == 13 &&
     666           2 :                        aDocStat.nChar == 15);
     667           2 :         aDocStat.Reset();
     668             : 
     669           2 :         const sal_Unicode aChunk[] = {' ', 0x2013, ' '};
     670           2 :         rtl::OUString sChunk(aChunk, SAL_N_ELEMENTS(aChunk));
     671           2 :         m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     672           2 :         m_pDoc->InsertString(aPaM, sTemplate.replaceAll(rtl::OUString('X'), sChunk));
     673           2 :         pTxtNode = aPaM.GetNode()->GetTxtNode();
     674           2 :         pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len());
     675           4 :         CPPUNIT_ASSERT(aDocStat.nWord == 4 &&
     676             :                        aDocStat.nCharExcludingSpaces == 13 &&
     677           2 :                        aDocStat.nChar == 17);
     678           2 :         aDocStat.Reset();
     679           2 :     }
     680           2 : }
     681             : 
     682             : //See https://bugs.freedesktop.org/show_bug.cgi?id=40599
     683           2 : void SwDocTest::testGraphicAnchorDeletion()
     684             : {
     685           2 :     CPPUNIT_ASSERT_MESSAGE("Expected initial 0 count", m_pDoc->GetDocStat().nChar == 0);
     686             : 
     687           2 :     SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1);
     688           2 :     SwPaM aPaM(aIdx);
     689             : 
     690           2 :     m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Paragraph 1")));
     691           2 :     m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     692             : 
     693           2 :     m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("graphic anchor>><<graphic anchor")));
     694           2 :     SwNodeIndex nPara2 = aPaM.GetPoint()->nNode;
     695           2 :     m_pDoc->AppendTxtNode(*aPaM.GetPoint());
     696             : 
     697           2 :     m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Paragraph 3")));
     698             : 
     699           2 :     aPaM.GetPoint()->nNode = nPara2;
     700           2 :     aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), RTL_CONSTASCII_LENGTH("graphic anchor>>"));
     701             : 
     702             :     //Insert a graphic at X of >>X<< in paragraph 2
     703           2 :     SfxItemSet aFlySet(m_pDoc->GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1);
     704           2 :     SwFmtAnchor aAnchor(FLY_AS_CHAR);
     705           2 :     aAnchor.SetAnchor(aPaM.GetPoint());
     706           2 :     aFlySet.Put(aAnchor);
     707           2 :     SwFlyFrmFmt *pFrame = m_pDoc->Insert(aPaM, rtl::OUString(), rtl::OUString(), NULL, &aFlySet, NULL, NULL);
     708           2 :     CPPUNIT_ASSERT_MESSAGE("Expected frame", pFrame != NULL);
     709             : 
     710           2 :     CPPUNIT_ASSERT_MESSAGE("Should be 1 graphic", m_pDoc->GetFlyCount(FLYCNTTYPE_GRF) == 1);
     711             : 
     712             :     //Delete >X<
     713           2 :     aPaM.GetPoint()->nNode = nPara2;
     714           4 :     aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(),
     715           4 :         RTL_CONSTASCII_LENGTH("graphic anchor>><")+1);
     716           2 :     aPaM.SetMark();
     717           2 :     aPaM.GetPoint()->nNode = nPara2;
     718           2 :     aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), RTL_CONSTASCII_LENGTH("graphic anchor>"));
     719           2 :     m_pDoc->DeleteRange(aPaM);
     720             : 
     721             : #ifdef DEBUG_AS_HTML
     722             :     {
     723             :         SvFileStream aPasteDebug(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     724             :             "cppunitDEBUG.html")), STREAM_WRITE|STREAM_TRUNC);
     725             :         WriterRef xWrt;
     726             :         GetHTMLWriter( String(), String(), xWrt );
     727             :         SwWriter aDbgWrt( aPasteDebug, *m_pDoc );
     728             :         aDbgWrt.Write( xWrt );
     729             :     }
     730             : #endif
     731             : 
     732           2 :     CPPUNIT_ASSERT_MESSAGE("Should be 0 graphics", m_pDoc->GetFlyCount(FLYCNTTYPE_GRF) == 0);
     733             : 
     734             :     //Now, if instead we swap FLY_AS_CHAR (inline graphic) to FLY_AT_CHAR (anchored to character)
     735             :     //and repeat the above, graphic is *not* deleted, i.e. it belongs to the paragraph, not the
     736             :     //range to which its anchored, which is annoying.
     737           2 : }
     738             : 
     739             : static int
     740       73174 : getRand(int modulus)
     741             : {
     742       73174 :     if (modulus <= 0)
     743           0 :         return 0;
     744       73174 :     return rand() % modulus;
     745             : }
     746             : 
     747             : static rtl::OUString
     748        8194 : getRandString()
     749             : {
     750        8194 :     rtl::OUString aText("AAAAA BBBB CCC DD E \n");
     751        8194 :     int s = getRand(aText.getLength());
     752        8194 :     int j = getRand(aText.getLength() - s);
     753        8194 :     rtl::OUString aRet(aText.copy(s, j));
     754        8194 :     if (!getRand(5))
     755        1709 :         aRet += rtl::OUString(sal_Unicode('\n'));
     756             : //    fprintf (stderr, "rand string '%s'\n", OUStringToOString(aRet, RTL_TEXTENCODING_UTF8).getStr());
     757        8194 :     return aRet;
     758             : }
     759             : 
     760             : static SwPosition
     761       37156 : getRandomPosition(SwDoc *pDoc, int /* nOffset */)
     762             : {
     763       37156 :     const SwPosition aPos(pDoc->GetNodes().GetEndOfContent());
     764       37156 :         sal_uLong nNodes = aPos.nNode.GetNode().GetIndex() - aPos.nNode.GetNode().StartOfSectionIndex();
     765       37156 :         sal_uLong n = (rand() * nNodes) / RAND_MAX;
     766       37156 :         SwPaM pam(aPos);
     767       55756 :         for (sal_uLong i = 0; i < n; ++i) {
     768       18600 :                 pam.Move(fnMoveBackward, fnGoNode);
     769             :         }
     770       37156 :     return *pam.GetPoint();
     771             : }
     772             : 
     773           2 : void SwDocTest::randomTest()
     774             : {
     775           2 :     CPPUNIT_ASSERT_MESSAGE("SwDoc::IsRedlineOn()", !m_pDoc->IsRedlineOn());
     776             :     RedlineMode_t modes[] = {
     777             :         nsRedlineMode_t::REDLINE_ON,
     778             :         nsRedlineMode_t::REDLINE_SHOW_MASK,
     779             :         nsRedlineMode_t::REDLINE_NONE,
     780             :         nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_MASK,
     781             :         nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_IGNORE,
     782             :         nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_IGNORE | nsRedlineMode_t::REDLINE_SHOW_MASK,
     783             :         nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_INSERT,
     784             :         nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_DELETE
     785           2 :     };
     786             :     static const char *authors[] = {
     787             :         "Jim", "Bob", "JimBobina", "Helga", "Gertrude", "Spagna", "Hurtleweed"
     788             :     };
     789             : 
     790          18 :     for( sal_uInt16 rlm = 0; rlm < SAL_N_ELEMENTS(modes); rlm++ )
     791             :     {
     792          16 :         m_pDoc->ClearDoc();
     793             : 
     794             :         // setup redlining
     795          16 :         m_pDoc->SetRedlineMode(modes[rlm]);
     796          16 :         SW_MOD()->SetRedlineAuthor(rtl::OUString::createFromAscii(authors[0]));
     797             : 
     798       32016 :         for( int i = 0; i < 2000; i++ )
     799             :         {
     800       32000 :             SwPaM aPam(m_pDoc->GetNodes());
     801       32000 :             SwCursor aCrs(getRandomPosition(m_pDoc, i/20), 0, false);
     802       32000 :             aCrs.SetMark();
     803             : 
     804       32000 :             switch (getRand (i < 50 ? 3 : 6)) {
     805             :             // insert ops first
     806             :             case 0: {
     807        5537 :                 if (!m_pDoc->InsertString(aCrs, getRandString())) {
     808             : //                    fprintf (stderr, "failed to insert string !\n");
     809             :                 }
     810        5537 :                 break;
     811             :             }
     812             :             case 1:
     813        5527 :                 break;
     814             :             case 2: { // switch author
     815        5394 :                 int a = getRand(SAL_N_ELEMENTS(authors));
     816        5394 :                 SW_MOD()->SetRedlineAuthor(rtl::OUString::createFromAscii(authors[a]));
     817        5394 :                 break;
     818             :             }
     819             : 
     820             :             // movement / deletion ops later
     821             :             case 3: // deletion
     822        5186 :                 switch (getRand(6)) {
     823             :                 case 0:
     824         798 :                     m_pDoc->DelFullPara(aCrs);
     825         798 :                     break;
     826             :                 case 1:
     827         875 :                     m_pDoc->DeleteRange(aCrs);
     828         875 :                     break;
     829             :                 case 2:
     830         856 :                     m_pDoc->DeleteAndJoin(aCrs, !!getRand(1));
     831         856 :                     break;
     832             :                 case 3:
     833             :                 default:
     834        2657 :                     m_pDoc->Overwrite(aCrs, getRandString());
     835        2657 :                     break;
     836             :                 }
     837        5186 :                 break;
     838             :             case 4: { // movement
     839             :                 IDocumentContentOperations::SwMoveFlags nFlags =
     840             :                     (IDocumentContentOperations::SwMoveFlags)
     841        5156 :                         (getRand(1) ? // FIXME: puterb this more ?
     842             :                          IDocumentContentOperations::DOC_MOVEDEFAULT :
     843             :                          IDocumentContentOperations::DOC_MOVEALLFLYS |
     844             :                          IDocumentContentOperations::DOC_CREATEUNDOOBJ |
     845             :                          IDocumentContentOperations::DOC_MOVEREDLINES |
     846        5156 :                          IDocumentContentOperations::DOC_NO_DELFRMS);
     847        5156 :                 SwPosition aTo(getRandomPosition(m_pDoc, i/10));
     848        5156 :                 m_pDoc->MoveRange(aCrs, aTo, nFlags);
     849        5156 :                 break;
     850             :             }
     851             : 
     852             :             case 5:
     853        5200 :                 break;
     854             : 
     855             :             // undo / redo ?
     856             :             default:
     857           0 :                 break;
     858             :             }
     859       32000 :         }
     860             : 
     861             : // Debug / verify the produced document has real content
     862             : #if 0
     863             :         rtl::OStringBuffer aBuffer("nodes-");
     864             :         aBuffer.append(sal_Int32(rlm));
     865             :         aBuffer.append(".xml");
     866             : 
     867             :         xmlTextWriterPtr writer;
     868             :         writer = xmlNewTextWriterFilename( aBuffer.makeStringAndClear().getStr(), 0 );
     869             :         xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
     870             :         m_pDoc->dumpAsXml(writer);
     871             :         xmlTextWriterEndDocument( writer );
     872             :         xmlFreeTextWriter( writer );
     873             : #endif
     874             :     }
     875           2 : }
     876             : 
     877          16 : void SwDocTest::setUp()
     878             : {
     879          16 :     BootstrapFixture::setUp();
     880             : 
     881          16 :     SwGlobals::ensure();
     882          16 :     m_pDoc = new SwDoc;
     883          16 :     m_xDocShRef = new SwDocShell(m_pDoc, SFX_CREATE_MODE_EMBEDDED);
     884          16 :     m_xDocShRef->DoInitNew(0);
     885          16 : }
     886             : 
     887          16 : void SwDocTest::tearDown()
     888             : {
     889          16 :     m_xDocShRef.Clear();
     890          16 :     delete m_pDoc;
     891             : 
     892          16 :     BootstrapFixture::tearDown();
     893          16 : }
     894             : 
     895           2 : CPPUNIT_TEST_SUITE_REGISTRATION(SwDocTest);
     896             : 
     897           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     898             : 
     899             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10