2012-04-11 14:29:11 -04:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
2013-04-19 21:10:42 +01:00
* This file is part of the LibreOffice project .
2012-04-11 14:29:11 -04:00
*
2013-04-19 21:10:42 +01:00
* 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/.
2012-04-11 14:29:11 -04:00
*/
2017-10-23 22:42:22 +02:00
# include <test/bootstrapfixture.hxx>
2012-04-11 14:29:11 -04:00
# include <cppunit/TestFixture.h>
# include <cppunit/extensions/HelperMacros.h>
2017-10-23 22:42:22 +02:00
# include <eerdll2.hxx>
# include <editdoc.hxx>
# include <sfx2/app.hxx>
# include <svl/itempool.hxx>
# include <editeng/eerdll.hxx>
# include <editeng/editeng.hxx>
# include <editeng/eeitem.hxx>
# include <editeng/editids.hrc>
# include <editeng/svxacorr.hxx>
# include <editeng/unofield.hxx>
# include <editeng/wghtitem.hxx>
# include <editeng/postitem.hxx>
# include <editeng/section.hxx>
# include <editeng/editobj.hxx>
# include <editeng/flditem.hxx>
# include <editeng/udlnitem.hxx>
# include <svl/srchitem.hxx>
2012-05-11 23:11:10 -04:00
# include <com/sun/star/text/textfield/Type.hpp>
2015-09-17 17:10:47 +01:00
# include <memory>
2017-07-13 00:36:46 +05:30
# include <editeng/outliner.hxx>
2013-08-20 14:56:27 -04:00
2012-05-11 23:11:10 -04:00
using namespace com : : sun : : star ;
2012-04-11 14:29:11 -04:00
namespace {
class Test : public test : : BootstrapFixture
{
public :
Test ( ) ;
2015-10-12 16:04:04 +02:00
virtual void setUp ( ) override ;
virtual void tearDown ( ) override ;
2012-04-11 21:53:33 -04:00
2012-04-11 14:29:11 -04:00
void testConstruction ( ) ;
2014-07-27 00:21:50 -04:00
/// Test UNO service class that implements text field items.
2012-05-11 23:11:10 -04:00
void testUnoTextFields ( ) ;
2014-07-27 00:21:50 -04:00
/// AutoCorrect tests
2013-03-01 10:50:11 +00:00
void testAutocorrect ( ) ;
2017-03-23 20:11:28 +05:30
/// Test Copy/Paste with hyperlinks in text using Legacy Format
void testHyperlinkCopyPaste ( ) ;
2017-02-22 21:57:44 +05:30
/// Test Copy/Paste using Legacy Format
void testCopyPaste ( ) ;
2017-06-23 09:39:21 +05:30
/// Test Copy/Paste with selective selection over multiple paragraphs
void testMultiParaSelCopyPaste ( ) ;
2017-03-23 14:42:40 +05:30
/// Test Copy/Paste with Tabs
void testTabsCopyPaste ( ) ;
2014-07-27 00:21:50 -04:00
/// Test hyperlinks
void testHyperlinkSearch ( ) ;
2017-03-09 02:02:15 +05:30
/// Test Copy/Paste with Bold/Italic text using Legacy Format
void testBoldItalicCopyPaste ( ) ;
2017-03-15 17:23:32 +05:30
/// Test Copy/Paste with Underline text using Legacy Format
void testUnderlineCopyPaste ( ) ;
2017-06-25 23:38:18 +02:00
/// Test Copy/Paste with multiple paragraphs
2017-06-22 22:05:21 +05:30
void testMultiParaCopyPaste ( ) ;
2017-06-25 02:27:27 +05:30
/// Test Copy/Paste with multiple paragraphs having Bold/Italic text
void testParaBoldItalicCopyPaste ( ) ;
2017-07-04 02:08:40 +05:30
void testParaStartCopyPaste ( ) ;
2013-08-20 14:56:27 -04:00
void testSectionAttributes ( ) ;
2017-07-06 02:00:59 +05:30
void testLargeParaCopyPaste ( ) ;
2017-07-13 00:36:46 +05:30
DECL_STATIC_LINK ( Test , CalcFieldValueHdl , EditFieldInfo * , void ) ;
2012-04-11 14:29:11 -04:00
CPPUNIT_TEST_SUITE ( Test ) ;
2012-04-13 11:13:19 +01:00
CPPUNIT_TEST ( testConstruction ) ;
2012-05-11 23:11:10 -04:00
CPPUNIT_TEST ( testUnoTextFields ) ;
2013-03-01 10:50:11 +00:00
CPPUNIT_TEST ( testAutocorrect ) ;
2017-03-23 20:11:28 +05:30
CPPUNIT_TEST ( testHyperlinkCopyPaste ) ;
2017-02-22 21:57:44 +05:30
CPPUNIT_TEST ( testCopyPaste ) ;
2017-06-23 09:39:21 +05:30
CPPUNIT_TEST ( testMultiParaSelCopyPaste ) ;
2017-03-23 14:42:40 +05:30
CPPUNIT_TEST ( testTabsCopyPaste ) ;
2014-07-27 00:21:50 -04:00
CPPUNIT_TEST ( testHyperlinkSearch ) ;
2017-03-09 02:02:15 +05:30
CPPUNIT_TEST ( testBoldItalicCopyPaste ) ;
2017-03-15 17:23:32 +05:30
CPPUNIT_TEST ( testUnderlineCopyPaste ) ;
2017-06-22 22:05:21 +05:30
CPPUNIT_TEST ( testMultiParaCopyPaste ) ;
2017-06-25 02:27:27 +05:30
CPPUNIT_TEST ( testParaBoldItalicCopyPaste ) ;
2017-07-04 02:08:40 +05:30
CPPUNIT_TEST ( testParaStartCopyPaste ) ;
2013-08-20 14:56:27 -04:00
CPPUNIT_TEST ( testSectionAttributes ) ;
2017-07-06 02:00:59 +05:30
CPPUNIT_TEST ( testLargeParaCopyPaste ) ;
2012-04-11 14:29:11 -04:00
CPPUNIT_TEST_SUITE_END ( ) ;
2012-04-11 21:53:33 -04:00
private :
EditEngineItemPool * mpItemPool ;
2012-04-11 14:29:11 -04:00
} ;
2015-11-10 10:14:16 +01:00
Test : : Test ( ) : mpItemPool ( nullptr ) { }
2012-04-11 21:53:33 -04:00
void Test : : setUp ( )
{
test : : BootstrapFixture : : setUp ( ) ;
2017-08-17 01:57:59 +05:30
mpItemPool = new EditEngineItemPool ( ) ;
2017-03-10 14:53:47 +00:00
SfxApplication : : GetOrCreate ( ) ;
2012-04-11 21:53:33 -04:00
}
void Test : : tearDown ( )
{
SfxItemPool : : Free ( mpItemPool ) ;
test : : BootstrapFixture : : tearDown ( ) ;
}
2012-04-11 14:29:11 -04:00
void Test : : testConstruction ( )
{
2012-04-11 21:53:33 -04:00
EditEngine aEngine ( mpItemPool ) ;
2013-04-07 12:06:47 +02:00
OUString aParaText = " I am Edit Engine. " ;
2012-04-11 23:29:01 -04:00
aEngine . SetText ( aParaText ) ;
2012-04-11 14:29:11 -04:00
}
2012-05-11 23:11:10 -04:00
namespace {
2013-04-07 12:06:47 +02:00
bool includes ( const uno : : Sequence < OUString > & rSeq , const OUString & rVal )
2012-05-11 23:11:10 -04:00
{
for ( sal_Int32 i = 0 , n = rSeq . getLength ( ) ; i < n ; + + i )
if ( rSeq [ i ] = = rVal )
return true ;
return false ;
}
}
void Test : : testUnoTextFields ( )
{
{
// DATE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : DATE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.DateTime " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// URL
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : URL ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.URL " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// PAGE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : PAGE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.PageNumber " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// PAGES
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : PAGES ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.PageCount " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// TIME
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : TIME ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.DateTime " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// FILE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : DOCINFO_TITLE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.docinfo.Title " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// TABLE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : TABLE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.SheetName " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// EXTENDED TIME
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : EXTENDED_TIME ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.DateTime " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// EXTENDED FILE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : EXTENDED_FILE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.FileName " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// AUTHOR
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : AUTHOR ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.Author " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// MEASURE
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : MEASURE ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.text.textfield.Measure " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// PRESENTATION HEADER
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : PRESENTATION_HEADER ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.presentation.textfield.Header " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// PRESENTATION FOOTER
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : PRESENTATION_FOOTER ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.presentation.textfield.Footer " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
{
// PRESENTATION DATE TIME
2016-05-26 16:02:39 +02:00
rtl : : Reference < SvxUnoTextField > xField ( new SvxUnoTextField ( text : : textfield : : Type : : PRESENTATION_DATE_TIME ) ) ;
2015-07-13 16:17:00 +02:00
uno : : Sequence < OUString > aSvcs = xField - > getSupportedServiceNames ( ) ;
2012-05-11 23:11:10 -04:00
bool bGood = includes ( aSvcs , " com.sun.star.presentation.textfield.DateTime " ) ;
CPPUNIT_ASSERT_MESSAGE ( " expected service is not present. " , bGood ) ;
}
}
2013-03-01 10:50:11 +00:00
class TestAutoCorrDoc : public SvxAutoCorrDoc
{
public :
2013-06-06 20:51:05 +02:00
/// just like the real thing, this dummy modifies the rText parameter :(
TestAutoCorrDoc ( OUString & rText , LanguageType eLang )
: m_rText ( rText )
2013-03-01 10:50:11 +00:00
, m_eLang ( eLang )
{
}
2013-06-06 20:51:05 +02:00
OUString const & getResult ( ) const
2013-03-01 10:50:11 +00:00
{
2013-06-06 20:51:05 +02:00
return m_rText ;
2013-03-01 10:50:11 +00:00
}
private :
2013-06-06 20:51:05 +02:00
OUString & m_rText ;
2013-03-01 10:50:11 +00:00
LanguageType m_eLang ;
2015-10-12 16:04:04 +02:00
virtual bool Delete ( sal_Int32 nStt , sal_Int32 nEnd ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::Delete\n");
2013-06-06 20:51:05 +02:00
m_rText = m_rText . replaceAt ( nStt , nEnd - nStt , " " ) ;
2013-03-01 10:50:11 +00:00
return true ;
}
2015-10-12 16:04:04 +02:00
virtual bool Insert ( sal_Int32 nPos , const OUString & rTxt ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::Insert\n");
2013-06-06 20:51:05 +02:00
m_rText = m_rText . replaceAt ( nPos , 0 , rTxt ) ;
2013-03-01 10:50:11 +00:00
return true ;
}
2015-10-12 16:04:04 +02:00
virtual bool Replace ( sal_Int32 nPos , const OUString & rTxt ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::Replace\n");
2013-09-06 12:01:31 +02:00
return ReplaceRange ( nPos , rTxt . getLength ( ) , rTxt ) ;
2013-03-01 10:50:11 +00:00
}
2015-10-12 16:04:04 +02:00
virtual bool ReplaceRange ( sal_Int32 nPos , sal_Int32 nLen , const OUString & rTxt ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::ReplaceRange %d %d %s\n", nPos, nLen, OUStringToOString(rTxt, RTL_TEXTENCODING_UTF8).getStr());
2013-06-06 20:51:05 +02:00
m_rText = m_rText . replaceAt ( nPos , nLen , rTxt ) ;
2013-03-01 10:50:11 +00:00
return true ;
}
2016-01-11 16:02:17 +02:00
virtual void SetAttr ( sal_Int32 , sal_Int32 , sal_uInt16 , SfxPoolItem & ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::SetAttr\n");
}
2015-10-12 16:04:04 +02:00
virtual bool SetINetAttr ( sal_Int32 , sal_Int32 , const OUString & ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::SetINetAttr\n");
return true ;
}
2015-10-12 16:04:04 +02:00
virtual OUString const * GetPrevPara ( bool ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::GetPrevPara\n");
2015-11-10 10:14:16 +01:00
return nullptr ;
2013-03-01 10:50:11 +00:00
}
2013-09-18 13:51:35 +01:00
virtual bool ChgAutoCorrWord ( sal_Int32 & rSttPos ,
sal_Int32 nEndPos , SvxAutoCorrect & rACorrect ,
2015-10-12 16:04:04 +02:00
OUString * pPara ) override
2013-03-01 10:50:11 +00:00
{
//fprintf(stderr, "TestAutoCorrDoc::ChgAutoCorrWord\n");
2013-06-06 20:51:05 +02:00
if ( m_rText . isEmpty ( ) )
2013-03-01 10:50:11 +00:00
return false ;
2013-09-21 15:20:49 +02:00
LanguageTag aLanguageTag ( m_eLang ) ;
2013-06-06 20:51:05 +02:00
const SvxAutocorrWord * pFnd = rACorrect . SearchWordsInList (
2013-09-21 15:20:49 +02:00
m_rText , rSttPos , nEndPos , * this , aLanguageTag ) ;
2013-03-01 10:50:11 +00:00
if ( pFnd & & pFnd - > IsTextOnly ( ) )
{
2013-06-06 20:51:05 +02:00
m_rText = m_rText . replaceAt ( rSttPos , nEndPos , pFnd - > GetLong ( ) ) ;
2013-09-06 12:01:31 +02:00
if ( pPara )
2014-12-18 13:23:07 +01:00
pPara - > clear ( ) ; // =&pCurNode->GetString();
2013-03-01 10:50:11 +00:00
return true ;
}
return false ;
}
} ;
2013-11-17 08:33:01 +01:00
//https://bugs.libreoffice.org/show_bug.cgi?id=55693
2013-03-01 10:50:11 +00:00
//Two capitalized letters are not corrected if dash or slash are directly
//before the two letters
void Test : : testAutocorrect ( )
{
2017-07-13 11:46:41 +02:00
SvxAutoCorrect aAutoCorrect ( ( OUString ( ) ) , ( OUString ( ) ) ) ;
2013-03-01 10:50:11 +00:00
{
OUString sInput ( " TEst-TEst " ) ;
2017-06-23 10:22:25 +02:00
sal_Unicode const cNextChar ( ' ' ) ;
OUString const sExpected ( " Test-Test " ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2013-03-01 10:50:11 +00:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2013-03-01 10:50:11 +00:00
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " autocorrect " , sExpected , aFoo . getResult ( ) ) ;
2013-03-01 10:50:11 +00:00
}
{
OUString sInput ( " TEst/TEst " ) ;
2017-06-23 10:22:25 +02:00
sal_Unicode const cNextChar ( ' ' ) ;
OUString const sExpected ( " Test/Test " ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2013-03-01 10:50:11 +00:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2013-03-01 10:50:11 +00:00
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " autocorrect " , sExpected , aFoo . getResult ( ) ) ;
2013-03-01 10:50:11 +00:00
}
2013-06-06 20:51:05 +02:00
{
// test auto-bolding with '*'
OUString sInput ( " *foo " ) ;
2017-06-23 10:22:25 +02:00
sal_Unicode const cNextChar ( ' * ' ) ;
OUString const sExpected ( " foo " ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2013-06-06 20:51:05 +02:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2013-06-06 20:51:05 +02:00
CPPUNIT_ASSERT_EQUAL ( sExpected , aFoo . getResult ( ) ) ;
}
2016-07-01 14:38:54 +01:00
{
OUString sInput ( " Test. test " ) ;
2017-06-23 10:22:25 +02:00
sal_Unicode const cNextChar ( ' ' ) ;
OUString const sExpected ( " Test. Test " ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2016-07-01 14:38:54 +01:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2016-07-01 14:38:54 +01:00
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " autocorrect " , sExpected , aFoo . getResult ( ) ) ;
2016-07-01 14:38:54 +01:00
}
2017-06-19 15:02:17 +01:00
// don't autocapitalize after a field mark
2016-07-01 14:38:54 +01:00
{
OUString sInput ( " Test. \x01 test " ) ;
2017-06-23 10:22:25 +02:00
sal_Unicode const cNextChar ( ' ' ) ;
OUString const sExpected ( " Test. \x01 test " ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2016-07-01 14:38:54 +01:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2016-07-01 14:38:54 +01:00
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " autocorrect " , sExpected , aFoo . getResult ( ) ) ;
2016-07-01 14:38:54 +01:00
}
2017-06-19 15:02:17 +01:00
// consider field contents as text for auto quotes
{
OUString sInput ( " T \x01 " ) ;
2017-06-13 10:27:38 +02:00
sal_Unicode const cNextChar ( ' " ' ) ;
2017-06-19 15:02:17 +01:00
const sal_Unicode EXPECTED [ ] = { ' T ' , 0x01 , 0x0201d } ;
OUString sExpected ( EXPECTED , SAL_N_ELEMENTS ( EXPECTED ) ) ;
2017-08-23 17:44:16 +02:00
bool bNbspRunNext = false ;
2017-06-19 15:02:17 +01:00
TestAutoCorrDoc aFoo ( sInput , LANGUAGE_ENGLISH_US ) ;
aAutoCorrect . SetAutoCorrFlag ( ChgQuotes , true ) ;
2017-08-23 17:44:16 +02:00
aAutoCorrect . DoAutoCorrect ( aFoo , sInput , sInput . getLength ( ) , cNextChar , true , bNbspRunNext ) ;
2017-06-19 15:02:17 +01:00
fprintf ( stderr , " text is %x \n " , aFoo . getResult ( ) [ aFoo . getResult ( ) . getLength ( ) - 1 ] ) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " autocorrect " , sExpected , aFoo . getResult ( ) ) ;
}
2013-08-20 14:56:27 -04:00
}
2017-07-13 00:36:46 +05:30
IMPL_STATIC_LINK ( Test , CalcFieldValueHdl , EditFieldInfo * , pInfo , void )
{
if ( ! pInfo )
return ;
const SvxFieldItem & rField = pInfo - > GetField ( ) ;
const SvxFieldData * pField = rField . GetField ( ) ;
if ( const SvxURLField * pURLField = dynamic_cast < const SvxURLField * > ( pField ) )
{
// URLField
OUString aURL = pURLField - > GetURL ( ) ;
switch ( pURLField - > GetFormat ( ) )
{
2017-09-15 10:34:59 +02:00
case SvxURLFormat : : AppDefault :
case SvxURLFormat : : Repr :
2017-07-13 00:36:46 +05:30
{
pInfo - > SetRepresentation ( pURLField - > GetRepresentation ( ) ) ;
}
break ;
2017-09-15 10:34:59 +02:00
case SvxURLFormat : : Url :
2017-07-13 00:36:46 +05:30
{
pInfo - > SetRepresentation ( aURL ) ;
}
break ;
}
}
else
{
OSL_FAIL ( " Unknown Field " ) ;
pInfo - > SetRepresentation ( OUString ( ' ? ' ) ) ;
}
}
2017-03-23 20:11:28 +05:30
void Test : : testHyperlinkCopyPaste ( )
{
2017-07-13 00:36:46 +05:30
// Create Outliner instance
Outliner aOutliner ( mpItemPool , OutlinerMode
: : TextObject ) ;
aOutliner . SetCalcFieldValueHdl ( LINK ( nullptr , Test , CalcFieldValueHdl ) ) ;
2017-03-23 20:11:28 +05:30
// Create EditEngine's instance
2017-07-13 00:36:46 +05:30
EditEngine & aEditEngine = const_cast < EditEngine & > ( aOutliner . GetEditEngine ( ) ) ;
2017-03-23 20:11:28 +05:30
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
2017-05-02 13:04:17 +02:00
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-23 20:11:28 +05:30
// Get corresponding Field Item for inserting URLs in text
// URL 1
OUString aURL1 = " mailto:///user@example.com " ;
OUString aRepres1 = " user@example.com " ;
2017-09-15 10:34:59 +02:00
SvxURLField aURLField1 ( aURL1 , aRepres1 , SvxURLFormat : : Repr ) ;
2017-03-23 20:11:28 +05:30
SvxFieldItem aField1 ( aURLField1 , EE_FEATURE_FIELD ) ;
// URL 2
OUString aURL2 = " mailto:///example@domain.com " ;
OUString aRepres2 = " example@domain.com " ;
2017-09-15 10:34:59 +02:00
SvxURLField aURLField2 ( aURL2 , aRepres2 , SvxURLFormat : : Repr ) ;
2017-03-23 20:11:28 +05:30
SvxFieldItem aField2 ( aURLField2 , EE_FEATURE_FIELD ) ;
// Insert initial text
OUString aParaText = " sampletextfortestingfeaturefields " ;
// Positions Ref .............*13....*20..........
sal_Int32 aTextLen = aParaText . getLength ( ) ;
aEditEngine . SetText ( aParaText ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aParaText , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert URL 1
ContentNode * pNode = rDoc . GetObject ( 0 ) ;
EditSelection aSel1 ( EditPaM ( pNode , 13 ) , EditPaM ( pNode , 13 ) ) ;
aEditEngine . InsertField ( aSel1 , aField1 ) ;
// Assert Field Count
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( 1 ) , aEditEngine . GetFieldCount ( 0 ) ) ;
// Insert URL 2
EditSelection aSel2 ( EditPaM ( pNode , 20 + 1 ) , EditPaM ( pNode , 20 + 1 ) ) ;
aEditEngine . InsertField ( aSel2 , aField2 ) ;
// Assert Field Count
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( 2 ) , aEditEngine . GetFieldCount ( 0 ) ) ;
// Assert URL Fields and text before copy
// Check text
2017-07-13 00:36:46 +05:30
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( " sampletextfortestingfeaturefields " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-23 20:11:28 +05:30
// Check Field 1
EFieldInfo aURLFieldInfo1 = aEditEngine . GetFieldInfo ( sal_Int32 ( 0 ) , sal_uInt16 ( 0 ) ) ;
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 13 ) , aURLFieldInfo1 . aPosition . nIndex ) ;
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( EE_FEATURE_FIELD ) , aURLFieldInfo1 . pFieldItem - > Which ( ) ) ;
SvxURLField * pURLField1 = dynamic_cast < SvxURLField * > ( const_cast < SvxFieldData * > ( aURLFieldInfo1 . pFieldItem - > GetField ( ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aURL1 , pURLField1 - > GetURL ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aRepres1 , pURLField1 - > GetRepresentation ( ) ) ;
// Check Field 2
EFieldInfo aURLFieldInfo2 = aEditEngine . GetFieldInfo ( sal_Int32 ( 0 ) , sal_uInt16 ( 1 ) ) ;
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 21 ) , aURLFieldInfo2 . aPosition . nIndex ) ;
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( EE_FEATURE_FIELD ) , aURLFieldInfo2 . pFieldItem - > Which ( ) ) ;
SvxURLField * pURLField2 = dynamic_cast < SvxURLField * > ( const_cast < SvxFieldData * > ( aURLFieldInfo2 . pFieldItem - > GetField ( ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aURL2 , pURLField2 - > GetURL ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aRepres2 , pURLField2 - > GetRepresentation ( ) ) ;
// Copy text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 10 , 0 , 21 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert Changes ACP, ACP: after Copy/Paste
// Check the fields count
2017-07-13 00:36:46 +05:30
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( 3 ) , aEditEngine . GetFieldCount ( 0 ) ) ;
2017-03-23 20:11:28 +05:30
// Check the updated text length
2017-07-13 00:36:46 +05:30
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + 10 ) , rDoc . GetTextLen ( ) ) ;
2017-03-23 20:11:28 +05:30
// Check the updated text contents
2017-07-13 00:36:46 +05:30
CPPUNIT_ASSERT_EQUAL ( OUString ( " sampletextfortestingfeaturefieldsfortesting " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-23 20:11:28 +05:30
// Check the Fields and their values
// Field 1
EFieldInfo aACPURLFieldInfo1 = aEditEngine . GetFieldInfo ( sal_Int32 ( 0 ) , sal_uInt16 ( 0 ) ) ;
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 13 ) , aACPURLFieldInfo1 . aPosition . nIndex ) ;
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( EE_FEATURE_FIELD ) , aACPURLFieldInfo1 . pFieldItem - > Which ( ) ) ;
SvxURLField * pACPURLField1 = dynamic_cast < SvxURLField * > ( const_cast < SvxFieldData * > ( aACPURLFieldInfo1 . pFieldItem - > GetField ( ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aURL1 , pACPURLField1 - > GetURL ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aRepres1 , pACPURLField1 - > GetRepresentation ( ) ) ;
// Field 2
EFieldInfo aACPURLFieldInfo2 = aEditEngine . GetFieldInfo ( sal_Int32 ( 0 ) , sal_uInt16 ( 1 ) ) ;
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 21 ) , aACPURLFieldInfo2 . aPosition . nIndex ) ;
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( EE_FEATURE_FIELD ) , aACPURLFieldInfo2 . pFieldItem - > Which ( ) ) ;
SvxURLField * pACPURLField2 = dynamic_cast < SvxURLField * > ( const_cast < SvxFieldData * > ( aACPURLFieldInfo2 . pFieldItem - > GetField ( ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aURL2 , pACPURLField2 - > GetURL ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aRepres2 , pACPURLField2 - > GetRepresentation ( ) ) ;
// Field 3
2017-07-13 00:36:46 +05:30
EFieldInfo aACPURLFieldInfo3 = aEditEngine . GetFieldInfo ( sal_Int32 ( 0 ) , sal_uInt16 ( 2 ) ) ;
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 38 ) , aACPURLFieldInfo3 . aPosition . nIndex ) ;
CPPUNIT_ASSERT_EQUAL ( sal_uInt16 ( EE_FEATURE_FIELD ) , aACPURLFieldInfo3 . pFieldItem - > Which ( ) ) ;
SvxURLField * pACPURLField3 = dynamic_cast < SvxURLField * > ( const_cast < SvxFieldData * > ( aACPURLFieldInfo3 . pFieldItem - > GetField ( ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aURL1 , pACPURLField3 - > GetURL ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aRepres1 , pACPURLField3 - > GetRepresentation ( ) ) ;
2017-03-23 20:11:28 +05:30
}
2017-02-22 21:57:44 +05:30
void Test : : testCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
2017-05-02 13:04:17 +02:00
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-02-22 21:57:44 +05:30
// Set initial text
OUString aText = " This is custom initial text " ;
sal_Int32 aTextLen = aText . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aText , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Copy initial text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 0 , 0 , aTextLen ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( aText + aText ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
}
2017-06-23 09:39:21 +05:30
void Test : : testMultiParaSelCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert initial text
OUString aFirstPara = " This is first paragraph " ;
// Selection Ref ........8..............
OUString aSecondPara = " This is second paragraph " ;
// Selection Ref .............14.........
OUString aThirdPara = " This is third paragraph " ;
OUString aText = aFirstPara + " \n " + aSecondPara + " \n " + aThirdPara ;
sal_Int32 aTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) + aThirdPara . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
OUString aCopyText = " first paragraphThis is second " ;
sal_Int32 aCopyTextLen = aCopyText . getLength ( ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
// Copy initial text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 8 , 1 , 14 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
OUString aThirdParaAfterCopyPaste = aThirdPara + " first paragraph " ;
OUString aFourthPara = " This is second " ;
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aCopyTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFourthPara , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
}
2017-03-23 14:42:40 +05:30
void Test : : testTabsCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
2017-05-02 13:04:17 +02:00
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-23 14:42:40 +05:30
// Get corresponding Item for inserting tabs in the text
SfxVoidItem aTab ( EE_FEATURE_TAB ) ;
// Insert initial text
OUString aParaText = " sampletextfortestingtab " ;
// Positions Ref ......*6...............*23
sal_Int32 aTextLen = aParaText . getLength ( ) ;
aEditEngine . SetText ( aParaText ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aParaText , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert tab 1 at desired position
ContentNode * pNode = rDoc . GetObject ( 0 ) ;
EditSelection aSel1 ( EditPaM ( pNode , 6 ) , EditPaM ( pNode , 6 ) ) ;
aEditEngine . InsertFeature ( aSel1 , aTab ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + 1 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( " sample \t textfortestingtab " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert tab 2 at desired position
EditSelection aSel2 ( EditPaM ( pNode , 23 + 1 ) , EditPaM ( pNode , 23 + 1 ) ) ;
aEditEngine . InsertFeature ( aSel2 , aTab ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + 2 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( " sample \t textfortestingtab \t " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Copy text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 6 , 0 , aTextLen + 2 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aTextLen - 6 + 4 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( " sample \t textfortestingtab \t \t textfortestingtab \t " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
}
2014-07-27 00:21:50 -04:00
namespace {
class UrlEditEngine : public EditEngine
{
public :
2015-09-07 09:33:18 +01:00
explicit UrlEditEngine ( SfxItemPool * pPool ) : EditEngine ( pPool ) { }
2014-07-27 00:21:50 -04:00
2015-10-12 16:04:04 +02:00
virtual OUString CalcFieldValue ( const SvxFieldItem & , sal_Int32 , sal_Int32 , Color * & , Color * & ) override
2014-07-27 00:21:50 -04:00
{
return OUString ( " jim@bob.com " ) ; // a sophisticated view of value:
}
} ;
}
// Odd accounting for hyperlink position & size etc.
// https://bugzilla.novell.com/show_bug.cgi?id=467459
void Test : : testHyperlinkSearch ( )
{
UrlEditEngine aEngine ( mpItemPool ) ;
EditDoc & rDoc = aEngine . GetEditDoc ( ) ;
OUString aSampleText = " Please write email to . if you find a fish(not a dog). " ;
aEngine . SetText ( aSampleText ) ;
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " set text " , aSampleText , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2014-07-27 00:21:50 -04:00
ContentNode * pNode = rDoc . GetObject ( 0 ) ;
EditSelection aSel ( EditPaM ( pNode , 22 ) , EditPaM ( pNode , 22 ) ) ;
SvxURLField aURLField ( " mailto:///jim@bob.com " , " jim@bob.com " ,
2017-09-15 10:34:59 +02:00
SvxURLFormat : : Repr ) ;
2014-07-27 00:21:50 -04:00
SvxFieldItem aField ( aURLField , EE_FEATURE_FIELD ) ;
aEngine . InsertField ( aSel , aField ) ;
aEngine . UpdateFields ( ) ;
OUString aContent = pNode - > GetExpandedText ( ) ;
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " get text " , OUString ( " Please write email to jim@bob.com. if you find a fish(not a dog). " ) ,
aContent ) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " wrong length " , ( sal_uLong ) aContent . getLength ( ) , rDoc . GetTextLen ( ) ) ;
2014-07-27 00:21:50 -04:00
// Check expansion and positioning re-work
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " wrong length " , ( sal_uLong ) aContent . getLength ( ) ,
pNode - > GetExpandedLen ( ) ) ;
2014-07-27 00:21:50 -04:00
for ( sal_Int32 n = 0 ; n < aContent . getLength ( ) ; n + + )
{
sal_Int32 nStart = n , nEnd = n ;
pNode - > UnExpandPositions ( nStart , nEnd ) ;
CPPUNIT_ASSERT_MESSAGE ( " out of bound start " , nStart < pNode - > Len ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " out of bound end " , nEnd < = pNode - > Len ( ) ) ;
}
static const struct {
sal_Int32 mnStart , mnEnd ;
sal_Int32 mnNewStart , mnNewEnd ;
} aTrickyOnes [ ] = {
{ 0 , 1 , /* -> */ 0 , 1 } ,
{ 21 , 25 , /* -> */ 21 , 23 } , // the field is really just one char
{ 25 , 27 , /* -> */ 22 , 23 } ,
{ 50 , 56 , /* -> */ 40 , 46 }
} ;
for ( size_t n = 0 ; n < SAL_N_ELEMENTS ( aTrickyOnes ) ; n + + )
{
sal_Int32 nStart = aTrickyOnes [ n ] . mnStart ;
sal_Int32 nEnd = aTrickyOnes [ n ] . mnEnd ;
pNode - > UnExpandPositions ( nStart , nEnd ) ;
2016-09-20 11:20:31 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE (
OString ( " in row " + OString : : number ( n ) ) . getStr ( ) ,
aTrickyOnes [ n ] . mnNewStart , nStart ) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE (
OString ( " in row " + OString : : number ( n ) ) . getStr ( ) ,
aTrickyOnes [ n ] . mnNewEnd , nEnd ) ;
2014-07-27 00:21:50 -04:00
}
SvxSearchItem aItem ( 1 ) ; //SID_SEARCH_ITEM);
aItem . SetBackward ( false ) ;
aItem . SetSelection ( false ) ;
aItem . SetSearchString ( " fish " ) ;
CPPUNIT_ASSERT_MESSAGE ( " no fish " , aEngine . HasText ( aItem ) ) ;
aItem . SetSearchString ( " dog " ) ;
CPPUNIT_ASSERT_MESSAGE ( " no dog " , aEngine . HasText ( aItem ) ) ;
}
2013-08-28 14:41:12 -04:00
bool hasBold ( const editeng : : Section & rSecAttr )
2013-08-20 14:56:27 -04:00
{
std : : vector < const SfxPoolItem * > : : const_iterator it = rSecAttr . maAttributes . begin ( ) , itEnd = rSecAttr . maAttributes . end ( ) ;
for ( ; it ! = itEnd ; + + it )
{
const SfxPoolItem * p = * it ;
if ( p - > Which ( ) ! = EE_CHAR_WEIGHT )
continue ;
if ( static_cast < const SvxWeightItem * > ( p ) - > GetWeight ( ) ! = WEIGHT_BOLD )
continue ;
return true ;
}
return false ;
}
2013-08-28 14:41:12 -04:00
bool hasItalic ( const editeng : : Section & rSecAttr )
2013-08-20 14:56:27 -04:00
{
std : : vector < const SfxPoolItem * > : : const_iterator it = rSecAttr . maAttributes . begin ( ) , itEnd = rSecAttr . maAttributes . end ( ) ;
for ( ; it ! = itEnd ; + + it )
{
const SfxPoolItem * p = * it ;
if ( p - > Which ( ) ! = EE_CHAR_ITALIC )
continue ;
if ( static_cast < const SvxPostureItem * > ( p ) - > GetPosture ( ) ! = ITALIC_NORMAL )
continue ;
return true ;
}
return false ;
}
2017-03-09 02:02:15 +05:30
void Test : : testBoldItalicCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
2017-05-02 13:04:17 +02:00
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-09 02:02:15 +05:30
// Get corresponding ItemSet for inserting Bold/Italic text
std : : unique_ptr < SfxItemSet > pSet ( new SfxItemSet ( aEditEngine . GetEmptyItemSet ( ) ) ) ;
SvxWeightItem aBold ( WEIGHT_BOLD , EE_CHAR_WEIGHT ) ;
SvxPostureItem aItalic ( ITALIC_NORMAL , EE_CHAR_ITALIC ) ;
// Insert initial text
OUString aParaText = " boldeditengineitalic " ;
// Positions Ref ..*2....*8...*13.*17
// Bold Ref ..[ BOLD ]......
// Italic Ref ........[ ITALIC ]..
sal_Int32 aTextLen = aParaText . getLength ( ) ;
aEditEngine . SetText ( aParaText ) ;
// Assert changes - text insertion
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aParaText , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Apply Bold to appropriate selection
pSet - > Put ( aBold ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 2 , 0 , 14 ) ) ;
// Assert changes
std : : unique_ptr < EditTextObject > pEditText1 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs1 ;
pEditText1 - > GetAllSections ( aAttrs1 ) ;
// There should be 3 sections - woBold - wBold - woBold (w - with, wo - without)
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 3 ) , aAttrs1 . size ( ) ) ;
2017-03-09 02:02:15 +05:30
const editeng : : Section * pSecAttr = & aAttrs1 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs1 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 20 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
// Apply Italic to appropriate selection
pSet . reset ( new SfxItemSet ( aEditEngine . GetEmptyItemSet ( ) ) ) ;
pSet - > Put ( aItalic ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 8 , 0 , 18 ) ) ;
// Assert changes
std : : unique_ptr < EditTextObject > pEditText2 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs2 ;
pEditText2 - > GetAllSections ( aAttrs2 ) ;
// There should be 5 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic (w - with, wo - without)
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 5 ) , aAttrs2 . size ( ) ) ;
2017-03-09 02:02:15 +05:30
pSecAttr = & aAttrs2 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs2 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 8 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 8 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 4 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 20 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
// Copy text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 1 , 0 , aTextLen - 1 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aTextLen - 2 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( aParaText + " oldeditengineitali " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Check updated text for appropriate Bold/Italics
std : : unique_ptr < EditTextObject > pEditText3 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs3 ;
pEditText3 - > GetAllSections ( aAttrs3 ) ;
// There should be 9 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic - wBold&woItalic
// - wBold&wItalic - woBold&wItalic - woBold&woItalic(w - with, wo - without)
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 9 ) , aAttrs3 . size ( ) ) ;
2017-03-09 02:02:15 +05:30
pSecAttr = & aAttrs3 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs3 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 8 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 8 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 4 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 21 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs3 [ 5 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 21 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 27 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 6 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 27 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 33 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 7 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 33 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 37 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 8 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 37 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 38 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
}
2017-03-15 17:23:32 +05:30
// Auxiliary function to test Underline text Copy/Paste using Legacy Format
bool hasUnderline ( const editeng : : Section & rSecAttr )
{
std : : vector < const SfxPoolItem * > : : const_iterator it = rSecAttr . maAttributes . begin ( ) , itEnd = rSecAttr . maAttributes . end ( ) ;
for ( ; it ! = itEnd ; + + it )
{
const SfxPoolItem * p = * it ;
if ( p - > Which ( ) ! = EE_CHAR_UNDERLINE )
continue ;
if ( static_cast < const SvxUnderlineItem * > ( p ) - > GetLineStyle ( ) ! = LINESTYLE_SINGLE )
continue ;
return true ;
}
return false ;
}
void Test : : testUnderlineCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
2017-05-02 13:04:17 +02:00
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
2017-03-15 17:23:32 +05:30
// Get corresponding ItemSet for inserting Underline text
std : : unique_ptr < SfxItemSet > pSet ( new SfxItemSet ( aEditEngine . GetEmptyItemSet ( ) ) ) ;
SvxUnderlineItem aULine ( LINESTYLE_SINGLE , EE_CHAR_UNDERLINE ) ;
// Insert initial text
OUString aParaText = " sampletextforunderline " ;
// Positions Ref ......*6.........*17..
// Underline Ref ......[UNDERLINE ]....
sal_Int32 aTextLen = aParaText . getLength ( ) ;
aEditEngine . SetText ( aParaText ) ;
// Apply Underline style
pSet - > Put ( aULine ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 6 , 0 , 18 ) ) ;
// Assert changes
std : : unique_ptr < EditTextObject > pEditText1 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs1 ;
pEditText1 - > GetAllSections ( aAttrs1 ) ;
// There should be 3 sections - woUnderline - wUnderline - woUnderline (w - with, wo - without)
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 3 ) , aAttrs1 . size ( ) ) ;
2017-03-15 17:23:32 +05:30
const editeng : : Section * pSecAttr = & aAttrs1 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be underlined. " , hasUnderline ( * pSecAttr ) ) ;
pSecAttr = & aAttrs1 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 22 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
// Copy text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 6 , 0 , aTextLen - 4 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + ( OUString ( " textforunder " ) ) . getLength ( ) ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( aParaText + " textforunder " ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Check updated text for appropriate Underline
std : : unique_ptr < EditTextObject > pEditText2 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs2 ;
pEditText2 - > GetAllSections ( aAttrs2 ) ;
// There should be 4 sections - woUnderline - wUnderline - woUnderline - wUnderline (w - with, wo - without)
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 4 ) , aAttrs2 . size ( ) ) ;
2017-03-15 17:23:32 +05:30
pSecAttr = & aAttrs2 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs2 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be underlined. " , hasUnderline ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 22 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs2 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 22 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 34 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be underlined. " , hasUnderline ( * pSecAttr ) ) ;
}
2017-06-22 22:05:21 +05:30
void Test : : testMultiParaCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert initial text
OUString aFirstPara = " This is first paragraph " ;
OUString aSecondPara = " This is second paragraph " ;
OUString aThirdPara = " This is third paragraph " ;
OUString aText = aFirstPara + " \n " + aSecondPara + " \n " + aThirdPara ;
sal_Int32 aTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) + aThirdPara . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
sal_Int32 aCopyTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
// Copy initial text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 0 , 1 , aSecondPara . getLength ( ) ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
OUString aThirdParaAfterCopyPaste = aThirdPara + aFirstPara ;
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aCopyTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
}
2017-06-25 02:27:27 +05:30
void Test : : testParaBoldItalicCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Get corresponding ItemSet for inserting Bold/Italic text
std : : unique_ptr < SfxItemSet > pSet ( new SfxItemSet ( aEditEngine . GetEmptyItemSet ( ) ) ) ;
SvxWeightItem aBold ( WEIGHT_BOLD , EE_CHAR_WEIGHT ) ;
SvxPostureItem aItalic ( ITALIC_NORMAL , EE_CHAR_ITALIC ) ;
// Insert initial text
OUString aFirstPara = " This is first paragraph " ;
// Positions Ref .....*5.*8....*14*17...
// Bold Ref .....[ BOLD ].....
// Italic Ref ..............[ ITA
// Copy Ref ........[ Copy Sel
OUString aSecondPara = " This is second paragraph " ;
// Positions Ref .....*5.*8...*13..*18...
// Bold Ref .....[ BOLD ].....
// Italic Ref LIC ]...............
// Copy Ref ection ]..........
OUString aThirdPara = " This is third paragraph " ;
OUString aText = aFirstPara + " \n " + aSecondPara + " \n " + aThirdPara ;
sal_Int32 aTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) + aThirdPara . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
OUString aCopyText = " first paragraphThis is second " ;
sal_Int32 aCopyTextLen = aCopyText . getLength ( ) ;
// Assert changes - text insertion
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
// Apply Bold to appropriate selections
pSet - > Put ( aBold ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 5 , 0 , 18 ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 1 , 5 , 1 , 19 ) ) ;
// Assert changes
std : : unique_ptr < EditTextObject > pEditText1 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs1 ;
pEditText1 - > GetAllSections ( aAttrs1 ) ;
// There should be 7 sections - woB - wB - woB -woB -wB -woB -woB (w - with, wo - without, B - Bold, I - Italic)
CPPUNIT_ASSERT_EQUAL ( size_t ( 7 ) , aAttrs1 . size ( ) ) ;
const editeng : : Section * pSecAttr = & aAttrs1 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs1 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 4 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs1 [ 5 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 24 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs1 [ 6 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
// Apply Italic to appropriate selection
pSet . reset ( new SfxItemSet ( aEditEngine . GetEmptyItemSet ( ) ) ) ;
pSet - > Put ( aItalic ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
aEditEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 14 , 1 , 9 ) ) ;
// Assert changes
std : : unique_ptr < EditTextObject > pEditText2 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs2 ;
pEditText2 - > GetAllSections ( aAttrs2 ) ;
// There should be 9 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI (w - with, wo - without, B - Bold, I - Italic)
CPPUNIT_ASSERT_EQUAL ( size_t ( 9 ) , aAttrs2 . size ( ) ) ;
pSecAttr = & aAttrs2 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs2 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 4 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 5 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 6 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs2 [ 7 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 24 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs2 [ 8 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
// Copy text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 8 , 1 , 14 ) ) ;
// Paste text at the end
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetEndPaM ( ) , true ) ;
// Assert changes
OUString aThirdParaAfterCopyPaste = aThirdPara + " first paragraph " ;
OUString aFourthParaAfterCopyPaste = " This is second " ;
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aCopyTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFourthParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
// Check updated text for appropriate Bold/Italics
std : : unique_ptr < EditTextObject > pEditText3 ( aEditEngine . CreateTextObject ( ) ) ;
std : : vector < editeng : : Section > aAttrs3 ;
pEditText3 - > GetAllSections ( aAttrs3 ) ;
// There should be 15 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI
// - wB&woI - wB&wI - woB&wI - -woB&wI - wB&wI - wB&woI (w - with, wo - without, B - Bold, I - Italic)
CPPUNIT_ASSERT_EQUAL ( size_t ( 15 ) , aAttrs3 . size ( ) ) ;
pSecAttr = & aAttrs3 [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs3 [ 1 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 2 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 3 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 18 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 4 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 5 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 6 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 7 ] ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 19 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 24 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs3 [ 8 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
pSecAttr = & aAttrs3 [ 9 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 23 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 29 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 10 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 29 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 33 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 11 ] ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 33 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 38 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 12 ] ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 13 ] ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
pSecAttr = & aAttrs3 [ 14 ] ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 14 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
}
2017-07-04 02:08:40 +05:30
void Test : : testParaStartCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert initial text
OUString aFirstPara = " This is first paragraph " ;
// Selection Ref ........8..............
OUString aSecondPara = " This is second paragraph " ;
// Selection Ref .............14.........
OUString aThirdPara = " This is third paragraph " ;
OUString aText = aFirstPara + " \n " + aSecondPara + " \n " + aThirdPara ;
sal_Int32 aTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) + aThirdPara . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
OUString aCopyText = " first paragraphThis is second " ;
sal_Int32 aCopyTextLen = aCopyText . getLength ( ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
// Copy initial text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 0 , 8 , 1 , 14 ) ) ;
// Paste text at the start
aEditEngine . InsertText ( xData , OUString ( ) , rDoc . GetStartPaM ( ) , true ) ;
// Assert changes
OUString aFirstParaAfterCopyPaste = " first paragraph " ;
OUString aSecondParaAfterCopyPaste = " This is second " + aFirstPara ;
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aCopyTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
}
2013-08-20 14:56:27 -04:00
void Test : : testSectionAttributes ( )
{
EditEngine aEngine ( mpItemPool ) ;
2015-09-17 17:10:47 +01:00
std : : unique_ptr < SfxItemSet > pSet ( new SfxItemSet ( aEngine . GetEmptyItemSet ( ) ) ) ;
2013-08-20 14:56:27 -04:00
SvxWeightItem aBold ( WEIGHT_BOLD , EE_CHAR_WEIGHT ) ;
SvxPostureItem aItalic ( ITALIC_NORMAL , EE_CHAR_ITALIC ) ;
2013-06-06 20:51:05 +02:00
2013-08-28 11:16:12 -04:00
{
OUString aParaText = " aaabbbccc " ;
aEngine . SetText ( aParaText ) ;
pSet - > Put ( aBold ) ;
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " There should be exactly one item. " , static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
2013-08-28 11:16:12 -04:00
aEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 0 , 0 , 6 ) ) ; // 'aaabbb' - end point is not inclusive.
pSet . reset ( new SfxItemSet ( aEngine . GetEmptyItemSet ( ) ) ) ;
pSet - > Put ( aItalic ) ;
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " There should be exactly one item. " , static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
2013-08-28 11:16:12 -04:00
aEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 3 , 0 , 9 ) ) ; // 'bbbccc'
2015-09-17 17:10:47 +01:00
std : : unique_ptr < EditTextObject > pEditText ( aEngine . CreateTextObject ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " Failed to create text object. " , pEditText . get ( ) ) ;
2013-08-28 14:41:12 -04:00
std : : vector < editeng : : Section > aAttrs ;
pEditText - > GetAllSections ( aAttrs ) ;
2013-08-28 11:16:12 -04:00
// Now, we should have a total of 3 sections.
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " There should be 3 sections. " , static_cast < size_t > ( 3 ) , aAttrs . size ( ) ) ;
2013-08-28 11:16:12 -04:00
// First section should be 0-3 of paragraph 0, and it should only have boldness applied.
2013-08-28 14:41:12 -04:00
const editeng : : Section * pSecAttr = & aAttrs [ 0 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
// Second section should be 3-6, and it should be both bold and italic.
pSecAttr = & aAttrs [ 1 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold and italic. " , hasBold ( * pSecAttr ) & & hasItalic ( * pSecAttr ) ) ;
// Third section should be 6-9, and it should be only italic.
pSecAttr = & aAttrs [ 2 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 6 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 9 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be italic. " , hasItalic ( * pSecAttr ) ) ;
}
{
// Set text consisting of 5 paragraphs with the 2nd and 4th paragraphs
// being empty.
aEngine . Clear ( ) ;
aEngine . SetText ( " one \n \n two \n \n three " ) ;
sal_Int32 nParaCount = aEngine . GetParagraphCount ( ) ;
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( sal_Int32 ( 5 ) , nParaCount ) ;
2013-08-28 11:16:12 -04:00
// Apply boldness to paragraphs 1, 3, 5 only. Leave 2 and 4 unformatted.
pSet . reset ( new SfxItemSet ( aEngine . GetEmptyItemSet ( ) ) ) ;
pSet - > Put ( aBold ) ;
2016-09-23 09:05:10 +02:00
CPPUNIT_ASSERT_EQUAL_MESSAGE ( " There should be exactly one item. " , static_cast < sal_uInt16 > ( 1 ) , pSet - > Count ( ) ) ;
2013-08-28 11:16:12 -04:00
aEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 0 , 0 , 3 ) ) ;
aEngine . QuickSetAttribs ( * pSet , ESelection ( 2 , 0 , 2 , 3 ) ) ;
aEngine . QuickSetAttribs ( * pSet , ESelection ( 4 , 0 , 4 , 5 ) ) ;
2015-09-17 17:10:47 +01:00
std : : unique_ptr < EditTextObject > pEditText ( aEngine . CreateTextObject ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " Failed to create text object. " , pEditText . get ( ) ) ;
2013-08-28 14:41:12 -04:00
std : : vector < editeng : : Section > aAttrs ;
pEditText - > GetAllSections ( aAttrs ) ;
2017-06-23 10:22:25 +02:00
CPPUNIT_ASSERT_EQUAL ( size_t ( 5 ) , aAttrs . size ( ) ) ;
2013-08-28 11:16:12 -04:00
// 1st, 3rd and 5th sections should correspond with 1st, 3rd and 5th paragraphs.
2013-08-28 14:41:12 -04:00
const editeng : : Section * pSecAttr = & aAttrs [ 0 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs [ 2 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 2 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
pSecAttr = & aAttrs [ 4 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 4 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 5 , ( int ) pSecAttr - > mnEnd ) ;
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > maAttributes . size ( ) ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " This section must be bold. " , hasBold ( * pSecAttr ) ) ;
// The 2nd and 4th paragraphs should be empty.
pSecAttr = & aAttrs [ 1 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 1 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnEnd ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " Attribute array should be empty. " , pSecAttr - > maAttributes . empty ( ) ) ;
pSecAttr = & aAttrs [ 3 ] ;
2014-02-02 22:16:48 -06:00
CPPUNIT_ASSERT_EQUAL ( 3 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnEnd ) ;
2013-08-28 11:16:12 -04:00
CPPUNIT_ASSERT_MESSAGE ( " Attribute array should be empty. " , pSecAttr - > maAttributes . empty ( ) ) ;
}
2014-12-01 19:21:49 +01:00
{
aEngine . Clear ( ) ;
aEngine . SetText ( " one \n two " ) ;
2014-12-02 07:54:10 +02:00
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_Int32 > ( 2 ) , aEngine . GetParagraphCount ( ) ) ;
2014-12-01 19:21:49 +01:00
// embolden 2nd paragraph
pSet . reset ( new SfxItemSet ( aEngine . GetEmptyItemSet ( ) ) ) ;
pSet - > Put ( aBold ) ;
aEngine . QuickSetAttribs ( * pSet , ESelection ( 1 , 0 , 1 , 3 ) ) ;
// disboldify 1st paragraph
SvxWeightItem aNotSoBold ( WEIGHT_NORMAL , EE_CHAR_WEIGHT ) ;
pSet - > Put ( aNotSoBold ) ;
aEngine . QuickSetAttribs ( * pSet , ESelection ( 0 , 0 , 0 , 3 ) ) ;
// now delete & join the paragraphs - this is fdo#85496 scenario
aEngine . QuickDelete ( ESelection ( 0 , 0 , 1 , 3 ) ) ;
2014-12-02 08:21:31 +02:00
CPPUNIT_ASSERT_EQUAL ( static_cast < sal_Int32 > ( 1 ) , aEngine . GetParagraphCount ( ) ) ;
2014-12-01 19:21:49 +01:00
2015-09-17 17:10:47 +01:00
std : : unique_ptr < EditTextObject > pEditText ( aEngine . CreateTextObject ( ) ) ;
2014-12-01 19:21:49 +01:00
CPPUNIT_ASSERT_MESSAGE ( " Failed to create text object. " , pEditText . get ( ) ) ;
std : : vector < editeng : : Section > aAttrs ;
pEditText - > GetAllSections ( aAttrs ) ;
CPPUNIT_ASSERT_EQUAL ( static_cast < size_t > ( 1 ) , aAttrs . size ( ) ) ;
const editeng : : Section * pSecAttr = & aAttrs [ 0 ] ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnParagraph ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnStart ) ;
CPPUNIT_ASSERT_EQUAL ( 0 , ( int ) pSecAttr - > mnEnd ) ;
std : : set < sal_uInt16 > whiches ;
for ( size_t i = 0 ; i < pSecAttr - > maAttributes . size ( ) ; + + i )
{
sal_uInt16 const nWhich ( pSecAttr - > maAttributes [ i ] - > Which ( ) ) ;
CPPUNIT_ASSERT_MESSAGE ( " duplicate item in text portion attributes " ,
whiches . insert ( nWhich ) . second ) ;
}
}
2013-03-01 10:50:11 +00:00
}
2017-07-06 02:00:59 +05:30
void Test : : testLargeParaCopyPaste ( )
{
// Create EditEngine's instance
EditEngine aEditEngine ( mpItemPool ) ;
// Get EditDoc for current EditEngine's instance
EditDoc & rDoc = aEditEngine . GetEditDoc ( ) ;
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( 0 ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( OUString ( ) , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
// Insert initial text
OUString aFirstPara = " This is first paragraph " ;
OUString aSecondPara = " This is second paragraph " ;
OUString aThirdPara = " This is third paragraph " ;
OUString aFourthPara = " This is fourth paragraph " ;
OUString aFifthPara = " This is fifth paragraph " ;
OUString aSixthPara = " This is sixth paragraph " ;
//Positions Ref: ........*8.............
OUString aSeventhPara = " This is seventh paragraph " ;
OUString aEighthPara = " This is eighth paragraph " ;
//Positions Ref: .............*13
OUString aNinthPara = " This is ninth paragraph " ;
OUString aTenthPara = " This is tenth paragraph " ;
OUString aText = aFirstPara + " \n " + aSecondPara + " \n " + aThirdPara + " \n " +
aFourthPara + " \n " + aFifthPara + " \n " + aSixthPara + " \n " + aSeventhPara + " \n " +
aEighthPara + " \n " + aNinthPara + " \n " + aTenthPara ;
sal_Int32 aTextLen = aFirstPara . getLength ( ) + aSecondPara . getLength ( ) + aThirdPara . getLength ( ) +
aFourthPara . getLength ( ) + aFifthPara . getLength ( ) + aSixthPara . getLength ( ) +
aSeventhPara . getLength ( ) + aEighthPara . getLength ( ) + aNinthPara . getLength ( ) + aTenthPara . getLength ( ) ;
aEditEngine . SetText ( aText ) ;
OUString aCopyText = " sixth paragraphThis is seventh paragraphThis is eighth " ;
sal_Int32 aCopyTextLen = aCopyText . getLength ( ) ;
// Assert changes
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFourthPara , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFifthPara , rDoc . GetParaAsString ( sal_Int32 ( 4 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSixthPara , rDoc . GetParaAsString ( sal_Int32 ( 5 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSeventhPara , rDoc . GetParaAsString ( sal_Int32 ( 6 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aEighthPara , rDoc . GetParaAsString ( sal_Int32 ( 7 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aNinthPara , rDoc . GetParaAsString ( sal_Int32 ( 8 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aTenthPara , rDoc . GetParaAsString ( sal_Int32 ( 9 ) ) ) ;
// Copy initial text using legacy format
uno : : Reference < datatransfer : : XTransferable > xData = aEditEngine . CreateTransferable ( ESelection ( 5 , 8 , 7 , 14 ) ) ;
// Paste text at the end of 4th Para
ContentNode * pLastNode = rDoc . GetObject ( 3 ) ;
aEditEngine . InsertText ( xData , OUString ( ) , EditPaM ( pLastNode , pLastNode - > Len ( ) ) , true ) ;
// Assert changes
OUString aFourthParaAfterCopyPaste = aFourthPara + " sixth paragraph " ;
OUString aSixthParaAfterCopyPaste = " This is eighth " ;
CPPUNIT_ASSERT_EQUAL ( sal_uLong ( aTextLen + aCopyTextLen ) , rDoc . GetTextLen ( ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFirstPara , rDoc . GetParaAsString ( sal_Int32 ( 0 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSecondPara , rDoc . GetParaAsString ( sal_Int32 ( 1 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aThirdPara , rDoc . GetParaAsString ( sal_Int32 ( 2 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFourthParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 3 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSeventhPara , rDoc . GetParaAsString ( sal_Int32 ( 4 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSixthParaAfterCopyPaste , rDoc . GetParaAsString ( sal_Int32 ( 5 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aFifthPara , rDoc . GetParaAsString ( sal_Int32 ( 6 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSixthPara , rDoc . GetParaAsString ( sal_Int32 ( 7 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aSeventhPara , rDoc . GetParaAsString ( sal_Int32 ( 8 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aEighthPara , rDoc . GetParaAsString ( sal_Int32 ( 9 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aNinthPara , rDoc . GetParaAsString ( sal_Int32 ( 10 ) ) ) ;
CPPUNIT_ASSERT_EQUAL ( aTenthPara , rDoc . GetParaAsString ( sal_Int32 ( 11 ) ) ) ;
}
2012-04-11 14:29:11 -04:00
CPPUNIT_TEST_SUITE_REGISTRATION ( Test ) ;
}
CPPUNIT_PLUGIN_IMPLEMENT ( ) ;
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */