Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : */
8 :
9 : #include <com/sun/star/i18n/TextConversionOption.hpp>
10 : #include <swmodeltestbase.hxx>
11 : #include <ndtxt.hxx>
12 : #include <wrtsh.hxx>
13 : #include <crsskip.hxx>
14 : #include <shellio.hxx>
15 : #include <expfld.hxx>
16 : #include <drawdoc.hxx>
17 : #include <docary.hxx>
18 : #include <redline.hxx>
19 : #include <section.hxx>
20 : #include <fmtclds.hxx>
21 : #include <dcontact.hxx>
22 : #include <textboxhelper.hxx>
23 : #include <view.hxx>
24 : #include <hhcwrp.hxx>
25 :
26 : #include <svx/svdpage.hxx>
27 : #include <svx/svdview.hxx>
28 :
29 : #include "UndoManager.hxx"
30 :
31 : static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
32 :
33 120 : class SwUiWriterTest : public SwModelTestBase
34 : {
35 :
36 : public:
37 : void testReplaceForward();
38 : //Regression test of fdo#70143
39 : //EDITING: undo search&replace corrupt text when searching backward
40 : void testReplaceBackward();
41 : void testFdo69893();
42 : void testFdo70807();
43 : void testImportRTF();
44 : void testExportRTF();
45 : void testFdo75110();
46 : void testFdo75898();
47 : void testFdo74981();
48 : void testShapeTextboxSelect();
49 : void testShapeTextboxDelete();
50 : void testCp1000071();
51 : void testShapeTextboxVertadjust();
52 : void testShapeTextboxAutosize();
53 : void testFdo82191();
54 : void testCommentedWord();
55 : void testChineseConversionBlank();
56 : void testChineseConversionNonChineseText();
57 : void testChineseConversionTraditionalToSimplified();
58 : void testChineseConversionSimplifiedToTraditional();
59 :
60 4 : CPPUNIT_TEST_SUITE(SwUiWriterTest);
61 2 : CPPUNIT_TEST(testReplaceForward);
62 2 : CPPUNIT_TEST(testReplaceBackward);
63 2 : CPPUNIT_TEST(testFdo69893);
64 2 : CPPUNIT_TEST(testFdo70807);
65 2 : CPPUNIT_TEST(testImportRTF);
66 2 : CPPUNIT_TEST(testExportRTF);
67 2 : CPPUNIT_TEST(testFdo75110);
68 2 : CPPUNIT_TEST(testFdo75898);
69 2 : CPPUNIT_TEST(testFdo74981);
70 2 : CPPUNIT_TEST(testShapeTextboxSelect);
71 2 : CPPUNIT_TEST(testShapeTextboxDelete);
72 2 : CPPUNIT_TEST(testCp1000071);
73 2 : CPPUNIT_TEST(testShapeTextboxVertadjust);
74 2 : CPPUNIT_TEST(testShapeTextboxAutosize);
75 2 : CPPUNIT_TEST(testFdo82191);
76 2 : CPPUNIT_TEST(testCommentedWord);
77 2 : CPPUNIT_TEST(testChineseConversionBlank);
78 2 : CPPUNIT_TEST(testChineseConversionNonChineseText);
79 2 : CPPUNIT_TEST(testChineseConversionTraditionalToSimplified);
80 2 : CPPUNIT_TEST(testChineseConversionSimplifiedToTraditional);
81 :
82 4 : CPPUNIT_TEST_SUITE_END();
83 :
84 : private:
85 : SwDoc* createDoc(const char* pName = 0);
86 : };
87 :
88 38 : SwDoc* SwUiWriterTest::createDoc(const char* pName)
89 : {
90 38 : if (!pName)
91 18 : pName = "empty.odt";
92 38 : load(DATA_DIRECTORY, pName);
93 :
94 38 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
95 38 : CPPUNIT_ASSERT(pTxtDoc);
96 38 : return pTxtDoc->GetDocShell()->GetDoc();
97 : }
98 :
99 : //Replacement tests
100 :
101 4 : static void lcl_selectCharacters(SwPaM& rPaM, sal_Int32 first, sal_Int32 end)
102 : {
103 4 : rPaM.GetPoint()->nContent.Assign(rPaM.GetCntntNode(), first);
104 4 : rPaM.SetMark();
105 4 : rPaM.GetPoint()->nContent.Assign(rPaM.GetCntntNode(), end);
106 4 : }
107 :
108 2 : static const OUString ORIGINAL_REPLACE_CONTENT("toto titi tutu");
109 2 : static const OUString EXPECTED_REPLACE_CONTENT("toto toto tutu");
110 :
111 2 : void SwUiWriterTest::testReplaceForward()
112 : {
113 2 : SwDoc* pDoc = createDoc();
114 :
115 2 : sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
116 :
117 2 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
118 4 : SwPaM aPaM(aIdx);
119 :
120 2 : pDoc->getIDocumentContentOperations().InsertString(aPaM, ORIGINAL_REPLACE_CONTENT);
121 :
122 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
123 2 : lcl_selectCharacters(aPaM, 5, 9);
124 2 : pDoc->getIDocumentContentOperations().ReplaceRange(aPaM, OUString("toto"), false);
125 :
126 2 : CPPUNIT_ASSERT_EQUAL(EXPECTED_REPLACE_CONTENT, pTxtNode->GetTxt());
127 :
128 2 : rUndoManager.Undo();
129 :
130 4 : CPPUNIT_ASSERT_EQUAL(ORIGINAL_REPLACE_CONTENT, pTxtNode->GetTxt());
131 2 : }
132 :
133 2 : void SwUiWriterTest::testFdo75110()
134 : {
135 2 : SwDoc* pDoc = createDoc("fdo75110.odt");
136 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
137 :
138 2 : pWrtShell->SelAll();
139 : // The problem was that SwEditShell::DeleteSel() what this Delete() invokes took the wrong selection...
140 2 : pWrtShell->Delete();
141 2 : sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
142 : // ... so this Undo() call resulted in a crash.
143 2 : rUndoManager.Undo();
144 2 : }
145 :
146 2 : void SwUiWriterTest::testFdo75898()
147 : {
148 2 : SwDoc* pDoc = createDoc("fdo75898.odt");
149 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
150 2 : pWrtShell->SelAll();
151 2 : pWrtShell->InsertRow(1, true);
152 2 : pWrtShell->InsertRow(1, true);
153 :
154 : // Now check if the table has 3 lines.
155 2 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
156 2 : SwTableNode* pTableNode = pShellCrsr->Start()->nNode.GetNode().FindTableNode();
157 : // This was 1, when doing the same using the UI, Writer even crashed.
158 2 : CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pTableNode->GetTable().GetTabLines().size());
159 2 : }
160 :
161 2 : void SwUiWriterTest::testReplaceBackward()
162 : {
163 2 : SwDoc* pDoc = createDoc();
164 :
165 2 : sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
166 :
167 2 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
168 4 : SwPaM aPaM(aIdx);
169 :
170 2 : pDoc->getIDocumentContentOperations().InsertString(aPaM, OUString("toto titi tutu"));
171 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
172 2 : lcl_selectCharacters(aPaM, 9, 5);
173 :
174 2 : pDoc->getIDocumentContentOperations().ReplaceRange(aPaM, OUString("toto"), false);
175 :
176 2 : CPPUNIT_ASSERT_EQUAL(EXPECTED_REPLACE_CONTENT, pTxtNode->GetTxt());
177 :
178 2 : rUndoManager.Undo();
179 :
180 4 : CPPUNIT_ASSERT_EQUAL(ORIGINAL_REPLACE_CONTENT, pTxtNode->GetTxt());
181 2 : }
182 :
183 2 : void SwUiWriterTest::testFdo69893()
184 : {
185 2 : SwDoc* pDoc = createDoc("fdo69893.odt");
186 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
187 :
188 2 : pWrtShell->SelAll();
189 :
190 2 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
191 2 : SwTxtNode& rEnd = dynamic_cast<SwTxtNode&>(pShellCrsr->End()->nNode.GetNode());
192 : // Selection did not include the para after table, this was "B1".
193 2 : CPPUNIT_ASSERT_EQUAL(OUString("Para after table."), rEnd.GetTxt());
194 2 : }
195 :
196 2 : void SwUiWriterTest::testFdo70807()
197 : {
198 2 : load(DATA_DIRECTORY, "fdo70807.odt");
199 :
200 2 : uno::Reference<container::XIndexAccess> stylesIter(getStyles("PageStyles"), uno::UNO_QUERY);
201 :
202 26 : for (sal_Int32 i = 0; i < stylesIter->getCount(); ++i)
203 : {
204 24 : uno::Reference<style::XStyle> xStyle(stylesIter->getByIndex(i), uno::UNO_QUERY);
205 48 : uno::Reference<container::XNamed> xName(xStyle, uno::UNO_QUERY);
206 :
207 24 : bool expectedUsedStyle = false;
208 24 : bool expectedUserDefined = false;
209 :
210 48 : OUString styleName(xName->getName());
211 :
212 : // just these styles are user defined styles
213 24 : if (styleName == "pagestyle1" || styleName == "pagestyle2")
214 4 : expectedUserDefined = true;
215 :
216 : // just these styles are used in the document
217 24 : if (styleName == "Right Page" || styleName == "pagestyle1" || styleName == "pagestyle2")
218 6 : expectedUsedStyle = true;
219 :
220 24 : CPPUNIT_ASSERT_EQUAL(expectedUserDefined, bool(xStyle->isUserDefined()));
221 24 : CPPUNIT_ASSERT_EQUAL(expectedUsedStyle, bool(xStyle->isInUse()));
222 26 : }
223 2 : }
224 :
225 2 : void SwUiWriterTest::testImportRTF()
226 : {
227 : // Insert "foobar" and position the cursor between "foo" and "bar".
228 2 : SwDoc* pDoc = createDoc();
229 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
230 2 : pWrtShell->Insert("foobar");
231 2 : pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 3, /*bBasicCall=*/false);
232 :
233 : // Insert the RTF at the cursor position.
234 2 : OString aData = "{\\rtf1 Hello world!\\par}";
235 4 : SvMemoryStream aStream(const_cast<sal_Char*>(aData.getStr()), aData.getLength(), STREAM_READ);
236 4 : SwReader aReader(aStream, OUString(), OUString(), *pWrtShell->GetCrsr());
237 2 : Reader* pRTFReader = SwReaderWriter::GetReader(READER_WRITER_RTF);
238 2 : CPPUNIT_ASSERT(pRTFReader != 0);
239 2 : CPPUNIT_ASSERT_EQUAL(sal_uLong(0), aReader.Read(*pRTFReader));
240 :
241 2 : sal_uLong nIndex = pWrtShell->GetCrsr()->GetNode().GetIndex();
242 2 : CPPUNIT_ASSERT_EQUAL(OUString("fooHello world!"), static_cast<SwTxtNode*>(pDoc->GetNodes()[nIndex - 1])->GetTxt());
243 4 : CPPUNIT_ASSERT_EQUAL(OUString("bar"), static_cast<SwTxtNode*>(pDoc->GetNodes()[nIndex])->GetTxt());
244 2 : }
245 :
246 2 : void SwUiWriterTest::testExportRTF()
247 : {
248 : // Insert "aaabbbccc" and select "bbb".
249 2 : SwDoc* pDoc = createDoc();
250 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
251 2 : pWrtShell->Insert("aaabbbccc");
252 2 : pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 3, /*bBasicCall=*/false);
253 2 : pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 3, /*bBasicCall=*/false);
254 :
255 : // Create the clipboard document.
256 2 : boost::shared_ptr<SwDoc> pClpDoc(new SwDoc());
257 2 : pClpDoc->SetClipBoard(true);
258 2 : pWrtShell->Copy(pClpDoc.get());
259 :
260 : // And finally export it as RTF.
261 4 : WriterRef xWrt;
262 2 : SwReaderWriter::GetWriter("RTF", OUString(), xWrt);
263 4 : SvMemoryStream aStream;
264 4 : SwWriter aWrt(aStream, *pClpDoc);
265 2 : aWrt.Write(xWrt);
266 :
267 4 : OString aData(static_cast<const sal_Char*>(aStream.GetBuffer()), aStream.GetSize());
268 :
269 : //Amusingly eventually there was a commit id with "ccc" in it, and so the rtf contained
270 : //{\*\generator LibreOfficeDev/4.4.0.0.alpha0$Linux_X86_64 LibreOffice_project/f70664ccc6837f2cc21a29bb4f44e41e100efe6b}
271 : //so the test fell over. so strip the generator tag
272 2 : sal_Int32 nGeneratorStart = aData.indexOf("{\\*\\generator ");
273 2 : CPPUNIT_ASSERT(nGeneratorStart != -1);
274 2 : sal_Int32 nGeneratorEnd = aData.indexOf('}', nGeneratorStart + 1);
275 2 : CPPUNIT_ASSERT(nGeneratorEnd != -1);
276 2 : aData = aData.replaceAt(nGeneratorStart, nGeneratorEnd-nGeneratorStart+1, "");
277 :
278 2 : CPPUNIT_ASSERT(aData.startsWith("{\\rtf1"));
279 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aData.indexOf("aaa"));
280 2 : CPPUNIT_ASSERT(aData.indexOf("bbb") != -1);
281 4 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aData.indexOf("ccc"));
282 2 : }
283 :
284 2 : void SwUiWriterTest::testFdo74981()
285 : {
286 : // create a document with an input field
287 2 : SwDoc* pDoc = createDoc();
288 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
289 2 : SwInputField aField((SwInputFieldType*)pWrtShell->GetFldType(0, RES_INPUTFLD), OUString("foo"), OUString("bar"), 0, 0);
290 2 : pWrtShell->Insert(aField);
291 :
292 : // expect hints
293 4 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
294 2 : SwTxtNode* pTxtNode = aIdx.GetNode().GetTxtNode();
295 2 : CPPUNIT_ASSERT(pTxtNode->HasHints());
296 :
297 : // go to the begin of the paragraph and split this node
298 2 : pWrtShell->Left(CRSR_SKIP_CHARS, false, 100, false);
299 2 : pWrtShell->SplitNode();
300 :
301 : // expect only the second paragraph to have hints
302 2 : aIdx = SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1);
303 2 : pTxtNode = aIdx.GetNode().GetTxtNode();
304 2 : CPPUNIT_ASSERT(pTxtNode->HasHints());
305 2 : aIdx--;
306 2 : pTxtNode = aIdx.GetNode().GetTxtNode();
307 4 : CPPUNIT_ASSERT(!pTxtNode->HasHints());
308 2 : }
309 :
310 2 : void SwUiWriterTest::testShapeTextboxSelect()
311 : {
312 2 : SwDoc* pDoc = createDoc("shape-textbox.odt");
313 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
314 2 : SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
315 2 : SdrObject* pObject = pPage->GetObj(1);
316 2 : SwContact* pTextBox = static_cast<SwContact*>(pObject->GetUserCall());
317 : // First, make sure that pTextBox is a fly frame (textbox of a shape).
318 2 : CPPUNIT_ASSERT_EQUAL(RES_FLYFRMFMT, static_cast<RES_FMT>(pTextBox->GetFmt()->Which()));
319 :
320 : // Then select it.
321 2 : pWrtShell->SelectObj(Point(), 0, pObject);
322 2 : const SdrMarkList& rMarkList = pWrtShell->GetDrawView()->GetMarkedObjectList();
323 2 : SwDrawContact* pShape = static_cast<SwDrawContact*>(rMarkList.GetMark(0)->GetMarkedSdrObj()->GetUserCall());
324 : // And finally make sure the shape got selected, not just the textbox itself.
325 2 : CPPUNIT_ASSERT_EQUAL(RES_DRAWFRMFMT, static_cast<RES_FMT>(pShape->GetFmt()->Which()));
326 2 : }
327 :
328 2 : void SwUiWriterTest::testShapeTextboxDelete()
329 : {
330 2 : SwDoc* pDoc = createDoc("shape-textbox.odt");
331 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
332 2 : SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
333 2 : SdrObject* pObject = pPage->GetObj(0);
334 2 : pWrtShell->SelectObj(Point(), 0, pObject);
335 2 : size_t nActual = pPage->GetObjCount();
336 : // Two objects on the draw page: the shape and its textbox.
337 2 : CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), nActual);
338 :
339 2 : pWrtShell->DelSelectedObj();
340 2 : nActual = pPage->GetObjCount();
341 : // Both (not only the shape) should be removed by now (the textbox wasn't removed, so this was 1).
342 2 : CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), nActual);
343 2 : }
344 :
345 2 : void SwUiWriterTest::testCp1000071()
346 : {
347 2 : SwDoc* pDoc = createDoc("cp1000071.odt");
348 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
349 :
350 2 : const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl();
351 2 : CPPUNIT_ASSERT_EQUAL( size_t( 2 ), rTbl.size());
352 2 : sal_uLong redlineStart0NodeIndex = rTbl[ 0 ]->Start()->nNode.GetIndex();
353 2 : sal_Int32 redlineStart0Index = rTbl[ 0 ]->Start()->nContent.GetIndex();
354 2 : sal_uLong redlineEnd0NodeIndex = rTbl[ 0 ]->End()->nNode.GetIndex();
355 2 : sal_Int32 redlineEnd0Index = rTbl[ 0 ]->End()->nContent.GetIndex();
356 2 : sal_uLong redlineStart1NodeIndex = rTbl[ 1 ]->Start()->nNode.GetIndex();
357 2 : sal_Int32 redlineStart1Index = rTbl[ 1 ]->Start()->nContent.GetIndex();
358 2 : sal_uLong redlineEnd1NodeIndex = rTbl[ 1 ]->End()->nNode.GetIndex();
359 2 : sal_Int32 redlineEnd1Index = rTbl[ 1 ]->End()->nContent.GetIndex();
360 :
361 : // Change the document layout to be 2 columns, and then undo.
362 2 : pWrtShell->SelAll();
363 2 : SwSectionData section(CONTENT_SECTION, pWrtShell->GetUniqueSectionName());
364 4 : SfxItemSet set( pDoc->GetDocShell()->GetPool(), RES_COL, RES_COL, 0 );
365 4 : SwFmtCol col;
366 2 : col.Init( 2, 0, 10000 );
367 2 : set.Put( col );
368 2 : pWrtShell->InsertSection( section, &set );
369 2 : sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
370 2 : rUndoManager.Undo();
371 :
372 : // Check that redlines are the same like at the beginning.
373 2 : CPPUNIT_ASSERT_EQUAL( size_t( 2 ), rTbl.size());
374 2 : CPPUNIT_ASSERT_EQUAL( redlineStart0NodeIndex, rTbl[ 0 ]->Start()->nNode.GetIndex());
375 2 : CPPUNIT_ASSERT_EQUAL( redlineStart0Index, rTbl[ 0 ]->Start()->nContent.GetIndex());
376 2 : CPPUNIT_ASSERT_EQUAL( redlineEnd0NodeIndex, rTbl[ 0 ]->End()->nNode.GetIndex());
377 2 : CPPUNIT_ASSERT_EQUAL( redlineEnd0Index, rTbl[ 0 ]->End()->nContent.GetIndex());
378 2 : CPPUNIT_ASSERT_EQUAL( redlineStart1NodeIndex, rTbl[ 1 ]->Start()->nNode.GetIndex());
379 2 : CPPUNIT_ASSERT_EQUAL( redlineStart1Index, rTbl[ 1 ]->Start()->nContent.GetIndex());
380 2 : CPPUNIT_ASSERT_EQUAL( redlineEnd1NodeIndex, rTbl[ 1 ]->End()->nNode.GetIndex());
381 4 : CPPUNIT_ASSERT_EQUAL( redlineEnd1Index, rTbl[ 1 ]->End()->nContent.GetIndex());
382 2 : }
383 :
384 2 : void SwUiWriterTest::testShapeTextboxVertadjust()
385 : {
386 2 : SwDoc* pDoc = createDoc("shape-textbox-vertadjust.odt");
387 2 : SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
388 2 : SdrObject* pObject = pPage->GetObj(1);
389 2 : SwFrmFmt* pFmt = static_cast<SwContact*>(pObject->GetUserCall())->GetFmt();
390 : // This was SDRTEXTVERTADJUST_TOP.
391 2 : CPPUNIT_ASSERT_EQUAL(SDRTEXTVERTADJUST_CENTER, pFmt->GetTextVertAdjust().GetValue());
392 2 : }
393 :
394 2 : void SwUiWriterTest::testShapeTextboxAutosize()
395 : {
396 2 : SwDoc* pDoc = createDoc("shape-textbox-autosize.odt");
397 2 : SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
398 2 : SdrObject* pFirst = pPage->GetObj(0);
399 2 : CPPUNIT_ASSERT_EQUAL(OUString("1st"), pFirst->GetName());
400 :
401 2 : SdrObject* pSecond = pPage->GetObj(1);
402 2 : CPPUNIT_ASSERT_EQUAL(OUString("2nd"), pSecond->GetName());
403 :
404 : // Shape -> textbox synchronization was missing, the second shape had the
405 : // same height as the first, even though the first contained 1 paragraph
406 : // and the other 2 ones.
407 2 : CPPUNIT_ASSERT(pFirst->GetSnapRect().getHeight() < pSecond->GetSnapRect().getHeight());
408 2 : }
409 :
410 2 : void SwUiWriterTest::testFdo82191()
411 : {
412 2 : SwDoc* pDoc = createDoc("fdo82191.odt");
413 2 : SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
414 2 : std::set<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
415 : // Make sure we have a single draw shape.
416 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), SwTextBoxHelper::getCount(pPage, aTextBoxes));
417 :
418 4 : SwDoc aClipboard;
419 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
420 2 : SdrObject* pObject = pPage->GetObj(0);
421 : // Select it, then copy and paste.
422 2 : pWrtShell->SelectObj(Point(), 0, pObject);
423 2 : pWrtShell->Copy(&aClipboard);
424 2 : pWrtShell->Paste(&aClipboard);
425 :
426 2 : aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
427 : // This was one: the textbox of the shape wasn't copied.
428 4 : CPPUNIT_ASSERT_EQUAL(size_t(2), aTextBoxes.size());
429 2 : }
430 :
431 2 : void SwUiWriterTest::testCommentedWord()
432 : {
433 : // This word is commented. <- string in document
434 : // 123456789 <- character positions
435 2 : SwDoc* pDoc = createDoc("commented-word.odt");
436 2 : SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
437 : // Move the cursor into the second word.
438 2 : pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 5, /*bBasicCall=*/false);
439 : // Select the word.
440 2 : pWrtShell->SelWrd();
441 :
442 : // Make sure that not only the word, but its comment anchor is also selected.
443 2 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
444 : // This was 9, only "word", not "word<anchor character>" was selected.
445 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(10), pShellCrsr->End()->nContent.GetIndex());
446 2 : }
447 :
448 :
449 : // Chinese conversion tests
450 :
451 2 : static const OUString CHINESE_TRADITIONAL_CONTENT(sal_Unicode(0x9F8D));
452 2 : static const OUString CHINESE_SIMPLIFIED_CONTENT(sal_Unicode(0x9F99));
453 2 : static const OUString NON_CHINESE_CONTENT ("Hippopotamus");
454 :
455 : // Tests that a blank document is still blank after conversion
456 2 : void SwUiWriterTest::testChineseConversionBlank()
457 : {
458 :
459 : // Given
460 2 : SwDoc* pDoc = createDoc();
461 2 : SwView* pView = pDoc->GetDocShell()->GetView();
462 2 : const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
463 4 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
464 4 : SwPaM aPaM(aIdx);
465 :
466 : // When
467 : SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
468 : i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
469 4 : true, false, false );
470 2 : aWrap.Convert();
471 :
472 :
473 : // Then
474 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
475 4 : CPPUNIT_ASSERT_EQUAL(OUString(), pTxtNode->GetTxt());
476 :
477 2 : }
478 :
479 : // Tests that non Chinese text is unchanged after conversion
480 2 : void SwUiWriterTest::testChineseConversionNonChineseText()
481 : {
482 :
483 : // Given
484 2 : SwDoc* pDoc = createDoc();
485 2 : SwView* pView = pDoc->GetDocShell()->GetView();
486 2 : const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
487 4 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
488 4 : SwPaM aPaM(aIdx);
489 2 : pDoc->getIDocumentContentOperations().InsertString(aPaM, NON_CHINESE_CONTENT);
490 :
491 :
492 : // When
493 : SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
494 : i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
495 4 : true, false, false );
496 2 : aWrap.Convert();
497 :
498 :
499 : // Then
500 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
501 4 : CPPUNIT_ASSERT_EQUAL(NON_CHINESE_CONTENT, pTxtNode->GetTxt());
502 :
503 2 : }
504 :
505 : // Tests conversion of traditional Chinese characters to simplified Chinese
506 2 : void SwUiWriterTest::testChineseConversionTraditionalToSimplified()
507 : {
508 :
509 : // Given
510 2 : SwDoc* pDoc = createDoc();
511 2 : SwView* pView = pDoc->GetDocShell()->GetView();
512 2 : const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
513 4 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
514 4 : SwPaM aPaM(aIdx);
515 2 : pDoc->getIDocumentContentOperations().InsertString(aPaM, CHINESE_TRADITIONAL_CONTENT);
516 :
517 :
518 : // When
519 : SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
520 : i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
521 4 : true, false, false );
522 2 : aWrap.Convert();
523 :
524 :
525 : // Then
526 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
527 4 : CPPUNIT_ASSERT_EQUAL(CHINESE_SIMPLIFIED_CONTENT, pTxtNode->GetTxt());
528 :
529 2 : }
530 :
531 : // Tests conversion of simplified Chinese characters to traditional Chinese
532 2 : void SwUiWriterTest::testChineseConversionSimplifiedToTraditional()
533 : {
534 :
535 : // Given
536 2 : SwDoc* pDoc = createDoc();
537 2 : SwView* pView = pDoc->GetDocShell()->GetView();
538 2 : const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
539 4 : SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
540 4 : SwPaM aPaM(aIdx);
541 2 : pDoc->getIDocumentContentOperations().InsertString(aPaM, CHINESE_SIMPLIFIED_CONTENT);
542 :
543 :
544 : // When
545 : SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_SIMPLIFIED, LANGUAGE_CHINESE_TRADITIONAL, NULL,
546 : i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
547 4 : true, false, false );
548 2 : aWrap.Convert();
549 :
550 :
551 : // Then
552 2 : SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
553 4 : CPPUNIT_ASSERT_EQUAL(CHINESE_TRADITIONAL_CONTENT, pTxtNode->GetTxt());
554 :
555 2 : }
556 :
557 :
558 2 : CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
559 8 : CPPUNIT_PLUGIN_IMPLEMENT();
560 :
561 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|