1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <swmodeltestbase.hxx>
#include <officecfg/Office/Common.hxx>
#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/table/TableBorder2.hpp>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/text/XPageCursor.hpp>
#include <com/sun/star/text/XParagraphCursor.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <comphelper/lok.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/configuration.hxx>
#include <swdtflvr.hxx>
#include <o3tl/string_view.hxx>
#include <editeng/acorrcfg.hxx>
#include <swacorr.hxx>
#include <sfx2/linkmgr.hxx>
#include <scriptinfo.hxx>
#include <txtfrm.hxx>
#include <edtwin.hxx>
#include <view.hxx>
#include <wrtsh.hxx>
#include <unotxdoc.hxx>
#include <itabenum.hxx>
#include <ndtxt.hxx>
#include <toxmgr.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <IDocumentLinksAdministration.hxx>
#include <fmtinfmt.hxx>
#include <rootfrm.hxx>
#include <svx/svdview.hxx>
#include <svx/svdmark.hxx>
namespace
{
class SwUiWriterTest9 : public SwModelTestBase
{
public:
SwUiWriterTest9()
: SwModelTestBase(u"/sw/qa/extras/uiwriter/data/"_ustr)
{
}
};
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158785)
{
// given a document with a hyperlink surrounded by N-dashes (–www.dordt.edu–)
createSwDoc("tdf158785_hyperlink.fodt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// go to the end of the hyperlink
pWrtShell->SttEndDoc(/*bStart=*/false);
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
// get last point that will be part of the hyperlink (current position 1pt wide).
Point aLogicL(pWrtShell->GetCharRect().Center());
Point aLogicR(aLogicL);
// sanity check - we really are right by the hyperlink
aLogicL.AdjustX(-1);
SwContentAtPos aContentAtPos(IsAttrAtPos::InetAttr);
pWrtShell->GetContentAtPos(aLogicL, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::InetAttr, aContentAtPos.eContentAtPos);
// The test: the position of the N-dash should not indicate hyperlink properties
// cursor pos would NOT be considered part of the hyperlink, but increase for good measure...
aLogicR.AdjustX(1);
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
/*
* tdf#111969: the beginning of the hyperlink should allow the right-click menu to remove it
*/
// move cursor (with no selection) to the start of the hyperlink - after the N-dash
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
aLogicL = pWrtShell->GetCharRect().Center();
aLogicR = aLogicL;
// sanity check - we really are right in front of the hyperlink
aLogicL.AdjustX(-1);
aContentAtPos = IsAttrAtPos::InetAttr;
pWrtShell->GetContentAtPos(aLogicL, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
aLogicR.AdjustX(1);
aContentAtPos = IsAttrAtPos::InetAttr;
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::InetAttr, aContentAtPos.eContentAtPos);
// Remove the hyperlink
dispatchCommand(mxComponent, u".uno:RemoveHyperlink"_ustr, {});
// The test: was the hyperlink actually removed?
aContentAtPos = IsAttrAtPos::InetAttr;
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159377)
{
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2);
pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {});
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
pWrtShell->InsertFootnote(u""_ustr);
CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote());
CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count());
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
// this pasted the 4 text nodes in the table, but no table nodes
// as currently tables aren't allowed in footnotes
CPPUNIT_ASSERT_EQUAL(SwNodeOffset(32), pDoc->GetNodes().Count());
pWrtShell->Undo();
CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote());
// problem was that this was 29 with an extra text node in the footnote
CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count());
pWrtShell->Redo();
CPPUNIT_ASSERT_EQUAL(SwNodeOffset(32), pDoc->GetNodes().Count());
pWrtShell->Undo();
CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testPasteTableInMiddleOfParagraph)
{
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2);
pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {});
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
pWrtShell->Undo();
pWrtShell->Insert(u"AB"_ustr);
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
pWrtShell->Undo();
// the problem was that the A was missing
CPPUNIT_ASSERT_EQUAL(OUString("AB"),
pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
pWrtShell->Redo();
pWrtShell->Undo();
CPPUNIT_ASSERT_EQUAL(OUString("AB"),
pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf111969)
{
// given a document with a field surrounded by N-dashes (–date–)
createSwDoc("tdf111969_field.fodt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// go to the end of the field
pWrtShell->SttEndDoc(/*bStart=*/false);
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
// get last point that will be part of the field (current position 1pt wide).
Point aLogicL(pWrtShell->GetCharRect().Center());
Point aLogicR(aLogicL);
// sanity check - we really are at the right edge of the field
aLogicR.AdjustX(1);
SwContentAtPos aContentAtPos(IsAttrAtPos::Field);
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
aLogicL.AdjustX(-1);
aContentAtPos = IsAttrAtPos::Field;
pWrtShell->GetContentAtPos(aLogicL, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::Field, aContentAtPos.eContentAtPos);
// the test: simulate a right-click of a mouse which sets the cursor and then acts on that pos.
pWrtShell->SwCursorShell::SetCursor(aLogicL, false, /*Block=*/false, /*FieldInfo=*/true);
CPPUNIT_ASSERT(pWrtShell->GetCurField(true));
/*
* An edge case at the start of a field - don't start the field menu on the first N-dash
*/
// go to the start of the field
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
// get first point that will be part of the field (current position 1pt wide).
aLogicL = pWrtShell->GetCharRect().Center();
aLogicR = aLogicL;
// sanity check - we really are at the left edge of the field
aLogicR.AdjustX(1);
aContentAtPos = IsAttrAtPos::Field;
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::Field, aContentAtPos.eContentAtPos);
aLogicL.AdjustX(-1);
aContentAtPos = IsAttrAtPos::Field;
pWrtShell->GetContentAtPos(aLogicL, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
// the test: simulate a right-click of a mouse (at the end-edge of the N-dash)
// which sets the cursor and then acts on that pos.
pWrtShell->SwCursorShell::SetCursor(aLogicL, false, /*Block=*/false, /*FieldInfo=*/true);
CPPUNIT_ASSERT(!pWrtShell->GetCurField(true));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf111969B)
{
// given a document with a field surrounded by two N-dashes (––date––)
createSwDoc("tdf111969_fieldB.fodt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// go to the start of the field
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false);
// get first point that will be part of the field (current position 1pt wide).
Point aLogicL(pWrtShell->GetCharRect().Center());
Point aLogicR(aLogicL);
// sanity check - we really are at the left edge of the field
aLogicR.AdjustX(1);
SwContentAtPos aContentAtPos(IsAttrAtPos::Field);
pWrtShell->GetContentAtPos(aLogicR, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::Field, aContentAtPos.eContentAtPos);
aLogicL.AdjustX(-1);
aContentAtPos = IsAttrAtPos::Field;
pWrtShell->GetContentAtPos(aLogicL, aContentAtPos);
CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos);
// the test: simulate a right-click of a mouse (at the end-edge of the second N-dash)
// which sets the cursor and then acts on that pos.
pWrtShell->SwCursorShell::SetCursor(aLogicL, false, /*Block=*/false, /*FieldInfo=*/true);
CPPUNIT_ASSERT(!pWrtShell->GetCurField(true));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159049)
{
// The document contains a shape which has a text with a line break. When copying the text to
// clipboard the line break was missing in the RTF flavor of the clipboard.
createSwDoc("tdf159049_LineBreakRTFClipboard.fodt");
CPPUNIT_ASSERT_EQUAL(1, getShapes());
selectShape(1);
// Bring shape into text edit mode
SwXTextDocument* pTextDoc = getSwTextDoc();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
// Copy text
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
// Deactivate text edit mode ...
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_ESCAPE);
Scheduler::ProcessEventsToIdle();
// ... and deselect shape.
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_ESCAPE);
Scheduler::ProcessEventsToIdle();
// Paste special as RTF
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "SelectedFormat", uno::Any(static_cast<sal_uInt32>(SotClipboardFormatId::RTF)) } }));
dispatchCommand(mxComponent, u".uno:ClipboardFormatItems"_ustr, aArgs);
// Without fix Actual was "Abreakhere", the line break \n was missing.
CPPUNIT_ASSERT_EQUAL(u"Abreak\nhere"_ustr, getParagraph(1)->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf135083)
{
createSwDoc("tdf135083-simple-text-plus-list.fodt");
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
// Paste special as RTF
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { u"SelectedFormat"_ustr,
uno::Any(static_cast<sal_uInt32>(SotClipboardFormatId::RTF)) } }));
dispatchCommand(mxComponent, u".uno:ClipboardFormatItems"_ustr, aArgs);
auto xLastPara = getParagraph(3);
CPPUNIT_ASSERT_EQUAL(u"dolor"_ustr, xLastPara->getString());
// Without the fix in place, the last paragraph would loose its settings. ListId would be empty.
CPPUNIT_ASSERT(!getProperty<OUString>(xLastPara, u"ListId"_ustr).isEmpty());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testHiddenSectionsAroundPageBreak)
{
createSwDoc("hiddenSectionsAroundPageBreak.fodt");
CPPUNIT_ASSERT_EQUAL(1, getPages());
auto xModel(mxComponent.queryThrow<frame::XModel>());
auto xTextViewCursorSupplier(
xModel->getCurrentController().queryThrow<text::XTextViewCursorSupplier>());
auto xCursor(xTextViewCursorSupplier->getViewCursor().queryThrow<text::XPageCursor>());
// Make sure that the page style is set correctly
xCursor->jumpToFirstPage();
CPPUNIT_ASSERT_EQUAL(u"Landscape"_ustr, getProperty<OUString>(xCursor, u"PageStyleName"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159565)
{
// Given a document with a hidden section in the beginning, additionally containing a frame
createSwDoc("FrameInHiddenSection.fodt");
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
// Check that the selection covers the whole visible text
auto xModel(mxComponent.queryThrow<css::frame::XModel>());
auto xSelSupplier(xModel->getCurrentController().queryThrow<css::view::XSelectionSupplier>());
auto xSelections(xSelSupplier->getSelection().queryThrow<css::container::XIndexAccess>());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelections->getCount());
auto xSelection(xSelections->getByIndex(0).queryThrow<css::text::XTextRange>());
// Without the fix, this would fail - there was no selection
CPPUNIT_ASSERT_EQUAL(u"" SAL_NEWLINE_STRING SAL_NEWLINE_STRING "ipsum"_ustr,
xSelection->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159816)
{
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// Add 5 empty paragraphs
pWrtShell->SplitNode();
pWrtShell->SplitNode();
pWrtShell->SplitNode();
pWrtShell->SplitNode();
pWrtShell->SplitNode();
// Add a bookmark at the very end
IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess());
rIDMA.makeMark(*pWrtShell->GetCursor(), u"Mark"_ustr, IDocumentMarkAccess::MarkType::BOOKMARK,
sw::mark::InsertMode::New);
// Get coordinates of the end point in the document
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPage = pLayout->Lower();
SwFrame* pBody = pPage->GetLower();
SwFrame* pLastPara = pBody->GetLower()->GetNext()->GetNext()->GetNext()->GetNext()->GetNext();
Point ptTo = pLastPara->getFrameArea().BottomRight();
pWrtShell->SelAll();
// Drag-n-drop to its own end
rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell);
// Without the fix, this would crash: either in CopyFlyInFlyImpl (tdf#159813):
// Assertion failed: !pCopiedPaM || pCopiedPaM->End()->GetNode() == rRg.aEnd.GetNode()
// or in BigPtrArray::operator[] (tdf#159816):
// Assertion failed: idx < m_nSize
xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf34804)
{
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
// Simulate a keyboard shortcut to SID_ATTR_CHAR_COLOR2 (which must use the shared button color)
dispatchCommand(mxComponent, u".uno:FontColor"_ustr, {});
pWrtShell->Insert(u"New World!"_ustr);
const uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1, "New World!"), 1);
// (This test assumes that nothing in the unit tests has modified the app's recent font color)
// COL_DEFAULT_FONT is the default red color for the fontColor button on the toolbar.
CPPUNIT_ASSERT_EQUAL(COL_DEFAULT_FONT, getProperty<Color>(xRun, u"CharColor"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf139631)
{
// Unit test for tdf#139631
// Test to see if preceding space is cut when cutting a word with track changes (redline) on
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->Insert(u"New World!\""_ustr);
// Assert that the string, New World!", is inserted correctly into the document
CPPUNIT_ASSERT_EQUAL(u"New World!\""_ustr, getParagraph(1)->getString());
// Enable redline
dispatchCommand(mxComponent, u".uno:TrackChanges"_ustr, {});
CPPUNIT_ASSERT(pDoc->getIDocumentRedlineAccess().IsRedlineOn());
// Hide redline changes
dispatchCommand(mxComponent, u".uno:ShowTrackedChanges"_ustr, {});
CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
pWrtShell->Left(SwCursorSkipMode::Chars, false, 2, false);
// Select and cut "World" from string
pWrtShell->Left(SwCursorSkipMode::Chars, true, 5, false);
dispatchCommand(mxComponent, u".uno:Cut"_ustr, {});
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
pXmlDoc = parseLayoutDump();
// Verifies that the leading space before "World" was also cut
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion",
"portion", u"New!\"");
// Reset to initial string
dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion",
"portion", u"New World!\"");
pWrtShell->EndPara(false);
pWrtShell->Left(SwCursorSkipMode::Chars, false, 1, false);
// Replace ! with .
pWrtShell->Left(SwCursorSkipMode::Chars, true, 1, false);
pWrtShell->Delete();
pWrtShell->Insert(u"."_ustr);
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion",
"portion", u"New World.\"");
pWrtShell->Left(SwCursorSkipMode::Chars, false, 1, false);
// Select and cut "World" from string
pWrtShell->Left(SwCursorSkipMode::Chars, true, 5, false);
dispatchCommand(mxComponent, u".uno:Cut"_ustr, {});
pXmlDoc = parseLayoutDump();
// Without the test in place, the leading space before "World" is not also cut.
// Expected: New."
// Actual: New ."
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwParaPortion",
"portion", u"New.\"");
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf151710)
{
createSwDoc();
// Check that the particular setting is turned on by default
const SwViewOption* pVwOpt = getSwDocShell()->GetWrtShell()->GetViewOptions();
CPPUNIT_ASSERT(pVwOpt);
CPPUNIT_ASSERT(pVwOpt->IsEncloseWithCharactersOn());
// Localized quotation marks
SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
CPPUNIT_ASSERT(pACorr);
LanguageType eLang = Application::GetSettings().GetLanguageTag().getLanguageType();
OUString sStartSingleQuote{ pACorr->GetQuote('\'', true, eLang) };
OUString sEndSingleQuote{ pACorr->GetQuote('\'', false, eLang) };
OUString sStartDoubleQuote{ pACorr->GetQuote('\"', true, eLang) };
OUString sEndDoubleQuote{ pACorr->GetQuote('\"', false, eLang) };
// Insert some text to work with
uno::Sequence<beans::PropertyValue> aArgsInsert(
comphelper::InitPropertySequence({ { "Text", uno::Any(u"abcd"_ustr) } }));
dispatchCommand(mxComponent, u".uno:InsertText"_ustr, aArgsInsert);
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"abcd"_ustr, xTextDocument->getText()->getString());
// Successfully enclose the text; afterwards the selection should exist with the new
// enclosed text
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
SwXTextDocument* pTextDoc = getSwTextDoc();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '(', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"(abcd)"_ustr, xTextDocument->getText()->getString());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '[', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"[(abcd)]"_ustr, xTextDocument->getText()->getString());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '{', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"{[(abcd)]}"_ustr, xTextDocument->getText()->getString());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '\'', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(OUString(sStartSingleQuote + "{[(abcd)]}" + sEndSingleQuote),
xTextDocument->getText()->getString());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '\"', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(OUString(sStartDoubleQuote + sStartSingleQuote + "{[(abcd)]}"
+ sEndSingleQuote + sEndDoubleQuote),
xTextDocument->getText()->getString());
// Disable the setting and check that enclosing doesn't happen anymore
const_cast<SwViewOption*>(pVwOpt)->SetEncloseWithCharactersOn(false);
CPPUNIT_ASSERT(!pVwOpt->IsEncloseWithCharactersOn());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '(', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"("_ustr, xTextDocument->getText()->getString());
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '[', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"["_ustr, xTextDocument->getText()->getString());
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '{', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"{"_ustr, xTextDocument->getText()->getString());
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '\'', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sStartSingleQuote, xTextDocument->getText()->getString());
dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '\"', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sStartDoubleQuote, xTextDocument->getText()->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159054_disableOutlineNumbering)
{
createSwDoc("tdf159054_disableOutlineNumbering.docx");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
const uno::Reference<text::XTextRange> xPara1 = getParagraph(1, u"Heading A"_ustr);
const uno::Reference<text::XTextRange> xPara2 = getParagraph(2, u"Heading B"_ustr);
const uno::Reference<text::XTextRange> xPara3 = getParagraph(3, u"Heading C"_ustr);
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xPara1, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u"B."_ustr, getProperty<OUString>(xPara2, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u"C."_ustr, getProperty<OUString>(xPara3, u"ListLabelString"_ustr));
// select (at least parts) of the first two paragraphs
pWrtShell->Down(/*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/true);
// on the selection, simulate pressing the toolbar button to toggle OFF numbering
dispatchCommand(mxComponent, u".uno:DefaultNumbering"_ustr, {});
// the selected paragraphs should definitely have the list label removed
CPPUNIT_ASSERT_EQUAL(u""_ustr, getProperty<OUString>(xPara1, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u""_ustr, getProperty<OUString>(xPara2, u"ListLabelString"_ustr));
// the third paragraph must retain the existing numbering format
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xPara3, u"ListLabelString"_ustr));
// on the selection, simulate pressing the toolbar button to toggle ON numbering again
dispatchCommand(mxComponent, u".uno:DefaultNumbering"_ustr, {});
// the outline numbering format must be re-applied to the first two paragraphs
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xPara1, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u"B."_ustr, getProperty<OUString>(xPara2, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u"C."_ustr, getProperty<OUString>(xPara3, u"ListLabelString"_ustr));
// on the selection, simulate a right click - list - No list
dispatchCommand(mxComponent, u".uno:RemoveBullets"_ustr, {});
// the selected paragraphs should definitely have the list label removed
CPPUNIT_ASSERT_EQUAL(u""_ustr, getProperty<OUString>(xPara1, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u""_ustr, getProperty<OUString>(xPara2, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xPara3, u"ListLabelString"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_dde_disable)
{
std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(true, pBatch);
pBatch->commit();
comphelper::ScopeGuard g([] {
std::shared_ptr<comphelper::ConfigurationChanges> _pBatch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(false, _pBatch);
_pBatch->commit();
});
createSwDoc();
SwDoc* pDoc = getSwDoc();
// force the AppName to enable DDE, it is not there for test runs
Application::SetAppName(u"soffice"_ustr);
// temp copy for the file that will be used as a reference for DDE link
// this file includes a section named "Section1" with text inside
createTempCopy(u"tdf158375_dde_reference.fodt");
comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer
= getSwDocShell()->getEmbeddedObjectContainer();
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
// create a section with DDE link
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xTextSectionProps(
xFactory->createInstance(u"com.sun.star.text.TextSection"_ustr), uno::UNO_QUERY);
uno::Sequence<OUString> aNames{ u"DDECommandFile"_ustr, u"DDECommandType"_ustr,
u"DDECommandElement"_ustr, u"IsAutomaticUpdate"_ustr,
u"IsProtected"_ustr };
uno::Sequence<uno::Any> aValues{ uno::Any(u"soffice"_ustr), uno::Any(maTempFile.GetURL()),
uno::Any(u"Section1"_ustr), uno::Any(true), uno::Any(true) };
uno::Reference<beans::XMultiPropertySet> rMultiPropSet(xTextSectionProps, uno::UNO_QUERY);
rMultiPropSet->setPropertyValues(aNames, aValues);
// insert the TextSection with DDE link
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextRange> xTextRange = xTextDocument->getText();
uno::Reference<text::XText> xText = xTextRange->getText();
uno::Reference<text::XParagraphCursor> xCursor(xText->createTextCursor(), uno::UNO_QUERY);
xText->insertTextContent(
xCursor, uno::Reference<text::XTextContent>(xTextSectionProps, uno::UNO_QUERY), false);
CPPUNIT_ASSERT_EQUAL(
size_t(1), pDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
pDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, false, nullptr,
u""_ustr);
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(),
uno::UNO_QUERY);
uno::Reference<text::XTextSection> xSection(xSections->getByIndex(0), uno::UNO_QUERY);
// make sure there's no text in the section after UpdateAllLinks, since
// DisableActiveContent disables DDE links.
CPPUNIT_ASSERT_EQUAL(u""_ustr, xSection->getAnchor()->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_ole_object_disable)
{
std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(true, pBatch);
pBatch->commit();
comphelper::ScopeGuard g([] {
std::shared_ptr<comphelper::ConfigurationChanges> _pBatch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(false, _pBatch);
_pBatch->commit();
});
// Enable LOK mode, otherwise OCommonEmbeddedObject::SwitchStateTo_Impl() will throw when it
// finds out that the test runs headless.
comphelper::LibreOfficeKit::setActive();
// Load a document with a Draw doc in it.
createSwDoc("ole-save-while-edit.odt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
selectShape(1);
// attempt to edit the OLE object.
pWrtShell->LaunchOLEObj();
// it shouldn't switch because the current configuration
// (DisableActiveContent) prohibits OLE objects changing to states other
// then LOADED
auto xShape = getShape(1);
uno::Reference<document::XEmbeddedObjectSupplier2> xEmbedSupplier(xShape, uno::UNO_QUERY);
auto xEmbeddedObj = xEmbedSupplier->getExtendedControlOverEmbeddedObject();
CPPUNIT_ASSERT_EQUAL(embed::EmbedStates::LOADED, xEmbeddedObj->getCurrentState());
// Dispose the document while LOK is still active to avoid leaks.
mxComponent->dispose();
mxComponent.clear();
comphelper::LibreOfficeKit::setActive(false);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf146190)
{
// Given a document with a number rule at the start of a paragraph and two drawing objects:
createSwDoc("tdf146190.odt");
SwDocShell* pDocShell = getSwDocShell();
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
const SdrMarkList& rMrkList = pWrtShell->GetDrawView()->GetMarkedObjectList();
// Assert the current cursor position has a number rule and is at the start of a paragraph:
pWrtShell->SttEndDoc(/*bStt=*/true);
CPPUNIT_ASSERT(pWrtShell->GetNumRuleAtCurrCursorPos());
CPPUNIT_ASSERT(pWrtShell->IsSttOfPara());
// Then go to "Shape 1" drawing object using the GotoDrawingObject function:
pWrtShell->GotoDrawingObject(u"Shape 1");
CPPUNIT_ASSERT_EQUAL(u"Shape 1"_ustr, rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName());
// Move to the next drawing object by Tab key press:
SwXTextDocument* pTextDoc = getSwTextDoc();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
// Without the fix in place, this test would have failed with:
// equality assertion failed
// - Expected: Shape 2
// - Actual : Shape 1
// i.e. Tab did not move to the next drawing object
CPPUNIT_ASSERT_EQUAL(u"Shape 2"_ustr, rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName());
// Tab key press should now select 'Shape 1':
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"Shape 1"_ustr, rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf160898)
{
// Given a document with a 1-cell table in another 1-cell table:
createSwDoc("table-in-table.fodt");
SwDocShell* pDocShell = getSwDocShell();
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
// Move to the normally hidden paragraph inside the outer table cell, following the inner table
pWrtShell->Down(false, 2);
// Without the fix, this would crash:
pWrtShell->SelAll();
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf164949)
{
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2);
pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {});
uno::Sequence aArgs{ comphelper::makePropertyValue(u"PersistentCopy"_ustr, uno::Any(false)) };
// Without the fix in place, this test would have crashed here
dispatchCommand(mxComponent, u".uno:FormatPaintbrush"_ustr, aArgs);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testParagraphStyleCloneFormatting)
{
createSwDoc();
emulateTyping(u"First Line");
SwXTextDocument* pTextDoc = getSwTextDoc();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
emulateTyping(u"Second Line");
CPPUNIT_ASSERT_EQUAL(u"Standard"_ustr,
getProperty<OUString>(getParagraph(1), u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Standard"_ustr,
getProperty<OUString>(getParagraph(2), u"ParaStyleName"_ustr));
uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({
{ "Style", uno::Any(u"Heading 1"_ustr) },
{ "FamilyName", uno::Any(u"ParagraphStyles"_ustr) },
});
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr, aPropertyValues);
CPPUNIT_ASSERT_EQUAL(u"Standard"_ustr,
getProperty<OUString>(getParagraph(1), u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Heading 1"_ustr,
getProperty<OUString>(getParagraph(2), u"ParaStyleName"_ustr));
uno::Sequence aArgs{ comphelper::makePropertyValue(u"PersistentCopy"_ustr, uno::Any(false)) };
dispatchCommand(mxComponent, u".uno:FormatPaintbrush"_ustr, aArgs);
// Disable map mode, so that it's possible to send mouse event coordinates
// directly in twips.
SwEditWin& rEditWin = getSwDocShell()->GetView()->GetEditWin();
rEditWin.EnableMapMode(false);
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
// move to first line
pWrtShell->Up(/*bSelect=*/false, 1);
Point aPoint = pShellCursor->GetSttPos();
// click on first line
pTextDoc->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aPoint.getX(), aPoint.getY(), 1,
MOUSE_LEFT, 0);
pTextDoc->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aPoint.getX(), aPoint.getY(), 1,
MOUSE_LEFT, 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"Heading 1"_ustr,
getProperty<OUString>(getParagraph(1), u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Heading 1"_ustr,
getProperty<OUString>(getParagraph(2), u"ParaStyleName"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf122756)
{
createSwDoc("tdf122756.odt");
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCellA1(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"€ 100,00"_ustr, xCellA1->getString());
uno::Reference<text::XTextRange> xCellA2(xTable->getCellByName(u"A2"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"100"_ustr, xCellA2->getString());
// Cursor is already on cell A1
uno::Sequence aArgs{ comphelper::makePropertyValue(u"PersistentCopy"_ustr, uno::Any(false)) };
dispatchCommand(mxComponent, u".uno:FormatPaintbrush"_ustr, aArgs);
// Disable map mode, so that it's possible to send mouse event coordinates
// directly in twips.
SwEditWin& rEditWin = getSwDocShell()->GetView()->GetEditWin();
rEditWin.EnableMapMode(false);
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
// move to cell A2
pWrtShell->Down(/*bSelect=*/false, 1);
Point aPoint = pShellCursor->GetSttPos();
// click on cell A2
SwXTextDocument* pTextDoc = getSwTextDoc();
pTextDoc->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aPoint.getX(), aPoint.getY(), 1,
MOUSE_LEFT, 0);
pTextDoc->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aPoint.getX(), aPoint.getY(), 1,
MOUSE_LEFT, 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(u"€ 100,00"_ustr, xCellA1->getString());
// Without the fix in place, this test would have failed with
// - Expected: € 100,00
// - Actual : 100
CPPUNIT_ASSERT_EQUAL(u"€ 100,00"_ustr, xCellA2->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf161172)
{
// Given a paragraph manually made a member of a list:
createSwDoc("tdf161172.fodt");
auto para = getParagraph(1);
// Check initial state: the first paragraph has "No_list" para style, "Num_1" numbering style,
// numbering level 0, and "Num1_lvl1_1" numbering label.
CPPUNIT_ASSERT_EQUAL(u"No_list"_ustr, getProperty<OUString>(para, u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, u"NumberingStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Num1_lvl1_1"_ustr, getProperty<OUString>(para, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(para, u"NumberingLevel"_ustr));
// Assign "Num_1_lvl2" paragraph style to the first paragraph. The style is associated with
// "Num_1" numbering style, level 1.
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
{ comphelper::makePropertyValue(u"FamilyName"_ustr, u"ParagraphStyles"_ustr),
comphelper::makePropertyValue(u"Style"_ustr, u"Num_1_lvl2"_ustr) });
// Check that the respective properties got correctly applied
CPPUNIT_ASSERT_EQUAL(u"Num_1_lvl2"_ustr, getProperty<OUString>(para, u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, u"NumberingStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Num1_lvl2_1"_ustr, getProperty<OUString>(para, u"ListLabelString"_ustr));
CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(para, u"NumberingLevel"_ustr));
// Undo
dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
// Check that the numbering properties got correctly restored
CPPUNIT_ASSERT_EQUAL(u"No_list"_ustr, getProperty<OUString>(para, u"ParaStyleName"_ustr));
CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, u"NumberingStyleName"_ustr));
// Without the fix, this would fail with
// - Expected: Num1_lvl1_1
// - Actual : Num1_lvl2_1
CPPUNIT_ASSERT_EQUAL(u"Num1_lvl1_1"_ustr, getProperty<OUString>(para, u"ListLabelString"_ustr));
// Without the fix, this would fail with
// - Expected: 0
// - Actual : 1
CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(para, u"NumberingLevel"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf144752)
{
// Undoing/redoing a replacement must select the new text
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
emulateTyping(u"Some Text");
CPPUNIT_ASSERT(!pWrtShell->HasSelection());
// Select "Text", and replace with "Word"
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect*/ true, 4, /*bBasicCall*/ false);
pWrtShell->Replace(u"Word"_ustr, false);
pWrtShell->EndOfSection();
CPPUNIT_ASSERT(!pWrtShell->HasSelection());
// Undo and check, that the "Text" is selected
dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
// Without the fix, this would fail
CPPUNIT_ASSERT(pWrtShell->HasSelection());
CPPUNIT_ASSERT_EQUAL(u"Text"_ustr, pWrtShell->GetSelText());
// Redo and check, that the "Word" is selected
dispatchCommand(mxComponent, u".uno:Redo"_ustr, {});
CPPUNIT_ASSERT(pWrtShell->HasSelection());
CPPUNIT_ASSERT_EQUAL(u"Word"_ustr, pWrtShell->GetSelText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf162326_Paragraph)
{
createSwDoc("tdf162326.odt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD,
getProperty<float>(getRun(getParagraph(1), 1), u"CharWeight"_ustr));
CPPUNIT_ASSERT_EQUAL(
awt::FontSlant_ITALIC,
getProperty<awt::FontSlant>(getRun(getParagraph(2), 2), u"CharPosture"_ustr));
CPPUNIT_ASSERT_EQUAL(short(1),
getProperty<short>(getRun(getParagraph(3), 2), u"CharUnderline"_ustr));
pWrtShell->Down(/*bSelect=*/true, 3);
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
{ comphelper::makePropertyValue(u"FamilyName"_ustr, u"ParagraphStyles"_ustr),
comphelper::makePropertyValue(u"Style"_ustr, u"Footnote"_ustr),
comphelper::makePropertyValue(u"KeyModifier"_ustr, uno::Any(KEY_MOD1)) });
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL,
getProperty<float>(getRun(getParagraph(1), 1), u"CharWeight"_ustr));
CPPUNIT_ASSERT_THROW(getRun(getParagraph(2), 2), css::container::NoSuchElementException);
CPPUNIT_ASSERT_THROW(getRun(getParagraph(3), 2), css::container::NoSuchElementException);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf162326_Character)
{
createSwDoc("tdf162326.odt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD,
getProperty<float>(getRun(getParagraph(1), 1), u"CharWeight"_ustr));
CPPUNIT_ASSERT_EQUAL(
awt::FontSlant_ITALIC,
getProperty<awt::FontSlant>(getRun(getParagraph(2), 2), u"CharPosture"_ustr));
CPPUNIT_ASSERT_EQUAL(short(1),
getProperty<short>(getRun(getParagraph(3), 2), u"CharUnderline"_ustr));
pWrtShell->Down(/*bSelect=*/true, 3);
//add Ctrl/MOD_1
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
{ comphelper::makePropertyValue(u"FamilyName"_ustr, u"CharacterStyles"_ustr),
comphelper::makePropertyValue(u"Style"_ustr, u"Definition"_ustr),
comphelper::makePropertyValue(u"KeyModifier"_ustr, uno::Any(KEY_MOD1)) });
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL,
getProperty<float>(getRun(getParagraph(1), 1), u"CharWeight"_ustr));
CPPUNIT_ASSERT_THROW(getRun(getParagraph(2), 2), css::container::NoSuchElementException);
//last runs are not changed because the selection ends at the beginning of that paragraph
CPPUNIT_ASSERT_EQUAL(short(1),
getProperty<short>(getRun(getParagraph(3), 2), u"CharUnderline"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf162326_List)
{
createSwDoc("tdf162326_list.odt");
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XParagraphCursor> xParaCursor(xTextDocument->getText()->createTextCursor(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"A)"_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
{ comphelper::makePropertyValue(u"FamilyName"_ustr, u"ParagraphStyles"_ustr),
comphelper::makePropertyValue(u"Style"_ustr, u"Footnote"_ustr) });
//hard list attribute unchanged
CPPUNIT_ASSERT_EQUAL(u"A)"_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
{ comphelper::makePropertyValue(u"FamilyName"_ustr, u"ParagraphStyles"_ustr),
comphelper::makePropertyValue(u"Style"_ustr, u"Footnote"_ustr),
comphelper::makePropertyValue(u"KeyModifier"_ustr, uno::Any(KEY_MOD1)) });
//list replaced by para style list setting
CPPUNIT_ASSERT_EQUAL(u"1."_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf163340)
{
createSwDoc("tdf163340.odt");
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XText> xText = xTextDocument->getText();
uno::Reference<view::XSelectionSupplier> xSelSupplier(xModel->getCurrentController(),
uno::UNO_QUERY_THROW);
uno::Reference<text::XParagraphCursor> xParaCursor(xTextDocument->getText()->createTextCursor(),
uno::UNO_QUERY);
for (int i = 0; i < 14; i++)
xParaCursor->gotoNextParagraph(false);
xParaCursor->gotoEndOfParagraph(true);
xSelSupplier->select(uno::Any(xParaCursor));
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
xParaCursor = uno::Reference<text::XParagraphCursor>(xText->createTextCursor(), uno::UNO_QUERY);
for (int i = 0; i < 3; i++)
xParaCursor->gotoNextParagraph(false);
xParaCursor->gotoEndOfParagraph(true);
CPPUNIT_ASSERT_EQUAL(u"1."_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
xSelSupplier->select(uno::Any(xParaCursor));
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf163340_2)
{
//selects and copies a single paragraph with a list (bullets)
//and pastes it into an empty paragraph with a different list (numbers)
//checks that the resulting paragraph keeps that different list
createSwDoc("tdf163340_2.odt");
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XText> xText = xTextDocument->getText();
uno::Reference<view::XSelectionSupplier> xSelSupplier(xModel->getCurrentController(),
uno::UNO_QUERY_THROW);
uno::Reference<text::XParagraphCursor> xParaCursor(xTextDocument->getText()->createTextCursor(),
uno::UNO_QUERY);
for (int i = 0; i < 2; i++)
xParaCursor->gotoNextParagraph(false);
xParaCursor->gotoEndOfParagraph(true);
xSelSupplier->select(uno::Any(xParaCursor));
xParaCursor = uno::Reference<text::XParagraphCursor>(xText->createTextCursor(), uno::UNO_QUERY);
for (int i = 0; i < 10; i++)
xParaCursor->gotoNextParagraph(false);
xParaCursor->gotoEndOfParagraph(true);
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
CPPUNIT_ASSERT_EQUAL(u"5."_ustr, getProperty<OUString>(xParaCursor, u"ListLabelString"_ustr));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159023)
{
createSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2);
pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {});
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
pWrtShell->InsertFootnote(u""_ustr);
CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote());
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
dispatchCommand(mxComponent, u".uno:GoLeft"_ustr, {});
dispatchCommand(mxComponent, u".uno:GoLeft"_ustr, {});
// Without the fix in place, this test would have crashed here
CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf162195)
{
// Given a document, which has some index entries in a hidden section
createSwDoc("IndexElementsInHiddenSections.fodt");
auto xIndexSupplier(mxComponent.queryThrow<css::text::XDocumentIndexesSupplier>());
auto xIndexes = xIndexSupplier->getDocumentIndexes();
CPPUNIT_ASSERT(xIndexes);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexes->getCount()); // A ToC and a table index
auto xToC(xIndexes->getByIndex(0).queryThrow<css::text::XDocumentIndex>());
xToC->update();
// Without the fix, all the elements from the hidden section appeared in the index
CPPUNIT_ASSERT_EQUAL(u"Table of Contents" SAL_NEWLINE_STRING "Section Visible\t1"_ustr,
xToC->getAnchor()->getString());
auto xTables(xIndexes->getByIndex(1).queryThrow<css::text::XDocumentIndex>());
xTables->update();
// Without the fix, all the elements from the hidden section appeared in the index
CPPUNIT_ASSERT_EQUAL(u"Index of Tables" SAL_NEWLINE_STRING "Table1\t1"_ustr,
xTables->getAnchor()->getString());
// Show the hidden section
auto xTextSectionsSupplier = mxComponent.queryThrow<css::text::XTextSectionsSupplier>();
auto xSections = xTextSectionsSupplier->getTextSections();
CPPUNIT_ASSERT(xSections);
auto xSection
= xSections->getByName(u"Section Hidden"_ustr).queryThrow<css::beans::XPropertySet>();
xSection->setPropertyValue(u"IsVisible"_ustr, css::uno::Any(true));
xToC->update();
CPPUNIT_ASSERT_EQUAL(u"Table of Contents" SAL_NEWLINE_STRING
"Section Visible\t1" SAL_NEWLINE_STRING
"Section Hidden\t1" SAL_NEWLINE_STRING "entry\t1" SAL_NEWLINE_STRING
"CustomTOCStyle paragraph\t1"_ustr,
xToC->getAnchor()->getString());
xTables->update();
CPPUNIT_ASSERT_EQUAL(u"Index of Tables" SAL_NEWLINE_STRING "Table1\t1" SAL_NEWLINE_STRING
"Table2\t1"_ustr,
xTables->getAnchor()->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf164140)
{
createSwDoc("tdf164140.fodt");
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
SwTextFrame& pTextFrame
= dynamic_cast<SwTextFrame&>(*pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower());
const SwScriptInfo* pSI = pTextFrame.GetScriptInfo();
// Prior to editing, the three complete lines should be flagged as no-kashida:
auto stBeforeLines = pSI->GetNoKashidaLines();
CPPUNIT_ASSERT_EQUAL(size_t(4), stBeforeLines.size());
auto stBeforeIt = stBeforeLines.begin();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), std::get<0>(*stBeforeIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(88), std::get<1>(*stBeforeIt));
++stBeforeIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(88), std::get<0>(*stBeforeIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(180), std::get<1>(*stBeforeIt));
++stBeforeIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(180), std::get<0>(*stBeforeIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(269), std::get<1>(*stBeforeIt));
++stBeforeIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(269), std::get<0>(*stBeforeIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(312), std::get<1>(*stBeforeIt));
// Insert text at the beginning of the document
pWrtShell->Insert(u"A"_ustr);
// After editing, the three complete lines should still be flagged as no-kashida
auto stAfterLines = pSI->GetNoKashidaLines();
// Without the fix, this will be 2
CPPUNIT_ASSERT_EQUAL(size_t(4), stAfterLines.size());
auto stAfterIt = stAfterLines.begin();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), std::get<0>(*stAfterIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(89), std::get<1>(*stAfterIt));
++stAfterIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(89), std::get<0>(*stAfterIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(181), std::get<1>(*stAfterIt));
++stAfterIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(181), std::get<0>(*stAfterIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(270), std::get<1>(*stAfterIt));
++stAfterIt;
CPPUNIT_ASSERT_EQUAL(sal_Int32(270), std::get<0>(*stAfterIt));
CPPUNIT_ASSERT_EQUAL(sal_Int32(313), std::get<1>(*stAfterIt));
}
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|