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
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793 | /* -*- 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 <sstream>
#include <boost/property_tree/json_parser.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/text/TableColumnSeparator.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <comphelper/propertysequence.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <i18nlangtag/languagetag.hxx>
#include <vcl/scheduler.hxx>
#include <vcl/settings.hxx>
#include <ndtxt.hxx>
#include <swdtflvr.hxx>
#include <wrtsh.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <flyfrm.hxx>
#include <fmtanchr.hxx>
#include <UndoManager.hxx>
#include <sortedobjs.hxx>
#include <anchoredobject.hxx>
#include <itabenum.hxx>
#include <fmtfsize.hxx>
#include <xmloff/odffields.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <svl/stritem.hxx>
#include <comphelper/lok.hxx>
#include <txtfrm.hxx>
#include <redline.hxx>
#include <view.hxx>
#include <cmdid.h>
#include <AnnotationWin.hxx>
#include <PostItMgr.hxx>
#include <postithelper.hxx>
#include <fmtcntnt.hxx>
#include <frameformats.hxx>
#include <shellio.hxx>
#include <editeng/fontitem.hxx>
namespace
{
char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data2/";
char const FLOATING_TABLE_DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data/floating_table/";
} // namespace
/// Second set of tests asserting the behavior of Writer user interface shells.
class SwUiWriterTest2 : public SwModelTestBase
{
public:
virtual std::unique_ptr<Resetter> preTest(const char* filename) override
{
m_aSavedSettings = Application::GetSettings();
if (OString(filename).indexOf("LocaleArabic") != -1)
{
std::unique_ptr<Resetter> pResetter(
new Resetter([this]() { Application::SetSettings(this->m_aSavedSettings); }));
AllSettings aSettings(m_aSavedSettings);
aSettings.SetLanguageTag(LanguageTag("ar"));
Application::SetSettings(aSettings);
return pResetter;
}
return nullptr;
}
protected:
AllSettings m_aSavedSettings;
SwDoc* createDoc(const char* pName = nullptr);
};
SwDoc* SwUiWriterTest2::createDoc(const char* pName)
{
if (!pName)
loadURL("private:factory/swriter", nullptr);
else
load(DATA_DIRECTORY, pName);
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
return pTextDoc->GetDocShell()->GetDoc();
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf47471_paraStyleBackground)
{
SwDoc* pDoc = createDoc("tdf47471_paraStyleBackground.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT_EQUAL(OUString("00Background"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(14729933), getProperty<sal_Int32>(getParagraph(2), "FillColor"));
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->EndPara(/*bSelect=*/true);
dispatchCommand(mxComponent, ".uno:ResetAttributes", {});
// the background color should revert to the color for 00Background style
CPPUNIT_ASSERT_EQUAL(sal_Int32(14605542), getProperty<sal_Int32>(getParagraph(2), "FillColor"));
// the paragraph style should not be reset
CPPUNIT_ASSERT_EQUAL(OUString("00Background"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("00Background"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
// Save it and load it back.
reload("writer8", "tdf47471_paraStyleBackgroundRT.odt");
CPPUNIT_ASSERT_EQUAL(sal_Int32(14605542), getProperty<sal_Int32>(getParagraph(2), "FillColor"));
// on round-trip, the paragraph style name was lost
CPPUNIT_ASSERT_EQUAL(OUString("00Background"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("00Background"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdfChangeNumberingListAutoFormat)
{
createDoc("tdf117923.docx");
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Check that we actually test the line we need
assertXPathContent(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]", "GHI GHI GHI GHI");
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]/Special", "nType",
"PortionType::Number");
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]/Special", "rText", "2.");
// The numbering height was 960 in DOC format.
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]/Special", "nHeight", "220");
// tdf#127606: now it's possible to change formatting of numbering
// increase font size (220 -> 260)
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Grow", {});
pViewShell->Reformat();
discardDumpedLayout();
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]/Special", "nHeight", "260");
// save it to DOCX
reload("Office Open XML Text", "tdf117923.docx");
pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
pViewShell->Reformat();
discardDumpedLayout();
pXmlDoc = parseLayoutDump();
// this was 220
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/txt[3]/Special", "nHeight", "260");
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf101534)
{
// Copy the first paragraph of the document.
load(DATA_DIRECTORY, "tdf101534.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->EndPara(/*bSelect=*/true);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Copy();
// Go to the second paragraph, assert that we have margins as direct
// formatting.
pWrtShell->Down(/*bSelect=*/false);
SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items<RES_LR_SPACE, RES_LR_SPACE>{});
pWrtShell->GetCurAttr(aSet);
CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
// Make sure that direct formatting is preserved during paste.
pWrtShell->EndPara(/*bSelect=*/false);
TransferableDataHelper aHelper(pTransfer.get());
SwTransferable::Paste(*pWrtShell, aHelper);
aSet.ClearItem();
pWrtShell->GetCurAttr(aSet);
// This failed, direct formatting was lost.
CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRedlineMoveInsertInDelete)
{
loadURL("private:factory/swriter", nullptr);
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwWrtShell* const pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Insert(" foo");
pWrtShell->SttEndDoc(true);
pWrtShell->InsertFootnote("");
CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote());
RedlineFlags const mode(pWrtShell->GetRedlineFlags() | RedlineFlags::On);
CPPUNIT_ASSERT(mode & (RedlineFlags::ShowDelete | RedlineFlags::ShowInsert));
pWrtShell->SetRedlineFlags(mode);
// insert redline
pWrtShell->Insert("bar");
// first delete redline, logically containing the insert redline
// (note: Word apparently allows similar things...)
pWrtShell->SttEndDoc(true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
pWrtShell->Delete(); // the footnote
// second delete redline, following the first one
pWrtShell->EndOfSection(false);
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 3, /*bBasicCall=*/false);
pWrtShell->Delete(); // "foo"
// hiding used to copy the 2nd delete redline "foo", but not delete it
pWrtShell->SetRedlineFlags(mode & ~RedlineFlags::ShowDelete); // hide
CPPUNIT_ASSERT_EQUAL(
OUString(" "),
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
pWrtShell->SetRedlineFlags(mode); // show again
CPPUNIT_ASSERT_EQUAL(
OUString(u"\u0001 foo"),
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRedlineInHiddenSection)
{
loadURL("private:factory/swriter", nullptr);
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwWrtShell* const pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->SplitNode();
pWrtShell->Insert("foo");
pWrtShell->SplitNode();
pWrtShell->Insert("bar");
pWrtShell->SplitNode();
pWrtShell->Insert("baz");
RedlineFlags const mode(pWrtShell->GetRedlineFlags() | RedlineFlags::On);
CPPUNIT_ASSERT(mode & (RedlineFlags::ShowDelete | RedlineFlags::ShowInsert));
pWrtShell->SetRedlineFlags(mode);
// delete paragraph "bar"
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false);
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 8, /*bBasicCall=*/false);
pWrtShell->Delete();
pWrtShell->StartOfSection();
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
pWrtShell->EndOfSection(true);
SwSectionData section(SectionType::Content, pWrtShell->GetUniqueSectionName());
section.SetHidden(true);
SwSection const* pSection = pWrtShell->InsertSection(section, nullptr);
SwSectionNode const* pNode = pSection->GetFormat()->GetSectionNode();
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 2]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 3]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 4]->IsEndNode());
pWrtShell->SetRedlineFlags(mode & ~RedlineFlags::ShowDelete); // hide
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 2]->IsEndNode());
pWrtShell->SetRedlineFlags(mode); // show again
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr));
// there was a frame created here
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 2]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(
!pNode->GetNodes()[pNode->GetIndex() + 3]->GetTextNode()->getLayoutFrame(nullptr));
CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 4]->IsEndNode());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf132236)
{
load(DATA_DIRECTORY, "tdf132236.odt");
SwXTextDocument* const pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// select everything and delete
SwWrtShell* const pWrtShell(pTextDoc->GetDocShell()->GetWrtShell());
pWrtShell->Down(true);
pWrtShell->Down(true);
pWrtShell->Down(true);
pWrtShell->Delete();
SwDoc* const pDoc(pWrtShell->GetDoc());
sw::UndoManager& rUndoManager(pDoc->GetUndoManager());
rUndoManager.Undo();
// check that the text frames exist inside their sections
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[1]/body/section[1]/txt", 1);
assertXPath(pXmlDoc, "/root/page[1]/body/section[2]/txt", 2);
assertXPath(pXmlDoc, "/root/page[1]/body/txt", 1);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf131912)
{
SwDoc* const pDoc = createDoc();
SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
sw::UnoCursorPointer pCursor(
pDoc->CreateUnoCursor(SwPosition(SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1))));
pDoc->getIDocumentContentOperations().InsertString(*pCursor, "foo");
{
SfxItemSet flySet(pDoc->GetAttrPool(),
svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{});
SwFormatAnchor anchor(RndStdIds::FLY_AT_CHAR);
pWrtShell->StartOfSection(false);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false);
anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint());
flySet.Put(anchor);
SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000);
flySet.Put(size); // set a size, else we get 1 char per line...
SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true);
CPPUNIT_ASSERT(pFly != nullptr);
}
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pCursor->SetMark();
pCursor->GetMark()->nContent.Assign(pCursor->GetContentNode(), 0);
pCursor->GetPoint()->nContent.Assign(pCursor->GetContentNode(), 3);
// replace with more text
pDoc->getIDocumentContentOperations().ReplaceRange(*pCursor, "blahblah", false);
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("blahblah"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("blahblah"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Undo();
pCursor->GetMark()->nContent.Assign(pCursor->GetContentNode(), 0);
pCursor->GetPoint()->nContent.Assign(pCursor->GetContentNode(), 3);
// replace with less text
pDoc->getIDocumentContentOperations().ReplaceRange(*pCursor, "x", false);
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("x"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("x"), pCursor->GetNode().GetTextNode()->GetText());
rUndoManager.Undo();
pCursor->GetMark()->nContent.Assign(pCursor->GetContentNode(), 0);
pCursor->GetPoint()->nContent.Assign(pCursor->GetContentNode(), 3);
// regex replace with paragraph breaks
pDoc->getIDocumentContentOperations().ReplaceRange(*pCursor, "xyz\\n\\nquux\\n", true);
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("xyz"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("xyz\n\nquux\n"), pWrtShell->GetCursor()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pCursor->GetNode().GetTextNode()->GetText());
pWrtShell->StartOfSection(false);
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pWrtShell->GetCursor()->GetText());
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("xyz"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("xyz\n\nquux\n"), pWrtShell->GetCursor()->GetText());
// regex replace with paragraph join
pWrtShell->StartOfSection(false);
pWrtShell->Down(true);
pDoc->getIDocumentContentOperations().ReplaceRange(*pWrtShell->GetCursor(), "bar", true);
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("bar"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("bar\nquux\n"), pWrtShell->GetCursor()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("xyz"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("xyz\n\nquux\n"), pWrtShell->GetCursor()->GetText());
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("bar"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("bar\nquux\n"), pWrtShell->GetCursor()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
pWrtShell->StartOfSection(false);
CPPUNIT_ASSERT_EQUAL(OUString("xyz"),
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText());
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("xyz\n\nquux\n"), pWrtShell->GetCursor()->GetText());
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_FRM));
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pCursor->GetNode().GetTextNode()->GetText());
pWrtShell->StartOfSection(false);
pWrtShell->EndOfSection(true);
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pWrtShell->GetCursor()->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf54819)
{
load(DATA_DIRECTORY, "tdf54819.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
//turn on red-lining and hide changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE("redlines shouldn't be visible",
!IDocumentRedlineAccess::IsShowChanges(
pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// remove first paragraph with paragraph break
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// remaining paragraph keeps its original style
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf54819_keep_numbering_with_Undo)
{
load(DATA_DIRECTORY, "tdf54819b.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
OUString sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
//turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE("redlines shouldn't be visible",
!IDocumentRedlineAccess::IsShowChanges(
pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// remove heading with paragraph break
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// solved problem: changing paragraph style after deletion
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(2), "NumberingStyleName");
// solved problem: lost numbering
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// accept deletion, remaining (now second) paragraph: still bulleted list item
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(2), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// solved problem: Undo with the workaround
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
rUndoManager.Undo();
// heading, manual test is correct
// TODO: it works well, but the test fails...
// SwWrtShell* const pWrtShell2 = pTextDoc->GetDocShell()->GetWrtShell();
// CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
// getProperty<OUString>(getParagraph(2), "ParaStyleName"));
// CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
// getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf119571_keep_numbering_with_Undo)
{
// as the previous test, but with partial paragraph deletion:
// all deleted paragraphs get the formatting of the first (the partially deleted) one
load(DATA_DIRECTORY, "tdf54819b.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
OUString sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// third paragraph: normal text without numbering
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(4), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Bad numbering", sNumName.isEmpty());
//turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE("redlines shouldn't be visible",
!IDocumentRedlineAccess::IsShowChanges(
pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// remove only end part of the heading and the next numbered paragraph with paragraph break
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 6, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 2, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// solved problem: changing paragraph style after deletion
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
// solved problem: apply numbering
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// accept deletion
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
// Joined paragraph 2 and paragraph 4: Fusce...nunc.
CPPUNIT_ASSERT(getParagraph(2)->getString().startsWith("Fusce"));
CPPUNIT_ASSERT(getParagraph(2)->getString().endsWith("nunc."));
// Remaining (now second) paragraph: it is still heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// solved problem: Undo with the workaround
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
rUndoManager.Undo();
// heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// third paragraph: normal text without numbering
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(4), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Bad numbering", sNumName.isEmpty());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf119571_keep_numbering_with_Reject)
{
// as the previous test, but with partial paragraph deletion:
// all deleted paragraphs get the formatting of the first (the partially deleted) one
load(DATA_DIRECTORY, "tdf54819b.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
OUString sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// third paragraph: normal text without numbering
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(4), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Bad numbering", sNumName.isEmpty());
//turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE("redlines shouldn't be visible",
!IDocumentRedlineAccess::IsShowChanges(
pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// remove only end part of the heading and the next numbered paragraph with paragraph break
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 6, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 2, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// solved problem: changing paragraph style after deletion
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
// solved problem: apply numbering
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// reject deletion
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(false);
// heading
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Outline"),
getProperty<OUString>(getParagraph(2), "NumberingStyleName"));
// next paragraph: bulleted list item
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(3), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Missing numbering style", !sNumName.isEmpty());
CPPUNIT_ASSERT_MESSAGE("Not a bulleted list item", sNumName != "Outline");
// third paragraph: normal text without numbering
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
sNumName = getProperty<OUString>(getParagraph(4), "NumberingStyleName");
CPPUNIT_ASSERT_MESSAGE("Bad numbering", sNumName.isEmpty());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376_redline)
{
SwDoc* pDoc = createDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// need 2 paragraphs to get to the bMoveNds case
pWrtShell->Insert("foo");
pWrtShell->SplitNode();
pWrtShell->Insert("bar");
pWrtShell->SplitNode();
pWrtShell->StartOfSection(false);
// add AT_PARA fly at 1st to be deleted node
SwFormatAnchor anchor(RndStdIds::FLY_AT_PARA);
anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint());
SfxItemSet flySet(pDoc->GetAttrPool(),
svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{});
flySet.Put(anchor);
SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000);
flySet.Put(size); // set a size, else we get 1 char per line...
SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true);
CPPUNIT_ASSERT(pFly != nullptr);
pWrtShell->SttEndDoc(false);
SwInsertTableOptions tableOpt(SwInsertTableFlags::DefaultBorder, 0);
const SwTable& rTable = pWrtShell->InsertTable(tableOpt, 1, 1);
pWrtShell->StartOfSection(false);
SwPaM pam(*pWrtShell->GetCursor()->GetPoint());
pam.SetMark();
pam.GetPoint()->nNode = *rTable.GetTableNode();
pam.GetPoint()->nContent.Assign(nullptr, 0);
pam.Exchange(); // same selection direction as in doc compare...
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert | RedlineFlags::ShowDelete);
rIDRA.AppendRedline(new SwRangeRedline(RedlineType::Delete, pam), true);
// this used to assert/crash with m_pAnchoredFlys mismatch because the
// fly was not deleted but its anchor was moved to the SwTableNode
rIDRA.AcceptAllRedline(true);
CPPUNIT_ASSERT_EQUAL(size_t(0), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(0), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376)
{
SwDoc* pDoc = createDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// need 2 paragraphs to get to the bMoveNds case
pWrtShell->Insert("foo");
pWrtShell->SplitNode();
pWrtShell->Insert("bar");
pWrtShell->SplitNode();
pWrtShell->StartOfSection(false);
// add AT_PARA fly at 1st to be deleted node
SwFormatAnchor anchor(RndStdIds::FLY_AT_PARA);
anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint());
SfxItemSet flySet(pDoc->GetAttrPool(),
svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{});
flySet.Put(anchor);
SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000);
flySet.Put(size); // set a size, else we get 1 char per line...
SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true);
CPPUNIT_ASSERT(pFly != nullptr);
pWrtShell->SttEndDoc(false);
SwInsertTableOptions tableOpt(SwInsertTableFlags::DefaultBorder, 0);
const SwTable& rTable = pWrtShell->InsertTable(tableOpt, 1, 1);
pWrtShell->StartOfSection(false);
SwPaM pam(*pWrtShell->GetCursor()->GetPoint());
pam.SetMark();
pam.GetPoint()->nNode = *rTable.GetTableNode();
pam.GetPoint()->nContent.Assign(nullptr, 0);
pam.Exchange(); // same selection direction as in doc compare...
// this used to assert/crash with m_pAnchoredFlys mismatch because the
// fly was not deleted but its anchor was moved to the SwTableNode
pDoc->getIDocumentContentOperations().DeleteRange(pam);
CPPUNIT_ASSERT_EQUAL(size_t(0), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
rUndoManager.Redo();
CPPUNIT_ASSERT_EQUAL(size_t(0), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
rUndoManager.Undo();
CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf64242_optimizeTable)
{
SwDoc* pDoc = createDoc("tdf64242_optimizeTable.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<table::XTableRows> xTableRows = xTextTable->getRows();
double origWidth = getProperty<double>(xTextTable, "Width");
sal_Int32 nToleranceW = origWidth * .01;
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table Width", double(17013), origWidth, nToleranceW);
pWrtShell->SelTable(); //select the whole table
dispatchCommand(mxComponent, ".uno:SetOptimalColumnWidth", {});
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table Width: optimize", origWidth,
getProperty<double>(xTextTable, "Width"), nToleranceW);
dispatchCommand(mxComponent, ".uno:SetMinimalColumnWidth", {});
CPPUNIT_ASSERT_MESSAGE("Table Width: minimized",
(origWidth - nToleranceW) > getProperty<double>(xTextTable, "Width"));
double origRowHeight = getProperty<double>(xTableRows->getByIndex(2), "Height");
sal_Int32 nToleranceH = origRowHeight * .01;
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Row Height", double(3441), origRowHeight, nToleranceH);
dispatchCommand(mxComponent, ".uno:SetOptimalRowHeight", {});
double optimalRowHeight = getProperty<double>(xTableRows->getByIndex(2), "Height");
CPPUNIT_ASSERT_MESSAGE("Row Height: optimized",
(origRowHeight - nToleranceH) > optimalRowHeight);
dispatchCommand(mxComponent, ".uno:SetMinimalRowHeight", {});
double minimalRowHeight = getProperty<double>(xTableRows->getByIndex(2), "Height");
CPPUNIT_ASSERT_MESSAGE("Row Height: minimized",
(optimalRowHeight - nToleranceH) > minimalRowHeight);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Row set to auto-height", double(0), minimalRowHeight);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126784_distributeSelectedColumns)
{
SwDoc* pDoc = createDoc("tdf126784_distributeSelectedColumns.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<table::XTableRows> xTableRows = xTextTable->getRows();
auto aSeq = getProperty<uno::Sequence<text::TableColumnSeparator>>(xTableRows->getByIndex(0),
"TableColumnSeparators");
sal_Int16 nOrigCol2Pos = aSeq[0].Position;
sal_Int16 nOrigCol3Pos = aSeq[1].Position;
//Select column 1 and 2
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
dispatchCommand(mxComponent, ".uno:DistributeColumns", {});
aSeq = getProperty<uno::Sequence<text::TableColumnSeparator>>(xTableRows->getByIndex(0),
"TableColumnSeparators");
CPPUNIT_ASSERT_MESSAGE("Second column should shrink", nOrigCol2Pos < aSeq[0].Position);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Last column shouldn't change", nOrigCol3Pos, aSeq[1].Position);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf108687_tabstop)
{
SwDoc* pDoc = createDoc("tdf108687_tabstop.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
sal_Int32 nStartIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
CPPUNIT_ASSERT_EQUAL(sal_Int32(9), nStartIndex);
// Now pressing 'tab' should jump to the radio buttons.
SwXTextDocument* pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pXTextDocument);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
//sal_Int32 nEndIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
//CPPUNIT_ASSERT_EQUAL(sal_Int32(11), nEndIndex);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf119571)
{
load(DATA_DIRECTORY, "tdf54819.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
//turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// join paragraphs by removing the end of the first one with paragraph break
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// second paragraph changes its style in "Show changes" mode
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf119019)
{
// check handling of overlapping redlines
load(DATA_DIRECTORY, "tdf119019.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus."),
getParagraph(2)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(2), 1)->getString());
// second paragraph has got a tracked paragraph formatting at this point
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 1), "RedlineType"));
// delete last word of the second paragraph to remove tracked paragraph formatting
// of this paragraph to track and show word deletion correctly.
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/false);
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 7, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// check tracked text deletion
CPPUNIT_ASSERT_EQUAL(OUString("tellus."), getRun(getParagraph(2), 3)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(2), 2)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 2), "RedlineType"));
// make sure that the tracked paragraph formatting is removed
CPPUNIT_ASSERT(!hasProperty(getRun(getParagraph(2), 1), "RedlineType"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf119824)
{
// check handling of overlapping redlines with Redo
SwDoc* pDoc = createDoc("tdf119019.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique senectus "
"et netus et malesuada fames ac turpis egestas. "
"Proin pharetra nonummy pede. Mauris et orci."),
getParagraph(3)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 1)->getString());
// third paragraph has got a tracked paragraph formatting at this point
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
// and a tracked text deletion at the beginning of the paragraph
CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique senectus "),
getRun(getParagraph(3), 3)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 2)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 2), "RedlineType"));
// delete last word of the third paragraph to remove tracked paragraph formatting
// of this paragraph to track and show word deletion correctly.
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/false);
pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// check tracking of the new text deletion
CPPUNIT_ASSERT_EQUAL(OUString("orci."), getRun(getParagraph(3), 7)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 6)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 6), "RedlineType"));
// make sure that the tracked paragraph formatting is removed (tracked deletion is in the second run)
CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique senectus "),
getRun(getParagraph(3), 2)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 1)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
// tdf#119824 check redo
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
rUndoManager.Undo();
rUndoManager.Redo();
rUndoManager.Redo();
// check again the first tracked text deletion (we lost this before the redo fix)
CPPUNIT_ASSERT_EQUAL(OUString("Pellentesque habitant morbi tristique senectus "),
getRun(getParagraph(3), 2)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 1)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
// check redo of the new tracked text deletion
CPPUNIT_ASSERT_EQUAL(OUString("orci."), getRun(getParagraph(3), 7)->getString());
CPPUNIT_ASSERT_EQUAL(OUString(""), getRun(getParagraph(3), 6)->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 6), "RedlineType"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf105413)
{
load(DATA_DIRECTORY, "tdf105413.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// all paragraphs have got Standard paragraph style
for (int i = 1; i < 4; ++i)
{
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(i), "ParaStyleName"));
}
// turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert
| RedlineFlags::ShowDelete);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// Set Heading 1 paragraph style in the 3th paragraph.
// Because of the tracked deleted region between them,
// this sets also the same style in the first paragraph automatically
// to keep the changed paragraph style at hiding tracked changes or saving the document
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/false);
uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({
{ "Style", uno::makeAny(OUString("Heading 1")) },
{ "FamilyName", uno::makeAny(OUString("ParagraphStyles")) },
});
dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
// first paragraph gets the same heading style
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817)
{
load(DATA_DIRECTORY, "num-parent-style.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("1.1"),
getProperty<OUString>(getParagraph(2), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("2.1"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
// set Heading 2 style of paragraph 2 to Heading 1
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({
{ "Style", uno::makeAny(OUString("Heading 1")) },
{ "FamilyName", uno::makeAny(OUString("ParagraphStyles")) },
});
dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
// This was "1 Heading" instead of "2 Heading"
CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty<OUString>(getParagraph(2), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
// This was "2.1 Heading"
CPPUNIT_ASSERT_EQUAL(OUString("3.1"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
// set Heading 1 style of paragraph 3 to Heading 2
pWrtShell->Down(/*bSelect=*/false);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
getProperty<sal_Int32>(getParagraph(3), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("3"), getProperty<OUString>(getParagraph(3), "ListLabelString"));
uno::Sequence<beans::PropertyValue> aPropertyValues2 = comphelper::InitPropertySequence({
{ "Style", uno::makeAny(OUString("Heading 2")) },
{ "FamilyName", uno::makeAny(OUString("ParagraphStyles")) },
});
dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues2);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(3), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("2.1"),
getProperty<OUString>(getParagraph(3), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("2.2"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817_custom_outline)
{
load(DATA_DIRECTORY, "tdf76817.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
getProperty<sal_Int32>(getParagraph(1), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(getParagraph(1), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
// This wasn't numbered
CPPUNIT_ASSERT_EQUAL(OUString("1.1"),
getProperty<OUString>(getParagraph(2), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
// This wasn't numbered
CPPUNIT_ASSERT_EQUAL(OUString("2.1"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
// set Heading 2 style of paragraph 2 to Heading 1
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({
{ "Style", uno::makeAny(OUString("Heading 1")) },
{ "FamilyName", uno::makeAny(OUString("ParagraphStyles")) },
});
dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty<OUString>(getParagraph(2), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(4), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
// This wasn't numbered
CPPUNIT_ASSERT_EQUAL(OUString("3.1"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf123102)
{
createDoc("tdf123102.odt");
// insert a new row after a vertically merged cell
dispatchCommand(mxComponent, ".uno:InsertRowsAfter", {});
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was "3." - caused by the hidden numbered paragraph of the new merged cell
assertXPath(pXmlDoc, "/root/page/body/tab/row[6]/cell[1]/txt/Special", "rText", "2.");
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButtonSmallTable)
{
// The floating table in the test document is too small, so we don't provide an unfloat button
load(FLOATING_TABLE_DATA_DIRECTORY, "small_floating_table.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
const SwSortedObjs* pAnchored
= pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT(pAnchored);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT(pFlyFrame);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT(pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButton)
{
// Different use cases where unfloat button should be visible
const std::vector<OUString> aTestFiles = {
"unfloatable_floating_table.odt", // Typical use case of multipage floating table
"unfloatable_floating_table.docx", // Need to test the DOCX import whether we detect the floating table correctly
"unfloatable_floating_table.doc", // Also the DOC import
"unfloatable_small_floating_table.docx" // Atypical use case, when the table is small, but because of it's position is it broken to two pages
};
for (const OUString& aTestFile : aTestFiles)
{
OString sTestFileName = OUStringToOString(aTestFile, RTL_TEXTENCODING_UTF8);
OString sFailureMessage = OStringLiteral("Failure in the test file: ") + sTestFileName;
load(FLOATING_TABLE_DATA_DIRECTORY, sTestFileName.getStr());
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pWrtShell);
const SwSortedObjs* pAnchored;
if (sTestFileName == "unfloatable_small_floating_table.docx")
pAnchored = pWrtShell->GetLayout()
->GetLower()
->GetLower()
->GetLower()
->GetNext()
->GetDrawObjs();
else
pAnchored = pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pAnchored);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), static_cast<size_t>(1),
pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
// The unfloat button is not visible until it gets selected
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloatButtonReadOnlyMode)
{
// In read only mode we don't show the unfloat button even if we have a multipage floating table
load(FLOATING_TABLE_DATA_DIRECTORY, "unfloatable_floating_table.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
pWrtShell->SetReadonlyOption(true);
const SwSortedObjs* pAnchored
= pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT(pAnchored);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT(pFlyFrame);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT(pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testUnfloating)
{
// Test unfloating with tables imported from different file formats
const std::vector<OUString> aTestFiles = {
"unfloatable_floating_table.odt",
"unfloatable_floating_table.docx",
"unfloatable_floating_table.doc",
};
for (const OUString& aTestFile : aTestFiles)
{
OString sTestFileName = OUStringToOString(aTestFile, RTL_TEXTENCODING_UTF8);
OString sFailureMessage = OStringLiteral("Failure in the test file: ") + sTestFileName;
// Test what happens when pushing the unfloat button
load(FLOATING_TABLE_DATA_DIRECTORY, "unfloatable_floating_table.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pWrtShell);
SwFlyFrame* pFlyFrame;
// Before unfloating we have only one page with a fly frame
{
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), SwFrameType::Page,
pWrtShell->GetLayout()->GetLower()->GetType());
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
!pWrtShell->GetLayout()->GetLower()->GetNext());
CPPUNIT_ASSERT_EQUAL_MESSAGE(
sFailureMessage.getStr(), SwFrameType::Txt,
pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
const SwSortedObjs* pAnchored
= pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pAnchored);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), static_cast<size_t>(1),
pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame);
}
// Select the floating table
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame->IsShowUnfloatButton(pWrtShell));
// Push the unfloat button
pFlyFrame->ActiveUnfloatButton(pWrtShell);
Scheduler::ProcessEventsToIdle();
// After unfloating we have two pages with one table frame on each page
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
pWrtShell->GetLayout()->GetLower()->GetNext());
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), SwFrameType::Page,
pWrtShell->GetLayout()->GetLower()->GetNext()->GetType());
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
!pWrtShell->GetLayout()->GetLower()->GetNext()->GetNext());
CPPUNIT_ASSERT_EQUAL_MESSAGE(
sFailureMessage.getStr(), SwFrameType::Tab,
pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
CPPUNIT_ASSERT_EQUAL_MESSAGE(
sFailureMessage.getStr(), SwFrameType::Tab,
pWrtShell->GetLayout()->GetLower()->GetNext()->GetLower()->GetLower()->GetType());
}
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRTLparaStyle_LocaleArabic)
{
// New documents, created in RTL locales, were not round-tripping the paragraph style as RTL.
// Set the locale to "ar" for this test - see preTest() at the top of this file.
std::unique_ptr<Resetter> const pChanges(preTest("LocaleArabic"));
createDoc(); // new, empty doc - everything defaults to RTL with Arabic locale
// Save it and load it back.
reload("Office Open XML Text", "tdf116404_paraStyleFrameDir.docx");
uno::Reference<beans::XPropertySet> xPageStyle(
getStyles("ParagraphStyles")->getByName("Default Paragraph Style"), uno::UNO_QUERY_THROW);
// Test the text Direction value for the -none- based paragraph styles
CPPUNIT_ASSERT_EQUAL_MESSAGE("RTL Writing Mode", sal_Int32(1),
getProperty<sal_Int32>(xPageStyle, "WritingMode"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf122893)
{
load(DATA_DIRECTORY, "tdf105413.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// all paragraphs are left-aligned with preset single line spacing
for (int i = 1; i < 4; ++i)
{
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(i), "ParaAdjust"));
dispatchCommand(mxComponent, ".uno:SpacePara1", {});
}
// turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert
| RedlineFlags::ShowDelete);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// Set center-aligned paragraph with preset double line spacing in the 3th paragraph.
// Because of the tracked deleted region between them,
// this sets also the same formatting in the first paragraph automatically
// to keep the changed paragraph formatting at hiding tracked changes or saving the document
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/false);
dispatchCommand(mxComponent, ".uno:CenterPara", {});
dispatchCommand(mxComponent, ".uno:SpacePara2", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // center-aligned
CPPUNIT_ASSERT_EQUAL(sal_Int16(200),
getProperty<style::LineSpacing>(getParagraph(3), "ParaLineSpacing")
.Height); // double line spacing
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // left-aligned
CPPUNIT_ASSERT_EQUAL(sal_Int16(100),
getProperty<style::LineSpacing>(getParagraph(2), "ParaLineSpacing")
.Height); // single line spacing
// first paragraph is also center-aligned with double line spacing
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty<sal_Int32>(getParagraph(1), "ParaAdjust"));
CPPUNIT_ASSERT_EQUAL(
sal_Int16(200), getProperty<style::LineSpacing>(getParagraph(1), "ParaLineSpacing").Height);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf122901)
{
load(DATA_DIRECTORY, "tdf105413.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// all paragraphs with zero borders
for (int i = 1; i < 4; ++i)
{
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(i), "ParaTopMargin"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(i), "ParaBottomMargin"));
}
// turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert
| RedlineFlags::ShowDelete);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// Increase paragraph borders in the 3th paragraph, similar to the default icon of the UI
// "Increase Paragraph Spacing". Because of the tracked deleted region between them,
// this sets also the same formatting in the first paragraph automatically
// to keep the changed paragraph formatting at hiding tracked changes or saving the document
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->EndPara(/*bSelect=*/false);
dispatchCommand(mxComponent, ".uno:ParaspaceIncrease", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(101), getProperty<sal_Int32>(getParagraph(3), "ParaTopMargin"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(101),
getProperty<sal_Int32>(getParagraph(3), "ParaBottomMargin"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(2), "ParaTopMargin"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(2), "ParaBottomMargin"));
// first paragraph is also center-aligned with double line spacing
CPPUNIT_ASSERT_EQUAL(sal_Int32(101), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(101),
getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf122942)
{
load(DATA_DIRECTORY, "tdf122942.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
// Do the moral equivalent of mouse button down, move and up.
// Start creating a custom shape that overlaps with the rounded rectangle
// already present in the document.
Point aStartPos(8000, 3000);
pWrtShell->BeginCreate(static_cast<sal_uInt16>(OBJ_CUSTOMSHAPE), aStartPos);
// Set its size.
Point aMovePos(10000, 5000);
pWrtShell->MoveCreate(aMovePos);
// Finish creation.
pWrtShell->EndCreate(SdrCreateCmd::ForceEnd);
// Make sure that the shape is inserted.
SwDoc* pDoc = pWrtShell->GetDoc();
const SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats.size());
reload("writer8", "tdf122942.odt");
pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pDoc = pWrtShell->GetDoc();
const SwFrameFormats& rFormats2 = *pDoc->GetSpzFrameFormats();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats2.size());
// Make sure the top of the inserted shape does not move outside the existing shape, even after
// reload.
SdrObject* pObject1 = rFormats2[0]->FindSdrObject();
CPPUNIT_ASSERT(pObject1);
const tools::Rectangle& rOutRect1 = pObject1->GetLastBoundRect();
SdrObject* pObject2 = rFormats2[1]->FindSdrObject();
CPPUNIT_ASSERT(pObject2);
const tools::Rectangle& rOutRect2 = pObject2->GetLastBoundRect();
CPPUNIT_ASSERT(rOutRect2.Top() > rOutRect1.Top() && rOutRect2.Top() < rOutRect1.Bottom());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf52391)
{
load(DATA_DIRECTORY, "tdf52391.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
const uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1), 1);
// this was "Portion1", because the tracked background color of Portion1 was
// accepted for "Reject All". Now rejection clears formatting of the text
// in format-only changes, concatenating the text portions in the first paragraph.
CPPUNIT_ASSERT_EQUAL(OUString("Portion1Portion2"), xRun->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126206)
{
load(DATA_DIRECTORY, "tdf126206.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// normal text (it was bold)
auto xText = getParagraph(1)->getText();
CPPUNIT_ASSERT(xText.is());
{
auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 4)));
CPPUNIT_ASSERT(xCursor.is());
CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, getProperty<float>(xCursor, "CharWeight"));
}
// reject tracked changes
dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
// bold text again
xText = getParagraph(1)->getText();
CPPUNIT_ASSERT(xText.is());
{
auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 3)));
CPPUNIT_ASSERT(xCursor.is());
CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xCursor, "CharWeight"));
}
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf101873)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
SwDocShell* pDocShell = pDoc->GetDocShell();
CPPUNIT_ASSERT(pDocShell);
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// Insert some content.
pWrtShell->Insert("something");
// Search for something which does not exist, twice.
uno::Sequence<beans::PropertyValue> aFirst(comphelper::InitPropertySequence({
{ "SearchItem.SearchString", uno::makeAny(OUString("fig")) },
{ "SearchItem.Backward", uno::makeAny(false) },
}));
dispatchCommand(mxComponent, ".uno:ExecuteSearch", aFirst);
dispatchCommand(mxComponent, ".uno:ExecuteSearch", aFirst);
uno::Sequence<beans::PropertyValue> aSecond(comphelper::InitPropertySequence({
{ "SearchItem.SearchString", uno::makeAny(OUString("something")) },
{ "SearchItem.Backward", uno::makeAny(false) },
}));
dispatchCommand(mxComponent, ".uno:ExecuteSearch", aSecond);
// Without the accompanying fix in place, this test would have failed with "Expected: something;
// Actual:", i.e. searching for "something" failed, even if it was inserted above.
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
CPPUNIT_ASSERT_EQUAL(OUString("something"), pShellCursor->GetText());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTableWidth)
{
load(DATA_DIRECTORY, "frame_size_export.docx");
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
// after exporting: table width was overwritten in the doc model
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int16(100),
getProperty<sal_Int16>(xTables->getByIndex(0), "RelativeWidth"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTextFormFieldInsertion)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a text form field
dispatchCommand(mxComponent, ".uno:TextFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMTEXT), pFieldmark->GetFieldname());
// The text form field has the placeholder text in it
uno::Reference<text::XTextRange> xPara = getParagraph(1);
sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
// Undo insertion
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
xPara.set(getParagraph(1));
CPPUNIT_ASSERT(xPara->getString().isEmpty());
// Redo insertion
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
xPara.set(getParagraph(1));
CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testCheckboxFormFieldInsertion)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a checkbox form field
dispatchCommand(mxComponent, ".uno:CheckBoxFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname());
// The checkbox is not checked by default
::sw::mark::ICheckboxFieldmark* pCheckBox
= dynamic_cast<::sw::mark::ICheckboxFieldmark*>(pFieldmark);
CPPUNIT_ASSERT(pCheckBox);
CPPUNIT_ASSERT(!pCheckBox->IsChecked());
// Undo insertion
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Redo insertion
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDropDownFormFieldInsertion)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a drop-down form field
dispatchCommand(mxComponent, ".uno:DropDownFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
// Check drop down field's parameters. By default these params are not set
const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
auto pListEntries = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
CPPUNIT_ASSERT(bool(pListEntries == pParameters->end()));
auto pResult = pParameters->find(ODF_FORMDROPDOWN_RESULT);
CPPUNIT_ASSERT(bool(pResult == pParameters->end()));
// Undo insertion
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Redo insertion
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testMixedFormFieldInsertion)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert fields
dispatchCommand(mxComponent, ".uno:TextFormField", {});
dispatchCommand(mxComponent, ".uno:CheckBoxFormField", {});
dispatchCommand(mxComponent, ".uno:DropDownFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pMarkAccess->getAllMarksCount());
// Undo insertion
dispatchCommand(mxComponent, ".uno:Undo", {});
dispatchCommand(mxComponent, ".uno:Undo", {});
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Redo insertion
dispatchCommand(mxComponent, ".uno:Redo", {});
dispatchCommand(mxComponent, ".uno:Redo", {});
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pMarkAccess->getAllMarksCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf124261)
{
#if !defined(_WIN32)
// Make sure that pressing a key in a btlr cell frame causes an immediate, correct repaint.
SwDoc* pDoc = createDoc("tdf124261.docx");
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPageFrame = pLayout->GetLower();
CPPUNIT_ASSERT(pPageFrame->IsPageFrame());
SwFrame* pBodyFrame = pPageFrame->GetLower();
CPPUNIT_ASSERT(pBodyFrame->IsBodyFrame());
SwFrame* pTabFrame = pBodyFrame->GetLower();
CPPUNIT_ASSERT(pTabFrame->IsTabFrame());
SwFrame* pRowFrame = pTabFrame->GetLower();
CPPUNIT_ASSERT(pRowFrame->IsRowFrame());
SwFrame* pCellFrame = pRowFrame->GetLower();
CPPUNIT_ASSERT(pCellFrame->IsCellFrame());
SwFrame* pFrame = pCellFrame->GetLower();
CPPUNIT_ASSERT(pFrame->IsTextFrame());
// Make sure that the text frame's area and the paint rectangle match.
// Without the accompanying fix in place, this test would have failed with 'Expected: 1721;
// Actual: 1547', i.e. an area other than the text frame was invalidated for a single-line
// paragraph.
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pFrame);
SwRect aRect = pTextFrame->GetPaintSwRect();
CPPUNIT_ASSERT_EQUAL(pTextFrame->getFrameArea().Top(), aRect.Top());
#endif
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDocxAttributeTableExport)
{
createDoc("floating-table-position.docx");
// get the table frame, set new values and dismiss the references
{
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
// change the properties
// 8133 -> 8000
xShape->setPropertyValue("VertOrientPosition", uno::makeAny(static_cast<sal_Int32>(8000)));
// 5964 -> 5000
xShape->setPropertyValue("HoriOrientPosition", uno::makeAny(static_cast<sal_Int32>(5000)));
// 0 (frame) -> 8 (page print area)
xShape->setPropertyValue("VertOrientRelation", uno::makeAny(static_cast<sal_Int16>(8)));
// 8 (page print area) -> 0 (frame)
xShape->setPropertyValue("HoriOrientRelation", uno::makeAny(static_cast<sal_Int16>(0)));
}
// save it to docx
reload("Office Open XML Text", "floating-table-position.docx");
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
// test the new values
sal_Int32 nValue = getProperty<sal_Int32>(xShape, "VertOrientPosition");
CPPUNIT_ASSERT(sal_Int32(7999) <= nValue && nValue <= sal_Int32(8001));
nValue = getProperty<sal_Int32>(xShape, "HoriOrientPosition");
CPPUNIT_ASSERT(sal_Int32(4999) <= nValue && nValue <= sal_Int32(5001));
CPPUNIT_ASSERT_EQUAL(sal_Int16(8), getProperty<sal_Int16>(xShape, "VertOrientRelation"));
CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(xShape, "HoriOrientRelation"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf118699_redline_numbering)
{
load(DATA_DIRECTORY, "tdf118699.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
uno::Reference<beans::XPropertySet> xProps(getParagraph(2), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("first paragraph after the first deletion: erroneous numbering",
!xProps->getPropertyValue("NumberingRules").hasValue());
CPPUNIT_ASSERT_MESSAGE(
"first paragraph after the second deletion: missing numbering",
getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(5), "NumberingRules")
.is());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125881_redline_list_level)
{
load(DATA_DIRECTORY, "tdf125881.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<beans::XPropertySet> xProps(getParagraph(8), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("deleted paragraph: erroneous numbering",
!xProps->getPropertyValue("NumberingRules").hasValue());
// deleted paragraph gets the numbering of the next paragraph
uno::Reference<beans::XPropertySet> xProps2(getParagraph(9), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("first paragraph after the first deletion: missing numbering",
xProps2->getPropertyValue("NumberingRules").hasValue());
// check numbering level at deletion (1 instead of 0)
CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(getParagraph(9), "NumberingLevel"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125916_redline_restart_numbering)
{
load(DATA_DIRECTORY, "tdf125916.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
// check unnecessary numbering
uno::Reference<beans::XPropertySet> xProps(getParagraph(3), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("first paragraph after the first deletion: erroneous numbering",
!xProps->getPropertyValue("NumberingRules").hasValue());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125310)
{
load(DATA_DIRECTORY, "tdf125310.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(1, getPages());
// turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
// paragraph join
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
pWrtShell->EndPara(/*bSelect=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
// copied paragraph style
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
// without copying the page break
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125310b)
{
SwDoc* pDoc = createDoc("tdf125310b.fodt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(2, getPages());
// turn on red-lining and show changes
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
// remove second paragraph with the page break
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Down(/*bSelect=*/false);
pWrtShell->Up(/*bSelect=*/true);
pWrtShell->DelLeft();
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
// losing the page break, as without redlining
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120336)
{
load(DATA_DIRECTORY, "tdf120336.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// turn on red-lining and show changes
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
| RedlineFlags::ShowInsert);
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
CPPUNIT_ASSERT_MESSAGE(
"redlines should be visible",
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
CPPUNIT_ASSERT_EQUAL(2, getPages());
IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
rIDRA.AcceptAllRedline(true);
// keep page break, as without redlining
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf106843)
{
load(DATA_DIRECTORY, "tdf106843.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
// try to turn off red-lining
dispatchCommand(mxComponent, ".uno:TrackChanges", {});
// but the protection doesn't allow it
CPPUNIT_ASSERT_MESSAGE("redlining should be on",
pDoc->getIDocumentRedlineAccess().IsRedlineOn());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageComment)
{
// Load a document with an as-char image in it.
SwDoc* pDoc = createDoc("image-comment.odt");
SwView* pView = pDoc->GetDocShell()->GetView();
// Test document has "before<image>after", remove the content before the image.
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 6, /*bBasicCall=*/false);
pWrtShell->Delete();
// Select the image.
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Insert a comment while the image is selected.
pView->GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT, SfxCallMode::SYNCHRON);
// Verify that the comment is around the image.
// Without the accompanying fix in place, this test would have failed, as FN_POSTIT was disabled
// in the frame shell.
// Then this test would have failed, as in case the as-char anchored image was at the start of
// the paragraph, the comment of the image covered the character after the image, not the image.
uno::Reference<text::XTextRange> xPara = getParagraph(1);
CPPUNIT_ASSERT_EQUAL(OUString("Annotation"),
getProperty<OUString>(getRun(xPara, 1), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("Frame"),
getProperty<OUString>(getRun(xPara, 2), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"),
getProperty<OUString>(getRun(xPara, 3), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("Text"),
getProperty<OUString>(getRun(xPara, 4), "TextPortionType"));
// Insert content to the comment, and select the image again.
SfxStringItem aItem(FN_INSERT_STRING, "x");
pView->GetViewFrame()->GetDispatcher()->ExecuteList(FN_INSERT_STRING, SfxCallMode::SYNCHRON,
{ &aItem });
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
#if !defined(MACOSX)
// Calc the left edge of the as-char frame.
SwRootFrame* pLayout = pWrtShell->GetLayout();
SwFrame* pPage = pLayout->GetLower();
SwFrame* pBody = pPage->GetLower();
SwFrame* pTextFrame = pBody->GetLower();
CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
const SwSortedObjs& rAnchored = *pTextFrame->GetDrawObjs();
CPPUNIT_ASSERT_GREATER(static_cast<size_t>(0), rAnchored.size());
SwAnchoredObject* pObject = rAnchored[0];
long nFrameLeft = pObject->GetObjRect().Left();
long nFrameTop = pObject->GetObjRect().Top();
// Make sure that the anchor points to the bottom left corner of the image.
// Without the accompanying fix in place, this test would have failed with:
// - Expected less or equal than: 1418
// - Actual: 2442
// The anchor pointed to the bottom right corner, so as-char and at-char was inconsistent.
Scheduler::ProcessEventsToIdle();
SwPostItMgr* pPostItMgr = pView->GetPostItMgr();
for (const auto& pItem : *pPostItMgr)
{
const SwRect& rAnchor = pItem->pPostIt->GetAnchorRect();
CPPUNIT_ASSERT_EQUAL(nFrameLeft, rAnchor.Left());
}
// Test the comment anchor we expose via the LOK API.
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1418, 1418, 0, 0
// - Actual : 1418, 1418, 1024, 1024
// I.e. the anchor position had a non-empty size, which meant different rendering via tiled
// rendering and on the desktop.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
OUString aPostits = pTextDoc->getPostIts();
std::stringstream aStream(aPostits.toUtf8().getStr());
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
for (const boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments"))
{
const boost::property_tree::ptree& rComment = rValue.second;
OString aAnchorPos(rComment.get<std::string>("anchorPos").c_str());
OString aExpected
= OString::number(nFrameLeft) + ", " + OString::number(nFrameTop) + ", 0, 0";
CPPUNIT_ASSERT_EQUAL(aExpected, aAnchorPos);
}
#endif
// Now delete the image.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
// Without the accompanying fix in place, this test would have failed with 'Expected: 0; Actual:
// 1', i.e. the comment of the image was not deleted when the image was deleted.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar)
{
// Load a document with an at-char image in it.
SwDoc* pDoc = createDoc("image-comment-at-char.odt");
SwView* pView = pDoc->GetDocShell()->GetView();
// Select the image.
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Insert a comment while the image is selected.
pView->GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT, SfxCallMode::SYNCHRON);
// Verify that the comment is around the image.
// Without the accompanying fix in place, this test would have failed, as the comment was
// anchored at the end of the paragraph, it was not around the image.
uno::Reference<text::XTextRange> xPara = getParagraph(1);
CPPUNIT_ASSERT_EQUAL(OUString("Text"),
getProperty<OUString>(getRun(xPara, 1), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("Annotation"),
getProperty<OUString>(getRun(xPara, 2), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("Frame"),
getProperty<OUString>(getRun(xPara, 3), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"),
getProperty<OUString>(getRun(xPara, 4), "TextPortionType"));
CPPUNIT_ASSERT_EQUAL(OUString("Text"),
getProperty<OUString>(getRun(xPara, 5), "TextPortionType"));
// Insert content to the comment, and select the image again.
SfxStringItem aItem(FN_INSERT_STRING, "x");
pView->GetViewFrame()->GetDispatcher()->ExecuteList(FN_INSERT_STRING, SfxCallMode::SYNCHRON,
{ &aItem });
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Now delete the image.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
// Without the accompanying fix in place, this test would have failed with 'Expected: 0; Actual:
// 1', i.e. the comment of the image was not deleted when the image was deleted.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount());
// Undo the deletion and move the image down, so the anchor changes.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount());
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
Point aNewAnchor = pWrtShell->GetFlyRect().TopLeft();
aNewAnchor.Move(0, 600);
pWrtShell->SetFlyPos(aNewAnchor);
// Get the image anchor doc model position.
SwFlyFrame* pFly = pWrtShell->GetCurrFlyFrame(false);
CPPUNIT_ASSERT(pFly);
SwFrameFormat& rFlyFormat = pFly->GetFrameFormat();
const SwPosition* pImageAnchor = rFlyFormat.GetAnchor().GetContentAnchor();
CPPUNIT_ASSERT(pImageAnchor);
// Get the annotation mark doc model start.
auto it = pDoc->getIDocumentMarkAccess()->getAnnotationMarksBegin();
CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAnnotationMarksEnd());
const sw::mark::IMark* pMark = *it;
const SwPosition& rAnnotationMarkStart = pMark->GetMarkPos();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: SwPosition (node 14, offset 15)
// - Actual : SwPosition (node 12, offset 3)
// This means moving the image anchor did not move the comment anchor / annotation mark, so the
// image and its comment got out of sync.
CPPUNIT_ASSERT_EQUAL(*pImageAnchor, rAnnotationMarkStart);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338)
{
load(DATA_DIRECTORY, "tdf120338.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // right
CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // right
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(4), "ParaAdjust")); // left
CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
getProperty<sal_Int32>(getParagraph(5), "ParaAdjust")); // right
CPPUNIT_ASSERT_EQUAL(OUString(""),
getProperty<OUString>(getParagraph(7), "NumberingStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("WWNum2"),
getProperty<OUString>(getParagraph(8), "NumberingStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(10), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(11), "ParaStyleName"));
// reject tracked paragraph adjustments
dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // left
CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // center
CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
getProperty<sal_Int32>(getParagraph(4), "ParaAdjust")); // center
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
getProperty<sal_Int32>(getParagraph(5), "ParaAdjust")); // left
// tdf#126245 revert numbering changes
CPPUNIT_ASSERT_EQUAL(OUString("WWNum2"),
getProperty<OUString>(getParagraph(7), "NumberingStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString(""),
getProperty<OUString>(getParagraph(8), "NumberingStyleName"));
// tdf#126243 revert paragraph styles
CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
getProperty<OUString>(getParagraph(10), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 3"),
getProperty<OUString>(getParagraph(11), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338_multiple_paragraph_join)
{
load(DATA_DIRECTORY, "redline-para-join.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
// reject tracked paragraph styles
dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
getProperty<OUString>(getParagraph(2), "ParaStyleName"));
CPPUNIT_ASSERT_EQUAL(OUString("Heading 3"),
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testShapePageMove)
{
// Load a document with 2 pages, shape on the first page.
SwDoc* pDoc = createDoc("shape-page-move.odt");
SwView* pView = pDoc->GetDocShell()->GetView();
// Make sure that the 2nd page is below the 1st one.
pView->SetViewLayout(/*nColumns=*/1, /*bBookMode=*/false);
calcLayout();
// Select the shape.
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the
// SwView ctor.
pView->StopShellTimer();
// Move the shape down to the 2nd page.
SfxInt32Item aXItem(SID_ATTR_TRANSFORM_POS_X, 4000);
SfxInt32Item aYItem(SID_ATTR_TRANSFORM_POS_Y, 12000);
pView->GetViewFrame()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM, SfxCallMode::SYNCHRON,
{ &aXItem, &aYItem });
// Check if the shape anchor was moved to the 2nd page as well.
SwFrameFormats* pShapeFormats = pDoc->GetSpzFrameFormats();
CPPUNIT_ASSERT(!pShapeFormats->empty());
auto it = pShapeFormats->begin();
SwFrameFormat* pShapeFormat = *it;
const SwPosition* pAnchor = pShapeFormat->GetAnchor().GetContentAnchor();
CPPUNIT_ASSERT(pAnchor);
// Find out the node index of the 1st para on the 2nd page.
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pFirstPage = pLayout->Lower();
SwFrame* pSecondPage = pFirstPage->GetNext();
CPPUNIT_ASSERT(pSecondPage->IsLayoutFrame());
SwFrame* pBodyFrame = static_cast<SwLayoutFrame*>(pSecondPage)->GetLower();
CPPUNIT_ASSERT(pBodyFrame->IsLayoutFrame());
SwFrame* pTextFrame = static_cast<SwLayoutFrame*>(pBodyFrame)->GetLower();
CPPUNIT_ASSERT(pTextFrame->IsTextFrame());
sal_uLong nNodeIndex = static_cast<SwTextFrame*>(pTextFrame)->GetTextNodeFirst()->GetIndex();
// Without the accompanying fix in place, this test would have failed with "Expected: 13;
// Actual: 12", i.e. the shape was anchored to the last paragraph of the 1st page, not to a
// paragraph on the 2nd page.
CPPUNIT_ASSERT_EQUAL(nNodeIndex, pAnchor->nNode.GetIndex());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldInsertion)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a date form field
dispatchCommand(mxComponent, ".uno:DatePickerFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
// The date form field has the placeholder text in it
uno::Reference<text::XTextRange> xPara = getParagraph(1);
sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
// Undo insertion
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Redo insertion
dispatchCommand(mxComponent, ".uno:Redo", {});
aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldContentOperations)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a date form field
dispatchCommand(mxComponent, ".uno:DatePickerFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
// Check the default content added by insertion
uno::Reference<text::XTextRange> xPara = getParagraph(1);<--- Variable 'xPara' is assigned a value that is never used.
sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent());
// Set content to empty string
pFieldmark->ReplaceContent("");
CPPUNIT_ASSERT_EQUAL(OUString(""), pFieldmark->GetContent());
// Replace empty string with a valid content
pFieldmark->ReplaceContent("2019-10-23");
CPPUNIT_ASSERT_EQUAL(OUString("2019-10-23"), pFieldmark->GetContent());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldCurrentDateHandling)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a date form field
dispatchCommand(mxComponent, ".uno:DatePickerFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
// The default content is not a valid date
uno::Reference<text::XTextRange> xPara = getParagraph(1);<--- Variable 'xPara' is assigned a value that is never used.
sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent());
std::pair<bool, double> aResult = pFieldmark->GetCurrentDate();
CPPUNIT_ASSERT(!aResult.first);
// Check empty string
pFieldmark->ReplaceContent("");
aResult = pFieldmark->GetCurrentDate();
CPPUNIT_ASSERT(!aResult.first);
// Check valid date
// Set date format first
sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters();
(*pParameters)[ODF_FORMDATE_DATEFORMAT] <<= OUString("YYYY/MM/DD");
(*pParameters)[ODF_FORMDATE_DATEFORMAT_LANGUAGE] <<= OUString("en-US");
// Set date value and check whether the content is formatted correctly
pFieldmark->SetCurrentDate(48000.0);
aResult = pFieldmark->GetCurrentDate();
CPPUNIT_ASSERT(aResult.first);
CPPUNIT_ASSERT_EQUAL(48000.0, aResult.second);
CPPUNIT_ASSERT_EQUAL(OUString("2031/06/01"), pFieldmark->GetContent());
// Current date param contains date in a "standard format"
OUString sCurrentDate;
auto pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
if (pResult != pParameters->end())
{
pResult->second >>= sCurrentDate;
}
CPPUNIT_ASSERT_EQUAL(OUString("2031-06-01"), sCurrentDate);
}
#if !defined(_WIN32)
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldCurrentDateInvalidation)
{
SwDoc* pDoc = createDoc();
CPPUNIT_ASSERT(pDoc);
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT(pMarkAccess);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
// Insert a date form field
dispatchCommand(mxComponent, ".uno:DatePickerFormField", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
// Check whether the fieldmark is created
auto aIter = pMarkAccess->getAllMarksBegin();
CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
// Set a date first
sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters();
pFieldmark->SetCurrentDate(48000.0);
std::pair<bool, double> aResult = pFieldmark->GetCurrentDate();
CPPUNIT_ASSERT(aResult.first);
CPPUNIT_ASSERT_EQUAL(48000.0, aResult.second);
// Do the layouting to trigger invalidation
// Since we have the current date consistent with the field content
// This invalidation won't change anything
calcLayout();
Scheduler::ProcessEventsToIdle();
// Current date param contains date in a "standard format"
OUString sCurrentDate;
auto pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
if (pResult != pParameters->end())
{
pResult->second >>= sCurrentDate;
}
// We have the current date parameter set
CPPUNIT_ASSERT_EQUAL(OUString("2031-06-01"), sCurrentDate);
// Now change the content of the field
pFieldmark->ReplaceContent("[select date]");
// Do the layouting to trigger invalidation
calcLayout();
Scheduler::ProcessEventsToIdle();
sCurrentDate.clear();
pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
if (pResult != pParameters->end())
{
pResult->second >>= sCurrentDate;
}
CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate);
}
#endif
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testOleSaveWhileEdit)
{
// 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.
SwDoc* pDoc = createDoc("ole-save-while-edit.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any);
// Select the frame and switch to the frame shell.
SwView* pView = pDoc->GetDocShell()->GetView();
pView->StopShellTimer();
// Start editing the OLE object.
pWrtShell->LaunchOLEObj();
// Save the document without existing the OLE edit.
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
xStorable->storeToURL(maTempFile.GetURL(), {});
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory),
maTempFile.GetURL());
// Without the accompanying fix in place, this test would have failed: the OLE object lost its
// replacement on save if the edit was active while saving.
CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 1"));
// Dispose the document while LOK is still active to avoid leaks.
mxComponent->dispose();
mxComponent.clear();
comphelper::LibreOfficeKit::setActive(false);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf105330)
{
load(DATA_DIRECTORY, "tdf105330.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
SwView* pView = pDoc->GetDocShell()->GetView();
SfxUInt16Item aRows(SID_ATTR_TABLE_ROW, 1);
SfxUInt16Item aColumns(SID_ATTR_TABLE_COLUMN, 1);
pView->GetViewFrame()->GetDispatcher()->ExecuteList(FN_INSERT_TABLE, SfxCallMode::SYNCHRON,
{ &aRows, &aColumns });
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
// Without the accompanying fix in place, height was only 1 twips (practically invisible).
// Require at least 12pt height (font size under the cursor), in twips.
CPPUNIT_ASSERT_GREATEREQUAL(
static_cast<long>(240),
pWrtShell->GetVisibleCursor()->GetTextCursor().GetSize().getHeight());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf118311)
{
load(DATA_DIRECTORY, "tdf118311.fodt");
SwXTextDocument* pDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pDoc);
SwDocShell* pDocShell = pDoc->GetDocShell();
CPPUNIT_ASSERT(pDocShell);
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// Jump to the first cell, selecting its content
uno::Sequence<beans::PropertyValue> aSearch(comphelper::InitPropertySequence({
{ "SearchItem.SearchString", uno::makeAny(OUString("a")) },
{ "SearchItem.Backward", uno::makeAny(false) },
}));
dispatchCommand(mxComponent, ".uno:ExecuteSearch", aSearch);
// .uno:Cut doesn't remove the table, only the selected content of the first cell
dispatchCommand(mxComponent, ".uno:Cut", {});
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "//page[1]//body/tab");
// .uno:SelectAll selects the whole table, and UNO command Cut cuts it
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Cut", {});
discardDumpedLayout();
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "//page[1]//body/tab", 0);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf128335)
{
// Load the bugdoc, which has 3 textboxes.
SwDoc* pDoc = createDoc("tdf128335.odt");
// Select the 3rd textbox.
SwView* pView = pDoc->GetDocShell()->GetView();
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the
// SwView ctor.
pView->StopShellTimer();
SwXTextDocument* pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
// Cut it.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_CUT, SfxCallMode::SYNCHRON);
// Paste it: this makes the 3rd textbox anchored in the 2nd one.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_PASTE, SfxCallMode::SYNCHRON);
// Select all shapes.
uno::Reference<view::XSelectionSupplier> xSelectionSupplier(
pXTextDocument->getCurrentController(), uno::UNO_QUERY);
xSelectionSupplier->select(pXTextDocument->getDrawPages()->getByIndex(0));
// Cut them.
// Without the accompanying fix in place, this test would have crashed as the textboxes were
// deleted in an incorrect order.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_CUT, SfxCallMode::SYNCHRON);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf128603)
{
// Load the bugdoc, which has 3 textboxes.
SwDoc* pDoc = createDoc("tdf128603.odt");
// Select the 3rd textbox.
SwView* pView = pDoc->GetDocShell()->GetView();
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
// Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the
// SwView ctor.
pView->StopShellTimer();
SwXTextDocument* pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
// Cut it.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_CUT, SfxCallMode::SYNCHRON);
// Paste it: this makes the 3rd textbox anchored in the 2nd one.
pView->GetViewFrame()->GetDispatcher()->Execute(SID_PASTE, SfxCallMode::SYNCHRON);
// Undo all of this.
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
rUndoManager.Undo();
// Make sure the content indexes still match.
const SwFrameFormats& rSpzFrameFormats = *pDoc->GetSpzFrameFormats();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(6), rSpzFrameFormats.size());
const SwNodeIndex* pIndex4 = rSpzFrameFormats[4]->GetContent().GetContentIdx();
CPPUNIT_ASSERT(pIndex4);
const SwNodeIndex* pIndex5 = rSpzFrameFormats[5]->GetContent().GetContentIdx();
CPPUNIT_ASSERT(pIndex5);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 11
// - Actual : 14
// i.e. the shape content index and the frame content index did not match after undo, even if
// their "other text box format" pointers pointed to each other.
CPPUNIT_ASSERT_EQUAL(pIndex4->GetIndex(), pIndex5->GetIndex());
}
// only care that it doesn't assert/crash
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testOfz18563)
{
OUString sURL(m_directories.getURLFromSrc("/sw/qa/extras/uiwriter/data2/ofz18563.docx"));
SvFileStream aFileStream(sURL, StreamMode::READ);
TestImportDOCX(aFileStream);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf90069)
{
SwDoc* pDoc = createDoc("tdf90069.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDocShell* pDocShell = pTextDoc->GetDocShell();
CPPUNIT_ASSERT(pDocShell);
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
sal_uLong nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
dispatchCommand(mxComponent, ".uno:InsertRowsAfter", {});
pWrtShell->Down(false);
pWrtShell->Insert("foo");
SwTextNode* pTextNodeA1 = static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex]);
CPPUNIT_ASSERT(pTextNodeA1->GetText().startsWith("Insert"));
nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
SwTextNode* pTextNodeA2 = static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex]);
CPPUNIT_ASSERT_EQUAL(OUString("foo"), pTextNodeA2->GetText());
CPPUNIT_ASSERT_EQUAL(true, pTextNodeA2->GetSwAttrSet().HasItem(RES_CHRATR_FONT));
OUString sFontName = pTextNodeA2->GetSwAttrSet().GetItem(RES_CHRATR_FONT)->GetFamilyName();
CPPUNIT_ASSERT_EQUAL(OUString("Lohit Devanagari"), sFontName);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf129655)
{
createDoc("tdf129655-vtextbox.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "//fly/txt[@WritingMode='Vertical']", 1);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|