tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sw / qa / extras / uiwriter / uiwriter7.cxx
blob909d31d7024961814b0e620898ffa17b068891fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <com/sun/star/awt/FontWeight.hpp>
11 #include <swmodeltestbase.hxx>
12 #include <itabenum.hxx>
13 #include <ndtxt.hxx>
14 #include <wrtsh.hxx>
15 #include <expfld.hxx>
16 #include <drawdoc.hxx>
17 #include <view.hxx>
18 #include <swacorr.hxx>
19 #include <swmodule.hxx>
20 #include <charatr.hxx>
21 #include <editeng/acorrcfg.hxx>
22 #include <unotbl.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>
33 #include <txtftn.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>
40 #include <textsh.hxx>
41 #include <frmatr.hxx>
42 #include <frmmgr.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>
59 #include <txtfrm.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>
74 #include <vcl/idletask.hxx>
76 namespace
78 int CountFilesInDirectory(const OUString& rURL)
80 int nRet = 0;
82 osl::Directory aDir(rURL);
83 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aDir.open());
85 osl::DirectoryItem aItem;
86 osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL | osl_FileStatus_Mask_Type);
87 while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
89 aItem.getFileStatus(aFileStatus);
90 if (aFileStatus.getFileType() != osl::FileStatus::Directory)
91 ++nRet;
94 return nRet;
97 } //namespace
99 class SwUiWriterTest7 : public SwModelTestBase
101 public:
102 SwUiWriterTest7()
103 : SwModelTestBase(u"/sw/qa/extras/uiwriter/data/"_ustr)
108 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testExportToPicture)
110 createSwDoc();
111 uno::Sequence<beans::PropertyValue> aFilterData(
112 comphelper::InitPropertySequence({ { "PixelWidth", uno::Any(sal_Int32(610)) },
113 { "PixelHeight", uno::Any(sal_Int32(610)) } }));
114 uno::Sequence<beans::PropertyValue> aDescriptor(
115 comphelper::InitPropertySequence({ { "FilterName", uno::Any(u"writer_png_Export"_ustr) },
116 { "FilterData", uno::Any(aFilterData) } }));
117 uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
118 xStorable->storeToURL(maTempFile.GetURL(), aDescriptor);
119 bool extchk = maTempFile.IsValid();
120 CPPUNIT_ASSERT_EQUAL(true, extchk);
121 osl::File tmpFile(maTempFile.GetURL());
122 tmpFile.open(sal_uInt32(osl_File_OpenFlag_Read));
123 sal_uInt64 val;
124 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, tmpFile.getSize(val));
125 CPPUNIT_ASSERT(val > 100);
128 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf77340)
130 createSwDoc();
131 //Getting some paragraph style in our document
132 uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
133 uno::Reference<style::XStyle> xStyle(
134 xFactory->createInstance(u"com.sun.star.style.ParagraphStyle"_ustr), uno::UNO_QUERY);
135 uno::Reference<beans::XPropertySet> xPropSet(xStyle, uno::UNO_QUERY_THROW);
136 xPropSet->setPropertyValue(u"ParaBackColor"_ustr, uno::Any(sal_Int32(0xFF00FF)));
137 uno::Reference<style::XStyleFamiliesSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
138 uno::Reference<container::XNameAccess> xNameAccess(xSupplier->getStyleFamilies());
139 uno::Reference<container::XNameContainer> xNameCont;
140 xNameAccess->getByName(u"ParagraphStyles"_ustr) >>= xNameCont;
141 xNameCont->insertByName(u"myStyle"_ustr, uno::Any(xStyle));
142 CPPUNIT_ASSERT_EQUAL(u"myStyle"_ustr, xStyle->getName());
143 //Setting the properties with proper values
144 xPropSet->setPropertyValue(u"PageDescName"_ustr, uno::Any(u"First Page"_ustr));
145 xPropSet->setPropertyValue(u"PageNumberOffset"_ustr, uno::Any(sal_Int16(3)));
146 //Getting the properties and checking that they have proper values
147 CPPUNIT_ASSERT_EQUAL(uno::Any(u"First Page"_ustr),
148 xPropSet->getPropertyValue(u"PageDescName"_ustr));
149 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(3)),
150 xPropSet->getPropertyValue(u"PageNumberOffset"_ustr));
153 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf79236)
155 createSwDoc();
156 SwDoc* pDoc = getSwDoc();
157 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
158 //Getting some paragraph style
159 SwTextFormatColl* pTextFormat = pDoc->FindTextFormatCollByName(u"Body Text"_ustr);
160 const SwAttrSet& rAttrSet = pTextFormat->GetAttrSet();
161 std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
162 sal_uInt16 initialCount = pNewSet->Count();
163 SvxAdjustItem AdjustItem = rAttrSet.GetAdjust();
164 SvxAdjust initialAdjust = AdjustItem.GetAdjust();
165 //By default the adjust is LEFT
166 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left, initialAdjust);
167 //Changing the adjust to RIGHT
168 AdjustItem.SetAdjust(SvxAdjust::Right);
169 //Checking whether the change is made or not
170 SvxAdjust modifiedAdjust = AdjustItem.GetAdjust();
171 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right, modifiedAdjust);
172 //Modifying the itemset, putting *one* item
173 pNewSet->Put(AdjustItem);
174 //The count should increment by 1
175 sal_uInt16 modifiedCount = pNewSet->Count();
176 CPPUNIT_ASSERT_EQUAL(sal_uInt16(initialCount + 1), modifiedCount);
177 //Setting the updated item set on the style
178 pDoc->ChgFormat(*pTextFormat, *pNewSet);
179 //Checking the Changes
180 SwTextFormatColl* pTextFormat2 = pDoc->FindTextFormatCollByName(u"Body Text"_ustr);
181 const SwAttrSet& rAttrSet2 = pTextFormat2->GetAttrSet();
182 const SvxAdjustItem& rAdjustItem2 = rAttrSet2.GetAdjust();
183 SvxAdjust Adjust2 = rAdjustItem2.GetAdjust();
184 //The adjust should be RIGHT as per the modifications made
185 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right, Adjust2);
186 //Undo the changes
187 rUndoManager.Undo();
188 SwTextFormatColl* pTextFormat3 = pDoc->FindTextFormatCollByName(u"Body Text"_ustr);
189 const SwAttrSet& rAttrSet3 = pTextFormat3->GetAttrSet();
190 const SvxAdjustItem& rAdjustItem3 = rAttrSet3.GetAdjust();
191 SvxAdjust Adjust3 = rAdjustItem3.GetAdjust();
192 //The adjust should be back to default, LEFT
193 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left, Adjust3);
194 //Redo the changes
195 rUndoManager.Redo();
196 SwTextFormatColl* pTextFormat4 = pDoc->FindTextFormatCollByName(u"Body Text"_ustr);
197 const SwAttrSet& rAttrSet4 = pTextFormat4->GetAttrSet();
198 const SvxAdjustItem& rAdjustItem4 = rAttrSet4.GetAdjust();
199 SvxAdjust Adjust4 = rAdjustItem4.GetAdjust();
200 //The adjust should be RIGHT as per the modifications made
201 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right, Adjust4);
202 //Undo the changes
203 rUndoManager.Undo();
204 SwTextFormatColl* pTextFormat5 = pDoc->FindTextFormatCollByName(u"Body Text"_ustr);
205 const SwAttrSet& rAttrSet5 = pTextFormat5->GetAttrSet();
206 const SvxAdjustItem& rAdjustItem5 = rAttrSet5.GetAdjust();
207 SvxAdjust Adjust5 = rAdjustItem5.GetAdjust();
208 //The adjust should be back to default, LEFT
209 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Left, Adjust5);
212 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTextSearch)
214 // Create a new empty Writer document
215 createSwDoc();
216 SwDoc* pDoc = getSwDoc();
217 SwCursorShell* pShell(pDoc->GetEditShell());
218 CPPUNIT_ASSERT(pShell);
219 SwPaM* pCursor = pShell->GetCursor();
220 IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
221 // Insert some text
222 rIDCO.InsertString(*pCursor, u"Hello World This is a test"_ustr);
223 // Use cursor to select part of text
224 for (int i = 0; i < 10; i++)
226 pCursor->Move(fnMoveBackward);
228 pCursor->SetMark();
229 for (int i = 0; i < 4; i++)
231 pCursor->Move(fnMoveBackward);
233 //Checking that the proper selection is made
234 CPPUNIT_ASSERT_EQUAL(u"This"_ustr, pCursor->GetText());
235 // Apply a "Bold" attribute to selection
236 SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
237 rIDCO.InsertPoolItem(*pCursor, aWeightItem);
238 //making another selection of text
239 for (int i = 0; i < 7; i++)
241 pCursor->Move(fnMoveBackward);
243 pCursor->SetMark();
244 for (int i = 0; i < 5; i++)
246 pCursor->Move(fnMoveBackward);
248 //Checking that the proper selection is made
249 CPPUNIT_ASSERT_EQUAL(u"Hello"_ustr, pCursor->GetText());
250 // Apply a "Bold" attribute to selection
251 rIDCO.InsertPoolItem(*pCursor, aWeightItem);
252 //Performing Search Operation and also covering the UNO coverage for setProperty
253 uno::Reference<util::XSearchable> xSearch(mxComponent, uno::UNO_QUERY);
254 uno::Reference<util::XSearchDescriptor> xSearchDes = xSearch->createSearchDescriptor();
255 uno::Reference<util::XPropertyReplace> xProp(xSearchDes, uno::UNO_QUERY);
256 //setting some properties
257 uno::Sequence<beans::PropertyValue> aDescriptor(comphelper::InitPropertySequence(
258 { { "CharWeight", uno::Any(float(css::awt::FontWeight::BOLD)) } }));
259 xProp->setSearchAttributes(aDescriptor);
260 //receiving the defined properties and asserting them with expected values, covering UNO
261 uno::Sequence<beans::PropertyValue> aPropVal2(xProp->getSearchAttributes());
262 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aPropVal2.getLength());
263 CPPUNIT_ASSERT_EQUAL(u"CharWeight"_ustr, aPropVal2[0].Name);
264 CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD)), aPropVal2[0].Value);
265 //specifying the search attributes
266 uno::Reference<beans::XPropertySet> xPropSet(xSearchDes, uno::UNO_QUERY_THROW);
267 xPropSet->setPropertyValue(u"SearchWords"_ustr, uno::Any(true));
268 xPropSet->setPropertyValue(u"SearchCaseSensitive"_ustr, uno::Any(true));
269 //this will search all the BOLD words
270 uno::Reference<container::XIndexAccess> xIndex(xSearch->findAll(xSearchDes));
271 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndex->getCount());
272 //Replacing the searched string via XReplaceable
273 uno::Reference<util::XReplaceable> xReplace(mxComponent, uno::UNO_QUERY);
274 uno::Reference<util::XReplaceDescriptor> xReplaceDes = xReplace->createReplaceDescriptor();
275 uno::Reference<util::XPropertyReplace> xProp2(xReplaceDes, uno::UNO_QUERY);
276 xProp2->setReplaceAttributes(aDescriptor);
277 //checking that the proper attributes are there or not
278 uno::Sequence<beans::PropertyValue> aRepProp(xProp2->getReplaceAttributes());
279 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRepProp.getLength());
280 CPPUNIT_ASSERT_EQUAL(u"CharWeight"_ustr, aRepProp[0].Name);
281 CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD)), aRepProp[0].Value);
282 //setting strings for replacement
283 xReplaceDes->setSearchString(u"test"_ustr);
284 xReplaceDes->setReplaceString(u"task"_ustr);
285 //checking the replaceString
286 CPPUNIT_ASSERT_EQUAL(u"task"_ustr, xReplaceDes->getReplaceString());
287 //this will replace *normal*test to *bold*task
288 sal_Int32 ReplaceCount = xReplace->replaceAll(xReplaceDes);
289 //There should be only 1 replacement since there is only one occurrence of "test" in the document
290 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
291 //Now performing search again for BOLD words, count should be 3 due to replacement
292 uno::Reference<container::XIndexAccess> xIndex2(xReplace->findAll(xSearchDes));
293 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndex2->getCount());
294 // regex tests
295 xSearchDes->setPropertyValue(u"SearchRegularExpression"_ustr, uno::Any(true));
296 // regex: test correct matching combined with attributes like BOLD
297 xSearchDes->setSearchString(u".*"_ustr); // should match all bold words in the text
298 xIndex.set(xReplace->findAll(xSearchDes), uno::UNO_SET_THROW);
299 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndex->getCount());
300 uno::Reference<text::XTextRange> xFound(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
301 CPPUNIT_ASSERT_EQUAL(u"Hello"_ustr, xFound->getString());
302 xFound.set(xIndex->getByIndex(1), uno::UNO_QUERY_THROW);
303 CPPUNIT_ASSERT_EQUAL(u"This"_ustr, xFound->getString());
304 xFound.set(xIndex->getByIndex(2), uno::UNO_QUERY_THROW);
305 CPPUNIT_ASSERT_EQUAL(u"task"_ustr, xFound->getString());
306 // regex: test anchor combined with attributes like BOLD
307 xSearchDes->setSearchString(
308 u"^.*|.*$"_ustr); // should match first and last words (they are bold)
309 xIndex.set(xReplace->findAll(xSearchDes), uno::UNO_SET_THROW);
310 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndex->getCount());
311 xFound.set(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
312 CPPUNIT_ASSERT_EQUAL(u"Hello"_ustr, xFound->getString());
313 xFound.set(xIndex->getByIndex(1), uno::UNO_QUERY_THROW);
314 CPPUNIT_ASSERT_EQUAL(u"task"_ustr, xFound->getString());
315 // regex: test look-ahead/look-behind assertions outside of the bold text
316 xSearchDes->setSearchString(u"(?<= ).*(?= )"_ustr); // should match second bold word
317 xIndex.set(xReplace->findAll(xSearchDes), uno::UNO_SET_THROW);
318 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex->getCount());
319 xFound.set(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
320 CPPUNIT_ASSERT_EQUAL(u"This"_ustr, xFound->getString());
321 xReplaceDes->setPropertyValue(u"SearchRegularExpression"_ustr, uno::Any(true));
322 // regex: test correct match of paragraph start
323 xReplaceDes->setSearchString(u"^."_ustr); // should only match first character of the paragraph
324 xReplaceDes->setReplaceString(u"C"_ustr);
325 ReplaceCount = xReplace->replaceAll(xReplaceDes);
326 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
327 // regex: test correct match of word start
328 xReplaceDes->setSearchString(u"\\b\\w"_ustr); // should match all words' first characters
329 xReplaceDes->setReplaceString(u"x&"_ustr);
330 ReplaceCount = xReplace->replaceAll(xReplaceDes);
331 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ReplaceCount);
332 // regex: test negative look-behind assertion
333 xReplaceDes->setSearchString(u"(?<!xCelly xW)o"_ustr); // only "o" in "xCello", not in "xWorld"
334 xReplaceDes->setReplaceString(u"y"_ustr);
335 ReplaceCount = xReplace->replaceAll(xReplaceDes);
336 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
337 // regex: test positive look-behind assertion
338 xReplaceDes->setSearchString(
339 u"(?<=xCelly xWorld xTh)i"_ustr); // only "i" in "xThis", not in "xis"
340 xReplaceDes->setReplaceString(u"z"_ustr);
341 ReplaceCount = xReplace->replaceAll(xReplaceDes);
342 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
343 // regex: use capturing group to test reference
344 xReplaceDes->setSearchString(u"\\b(\\w\\w\\w\\w)\\w"_ustr);
345 xReplaceDes->setReplaceString(u"$1q"_ustr); // only fifth characters in words should change
346 ReplaceCount = xReplace->replaceAll(xReplaceDes);
347 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), ReplaceCount);
348 // check of the end result
349 CPPUNIT_ASSERT_EQUAL(u"xCelqy xWorqd xThzq xis xa xtasq"_ustr,
350 pCursor->GetPointNode().GetTextNode()->GetText());
351 // regex: use positive look-ahead assertion
352 xReplaceDes->setSearchString(u"Wor(?=qd xThzq xis xa xtasq)"_ustr);
353 xReplaceDes->setReplaceString(u"&p"_ustr); // testing & reference
354 ReplaceCount = xReplace->replaceAll(xReplaceDes);
355 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ReplaceCount);
356 // regex: use negative look-ahead assertion
357 xReplaceDes->setSearchString(u"x(?!Worpqd xThzq xis xa xtasq)"_ustr);
358 xReplaceDes->setReplaceString(u"m"_ustr);
359 ReplaceCount = xReplace->replaceAll(xReplaceDes);
360 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ReplaceCount); // one of the 6 "x" must not be replaced
361 // check of the end result
362 CPPUNIT_ASSERT_EQUAL(u"mCelqy xWorpqd mThzq mis ma mtasq"_ustr,
363 pCursor->GetPointNode().GetTextNode()->GetText());
366 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf147583_backwardSearch)
368 createSwDoc("tdf147583_backwardSearch.odt");
369 uno::Reference<util::XSearchable> xSearch(mxComponent, uno::UNO_QUERY);
370 uno::Reference<util::XSearchDescriptor> xSearchDes = xSearch->createSearchDescriptor();
372 uno::Reference<container::XIndexAccess> xIndex;
373 const sal_Int32 nParas = getParagraphs();
375 //specifying the search attributes
376 uno::Reference<beans::XPropertySet> xPropSet(xSearchDes, uno::UNO_QUERY_THROW);
377 xSearchDes->setPropertyValue(u"SearchRegularExpression"_ustr, uno::Any(true)); // regex
378 xSearchDes->setSearchString(u"$"_ustr); // the end of the paragraph pilcrow marker
380 // xSearchDes->setPropertyValue("SearchBackwards", uno::Any(false));
381 // xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
382 // // all paragraphs (including the unselected last one) should be found
383 // CPPUNIT_ASSERT_EQUAL(nParas, xIndex->getCount());
385 xSearchDes->setPropertyValue(u"SearchBackwards"_ustr, uno::Any(true));
386 xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
387 // all paragraphs (except the troublesome last one) are found
388 CPPUNIT_ASSERT_EQUAL(nParas - 1, xIndex->getCount());
390 xSearchDes->setSearchString(u"^$"_ustr); // empty paragraphs
391 xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
392 // should actually be 10 (including the empty para with the comment marker, and the last para)
393 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xIndex->getCount());
395 xSearchDes->setSearchString(
396 u".$"_ustr); // any last character (not just full-stops) in a paragraph
397 xIndex.set(xSearch->findAll(xSearchDes), uno::UNO_SET_THROW);
398 // should be one for every non-empty paragraph
399 CPPUNIT_ASSERT_EQUAL(sal_Int32(14), xIndex->getCount());
402 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf69282)
404 createSwDoc();
405 SwDoc* source = getSwDoc();
406 uno::Reference<lang::XComponent> xSourceDoc = mxComponent;
407 mxComponent.clear();
408 createSwDoc();
409 SwDoc* target = getSwDoc();
410 SwPageDesc* sPageDesc = source->MakePageDesc(u"SourceStyle"_ustr);
411 SwPageDesc* tPageDesc = target->MakePageDesc(u"TargetStyle"_ustr);
412 sPageDesc->ChgFirstShare(false);
413 CPPUNIT_ASSERT(!sPageDesc->IsFirstShared());
414 SwFrameFormat& rSourceMasterFormat = sPageDesc->GetMaster();
415 //Setting horizontal spaces on master
416 SvxLRSpaceItem horizontalSpace(RES_LR_SPACE);
417 horizontalSpace.SetLeft(SvxIndentValue::twips(11));
418 horizontalSpace.SetRight(SvxIndentValue::twips(12));
419 rSourceMasterFormat.SetFormatAttr(horizontalSpace);
420 //Setting vertical spaces on master
421 SvxULSpaceItem verticalSpace(RES_UL_SPACE);
422 verticalSpace.SetUpper(13);
423 verticalSpace.SetLower(14);
424 rSourceMasterFormat.SetFormatAttr(verticalSpace);
425 //Changing the style and copying it to target
426 source->ChgPageDesc(u"SourceStyle"_ustr, *sPageDesc);
427 target->CopyPageDesc(*sPageDesc, *tPageDesc);
428 //Checking the set values on all Formats in target
429 SwFrameFormat& rTargetMasterFormat = tPageDesc->GetMaster();
430 SwFrameFormat& rTargetLeftFormat = tPageDesc->GetLeft();
431 SwFrameFormat& rTargetFirstMasterFormat = tPageDesc->GetFirstMaster();
432 SwFrameFormat& rTargetFirstLeftFormat = tPageDesc->GetFirstLeft();
433 //Checking horizontal spaces
434 const SvxLRSpaceItem MasterLRSpace = rTargetMasterFormat.GetLRSpace();
435 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), MasterLRSpace.ResolveLeft({}));
436 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), MasterLRSpace.ResolveRight({}));
437 const SvxLRSpaceItem LeftLRSpace = rTargetLeftFormat.GetLRSpace();
438 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), LeftLRSpace.ResolveLeft({}));
439 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), LeftLRSpace.ResolveRight({}));
440 const SvxLRSpaceItem FirstMasterLRSpace = rTargetFirstMasterFormat.GetLRSpace();
441 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), FirstMasterLRSpace.ResolveLeft({}));
442 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), FirstMasterLRSpace.ResolveRight({}));
443 const SvxLRSpaceItem FirstLeftLRSpace = rTargetFirstLeftFormat.GetLRSpace();
444 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), FirstLeftLRSpace.ResolveLeft({}));
445 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), FirstLeftLRSpace.ResolveRight({}));
446 //Checking vertical spaces
447 const SvxULSpaceItem MasterULSpace = rTargetMasterFormat.GetULSpace();
448 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), MasterULSpace.GetUpper());
449 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), MasterULSpace.GetLower());
450 const SvxULSpaceItem LeftULSpace = rTargetLeftFormat.GetULSpace();
451 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), LeftULSpace.GetUpper());
452 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), LeftULSpace.GetLower());
453 const SvxULSpaceItem FirstMasterULSpace = rTargetFirstMasterFormat.GetULSpace();
454 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), FirstMasterULSpace.GetUpper());
455 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), FirstMasterULSpace.GetLower());
456 const SvxULSpaceItem FirstLeftULSpace = rTargetFirstLeftFormat.GetULSpace();
457 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), FirstLeftULSpace.GetUpper());
458 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), FirstLeftULSpace.GetLower());
459 xSourceDoc->dispose();
462 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf69282WithMirror)
464 createSwDoc();
465 SwDoc* source = getSwDoc();
466 uno::Reference<lang::XComponent> xSourceDoc = mxComponent;
467 mxComponent.clear();
468 createSwDoc();
469 SwDoc* target = getSwDoc();
470 SwPageDesc* sPageDesc = source->MakePageDesc(u"SourceStyle"_ustr);
471 SwPageDesc* tPageDesc = target->MakePageDesc(u"TargetStyle"_ustr);
472 //Enabling Mirror
473 sPageDesc->SetUseOn(UseOnPage::Mirror);
474 SwFrameFormat& rSourceMasterFormat = sPageDesc->GetMaster();
475 //Setting horizontal spaces on master
476 SvxLRSpaceItem horizontalSpace(RES_LR_SPACE);
477 horizontalSpace.SetLeft(SvxIndentValue::twips(11));
478 horizontalSpace.SetRight(SvxIndentValue::twips(12));
479 rSourceMasterFormat.SetFormatAttr(horizontalSpace);
480 //Setting vertical spaces on master
481 SvxULSpaceItem verticalSpace(RES_UL_SPACE);
482 verticalSpace.SetUpper(13);
483 verticalSpace.SetLower(14);
484 rSourceMasterFormat.SetFormatAttr(verticalSpace);
485 //Changing the style and copying it to target
486 source->ChgPageDesc(u"SourceStyle"_ustr, *sPageDesc);
487 target->CopyPageDesc(*sPageDesc, *tPageDesc);
488 //Checking the set values on all Formats in target
489 SwFrameFormat& rTargetMasterFormat = tPageDesc->GetMaster();
490 SwFrameFormat& rTargetLeftFormat = tPageDesc->GetLeft();
491 SwFrameFormat& rTargetFirstMasterFormat = tPageDesc->GetFirstMaster();
492 SwFrameFormat& rTargetFirstLeftFormat = tPageDesc->GetFirstLeft();
493 //Checking horizontal spaces
494 const SvxLRSpaceItem MasterLRSpace = rTargetMasterFormat.GetLRSpace();
495 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), MasterLRSpace.ResolveLeft({}));
496 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), MasterLRSpace.ResolveRight({}));
497 //mirror effect should be present
498 const SvxLRSpaceItem LeftLRSpace = rTargetLeftFormat.GetLRSpace();
499 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), LeftLRSpace.ResolveLeft({}));
500 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), LeftLRSpace.ResolveRight({}));
501 const SvxLRSpaceItem FirstMasterLRSpace = rTargetFirstMasterFormat.GetLRSpace();
502 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), FirstMasterLRSpace.ResolveLeft({}));
503 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), FirstMasterLRSpace.ResolveRight({}));
504 //mirror effect should be present
505 const SvxLRSpaceItem FirstLeftLRSpace = rTargetFirstLeftFormat.GetLRSpace();
506 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveRight({}), FirstLeftLRSpace.ResolveLeft({}));
507 CPPUNIT_ASSERT_EQUAL(horizontalSpace.ResolveLeft({}), FirstLeftLRSpace.ResolveRight({}));
508 //Checking vertical spaces
509 const SvxULSpaceItem MasterULSpace = rTargetMasterFormat.GetULSpace();
510 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), MasterULSpace.GetUpper());
511 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), MasterULSpace.GetLower());
512 const SvxULSpaceItem LeftULSpace = rTargetLeftFormat.GetULSpace();
513 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), LeftULSpace.GetUpper());
514 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), LeftULSpace.GetLower());
515 const SvxULSpaceItem FirstMasterULSpace = rTargetFirstMasterFormat.GetULSpace();
516 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), FirstMasterULSpace.GetUpper());
517 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), FirstMasterULSpace.GetLower());
518 const SvxULSpaceItem FirstLeftULSpace = rTargetFirstLeftFormat.GetULSpace();
519 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetUpper(), FirstLeftULSpace.GetUpper());
520 CPPUNIT_ASSERT_EQUAL(verticalSpace.GetLower(), FirstLeftULSpace.GetLower());
521 xSourceDoc->dispose();
524 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf78742)
526 //testing with service type and any .ods file
527 OUString path = createFileURL(u"calc-data-source.ods");
528 SfxMedium aMedium(path, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
529 SfxFilterMatcher aMatcher(u"com.sun.star.text.TextDocument"_ustr);
530 std::shared_ptr<const SfxFilter> pFilter;
531 ErrCode filter = aMatcher.DetectFilter(aMedium, pFilter);
532 CPPUNIT_ASSERT_EQUAL(ERRCODE_IO_ABORT, filter);
533 //it should not return any Filter
534 CPPUNIT_ASSERT(!pFilter);
535 //testing without service type and any .ods file
536 SfxMedium aMedium2(path, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
537 SfxFilterMatcher aMatcher2;
538 std::shared_ptr<const SfxFilter> pFilter2;
539 ErrCode filter2 = aMatcher2.DetectFilter(aMedium2, pFilter2);
540 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, filter2);
541 //Filter should be returned with proper Name
542 CPPUNIT_ASSERT_EQUAL(u"calc8"_ustr, pFilter2->GetFilterName());
543 //testing with service type and any .odt file
544 OUString path2 = createFileURL(u"fdo69893.odt");
545 SfxMedium aMedium3(path2, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
546 SfxFilterMatcher aMatcher3(u"com.sun.star.text.TextDocument"_ustr);
547 std::shared_ptr<const SfxFilter> pFilter3;
548 ErrCode filter3 = aMatcher3.DetectFilter(aMedium3, pFilter3);
549 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, filter3);
550 //Filter should be returned with proper Name
551 CPPUNIT_ASSERT_EQUAL(u"writer8"_ustr, pFilter3->GetFilterName());
554 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUnoParagraph)
556 createSwDoc();
557 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
558 //Inserting some text content in the document
559 pWrtShell->Insert(u"This is initial text in paragraph one"_ustr);
560 pWrtShell->SplitNode();
561 //Inserting second paragraph
562 pWrtShell->Insert(u"This is initial text in paragraph two"_ustr);
563 //now testing the SwXParagraph
564 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
565 uno::Reference<text::XText> xText(xTextDocument->getText());
566 uno::Reference<container::XEnumerationAccess> xParaAccess(xText, uno::UNO_QUERY);
567 uno::Reference<container::XEnumeration> xPara(xParaAccess->createEnumeration());
568 //getting first paragraph
569 uno::Reference<text::XTextContent> xFirstParaContent(xPara->nextElement(), uno::UNO_QUERY);
570 uno::Reference<text::XTextRange> xFirstPara(xFirstParaContent, uno::UNO_QUERY);
571 //testing the initial text
572 CPPUNIT_ASSERT_EQUAL(u"This is initial text in paragraph one"_ustr, xFirstPara->getString());
573 //changing the text content in first paragraph
574 xFirstPara->setString(u"This is modified text in paragraph one"_ustr);
575 //testing the changes
576 CPPUNIT_ASSERT_EQUAL(u"This is modified text in paragraph one"_ustr, xFirstPara->getString());
577 //getting second paragraph
578 uno::Reference<text::XTextContent> xSecondParaContent(xPara->nextElement(), uno::UNO_QUERY);
579 uno::Reference<text::XTextRange> xSecondPara(xSecondParaContent, uno::UNO_QUERY);
580 //testing the initial text
581 CPPUNIT_ASSERT_EQUAL(u"This is initial text in paragraph two"_ustr, xSecondPara->getString());
582 //changing the text content in second paragraph
583 xSecondPara->setString(u"This is modified text in paragraph two"_ustr);
584 //testing the changes
585 CPPUNIT_ASSERT_EQUAL(u"This is modified text in paragraph two"_ustr, xSecondPara->getString());
588 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf72788)
590 //Create a new empty Writer document
591 createSwDoc();
592 SwDoc* pDoc = getSwDoc();
593 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
594 SwCursorShell* pShell(pDoc->GetEditShell());
595 CPPUNIT_ASSERT(pShell);
596 SwPaM* pCursor = pShell->GetCursor();
597 IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
598 //Insert some text - two paragraphs
599 rIDCO.InsertString(*pCursor, u"this is text"_ustr);
600 //Position of word 9876543210
601 //Position of word 0123456789
602 //Change Paragraph
603 pWrtShell->SplitNode();
604 //Insert second paragraph
605 rIDCO.InsertString(*pCursor, u"more text"_ustr);
606 //Position of word 012345678
607 //Make the following selection *bold*
608 //this[is text
609 //more] text
610 //Move cursor back
611 for (int i = 0; i < 5; i++)
613 pCursor->Move(fnMoveBackward);
615 //Start selection
616 pCursor->SetMark();
617 for (int i = 0; i < 12; i++)
619 pCursor->Move(fnMoveBackward);
621 //Check the text selection
622 CPPUNIT_ASSERT_EQUAL(OUString(u"is text" + OUStringChar(CH_TXTATR_NEWLINE) + u"more"),
623 pCursor->GetText());
624 //Apply a *Bold* attribute to selection
625 SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
626 rIDCO.InsertPoolItem(*pCursor, aWeightItem);
627 SfxItemSet aSet(pDoc->GetAttrPool(), svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>);
628 //Add selected text's attributes to aSet
629 pCursor->GetPointNode().GetTextNode()->GetParaAttr(aSet, 5, 12);
630 SfxPoolItem const* pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
631 //Check that bold is active on the selection and it's in aSet
632 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem == aWeightItem));
633 //Make selection to remove formatting in first paragraph
634 //[this is text
635 //]more text
636 pWrtShell->StartOfSection();
637 //Start selection
638 pCursor->SetMark();
639 for (int i = 0; i < 13; i++)
641 pCursor->Move(fnMoveForward);
643 //Clear all the Direct Formatting ( Ctrl + M )
644 SwTextNode* pTextNode = pCursor->GetPointNode().GetTextNode();
645 sal_Int32 nEnd = pTextNode->Len();
646 pTextNode->RstTextAttr(0, nEnd);
647 //In case of Regression RstTextAttr() call will result to infinite recursion
648 //Check that bold is removed in first paragraph
649 aSet.ClearItem();
650 pTextNode->GetParaAttr(aSet, 5, 12);
651 SfxPoolItem const* pPoolItem2 = aSet.GetItem(RES_CHRATR_WEIGHT);
652 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem2 != aWeightItem));
655 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf60967)
657 createSwDoc();
658 SwDoc* pDoc = getSwDoc();
659 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
660 SwCursorShell* pShell(pDoc->GetEditShell());
661 CPPUNIT_ASSERT(pShell);
662 SwPaM* pCursor = pShell->GetCursor();
663 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
664 pWrtShell->ChangeHeaderOrFooter(u"Default Page Style", true, true, true);
665 //Inserting table
666 SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
667 pWrtShell->InsertTable(TableOpt, 2, 2);
668 //getting the cursor's position just after the table insert
669 SwPosition aPosAfterTable(*(pCursor->GetPoint()));
670 //moving cursor to B2 (bottom right cell)
671 pCursor->Move(fnMoveBackward);
672 SwPosition aPosInTable(*(pCursor->GetPoint()));
673 //deleting paragraph following table with Ctrl+Shift+Del
674 bool val = pWrtShell->DelToEndOfSentence();
675 CPPUNIT_ASSERT_EQUAL(true, val);
676 //getting the cursor's position just after the paragraph deletion
677 SwPosition aPosAfterDel(*(pCursor->GetPoint()));
678 //moving cursor forward to check whether there is any node following the table, BTW there should not be any such node
679 pCursor->Move(fnMoveForward);
680 SwPosition aPosMoveAfterDel(*(pCursor->GetPoint()));
681 //checking the positions to verify that the paragraph is actually deleted
682 CPPUNIT_ASSERT_EQUAL(aPosAfterDel, aPosInTable);
683 CPPUNIT_ASSERT_EQUAL(aPosMoveAfterDel, aPosInTable);
684 //Undo the changes
685 rUndoManager.Undo();
687 //paragraph *text node* should be back
688 SwPosition aPosAfterUndo(*(pCursor->GetPoint()));
689 //after undo aPosAfterTable increases the node position by one, since this contains the position *text node* so aPosAfterUndo should be less than aPosAfterTable
690 CPPUNIT_ASSERT(aPosAfterTable > aPosAfterUndo);
691 //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
692 pCursor->Move(fnMoveForward);
693 SwPosition aPosMoveAfterUndo(*(pCursor->GetPoint()));
694 //checking positions to verify that paragraph node is the last one and we are paragraph node only
695 CPPUNIT_ASSERT(aPosAfterTable > aPosMoveAfterUndo);
696 CPPUNIT_ASSERT_EQUAL(aPosAfterUndo, aPosMoveAfterUndo);
698 //Redo the changes
699 rUndoManager.Redo();
700 //paragraph *text node* should not be there
701 SwPosition aPosAfterRedo(*(pCursor->GetPoint()));
702 //position should be exactly same as it was after deletion of *text node*
703 CPPUNIT_ASSERT_EQUAL(aPosAfterRedo, aPosMoveAfterDel);
704 //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
705 pCursor->Move(fnMoveForward);
706 SwPosition aPosAfterUndoMove(*(pCursor->GetPoint()));
707 CPPUNIT_ASSERT_EQUAL(aPosAfterRedo, aPosAfterUndoMove);
710 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testSearchWithTransliterate)
712 createSwDoc();
713 SwDoc* pDoc = getSwDoc();
714 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
716 SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
717 SwPaM aPaM(aIdx);
718 pDoc->getIDocumentContentOperations().InsertString(aPaM, u"This is paragraph one"_ustr);
719 pWrtShell->SplitNode();
722 SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
723 SwPaM aPaM(aIdx);
724 pDoc->getIDocumentContentOperations().InsertString(aPaM, u"This is Other PARAGRAPH"_ustr);
726 i18nutil::SearchOptions2 SearchOpt;
727 SearchOpt.searchFlag = css::util::SearchFlags::ALL_IGNORE_CASE;
728 SearchOpt.searchString = "other";
729 SearchOpt.replaceString.clear();
730 SearchOpt.changedChars = 0;
731 SearchOpt.deletedChars = 0;
732 SearchOpt.insertedChars = 0;
733 SearchOpt.transliterateFlags = TransliterationFlags::IGNORE_DIACRITICS_CTL;
734 SearchOpt.AlgorithmType2 = css::util::SearchAlgorithms2::ABSOLUTE;
735 SearchOpt.WildcardEscapeCharacter = 0;
736 //transliteration option set so that at least one of the search strings is not found
737 sal_Int32 case1
738 = pWrtShell->SearchPattern(SearchOpt, true, SwDocPositions::Start, SwDocPositions::End);
739 SwShellCursor* pShellCursor = pWrtShell->getShellCursor(true);
740 CPPUNIT_ASSERT_EQUAL(OUString(), pShellCursor->GetText());
741 CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(case1));
742 SearchOpt.searchString = "paragraph";
743 SearchOpt.transliterateFlags = TransliterationFlags::IGNORE_KASHIDA_CTL;
744 //transliteration option set so that all search strings are found
745 sal_Int32 case2
746 = pWrtShell->SearchPattern(SearchOpt, true, SwDocPositions::Start, SwDocPositions::End);
747 pShellCursor = pWrtShell->getShellCursor(true);
748 CPPUNIT_ASSERT_EQUAL(u"paragraph"_ustr, pShellCursor->GetText());
749 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(case2));
752 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf73660)
754 createSwDoc();
755 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
756 OUString aData1 = "First" + OUStringChar(CHAR_SOFTHYPHEN) + "Word";
757 OUString aData2 = "Seco" + OUStringChar(CHAR_SOFTHYPHEN) + "nd";
758 OUString aData3 = OUStringChar(CHAR_SOFTHYPHEN) + "Third";
759 OUString aData4 = "Fourth" + OUStringChar(CHAR_SOFTHYPHEN);
760 pWrtShell->Insert(
761 u"We are inserting some text in the document to check the search feature "_ustr);
762 pWrtShell->Insert(aData1 + " ");
763 pWrtShell->Insert(aData2 + " ");
764 pWrtShell->Insert(aData3 + " ");
765 pWrtShell->Insert(aData4 + " ");
766 pWrtShell->Insert(u"Fifth "_ustr);
767 pWrtShell->Insert(u"Now we have enough text let's test search for all the cases"_ustr);
768 //searching for all 5 strings entered with soft-hyphen, search string contains no soft-hyphen
769 i18nutil::SearchOptions2 searchOpt;
770 searchOpt.searchFlag = css::util::SearchFlags::NORM_WORD_ONLY;
771 searchOpt.AlgorithmType2 = css::util::SearchAlgorithms2::REGEXP;
772 //case 1
773 searchOpt.searchString = "First";
774 CPPUNIT_ASSERT_EQUAL(
775 sal_Int32(1),
776 pWrtShell->SearchPattern(searchOpt, true, SwDocPositions::Start, SwDocPositions::End));
777 //case 2
778 searchOpt.searchString = "Second";
779 CPPUNIT_ASSERT_EQUAL(
780 sal_Int32(1),
781 pWrtShell->SearchPattern(searchOpt, true, SwDocPositions::Start, SwDocPositions::End));
782 //case 3
783 searchOpt.searchString = "Third";
784 CPPUNIT_ASSERT_EQUAL(
785 sal_Int32(1),
786 pWrtShell->SearchPattern(searchOpt, true, SwDocPositions::Start, SwDocPositions::End));
787 //case 4
788 searchOpt.searchString = "Fourth";
789 CPPUNIT_ASSERT_EQUAL(
790 sal_Int32(1),
791 pWrtShell->SearchPattern(searchOpt, true, SwDocPositions::Start, SwDocPositions::End));
792 //case 5
793 searchOpt.searchString = "Fifth";
794 CPPUNIT_ASSERT_EQUAL(
795 sal_Int32(1),
796 pWrtShell->SearchPattern(searchOpt, true, SwDocPositions::Start, SwDocPositions::End));
799 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testNewDocModifiedState)
801 //creating a new doc
802 SwDoc* pDoc = new SwDoc();
803 //getting the state of the document via IDocumentState
804 IDocumentState& rState(pDoc->getIDocumentState());
805 //the state should not be modified, no modifications yet
806 CPPUNIT_ASSERT(!(rState.IsModified()));
809 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf77342)
811 createSwDoc();
812 SwDoc* pDoc = getSwDoc();
813 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
814 SwCursorShell* pShell(pDoc->GetEditShell());
815 CPPUNIT_ASSERT(pShell);
816 SwPaM* pCursor = pShell->GetCursor();
817 //inserting first footnote
818 pWrtShell->InsertFootnote(u""_ustr);
819 SwFieldType* pField = pWrtShell->GetFieldType(0, SwFieldIds::GetRef);
820 SwGetRefFieldType* pRefType = static_cast<SwGetRefFieldType*>(pField);
821 //moving cursor to the starting of document
822 pWrtShell->StartOfSection();
823 //inserting reference field 1
824 SwGetRefField aField1(pRefType, u""_ustr, u""_ustr, REF_FOOTNOTE, sal_uInt16(0), sal_uInt16(0),
825 REF_CONTENT);
826 pWrtShell->InsertField2(aField1);
827 //inserting second footnote
828 pWrtShell->InsertFootnote(u""_ustr);
829 pWrtShell->StartOfSection();
830 pCursor->Move(fnMoveForward);
831 //inserting reference field 2
832 SwGetRefField aField2(pRefType, u""_ustr, u""_ustr, REF_FOOTNOTE, sal_uInt16(1), sal_uInt16(0),
833 REF_CONTENT);
834 pWrtShell->InsertField2(aField2);
835 //inserting third footnote
836 pWrtShell->InsertFootnote(u""_ustr);
837 pWrtShell->StartOfSection();
838 pCursor->Move(fnMoveForward);
839 pCursor->Move(fnMoveForward);
840 //inserting reference field 3
841 SwGetRefField aField3(pRefType, u""_ustr, u""_ustr, REF_FOOTNOTE, sal_uInt16(2), sal_uInt16(0),
842 REF_CONTENT);
843 pWrtShell->InsertField2(aField3);
844 //updating the fields
845 IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess());
846 rField.UpdateExpFields(nullptr, true);
847 //creating new clipboard doc
848 rtl::Reference<SwDoc> xClpDoc(new SwDoc());
849 xClpDoc->SetClipBoard(true);
850 xClpDoc->getIDocumentFieldsAccess().LockExpFields();
851 //selecting reference field 2 and reference field 3 and footnote 1 and footnote 2
852 //selection is such that more than one and not all footnotes and ref fields are selected
853 pCursor->Move(fnMoveBackward);
854 pCursor->Move(fnMoveBackward);
855 //start marking
856 pCursor->SetMark();
857 pCursor->Move(fnMoveForward);
858 pCursor->Move(fnMoveForward);
859 pCursor->Move(fnMoveForward);
860 //copying the selection to clipboard
861 pWrtShell->Copy(*xClpDoc);
862 //deleting selection mark after copy
863 pCursor->DeleteMark();
864 //checking that the footnotes reference fields have same values after copy operation
865 uno::Any aAny;
866 sal_uInt16 aFormat;
867 //reference field 1
868 pWrtShell->StartOfSection();
869 SwField* pRef1 = SwCursorShell::GetFieldAtCursor(pCursor, true);
870 aFormat = pRef1->GetFormat();
871 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
872 pRef1->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
873 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
874 //reference field 2
875 pCursor->Move(fnMoveForward);
876 SwField* pRef2 = SwCursorShell::GetFieldAtCursor(pCursor, true);
877 aFormat = pRef2->GetFormat();
878 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
879 pRef2->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
880 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
881 //reference field 3
882 pCursor->Move(fnMoveForward);
883 SwField* pRef3 = SwCursorShell::GetFieldAtCursor(pCursor, true);
884 aFormat = pRef3->GetFormat();
885 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
886 pRef3->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
887 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
888 //moving cursor to the end of the document
889 pWrtShell->EndOfSection();
890 //pasting the copied selection at current cursor position
891 pWrtShell->Paste(*xClpDoc);
892 //checking the fields, both new and old, for proper values
893 pWrtShell->StartOfSection();
894 //old reference field 1
895 SwField* pOldRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
896 aFormat = pOldRef11->GetFormat();
897 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
898 pOldRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
899 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
900 //old reference field 2
901 pCursor->Move(fnMoveForward);
902 SwField* pOldRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
903 aFormat = pOldRef12->GetFormat();
904 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
905 pOldRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
906 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
907 //old reference field 3
908 pCursor->Move(fnMoveForward);
909 SwField* pOldRef13 = SwCursorShell::GetFieldAtCursor(pCursor, true);
910 aFormat = pOldRef13->GetFormat();
911 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
912 pOldRef13->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
913 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
914 //old footnote 1
915 pCursor->Move(fnMoveForward);
916 SwTextNode* pTextNd1 = pCursor->GetPointNode().GetTextNode();
917 SwTextAttr* const pFootnote1
918 = pTextNd1->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
919 const SwFormatFootnote& rFootnote1(pFootnote1->GetFootnote());
920 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), rFootnote1.GetNumber());
921 SwTextFootnote* pTFNote1 = static_cast<SwTextFootnote*>(pFootnote1);
922 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pTFNote1->GetSeqRefNo());
923 //old footnote 2
924 pCursor->Move(fnMoveForward);
925 SwTextNode* pTextNd2 = pCursor->GetPointNode().GetTextNode();
926 SwTextAttr* const pFootnote2
927 = pTextNd2->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
928 const SwFormatFootnote& rFootnote2(pFootnote2->GetFootnote());
929 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), rFootnote2.GetNumber());
930 SwTextFootnote* pTFNote2 = static_cast<SwTextFootnote*>(pFootnote2);
931 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pTFNote2->GetSeqRefNo());
932 //old footnote 3
933 pCursor->Move(fnMoveForward);
934 SwTextNode* pTextNd3 = pCursor->GetPointNode().GetTextNode();
935 SwTextAttr* const pFootnote3
936 = pTextNd3->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
937 const SwFormatFootnote& rFootnote3(pFootnote3->GetFootnote());
938 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), rFootnote3.GetNumber());
939 SwTextFootnote* pTFNote3 = static_cast<SwTextFootnote*>(pFootnote3);
940 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pTFNote3->GetSeqRefNo());
941 //new reference field 1
942 pCursor->Move(fnMoveForward);
943 SwField* pNewRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
944 aFormat = pNewRef11->GetFormat();
945 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
946 pNewRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
947 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
948 //new reference field 2
949 pCursor->Move(fnMoveForward);
950 SwField* pNewRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
951 aFormat = pNewRef12->GetFormat();
952 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
953 pNewRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
954 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(3)), aAny);
955 //new footnote 1
956 pCursor->Move(fnMoveForward);
957 SwTextNode* pTextNd4 = pCursor->GetPointNode().GetTextNode();
958 SwTextAttr* const pFootnote4
959 = pTextNd4->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
960 const SwFormatFootnote& rFootnote4(pFootnote4->GetFootnote());
961 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), rFootnote4.GetNumber());
962 SwTextFootnote* pTFNote4 = static_cast<SwTextFootnote*>(pFootnote4);
963 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pTFNote4->GetSeqRefNo());
964 //moving the cursor to the starting of document
965 pWrtShell->StartOfSection();
966 //pasting the selection again at current cursor position
967 pWrtShell->Paste(*xClpDoc);
968 //checking the fields, both new and old, for proper values
969 pWrtShell->StartOfSection();
970 //new reference field 1
971 SwField* pNewRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
972 aFormat = pNewRef21->GetFormat();
973 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
974 pNewRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
975 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
976 //new reference field 2
977 pCursor->Move(fnMoveForward);
978 SwField* pNewRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
979 aFormat = pNewRef22->GetFormat();
980 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
981 pNewRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
982 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny);
983 //new footnote 1
984 pCursor->Move(fnMoveForward);
985 SwTextNode* pTextNd11 = pCursor->GetPointNode().GetTextNode();
986 SwTextAttr* const pFootnote11
987 = pTextNd11->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
988 const SwFormatFootnote& rFootnote11(pFootnote11->GetFootnote());
989 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), rFootnote11.GetNumber());
990 SwTextFootnote* pTFNote11 = static_cast<SwTextFootnote*>(pFootnote11);
991 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pTFNote11->GetSeqRefNo());
992 //old reference field 1
993 pCursor->Move(fnMoveForward);
994 SwField* pOldRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
995 aFormat = pOldRef21->GetFormat();
996 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
997 pOldRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
998 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
999 //old reference field 2
1000 pCursor->Move(fnMoveForward);
1001 SwField* pOldRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1002 aFormat = pOldRef22->GetFormat();
1003 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1004 pOldRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1005 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
1006 //old reference field 3
1007 pCursor->Move(fnMoveForward);
1008 SwField* pOldRef23 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1009 aFormat = pOldRef23->GetFormat();
1010 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1011 pOldRef23->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1012 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1013 //old footnote 1
1014 pCursor->Move(fnMoveForward);
1015 SwTextNode* pTextNd12 = pCursor->GetPointNode().GetTextNode();
1016 SwTextAttr* const pFootnote12
1017 = pTextNd12->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
1018 const SwFormatFootnote& rFootnote12(pFootnote12->GetFootnote());
1019 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), rFootnote12.GetNumber());
1020 SwTextFootnote* pTFNote12 = static_cast<SwTextFootnote*>(pFootnote12);
1021 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pTFNote12->GetSeqRefNo());
1022 //old footnote 2
1023 pCursor->Move(fnMoveForward);
1024 SwTextNode* pTextNd13 = pCursor->GetPointNode().GetTextNode();
1025 SwTextAttr* const pFootnote13
1026 = pTextNd13->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
1027 const SwFormatFootnote& rFootnote13(pFootnote13->GetFootnote());
1028 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), rFootnote13.GetNumber());
1029 SwTextFootnote* pTFNote13 = static_cast<SwTextFootnote*>(pFootnote13);
1030 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pTFNote13->GetSeqRefNo());
1031 //old footnote 3
1032 pCursor->Move(fnMoveForward);
1033 SwTextNode* pTextNd14 = pCursor->GetPointNode().GetTextNode();
1034 SwTextAttr* const pFootnote14
1035 = pTextNd14->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
1036 const SwFormatFootnote& rFootnote14(pFootnote14->GetFootnote());
1037 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), rFootnote14.GetNumber());
1038 SwTextFootnote* pTFNote14 = static_cast<SwTextFootnote*>(pFootnote14);
1039 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pTFNote14->GetSeqRefNo());
1040 //old reference field 4
1041 pCursor->Move(fnMoveForward);
1042 SwField* pOldRef24 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1043 aFormat = pOldRef24->GetFormat();
1044 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1045 pOldRef24->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1046 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
1047 //old reference field 5
1048 pCursor->Move(fnMoveForward);
1049 SwField* pOldRef25 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1050 aFormat = pOldRef25->GetFormat();
1051 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1052 pOldRef25->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1053 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(3)), aAny);
1054 //old footnote 4
1055 pCursor->Move(fnMoveForward);
1056 SwTextNode* pTextNd15 = pCursor->GetPointNode().GetTextNode();
1057 SwTextAttr* const pFootnote15
1058 = pTextNd15->GetTextAttrForCharAt(pCursor->GetPoint()->GetContentIndex(), RES_TXTATR_FTN);
1059 const SwFormatFootnote& rFootnote15(pFootnote15->GetFootnote());
1060 CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), rFootnote15.GetNumber());
1061 SwTextFootnote* pTFNote15 = static_cast<SwTextFootnote*>(pFootnote15);
1062 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pTFNote15->GetSeqRefNo());
1065 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf63553)
1067 createSwDoc();
1068 SwDoc* pDoc = getSwDoc();
1069 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1070 SwCursorShell* pShell(pDoc->GetEditShell());
1071 CPPUNIT_ASSERT(pShell);
1072 SwPaM* pCursor = pShell->GetCursor();
1073 //inserting sequence field 1
1074 SwSetExpFieldType* pSeqType = static_cast<SwSetExpFieldType*>(
1075 pWrtShell->GetFieldType(SwFieldIds::SetExp, u"Illustration"_ustr));
1076 SwSetExpField aSetField1(pSeqType, u""_ustr, SVX_NUM_ARABIC);
1077 pWrtShell->InsertField2(aSetField1);
1078 SwGetRefFieldType* pRefType
1079 = static_cast<SwGetRefFieldType*>(pWrtShell->GetFieldType(0, SwFieldIds::GetRef));
1080 //moving cursor to the starting of document
1081 pWrtShell->StartOfSection();
1082 //inserting reference field 1
1083 SwGetRefField aGetField1(pRefType, u"Illustration"_ustr, u""_ustr, REF_SEQUENCEFLD,
1084 sal_uInt16(0), sal_uInt16(0), REF_CONTENT);
1085 pWrtShell->InsertField2(aGetField1);
1086 //now we have ref1-seq1
1087 //moving the cursor
1088 pCursor->Move(fnMoveForward);
1089 //inserting sequence field 2
1090 SwSetExpField aSetField2(pSeqType, u""_ustr, SVX_NUM_ARABIC);
1091 pWrtShell->InsertField2(aSetField2);
1092 //moving the cursor
1093 pWrtShell->StartOfSection();
1094 pCursor->Move(fnMoveForward);
1095 //inserting reference field 2
1096 SwGetRefField aGetField2(pRefType, u"Illustration"_ustr, u""_ustr, REF_SEQUENCEFLD,
1097 sal_uInt16(1), sal_uInt16(0), REF_CONTENT);
1098 pWrtShell->InsertField2(aGetField2);
1099 //now we have ref1-ref2-seq1-seq2
1100 //moving the cursor
1101 pCursor->Move(fnMoveForward);
1102 pCursor->Move(fnMoveForward);
1103 //inserting sequence field 3
1104 SwSetExpField aSetField3(pSeqType, u""_ustr, SVX_NUM_ARABIC);
1105 pWrtShell->InsertField2(aSetField3);
1106 pWrtShell->StartOfSection();
1107 pCursor->Move(fnMoveForward);
1108 pCursor->Move(fnMoveForward);
1109 //inserting reference field 3
1110 SwGetRefField aGetField3(pRefType, u"Illustration"_ustr, u""_ustr, REF_SEQUENCEFLD,
1111 sal_uInt16(2), sal_uInt16(0), REF_CONTENT);
1112 pWrtShell->InsertField2(aGetField3);
1113 //now after insertion we have ref1-ref2-ref3-seq1-seq2-seq3
1114 //updating the fields
1115 IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess());
1116 rField.UpdateExpFields(nullptr, true);
1117 //creating new clipboard doc
1118 rtl::Reference<SwDoc> xClpDoc(new SwDoc());
1119 xClpDoc->SetClipBoard(true);
1120 xClpDoc->getIDocumentFieldsAccess().LockExpFields();
1121 //selecting reference field 2 and 3 and sequence field 1 and 2
1122 //selection is such that more than one and not all sequence fields and reference fields are selected
1123 //ref1-[ref2-ref3-seq1-seq2]-seq3
1124 pWrtShell->StartOfSection();
1125 pCursor->Move(fnMoveForward);
1126 //start marking
1127 pCursor->SetMark();
1128 pCursor->Move(fnMoveForward);
1129 pCursor->Move(fnMoveForward);
1130 pCursor->Move(fnMoveForward);
1131 pCursor->Move(fnMoveForward);
1132 //copying the selection to clipboard
1133 pWrtShell->Copy(*xClpDoc);
1134 //deleting selection mark after copy
1135 pCursor->DeleteMark();
1136 //checking whether the sequence and reference fields have same values after copy operation
1137 uno::Any aAny;
1138 sal_uInt16 aFormat;
1139 //reference field 1
1140 pWrtShell->StartOfSection();
1141 SwField* pRef1 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1142 aFormat = pRef1->GetFormat();
1143 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1144 pRef1->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1145 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
1146 //reference field 2
1147 pCursor->Move(fnMoveForward);
1148 SwField* pRef2 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1149 aFormat = pRef2->GetFormat();
1150 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1151 pRef2->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1152 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
1153 //reference field 3
1154 pCursor->Move(fnMoveForward);
1155 SwField* pRef3 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1156 aFormat = pRef3->GetFormat();
1157 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1158 pRef3->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1159 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1160 //sequence field 1
1161 pCursor->Move(fnMoveForward);
1162 SwSetExpField* pSeqF1
1163 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1164 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeqF1->GetSeqNumber());
1165 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeqF1->GetFieldName());
1166 //sequence field 2
1167 pCursor->Move(fnMoveForward);
1168 SwSetExpField* pSeqF2
1169 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1170 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeqF2->GetSeqNumber());
1171 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeqF2->GetFieldName());
1172 //sequence field 3
1173 pCursor->Move(fnMoveForward);
1174 SwSetExpField* pSeqF3
1175 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1176 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeqF3->GetSeqNumber());
1177 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeqF3->GetFieldName());
1178 //moving cursor to the end of the document
1179 pWrtShell->EndOfSection();
1180 //pasting the copied selection at current cursor position
1181 pWrtShell->Paste(*xClpDoc);
1182 //checking the fields, both new and old, for proper values
1183 pWrtShell->StartOfSection();
1184 //now we have ref1-ref2-ref3-seq1-seq2-seq3-nref1-nref2-nseq1-nseq2
1185 //old reference field 1
1186 SwField* pOldRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1187 aFormat = pOldRef11->GetFormat();
1188 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1189 pOldRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1190 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
1191 //old reference field 2
1192 pCursor->Move(fnMoveForward);
1193 SwField* pOldRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1194 aFormat = pOldRef12->GetFormat();
1195 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1196 pOldRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1197 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
1198 //old reference field 3
1199 pCursor->Move(fnMoveForward);
1200 SwField* pOldRef13 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1201 aFormat = pOldRef13->GetFormat();
1202 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1203 pOldRef13->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1204 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1205 //old sequence field 1
1206 pCursor->Move(fnMoveForward);
1207 SwSetExpField* pSeq1
1208 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1209 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeq1->GetSeqNumber());
1210 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeq1->GetFieldName());
1211 //old sequence field 2
1212 pCursor->Move(fnMoveForward);
1213 SwSetExpField* pSeq2
1214 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1215 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeq2->GetSeqNumber());
1216 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeq2->GetFieldName());
1217 //old sequence field 3
1218 pCursor->Move(fnMoveForward);
1219 SwSetExpField* pSeq3
1220 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1221 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeq3->GetSeqNumber());
1222 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pSeq3->GetFieldName());
1223 //new reference field 1
1224 pCursor->Move(fnMoveForward);
1225 SwField* pNewRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1226 aFormat = pNewRef11->GetFormat();
1227 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1228 pNewRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1229 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny);
1230 //new reference field 2
1231 pCursor->Move(fnMoveForward);
1232 SwField* pNewRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1233 aFormat = pNewRef12->GetFormat();
1234 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1235 pNewRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1236 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1237 //new sequence field 1
1238 pCursor->Move(fnMoveForward);
1239 SwSetExpField* pNewSeq1
1240 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1241 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pNewSeq1->GetSeqNumber());
1242 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pNewSeq1->GetFieldName());
1243 //new sequence field 2
1244 pCursor->Move(fnMoveForward);
1245 SwSetExpField* pNewSeq2
1246 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1247 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pNewSeq2->GetSeqNumber());
1248 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pNewSeq2->GetFieldName());
1249 //moving the cursor to the starting of document
1250 pWrtShell->StartOfSection();
1251 //pasting the selection again at current cursor position
1252 pWrtShell->Paste(*xClpDoc);
1253 //checking the fields, both new and old, for proper values
1254 pWrtShell->StartOfSection();
1255 //now we have [nnref1-nnref2-nnseq1-nnseq2]-ref1-[ref2-ref3-seq1-seq2]-seq3-[nref1-nref2-nseq1-nseq2]
1256 //new reference field 1
1257 SwField* pNewRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1258 aFormat = pNewRef21->GetFormat();
1259 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1260 pNewRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1261 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(6)), aAny);
1262 //new reference field 2
1263 pCursor->Move(fnMoveForward);
1264 SwField* pNewRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1265 aFormat = pNewRef22->GetFormat();
1266 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1267 pNewRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1268 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1269 //new sequence field 1
1270 pCursor->Move(fnMoveForward);
1271 SwSetExpField* pNewSeq11
1272 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1273 CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), pNewSeq11->GetSeqNumber());
1274 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pNewSeq11->GetFieldName());
1275 //new sequence field 2
1276 pCursor->Move(fnMoveForward);
1277 SwSetExpField* pNewSeq12
1278 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1279 CPPUNIT_ASSERT_EQUAL(sal_uInt16(6), pNewSeq12->GetSeqNumber());
1280 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pNewSeq12->GetFieldName());
1281 //old reference field 1
1282 pCursor->Move(fnMoveForward);
1283 SwField* pOldRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1284 aFormat = pOldRef21->GetFormat();
1285 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1286 pOldRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1287 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(0)), aAny);
1288 //old reference field 2
1289 pCursor->Move(fnMoveForward);
1290 SwField* pOldRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1291 aFormat = pOldRef22->GetFormat();
1292 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1293 pOldRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1294 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(1)), aAny);
1295 //old reference field 3
1296 pCursor->Move(fnMoveForward);
1297 SwField* pOldRef23 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1298 aFormat = pOldRef23->GetFormat();
1299 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1300 pOldRef23->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1301 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1302 //old sequence field 1
1303 pCursor->Move(fnMoveForward);
1304 SwSetExpField* pOldSeq11
1305 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1306 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pOldSeq11->GetSeqNumber());
1307 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pOldSeq11->GetFieldName());
1308 //old sequence field 2
1309 pCursor->Move(fnMoveForward);
1310 SwSetExpField* pOldSeq12
1311 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1312 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pOldSeq12->GetSeqNumber());
1313 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pOldSeq12->GetFieldName());
1314 //old sequence field 3
1315 pCursor->Move(fnMoveForward);
1316 SwSetExpField* pOldSeq13
1317 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1318 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pOldSeq13->GetSeqNumber());
1319 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pOldSeq13->GetFieldName());
1320 //old reference field 4
1321 pCursor->Move(fnMoveForward);
1322 SwField* pOldRef24 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1323 aFormat = pOldRef24->GetFormat();
1324 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1325 pOldRef24->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1326 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(4)), aAny);
1327 //old reference field 5
1328 pCursor->Move(fnMoveForward);
1329 SwField* pOldRef25 = SwCursorShell::GetFieldAtCursor(pCursor, true);
1330 aFormat = pOldRef25->GetFormat();
1331 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
1332 pOldRef25->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
1333 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_uInt16(2)), aAny);
1334 //old sequence field 4
1335 pCursor->Move(fnMoveForward);
1336 SwSetExpField* pOldSeq14
1337 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1338 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pOldSeq14->GetSeqNumber());
1339 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pOldSeq14->GetFieldName());
1340 //old sequence field 5
1341 pCursor->Move(fnMoveForward);
1342 SwSetExpField* pOldSeq15
1343 = static_cast<SwSetExpField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
1344 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pOldSeq15->GetSeqNumber());
1345 CPPUNIT_ASSERT_EQUAL(u"Number range Illustration"_ustr, pOldSeq15->GetFieldName());
1348 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf74230)
1350 createSwDoc();
1351 //exporting the empty document to ODT via TempFile
1352 save(u"writer8"_ustr);
1353 CPPUNIT_ASSERT(maTempFile.IsValid());
1354 //loading an XML DOM of the "styles.xml" of the TempFile
1355 xmlDocUniquePtr pXmlDoc = parseExport(u"styles.xml"_ustr);
1356 //pXmlDoc should not be null
1357 CPPUNIT_ASSERT(pXmlDoc);
1358 //asserting XPath in loaded XML DOM
1359 assertXPath(pXmlDoc, "//office:styles/style:default-style[@style:family='graphic']/"
1360 "style:graphic-properties[@svg:stroke-color='#3465a4']");
1361 assertXPath(pXmlDoc, "//office:styles/style:default-style[@style:family='graphic']/"
1362 "style:graphic-properties[@draw:fill-color='#729fcf']");
1365 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf80663)
1367 createSwDoc();
1368 SwDoc* pDoc = getSwDoc();
1369 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1370 //Inserting 2x2 Table
1371 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
1372 SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
1373 pWrtShell->InsertTable(TableOpt, 2, 2);
1374 //Checking for the number of rows and columns
1375 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
1376 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1377 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1378 //Deleting the first row
1379 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1380 pWrtShell->SelTableRow(); //selects the first row
1381 pWrtShell->DeleteRow();
1382 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1383 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1384 //Undo changes
1385 rUndoManager.Undo();
1386 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1387 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1388 //Redo changes
1389 rUndoManager.Redo();
1390 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1391 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1392 //Undo changes
1393 rUndoManager.Undo();
1394 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1395 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1396 //Deleting the second row
1397 pWrtShell->GoNextCell(); //moves the cursor to next cell
1398 pWrtShell->SelTableRow(); //selects the second row
1399 pWrtShell->DeleteRow();
1400 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1401 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1402 //Undo changes
1403 rUndoManager.Undo();
1404 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1405 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1406 //Redo changes
1407 rUndoManager.Redo();
1408 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1409 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1410 //Undo changes
1411 rUndoManager.Undo();
1412 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1413 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1414 //Deleting the first column
1415 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1416 pWrtShell->SelTableCol(); //selects first column
1417 pWrtShell->DeleteCol();
1418 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1419 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1420 //Undo changes
1421 rUndoManager.Undo();
1422 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1423 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1424 //Redo changes
1425 rUndoManager.Redo();
1426 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1427 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1428 //Undo changes
1429 rUndoManager.Undo();
1430 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1431 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1432 //Deleting the second column
1433 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1434 pWrtShell->GoNextCell(); //moves the cursor to next cell
1435 pWrtShell->SelTableCol(); //selects second column
1436 pWrtShell->DeleteCol();
1437 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1438 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1439 //Undo changes
1440 rUndoManager.Undo();
1441 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1442 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1443 //Redo changes
1444 rUndoManager.Redo();
1445 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1446 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1447 //Undo changes
1448 rUndoManager.Undo();
1449 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1450 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1453 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf57197)
1455 createSwDoc();
1456 SwDoc* pDoc = getSwDoc();
1457 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1458 //Inserting 1x1 Table
1459 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
1460 SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
1461 pWrtShell->InsertTable(TableOpt, 1, 1);
1462 //Checking for the number of rows and columns
1463 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
1464 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1465 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1466 //Inserting one row before the existing row
1467 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1468 pWrtShell->InsertRow(1, false);
1469 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1470 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1471 //Undo changes
1472 rUndoManager.Undo();
1473 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1474 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1475 //Redo changes
1476 rUndoManager.Redo();
1477 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1478 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1479 //Undo changes
1480 rUndoManager.Undo();
1481 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1482 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1483 //Inserting one row after the existing row
1484 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1485 pWrtShell->InsertRow(1, true);
1486 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1487 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1488 //Undo changes
1489 rUndoManager.Undo();
1490 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1491 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1492 //Redo changes
1493 rUndoManager.Redo();
1494 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
1495 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1496 //Undo changes
1497 rUndoManager.Undo();
1498 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1499 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1500 //Inserting one column before the existing column
1501 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1502 pWrtShell->InsertCol(1, false);
1503 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1504 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1505 //Undo changes
1506 rUndoManager.Undo();
1507 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1508 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1509 //Redo changes
1510 rUndoManager.Redo();
1511 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1512 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1513 //Undo changes
1514 rUndoManager.Undo();
1515 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1516 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1517 //Inserting one column after the existing column
1518 pWrtShell->StartOfSection(); //moves the cursor to the start of Doc
1519 pWrtShell->InsertCol(1, true);
1520 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1521 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1522 //Undo changes
1523 rUndoManager.Undo();
1524 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1525 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1526 //Redo changes
1527 rUndoManager.Redo();
1528 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1529 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getColumns()->getCount());
1530 //Undo changes
1531 rUndoManager.Undo();
1532 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1533 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1536 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf131990)
1538 createSwDoc();
1539 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1541 CPPUNIT_ASSERT(!pWrtShell->Up(false, 1, true));
1542 CPPUNIT_ASSERT(!pWrtShell->Down(false, 1, true));
1545 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf90808)
1547 createSwDoc();
1548 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1549 uno::Reference<text::XTextRange> xTextRange = xTextDocument->getText();
1550 uno::Reference<text::XText> xText = xTextRange->getText();
1551 uno::Reference<text::XParagraphCursor> xCursor(xText->createTextCursor(), uno::UNO_QUERY);
1552 //inserting text into document so that the paragraph is not empty
1553 xText->setString(u"Hello World!"_ustr);
1554 uno::Reference<lang::XMultiServiceFactory> xFact(mxComponent, uno::UNO_QUERY);
1555 //creating bookmark 1
1556 uno::Reference<text::XTextContent> xHeadingBookmark1(
1557 xFact->createInstance(u"com.sun.star.text.Bookmark"_ustr), uno::UNO_QUERY);
1558 uno::Reference<container::XNamed> xHeadingName1(xHeadingBookmark1, uno::UNO_QUERY);
1559 xHeadingName1->setName(u"__RefHeading__1"_ustr);
1560 //moving cursor to the starting of paragraph
1561 xCursor->gotoStartOfParagraph(false);
1562 //inserting the bookmark in paragraph
1563 xText->insertTextContent(xCursor, xHeadingBookmark1, true);
1564 //creating bookmark 2
1565 uno::Reference<text::XTextContent> xHeadingBookmark2(
1566 xFact->createInstance(u"com.sun.star.text.Bookmark"_ustr), uno::UNO_QUERY);
1567 uno::Reference<container::XNamed> xHeadingName2(xHeadingBookmark2, uno::UNO_QUERY);
1568 xHeadingName2->setName(u"__RefHeading__2"_ustr);
1569 //inserting the bookmark in same paragraph, at the end
1570 //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
1571 xCursor->gotoEndOfParagraph(true);
1572 CPPUNIT_ASSERT_THROW(xText->insertTextContent(xCursor, xHeadingBookmark2, true),
1573 css::lang::IllegalArgumentException);
1574 //now testing for __RefNumPara__
1575 //creating bookmark 1
1576 uno::Reference<text::XTextContent> xNumBookmark1(
1577 xFact->createInstance(u"com.sun.star.text.Bookmark"_ustr), uno::UNO_QUERY);
1578 uno::Reference<container::XNamed> xNumName1(xNumBookmark1, uno::UNO_QUERY);
1579 xNumName1->setName(u"__RefNumPara__1"_ustr);
1580 //moving cursor to the starting of paragraph
1581 xCursor->gotoStartOfParagraph(false);
1582 //inserting the bookmark in paragraph
1583 xText->insertTextContent(xCursor, xNumBookmark1, true);
1584 //creating bookmark 2
1585 uno::Reference<text::XTextContent> xNumBookmark2(
1586 xFact->createInstance(u"com.sun.star.text.Bookmark"_ustr), uno::UNO_QUERY);
1587 uno::Reference<container::XNamed> xNumName2(xNumBookmark2, uno::UNO_QUERY);
1588 xNumName2->setName(u"__RefNumPara__2"_ustr);
1589 //inserting the bookmark in same paragraph, at the end
1590 //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
1591 xCursor->gotoEndOfParagraph(true);
1592 CPPUNIT_ASSERT_THROW(xText->insertTextContent(xCursor, xNumBookmark2, true),
1593 css::lang::IllegalArgumentException);
1596 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf97601)
1598 // Instructions from the bugreport to trigger an infinite loop.
1599 createSwDoc("tdf97601.odt");
1600 uno::Reference<text::XTextEmbeddedObjectsSupplier> xEmbeddedObjectsSupplier(mxComponent,
1601 uno::UNO_QUERY);
1602 uno::Reference<container::XNameAccess> xEmbeddedObjects
1603 = xEmbeddedObjectsSupplier->getEmbeddedObjects();
1604 uno::Reference<beans::XPropertySet> xChart;
1605 xEmbeddedObjects->getByName(u"myChart"_ustr) >>= xChart;
1606 uno::Reference<chart2::data::XDataSource> xChartComponent;
1607 xChart->getPropertyValue(u"Component"_ustr) >>= xChartComponent;
1608 uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>> aDataSequences
1609 = xChartComponent->getDataSequences();
1610 uno::Reference<document::XEmbeddedObjectSupplier2> xChartState(xChart, uno::UNO_QUERY);
1611 xChartState->getExtendedControlOverEmbeddedObject()->changeState(1);
1612 uno::Reference<util::XModifiable> xDataSequenceModifiable(aDataSequences[2]->getValues(),
1613 uno::UNO_QUERY);
1614 xDataSequenceModifiable->setModified(true);
1616 // Make sure that the chart is marked as modified.
1617 uno::Reference<util::XModifiable> xModifiable(xChartComponent, uno::UNO_QUERY);
1618 CPPUNIT_ASSERT_EQUAL(true, bool(xModifiable->isModified()));
1619 calcLayout();
1620 // This never returned.
1621 Scheduler::ProcessEventsToIdle();
1624 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf75137)
1626 createSwDoc();
1627 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1628 SwShellCursor* pShellCursor = pWrtShell->getShellCursor(true);
1629 pWrtShell->InsertFootnote(u"This is first footnote"_ustr);
1630 SwNodeOffset firstIndex = pShellCursor->GetPointNode().GetIndex();
1631 pShellCursor->GotoFootnoteAnchor();
1632 pWrtShell->InsertFootnote(u"This is second footnote"_ustr);
1633 pWrtShell->Up(false);
1634 SwNodeOffset secondIndex = pShellCursor->GetPointNode().GetIndex();
1635 pWrtShell->Down(false);
1636 SwNodeOffset thirdIndex = pShellCursor->GetPointNode().GetIndex();
1637 CPPUNIT_ASSERT_EQUAL(firstIndex, thirdIndex);
1638 CPPUNIT_ASSERT(firstIndex != secondIndex);
1641 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf83798)
1643 createSwDoc("tdf83798.odt");
1644 SwDoc* pDoc = getSwDoc();
1645 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1646 pWrtShell->GotoNextTOXBase();
1647 const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX();
1648 pWrtShell->UpdateTableOf(*pTOXBase);
1649 SwCursorShell* pShell(pDoc->GetEditShell());
1650 CPPUNIT_ASSERT(pShell);
1651 SwPaM* pCursor = pShell->GetCursor();
1652 pCursor->SetMark();
1653 pCursor->Move(fnMoveForward, GoInNode);
1654 pCursor->Move(fnMoveBackward, GoInContent);
1655 CPPUNIT_ASSERT_EQUAL(u"Table of Contents"_ustr, pCursor->GetText());
1656 pCursor->Move(fnMoveForward, GoInContent);
1657 pCursor->DeleteMark();
1658 pCursor->SetMark();
1659 pCursor->Move(fnMoveForward, GoInContent);
1660 CPPUNIT_ASSERT_EQUAL(u"1"_ustr, pCursor->GetText());
1661 pCursor->DeleteMark();
1662 pCursor->Move(fnMoveForward, GoInNode);
1663 pCursor->SetMark();
1664 pCursor->Move(fnMoveForward, GoInContent);
1665 pCursor->Move(fnMoveForward, GoInContent);
1666 pCursor->Move(fnMoveForward, GoInContent);
1667 CPPUNIT_ASSERT_EQUAL(u"1.A"_ustr, pCursor->GetText());
1668 pCursor->DeleteMark();
1669 pCursor->Move(fnMoveForward, GoInNode);
1670 pCursor->SetMark();
1671 pCursor->Move(fnMoveForward, GoInContent);
1672 CPPUNIT_ASSERT_EQUAL(u"2"_ustr, pCursor->GetText());
1673 pCursor->DeleteMark();
1674 pCursor->Move(fnMoveForward, GoInNode);
1675 pCursor->SetMark();
1676 pCursor->Move(fnMoveForward, GoInContent);
1677 pCursor->Move(fnMoveForward, GoInContent);
1678 pCursor->Move(fnMoveForward, GoInContent);
1679 CPPUNIT_ASSERT_EQUAL(u"2.A"_ustr, pCursor->GetText());
1680 pCursor->DeleteMark();
1683 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf89714)
1685 createSwDoc();
1686 uno::Reference<lang::XMultiServiceFactory> xFact(mxComponent, uno::UNO_QUERY);
1687 uno::Reference<uno::XInterface> xInterface(
1688 xFact->createInstance(u"com.sun.star.text.Defaults"_ustr), uno::UNO_QUERY);
1689 uno::Reference<beans::XPropertyState> xPropState(xInterface, uno::UNO_QUERY);
1690 //enabled Paragraph Orphan and Widows by default starting in LO5.1
1691 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int8(2)),
1692 xPropState->getPropertyDefault(u"ParaOrphans"_ustr));
1693 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int8(2)), xPropState->getPropertyDefault(u"ParaWidows"_ustr));
1696 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf130287)
1698 //create a new writer document
1699 createSwDoc();
1700 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1701 //insert a 1-cell table in the newly created document
1702 SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
1703 pWrtShell->InsertTable(TableOpt, 1, 1);
1704 //checking for the row and column
1705 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
1706 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
1707 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
1708 uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr);
1709 uno::Reference<text::XText> xCellText(xCell, uno::UNO_QUERY);
1710 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xCellText);
1711 // they were 2 (orphan/widow control enabled unnecessarily in Table Contents paragraph style)
1712 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), getProperty<sal_Int8>(xParagraph, u"ParaOrphans"_ustr));
1713 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), getProperty<sal_Int8>(xParagraph, u"ParaWidows"_ustr));
1716 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testPropertyDefaults)
1718 createSwDoc();
1719 uno::Reference<lang::XMultiServiceFactory> xFact(mxComponent, uno::UNO_QUERY);
1720 uno::Reference<uno::XInterface> xInterface(
1721 xFact->createInstance(u"com.sun.star.text.Defaults"_ustr), uno::UNO_QUERY);
1722 uno::Reference<beans::XPropertySet> xPropSet(xInterface, uno::UNO_QUERY_THROW);
1723 uno::Reference<beans::XPropertyState> xPropState(xInterface, uno::UNO_QUERY);
1724 //testing CharFontName from style::CharacterProperties
1725 //getting property default
1726 uno::Any aCharFontName = xPropState->getPropertyDefault(u"CharFontName"_ustr);
1727 //asserting property default and defaults received from "css.text.Defaults" service
1728 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharFontName"_ustr), aCharFontName);
1729 //changing the default value
1730 xPropSet->setPropertyValue(u"CharFontName"_ustr, uno::Any(u"Symbol"_ustr));
1731 CPPUNIT_ASSERT_EQUAL(uno::Any(u"Symbol"_ustr),
1732 xPropSet->getPropertyValue(u"CharFontName"_ustr));
1733 //resetting the value to default
1734 xPropState->setPropertyToDefault(u"CharFontName"_ustr);
1735 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharFontName"_ustr), aCharFontName);
1736 //testing CharHeight from style::CharacterProperties
1737 //getting property default
1738 uno::Any aCharHeight = xPropState->getPropertyDefault(u"CharHeight"_ustr);
1739 //asserting property default and defaults received from "css.text.Defaults" service
1740 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharHeight"_ustr), aCharHeight);
1741 //changing the default value
1742 xPropSet->setPropertyValue(u"CharHeight"_ustr, uno::Any(float(14)));
1743 CPPUNIT_ASSERT_EQUAL(uno::Any(float(14)), xPropSet->getPropertyValue(u"CharHeight"_ustr));
1744 //resetting the value to default
1745 xPropState->setPropertyToDefault(u"CharHeight"_ustr);
1746 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharHeight"_ustr), aCharHeight);
1747 //testing CharWeight from style::CharacterProperties
1748 uno::Any aCharWeight = xPropSet->getPropertyValue(u"CharWeight"_ustr);
1749 //changing the default value
1750 xPropSet->setPropertyValue(u"CharWeight"_ustr, uno::Any(float(awt::FontWeight::BOLD)));
1751 CPPUNIT_ASSERT_EQUAL(uno::Any(float(awt::FontWeight::BOLD)),
1752 xPropSet->getPropertyValue(u"CharWeight"_ustr));
1753 //resetting the value to default
1754 xPropState->setPropertyToDefault(u"CharWeight"_ustr);
1755 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharWeight"_ustr), aCharWeight);
1756 //testing CharUnderline from style::CharacterProperties
1757 uno::Any aCharUnderline = xPropSet->getPropertyValue(u"CharUnderline"_ustr);
1758 //changing the default value
1759 xPropSet->setPropertyValue(u"CharUnderline"_ustr,
1760 uno::Any(sal_Int16(awt::FontUnderline::SINGLE)));
1761 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(awt::FontUnderline::SINGLE)),
1762 xPropSet->getPropertyValue(u"CharUnderline"_ustr));
1763 //resetting the value to default
1764 xPropState->setPropertyToDefault(u"CharUnderline"_ustr);
1765 CPPUNIT_ASSERT_EQUAL(xPropSet->getPropertyValue(u"CharUnderline"_ustr), aCharUnderline);
1768 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTableBackgroundColor)
1770 createSwDoc();
1771 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1772 SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0);
1773 pWrtShell->InsertTable(TableOpt, 3, 3); //Inserting Table
1774 //Checking Rows and Columns of Inserted Table
1775 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
1776 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRows()->getCount());
1777 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getColumns()->getCount());
1778 pWrtShell->StartOfSection();
1779 pWrtShell->SelTableRow(); //Selecting First Row
1780 pWrtShell->ClearMark();
1781 //Modifying the color of Table Box
1782 pWrtShell->SetBoxBackground(
1783 SvxBrushItem(Color(sal_Int32(0xFF00FF)), sal_Int16(RES_BACKGROUND)));
1784 //Checking cells for background color only A1 should be modified
1785 uno::Reference<table::XCell> xCell;
1786 xCell = xTable->getCellByName(u"A1"_ustr);
1787 CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, getProperty<Color>(xCell, u"BackColor"_ustr));
1788 xCell = xTable->getCellByName(u"A2"_ustr);
1789 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1790 xCell = xTable->getCellByName(u"A3"_ustr);
1791 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1792 xCell = xTable->getCellByName(u"B1"_ustr);
1793 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1794 xCell = xTable->getCellByName(u"B2"_ustr);
1795 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1796 xCell = xTable->getCellByName(u"B3"_ustr);
1797 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1798 xCell = xTable->getCellByName(u"C1"_ustr);
1799 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1800 xCell = xTable->getCellByName(u"C2"_ustr);
1801 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1802 xCell = xTable->getCellByName(u"C3"_ustr);
1803 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell, u"BackColor"_ustr));
1806 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf88899)
1808 createSwDoc();
1809 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(
1810 mxComponent, uno::UNO_QUERY);
1811 uno::Reference<document::XDocumentProperties> xProps(
1812 xDocumentPropertiesSupplier->getDocumentProperties());
1813 uno::Reference<beans::XPropertyContainer> xUserProps = xProps->getUserDefinedProperties();
1814 css::util::DateTime aDateTime
1815 = { sal_uInt32(1234567), sal_uInt16(3), sal_uInt16(3), sal_uInt16(3),
1816 sal_uInt16(10), sal_uInt16(11), sal_uInt16(2014), true };
1817 xUserProps->addProperty(u"dateTime"_ustr, sal_Int16(beans::PropertyAttribute::OPTIONAL),
1818 uno::Any(aDateTime));
1819 uno::Reference<lang::XMultiServiceFactory> xFact(mxComponent, uno::UNO_QUERY);
1820 uno::Reference<text::XTextField> xTextField(
1821 xFact->createInstance(u"com.sun.star.text.textfield.docinfo.Custom"_ustr), uno::UNO_QUERY);
1822 //Setting Name Property
1823 uno::Reference<beans::XPropertySet> xPropSet(xTextField, uno::UNO_QUERY_THROW);
1824 xPropSet->setPropertyValue(u"Name"_ustr, uno::Any(u"dateTime"_ustr));
1825 //Setting NumberFormat
1826 uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(mxComponent,
1827 uno::UNO_QUERY);
1828 uno::Reference<util::XNumberFormatTypes> xNumFormat(xNumberFormatsSupplier->getNumberFormats(),
1829 uno::UNO_QUERY);
1830 css::lang::Locale alocale;
1831 alocale.Language = "en";
1832 alocale.Country = "US";
1833 sal_Int16 key = xNumFormat->getStandardFormat(util::NumberFormat::DATETIME, alocale);
1834 xPropSet->setPropertyValue(u"NumberFormat"_ustr, uno::Any(key));
1835 //Inserting Text Content
1836 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1837 uno::Reference<text::XTextRange> xTextRange = xTextDocument->getText();
1838 uno::Reference<text::XText> xText = xTextRange->getText();
1839 xText->insertTextContent(xTextRange, xTextField, true);
1840 //Retrieving the contents for verification
1841 CPPUNIT_ASSERT_EQUAL(u"11/10/14 03:03 AM"_ustr, xTextField->getPresentation(false));
1844 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf151605)
1846 createSwDoc("tdf151605.odt");
1848 // disable IncludeHiddenText
1849 std::shared_ptr<comphelper::ConfigurationChanges> batch(
1850 comphelper::ConfigurationChanges::create());
1851 officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(false, batch);
1852 officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(false, batch);
1853 batch->commit();
1855 dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
1856 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
1858 uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence(
1859 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32>(SotClipboardFormatId::STRING)) } });
1861 // Paste as Unformatted text
1862 dispatchCommand(mxComponent, u".uno:ClipboardFormatItems"_ustr, aPropertyValues);
1864 CPPUNIT_ASSERT_EQUAL(u"Before"_ustr, getParagraph(1)->getString());
1865 CPPUNIT_ASSERT_EQUAL(u"After"_ustr, getParagraph(2)->getString());
1867 // re-enable it
1868 officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(true, batch);
1869 officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(true, batch);
1870 batch->commit();
1873 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf90362)
1875 createSwDoc("tdf90362.fodt");
1876 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
1877 // Ensure correct initial setting
1878 std::shared_ptr<comphelper::ConfigurationChanges> batch(
1879 comphelper::ConfigurationChanges::create());
1880 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(false, batch);
1881 batch->commit();
1882 // First check if the end of the second paragraph is indeed protected.
1883 pWrtShell->EndPara();
1884 pWrtShell->Down(/*bSelect=*/false);
1885 CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel());
1887 // Then enable ignoring of protected areas and make sure that this time the cursor is read-write.
1888 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(true, batch);
1889 batch->commit();
1890 CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel());
1891 // Clean up, otherwise following tests will have that option set
1892 officecfg::Office::Writer::Cursor::Option::IgnoreProtectedArea::set(false, batch);
1893 batch->commit();
1896 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUndoDelAsCharTdf107512)
1898 createSwDoc();
1899 SwDoc* pDoc = getSwDoc();
1900 sw::UndoManager& rUndoManager(pDoc->GetUndoManager());
1901 IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
1902 SwCursorShell* pShell(pDoc->GetEditShell());
1903 CPPUNIT_ASSERT(pShell);
1904 SfxItemSet frameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>);
1905 SfxItemSet grfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>);
1906 rIDCO.InsertString(*pShell->GetCursor(), u"foo"_ustr);
1907 pShell->ClearMark();
1908 SwFormatAnchor anchor(RndStdIds::FLY_AS_CHAR);
1909 frameSet.Put(anchor);
1910 Graphic grf;
1911 pShell->SttEndDoc(true);
1912 CPPUNIT_ASSERT(rIDCO.InsertGraphic(*pShell->GetCursor(), OUString(), OUString(), &grf,
1913 &frameSet, &grfSet, nullptr));
1914 pShell->SttEndDoc(false);
1915 CPPUNIT_ASSERT(rIDCO.InsertGraphic(*pShell->GetCursor(), OUString(), OUString(), &grf,
1916 &frameSet, &grfSet, nullptr));
1917 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1918 SvxCharHiddenItem hidden(true, RES_CHRATR_HIDDEN);
1919 pShell->SelectTextModel(1, 4);
1920 rIDCO.InsertPoolItem(*pShell->GetCursor(), hidden);
1921 // now we have "\1foo\1" with the "foo" hidden
1922 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1923 0, RES_TXTATR_FLYCNT));
1924 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1925 4, RES_TXTATR_FLYCNT));
1926 CPPUNIT_ASSERT_EQUAL(
1927 OUString(OUStringChar(CH_TXTATR_BREAKWORD) + u"foo" + OUStringChar(CH_TXTATR_BREAKWORD)),
1928 pShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
1929 SfxPoolItem const* pItem;
1930 SfxItemSet query(pDoc->GetAttrPool(), svl::Items<RES_CHRATR_HIDDEN, RES_CHRATR_HIDDEN>);
1931 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 1, 4);
1932 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1933 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue());
1934 query.ClearItem(RES_CHRATR_HIDDEN);
1936 // delete from the start
1937 pShell->SelectTextModel(0, 4);
1938 rIDCO.DeleteAndJoin(*pShell->GetCursor());
1939 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1940 0, RES_TXTATR_FLYCNT));
1941 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1942 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
1943 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 0, 1);
1944 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
1945 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1946 query.ClearItem(RES_CHRATR_HIDDEN);
1947 rUndoManager.Undo();
1948 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1949 0, RES_TXTATR_FLYCNT));
1950 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1951 4, RES_TXTATR_FLYCNT));
1952 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1953 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
1954 CPPUNIT_ASSERT_EQUAL(
1955 OUString(OUStringChar(CH_TXTATR_BREAKWORD) + u"foo" + OUStringChar(CH_TXTATR_BREAKWORD)),
1956 pShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
1957 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 0, 1);
1958 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
1959 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1960 query.ClearItem(RES_CHRATR_HIDDEN);
1961 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 1, 4);
1962 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1963 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue());
1964 query.ClearItem(RES_CHRATR_HIDDEN);
1965 rUndoManager.Redo();
1966 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1967 0, RES_TXTATR_FLYCNT));
1968 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1969 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
1970 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 0, 1);
1971 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
1972 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1973 query.ClearItem(RES_CHRATR_HIDDEN);
1974 rUndoManager.Undo();
1975 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1976 0, RES_TXTATR_FLYCNT));
1977 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1978 4, RES_TXTATR_FLYCNT));
1979 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1980 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
1981 CPPUNIT_ASSERT_EQUAL(
1982 OUString(OUStringChar(CH_TXTATR_BREAKWORD) + u"foo" + OUStringChar(CH_TXTATR_BREAKWORD)),
1983 pShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
1984 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 0, 1);
1985 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
1986 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1987 query.ClearItem(RES_CHRATR_HIDDEN);
1988 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 1, 4);
1989 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
1990 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue());
1991 query.ClearItem(RES_CHRATR_HIDDEN);
1993 // delete from the end
1994 pShell->SelectTextModel(1, 5);
1995 rIDCO.DeleteAndJoin(*pShell->GetCursor());
1996 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
1997 0, RES_TXTATR_FLYCNT));
1998 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
1999 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2000 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 4, 5);
2001 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
2002 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2003 query.ClearItem(RES_CHRATR_HIDDEN);
2004 rUndoManager.Undo();
2005 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
2006 0, RES_TXTATR_FLYCNT));
2007 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
2008 4, RES_TXTATR_FLYCNT));
2009 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2010 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2011 CPPUNIT_ASSERT_EQUAL(
2012 OUString(OUStringChar(CH_TXTATR_BREAKWORD) + u"foo" + OUStringChar(CH_TXTATR_BREAKWORD)),
2013 pShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
2014 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 4, 5);
2015 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
2016 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2017 query.ClearItem(RES_CHRATR_HIDDEN);
2018 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 1, 4);
2019 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2020 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue());
2021 query.ClearItem(RES_CHRATR_HIDDEN);
2022 rUndoManager.Redo();
2023 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
2024 0, RES_TXTATR_FLYCNT));
2025 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2026 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2027 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 4, 5);
2028 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
2029 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2030 query.ClearItem(RES_CHRATR_HIDDEN);
2031 rUndoManager.Undo();
2032 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
2033 0, RES_TXTATR_FLYCNT));
2034 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(
2035 4, RES_TXTATR_FLYCNT));
2036 CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2037 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2038 CPPUNIT_ASSERT_EQUAL(
2039 OUString(OUStringChar(CH_TXTATR_BREAKWORD) + u"foo" + OUStringChar(CH_TXTATR_BREAKWORD)),
2040 pShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
2041 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 4, 5);
2042 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
2043 query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2044 query.ClearItem(RES_CHRATR_HIDDEN);
2045 pShell->GetCursor()->GetPointNode().GetTextNode()->GetParaAttr(query, 1, 4);
2046 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, query.GetItemState(RES_CHRATR_HIDDEN, false, &pItem));
2047 CPPUNIT_ASSERT(static_cast<SvxCharHiddenItem const*>(pItem)->GetValue());
2048 query.ClearItem(RES_CHRATR_HIDDEN);
2051 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUndoCharAttribute)
2053 // Create a new empty Writer document
2054 createSwDoc();
2055 SwDoc* pDoc = getSwDoc();
2056 SwCursorShell* pShell(pDoc->GetEditShell());
2057 CPPUNIT_ASSERT(pShell);
2058 SwPaM* pCursor = pShell->GetCursor();
2059 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
2060 IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
2061 // Insert some text
2062 rIDCO.InsertString(*pCursor, u"This will be bolded"_ustr);
2063 // Position of word 9876543210
2064 // Use cursor to select part of text
2065 pCursor->SetMark();
2066 for (int i = 0; i < 9; i++)
2068 pCursor->Move(fnMoveBackward);
2070 // Check that correct text was selected
2071 CPPUNIT_ASSERT_EQUAL(u"be bolded"_ustr, pCursor->GetText());
2072 // Apply a "Bold" attribute to selection
2073 SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
2074 rIDCO.InsertPoolItem(*pCursor, aWeightItem);
2075 SfxItemSet aSet(pDoc->GetAttrPool(), svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>);
2076 // Adds selected text's attributes to aSet
2077 pCursor->GetPointNode().GetTextNode()->GetParaAttr(aSet, 10, 19);
2078 SfxPoolItem const* pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
2079 // Check that bold is active on the selection; checks if it's in aSet
2080 CPPUNIT_ASSERT_EQUAL(true, (*pPoolItem == aWeightItem));
2081 // Invoke Undo
2082 rUndoManager.Undo();
2083 // Check that bold is no longer active
2084 aSet.ClearItem(RES_CHRATR_WEIGHT);
2085 pCursor->GetPointNode().GetTextNode()->GetParaAttr(aSet, 10, 19);
2086 pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
2087 CPPUNIT_ASSERT_EQUAL(false, (*pPoolItem == aWeightItem));
2090 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUndoDelAsChar)
2092 createSwDoc();
2093 SwDoc* pDoc = getSwDoc();
2094 sw::UndoManager& rUndoManager(pDoc->GetUndoManager());
2095 IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
2096 SwCursorShell* pShell(pDoc->GetEditShell());
2097 CPPUNIT_ASSERT(pShell);
2098 SfxItemSet frameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>);
2099 SfxItemSet grfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>);
2100 SwFormatAnchor anchor(RndStdIds::FLY_AS_CHAR);
2101 frameSet.Put(anchor);
2102 Graphic grf;
2103 CPPUNIT_ASSERT(rIDCO.InsertGraphic(*pShell->GetCursor(), OUString(), OUString(), &grf,
2104 &frameSet, &grfSet, nullptr));
2105 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2106 pShell->SetMark();
2107 pShell->Left(1, SwCursorSkipMode::Chars);
2108 rIDCO.DeleteAndJoin(*pShell->GetCursor());
2109 CPPUNIT_ASSERT_EQUAL(size_t(0), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2110 CPPUNIT_ASSERT(!pShell->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2111 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2112 rUndoManager.Undo();
2113 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2114 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2115 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2116 rUndoManager.Redo();
2117 CPPUNIT_ASSERT_EQUAL(size_t(0), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2118 CPPUNIT_ASSERT(!pShell->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2119 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2120 rUndoManager.Undo();
2121 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
2122 CPPUNIT_ASSERT(pShell->GetCursor()->GetPointNode().GetTextNode()->HasHints());
2123 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pShell->GetCursor()->GetPointNode().GetTextNode()->Len());
2126 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf86639)
2128 createSwDoc("tdf86639.rtf");
2129 SwDoc* pDoc = getSwDoc();
2130 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2131 SwTextFormatColl* pColl = pDoc->FindTextFormatCollByName(u"Heading"_ustr);
2132 pWrtShell->SetTextFormatColl(pColl);
2133 OUString aExpected = pColl->GetAttrSet().GetFont().GetFamilyName();
2134 // This was Calibri, should be Liberation Sans.
2135 CPPUNIT_ASSERT_EQUAL(aExpected,
2136 getProperty<OUString>(getRun(getParagraph(1), 1), u"CharFontName"_ustr));
2139 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf90883TableBoxGetCoordinates)
2141 createSwDoc("tdf90883.odt");
2142 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2143 pWrtShell->Down(true);
2144 SwSelBoxes aBoxes;
2145 ::GetTableSel(*pWrtShell, aBoxes);
2146 CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aBoxes.size()));
2147 Point pos(aBoxes[0]->GetCoordinates());
2148 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos.X()));
2149 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos.Y()));
2150 pos = aBoxes[1]->GetCoordinates();
2151 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(pos.X()));
2152 CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(pos.Y()));
2155 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testEmbeddedDataSource)
2157 // Initially no data source.
2158 uno::Reference<uno::XComponentContext> xComponentContext(
2159 comphelper::getProcessComponentContext());
2160 uno::Reference<sdb::XDatabaseContext> xDatabaseContext
2161 = sdb::DatabaseContext::create(xComponentContext);
2162 CPPUNIT_ASSERT(!xDatabaseContext->hasByName(u"calc-data-source"_ustr));
2164 // Load: should have a component and a data source, too.
2165 // Path with "#" must not cause issues
2166 createSwDoc("hash%23path/embedded-data-source.odt");
2167 CPPUNIT_ASSERT(xDatabaseContext->hasByName(u"calc-data-source"_ustr));
2169 // Data source has a table named Sheet1.
2170 uno::Reference<sdbc::XDataSource> xDataSource(
2171 xDatabaseContext->getByName(u"calc-data-source"_ustr), uno::UNO_QUERY);
2172 CPPUNIT_ASSERT(xDataSource.is());
2173 auto xConnection = xDataSource->getConnection(u""_ustr, u""_ustr);
2174 uno::Reference<container::XNameAccess> xTables
2175 = css::uno::Reference<css::sdbcx::XTablesSupplier>(xConnection, uno::UNO_QUERY_THROW)
2176 ->getTables();
2177 CPPUNIT_ASSERT(xTables.is());
2178 CPPUNIT_ASSERT(xTables->hasByName(u"Sheet1"_ustr));
2179 xConnection->close();
2181 // Reload: should still have a component and a data source, too.
2182 saveAndReload(u"writer8"_ustr);
2183 CPPUNIT_ASSERT(xDatabaseContext->hasByName(u"calc-data-source"_ustr));
2185 // Data source has a table named Sheet1 after saving to a different directory.
2186 xDataSource.set(xDatabaseContext->getByName(u"calc-data-source"_ustr), uno::UNO_QUERY);
2187 CPPUNIT_ASSERT(xDataSource.is());
2188 xConnection = xDataSource->getConnection(u""_ustr, u""_ustr);
2189 xTables = css::uno::Reference<css::sdbcx::XTablesSupplier>(xConnection, uno::UNO_QUERY_THROW)
2190 ->getTables();
2191 CPPUNIT_ASSERT(xTables.is());
2192 CPPUNIT_ASSERT(xTables->hasByName(u"Sheet1"_ustr));
2193 xConnection->close();
2195 // Close: should not have a data source anymore.
2196 mxComponent->dispose();
2197 mxComponent.clear();
2198 CPPUNIT_ASSERT(!xDatabaseContext->hasByName(u"calc-data-source"_ustr));
2200 // Now open again the saved result, and instead of 'save as', just 'save'.
2201 loadFromURL(maTempFile.GetURL());
2202 uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
2203 xStorable->store();
2206 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUnoCursorPointer)
2208 auto xDocComponent(
2209 loadFromDesktop(u"private:factory/swriter"_ustr, u"com.sun.star.text.TextDocument"_ustr));
2210 auto pxDocDocument(dynamic_cast<SwXTextDocument*>(xDocComponent.get()));
2211 CPPUNIT_ASSERT(pxDocDocument);
2212 SwDoc* const pDoc(pxDocDocument->GetDocShell()->GetDoc());
2213 std::unique_ptr<SwNodeIndex> pIdx(new SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1));
2214 std::unique_ptr<SwPosition> pPos(new SwPosition(*pIdx));
2215 sw::UnoCursorPointer pCursor(pDoc->CreateUnoCursor(*pPos));
2216 CPPUNIT_ASSERT(static_cast<bool>(pCursor));
2217 pPos.reset(); // we need to kill the SwPosition before disposing
2218 pIdx.reset(); // we need to kill the SwNodeIndex before disposing
2219 xDocComponent->dispose();
2220 CPPUNIT_ASSERT(!static_cast<bool>(pCursor));
2223 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTextTableCellNames)
2225 sal_Int32 nCol, nRow2;
2226 SwXTextTable::GetCellPosition(u"z1", nCol, nRow2);
2227 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(51), nCol);
2228 SwXTextTable::GetCellPosition(u"AA1", nCol, nRow2);
2229 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(52), nCol);
2230 SwXTextTable::GetCellPosition(u"AB1", nCol, nRow2);
2231 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(53), nCol);
2232 SwXTextTable::GetCellPosition(u"BB1", nCol, nRow2);
2233 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(105), nCol);
2236 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testShapeAnchorUndo)
2238 createSwDoc("draw-anchor-undo.odt");
2239 SwDoc* pDoc = getSwDoc();
2240 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2241 SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2242 SdrObject* pObject = pPage->GetObj(0);
2243 tools::Rectangle aOrigLogicRect(pObject->GetLogicRect());
2245 sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
2246 rUndoManager.StartUndo(SwUndoId::START, nullptr);
2248 pWrtShell->SelectObj(Point(), 0, pObject);
2250 pWrtShell->GetDrawView()->MoveMarkedObj(Size(100, 100));
2251 pWrtShell->ChgAnchor(RndStdIds::FLY_AT_PARA, true);
2253 rUndoManager.EndUndo(SwUndoId::END, nullptr);
2255 CPPUNIT_ASSERT(aOrigLogicRect != pObject->GetLogicRect());
2257 rUndoManager.Undo();
2259 CPPUNIT_ASSERT_EQUAL(pObject->GetLogicRect(), aOrigLogicRect);
2262 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf127635)
2264 createSwDoc();
2265 SwDoc* pDoc = getSwDoc();
2267 emulateTyping(u"a b");
2269 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2270 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false);
2272 //Select 'a'
2273 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false);
2275 // enable redlining
2276 dispatchCommand(mxComponent, u".uno:TrackChanges"_ustr, {});
2277 // hide
2278 dispatchCommand(mxComponent, u".uno:ShowTrackedChanges"_ustr, {});
2280 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
2281 pDoc->getIDocumentRedlineAccess().IsRedlineOn());
2282 CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
2284 emulateTyping(u"c d");
2286 SwEditShell* const pEditShell(pDoc->GetEditShell());
2287 CPPUNIT_ASSERT(pEditShell);
2288 // accept all redlines
2289 while (pEditShell->GetRedlineCount())
2290 pEditShell->AcceptRedline(0);
2292 // Without the fix in place, this test would have failed with
2293 // - Expected: C d b
2294 // - Actual : Cd b
2295 CPPUNIT_ASSERT_EQUAL(u"C d b"_ustr, getParagraph(1)->getString());
2298 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testDde)
2300 #if HAVE_FEATURE_UI
2301 Application::SetAppName(u"testDde"_ustr); // DDE needs an app name
2303 // Type asdf and copy it.
2304 createSwDoc();
2305 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2306 pWrtShell->Insert(u"asdf"_ustr);
2307 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 4, /*bBasicCall=*/false);
2308 uno::Sequence<beans::PropertyValue> aPropertyValues;
2309 dispatchCommand(mxComponent, u".uno:Copy"_ustr, aPropertyValues);
2311 // Go before the selection and paste as a DDE link.
2312 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
2313 aPropertyValues = comphelper::InitPropertySequence(
2314 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32>(SotClipboardFormatId::LINK)) } });
2315 dispatchCommand(mxComponent, u".uno:ClipboardFormatItems"_ustr, aPropertyValues);
2317 // Make sure that the document starts with a field now, and its expanded string value contains asdf.
2318 const uno::Reference<text::XTextRange> xField = getRun(getParagraph(1), 1);
2319 CPPUNIT_ASSERT_EQUAL(u"TextField"_ustr, getProperty<OUString>(xField, u"TextPortionType"_ustr));
2320 CPPUNIT_ASSERT(xField->getString().endsWith("asdf"));
2321 #endif
2324 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testDocModState)
2326 //creating a new writer document via the XDesktop(to have more shells etc.)
2327 createSwDoc();
2328 SwDoc* pDoc = getSwDoc();
2329 //checking the state of the document via IDocumentState
2330 IDocumentState& rState(pDoc->getIDocumentState());
2331 //the state should not be modified
2332 CPPUNIT_ASSERT(!(rState.IsModified()));
2333 //checking the state of the document via SfxObjectShell
2334 SwDocShell* pShell(getSwDocShell());
2335 CPPUNIT_ASSERT(!(pShell->IsModified()));
2337 IdleTask::waitUntilIdleDispatched();
2339 //again checking for the state via IDocumentState
2340 CPPUNIT_ASSERT(!(rState.IsModified()));
2341 //again checking for the state via SfxObjectShell
2342 CPPUNIT_ASSERT(!(pShell->IsModified()));
2345 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf94804)
2347 //create new writer document
2348 createSwDoc();
2349 SwDoc* pDoc = getSwDoc();
2350 //get cursor for making bookmark at a particular location
2351 SwCursorShell* pShell(pDoc->GetEditShell());
2352 CPPUNIT_ASSERT(pShell);
2353 SwPaM* pCrsr = pShell->GetCursor();
2354 IDocumentMarkAccess* pIDMAccess(pDoc->getIDocumentMarkAccess());
2355 //make first bookmark, CROSSREF_HEADING, with *empty* name
2356 sw::mark::MarkBase* pMark1(pIDMAccess->makeMark(
2357 *pCrsr, u""_ustr, IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK,
2358 ::sw::mark::InsertMode::New));
2359 //get the new(autogenerated) bookmark name
2360 OUString bookmark1name = pMark1->GetName();
2361 //match the bookmark name, it should be like "__RefHeading__**"
2362 CPPUNIT_ASSERT(bookmark1name.match("__RefHeading__"));
2363 //make second bookmark, CROSSREF_NUMITEM, with *empty* name
2364 sw::mark::MarkBase* pMark2(pIDMAccess->makeMark(
2365 *pCrsr, u""_ustr, IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK,
2366 ::sw::mark::InsertMode::New));
2367 //get the new(autogenerated) bookmark name
2368 OUString bookmark2name = pMark2->GetName();
2369 //match the bookmark name, it should be like "__RefNumPara__**"
2370 CPPUNIT_ASSERT(bookmark2name.match("__RefNumPara__"));
2373 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testUnicodeNotationToggle)
2375 createSwDoc("unicodeAltX.odt");
2376 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2377 OUString sOriginalDocString;
2378 OUString sDocString;
2379 OUString sExpectedString;
2380 uno::Sequence<beans::PropertyValue> aPropertyValues;
2382 pWrtShell->EndPara();
2383 sOriginalDocString = pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
2384 CPPUNIT_ASSERT_EQUAL(u"uU+002b"_ustr, sOriginalDocString);
2386 dispatchCommand(mxComponent, u".uno:UnicodeNotationToggle"_ustr, aPropertyValues);
2387 sExpectedString = "u+";
2388 sDocString = pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
2389 CPPUNIT_ASSERT_EQUAL(sExpectedString, sDocString);
2391 dispatchCommand(mxComponent, u".uno:UnicodeNotationToggle"_ustr, aPropertyValues);
2392 sDocString = pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
2393 CPPUNIT_ASSERT_EQUAL(sOriginalDocString, sDocString);
2395 static constexpr OUString sWithCombiningSMPName = u"xyzU+4faeU+e0101"_ustr;
2396 static constexpr OUString sWithCombiningSMP = u"xyz\U00004fae\U000e0101"_ustr;
2397 pWrtShell->SplitNode();
2398 pWrtShell->Insert2(sWithCombiningSMPName);
2399 dispatchCommand(mxComponent, u".uno:UnicodeNotationToggle"_ustr, aPropertyValues);
2400 sDocString = pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
2401 CPPUNIT_ASSERT_EQUAL(sWithCombiningSMP, sDocString);
2403 dispatchCommand(mxComponent, u".uno:UnicodeNotationToggle"_ustr, aPropertyValues);
2404 sDocString = pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
2405 // Before tdf#162656 fix, this failed with
2406 // - Expected: xyzU+4faeU+e0101
2407 // - Actual : xyxU+e0101
2408 // i.e., one codepoint to the left of the combining codepoint was removed
2409 // Before tdf#162657 fix, this failed with
2410 // - Expected: xyzU+4faeU+e0101
2411 // - Actual : xyzä¾®U+e0101
2412 // i.e., one codepoint to the left of the combining codepoint was not converted
2413 CPPUNIT_ASSERT_EQUAL(sWithCombiningSMPName, sDocString);
2416 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf34957)
2418 createSwDoc("tdf34957.odt");
2419 // table with "keep with next" always started on a new page if the table was large,
2420 // regardless of whether it was already kept with the previous paragraph,
2421 // or whether the following paragraph actually fit on the same page (MAB 3.6 - 5.0)
2422 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
2423 assertXPathContent(pXmlDoc, "/root/page[2]/body/tab[1]/row[2]/cell[1]/txt", u"Row 1");
2424 assertXPathContent(pXmlDoc, "/root/page[4]/body/tab[1]/row[2]/cell[1]/txt", u"Row 1");
2427 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf89954)
2429 createSwDoc("tdf89954.odt");
2430 SwDoc* pDoc = getSwDoc();
2431 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2432 pWrtShell->EndPara();
2433 emulateTyping(u"test.");
2435 SwNodeIndex aNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1);
2436 // Placeholder character for the comment anchor was ^A (CH_TXTATR_BREAKWORD), not <fff9> (CH_TXTATR_INWORD).
2437 // As a result, autocorrect did not turn the 't' input into 'T'.
2438 CPPUNIT_ASSERT_EQUAL(u"Tes\uFFF9t. Test."_ustr, aNodeIndex.GetNode().GetTextNode()->GetText());
2441 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf89720)
2443 createSwDoc("tdf89720.odt");
2444 SwView* pView = getSwDocShell()->GetView();
2445 SwPostItMgr* pPostItMgr = pView->GetPostItMgr();
2446 for (std::unique_ptr<SwAnnotationItem> const& pItem : *pPostItMgr)
2448 if (pItem->mpPostIt->IsFollow())
2449 // This was non-0: reply comments had a text range overlay,
2450 // resulting in unexpected dark color.
2451 CPPUNIT_ASSERT(!pItem->mpPostIt->TextRange());
2455 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf88986)
2457 // Create a text shell.
2458 createSwDoc();
2459 SwView* pView = getSwDocShell()->GetView();
2460 SwTextShell aShell(*pView);
2462 // Create the item set that is normally passed to the insert frame dialog.
2463 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2464 SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
2465 auto xSet = aShell.CreateInsertFrameItemSet(aMgr);
2467 // This was missing along with the gradient and other tables.
2468 CPPUNIT_ASSERT(xSet->HasItem(SID_COLOR_TABLE));
2471 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf78150)
2473 createSwDoc();
2474 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2475 pWrtShell->Insert(u"foobar"_ustr);
2477 CPPUNIT_ASSERT_EQUAL(u"foobar"_ustr, getParagraph(1)->getString());
2479 dispatchCommand(mxComponent, u".uno:DelToStartOfWord"_ustr, {});
2481 // Without the fix, test fails with:
2482 // equality assertion failed
2483 // - Expected:
2484 // - Actual : f
2485 CPPUNIT_ASSERT_EQUAL(u""_ustr, getParagraph(1)->getString());
2488 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf138873)
2490 createSwDoc();
2491 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2492 pWrtShell->Insert(u"A B C"_ustr);
2494 CPPUNIT_ASSERT_EQUAL(u"A B C"_ustr, getParagraph(1)->getString());
2496 // Select B
2497 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false);
2498 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false);
2500 pWrtShell->Insert(u"DDD"_ustr);
2502 CPPUNIT_ASSERT_EQUAL(u"A DDD C"_ustr, getParagraph(1)->getString());
2504 dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
2506 CPPUNIT_ASSERT_EQUAL(u"A B C"_ustr, getParagraph(1)->getString());
2508 // Select B and C
2509 pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 2, /*bBasicCall=*/false);
2511 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
2513 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
2515 // Without the fix in place, this test would have failed with
2516 // - Expected: A B C
2517 // - Actual : A CB CB
2518 CPPUNIT_ASSERT_EQUAL(u"A B C"_ustr, getParagraph(1)->getString());
2521 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf87922)
2523 // Create an SwDrawTextInfo.
2524 createSwDoc("tdf87922.odt");
2525 SwDoc* pDoc = getSwDoc();
2526 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2527 SwScriptInfo* pScriptInfo = nullptr;
2528 // Get access to the single paragraph in the document.
2529 SwNodeIndex aNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1);
2530 const OUString& rText = aNodeIndex.GetNode().GetTextNode()->GetText();
2531 sal_Int32 nLength = rText.getLength();
2532 SwDrawTextInfo aDrawTextInfo(pWrtShell, *pWrtShell->GetOut(), pScriptInfo, rText,
2533 TextFrameIndex(0), TextFrameIndex(nLength),
2534 /*layout context*/ std::nullopt);
2535 // Root -> page -> body -> text.
2536 SwTextFrame* pTextFrame
2537 = static_cast<SwTextFrame*>(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower());
2538 aDrawTextInfo.SetFrame(pTextFrame);
2540 // If no color background color is found, assume white.
2541 Color* pColor = sw::GetActiveRetoucheColor();
2542 *pColor = COL_WHITE;
2544 // Make sure that automatic color on black background is white, not black.
2545 vcl::Font aFont;
2546 aDrawTextInfo.ApplyAutoColor(&aFont);
2547 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aFont.GetColor());
2550 #if HAVE_MORE_FONTS
2551 namespace
2553 struct PortionItem
2555 PortionItem(OUString const& sItemType, sal_Int32 nLength, PortionType nTextType)
2556 : msItemType(sItemType)
2557 , mnLength(nLength)
2558 , mnTextType(nTextType)
2562 OUString msItemType;
2563 sal_Int32 mnLength;
2564 PortionType mnTextType;
2567 class PortionHandler : public SwPortionHandler
2569 public:
2570 std::vector<PortionItem> mPortionItems;
2571 explicit PortionHandler()
2572 : SwPortionHandler()
2576 void clear() { mPortionItems.clear(); }
2578 virtual void Text(TextFrameIndex nLength, PortionType nType) override
2580 mPortionItems.emplace_back("text", sal_Int32(nLength), nType);
2583 virtual void Special(TextFrameIndex nLength, const OUString& /*rText*/,
2584 PortionType nType) override
2586 mPortionItems.emplace_back("special", sal_Int32(nLength), nType);
2589 virtual void LineBreak() override
2591 mPortionItems.emplace_back("line_break", 0, PortionType::NONE);
2594 virtual void Skip(TextFrameIndex nLength) override
2596 mPortionItems.emplace_back("skip", sal_Int32(nLength), PortionType::NONE);
2599 virtual void Finish() override { mPortionItems.emplace_back("finish", 0, PortionType::NONE); }
2602 #endif
2604 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf77014)
2606 #if HAVE_MORE_FONTS
2607 // The problem described in the bug tdf#77014 is that the input
2608 // field text ("ThisIsAllOneWord") is broken up on linebreak, but
2609 // it should be in one piece (like normal text).
2611 // This test checks that the input field is in one piece and if the
2612 // input field has more words, it is broken up at the correct place.
2614 createSwDoc("tdf77014.odt");
2615 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2617 SwTextFrame* pTextFrame
2618 = static_cast<SwTextFrame*>(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower());
2620 PortionHandler aHandler;
2621 pTextFrame->VisitPortions(aHandler);
2624 // Input Field - "One Two Three Four Five" = 25 chars
2625 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, aHandler.mPortionItems[0].msItemType);
2626 CPPUNIT_ASSERT_EQUAL(sal_Int32(25), aHandler.mPortionItems[0].mnLength);
2627 CPPUNIT_ASSERT_EQUAL(PortionType::InputField, aHandler.mPortionItems[0].mnTextType);
2629 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, aHandler.mPortionItems[1].msItemType);
2631 CPPUNIT_ASSERT_EQUAL(u"finish"_ustr, aHandler.mPortionItems[2].msItemType);
2634 aHandler.clear();
2636 pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
2637 pTextFrame->VisitPortions(aHandler);
2640 // Input Field - "ThisIsAllOneWord" = 18 chars
2641 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, aHandler.mPortionItems[0].msItemType);
2642 CPPUNIT_ASSERT_EQUAL(sal_Int32(18), aHandler.mPortionItems[0].mnLength);
2643 CPPUNIT_ASSERT_EQUAL(PortionType::InputField, aHandler.mPortionItems[0].mnTextType);
2645 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, aHandler.mPortionItems[1].msItemType);
2647 CPPUNIT_ASSERT_EQUAL(u"finish"_ustr, aHandler.mPortionItems[2].msItemType);
2650 aHandler.clear();
2652 // skip empty paragraph
2653 pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
2655 pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
2656 pTextFrame->VisitPortions(aHandler);
2659 // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
2660 // = 91 chars
2661 auto& rPortionItem = aHandler.mPortionItems[0];
2662 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2663 CPPUNIT_ASSERT_EQUAL(sal_Int32(91), rPortionItem.mnLength);
2664 CPPUNIT_ASSERT_EQUAL(PortionType::Text, rPortionItem.mnTextType);
2666 // NEW LINE
2667 rPortionItem = aHandler.mPortionItems[1];
2668 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, rPortionItem.msItemType);
2670 // Input Field: "ThisIsAllOneWord" = 18 chars
2671 // which is 16 chars + 2 hidden chars (start & end input field) = 18 chars
2672 // If this is correct then the input field is in one piece
2673 rPortionItem = aHandler.mPortionItems[2];
2674 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2675 CPPUNIT_ASSERT_EQUAL(sal_Int32(18), rPortionItem.mnLength);
2676 CPPUNIT_ASSERT_EQUAL(PortionType::InputField, rPortionItem.mnTextType);
2678 // Text "."
2679 rPortionItem = aHandler.mPortionItems[3];
2680 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2681 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem.mnLength);
2682 CPPUNIT_ASSERT_EQUAL(PortionType::Text, rPortionItem.mnTextType);
2684 // NEW LINE
2685 rPortionItem = aHandler.mPortionItems[4];
2686 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, rPortionItem.msItemType);
2688 rPortionItem = aHandler.mPortionItems[5];
2689 CPPUNIT_ASSERT_EQUAL(u"finish"_ustr, rPortionItem.msItemType);
2692 aHandler.clear();
2694 pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
2695 pTextFrame->VisitPortions(aHandler);
2697 printf("Portions:\n");
2699 for (const auto& rPortionItem : aHandler.mPortionItems)
2701 printf("-- Type: %s length: %" SAL_PRIdINT32 " text type: %d\n",
2702 rPortionItem.msItemType.toUtf8().getStr(), rPortionItem.mnLength,
2703 sal_uInt16(rPortionItem.mnTextType));
2706 // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
2707 // 91 chars
2708 auto& rPortionItem = aHandler.mPortionItems[0];
2709 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2710 CPPUNIT_ASSERT_EQUAL(sal_Int32(91), rPortionItem.mnLength);
2711 CPPUNIT_ASSERT_EQUAL(PortionType::Text, rPortionItem.mnTextType);
2713 // The input field here has more words ("One Two Three Four Five")
2714 // and it should break after "Two".
2715 // Input Field: "One Two" = 7 chars + 1 start input field hidden character = 8 chars
2716 rPortionItem = aHandler.mPortionItems[1];
2717 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2718 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), rPortionItem.mnLength);
2719 CPPUNIT_ASSERT_EQUAL(PortionType::InputField, rPortionItem.mnTextType);
2721 rPortionItem = aHandler.mPortionItems[2];
2722 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2723 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem.mnLength);
2724 CPPUNIT_ASSERT_EQUAL(PortionType::Hole, rPortionItem.mnTextType);
2726 // NEW LINE
2727 rPortionItem = aHandler.mPortionItems[3];
2728 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, rPortionItem.msItemType);
2730 // Input Field: "Three Four Five" = 16 chars + 1 end input field hidden character = 16 chars
2731 rPortionItem = aHandler.mPortionItems[4];
2732 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2733 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rPortionItem.mnLength);
2734 CPPUNIT_ASSERT_EQUAL(PortionType::InputField, rPortionItem.mnTextType);
2736 // Text "."
2737 rPortionItem = aHandler.mPortionItems[5];
2738 CPPUNIT_ASSERT_EQUAL(u"text"_ustr, rPortionItem.msItemType);
2739 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rPortionItem.mnLength);
2740 CPPUNIT_ASSERT_EQUAL(PortionType::Text, rPortionItem.mnTextType);
2742 // NEW LINE
2743 rPortionItem = aHandler.mPortionItems[6];
2744 CPPUNIT_ASSERT_EQUAL(u"line_break"_ustr, rPortionItem.msItemType);
2746 rPortionItem = aHandler.mPortionItems[7];
2747 CPPUNIT_ASSERT_EQUAL(u"finish"_ustr, rPortionItem.msItemType);
2749 #endif
2752 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf92648)
2754 createSwDoc("tdf92648.docx");
2755 SwDoc* pDoc = getSwDoc();
2756 SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2757 // Make sure we have ten draw shapes.
2758 // Yes, we have if the left/right pages have different header/footer,
2759 // but if not we have only nine of them:
2760 CPPUNIT_ASSERT_EQUAL(sal_Int32(9), SwTextBoxHelper::getCount(pPage));
2761 // and the text boxes haven't got zero height
2762 sal_Int32 nCount = 0;
2763 for (const SwFrameFormat* pFormat : *pDoc->GetSpzFrameFormats())
2765 if (!SwTextBoxHelper::isTextBox(pFormat, RES_FLYFRMFMT))
2766 continue;
2767 SwFormatFrameSize aSize(pFormat->GetFrameSize());
2768 CPPUNIT_ASSERT(aSize.GetHeight() != 0);
2769 ++nCount;
2771 // and we have had five of them.
2772 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nCount);
2775 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf103978_backgroundTextShape)
2777 createSwDoc("tdf103978_backgroundTextShape.docx");
2778 SwDoc* pDoc = getSwDoc();
2780 // there is only one shape. It has an attached textbox
2781 bool bShapeIsOpaque = getProperty<bool>(getShape(1), u"Opaque"_ustr);
2782 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in the foreground", false, bShapeIsOpaque);
2783 sal_Int32 nCount = 0;
2784 for (const SwFrameFormat* pFormat : *pDoc->GetSpzFrameFormats())
2786 if (!SwTextBoxHelper::isTextBox(pFormat, RES_FLYFRMFMT))
2787 continue;
2788 CPPUNIT_ASSERT_EQUAL_MESSAGE("Textbox syncs the shape's transparency", bShapeIsOpaque,
2789 pFormat->GetOpaque().GetValue());
2790 ++nCount;
2792 //ensure that we don't skip the for loop without an error
2793 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of TextBoxes", sal_Int32(1), nCount);
2796 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf117225)
2798 // Test that saving a document with an embedded object does not leak
2799 // tempfiles in the directory of the target file.
2800 OUString aTargetDirectory
2801 = m_directories.getURLFromWorkdir(u"/CppunitTest/sw_uiwriter7.test.user/");
2802 OUString aTargetFile = aTargetDirectory + "tdf117225.odt";
2803 OUString aSourceFile = createFileURL(u"tdf117225.odt");
2804 osl::File::copy(aSourceFile, aTargetFile);
2805 loadFromURL(aTargetFile);
2806 uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
2807 int nExpected = CountFilesInDirectory(aTargetDirectory);
2808 xStorable->store();
2809 int nActual = CountFilesInDirectory(aTargetDirectory);
2810 // nActual was nExpected + 1, i.e. we leaked a tempfile.
2811 CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
2813 OUString aTargetFileSaveAs = aTargetDirectory + "tdf117225-save-as.odt";
2814 xStorable->storeAsURL(aTargetFileSaveAs, {});
2815 ++nExpected;
2816 nActual = CountFilesInDirectory(aTargetDirectory);
2817 // nActual was nExpected + 1, i.e. we leaked a tempfile.
2818 CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
2821 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf149184)
2823 createSwDoc("simplefooter.docx");
2824 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
2826 // Removing the footer for all styles
2827 pWrtShell->ChangeHeaderOrFooter(u"", false, false, false);
2829 // export to simplefooter.doc
2831 // Without the fix in place, the test fails with:
2832 // [CUT] sw_uiwriter7
2833 // Segmentation fault (core dumped)
2834 // [_RUN_____] testTdf149184::TestBody
2835 save(u"MS Word 97"_ustr);
2838 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf149089)
2840 createSwDoc("tdf149089.odt");
2841 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
2842 sal_Int32 nPorLen1 = getXPath(pXmlDoc, "(//SwLinePortion)[1]", "length").toInt32();
2843 sal_Int32 nPorLen2 = getXPath(pXmlDoc, "(//SwLinePortion)[2]", "length").toInt32();
2844 sal_Int32 nPorLen3 = getXPath(pXmlDoc, "(//SwLinePortion)[3]", "length").toInt32();
2845 // Two SwTextPortion and one SwKernPortion
2846 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), nPorLen1); // SwTextPortion "&#x4E00;&#x4E00; "
2847 CPPUNIT_ASSERT_EQUAL(sal_Int32(12), nPorLen2); // SwTextPortion "BUG 11111111"
2848 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nPorLen3); // SwKernPortion
2850 sal_Int32 nPorWidth1 = getXPath(pXmlDoc, "(//SwLinePortion)[1]", "width").toInt32();
2851 sal_Int32 nPorWidth2 = getXPath(pXmlDoc, "(//SwLinePortion)[2]", "width").toInt32();
2852 sal_Int32 nPorWidth3 = getXPath(pXmlDoc, "(//SwLinePortion)[3]", "width").toInt32();
2853 sal_Int32 nGridWidth1 = nPorWidth1 / 3;
2854 sal_Int32 nGridWidth2 = (nPorWidth2 + nPorWidth3) / 7;
2855 CPPUNIT_ASSERT_EQUAL(nGridWidth1, nGridWidth2);
2858 CPPUNIT_PLUGIN_IMPLEMENT();
2860 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */