1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <com/sun/star/awt/FontWeight.hpp>
11 #include <swmodeltestbase.hxx>
12 #include <itabenum.hxx>
16 #include <drawdoc.hxx>
18 #include <swacorr.hxx>
19 #include <swmodule.hxx>
20 #include <charatr.hxx>
21 #include <editeng/acorrcfg.hxx>
23 #include <PostItMgr.hxx>
24 #include <AnnotationWin.hxx>
25 #include <com/sun/star/awt/FontUnderline.hpp>
27 #include <svx/hdft.hxx>
28 #include <svx/svdpage.hxx>
29 #include <svx/svdview.hxx>
30 #include <svx/svxids.hrc>
32 #include <i18nutil/searchopt.hxx>
34 #include <IDocumentDrawModelAccess.hxx>
35 #include <IDocumentFieldsAccess.hxx>
36 #include <IDocumentRedlineAccess.hxx>
37 #include <IDocumentState.hxx>
38 #include <unofldmid.h>
39 #include <UndoManager.hxx>
44 #include <com/sun/star/util/XNumberFormatTypes.hpp>
45 #include <com/sun/star/util/NumberFormat.hpp>
46 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
47 #include <com/sun/star/util/SearchAlgorithms2.hpp>
48 #include <com/sun/star/util/SearchFlags.hpp>
49 #include <com/sun/star/sdb/DatabaseContext.hpp>
50 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
51 #include <com/sun/star/sdbc/XDataSource.hpp>
52 #include <com/sun/star/text/XParagraphCursor.hpp>
53 #include <com/sun/star/util/XPropertyReplace.hpp>
54 #include <com/sun/star/beans/PropertyAttribute.hpp>
55 #include <com/sun/star/chart2/data/XDataSource.hpp>
56 #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
57 #include <osl/file.hxx>
58 #include <drawfont.hxx>
60 #include <txttypes.hxx>
61 #include <SwPortionHandler.hxx>
62 #include <comphelper/propertysequence.hxx>
63 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
64 #include <sfx2/docfilt.hxx>
65 #include <vcl/scheduler.hxx>
66 #include <config_features.h>
67 #include <config_fonts.h>
68 #include <sfx2/fcontnr.hxx>
69 #include <sfx2/docfile.hxx>
70 #include <frameformats.hxx>
71 #include <unotxdoc.hxx>
72 #include <rootfrm.hxx>
73 #include <officecfg/Office/Writer.hxx>
77 int CountFilesInDirectory(const OUString
& rURL
)
81 osl::Directory
aDir(rURL
);
82 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None
, aDir
.open());
84 osl::DirectoryItem aItem
;
85 osl::FileStatus
aFileStatus(osl_FileStatus_Mask_FileURL
| osl_FileStatus_Mask_Type
);
86 while (aDir
.getNextItem(aItem
) == osl::FileBase::E_None
)
88 aItem
.getFileStatus(aFileStatus
);
89 if (aFileStatus
.getFileType() != osl::FileStatus::Directory
)
98 class SwUiWriterTest7
: public SwModelTestBase
102 : SwModelTestBase("/sw/qa/extras/uiwriter/data/")
107 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testExportToPicture
)
110 uno::Sequence
<beans::PropertyValue
> aFilterData(
111 comphelper::InitPropertySequence({ { "PixelWidth", uno::Any(sal_Int32(610)) },
112 { "PixelHeight", uno::Any(sal_Int32(610)) } }));
113 uno::Sequence
<beans::PropertyValue
> aDescriptor(comphelper::InitPropertySequence(
114 { { "FilterName", uno::Any(OUString("writer_png_Export")) },
115 { "FilterData", uno::Any(aFilterData
) } }));
116 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
117 xStorable
->storeToURL(maTempFile
.GetURL(), aDescriptor
);
118 bool extchk
= maTempFile
.IsValid();
119 CPPUNIT_ASSERT_EQUAL(true, extchk
);
120 osl::File
tmpFile(maTempFile
.GetURL());
121 tmpFile
.open(sal_uInt32(osl_File_OpenFlag_Read
));
123 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None
, tmpFile
.getSize(val
));
124 CPPUNIT_ASSERT(val
> 100);
127 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf77340
)
130 //Getting some paragraph style in our document
131 uno::Reference
<css::lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
132 uno::Reference
<style::XStyle
> xStyle(
133 xFactory
->createInstance("com.sun.star.style.ParagraphStyle"), uno::UNO_QUERY
);
134 uno::Reference
<beans::XPropertySet
> xPropSet(xStyle
, uno::UNO_QUERY_THROW
);
135 xPropSet
->setPropertyValue("ParaBackColor", uno::Any(sal_Int32(0xFF00FF)));
136 uno::Reference
<style::XStyleFamiliesSupplier
> xSupplier(mxComponent
, uno::UNO_QUERY
);
137 uno::Reference
<container::XNameAccess
> xNameAccess(xSupplier
->getStyleFamilies());
138 uno::Reference
<container::XNameContainer
> xNameCont
;
139 xNameAccess
->getByName("ParagraphStyles") >>= xNameCont
;
140 xNameCont
->insertByName("myStyle", uno::Any(xStyle
));
141 CPPUNIT_ASSERT_EQUAL(OUString("myStyle"), xStyle
->getName());
142 //Setting the properties with proper values
143 xPropSet
->setPropertyValue("PageDescName", uno::Any(OUString("First Page")));
144 xPropSet
->setPropertyValue("PageNumberOffset", uno::Any(sal_Int16(3)));
145 //Getting the properties and checking that they have proper values
146 CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("First Page")),
147 xPropSet
->getPropertyValue("PageDescName"));
148 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(3)), xPropSet
->getPropertyValue("PageNumberOffset"));
151 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf79236
)
154 SwDoc
* pDoc
= getSwDoc();
155 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
156 //Getting some paragraph style
157 SwTextFormatColl
* pTextFormat
= pDoc
->FindTextFormatCollByName(u
"Body Text");
158 const SwAttrSet
& rAttrSet
= pTextFormat
->GetAttrSet();
159 std::unique_ptr
<SfxItemSet
> pNewSet
= rAttrSet
.Clone();
160 sal_uInt16 initialCount
= pNewSet
->Count();
161 SvxAdjustItem AdjustItem
= rAttrSet
.GetAdjust();
162 SvxAdjust initialAdjust
= AdjustItem
.GetAdjust();
163 //By default the adjust is LEFT
164 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left
, initialAdjust
);
165 //Changing the adjust to RIGHT
166 AdjustItem
.SetAdjust(SvxAdjust::Right
);
167 //Checking whether the change is made or not
168 SvxAdjust modifiedAdjust
= AdjustItem
.GetAdjust();
169 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right
, modifiedAdjust
);
170 //Modifying the itemset, putting *one* item
171 pNewSet
->Put(AdjustItem
);
172 //The count should increment by 1
173 sal_uInt16 modifiedCount
= pNewSet
->Count();
174 CPPUNIT_ASSERT_EQUAL(sal_uInt16(initialCount
+ 1), modifiedCount
);
175 //Setting the updated item set on the style
176 pDoc
->ChgFormat(*pTextFormat
, *pNewSet
);
177 //Checking the Changes
178 SwTextFormatColl
* pTextFormat2
= pDoc
->FindTextFormatCollByName(u
"Body Text");
179 const SwAttrSet
& rAttrSet2
= pTextFormat2
->GetAttrSet();
180 const SvxAdjustItem
& rAdjustItem2
= rAttrSet2
.GetAdjust();
181 SvxAdjust Adjust2
= rAdjustItem2
.GetAdjust();
182 //The adjust should be RIGHT as per the modifications made
183 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right
, Adjust2
);
186 SwTextFormatColl
* pTextFormat3
= pDoc
->FindTextFormatCollByName(u
"Body Text");
187 const SwAttrSet
& rAttrSet3
= pTextFormat3
->GetAttrSet();
188 const SvxAdjustItem
& rAdjustItem3
= rAttrSet3
.GetAdjust();
189 SvxAdjust Adjust3
= rAdjustItem3
.GetAdjust();
190 //The adjust should be back to default, LEFT
191 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left
, Adjust3
);
194 SwTextFormatColl
* pTextFormat4
= pDoc
->FindTextFormatCollByName(u
"Body Text");
195 const SwAttrSet
& rAttrSet4
= pTextFormat4
->GetAttrSet();
196 const SvxAdjustItem
& rAdjustItem4
= rAttrSet4
.GetAdjust();
197 SvxAdjust Adjust4
= rAdjustItem4
.GetAdjust();
198 //The adjust should be RIGHT as per the modifications made
199 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right
, Adjust4
);
202 SwTextFormatColl
* pTextFormat5
= pDoc
->FindTextFormatCollByName(u
"Body Text");
203 const SwAttrSet
& rAttrSet5
= pTextFormat5
->GetAttrSet();
204 const SvxAdjustItem
& rAdjustItem5
= rAttrSet5
.GetAdjust();
205 SvxAdjust Adjust5
= rAdjustItem5
.GetAdjust();
206 //The adjust should be back to default, LEFT
207 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left
, Adjust5
);
210 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTextSearch
)
212 // Create a new empty Writer document
214 SwDoc
* pDoc
= getSwDoc();
215 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
216 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
218 rIDCO
.InsertString(*pCursor
, "Hello World This is a test");
219 // Use cursor to select part of text
220 for (int i
= 0; i
< 10; i
++)
222 pCursor
->Move(fnMoveBackward
);
225 for (int i
= 0; i
< 4; i
++)
227 pCursor
->Move(fnMoveBackward
);
229 //Checking that the proper selection is made
230 CPPUNIT_ASSERT_EQUAL(OUString("This"), pCursor
->GetText());
231 // Apply a "Bold" attribute to selection
232 SvxWeightItem
aWeightItem(WEIGHT_BOLD
, RES_CHRATR_WEIGHT
);
233 rIDCO
.InsertPoolItem(*pCursor
, aWeightItem
);
234 //making another selection of text
235 for (int i
= 0; i
< 7; i
++)
237 pCursor
->Move(fnMoveBackward
);
240 for (int i
= 0; i
< 5; i
++)
242 pCursor
->Move(fnMoveBackward
);
244 //Checking that the proper selection is made
245 CPPUNIT_ASSERT_EQUAL(OUString("Hello"), pCursor
->GetText());
246 // Apply a "Bold" attribute to selection
247 rIDCO
.InsertPoolItem(*pCursor
, aWeightItem
);
248 //Performing Search Operation and also covering the UNO coverage for setProperty
249 uno::Reference
<util::XSearchable
> xSearch(mxComponent
, uno::UNO_QUERY
);
250 uno::Reference
<util::XSearchDescriptor
> xSearchDes
= xSearch
->createSearchDescriptor();
251 uno::Reference
<util::XPropertyReplace
> xProp(xSearchDes
, uno::UNO_QUERY
);
252 //setting some properties
253 uno::Sequence
<beans::PropertyValue
> aDescriptor(comphelper::InitPropertySequence(
254 { { "CharWeight", uno::Any(float(css::awt::FontWeight::BOLD
)) } }));
255 xProp
->setSearchAttributes(aDescriptor
);
256 //receiving the defined properties and asserting them with expected values, covering UNO
257 uno::Sequence
<beans::PropertyValue
> aPropVal2(xProp
->getSearchAttributes());
258 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aPropVal2
.getLength());
259 CPPUNIT_ASSERT_EQUAL(OUString("CharWeight"), aPropVal2
[0].Name
);
260 CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD
)), aPropVal2
[0].Value
);
261 //specifying the search attributes
262 uno::Reference
<beans::XPropertySet
> xPropSet(xSearchDes
, uno::UNO_QUERY_THROW
);
263 xPropSet
->setPropertyValue("SearchWords", uno::Any(true));
264 xPropSet
->setPropertyValue("SearchCaseSensitive", uno::Any(true));
265 //this will search all the BOLD words
266 uno::Reference
<container::XIndexAccess
> xIndex(xSearch
->findAll(xSearchDes
));
267 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndex
->getCount());
268 //Replacing the searched string via XReplaceable
269 uno::Reference
<util::XReplaceable
> xReplace(mxComponent
, uno::UNO_QUERY
);
270 uno::Reference
<util::XReplaceDescriptor
> xReplaceDes
= xReplace
->createReplaceDescriptor();
271 uno::Reference
<util::XPropertyReplace
> xProp2(xReplaceDes
, uno::UNO_QUERY
);
272 xProp2
->setReplaceAttributes(aDescriptor
);
273 //checking that the proper attributes are there or not
274 uno::Sequence
<beans::PropertyValue
> aRepProp(xProp2
->getReplaceAttributes());
275 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRepProp
.getLength());
276 CPPUNIT_ASSERT_EQUAL(OUString("CharWeight"), aRepProp
[0].Name
);
277 CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD
)), aRepProp
[0].Value
);
278 //setting strings for replacement
279 xReplaceDes
->setSearchString("test");
280 xReplaceDes
->setReplaceString("task");
281 //checking the replaceString
282 CPPUNIT_ASSERT_EQUAL(OUString("task"), xReplaceDes
->getReplaceString());
283 //this will replace *normal*test to *bold*task
284 sal_Int32 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
285 //There should be only 1 replacement since there is only one occurrence of "test" in the document
286 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount
);
287 //Now performing search again for BOLD words, count should be 3 due to replacement
288 uno::Reference
<container::XIndexAccess
> xIndex2(xReplace
->findAll(xSearchDes
));
289 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndex2
->getCount());
291 xSearchDes
->setPropertyValue("SearchRegularExpression", uno::Any(true));
292 // regex: test correct matching combined with attributes like BOLD
293 xSearchDes
->setSearchString(".*"); // should match all bold words in the text
294 xIndex
.set(xReplace
->findAll(xSearchDes
), uno::UNO_SET_THROW
);
295 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndex
->getCount());
296 uno::Reference
<text::XTextRange
> xFound(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
297 CPPUNIT_ASSERT_EQUAL(OUString("Hello"), xFound
->getString());
298 xFound
.set(xIndex
->getByIndex(1), uno::UNO_QUERY_THROW
);
299 CPPUNIT_ASSERT_EQUAL(OUString("This"), xFound
->getString());
300 xFound
.set(xIndex
->getByIndex(2), uno::UNO_QUERY_THROW
);
301 CPPUNIT_ASSERT_EQUAL(OUString("task"), xFound
->getString());
302 // regex: test anchor combined with attributes like BOLD
303 xSearchDes
->setSearchString("^.*|.*$"); // should match first and last words (they are bold)
304 xIndex
.set(xReplace
->findAll(xSearchDes
), uno::UNO_SET_THROW
);
305 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndex
->getCount());
306 xFound
.set(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
307 CPPUNIT_ASSERT_EQUAL(OUString("Hello"), xFound
->getString());
308 xFound
.set(xIndex
->getByIndex(1), uno::UNO_QUERY_THROW
);
309 CPPUNIT_ASSERT_EQUAL(OUString("task"), xFound
->getString());
310 // regex: test look-ahead/look-behind assertions outside of the bold text
311 xSearchDes
->setSearchString("(?<= ).*(?= )"); // should match second bold word
312 xIndex
.set(xReplace
->findAll(xSearchDes
), uno::UNO_SET_THROW
);
313 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex
->getCount());
314 xFound
.set(xIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
315 CPPUNIT_ASSERT_EQUAL(OUString("This"), xFound
->getString());
316 xReplaceDes
->setPropertyValue("SearchRegularExpression", uno::Any(true));
317 // regex: test correct match of paragraph start
318 xReplaceDes
->setSearchString("^."); // should only match first character of the paragraph
319 xReplaceDes
->setReplaceString("C");
320 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
321 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount
);
322 // regex: test correct match of word start
323 xReplaceDes
->setSearchString("\\b\\w"); // should match all words' first characters
324 xReplaceDes
->setReplaceString("x&");
325 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
326 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ReplaceCount
);
327 // regex: test negative look-behind assertion
328 xReplaceDes
->setSearchString("(?<!xCelly xW)o"); // only "o" in "xCello", not in "xWorld"
329 xReplaceDes
->setReplaceString("y");
330 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
331 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount
);
332 // regex: test positive look-behind assertion
333 xReplaceDes
->setSearchString("(?<=xCelly xWorld xTh)i"); // only "i" in "xThis", not in "xis"
334 xReplaceDes
->setReplaceString("z");
335 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
336 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount
);
337 // regex: use capturing group to test reference
338 xReplaceDes
->setSearchString("\\b(\\w\\w\\w\\w)\\w");
339 xReplaceDes
->setReplaceString("$1q"); // only fifth characters in words should change
340 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
341 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), ReplaceCount
);
342 // check of the end result
343 CPPUNIT_ASSERT_EQUAL(OUString("xCelqy xWorqd xThzq xis xa xtasq"),
344 pCursor
->GetPointNode().GetTextNode()->GetText());
345 // regex: use positive look-ahead assertion
346 xReplaceDes
->setSearchString("Wor(?=qd xThzq xis xa xtasq)");
347 xReplaceDes
->setReplaceString("&p"); // testing & reference
348 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
349 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount
);
350 // regex: use negative look-ahead assertion
351 xReplaceDes
->setSearchString("x(?!Worpqd xThzq xis xa xtasq)");
352 xReplaceDes
->setReplaceString("m");
353 ReplaceCount
= xReplace
->replaceAll(xReplaceDes
);
354 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ReplaceCount
); // one of the 6 "x" must not be replaced
355 // check of the end result
356 CPPUNIT_ASSERT_EQUAL(OUString("mCelqy xWorpqd mThzq mis ma mtasq"),
357 pCursor
->GetPointNode().GetTextNode()->GetText());
360 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf69282
)
363 SwDoc
* source
= getSwDoc();
364 uno::Reference
<lang::XComponent
> xSourceDoc
= mxComponent
;
367 SwDoc
* target
= getSwDoc();
368 SwPageDesc
* sPageDesc
= source
->MakePageDesc("SourceStyle");
369 SwPageDesc
* tPageDesc
= target
->MakePageDesc("TargetStyle");
370 sPageDesc
->ChgFirstShare(false);
371 CPPUNIT_ASSERT(!sPageDesc
->IsFirstShared());
372 SwFrameFormat
& rSourceMasterFormat
= sPageDesc
->GetMaster();
373 //Setting horizontal spaces on master
374 SvxLRSpaceItem
horizontalSpace(RES_LR_SPACE
);
375 horizontalSpace
.SetLeft(11);
376 horizontalSpace
.SetRight(12);
377 rSourceMasterFormat
.SetFormatAttr(horizontalSpace
);
378 //Setting vertical spaces on master
379 SvxULSpaceItem
verticalSpace(RES_UL_SPACE
);
380 verticalSpace
.SetUpper(13);
381 verticalSpace
.SetLower(14);
382 rSourceMasterFormat
.SetFormatAttr(verticalSpace
);
383 //Changing the style and copying it to target
384 source
->ChgPageDesc("SourceStyle", *sPageDesc
);
385 target
->CopyPageDesc(*sPageDesc
, *tPageDesc
);
386 //Checking the set values on all Formats in target
387 SwFrameFormat
& rTargetMasterFormat
= tPageDesc
->GetMaster();
388 SwFrameFormat
& rTargetLeftFormat
= tPageDesc
->GetLeft();
389 SwFrameFormat
& rTargetFirstMasterFormat
= tPageDesc
->GetFirstMaster();
390 SwFrameFormat
& rTargetFirstLeftFormat
= tPageDesc
->GetFirstLeft();
391 //Checking horizontal spaces
392 const SvxLRSpaceItem MasterLRSpace
= rTargetMasterFormat
.GetLRSpace();
393 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), MasterLRSpace
.GetLeft());
394 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), MasterLRSpace
.GetRight());
395 const SvxLRSpaceItem LeftLRSpace
= rTargetLeftFormat
.GetLRSpace();
396 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), LeftLRSpace
.GetLeft());
397 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), LeftLRSpace
.GetRight());
398 const SvxLRSpaceItem FirstMasterLRSpace
= rTargetFirstMasterFormat
.GetLRSpace();
399 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), FirstMasterLRSpace
.GetLeft());
400 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), FirstMasterLRSpace
.GetRight());
401 const SvxLRSpaceItem FirstLeftLRSpace
= rTargetFirstLeftFormat
.GetLRSpace();
402 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), FirstLeftLRSpace
.GetLeft());
403 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), FirstLeftLRSpace
.GetRight());
404 //Checking vertical spaces
405 const SvxULSpaceItem MasterULSpace
= rTargetMasterFormat
.GetULSpace();
406 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), MasterULSpace
.GetUpper());
407 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), MasterULSpace
.GetLower());
408 const SvxULSpaceItem LeftULSpace
= rTargetLeftFormat
.GetULSpace();
409 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), LeftULSpace
.GetUpper());
410 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), LeftULSpace
.GetLower());
411 const SvxULSpaceItem FirstMasterULSpace
= rTargetFirstMasterFormat
.GetULSpace();
412 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), FirstMasterULSpace
.GetUpper());
413 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), FirstMasterULSpace
.GetLower());
414 const SvxULSpaceItem FirstLeftULSpace
= rTargetFirstLeftFormat
.GetULSpace();
415 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), FirstLeftULSpace
.GetUpper());
416 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), FirstLeftULSpace
.GetLower());
417 xSourceDoc
->dispose();
420 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf69282WithMirror
)
423 SwDoc
* source
= getSwDoc();
424 uno::Reference
<lang::XComponent
> xSourceDoc
= mxComponent
;
427 SwDoc
* target
= getSwDoc();
428 SwPageDesc
* sPageDesc
= source
->MakePageDesc("SourceStyle");
429 SwPageDesc
* tPageDesc
= target
->MakePageDesc("TargetStyle");
431 sPageDesc
->SetUseOn(UseOnPage::Mirror
);
432 SwFrameFormat
& rSourceMasterFormat
= sPageDesc
->GetMaster();
433 //Setting horizontal spaces on master
434 SvxLRSpaceItem
horizontalSpace(RES_LR_SPACE
);
435 horizontalSpace
.SetLeft(11);
436 horizontalSpace
.SetRight(12);
437 rSourceMasterFormat
.SetFormatAttr(horizontalSpace
);
438 //Setting vertical spaces on master
439 SvxULSpaceItem
verticalSpace(RES_UL_SPACE
);
440 verticalSpace
.SetUpper(13);
441 verticalSpace
.SetLower(14);
442 rSourceMasterFormat
.SetFormatAttr(verticalSpace
);
443 //Changing the style and copying it to target
444 source
->ChgPageDesc("SourceStyle", *sPageDesc
);
445 target
->CopyPageDesc(*sPageDesc
, *tPageDesc
);
446 //Checking the set values on all Formats in target
447 SwFrameFormat
& rTargetMasterFormat
= tPageDesc
->GetMaster();
448 SwFrameFormat
& rTargetLeftFormat
= tPageDesc
->GetLeft();
449 SwFrameFormat
& rTargetFirstMasterFormat
= tPageDesc
->GetFirstMaster();
450 SwFrameFormat
& rTargetFirstLeftFormat
= tPageDesc
->GetFirstLeft();
451 //Checking horizontal spaces
452 const SvxLRSpaceItem MasterLRSpace
= rTargetMasterFormat
.GetLRSpace();
453 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), MasterLRSpace
.GetLeft());
454 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), MasterLRSpace
.GetRight());
455 //mirror effect should be present
456 const SvxLRSpaceItem LeftLRSpace
= rTargetLeftFormat
.GetLRSpace();
457 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), LeftLRSpace
.GetLeft());
458 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), LeftLRSpace
.GetRight());
459 const SvxLRSpaceItem FirstMasterLRSpace
= rTargetFirstMasterFormat
.GetLRSpace();
460 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), FirstMasterLRSpace
.GetLeft());
461 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), FirstMasterLRSpace
.GetRight());
462 //mirror effect should be present
463 const SvxLRSpaceItem FirstLeftLRSpace
= rTargetFirstLeftFormat
.GetLRSpace();
464 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetRight(), FirstLeftLRSpace
.GetLeft());
465 CPPUNIT_ASSERT_EQUAL(horizontalSpace
.GetLeft(), FirstLeftLRSpace
.GetRight());
466 //Checking vertical spaces
467 const SvxULSpaceItem MasterULSpace
= rTargetMasterFormat
.GetULSpace();
468 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), MasterULSpace
.GetUpper());
469 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), MasterULSpace
.GetLower());
470 const SvxULSpaceItem LeftULSpace
= rTargetLeftFormat
.GetULSpace();
471 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), LeftULSpace
.GetUpper());
472 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), LeftULSpace
.GetLower());
473 const SvxULSpaceItem FirstMasterULSpace
= rTargetFirstMasterFormat
.GetULSpace();
474 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), FirstMasterULSpace
.GetUpper());
475 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), FirstMasterULSpace
.GetLower());
476 const SvxULSpaceItem FirstLeftULSpace
= rTargetFirstLeftFormat
.GetULSpace();
477 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetUpper(), FirstLeftULSpace
.GetUpper());
478 CPPUNIT_ASSERT_EQUAL(verticalSpace
.GetLower(), FirstLeftULSpace
.GetLower());
479 xSourceDoc
->dispose();
482 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf78742
)
484 //testing with service type and any .ods file
485 OUString path
= createFileURL(u
"calc-data-source.ods");
486 SfxMedium
aMedium(path
, StreamMode::READ
| StreamMode::SHARE_DENYWRITE
);
487 SfxFilterMatcher
aMatcher("com.sun.star.text.TextDocument");
488 std::shared_ptr
<const SfxFilter
> pFilter
;
489 ErrCode filter
= aMatcher
.DetectFilter(aMedium
, pFilter
);
490 CPPUNIT_ASSERT_EQUAL(ERRCODE_IO_ABORT
, filter
);
491 //it should not return any Filter
492 CPPUNIT_ASSERT(!pFilter
);
493 //testing without service type and any .ods file
494 SfxMedium
aMedium2(path
, StreamMode::READ
| StreamMode::SHARE_DENYWRITE
);
495 SfxFilterMatcher aMatcher2
;
496 std::shared_ptr
<const SfxFilter
> pFilter2
;
497 ErrCode filter2
= aMatcher2
.DetectFilter(aMedium2
, pFilter2
);
498 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
, filter2
);
499 //Filter should be returned with proper Name
500 CPPUNIT_ASSERT_EQUAL(OUString("calc8"), pFilter2
->GetFilterName());
501 //testing with service type and any .odt file
502 OUString path2
= createFileURL(u
"fdo69893.odt");
503 SfxMedium
aMedium3(path2
, StreamMode::READ
| StreamMode::SHARE_DENYWRITE
);
504 SfxFilterMatcher
aMatcher3("com.sun.star.text.TextDocument");
505 std::shared_ptr
<const SfxFilter
> pFilter3
;
506 ErrCode filter3
= aMatcher3
.DetectFilter(aMedium3
, pFilter3
);
507 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
, filter3
);
508 //Filter should be returned with proper Name
509 CPPUNIT_ASSERT_EQUAL(OUString("writer8"), pFilter3
->GetFilterName());
512 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUnoParagraph
)
515 SwDoc
* pDoc
= getSwDoc();
516 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
517 //Inserting some text content in the document
518 pWrtShell
->Insert("This is initial text in paragraph one");
519 pWrtShell
->SplitNode();
520 //Inserting second paragraph
521 pWrtShell
->Insert("This is initial text in paragraph two");
522 //now testing the SwXParagraph
523 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
524 uno::Reference
<text::XText
> xText(xTextDocument
->getText());
525 uno::Reference
<container::XEnumerationAccess
> xParaAccess(xText
, uno::UNO_QUERY
);
526 uno::Reference
<container::XEnumeration
> xPara(xParaAccess
->createEnumeration());
527 //getting first paragraph
528 uno::Reference
<text::XTextContent
> xFirstParaContent(xPara
->nextElement(), uno::UNO_QUERY
);
529 uno::Reference
<text::XTextRange
> xFirstPara(xFirstParaContent
, uno::UNO_QUERY
);
530 //testing the initial text
531 CPPUNIT_ASSERT_EQUAL(OUString("This is initial text in paragraph one"),
532 xFirstPara
->getString());
533 //changing the text content in first paragraph
534 xFirstPara
->setString("This is modified text in paragraph one");
535 //testing the changes
536 CPPUNIT_ASSERT_EQUAL(OUString("This is modified text in paragraph one"),
537 xFirstPara
->getString());
538 //getting second paragraph
539 uno::Reference
<text::XTextContent
> xSecondParaContent(xPara
->nextElement(), uno::UNO_QUERY
);
540 uno::Reference
<text::XTextRange
> xSecondPara(xSecondParaContent
, uno::UNO_QUERY
);
541 //testing the initial text
542 CPPUNIT_ASSERT_EQUAL(OUString("This is initial text in paragraph two"),
543 xSecondPara
->getString());
544 //changing the text content in second paragraph
545 xSecondPara
->setString("This is modified text in paragraph two");
546 //testing the changes
547 CPPUNIT_ASSERT_EQUAL(OUString("This is modified text in paragraph two"),
548 xSecondPara
->getString());
551 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf72788
)
553 //Create a new empty Writer document
555 SwDoc
* pDoc
= getSwDoc();
556 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
557 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
558 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
559 //Insert some text - two paragraphs
560 rIDCO
.InsertString(*pCursor
, "this is text");
561 //Position of word 9876543210
562 //Position of word 0123456789
564 pWrtShell
->SplitNode();
565 //Insert second paragraph
566 rIDCO
.InsertString(*pCursor
, "more text");
567 //Position of word 012345678
568 //Make the following selection *bold*
572 for (int i
= 0; i
< 5; i
++)
574 pCursor
->Move(fnMoveBackward
);
578 for (int i
= 0; i
< 12; i
++)
580 pCursor
->Move(fnMoveBackward
);
582 //Check the text selection
583 CPPUNIT_ASSERT_EQUAL(OUString(u
"is text" + OUStringChar(CH_TXTATR_NEWLINE
) + u
"more"),
585 //Apply a *Bold* attribute to selection
586 SvxWeightItem
aWeightItem(WEIGHT_BOLD
, RES_CHRATR_WEIGHT
);
587 rIDCO
.InsertPoolItem(*pCursor
, aWeightItem
);
588 SfxItemSet
aSet(pDoc
->GetAttrPool(), svl::Items
<RES_CHRATR_WEIGHT
, RES_CHRATR_WEIGHT
>);
589 //Add selected text's attributes to aSet
590 pCursor
->GetPointNode().GetTextNode()->GetParaAttr(aSet
, 5, 12);
591 SfxPoolItem
const* pPoolItem
= aSet
.GetItem(RES_CHRATR_WEIGHT
);
592 //Check that bold is active on the selection and it's in aSet
593 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem
== aWeightItem
));
594 //Make selection to remove formatting in first paragraph
597 pWrtShell
->StartOfSection();
600 for (int i
= 0; i
< 13; i
++)
602 pCursor
->Move(fnMoveForward
);
604 //Clear all the Direct Formatting ( Ctrl + M )
605 SwTextNode
* pTextNode
= pCursor
->GetPointNode().GetTextNode();
606 sal_Int32 nEnd
= pTextNode
->Len();
607 pTextNode
->RstTextAttr(0, nEnd
);
608 //In case of Regression RstTextAttr() call will result to infinite recursion
609 //Check that bold is removed in first paragraph
611 pTextNode
->GetParaAttr(aSet
, 5, 12);
612 SfxPoolItem
const* pPoolItem2
= aSet
.GetItem(RES_CHRATR_WEIGHT
);
613 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem2
!= aWeightItem
));
616 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf60967
)
619 SwDoc
* pDoc
= getSwDoc();
620 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
621 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
622 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
623 pWrtShell
->ChangeHeaderOrFooter(u
"Default Page Style", true, true, true);
625 SwInsertTableOptions
TableOpt(SwInsertTableFlags::DefaultBorder
, 0);
626 pWrtShell
->InsertTable(TableOpt
, 2, 2);
627 //getting the cursor's position just after the table insert
628 SwPosition
aPosAfterTable(*(pCursor
->GetPoint()));
629 //moving cursor to B2 (bottom right cell)
630 pCursor
->Move(fnMoveBackward
);
631 SwPosition
aPosInTable(*(pCursor
->GetPoint()));
632 //deleting paragraph following table with Ctrl+Shift+Del
633 bool val
= pWrtShell
->DelToEndOfSentence();
634 CPPUNIT_ASSERT_EQUAL(true, val
);
635 //getting the cursor's position just after the paragraph deletion
636 SwPosition
aPosAfterDel(*(pCursor
->GetPoint()));
637 //moving cursor forward to check whether there is any node following the table, BTW there should not be any such node
638 pCursor
->Move(fnMoveForward
);
639 SwPosition
aPosMoveAfterDel(*(pCursor
->GetPoint()));
640 //checking the positions to verify that the paragraph is actually deleted
641 CPPUNIT_ASSERT_EQUAL(aPosAfterDel
, aPosInTable
);
642 CPPUNIT_ASSERT_EQUAL(aPosMoveAfterDel
, aPosInTable
);
646 //paragraph *text node* should be back
647 SwPosition
aPosAfterUndo(*(pCursor
->GetPoint()));
648 //after undo aPosAfterTable increases the node position by one, since this contains the position *text node* so aPosAfterUndo should be less than aPosAfterTable
649 CPPUNIT_ASSERT(aPosAfterTable
> aPosAfterUndo
);
650 //moving cursor forward to check whether there is any node following the paragraph, BTW there should not be any such node as paragraph node is the last one in header
651 pCursor
->Move(fnMoveForward
);
652 SwPosition
aPosMoveAfterUndo(*(pCursor
->GetPoint()));
653 //checking positions to verify that paragraph node is the last one and we are paragraph node only
654 CPPUNIT_ASSERT(aPosAfterTable
> aPosMoveAfterUndo
);
655 CPPUNIT_ASSERT_EQUAL(aPosAfterUndo
, aPosMoveAfterUndo
);
659 //paragraph *text node* should not be there
660 SwPosition
aPosAfterRedo(*(pCursor
->GetPoint()));
661 //position should be exactly same as it was after deletion of *text node*
662 CPPUNIT_ASSERT_EQUAL(aPosAfterRedo
, aPosMoveAfterDel
);
663 //moving the cursor forward, but it should not actually move as there is no *text node* after the table due to this same position is expected after move as it was before move
664 pCursor
->Move(fnMoveForward
);
665 SwPosition
aPosAfterUndoMove(*(pCursor
->GetPoint()));
666 CPPUNIT_ASSERT_EQUAL(aPosAfterRedo
, aPosAfterUndoMove
);
669 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testSearchWithTransliterate
)
672 SwDoc
* pDoc
= getSwDoc();
673 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
675 SwNodeIndex
aIdx(pDoc
->GetNodes().GetEndOfContent(), -1);
677 pDoc
->getIDocumentContentOperations().InsertString(aPaM
, "This is paragraph one");
678 pWrtShell
->SplitNode();
681 SwNodeIndex
aIdx(pDoc
->GetNodes().GetEndOfContent(), -1);
683 pDoc
->getIDocumentContentOperations().InsertString(aPaM
, "This is Other PARAGRAPH");
685 i18nutil::SearchOptions2 SearchOpt
;
686 SearchOpt
.algorithmType
= css::util::SearchAlgorithms_ABSOLUTE
;
687 SearchOpt
.searchFlag
= css::util::SearchFlags::ALL_IGNORE_CASE
;
688 SearchOpt
.searchString
= "other";
689 SearchOpt
.replaceString
.clear();
690 SearchOpt
.changedChars
= 0;
691 SearchOpt
.deletedChars
= 0;
692 SearchOpt
.insertedChars
= 0;
693 SearchOpt
.transliterateFlags
= TransliterationFlags::IGNORE_DIACRITICS_CTL
;
694 SearchOpt
.AlgorithmType2
= css::util::SearchAlgorithms2::ABSOLUTE
;
695 SearchOpt
.WildcardEscapeCharacter
= 0;
696 //transliteration option set so that at least one of the search strings is not found
698 = pWrtShell
->SearchPattern(SearchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
);
699 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(true);
700 CPPUNIT_ASSERT_EQUAL(OUString(), pShellCursor
->GetText());
701 CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(case1
));
702 SearchOpt
.searchString
= "paragraph";
703 SearchOpt
.transliterateFlags
= TransliterationFlags::IGNORE_KASHIDA_CTL
;
704 //transliteration option set so that all search strings are found
706 = pWrtShell
->SearchPattern(SearchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
);
707 pShellCursor
= pWrtShell
->getShellCursor(true);
708 CPPUNIT_ASSERT_EQUAL(OUString("paragraph"), pShellCursor
->GetText());
709 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(case2
));
712 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf73660
)
715 SwDoc
* pDoc
= getSwDoc();
716 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
717 OUString aData1
= "First" + OUStringChar(CHAR_SOFTHYPHEN
) + "Word";
718 OUString aData2
= "Seco" + OUStringChar(CHAR_SOFTHYPHEN
) + "nd";
719 OUString aData3
= OUStringChar(CHAR_SOFTHYPHEN
) + "Third";
720 OUString aData4
= "Fourth" + OUStringChar(CHAR_SOFTHYPHEN
);
721 pWrtShell
->Insert("We are inserting some text in the document to check the search feature ");
722 pWrtShell
->Insert(aData1
+ " ");
723 pWrtShell
->Insert(aData2
+ " ");
724 pWrtShell
->Insert(aData3
+ " ");
725 pWrtShell
->Insert(aData4
+ " ");
726 pWrtShell
->Insert("Fifth ");
727 pWrtShell
->Insert("Now we have enough text let's test search for all the cases");
728 //searching for all 5 strings entered with soft-hyphen, search string contains no soft-hyphen
729 i18nutil::SearchOptions2 searchOpt
;
730 searchOpt
.algorithmType
= css::util::SearchAlgorithms_REGEXP
;
731 searchOpt
.searchFlag
= css::util::SearchFlags::NORM_WORD_ONLY
;
733 searchOpt
.searchString
= "First";
734 CPPUNIT_ASSERT_EQUAL(
736 pWrtShell
->SearchPattern(searchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
));
738 searchOpt
.searchString
= "Second";
739 CPPUNIT_ASSERT_EQUAL(
741 pWrtShell
->SearchPattern(searchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
));
743 searchOpt
.searchString
= "Third";
744 CPPUNIT_ASSERT_EQUAL(
746 pWrtShell
->SearchPattern(searchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
));
748 searchOpt
.searchString
= "Fourth";
749 CPPUNIT_ASSERT_EQUAL(
751 pWrtShell
->SearchPattern(searchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
));
753 searchOpt
.searchString
= "Fifth";
754 CPPUNIT_ASSERT_EQUAL(
756 pWrtShell
->SearchPattern(searchOpt
, true, SwDocPositions::Start
, SwDocPositions::End
));
759 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testNewDocModifiedState
)
762 SwDoc
* pDoc
= new SwDoc();
763 //getting the state of the document via IDocumentState
764 IDocumentState
& rState(pDoc
->getIDocumentState());
765 //the state should not be modified, no modifications yet
766 CPPUNIT_ASSERT(!(rState
.IsModified()));
769 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf77342
)
772 SwDoc
* pDoc
= getSwDoc();
773 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
774 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
775 //inserting first footnote
776 pWrtShell
->InsertFootnote("");
777 SwFieldType
* pField
= pWrtShell
->GetFieldType(0, SwFieldIds::GetRef
);
778 SwGetRefFieldType
* pRefType
= static_cast<SwGetRefFieldType
*>(pField
);
779 //moving cursor to the starting of document
780 pWrtShell
->StartOfSection();
781 //inserting reference field 1
782 SwGetRefField
aField1(pRefType
, "", "", REF_FOOTNOTE
, sal_uInt16(0), REF_CONTENT
);
783 pWrtShell
->InsertField2(aField1
);
784 //inserting second footnote
785 pWrtShell
->InsertFootnote("");
786 pWrtShell
->StartOfSection();
787 pCursor
->Move(fnMoveForward
);
788 //inserting reference field 2
789 SwGetRefField
aField2(pRefType
, "", "", REF_FOOTNOTE
, sal_uInt16(1), REF_CONTENT
);
790 pWrtShell
->InsertField2(aField2
);
791 //inserting third footnote
792 pWrtShell
->InsertFootnote("");
793 pWrtShell
->StartOfSection();
794 pCursor
->Move(fnMoveForward
);
795 pCursor
->Move(fnMoveForward
);
796 //inserting reference field 3
797 SwGetRefField
aField3(pRefType
, "", "", REF_FOOTNOTE
, sal_uInt16(2), REF_CONTENT
);
798 pWrtShell
->InsertField2(aField3
);
799 //updating the fields
800 IDocumentFieldsAccess
& rField(pDoc
->getIDocumentFieldsAccess());
801 rField
.UpdateExpFields(nullptr, true);
802 //creating new clipboard doc
803 rtl::Reference
<SwDoc
> xClpDoc(new SwDoc());
804 xClpDoc
->SetClipBoard(true);
805 xClpDoc
->getIDocumentFieldsAccess().LockExpFields();
806 //selecting reference field 2 and reference field 3 and footnote 1 and footnote 2
807 //selection is such that more than one and not all footnotes and ref fields are selected
808 pCursor
->Move(fnMoveBackward
);
809 pCursor
->Move(fnMoveBackward
);
812 pCursor
->Move(fnMoveForward
);
813 pCursor
->Move(fnMoveForward
);
814 pCursor
->Move(fnMoveForward
);
815 //copying the selection to clipboard
816 pWrtShell
->Copy(*xClpDoc
);
817 //deleting selection mark after copy
818 pCursor
->DeleteMark();
819 //checking that the footnotes reference fields have same values after copy operation
823 pWrtShell
->StartOfSection();
824 SwField
* pRef1
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
825 aFormat
= pRef1
->GetFormat();
826 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
827 pRef1
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
828 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
830 pCursor
->Move(fnMoveForward
);
831 SwField
* pRef2
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
832 aFormat
= pRef2
->GetFormat();
833 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
834 pRef2
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
835 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
837 pCursor
->Move(fnMoveForward
);
838 SwField
* pRef3
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
839 aFormat
= pRef3
->GetFormat();
840 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
841 pRef3
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
842 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
843 //moving cursor to the end of the document
844 pWrtShell
->EndOfSection();
845 //pasting the copied selection at current cursor position
846 pWrtShell
->Paste(*xClpDoc
);
847 //checking the fields, both new and old, for proper values
848 pWrtShell
->StartOfSection();
849 //old reference field 1
850 SwField
* pOldRef11
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
851 aFormat
= pOldRef11
->GetFormat();
852 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
853 pOldRef11
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
854 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
855 //old reference field 2
856 pCursor
->Move(fnMoveForward
);
857 SwField
* pOldRef12
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
858 aFormat
= pOldRef12
->GetFormat();
859 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
860 pOldRef12
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
861 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
862 //old reference field 3
863 pCursor
->Move(fnMoveForward
);
864 SwField
* pOldRef13
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
865 aFormat
= pOldRef13
->GetFormat();
866 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
867 pOldRef13
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
868 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
870 pCursor
->Move(fnMoveForward
);
871 SwTextNode
* pTextNd1
= pCursor
->GetPointNode().GetTextNode();
872 SwTextAttr
* const pFootnote1
873 = pTextNd1
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
874 const SwFormatFootnote
& rFootnote1(pFootnote1
->GetFootnote());
875 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), rFootnote1
.GetNumber());
876 SwTextFootnote
* pTFNote1
= static_cast<SwTextFootnote
*>(pFootnote1
);
877 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pTFNote1
->GetSeqRefNo());
879 pCursor
->Move(fnMoveForward
);
880 SwTextNode
* pTextNd2
= pCursor
->GetPointNode().GetTextNode();
881 SwTextAttr
* const pFootnote2
882 = pTextNd2
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
883 const SwFormatFootnote
& rFootnote2(pFootnote2
->GetFootnote());
884 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), rFootnote2
.GetNumber());
885 SwTextFootnote
* pTFNote2
= static_cast<SwTextFootnote
*>(pFootnote2
);
886 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pTFNote2
->GetSeqRefNo());
888 pCursor
->Move(fnMoveForward
);
889 SwTextNode
* pTextNd3
= pCursor
->GetPointNode().GetTextNode();
890 SwTextAttr
* const pFootnote3
891 = pTextNd3
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
892 const SwFormatFootnote
& rFootnote3(pFootnote3
->GetFootnote());
893 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), rFootnote3
.GetNumber());
894 SwTextFootnote
* pTFNote3
= static_cast<SwTextFootnote
*>(pFootnote3
);
895 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pTFNote3
->GetSeqRefNo());
896 //new reference field 1
897 pCursor
->Move(fnMoveForward
);
898 SwField
* pNewRef11
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
899 aFormat
= pNewRef11
->GetFormat();
900 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
901 pNewRef11
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
902 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
903 //new reference field 2
904 pCursor
->Move(fnMoveForward
);
905 SwField
* pNewRef12
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
906 aFormat
= pNewRef12
->GetFormat();
907 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
908 pNewRef12
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
909 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(3)), aAny
);
911 pCursor
->Move(fnMoveForward
);
912 SwTextNode
* pTextNd4
= pCursor
->GetPointNode().GetTextNode();
913 SwTextAttr
* const pFootnote4
914 = pTextNd4
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
915 const SwFormatFootnote
& rFootnote4(pFootnote4
->GetFootnote());
916 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), rFootnote4
.GetNumber());
917 SwTextFootnote
* pTFNote4
= static_cast<SwTextFootnote
*>(pFootnote4
);
918 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pTFNote4
->GetSeqRefNo());
919 //moving the cursor to the starting of document
920 pWrtShell
->StartOfSection();
921 //pasting the selection again at current cursor position
922 pWrtShell
->Paste(*xClpDoc
);
923 //checking the fields, both new and old, for proper values
924 pWrtShell
->StartOfSection();
925 //new reference field 1
926 SwField
* pNewRef21
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
927 aFormat
= pNewRef21
->GetFormat();
928 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
929 pNewRef21
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
930 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
931 //new reference field 2
932 pCursor
->Move(fnMoveForward
);
933 SwField
* pNewRef22
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
934 aFormat
= pNewRef22
->GetFormat();
935 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
936 pNewRef22
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
937 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny
);
939 pCursor
->Move(fnMoveForward
);
940 SwTextNode
* pTextNd11
= pCursor
->GetPointNode().GetTextNode();
941 SwTextAttr
* const pFootnote11
942 = pTextNd11
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
943 const SwFormatFootnote
& rFootnote11(pFootnote11
->GetFootnote());
944 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), rFootnote11
.GetNumber());
945 SwTextFootnote
* pTFNote11
= static_cast<SwTextFootnote
*>(pFootnote11
);
946 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pTFNote11
->GetSeqRefNo());
947 //old reference field 1
948 pCursor
->Move(fnMoveForward
);
949 SwField
* pOldRef21
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
950 aFormat
= pOldRef21
->GetFormat();
951 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
952 pOldRef21
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
953 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
954 //old reference field 2
955 pCursor
->Move(fnMoveForward
);
956 SwField
* pOldRef22
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
957 aFormat
= pOldRef22
->GetFormat();
958 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
959 pOldRef22
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
960 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
961 //old reference field 3
962 pCursor
->Move(fnMoveForward
);
963 SwField
* pOldRef23
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
964 aFormat
= pOldRef23
->GetFormat();
965 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
966 pOldRef23
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
967 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
969 pCursor
->Move(fnMoveForward
);
970 SwTextNode
* pTextNd12
= pCursor
->GetPointNode().GetTextNode();
971 SwTextAttr
* const pFootnote12
972 = pTextNd12
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
973 const SwFormatFootnote
& rFootnote12(pFootnote12
->GetFootnote());
974 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), rFootnote12
.GetNumber());
975 SwTextFootnote
* pTFNote12
= static_cast<SwTextFootnote
*>(pFootnote12
);
976 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pTFNote12
->GetSeqRefNo());
978 pCursor
->Move(fnMoveForward
);
979 SwTextNode
* pTextNd13
= pCursor
->GetPointNode().GetTextNode();
980 SwTextAttr
* const pFootnote13
981 = pTextNd13
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
982 const SwFormatFootnote
& rFootnote13(pFootnote13
->GetFootnote());
983 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), rFootnote13
.GetNumber());
984 SwTextFootnote
* pTFNote13
= static_cast<SwTextFootnote
*>(pFootnote13
);
985 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pTFNote13
->GetSeqRefNo());
987 pCursor
->Move(fnMoveForward
);
988 SwTextNode
* pTextNd14
= pCursor
->GetPointNode().GetTextNode();
989 SwTextAttr
* const pFootnote14
990 = pTextNd14
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
991 const SwFormatFootnote
& rFootnote14(pFootnote14
->GetFootnote());
992 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), rFootnote14
.GetNumber());
993 SwTextFootnote
* pTFNote14
= static_cast<SwTextFootnote
*>(pFootnote14
);
994 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pTFNote14
->GetSeqRefNo());
995 //old reference field 4
996 pCursor
->Move(fnMoveForward
);
997 SwField
* pOldRef24
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
998 aFormat
= pOldRef24
->GetFormat();
999 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1000 pOldRef24
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1001 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
1002 //old reference field 5
1003 pCursor
->Move(fnMoveForward
);
1004 SwField
* pOldRef25
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1005 aFormat
= pOldRef25
->GetFormat();
1006 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1007 pOldRef25
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1008 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(3)), aAny
);
1010 pCursor
->Move(fnMoveForward
);
1011 SwTextNode
* pTextNd15
= pCursor
->GetPointNode().GetTextNode();
1012 SwTextAttr
* const pFootnote15
1013 = pTextNd15
->GetTextAttrForCharAt(pCursor
->GetPoint()->GetContentIndex(), RES_TXTATR_FTN
);
1014 const SwFormatFootnote
& rFootnote15(pFootnote15
->GetFootnote());
1015 CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), rFootnote15
.GetNumber());
1016 SwTextFootnote
* pTFNote15
= static_cast<SwTextFootnote
*>(pFootnote15
);
1017 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pTFNote15
->GetSeqRefNo());
1020 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf63553
)
1023 SwDoc
* pDoc
= getSwDoc();
1024 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1025 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
1026 //inserting sequence field 1
1027 SwSetExpFieldType
* pSeqType
= static_cast<SwSetExpFieldType
*>(
1028 pWrtShell
->GetFieldType(SwFieldIds::SetExp
, "Illustration"));
1029 SwSetExpField
aSetField1(pSeqType
, "", SVX_NUM_ARABIC
);
1030 pWrtShell
->InsertField2(aSetField1
);
1031 SwGetRefFieldType
* pRefType
1032 = static_cast<SwGetRefFieldType
*>(pWrtShell
->GetFieldType(0, SwFieldIds::GetRef
));
1033 //moving cursor to the starting of document
1034 pWrtShell
->StartOfSection();
1035 //inserting reference field 1
1036 SwGetRefField
aGetField1(pRefType
, "Illustration", "", REF_SEQUENCEFLD
, sal_uInt16(0),
1038 pWrtShell
->InsertField2(aGetField1
);
1039 //now we have ref1-seq1
1041 pCursor
->Move(fnMoveForward
);
1042 //inserting sequence field 2
1043 SwSetExpField
aSetField2(pSeqType
, "", SVX_NUM_ARABIC
);
1044 pWrtShell
->InsertField2(aSetField2
);
1046 pWrtShell
->StartOfSection();
1047 pCursor
->Move(fnMoveForward
);
1048 //inserting reference field 2
1049 SwGetRefField
aGetField2(pRefType
, "Illustration", "", REF_SEQUENCEFLD
, sal_uInt16(1),
1051 pWrtShell
->InsertField2(aGetField2
);
1052 //now we have ref1-ref2-seq1-seq2
1054 pCursor
->Move(fnMoveForward
);
1055 pCursor
->Move(fnMoveForward
);
1056 //inserting sequence field 3
1057 SwSetExpField
aSetField3(pSeqType
, "", SVX_NUM_ARABIC
);
1058 pWrtShell
->InsertField2(aSetField3
);
1059 pWrtShell
->StartOfSection();
1060 pCursor
->Move(fnMoveForward
);
1061 pCursor
->Move(fnMoveForward
);
1062 //inserting reference field 3
1063 SwGetRefField
aGetField3(pRefType
, "Illustration", "", REF_SEQUENCEFLD
, sal_uInt16(2),
1065 pWrtShell
->InsertField2(aGetField3
);
1066 //now after insertion we have ref1-ref2-ref3-seq1-seq2-seq3
1067 //updating the fields
1068 IDocumentFieldsAccess
& rField(pDoc
->getIDocumentFieldsAccess());
1069 rField
.UpdateExpFields(nullptr, true);
1070 //creating new clipboard doc
1071 rtl::Reference
<SwDoc
> xClpDoc(new SwDoc());
1072 xClpDoc
->SetClipBoard(true);
1073 xClpDoc
->getIDocumentFieldsAccess().LockExpFields();
1074 //selecting reference field 2 and 3 and sequence field 1 and 2
1075 //selection is such that more than one and not all sequence fields and reference fields are selected
1076 //ref1-[ref2-ref3-seq1-seq2]-seq3
1077 pWrtShell
->StartOfSection();
1078 pCursor
->Move(fnMoveForward
);
1081 pCursor
->Move(fnMoveForward
);
1082 pCursor
->Move(fnMoveForward
);
1083 pCursor
->Move(fnMoveForward
);
1084 pCursor
->Move(fnMoveForward
);
1085 //copying the selection to clipboard
1086 pWrtShell
->Copy(*xClpDoc
);
1087 //deleting selection mark after copy
1088 pCursor
->DeleteMark();
1089 //checking whether the sequence and reference fields have same values after copy operation
1093 pWrtShell
->StartOfSection();
1094 SwField
* pRef1
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1095 aFormat
= pRef1
->GetFormat();
1096 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1097 pRef1
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1098 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
1100 pCursor
->Move(fnMoveForward
);
1101 SwField
* pRef2
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1102 aFormat
= pRef2
->GetFormat();
1103 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1104 pRef2
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1105 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
1107 pCursor
->Move(fnMoveForward
);
1108 SwField
* pRef3
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1109 aFormat
= pRef3
->GetFormat();
1110 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1111 pRef3
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1112 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1114 pCursor
->Move(fnMoveForward
);
1115 SwSetExpField
* pSeqF1
1116 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1117 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeqF1
->GetSeqNumber());
1118 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF1
->GetFieldName());
1120 pCursor
->Move(fnMoveForward
);
1121 SwSetExpField
* pSeqF2
1122 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1123 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeqF2
->GetSeqNumber());
1124 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF2
->GetFieldName());
1126 pCursor
->Move(fnMoveForward
);
1127 SwSetExpField
* pSeqF3
1128 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1129 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeqF3
->GetSeqNumber());
1130 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF3
->GetFieldName());
1131 //moving cursor to the end of the document
1132 pWrtShell
->EndOfSection();
1133 //pasting the copied selection at current cursor position
1134 pWrtShell
->Paste(*xClpDoc
);
1135 //checking the fields, both new and old, for proper values
1136 pWrtShell
->StartOfSection();
1137 //now we have ref1-ref2-ref3-seq1-seq2-seq3-nref1-nref2-nseq1-nseq2
1138 //old reference field 1
1139 SwField
* pOldRef11
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1140 aFormat
= pOldRef11
->GetFormat();
1141 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1142 pOldRef11
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1143 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
1144 //old reference field 2
1145 pCursor
->Move(fnMoveForward
);
1146 SwField
* pOldRef12
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1147 aFormat
= pOldRef12
->GetFormat();
1148 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1149 pOldRef12
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1150 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
1151 //old reference field 3
1152 pCursor
->Move(fnMoveForward
);
1153 SwField
* pOldRef13
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1154 aFormat
= pOldRef13
->GetFormat();
1155 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1156 pOldRef13
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1157 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1158 //old sequence field 1
1159 pCursor
->Move(fnMoveForward
);
1160 SwSetExpField
* pSeq1
1161 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1162 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeq1
->GetSeqNumber());
1163 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq1
->GetFieldName());
1164 //old sequence field 2
1165 pCursor
->Move(fnMoveForward
);
1166 SwSetExpField
* pSeq2
1167 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1168 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeq2
->GetSeqNumber());
1169 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq2
->GetFieldName());
1170 //old sequence field 3
1171 pCursor
->Move(fnMoveForward
);
1172 SwSetExpField
* pSeq3
1173 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1174 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeq3
->GetSeqNumber());
1175 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq3
->GetFieldName());
1176 //new reference field 1
1177 pCursor
->Move(fnMoveForward
);
1178 SwField
* pNewRef11
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1179 aFormat
= pNewRef11
->GetFormat();
1180 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1181 pNewRef11
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1182 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny
);
1183 //new reference field 2
1184 pCursor
->Move(fnMoveForward
);
1185 SwField
* pNewRef12
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1186 aFormat
= pNewRef12
->GetFormat();
1187 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1188 pNewRef12
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1189 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1190 //new sequence field 1
1191 pCursor
->Move(fnMoveForward
);
1192 SwSetExpField
* pNewSeq1
1193 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1194 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pNewSeq1
->GetSeqNumber());
1195 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq1
->GetFieldName());
1196 //new sequence field 2
1197 pCursor
->Move(fnMoveForward
);
1198 SwSetExpField
* pNewSeq2
1199 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1200 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pNewSeq2
->GetSeqNumber());
1201 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq2
->GetFieldName());
1202 //moving the cursor to the starting of document
1203 pWrtShell
->StartOfSection();
1204 //pasting the selection again at current cursor position
1205 pWrtShell
->Paste(*xClpDoc
);
1206 //checking the fields, both new and old, for proper values
1207 pWrtShell
->StartOfSection();
1208 //now we have [nnref1-nnref2-nnseq1-nnseq2]-ref1-[ref2-ref3-seq1-seq2]-seq3-[nref1-nref2-nseq1-nseq2]
1209 //new reference field 1
1210 SwField
* pNewRef21
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1211 aFormat
= pNewRef21
->GetFormat();
1212 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1213 pNewRef21
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1214 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(6)), aAny
);
1215 //new reference field 2
1216 pCursor
->Move(fnMoveForward
);
1217 SwField
* pNewRef22
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1218 aFormat
= pNewRef22
->GetFormat();
1219 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1220 pNewRef22
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1221 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1222 //new sequence field 1
1223 pCursor
->Move(fnMoveForward
);
1224 SwSetExpField
* pNewSeq11
1225 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1226 CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), pNewSeq11
->GetSeqNumber());
1227 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq11
->GetFieldName());
1228 //new sequence field 2
1229 pCursor
->Move(fnMoveForward
);
1230 SwSetExpField
* pNewSeq12
1231 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1232 CPPUNIT_ASSERT_EQUAL(sal_uInt16(6), pNewSeq12
->GetSeqNumber());
1233 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq12
->GetFieldName());
1234 //old reference field 1
1235 pCursor
->Move(fnMoveForward
);
1236 SwField
* pOldRef21
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1237 aFormat
= pOldRef21
->GetFormat();
1238 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1239 pOldRef21
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1240 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny
);
1241 //old reference field 2
1242 pCursor
->Move(fnMoveForward
);
1243 SwField
* pOldRef22
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1244 aFormat
= pOldRef22
->GetFormat();
1245 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1246 pOldRef22
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1247 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny
);
1248 //old reference field 3
1249 pCursor
->Move(fnMoveForward
);
1250 SwField
* pOldRef23
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1251 aFormat
= pOldRef23
->GetFormat();
1252 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1253 pOldRef23
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1254 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1255 //old sequence field 1
1256 pCursor
->Move(fnMoveForward
);
1257 SwSetExpField
* pOldSeq11
1258 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1259 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pOldSeq11
->GetSeqNumber());
1260 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq11
->GetFieldName());
1261 //old sequence field 2
1262 pCursor
->Move(fnMoveForward
);
1263 SwSetExpField
* pOldSeq12
1264 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1265 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pOldSeq12
->GetSeqNumber());
1266 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq12
->GetFieldName());
1267 //old sequence field 3
1268 pCursor
->Move(fnMoveForward
);
1269 SwSetExpField
* pOldSeq13
1270 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1271 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pOldSeq13
->GetSeqNumber());
1272 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq13
->GetFieldName());
1273 //old reference field 4
1274 pCursor
->Move(fnMoveForward
);
1275 SwField
* pOldRef24
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1276 aFormat
= pOldRef24
->GetFormat();
1277 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1278 pOldRef24
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1279 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny
);
1280 //old reference field 5
1281 pCursor
->Move(fnMoveForward
);
1282 SwField
* pOldRef25
= SwCursorShell::GetFieldAtCursor(pCursor
, true);
1283 aFormat
= pOldRef25
->GetFormat();
1284 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT
), aFormat
);
1285 pOldRef25
->QueryValue(aAny
, sal_uInt16(FIELD_PROP_SHORT1
));
1286 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny
);
1287 //old sequence field 4
1288 pCursor
->Move(fnMoveForward
);
1289 SwSetExpField
* pOldSeq14
1290 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1291 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pOldSeq14
->GetSeqNumber());
1292 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq14
->GetFieldName());
1293 //old sequence field 5
1294 pCursor
->Move(fnMoveForward
);
1295 SwSetExpField
* pOldSeq15
1296 = static_cast<SwSetExpField
*>(SwCursorShell::GetFieldAtCursor(pCursor
, true));
1297 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pOldSeq15
->GetSeqNumber());
1298 CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq15
->GetFieldName());
1301 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf74230
)
1304 //exporting the empty document to ODT via TempFile
1306 CPPUNIT_ASSERT(maTempFile
.IsValid());
1307 //loading an XML DOM of the "styles.xml" of the TempFile
1308 xmlDocUniquePtr pXmlDoc
= parseExport("styles.xml");
1309 //pXmlDoc should not be null
1310 CPPUNIT_ASSERT(pXmlDoc
);
1311 //asserting XPath in loaded XML DOM
1312 assertXPath(pXmlDoc
, "//office:styles/style:default-style[@style:family='graphic']/"
1313 "style:graphic-properties[@svg:stroke-color='#3465a4']");
1314 assertXPath(pXmlDoc
, "//office:styles/style:default-style[@style:family='graphic']/"
1315 "style:graphic-properties[@draw:fill-color='#729fcf']");
1318 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf80663
)
1321 SwDoc
* pDoc
= getSwDoc();
1322 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1323 //Inserting 2x2 Table
1324 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
1325 SwInsertTableOptions
TableOpt(SwInsertTableFlags::DefaultBorder
, 0);
1326 pWrtShell
->InsertTable(TableOpt
, 2, 2);
1327 //Checking for the number of rows and columns
1328 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
1329 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1330 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1331 //Deleting the first row
1332 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1333 pWrtShell
->SelTableRow(); //selects the first row
1334 pWrtShell
->DeleteRow();
1335 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1336 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1338 rUndoManager
.Undo();
1339 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1340 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1342 rUndoManager
.Redo();
1343 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1344 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1346 rUndoManager
.Undo();
1347 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1348 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1349 //Deleting the second row
1350 pWrtShell
->GoNextCell(); //moves the cursor to next cell
1351 pWrtShell
->SelTableRow(); //selects the second row
1352 pWrtShell
->DeleteRow();
1353 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1354 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1356 rUndoManager
.Undo();
1357 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1358 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1360 rUndoManager
.Redo();
1361 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1362 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1364 rUndoManager
.Undo();
1365 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1366 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1367 //Deleting the first column
1368 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1369 pWrtShell
->SelTableCol(); //selects first column
1370 pWrtShell
->DeleteCol();
1371 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1372 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1374 rUndoManager
.Undo();
1375 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1376 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1378 rUndoManager
.Redo();
1379 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1380 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1382 rUndoManager
.Undo();
1383 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1384 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1385 //Deleting the second column
1386 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1387 pWrtShell
->GoNextCell(); //moves the cursor to next cell
1388 pWrtShell
->SelTableCol(); //selects second column
1389 pWrtShell
->DeleteCol();
1390 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1391 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1393 rUndoManager
.Undo();
1394 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1395 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1397 rUndoManager
.Redo();
1398 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1399 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1401 rUndoManager
.Undo();
1402 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1403 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1406 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf57197
)
1409 SwDoc
* pDoc
= getSwDoc();
1410 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1411 //Inserting 1x1 Table
1412 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
1413 SwInsertTableOptions
TableOpt(SwInsertTableFlags::DefaultBorder
, 0);
1414 pWrtShell
->InsertTable(TableOpt
, 1, 1);
1415 //Checking for the number of rows and columns
1416 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
1417 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1418 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1419 //Inserting one row before the existing row
1420 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1421 pWrtShell
->InsertRow(1, false);
1422 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1423 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1425 rUndoManager
.Undo();
1426 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1427 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1429 rUndoManager
.Redo();
1430 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1431 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1433 rUndoManager
.Undo();
1434 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1435 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1436 //Inserting one row after the existing row
1437 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1438 pWrtShell
->InsertRow(1, true);
1439 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1440 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1442 rUndoManager
.Undo();
1443 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1444 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1446 rUndoManager
.Redo();
1447 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
1448 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1450 rUndoManager
.Undo();
1451 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1452 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1453 //Inserting one column before the existing column
1454 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1455 pWrtShell
->InsertCol(1, false);
1456 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1457 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1459 rUndoManager
.Undo();
1460 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1461 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1463 rUndoManager
.Redo();
1464 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1465 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1467 rUndoManager
.Undo();
1468 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1469 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1470 //Inserting one column after the existing column
1471 pWrtShell
->StartOfSection(); //moves the cursor to the start of Doc
1472 pWrtShell
->InsertCol(1, true);
1473 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1474 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1476 rUndoManager
.Undo();
1477 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1478 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1480 rUndoManager
.Redo();
1481 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1482 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
1484 rUndoManager
.Undo();
1485 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1486 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1489 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf131990
)
1492 SwDoc
* pDoc
= getSwDoc();
1493 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1495 CPPUNIT_ASSERT(!pWrtShell
->Up(false, 1, true));
1496 CPPUNIT_ASSERT(!pWrtShell
->Down(false, 1, true));
1499 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf90808
)
1502 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
1503 uno::Reference
<text::XTextRange
> xTextRange
= xTextDocument
->getText();
1504 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
1505 uno::Reference
<text::XParagraphCursor
> xCursor(xText
->createTextCursor(), uno::UNO_QUERY
);
1506 //inserting text into document so that the paragraph is not empty
1507 xText
->setString("Hello World!");
1508 uno::Reference
<lang::XMultiServiceFactory
> xFact(mxComponent
, uno::UNO_QUERY
);
1509 //creating bookmark 1
1510 uno::Reference
<text::XTextContent
> xHeadingBookmark1(
1511 xFact
->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY
);
1512 uno::Reference
<container::XNamed
> xHeadingName1(xHeadingBookmark1
, uno::UNO_QUERY
);
1513 xHeadingName1
->setName("__RefHeading__1");
1514 //moving cursor to the starting of paragraph
1515 xCursor
->gotoStartOfParagraph(false);
1516 //inserting the bookmark in paragraph
1517 xText
->insertTextContent(xCursor
, xHeadingBookmark1
, true);
1518 //creating bookmark 2
1519 uno::Reference
<text::XTextContent
> xHeadingBookmark2(
1520 xFact
->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY
);
1521 uno::Reference
<container::XNamed
> xHeadingName2(xHeadingBookmark2
, uno::UNO_QUERY
);
1522 xHeadingName2
->setName("__RefHeading__2");
1523 //inserting the bookmark in same paragraph, at the end
1524 //only one bookmark of this type is allowed in each paragraph an exception of com.sun.star.lang.IllegalArgumentException must be thrown when inserting the other bookmark in same paragraph
1525 xCursor
->gotoEndOfParagraph(true);
1526 CPPUNIT_ASSERT_THROW(xText
->insertTextContent(xCursor
, xHeadingBookmark2
, true),
1527 css::lang::IllegalArgumentException
);
1528 //now testing for __RefNumPara__
1529 //creating bookmark 1
1530 uno::Reference
<text::XTextContent
> xNumBookmark1(
1531 xFact
->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY
);
1532 uno::Reference
<container::XNamed
> xNumName1(xNumBookmark1
, uno::UNO_QUERY
);
1533 xNumName1
->setName("__RefNumPara__1");
1534 //moving cursor to the starting of paragraph
1535 xCursor
->gotoStartOfParagraph(false);
1536 //inserting the bookmark in paragraph
1537 xText
->insertTextContent(xCursor
, xNumBookmark1
, true);
1538 //creating bookmark 2
1539 uno::Reference
<text::XTextContent
> xNumBookmark2(
1540 xFact
->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY
);
1541 uno::Reference
<container::XNamed
> xNumName2(xNumBookmark2
, uno::UNO_QUERY
);
1542 xNumName2
->setName("__RefNumPara__2");
1543 //inserting the bookmark in same paragraph, at the end
1544 //only one bookmark of this type is allowed in each paragraph an exception of com.sun.star.lang.IllegalArgumentException must be thrown when inserting the other bookmark in same paragraph
1545 xCursor
->gotoEndOfParagraph(true);
1546 CPPUNIT_ASSERT_THROW(xText
->insertTextContent(xCursor
, xNumBookmark2
, true),
1547 css::lang::IllegalArgumentException
);
1550 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf97601
)
1552 // Instructions from the bugreport to trigger an infinite loop.
1553 createSwDoc("tdf97601.odt");
1554 uno::Reference
<text::XTextEmbeddedObjectsSupplier
> xEmbeddedObjectsSupplier(mxComponent
,
1556 uno::Reference
<container::XNameAccess
> xEmbeddedObjects
1557 = xEmbeddedObjectsSupplier
->getEmbeddedObjects();
1558 uno::Reference
<beans::XPropertySet
> xChart
;
1559 xEmbeddedObjects
->getByName("myChart") >>= xChart
;
1560 uno::Reference
<chart2::data::XDataSource
> xChartComponent
;
1561 xChart
->getPropertyValue("Component") >>= xChartComponent
;
1562 uno::Sequence
<uno::Reference
<chart2::data::XLabeledDataSequence
>> aDataSequences
1563 = xChartComponent
->getDataSequences();
1564 uno::Reference
<document::XEmbeddedObjectSupplier2
> xChartState(xChart
, uno::UNO_QUERY
);
1565 xChartState
->getExtendedControlOverEmbeddedObject()->changeState(1);
1566 uno::Reference
<util::XModifiable
> xDataSequenceModifiable(aDataSequences
[2]->getValues(),
1568 xDataSequenceModifiable
->setModified(true);
1570 // Make sure that the chart is marked as modified.
1571 uno::Reference
<util::XModifiable
> xModifiable(xChartComponent
, uno::UNO_QUERY
);
1572 CPPUNIT_ASSERT_EQUAL(true, bool(xModifiable
->isModified()));
1574 // This never returned.
1575 Scheduler::ProcessEventsToIdle();
1578 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf75137
)
1581 SwDoc
* pDoc
= getSwDoc();
1582 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1583 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(true);
1584 pWrtShell
->InsertFootnote("This is first footnote");
1585 SwNodeOffset firstIndex
= pShellCursor
->GetPointNode().GetIndex();
1586 pShellCursor
->GotoFootnoteAnchor();
1587 pWrtShell
->InsertFootnote("This is second footnote");
1588 pWrtShell
->Up(false);
1589 SwNodeOffset secondIndex
= pShellCursor
->GetPointNode().GetIndex();
1590 pWrtShell
->Down(false);
1591 SwNodeOffset thirdIndex
= pShellCursor
->GetPointNode().GetIndex();
1592 CPPUNIT_ASSERT_EQUAL(firstIndex
, thirdIndex
);
1593 CPPUNIT_ASSERT(firstIndex
!= secondIndex
);
1596 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf83798
)
1598 createSwDoc("tdf83798.odt");
1599 SwDoc
* pDoc
= getSwDoc();
1600 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1601 pWrtShell
->GotoNextTOXBase();
1602 const SwTOXBase
* pTOXBase
= pWrtShell
->GetCurTOX();
1603 pWrtShell
->UpdateTableOf(*pTOXBase
);
1604 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
1606 pCursor
->Move(fnMoveForward
, GoInNode
);
1607 pCursor
->Move(fnMoveBackward
, GoInContent
);
1608 CPPUNIT_ASSERT_EQUAL(OUString("Table of Contents"), pCursor
->GetText());
1609 pCursor
->Move(fnMoveForward
, GoInContent
);
1610 pCursor
->DeleteMark();
1612 pCursor
->Move(fnMoveForward
, GoInContent
);
1613 CPPUNIT_ASSERT_EQUAL(OUString("1"), pCursor
->GetText());
1614 pCursor
->DeleteMark();
1615 pCursor
->Move(fnMoveForward
, GoInNode
);
1617 pCursor
->Move(fnMoveForward
, GoInContent
);
1618 pCursor
->Move(fnMoveForward
, GoInContent
);
1619 pCursor
->Move(fnMoveForward
, GoInContent
);
1620 CPPUNIT_ASSERT_EQUAL(OUString("1.A"), pCursor
->GetText());
1621 pCursor
->DeleteMark();
1622 pCursor
->Move(fnMoveForward
, GoInNode
);
1624 pCursor
->Move(fnMoveForward
, GoInContent
);
1625 CPPUNIT_ASSERT_EQUAL(OUString("2"), pCursor
->GetText());
1626 pCursor
->DeleteMark();
1627 pCursor
->Move(fnMoveForward
, GoInNode
);
1629 pCursor
->Move(fnMoveForward
, GoInContent
);
1630 pCursor
->Move(fnMoveForward
, GoInContent
);
1631 pCursor
->Move(fnMoveForward
, GoInContent
);
1632 CPPUNIT_ASSERT_EQUAL(OUString("2.A"), pCursor
->GetText());
1633 pCursor
->DeleteMark();
1636 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf89714
)
1639 uno::Reference
<lang::XMultiServiceFactory
> xFact(mxComponent
, uno::UNO_QUERY
);
1640 uno::Reference
<uno::XInterface
> xInterface(xFact
->createInstance("com.sun.star.text.Defaults"),
1642 uno::Reference
<beans::XPropertyState
> xPropState(xInterface
, uno::UNO_QUERY
);
1643 //enabled Paragraph Orphan and Widows by default starting in LO5.1
1644 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int8(2)), xPropState
->getPropertyDefault("ParaOrphans"));
1645 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int8(2)), xPropState
->getPropertyDefault("ParaWidows"));
1648 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf130287
)
1650 //create a new writer document
1652 SwDoc
* pDoc
= getSwDoc();
1653 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1654 //insert a 1-cell table in the newly created document
1655 SwInsertTableOptions
TableOpt(SwInsertTableFlags::DefaultBorder
, 0);
1656 pWrtShell
->InsertTable(TableOpt
, 1, 1);
1657 //checking for the row and column
1658 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
1659 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getRows()->getCount());
1660 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getColumns()->getCount());
1661 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByName("A1");
1662 uno::Reference
<text::XText
> xCellText(xCell
, uno::UNO_QUERY
);
1663 uno::Reference
<text::XTextRange
> xParagraph
= getParagraphOfText(1, xCellText
);
1664 // they were 2 (orphan/widow control enabled unnecessarily in Table Contents paragraph style)
1665 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), getProperty
<sal_Int8
>(xParagraph
, "ParaOrphans"));
1666 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), getProperty
<sal_Int8
>(xParagraph
, "ParaWidows"));
1669 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testPropertyDefaults
)
1672 uno::Reference
<lang::XMultiServiceFactory
> xFact(mxComponent
, uno::UNO_QUERY
);
1673 uno::Reference
<uno::XInterface
> xInterface(xFact
->createInstance("com.sun.star.text.Defaults"),
1675 uno::Reference
<beans::XPropertySet
> xPropSet(xInterface
, uno::UNO_QUERY_THROW
);
1676 uno::Reference
<beans::XPropertyState
> xPropState(xInterface
, uno::UNO_QUERY
);
1677 //testing CharFontName from style::CharacterProperties
1678 //getting property default
1679 uno::Any aCharFontName
= xPropState
->getPropertyDefault("CharFontName");
1680 //asserting property default and defaults received from "css.text.Defaults" service
1681 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharFontName"), aCharFontName
);
1682 //changing the default value
1683 xPropSet
->setPropertyValue("CharFontName", uno::Any(OUString("Symbol")));
1684 CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("Symbol")), xPropSet
->getPropertyValue("CharFontName"));
1685 //resetting the value to default
1686 xPropState
->setPropertyToDefault("CharFontName");
1687 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharFontName"), aCharFontName
);
1688 //testing CharHeight from style::CharacterProperties
1689 //getting property default
1690 uno::Any aCharHeight
= xPropState
->getPropertyDefault("CharHeight");
1691 //asserting property default and defaults received from "css.text.Defaults" service
1692 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharHeight"), aCharHeight
);
1693 //changing the default value
1694 xPropSet
->setPropertyValue("CharHeight", uno::Any(float(14)));
1695 CPPUNIT_ASSERT_EQUAL(uno::Any(float(14)), xPropSet
->getPropertyValue("CharHeight"));
1696 //resetting the value to default
1697 xPropState
->setPropertyToDefault("CharHeight");
1698 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharHeight"), aCharHeight
);
1699 //testing CharWeight from style::CharacterProperties
1700 uno::Any aCharWeight
= xPropSet
->getPropertyValue("CharWeight");
1701 //changing the default value
1702 xPropSet
->setPropertyValue("CharWeight", uno::Any(float(awt::FontWeight::BOLD
)));
1703 CPPUNIT_ASSERT_EQUAL(uno::Any(float(awt::FontWeight::BOLD
)),
1704 xPropSet
->getPropertyValue("CharWeight"));
1705 //resetting the value to default
1706 xPropState
->setPropertyToDefault("CharWeight");
1707 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharWeight"), aCharWeight
);
1708 //testing CharUnderline from style::CharacterProperties
1709 uno::Any aCharUnderline
= xPropSet
->getPropertyValue("CharUnderline");
1710 //changing the default value
1711 xPropSet
->setPropertyValue("CharUnderline", uno::Any(sal_Int16(awt::FontUnderline::SINGLE
)));
1712 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(awt::FontUnderline::SINGLE
)),
1713 xPropSet
->getPropertyValue("CharUnderline"));
1714 //resetting the value to default
1715 xPropState
->setPropertyToDefault("CharUnderline");
1716 CPPUNIT_ASSERT_EQUAL(xPropSet
->getPropertyValue("CharUnderline"), aCharUnderline
);
1719 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTableBackgroundColor
)
1722 SwDoc
* pDoc
= getSwDoc();
1723 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1724 SwInsertTableOptions
TableOpt(SwInsertTableFlags::DefaultBorder
, 0);
1725 pWrtShell
->InsertTable(TableOpt
, 3, 3); //Inserting Table
1726 //Checking Rows and Columns of Inserted Table
1727 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
1728 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable
->getRows()->getCount());
1729 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable
->getColumns()->getCount());
1730 pWrtShell
->StartOfSection();
1731 pWrtShell
->SelTableRow(); //Selecting First Row
1732 pWrtShell
->ClearMark();
1733 //Modifying the color of Table Box
1734 pWrtShell
->SetBoxBackground(
1735 SvxBrushItem(Color(sal_Int32(0xFF00FF)), sal_Int16(RES_BACKGROUND
)));
1736 //Checking cells for background color only A1 should be modified
1737 uno::Reference
<table::XCell
> xCell
;
1738 xCell
= xTable
->getCellByName("A1");
1739 CPPUNIT_ASSERT_EQUAL(Color(0xFF00FF), getProperty
<Color
>(xCell
, "BackColor"));
1740 xCell
= xTable
->getCellByName("A2");
1741 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1742 xCell
= xTable
->getCellByName("A3");
1743 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1744 xCell
= xTable
->getCellByName("B1");
1745 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1746 xCell
= xTable
->getCellByName("B2");
1747 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1748 xCell
= xTable
->getCellByName("B3");
1749 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1750 xCell
= xTable
->getCellByName("C1");
1751 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1752 xCell
= xTable
->getCellByName("C2");
1753 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1754 xCell
= xTable
->getCellByName("C3");
1755 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xCell
, "BackColor"));
1758 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf88899
)
1761 uno::Reference
<document::XDocumentPropertiesSupplier
> xDocumentPropertiesSupplier(
1762 mxComponent
, uno::UNO_QUERY
);
1763 uno::Reference
<document::XDocumentProperties
> xProps(
1764 xDocumentPropertiesSupplier
->getDocumentProperties());
1765 uno::Reference
<beans::XPropertyContainer
> xUserProps
= xProps
->getUserDefinedProperties();
1766 css::util::DateTime aDateTime
1767 = { sal_uInt32(1234567), sal_uInt16(3), sal_uInt16(3), sal_uInt16(3),
1768 sal_uInt16(10), sal_uInt16(11), sal_uInt16(2014), true };
1769 xUserProps
->addProperty("dateTime", sal_Int16(beans::PropertyAttribute::OPTIONAL
),
1770 uno::Any(aDateTime
));
1771 uno::Reference
<lang::XMultiServiceFactory
> xFact(mxComponent
, uno::UNO_QUERY
);
1772 uno::Reference
<text::XTextField
> xTextField(
1773 xFact
->createInstance("com.sun.star.text.textfield.docinfo.Custom"), uno::UNO_QUERY
);
1774 //Setting Name Property
1775 uno::Reference
<beans::XPropertySet
> xPropSet(xTextField
, uno::UNO_QUERY_THROW
);
1776 xPropSet
->setPropertyValue("Name", uno::Any(OUString("dateTime")));
1777 //Setting NumberFormat
1778 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(mxComponent
,
1780 uno::Reference
<util::XNumberFormatTypes
> xNumFormat(xNumberFormatsSupplier
->getNumberFormats(),
1782 css::lang::Locale alocale
;
1783 alocale
.Language
= "en";
1784 alocale
.Country
= "US";
1785 sal_Int16 key
= xNumFormat
->getStandardFormat(util::NumberFormat::DATETIME
, alocale
);
1786 xPropSet
->setPropertyValue("NumberFormat", uno::Any(key
));
1787 //Inserting Text Content
1788 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
1789 uno::Reference
<text::XTextRange
> xTextRange
= xTextDocument
->getText();
1790 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
1791 xText
->insertTextContent(xTextRange
, xTextField
, true);
1792 //Retrieving the contents for verification
1793 CPPUNIT_ASSERT_EQUAL(OUString("11/10/14 03:03 AM"), xTextField
->getPresentation(false));
1796 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf151605
)
1798 createSwDoc("tdf151605.odt");
1800 // disable IncludeHiddenText
1801 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
1802 comphelper::ConfigurationChanges::create());
1803 officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(false, batch
);
1804 officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(false, batch
);
1807 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1808 dispatchCommand(mxComponent
, ".uno:Copy", {});
1810 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1811 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::STRING
)) } });
1813 // Paste as Unformatted text
1814 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1816 CPPUNIT_ASSERT_EQUAL(OUString("Before"), getParagraph(1)->getString());
1817 CPPUNIT_ASSERT_EQUAL(OUString("After"), getParagraph(2)->getString());
1820 officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(true, batch
);
1821 officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(true, batch
);
1825 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf90362
)
1827 createSwDoc("tdf90362.fodt");
1828 SwDoc
* pDoc
= getSwDoc();
1829 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1830 // Ensure correct initial setting
1831 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
1832 comphelper::ConfigurationChanges::create());
1833 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(false, batch
);
1835 // First check if the end of the second paragraph is indeed protected.
1836 pWrtShell
->EndPara();
1837 pWrtShell
->Down(/*bSelect=*/false);
1838 CPPUNIT_ASSERT_EQUAL(true, pWrtShell
->HasReadonlySel());
1840 // Then enable ignoring of protected areas and make sure that this time the cursor is read-write.
1841 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(true, batch
);
1843 CPPUNIT_ASSERT_EQUAL(false, pWrtShell
->HasReadonlySel());
1844 // Clean up, otherwise following tests will have that option set
1845 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(false, batch
);
1849 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUndoDelAsCharTdf107512
)
1852 SwDoc
* pDoc
= getSwDoc();
1853 sw::UndoManager
& rUndoManager(pDoc
->GetUndoManager());
1854 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
1855 SwCursorShell
* pShell(pDoc
->GetEditShell());
1856 SfxItemSet
frameSet(pDoc
->GetAttrPool(), svl::Items
<RES_FRMATR_BEGIN
, RES_FRMATR_END
- 1>);
1857 SfxItemSet
grfSet(pDoc
->GetAttrPool(), svl::Items
<RES_GRFATR_BEGIN
, RES_GRFATR_END
- 1>);
1858 rIDCO
.InsertString(*pShell
->GetCursor(), "foo");
1859 pShell
->ClearMark();
1860 SwFormatAnchor
anchor(RndStdIds::FLY_AS_CHAR
);
1861 frameSet
.Put(anchor
);
1863 pShell
->SttEndDoc(true);
1864 CPPUNIT_ASSERT(rIDCO
.InsertGraphic(*pShell
->GetCursor(), OUString(), OUString(), &grf
,
1865 &frameSet
, &grfSet
, nullptr));
1866 pShell
->SttEndDoc(false);
1867 CPPUNIT_ASSERT(rIDCO
.InsertGraphic(*pShell
->GetCursor(), OUString(), OUString(), &grf
,
1868 &frameSet
, &grfSet
, nullptr));
1869 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1870 SvxCharHiddenItem
hidden(true, RES_CHRATR_HIDDEN
);
1871 pShell
->SelectTextModel(1, 4);
1872 rIDCO
.InsertPoolItem(*pShell
->GetCursor(), hidden
);
1873 // now we have "\1foo\1" with the "foo" hidden
1874 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1875 0, RES_TXTATR_FLYCNT
));
1876 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1877 4, RES_TXTATR_FLYCNT
));
1878 CPPUNIT_ASSERT_EQUAL(
1879 OUString(OUStringChar(CH_TXTATR_BREAKWORD
) + u
"foo" + OUStringChar(CH_TXTATR_BREAKWORD
)),
1880 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1881 SfxPoolItem
const* pItem
;
1882 SfxItemSet
query(pDoc
->GetAttrPool(), svl::Items
<RES_CHRATR_HIDDEN
, RES_CHRATR_HIDDEN
>);
1883 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 1, 4);
1884 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1885 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem
const*>(pItem
)->GetValue());
1886 query
.ClearItem(RES_CHRATR_HIDDEN
);
1888 // delete from the start
1889 pShell
->SelectTextModel(0, 4);
1890 rIDCO
.DeleteAndJoin(*pShell
->GetCursor());
1891 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1892 0, RES_TXTATR_FLYCNT
));
1893 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1894 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1895 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 0, 1);
1896 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1897 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1898 query
.ClearItem(RES_CHRATR_HIDDEN
);
1899 rUndoManager
.Undo();
1900 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1901 0, RES_TXTATR_FLYCNT
));
1902 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1903 4, RES_TXTATR_FLYCNT
));
1904 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1905 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1906 CPPUNIT_ASSERT_EQUAL(
1907 OUString(OUStringChar(CH_TXTATR_BREAKWORD
) + u
"foo" + OUStringChar(CH_TXTATR_BREAKWORD
)),
1908 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1909 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 0, 1);
1910 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1911 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1912 query
.ClearItem(RES_CHRATR_HIDDEN
);
1913 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 1, 4);
1914 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1915 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem
const*>(pItem
)->GetValue());
1916 query
.ClearItem(RES_CHRATR_HIDDEN
);
1917 rUndoManager
.Redo();
1918 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1919 0, RES_TXTATR_FLYCNT
));
1920 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1921 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1922 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 0, 1);
1923 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1924 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1925 query
.ClearItem(RES_CHRATR_HIDDEN
);
1926 rUndoManager
.Undo();
1927 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1928 0, RES_TXTATR_FLYCNT
));
1929 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1930 4, RES_TXTATR_FLYCNT
));
1931 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1932 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1933 CPPUNIT_ASSERT_EQUAL(
1934 OUString(OUStringChar(CH_TXTATR_BREAKWORD
) + u
"foo" + OUStringChar(CH_TXTATR_BREAKWORD
)),
1935 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1936 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 0, 1);
1937 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1938 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1939 query
.ClearItem(RES_CHRATR_HIDDEN
);
1940 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 1, 4);
1941 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1942 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem
const*>(pItem
)->GetValue());
1943 query
.ClearItem(RES_CHRATR_HIDDEN
);
1945 // delete from the end
1946 pShell
->SelectTextModel(1, 5);
1947 rIDCO
.DeleteAndJoin(*pShell
->GetCursor());
1948 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1949 0, RES_TXTATR_FLYCNT
));
1950 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1951 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1952 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 4, 5);
1953 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1954 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1955 query
.ClearItem(RES_CHRATR_HIDDEN
);
1956 rUndoManager
.Undo();
1957 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1958 0, RES_TXTATR_FLYCNT
));
1959 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1960 4, RES_TXTATR_FLYCNT
));
1961 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1962 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1963 CPPUNIT_ASSERT_EQUAL(
1964 OUString(OUStringChar(CH_TXTATR_BREAKWORD
) + u
"foo" + OUStringChar(CH_TXTATR_BREAKWORD
)),
1965 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1966 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 4, 5);
1967 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1968 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1969 query
.ClearItem(RES_CHRATR_HIDDEN
);
1970 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 1, 4);
1971 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1972 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem
const*>(pItem
)->GetValue());
1973 query
.ClearItem(RES_CHRATR_HIDDEN
);
1974 rUndoManager
.Redo();
1975 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1976 0, RES_TXTATR_FLYCNT
));
1977 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1978 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1979 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 4, 5);
1980 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1981 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1982 query
.ClearItem(RES_CHRATR_HIDDEN
);
1983 rUndoManager
.Undo();
1984 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1985 0, RES_TXTATR_FLYCNT
));
1986 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1987 4, RES_TXTATR_FLYCNT
));
1988 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
1989 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
1990 CPPUNIT_ASSERT_EQUAL(
1991 OUString(OUStringChar(CH_TXTATR_BREAKWORD
) + u
"foo" + OUStringChar(CH_TXTATR_BREAKWORD
)),
1992 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1993 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 4, 5);
1994 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1995 query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1996 query
.ClearItem(RES_CHRATR_HIDDEN
);
1997 pShell
->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query
, 1, 4);
1998 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, query
.GetItemState(RES_CHRATR_HIDDEN
, false, &pItem
));
1999 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem
const*>(pItem
)->GetValue());
2000 query
.ClearItem(RES_CHRATR_HIDDEN
);
2003 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUndoCharAttribute
)
2005 // Create a new empty Writer document
2007 SwDoc
* pDoc
= getSwDoc();
2008 SwPaM
* pCursor
= pDoc
->GetEditShell()->GetCursor();
2009 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
2010 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
2012 rIDCO
.InsertString(*pCursor
, "This will be bolded");
2013 // Position of word 9876543210
2014 // Use cursor to select part of text
2016 for (int i
= 0; i
< 9; i
++)
2018 pCursor
->Move(fnMoveBackward
);
2020 // Check that correct text was selected
2021 CPPUNIT_ASSERT_EQUAL(OUString("be bolded"), pCursor
->GetText());
2022 // Apply a "Bold" attribute to selection
2023 SvxWeightItem
aWeightItem(WEIGHT_BOLD
, RES_CHRATR_WEIGHT
);
2024 rIDCO
.InsertPoolItem(*pCursor
, aWeightItem
);
2025 SfxItemSet
aSet(pDoc
->GetAttrPool(), svl::Items
<RES_CHRATR_WEIGHT
, RES_CHRATR_WEIGHT
>);
2026 // Adds selected text's attributes to aSet
2027 pCursor
->GetPointNode().GetTextNode()->GetParaAttr(aSet
, 10, 19);
2028 SfxPoolItem
const* pPoolItem
= aSet
.GetItem(RES_CHRATR_WEIGHT
);
2029 // Check that bold is active on the selection; checks if it's in aSet
2030 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem
== aWeightItem
));
2032 rUndoManager
.Undo();
2033 // Check that bold is no longer active
2034 aSet
.ClearItem(RES_CHRATR_WEIGHT
);
2035 pCursor
->GetPointNode().GetTextNode()->GetParaAttr(aSet
, 10, 19);
2036 pPoolItem
= aSet
.GetItem(RES_CHRATR_WEIGHT
);
2037 CPPUNIT_ASSERT_EQUAL(false, (*pPoolItem
== aWeightItem
));
2040 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUndoDelAsChar
)
2043 SwDoc
* pDoc
= getSwDoc();
2044 sw::UndoManager
& rUndoManager(pDoc
->GetUndoManager());
2045 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
2046 SwCursorShell
* pShell(pDoc
->GetEditShell());
2047 SfxItemSet
frameSet(pDoc
->GetAttrPool(), svl::Items
<RES_FRMATR_BEGIN
, RES_FRMATR_END
- 1>);
2048 SfxItemSet
grfSet(pDoc
->GetAttrPool(), svl::Items
<RES_GRFATR_BEGIN
, RES_GRFATR_END
- 1>);
2049 SwFormatAnchor
anchor(RndStdIds::FLY_AS_CHAR
);
2050 frameSet
.Put(anchor
);
2052 CPPUNIT_ASSERT(rIDCO
.InsertGraphic(*pShell
->GetCursor(), OUString(), OUString(), &grf
,
2053 &frameSet
, &grfSet
, nullptr));
2054 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
2056 pShell
->Left(1, SwCursorSkipMode::Chars
);
2057 rIDCO
.DeleteAndJoin(*pShell
->GetCursor());
2058 CPPUNIT_ASSERT_EQUAL(size_t(0), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
2059 CPPUNIT_ASSERT(!pShell
->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2060 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
2061 rUndoManager
.Undo();
2062 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
2063 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2064 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
2065 rUndoManager
.Redo();
2066 CPPUNIT_ASSERT_EQUAL(size_t(0), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
2067 CPPUNIT_ASSERT(!pShell
->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2068 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
2069 rUndoManager
.Undo();
2070 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->GetFlyCount(FLYCNTTYPE_GRF
));
2071 CPPUNIT_ASSERT(pShell
->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2072 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell
->GetCursor()->GetPointNode().GetTextNode()->Len());
2075 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf86639
)
2077 createSwDoc("tdf86639.rtf");
2078 SwDoc
* pDoc
= getSwDoc();
2079 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2080 SwTextFormatColl
* pColl
= pDoc
->FindTextFormatCollByName(u
"Heading");
2081 pWrtShell
->SetTextFormatColl(pColl
);
2082 OUString aExpected
= pColl
->GetAttrSet().GetFont().GetFamilyName();
2083 // This was Calibri, should be Liberation Sans.
2084 CPPUNIT_ASSERT_EQUAL(aExpected
,
2085 getProperty
<OUString
>(getRun(getParagraph(1), 1), "CharFontName"));
2088 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf90883TableBoxGetCoordinates
)
2090 createSwDoc("tdf90883.odt");
2091 SwDoc
* pDoc
= getSwDoc();
2092 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2093 pWrtShell
->Down(true);
2095 ::GetTableSel(*pWrtShell
, aBoxes
);
2096 CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aBoxes
.size()));
2097 Point
pos(aBoxes
[0]->GetCoordinates());
2098 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos
.X()));
2099 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos
.Y()));
2100 pos
= aBoxes
[1]->GetCoordinates();
2101 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos
.X()));
2102 CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(pos
.Y()));
2105 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testEmbeddedDataSource
)
2107 // Initially no data source.
2108 uno::Reference
<uno::XComponentContext
> xComponentContext(
2109 comphelper::getProcessComponentContext());
2110 uno::Reference
<sdb::XDatabaseContext
> xDatabaseContext
2111 = sdb::DatabaseContext::create(xComponentContext
);
2112 CPPUNIT_ASSERT(!xDatabaseContext
->hasByName("calc-data-source"));
2114 // Load: should have a component and a data source, too.
2115 // Path with "#" must not cause issues
2116 createSwDoc("hash%23path/embedded-data-source.odt");
2117 CPPUNIT_ASSERT(xDatabaseContext
->hasByName("calc-data-source"));
2119 // Data source has a table named Sheet1.
2120 uno::Reference
<sdbc::XDataSource
> xDataSource(xDatabaseContext
->getByName("calc-data-source"),
2122 CPPUNIT_ASSERT(xDataSource
.is());
2123 auto xConnection
= xDataSource
->getConnection("", "");
2124 uno::Reference
<container::XNameAccess
> xTables
2125 = css::uno::Reference
<css::sdbcx::XTablesSupplier
>(xConnection
, uno::UNO_QUERY_THROW
)
2127 CPPUNIT_ASSERT(xTables
.is());
2128 CPPUNIT_ASSERT(xTables
->hasByName("Sheet1"));
2129 xConnection
->close();
2131 // Reload: should still have a component and a data source, too.
2132 saveAndReload("writer8");
2133 CPPUNIT_ASSERT(mxComponent
.is());
2134 CPPUNIT_ASSERT(xDatabaseContext
->hasByName("calc-data-source"));
2136 // Data source has a table named Sheet1 after saving to a different directory.
2137 xDataSource
.set(xDatabaseContext
->getByName("calc-data-source"), uno::UNO_QUERY
);
2138 CPPUNIT_ASSERT(xDataSource
.is());
2139 xConnection
= xDataSource
->getConnection("", "");
2140 xTables
= css::uno::Reference
<css::sdbcx::XTablesSupplier
>(xConnection
, uno::UNO_QUERY_THROW
)
2142 CPPUNIT_ASSERT(xTables
.is());
2143 CPPUNIT_ASSERT(xTables
->hasByName("Sheet1"));
2144 xConnection
->close();
2146 // Close: should not have a data source anymore.
2147 mxComponent
->dispose();
2148 mxComponent
.clear();
2149 CPPUNIT_ASSERT(!xDatabaseContext
->hasByName("calc-data-source"));
2151 // Now open again the saved result, and instead of 'save as', just 'save'.
2152 mxComponent
= loadFromDesktop(maTempFile
.GetURL(), "com.sun.star.text.TextDocument");
2153 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
2157 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUnoCursorPointer
)
2160 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"));
2161 auto pxDocDocument(dynamic_cast<SwXTextDocument
*>(xDocComponent
.get()));
2162 CPPUNIT_ASSERT(pxDocDocument
);
2163 SwDoc
* const pDoc(pxDocDocument
->GetDocShell()->GetDoc());
2164 std::unique_ptr
<SwNodeIndex
> pIdx(new SwNodeIndex(pDoc
->GetNodes().GetEndOfContent(), -1));
2165 std::unique_ptr
<SwPosition
> pPos(new SwPosition(*pIdx
));
2166 sw::UnoCursorPointer
pCursor(pDoc
->CreateUnoCursor(*pPos
));
2167 CPPUNIT_ASSERT(static_cast<bool>(pCursor
));
2168 pPos
.reset(); // we need to kill the SwPosition before disposing
2169 pIdx
.reset(); // we need to kill the SwNodeIndex before disposing
2170 xDocComponent
->dispose();
2171 CPPUNIT_ASSERT(!static_cast<bool>(pCursor
));
2174 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTextTableCellNames
)
2176 sal_Int32 nCol
, nRow2
;
2177 SwXTextTable::GetCellPosition(u
"z1", nCol
, nRow2
);
2178 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(51), nCol
);
2179 SwXTextTable::GetCellPosition(u
"AA1", nCol
, nRow2
);
2180 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(52), nCol
);
2181 SwXTextTable::GetCellPosition(u
"AB1", nCol
, nRow2
);
2182 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(53), nCol
);
2183 SwXTextTable::GetCellPosition(u
"BB1", nCol
, nRow2
);
2184 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(105), nCol
);
2187 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testShapeAnchorUndo
)
2189 createSwDoc("draw-anchor-undo.odt");
2190 SwDoc
* pDoc
= getSwDoc();
2191 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2192 SdrPage
* pPage
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2193 SdrObject
* pObject
= pPage
->GetObj(0);
2194 tools::Rectangle
aOrigLogicRect(pObject
->GetLogicRect());
2196 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
2197 rUndoManager
.StartUndo(SwUndoId::START
, nullptr);
2199 pWrtShell
->SelectObj(Point(), 0, pObject
);
2201 pWrtShell
->GetDrawView()->MoveMarkedObj(Size(100, 100));
2202 pWrtShell
->ChgAnchor(RndStdIds::FLY_AT_PARA
, true);
2204 rUndoManager
.EndUndo(SwUndoId::END
, nullptr);
2206 CPPUNIT_ASSERT(aOrigLogicRect
!= pObject
->GetLogicRect());
2208 rUndoManager
.Undo();
2210 CPPUNIT_ASSERT_EQUAL(pObject
->GetLogicRect(), aOrigLogicRect
);
2213 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf127635
)
2216 SwDoc
* pDoc
= getSwDoc();
2218 SwXTextDocument
* pXTextDocument
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
2219 CPPUNIT_ASSERT(pXTextDocument
);
2220 emulateTyping(*pXTextDocument
, u
"a b");
2222 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2223 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 2, /*bBasicCall=*/false);
2226 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
2229 dispatchCommand(mxComponent
, ".uno:TrackChanges", {});
2231 dispatchCommand(mxComponent
, ".uno:ShowTrackedChanges", {});
2233 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
2234 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
2235 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
2237 emulateTyping(*pXTextDocument
, u
"c d");
2239 SwEditShell
* const pEditShell(pDoc
->GetEditShell());
2240 // accept all redlines
2241 while (pEditShell
->GetRedlineCount())
2242 pEditShell
->AcceptRedline(0);
2244 // Without the fix in place, this test would have failed with
2245 // - Expected: C d b
2247 CPPUNIT_ASSERT_EQUAL(OUString("C d b"), getParagraph(1)->getString());
2250 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testDde
)
2253 // Type asdf and copy it.
2255 SwDoc
* pDoc
= getSwDoc();
2256 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2257 pWrtShell
->Insert("asdf");
2258 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 4, /*bBasicCall=*/false);
2259 uno::Sequence
<beans::PropertyValue
> aPropertyValues
;
2260 dispatchCommand(mxComponent
, ".uno:Copy", aPropertyValues
);
2262 // Go before the selection and paste as a DDE link.
2263 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
2264 aPropertyValues
= comphelper::InitPropertySequence(
2265 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::LINK
)) } });
2266 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
2268 // Make sure that the document starts with a field now, and its expanded string value contains asdf.
2269 const uno::Reference
<text::XTextRange
> xField
= getRun(getParagraph(1), 1);
2270 CPPUNIT_ASSERT_EQUAL(OUString("TextField"), getProperty
<OUString
>(xField
, "TextPortionType"));
2271 CPPUNIT_ASSERT(xField
->getString().endsWith("asdf"));
2277 //IdleTask class to add a low priority Idle task
2281 bool GetFlag() const;
2283 DECL_LINK(FlipFlag
, Timer
*, void);
2287 Idle maIdle
{ "sw uiwriter IdleTask" };
2291 //constructor of IdleTask Class
2292 IdleTask::IdleTask()
2295 //setting the Priority of Idle task to LOW, LOWEST
2296 maIdle
.SetPriority(TaskPriority::LOWEST
);
2297 //set idle for callback
2298 maIdle
.SetInvokeHandler(LINK(this, IdleTask
, FlipFlag
));
2303 //GetFlag() of IdleTask Class
2304 bool IdleTask::GetFlag() const
2306 //returning the status of current flag
2310 //Callback function of IdleTask Class
2311 IMPL_LINK(IdleTask
, FlipFlag
, Timer
*, , void)
2313 //setting the flag to make sure that low priority idle task has been dispatched
2317 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testDocModState
)
2319 //creating a new writer document via the XDesktop(to have more shells etc.)
2321 SwDoc
* pDoc
= getSwDoc();
2322 //creating instance of IdleTask Class
2324 //checking the state of the document via IDocumentState
2325 IDocumentState
& rState(pDoc
->getIDocumentState());
2326 //the state should not be modified
2327 CPPUNIT_ASSERT(!(rState
.IsModified()));
2328 //checking the state of the document via SfxObjectShell
2329 SwDocShell
* pShell(pDoc
->GetDocShell());
2330 CPPUNIT_ASSERT(!(pShell
->IsModified()));
2331 //looping around yield until low priority idle task is dispatched and flag is flipped
2332 while (!idleTask
.GetFlag())
2334 //dispatching all the events via VCL main-loop
2335 Application::Yield();
2337 //again checking for the state via IDocumentState
2338 CPPUNIT_ASSERT(!(rState
.IsModified()));
2339 //again checking for the state via SfxObjectShell
2340 CPPUNIT_ASSERT(!(pShell
->IsModified()));
2343 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf94804
)
2345 //create new writer document
2347 SwDoc
* pDoc
= getSwDoc();
2348 //get cursor for making bookmark at a particular location
2349 SwPaM
* pCrsr
= pDoc
->GetEditShell()->GetCursor();
2350 IDocumentMarkAccess
* pIDMAccess(pDoc
->getIDocumentMarkAccess());
2351 //make first bookmark, CROSSREF_HEADING, with *empty* name
2352 sw::mark::IMark
* pMark1(
2353 pIDMAccess
->makeMark(*pCrsr
, "", IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK
,
2354 ::sw::mark::InsertMode::New
));
2355 //get the new(autogenerated) bookmark name
2356 OUString bookmark1name
= pMark1
->GetName();
2357 //match the bookmark name, it should be like "__RefHeading__**"
2358 CPPUNIT_ASSERT(bookmark1name
.match("__RefHeading__"));
2359 //make second bookmark, CROSSREF_NUMITEM, with *empty* name
2360 sw::mark::IMark
* pMark2(
2361 pIDMAccess
->makeMark(*pCrsr
, "", IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK
,
2362 ::sw::mark::InsertMode::New
));
2363 //get the new(autogenerated) bookmark name
2364 OUString bookmark2name
= pMark2
->GetName();
2365 //match the bookmark name, it should be like "__RefNumPara__**"
2366 CPPUNIT_ASSERT(bookmark2name
.match("__RefNumPara__"));
2369 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testUnicodeNotationToggle
)
2371 createSwDoc("unicodeAltX.odt");
2372 SwDoc
* pDoc
= getSwDoc();
2373 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2374 OUString sOriginalDocString
;
2375 OUString sDocString
;
2376 OUString sExpectedString
;
2377 uno::Sequence
<beans::PropertyValue
> aPropertyValues
;
2379 pWrtShell
->EndPara();
2380 sOriginalDocString
= pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText();
2381 CPPUNIT_ASSERT_EQUAL(OUString("uU+002b"), sOriginalDocString
);
2383 dispatchCommand(mxComponent
, ".uno:UnicodeNotationToggle", aPropertyValues
);
2384 sExpectedString
= "u+";
2385 sDocString
= pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText();
2386 CPPUNIT_ASSERT_EQUAL(sDocString
, sExpectedString
);
2388 dispatchCommand(mxComponent
, ".uno:UnicodeNotationToggle", aPropertyValues
);
2389 sDocString
= pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText();
2390 CPPUNIT_ASSERT_EQUAL(sDocString
, sOriginalDocString
);
2393 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf34957
)
2395 createSwDoc("tdf34957.odt");
2396 // table with "keep with next" always started on a new page if the table was large,
2397 // regardless of whether it was already kept with the previous paragraph,
2398 // or whether the following paragraph actually fit on the same page (MAB 3.6 - 5.0)
2399 CPPUNIT_ASSERT_EQUAL(OUString("Row 1"),
2400 parseDump("/root/page[2]/body/tab[1]/row[2]/cell[1]/txt"));
2401 CPPUNIT_ASSERT_EQUAL(OUString("Row 1"),
2402 parseDump("/root/page[4]/body/tab[1]/row[2]/cell[1]/txt"));
2405 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf89954
)
2407 createSwDoc("tdf89954.odt");
2408 SwDoc
* pDoc
= getSwDoc();
2409 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2410 pWrtShell
->EndPara();
2411 SwXTextDocument
* pXTextDocument
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
2412 CPPUNIT_ASSERT(pXTextDocument
);
2413 emulateTyping(*pXTextDocument
, u
"test.");
2415 SwNodeIndex
aNodeIndex(pDoc
->GetNodes().GetEndOfContent(), -1);
2416 // Placeholder character for the comment anchor was ^A (CH_TXTATR_BREAKWORD), not <fff9> (CH_TXTATR_INWORD).
2417 // As a result, autocorrect did not turn the 't' input into 'T'.
2418 CPPUNIT_ASSERT_EQUAL(OUString(u
"Tes\uFFF9t. Test."),
2419 aNodeIndex
.GetNode().GetTextNode()->GetText());
2422 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf89720
)
2424 createSwDoc("tdf89720.odt");
2425 SwDoc
* pDoc
= getSwDoc();
2426 SwView
* pView
= pDoc
->GetDocShell()->GetView();
2427 SwPostItMgr
* pPostItMgr
= pView
->GetPostItMgr();
2428 for (std::unique_ptr
<SwSidebarItem
> const& pItem
: *pPostItMgr
)
2430 if (pItem
->mpPostIt
->IsFollow())
2431 // This was non-0: reply comments had a text range overlay,
2432 // resulting in unexpected dark color.
2433 CPPUNIT_ASSERT(!pItem
->mpPostIt
->TextRange());
2437 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf88986
)
2439 // Create a text shell.
2441 SwDoc
* pDoc
= getSwDoc();
2442 SwView
* pView
= pDoc
->GetDocShell()->GetView();
2443 SwTextShell
aShell(*pView
);
2445 // Create the item set that is normally passed to the insert frame dialog.
2446 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2447 SwFlyFrameAttrMgr
aMgr(true, pWrtShell
, Frmmgr_Type::TEXT
, nullptr);
2448 SfxItemSet aSet
= aShell
.CreateInsertFrameItemSet(aMgr
);
2450 // This was missing along with the gradient and other tables.
2451 CPPUNIT_ASSERT(aSet
.HasItem(SID_COLOR_TABLE
));
2454 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf78150
)
2457 SwDoc
* pDoc
= getSwDoc();
2458 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2459 pWrtShell
->Insert("foobar");
2461 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), getParagraph(1)->getString());
2463 dispatchCommand(mxComponent
, ".uno:DelToStartOfWord", {});
2465 // Without the fix, test fails with:
2466 // equality assertion failed
2469 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
2472 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf138873
)
2475 SwDoc
* pDoc
= getSwDoc();
2476 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2477 pWrtShell
->Insert("A B C");
2479 CPPUNIT_ASSERT_EQUAL(OUString("A B C"), getParagraph(1)->getString());
2482 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 2, /*bBasicCall=*/false);
2483 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
2485 pWrtShell
->Insert("DDD");
2487 CPPUNIT_ASSERT_EQUAL(OUString("A DDD C"), getParagraph(1)->getString());
2489 dispatchCommand(mxComponent
, ".uno:Undo", {});
2491 CPPUNIT_ASSERT_EQUAL(OUString("A B C"), getParagraph(1)->getString());
2494 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/true, 2, /*bBasicCall=*/false);
2496 dispatchCommand(mxComponent
, ".uno:Copy", {});
2498 dispatchCommand(mxComponent
, ".uno:Paste", {});
2500 // Without the fix in place, this test would have failed with
2501 // - Expected: A B C
2502 // - Actual : A CB CB
2503 CPPUNIT_ASSERT_EQUAL(OUString("A B C"), getParagraph(1)->getString());
2506 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf87922
)
2508 // Create an SwDrawTextInfo.
2509 createSwDoc("tdf87922.odt");
2510 SwDoc
* pDoc
= getSwDoc();
2511 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2512 SwScriptInfo
* pScriptInfo
= nullptr;
2513 // Get access to the single paragraph in the document.
2514 SwNodeIndex
aNodeIndex(pDoc
->GetNodes().GetEndOfContent(), -1);
2515 const OUString
& rText
= aNodeIndex
.GetNode().GetTextNode()->GetText();
2516 sal_Int32 nLength
= rText
.getLength();
2517 SwDrawTextInfo
aDrawTextInfo(pWrtShell
, *pWrtShell
->GetOut(), pScriptInfo
, rText
,
2518 TextFrameIndex(0), TextFrameIndex(nLength
));
2519 // Root -> page -> body -> text.
2520 SwTextFrame
* pTextFrame
2521 = static_cast<SwTextFrame
*>(pWrtShell
->GetLayout()->GetLower()->GetLower()->GetLower());
2522 aDrawTextInfo
.SetFrame(pTextFrame
);
2524 // If no color background color is found, assume white.
2525 Color
* pColor
= sw::GetActiveRetoucheColor();
2526 *pColor
= COL_WHITE
;
2528 // Make sure that automatic color on black background is white, not black.
2530 aDrawTextInfo
.ApplyAutoColor(&aFont
);
2531 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, aFont
.GetColor());
2539 PortionItem(OUString
const& sItemType
, sal_Int32 nLength
, PortionType nTextType
)
2540 : msItemType(sItemType
)
2542 , mnTextType(nTextType
)
2546 OUString msItemType
;
2548 PortionType mnTextType
;
2551 class PortionHandler
: public SwPortionHandler
2554 std::vector
<PortionItem
> mPortionItems
;
2555 explicit PortionHandler()
2556 : SwPortionHandler()
2560 void clear() { mPortionItems
.clear(); }
2562 virtual void Text(TextFrameIndex nLength
, PortionType nType
) override
2564 mPortionItems
.emplace_back("text", sal_Int32(nLength
), nType
);
2567 virtual void Special(TextFrameIndex nLength
, const OUString
& /*rText*/,
2568 PortionType nType
) override
2570 mPortionItems
.emplace_back("special", sal_Int32(nLength
), nType
);
2573 virtual void LineBreak() override
2575 mPortionItems
.emplace_back("line_break", 0, PortionType::NONE
);
2578 virtual void Skip(TextFrameIndex nLength
) override
2580 mPortionItems
.emplace_back("skip", sal_Int32(nLength
), PortionType::NONE
);
2583 virtual void Finish() override
{ mPortionItems
.emplace_back("finish", 0, PortionType::NONE
); }
2588 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf77014
)
2591 // The problem described in the bug tdf#77014 is that the input
2592 // field text ("ThisIsAllOneWord") is broken up on linebreak, but
2593 // it should be in one piece (like normal text).
2595 // This test checks that the input field is in one piece and if the
2596 // input field has more words, it is broken up at the correct place.
2598 createSwDoc("tdf77014.odt");
2599 SwDoc
* pDoc
= getSwDoc();
2600 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2602 SwTextFrame
* pTextFrame
2603 = static_cast<SwTextFrame
*>(pWrtShell
->GetLayout()->GetLower()->GetLower()->GetLower());
2605 PortionHandler aHandler
;
2606 pTextFrame
->VisitPortions(aHandler
);
2609 // Input Field - "One Two Three Four Five" = 25 chars
2610 CPPUNIT_ASSERT_EQUAL(OUString("text"), aHandler
.mPortionItems
[0].msItemType
);
2611 CPPUNIT_ASSERT_EQUAL(sal_Int32(25), aHandler
.mPortionItems
[0].mnLength
);
2612 CPPUNIT_ASSERT_EQUAL(PortionType::InputField
, aHandler
.mPortionItems
[0].mnTextType
);
2614 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), aHandler
.mPortionItems
[1].msItemType
);
2616 CPPUNIT_ASSERT_EQUAL(OUString("finish"), aHandler
.mPortionItems
[2].msItemType
);
2621 pTextFrame
= static_cast<SwTextFrame
*>(pTextFrame
->GetNext());
2622 pTextFrame
->VisitPortions(aHandler
);
2625 // Input Field - "ThisIsAllOneWord" = 18 chars
2626 CPPUNIT_ASSERT_EQUAL(OUString("text"), aHandler
.mPortionItems
[0].msItemType
);
2627 CPPUNIT_ASSERT_EQUAL(sal_Int32(18), aHandler
.mPortionItems
[0].mnLength
);
2628 CPPUNIT_ASSERT_EQUAL(PortionType::InputField
, aHandler
.mPortionItems
[0].mnTextType
);
2630 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), aHandler
.mPortionItems
[1].msItemType
);
2632 CPPUNIT_ASSERT_EQUAL(OUString("finish"), aHandler
.mPortionItems
[2].msItemType
);
2637 // skip empty paragraph
2638 pTextFrame
= static_cast<SwTextFrame
*>(pTextFrame
->GetNext());
2640 pTextFrame
= static_cast<SwTextFrame
*>(pTextFrame
->GetNext());
2641 pTextFrame
->VisitPortions(aHandler
);
2644 // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
2646 auto& rPortionItem
= aHandler
.mPortionItems
[0];
2647 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2648 CPPUNIT_ASSERT_EQUAL(sal_Int32(91), rPortionItem
.mnLength
);
2649 CPPUNIT_ASSERT_EQUAL(PortionType::Text
, rPortionItem
.mnTextType
);
2652 rPortionItem
= aHandler
.mPortionItems
[1];
2653 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem
.msItemType
);
2655 // Input Field: "ThisIsAllOneWord" = 18 chars
2656 // which is 16 chars + 2 hidden chars (start & end input field) = 18 chars
2657 // If this is correct then the input field is in one piece
2658 rPortionItem
= aHandler
.mPortionItems
[2];
2659 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2660 CPPUNIT_ASSERT_EQUAL(sal_Int32(18), rPortionItem
.mnLength
);
2661 CPPUNIT_ASSERT_EQUAL(PortionType::InputField
, rPortionItem
.mnTextType
);
2664 rPortionItem
= aHandler
.mPortionItems
[3];
2665 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2666 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem
.mnLength
);
2667 CPPUNIT_ASSERT_EQUAL(PortionType::Text
, rPortionItem
.mnTextType
);
2670 rPortionItem
= aHandler
.mPortionItems
[4];
2671 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem
.msItemType
);
2673 rPortionItem
= aHandler
.mPortionItems
[5];
2674 CPPUNIT_ASSERT_EQUAL(OUString("finish"), rPortionItem
.msItemType
);
2679 pTextFrame
= static_cast<SwTextFrame
*>(pTextFrame
->GetNext());
2680 pTextFrame
->VisitPortions(aHandler
);
2682 printf("Portions:\n");
2684 for (const auto& rPortionItem
: aHandler
.mPortionItems
)
2686 printf("-- Type: %s length: %" SAL_PRIdINT32
" text type: %d\n",
2687 rPortionItem
.msItemType
.toUtf8().getStr(), rPortionItem
.mnLength
,
2688 sal_uInt16(rPortionItem
.mnTextType
));
2691 // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
2693 auto& rPortionItem
= aHandler
.mPortionItems
[0];
2694 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2695 CPPUNIT_ASSERT_EQUAL(sal_Int32(91), rPortionItem
.mnLength
);
2696 CPPUNIT_ASSERT_EQUAL(PortionType::Text
, rPortionItem
.mnTextType
);
2698 // The input field here has more words ("One Two Three Four Five")
2699 // and it should break after "Two".
2700 // Input Field: "One Two" = 7 chars + 1 start input field hidden character = 8 chars
2701 rPortionItem
= aHandler
.mPortionItems
[1];
2702 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2703 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), rPortionItem
.mnLength
);
2704 CPPUNIT_ASSERT_EQUAL(PortionType::InputField
, rPortionItem
.mnTextType
);
2706 rPortionItem
= aHandler
.mPortionItems
[2];
2707 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2708 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem
.mnLength
);
2709 CPPUNIT_ASSERT_EQUAL(PortionType::Hole
, rPortionItem
.mnTextType
);
2712 rPortionItem
= aHandler
.mPortionItems
[3];
2713 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem
.msItemType
);
2715 // Input Field: "Three Four Five" = 16 chars + 1 end input field hidden character = 16 chars
2716 rPortionItem
= aHandler
.mPortionItems
[4];
2717 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2718 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rPortionItem
.mnLength
);
2719 CPPUNIT_ASSERT_EQUAL(PortionType::InputField
, rPortionItem
.mnTextType
);
2722 rPortionItem
= aHandler
.mPortionItems
[5];
2723 CPPUNIT_ASSERT_EQUAL(OUString("text"), rPortionItem
.msItemType
);
2724 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem
.mnLength
);
2725 CPPUNIT_ASSERT_EQUAL(PortionType::Text
, rPortionItem
.mnTextType
);
2728 rPortionItem
= aHandler
.mPortionItems
[6];
2729 CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem
.msItemType
);
2731 rPortionItem
= aHandler
.mPortionItems
[7];
2732 CPPUNIT_ASSERT_EQUAL(OUString("finish"), rPortionItem
.msItemType
);
2737 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf92648
)
2739 createSwDoc("tdf92648.docx");
2740 SwDoc
* pDoc
= getSwDoc();
2741 SdrPage
* pPage
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2742 // Make sure we have ten draw shapes.
2743 // Yes, we have if the left/right pages have different header/footer,
2744 // but if not we have only nine of them:
2745 CPPUNIT_ASSERT_EQUAL(sal_Int32(9), SwTextBoxHelper::getCount(pPage
));
2746 // and the text boxes haven't got zero height
2747 sal_Int32 nCount
= 0;
2748 for (const SwFrameFormat
* pFormat
: *pDoc
->GetSpzFrameFormats())
2750 if (!SwTextBoxHelper::isTextBox(pFormat
, RES_FLYFRMFMT
))
2752 SwFormatFrameSize
aSize(pFormat
->GetFrameSize());
2753 CPPUNIT_ASSERT(aSize
.GetHeight() != 0);
2756 // and we have had five of them.
2757 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nCount
);
2760 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf103978_backgroundTextShape
)
2762 createSwDoc("tdf103978_backgroundTextShape.docx");
2763 SwDoc
* pDoc
= getSwDoc();
2765 // there is only one shape. It has an attached textbox
2766 bool bShapeIsOpaque
= getProperty
<bool>(getShape(1), "Opaque");
2767 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in the foreground", false, bShapeIsOpaque
);
2768 sal_Int32 nCount
= 0;
2769 for (const SwFrameFormat
* pFormat
: *pDoc
->GetSpzFrameFormats())
2771 if (!SwTextBoxHelper::isTextBox(pFormat
, RES_FLYFRMFMT
))
2773 CPPUNIT_ASSERT_EQUAL_MESSAGE("Textbox syncs the shape's transparency", bShapeIsOpaque
,
2774 pFormat
->GetOpaque().GetValue());
2777 //ensure that we don't skip the for loop without an error
2778 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of TextBoxes", sal_Int32(1), nCount
);
2781 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf117225
)
2783 // Test that saving a document with an embedded object does not leak
2784 // tempfiles in the directory of the target file.
2785 OUString aTargetDirectory
2786 = m_directories
.getURLFromWorkdir(u
"/CppunitTest/sw_uiwriter7.test.user/");
2787 OUString aTargetFile
= aTargetDirectory
+ "tdf117225.odt";
2788 OUString aSourceFile
= createFileURL(u
"tdf117225.odt");
2789 osl::File::copy(aSourceFile
, aTargetFile
);
2790 mxComponent
= loadFromDesktop(aTargetFile
);
2791 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
2792 int nExpected
= CountFilesInDirectory(aTargetDirectory
);
2794 int nActual
= CountFilesInDirectory(aTargetDirectory
);
2795 // nActual was nExpected + 1, i.e. we leaked a tempfile.
2796 CPPUNIT_ASSERT_EQUAL(nExpected
, nActual
);
2798 OUString aTargetFileSaveAs
= aTargetDirectory
+ "tdf117225-save-as.odt";
2799 xStorable
->storeAsURL(aTargetFileSaveAs
, {});
2801 nActual
= CountFilesInDirectory(aTargetDirectory
);
2802 // nActual was nExpected + 1, i.e. we leaked a tempfile.
2803 CPPUNIT_ASSERT_EQUAL(nExpected
, nActual
);
2806 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf149184
)
2808 createSwDoc("simplefooter.docx");
2809 SwDoc
* pDoc
= getSwDoc();
2810 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
2812 // Removing the footer for all styles
2813 pWrtShell
->ChangeHeaderOrFooter(u
"", false, false, false);
2815 // export to simplefooter.doc
2817 // Without the fix in place, the test fails with:
2818 // [CUT] sw_uiwriter7
2819 // Segmentation fault (core dumped)
2820 // [_RUN_____] testTdf149184::TestBody
2824 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7
, testTdf149089
)
2826 createSwDoc("tdf149089.odt");
2827 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
2828 sal_Int32 nPorLen1
= getXPath(pXmlDoc
, "(//SwLinePortion)[1]", "length").toInt32();
2829 sal_Int32 nPorLen2
= getXPath(pXmlDoc
, "(//SwLinePortion)[2]", "length").toInt32();
2830 sal_Int32 nPorLen3
= getXPath(pXmlDoc
, "(//SwLinePortion)[3]", "length").toInt32();
2831 // Two SwTextPortion and one SwKernPortion
2832 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), nPorLen1
); // SwTextPortion "一一 "
2833 CPPUNIT_ASSERT_EQUAL(sal_Int32(12), nPorLen2
); // SwTextPortion "BUG 11111111"
2834 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nPorLen3
); // SwKernPortion
2836 sal_Int32 nPorWidth1
= getXPath(pXmlDoc
, "(//SwLinePortion)[1]", "width").toInt32();
2837 sal_Int32 nPorWidth2
= getXPath(pXmlDoc
, "(//SwLinePortion)[2]", "width").toInt32();
2838 sal_Int32 nPorWidth3
= getXPath(pXmlDoc
, "(//SwLinePortion)[3]", "width").toInt32();
2839 sal_Int32 nGridWidth1
= nPorWidth1
/ 3;
2840 sal_Int32 nGridWidth2
= (nPorWidth2
+ nPorWidth3
) / 7;
2841 CPPUNIT_ASSERT_EQUAL(nGridWidth1
, nGridWidth2
);
2844 CPPUNIT_PLUGIN_IMPLEMENT();
2846 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */