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
|
/* -*- 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 "charttest.hxx"
#include <com/sun/star/chart2/DataPointLabel.hpp>
#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart/XChartDocument.hpp>
#include <com/sun/star/chart2/XInternalDataProvider.hpp>
#include <com/sun/star/chart/XAxisXSupplier.hpp>
#include <com/sun/star/chart/DataLabelPlacement.hpp>
#include <com/sun/star/text/XText.hpp>
class Chart2ImportTest2 : public ChartTest
{
public:
void testTdf114179();
void testTdf124243();
void testTdf127393();
void testTdf128733();
void testTdf128432();
void testTdf128627();
void testTdf128634();
void testTdf130657();
void testDeletedDataLabel();
void testDataPointInheritedColorDOCX();
void testExternalStrRefsXLSX();
void testSourceNumberFormatComplexCategoriesXLS();
void testSimpleCategoryAxis();
void testMultilevelCategoryAxis();
void testXaxisValues();
void testTdf123504();
void testTdf122765();
void testTdf123206CustomLabelField();
void testTdf125444PercentageCustomLabel();
void testDataPointLabelCustomPos();
void testTdf130032();
void testTdf134978();
void testTdf119138MissingAutoTitleDeleted();
void testStockChartShiftedCategoryPosition();
void testTdf133376();
void testTdf134225();
void testTdf136105();
void testTdf91250();
void testTdf134111();
void testTdf136752();
void testTdf137505();
void testTdf137734();
void testTdf137874();
void testTdf146463();
void testTdfCustomShapePos();
void testTdf121281();
void testTdf139658();
void testTdf146066();
CPPUNIT_TEST_SUITE(Chart2ImportTest2);
CPPUNIT_TEST(testTdf114179);
CPPUNIT_TEST(testTdf124243);
CPPUNIT_TEST(testTdf127393);
CPPUNIT_TEST(testTdf128733);
CPPUNIT_TEST(testTdf128432);
CPPUNIT_TEST(testTdf128627);
CPPUNIT_TEST(testTdf128634);
CPPUNIT_TEST(testTdf130657);
CPPUNIT_TEST(testDeletedDataLabel);
CPPUNIT_TEST(testDataPointInheritedColorDOCX);
CPPUNIT_TEST(testExternalStrRefsXLSX);
CPPUNIT_TEST(testSourceNumberFormatComplexCategoriesXLS);
CPPUNIT_TEST(testSimpleCategoryAxis);
CPPUNIT_TEST(testMultilevelCategoryAxis);
CPPUNIT_TEST(testXaxisValues);
CPPUNIT_TEST(testTdf123504);
CPPUNIT_TEST(testTdf122765);
CPPUNIT_TEST(testTdf123206CustomLabelField);
CPPUNIT_TEST(testTdf125444PercentageCustomLabel);
CPPUNIT_TEST(testDataPointLabelCustomPos);
CPPUNIT_TEST(testTdf130032);
CPPUNIT_TEST(testTdf134978);
CPPUNIT_TEST(testTdf119138MissingAutoTitleDeleted);
CPPUNIT_TEST(testStockChartShiftedCategoryPosition);
CPPUNIT_TEST(testTdf133376);
CPPUNIT_TEST(testTdf134225);
CPPUNIT_TEST(testTdf136105);
CPPUNIT_TEST(testTdf91250);
CPPUNIT_TEST(testTdf134111);
CPPUNIT_TEST(testTdf136752);
CPPUNIT_TEST(testTdf137505);
CPPUNIT_TEST(testTdf137734);
CPPUNIT_TEST(testTdf137874);
CPPUNIT_TEST(testTdf146463);
CPPUNIT_TEST(testTdfCustomShapePos);
CPPUNIT_TEST(testTdf121281);
CPPUNIT_TEST(testTdf139658);
CPPUNIT_TEST(testTdf146066);
CPPUNIT_TEST_SUITE_END();
};
void Chart2ImportTest2::testTdf114179()
{
load(u"/chart2/qa/extras/data/docx/", u"testTdf114179.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
css::uno::Reference<chart2::XDiagram> xDiagram;
xDiagram.set(xChartDoc->getFirstDiagram());
CPPUNIT_ASSERT_MESSAGE("There is a Diagram.", xDiagram.is());
awt::Size aPage = getPageSize(xChartDoc);
awt::Size aSize = getSize(xDiagram, aPage);
CPPUNIT_ASSERT(aSize.Width > 0);
CPPUNIT_ASSERT(aSize.Height > 0);
}
void Chart2ImportTest2::testTdf124243()
{
load(u"/chart2/qa/extras/data/docx/", u"tdf124243.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY_THROW);
bool bShow = true;
// test X Axis is not visible.
bool bSuccess = xPS->getPropertyValue("Show") >>= bShow;
CPPUNIT_ASSERT(bSuccess);
CPPUNIT_ASSERT(!bShow);
}
void Chart2ImportTest2::testTdf127393()
{
load(u"/chart2/qa/extras/data/pptx/", u"tdf127393.pptx");
// 1st chart
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData1 = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData1.Categories.is());
CPPUNIT_ASSERT(aScaleData1.ShiftedCategoryPosition);
// 2nd chart
xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
xAxis.set(getAxisFromDoc(xChartDoc, 0, 0, 0));
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData2 = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData2.Categories.is());
CPPUNIT_ASSERT(!aScaleData2.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf128733()
{
load(u"/chart2/qa/extras/data/odt/", u"tdf128733.odt");
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
// test secondary X axis ShiftedCategoryPosition value
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 1);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(aScaleData.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf128432()
{
load(u"/chart2/qa/extras/data/ods/", u"tdf128432.ods");
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(aScaleData.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf128627()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf128627.xlsx");
// Test ShiftedCategoryPosition for Radar Chart
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(!aScaleData.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf128634()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf128634.xlsx");
// Test ShiftedCategoryPosition for 3D Charts
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(aScaleData.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf130657()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf130657.xlsx");
// Test ShiftedCategoryPosition for charts which is not contain a "crossbetween" OOXML tag.
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(aScaleData.ShiftedCategoryPosition);
}
namespace
{
void checkDataLabelProperties(const Reference<chart2::XDataSeries>& xDataSeries,
sal_Int32 nDataPointIndex, bool bValueVisible)
{
uno::Reference<beans::XPropertySet> xPropertySet(
xDataSeries->getDataPointByIndex(nDataPointIndex), uno::UNO_SET_THROW);
chart2::DataPointLabel aLabel;
xPropertySet->getPropertyValue("Label") >>= aLabel;
CPPUNIT_ASSERT_EQUAL(bValueVisible, static_cast<bool>(aLabel.ShowNumber));
CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(aLabel.ShowNumberInPercent));
}
}
void Chart2ImportTest2::testDeletedDataLabel()
{
load(u"/chart2/qa/extras/data/xlsx/", u"deleted_data_labels.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartCompFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<chart2::XDataSeries> xDataSeries0 = getDataSeriesFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT(xDataSeries0.is());
checkDataLabelProperties(xDataSeries0, 0, true);
checkDataLabelProperties(xDataSeries0, 1, false);
checkDataLabelProperties(xDataSeries0, 2, true);
Reference<chart2::XDataSeries> xDataSeries1 = getDataSeriesFromDoc(xChartDoc, 1);
CPPUNIT_ASSERT(xDataSeries1.is());
checkDataLabelProperties(xDataSeries1, 0, false);
checkDataLabelProperties(xDataSeries1, 1, false);
checkDataLabelProperties(xDataSeries1, 2, false);
}
void Chart2ImportTest2::testDataPointInheritedColorDOCX()
{
load(u"/chart2/qa/extras/data/docx/", u"data_point_inherited_color.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
css::uno::Reference<chart2::XDiagram> xDiagram(xChartDoc->getFirstDiagram(), UNO_SET_THROW);
Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(0),
uno::UNO_SET_THROW);
CPPUNIT_ASSERT(xPropertySet.is());
sal_Int32 nColor = xPropertySet->getPropertyValue("FillColor").get<sal_Int32>();
CPPUNIT_ASSERT_EQUAL(sal_Int32(16776960), nColor);
}
void Chart2ImportTest2::testExternalStrRefsXLSX()
{
load(u"/chart2/qa/extras/data/xlsx/", u"external_str_ref.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartCompFromSheet(0, mxComponent),
UNO_QUERY_THROW);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
chart2::ScaleData aScaleData = xAxis->getScaleData();
css::uno::Sequence<css::uno::Any> aValues = aScaleData.Categories->getValues()->getData();
CPPUNIT_ASSERT_EQUAL(OUString("test1"), aValues[0].get<OUString>());
CPPUNIT_ASSERT_EQUAL(OUString("test2"), aValues[1].get<OUString>());
}
void Chart2ImportTest2::testSourceNumberFormatComplexCategoriesXLS()
{
load(u"/chart2/qa/extras/data/xls/", u"source_number_format_axis.xls");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartCompFromSheet(0, mxComponent),
UNO_QUERY_THROW);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
chart2::ScaleData aScaleData = xAxis->getScaleData();
sal_Int32 nNumberFormat = aScaleData.Categories->getValues()->getNumberFormatKeyByIndex(-1);
CPPUNIT_ASSERT(nNumberFormat != 0);
}
void Chart2ImportTest2::testSimpleCategoryAxis()
{
load(u"/chart2/qa/extras/data/docx/", u"testSimpleCategoryAxis.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
// Test the internal data.
CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider());
Reference<chart2::XInternalDataProvider> xInternalProvider(xChartDoc->getDataProvider(),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xInternalProvider.is());
Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, uno::UNO_QUERY);
CPPUNIT_ASSERT(xDescAccess.is());
// Get the category labels.
Sequence<Sequence<OUString>> aCategories = xDescAccess->getComplexRowDescriptions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories[0].getLength());
CPPUNIT_ASSERT(aCategories[0][0].endsWith("ria 1"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories[1].getLength());
CPPUNIT_ASSERT(aCategories[1][0].endsWith("ria 2"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories[2].getLength());
CPPUNIT_ASSERT(aCategories[2][0].endsWith("ria 3"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories[3].getLength());
CPPUNIT_ASSERT(aCategories[3][0].endsWith("ria 4"));
}
void Chart2ImportTest2::testMultilevelCategoryAxis()
{
load(u"/chart2/qa/extras/data/docx/", u"testMultilevelCategoryAxis.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
// Test the internal data.
CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider());
Reference<chart2::XInternalDataProvider> xInternalProvider(xChartDoc->getDataProvider(),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xInternalProvider.is());
Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, uno::UNO_QUERY);
CPPUNIT_ASSERT(xDescAccess.is());
// Get the complex category labels.
Sequence<Sequence<OUString>> aCategories = xDescAccess->getComplexRowDescriptions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories.getLength());
CPPUNIT_ASSERT_EQUAL(OUString("2011"), aCategories[0][0]);
CPPUNIT_ASSERT_EQUAL(OUString(""), aCategories[1][0]);
CPPUNIT_ASSERT_EQUAL(OUString("2012"), aCategories[2][0]);
CPPUNIT_ASSERT_EQUAL(OUString(""), aCategories[3][0]);
CPPUNIT_ASSERT_EQUAL(OUString("Categoria 1"), aCategories[0][1]);
CPPUNIT_ASSERT_EQUAL(OUString("Categoria 2"), aCategories[1][1]);
CPPUNIT_ASSERT_EQUAL(OUString("Categoria 3"), aCategories[2][1]);
CPPUNIT_ASSERT_EQUAL(OUString("Categoria 4"), aCategories[3][1]);
}
void Chart2ImportTest2::testXaxisValues()
{
load(u"/chart2/qa/extras/data/docx/", u"tdf124083.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
const uno::Reference<chart2::data::XDataSequence> xDataSeq
= getDataSequenceFromDocByRole(xChartDoc, u"values-x");
Sequence<uno::Any> xSequence = xDataSeq->getData();
// test X values
CPPUNIT_ASSERT_EQUAL(uno::Any(0.04), xSequence[0]);
CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence[1].getValue())));
CPPUNIT_ASSERT_EQUAL(uno::Any(0.16), xSequence[2]);
CPPUNIT_ASSERT_EQUAL(uno::Any(0.11), xSequence[3]);
CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence[4].getValue())));
}
void Chart2ImportTest2::testTdf123504()
{
load(u"/chart2/qa/extras/data/ods/", u"pie_chart_100_and_0.ods");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<chart2::XChartDocument> xChartDoc2(xChartDoc, UNO_QUERY_THROW);
Reference<chart2::XChartType> xChartType(getChartTypeFromDoc(xChartDoc2, 0), UNO_SET_THROW);
std::vector aDataSeriesYValues = getDataSeriesYValuesFromChartType(xChartType);
CPPUNIT_ASSERT_EQUAL(size_t(1), aDataSeriesYValues.size());
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xSeriesSlices(getShapeByName(xShapes, "CID/D=0:CS=0:CT=0:Series=0"),
UNO_SET_THROW);
Reference<container::XIndexAccess> xIndexAccess(xSeriesSlices, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
Reference<drawing::XShape> xSlice(xIndexAccess->getByIndex(0), UNO_QUERY_THROW);
// Check size and position of the only slice in the chart (100%)
// In the regressed state, it used to be 0-sized at position 0,0
awt::Point aSlicePosition = xSlice->getPosition();
CPPUNIT_ASSERT_GREATER(sal_Int32(3000), aSlicePosition.X);
CPPUNIT_ASSERT_GREATER(sal_Int32(150), aSlicePosition.Y);
awt::Size aSliceSize = xSlice->getSize();
CPPUNIT_ASSERT_GREATER(sal_Int32(8500), aSliceSize.Height);
CPPUNIT_ASSERT_GREATER(sal_Int32(8500), aSliceSize.Width);
}
void Chart2ImportTest2::testTdf122765()
{
// The horizontal position of the slices was wrong.
load(u"/chart2/qa/extras/data/pptx/", u"tdf122765.pptx");
Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 0);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xSeriesSlices(getShapeByName(xShapes, "CID/D=0:CS=0:CT=0:Series=0"),
UNO_SET_THROW);
Reference<container::XIndexAccess> xIndexAccess(xSeriesSlices, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(9), xIndexAccess->getCount());
Reference<drawing::XShape> xSlice(xIndexAccess->getByIndex(0), UNO_QUERY_THROW);
// Check position of the first slice, all slices move together, so enough to check only one.
// Wrong position was around 5856.
awt::Point aSlicePosition = xSlice->getPosition();
CPPUNIT_ASSERT_GREATER(sal_Int32(7000), aSlicePosition.X);
}
void Chart2ImportTest2::testTdf123206CustomLabelField()
{
// File contains the deprecated "custom-label-field" attribute of the
// "data-point" element. It should be interpreted and stored as a data point
// property.
uno::Reference<chart2::XChartDocument> xChartDoc(
getChartDocFromImpress(u"/chart2/qa/extras/data/odp/", "tdf123206.odp"),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT(xDataSeries.is());
Reference<beans::XPropertySet> xDp = xDataSeries->getDataPointByIndex(1);
Sequence<Reference<chart2::XDataPointCustomLabelField>> aLabelFields;
CPPUNIT_ASSERT(xDp->getPropertyValue("CustomLabelFields") >>= aLabelFields);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aLabelFields.getLength());
CPPUNIT_ASSERT_EQUAL(OUString("Kiskacsa"), aLabelFields[0]->getString());
}
void Chart2ImportTest2::testTdf125444PercentageCustomLabel()
{
load(u"/chart2/qa/extras/data/pptx/", u"tdf125444.pptx");
// 1st chart
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
CPPUNIT_ASSERT(xDataSeries.is());
Reference<beans::XPropertySet> xDp = xDataSeries->getDataPointByIndex(1);
Sequence<Reference<chart2::XDataPointCustomLabelField>> aLabelFields;
CPPUNIT_ASSERT(xDp->getPropertyValue("CustomLabelFields") >>= aLabelFields);
// There are three label field: a value label, a newline and a percentage label. We want
// to assert the latter.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aLabelFields.getLength());
CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType_PERCENTAGE,
aLabelFields[2]->getFieldType());
}
void Chart2ImportTest2::testDataPointLabelCustomPos()
{
// test CustomLabelPosition on Bar chart
load(u"/chart2/qa/extras/data/xlsx/", u"testDataPointLabelCustomPos.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT(xChartDoc.is());
uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
CPPUNIT_ASSERT(xDataSeries.is());
uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(0),
uno::UNO_SET_THROW);
CPPUNIT_ASSERT(xPropertySet.is());
chart2::RelativePosition aCustomLabelPosition;
xPropertySet->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition;
CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Primary, -0.14621409921671025, 1e-7);
CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Secondary, -5.2887961029923464E-2, 1e-7);
sal_Int32 aPlacement;
xPropertySet->getPropertyValue("LabelPlacement") >>= aPlacement;
CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::OUTSIDE, aPlacement);
}
void Chart2ImportTest2::testTdf130032()
{
// test CustomLabelPosition on Line chart
load(u"/chart2/qa/extras/data/xlsx/", u"testTdf130032.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT(xChartDoc.is());
uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
CPPUNIT_ASSERT(xDataSeries.is());
uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(1),
uno::UNO_SET_THROW);
CPPUNIT_ASSERT(xPropertySet.is());
chart2::RelativePosition aCustomLabelPosition;
xPropertySet->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition;
CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Primary, -0.0438333333333334, 1e-7);
CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Secondary, 0.086794050743657, 1e-7);
sal_Int32 aPlacement;
xPropertySet->getPropertyValue("LabelPlacement") >>= aPlacement;
CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::RIGHT, aPlacement);
}
void Chart2ImportTest2::testTdf134978()
{
// test CustomLabelPosition on Pie chart
load(u"/chart2/qa/extras/data/xlsx/", u"tdf134978.xlsx");
uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT(xChartDoc.is());
uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
CPPUNIT_ASSERT(xDataSeries.is());
uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(2),
uno::UNO_SET_THROW);
CPPUNIT_ASSERT(xPropertySet.is());
chart2::RelativePosition aCustomLabelPosition;
xPropertySet->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition;
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.040273622047244093, aCustomLabelPosition.Primary, 1e-7);
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.25635352872557599, aCustomLabelPosition.Secondary, 1e-7);
}
void Chart2ImportTest2::testTdf119138MissingAutoTitleDeleted()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf119138-missing-autotitledeleted.xlsx");
Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
CPPUNIT_ASSERT_MESSAGE(
"Missing autoTitleDeleted is implied to be True if title text is present", xTitle.is());
}
void Chart2ImportTest2::testStockChartShiftedCategoryPosition()
{
load(u"/chart2/qa/extras/data/odt/", u"stock_chart_LO_6_2.odt");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Categories.is());
CPPUNIT_ASSERT(aScaleData.ShiftedCategoryPosition);
}
void Chart2ImportTest2::testTdf133376()
{
// FIXME: the DPI check should be removed when either (1) the test is fixed to work with
// non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
if (!IsDefaultDPI())
return;
load(u"/chart2/qa/extras/data/xlsx/", u"tdf133376.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=2"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel.is());
// Check the position of the 3rd data point label, which is out from the pie slice
awt::Point aLabelPosition = xDataPointLabel->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(1082, aLabelPosition.X, 30);
CPPUNIT_ASSERT_DOUBLES_EQUAL(5462, aLabelPosition.Y, 30);
}
void Chart2ImportTest2::testTdf134225()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf134225.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel1(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel1.is());
Reference<drawing::XShape> xDataPointLabel2(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=1"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel2.is());
#if defined(_WIN32)
// font is MS Comic Sans which we can only assume is available under windows
awt::Point aLabelPosition1 = xDataPointLabel1->getPosition();
awt::Point aLabelPosition2 = xDataPointLabel2->getPosition();
// Check the distance between the position of the 1st data point label and the second one
CPPUNIT_ASSERT_DOUBLES_EQUAL(1669, sal_Int32(aLabelPosition2.X - aLabelPosition1.X), 30);
CPPUNIT_ASSERT_DOUBLES_EQUAL(2166, sal_Int32(aLabelPosition2.Y - aLabelPosition1.Y), 30);
#endif
}
void Chart2ImportTest2::testTdf136105()
{
// FIXME: the DPI check should be removed when either (1) the test is fixed to work with
// non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
if (!IsDefaultDPI())
return;
load(u"/chart2/qa/extras/data/xlsx/", u"tdf136105.xlsx");
// 1st chart with fix inner position and size
{
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel.is());
// Check the position of the 1st data point label, which is out from the pie slice
awt::Point aLabelPosition = xDataPointLabel->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(8797, aLabelPosition.X, 500);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1374, aLabelPosition.Y, 500);
}
// 2nd chart with auto inner position and size
{
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(1, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel.is());
// Check the position of the 1st data point label, which is out from the pie slice
awt::Point aLabelPosition = xDataPointLabel->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(7978, aLabelPosition.X, 500);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1048, aLabelPosition.Y, 500);
}
}
void Chart2ImportTest2::testTdf91250()
{
load(u"/chart2/qa/extras/data/docx/", u"tdf91250.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XInternalDataProvider> xInternalProvider(xChartDoc->getDataProvider(),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xInternalProvider.is());
Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, uno::UNO_QUERY);
CPPUNIT_ASSERT(xDescAccess.is());
// Get the category labels.
Sequence<OUString> aCategories = xDescAccess->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories.getLength());
CPPUNIT_ASSERT_EQUAL(OUString("12.3254"), aCategories[0]);
CPPUNIT_ASSERT_EQUAL(OUString("11.62315"), aCategories[1]);
CPPUNIT_ASSERT_EQUAL(OUString("9.26"), aCategories[2]);
CPPUNIT_ASSERT_EQUAL(OUString("8.657"), aCategories[3]);
}
void Chart2ImportTest2::testTdf134111()
{
// tdf134111 : To check TextBreak value is true
load(u"/chart2/qa/extras/data/docx/", u"tdf134111.docx");
uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromWriter(0);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
uno::Reference<chart::XDiagram> mxDiagram(xChartDoc->getDiagram());
CPPUNIT_ASSERT(mxDiagram.is());
uno::Reference<chart::XAxisXSupplier> xAxisXSupp(mxDiagram, uno::UNO_QUERY);
CPPUNIT_ASSERT(xAxisXSupp.is());
uno::Reference<beans::XPropertySet> xAxisProp(xAxisXSupp->getXAxis());
bool bTextBreak = false;
xAxisProp->getPropertyValue("TextBreak") >>= bTextBreak;
// Expected value of 'TextBreak' is true
CPPUNIT_ASSERT(bTextBreak);
}
void Chart2ImportTest2::testTdf136752()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf136752.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel.is());
// Check the position of the 1st data point label, which is out from the pie slice
awt::Point aLabelPosition = xDataPointLabel->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(8675, aLabelPosition.X, 500);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1458, aLabelPosition.Y, 500);
}
void Chart2ImportTest2::testTdf137505()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf137505.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
CPPUNIT_ASSERT(xCustomShape.is());
float nFontSize;
Reference<text::XText> xRange(xCustomShape, uno::UNO_QUERY_THROW);
Reference<text::XTextCursor> xAt = xRange->createTextCursor();
Reference<beans::XPropertySet> xProps(xAt, UNO_QUERY);
// check the text size of custom shape, inside the chart.
CPPUNIT_ASSERT(xProps->getPropertyValue("CharHeight") >>= nFontSize);
CPPUNIT_ASSERT_EQUAL(float(12), nFontSize);
}
void Chart2ImportTest2::testTdf137734()
{
load(u"/chart2/qa/extras/data/xlsx/", u"tdf137734.xlsx");
Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT(xDataSeries.is());
Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY_THROW);
uno::Any aAny = xPropSet->getPropertyValue("VaryColorsByPoint");
bool bVaryColor = true;
CPPUNIT_ASSERT(aAny >>= bVaryColor);
CPPUNIT_ASSERT(!bVaryColor);
// tdf#126133 Test primary X axis Rotation value
Reference<chart2::XAxis> xXAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xXAxis.is());
Reference<chart2::XTitled> xTitled(xXAxis, uno::UNO_QUERY_THROW);
Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
CPPUNIT_ASSERT(xTitle.is());
Reference<beans::XPropertySet> xTitlePropSet(xTitle, uno::UNO_QUERY_THROW);
uno::Any aAny2 = xTitlePropSet->getPropertyValue("TextRotation");
double nRotation = -1;
CPPUNIT_ASSERT(aAny2 >>= nRotation);
CPPUNIT_ASSERT_EQUAL(0.0, nRotation);
}
void Chart2ImportTest2::testTdf137874()
{
load(u"/chart2/qa/extras/data/xlsx/", u"piechart_legend.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xLegendEntry;
xLegendEntry
= getShapeByName(xShapes, "CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=0:LegendEntry=0");
CPPUNIT_ASSERT(xLegendEntry.is());
}
void Chart2ImportTest2::testTdf146463()
{
load(u"/chart2/qa/extras/data/ods/", u"tdf146463.ods");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
uno::Reference<drawing::XShape> xLegend = getShapeByName(xShapes, "CID/D=0:Legend=");
CPPUNIT_ASSERT(xLegend.is());
awt::Size aSize = xLegend->getSize();
// Without the fix in place, this test would have failed with
// - Expected: 598
// - Actual : 7072
CPPUNIT_ASSERT_DOUBLES_EQUAL(598, aSize.Height, 30);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4256, aSize.Width, 30);
awt::Point aPosition = xLegend->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(11534, aPosition.X, 30);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4201, aPosition.Y, 30);
}
void Chart2ImportTest2::testTdfCustomShapePos()
{
load(u"/chart2/qa/extras/data/docx/", u"testcustomshapepos.docx");
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
// test position and size of a custom shape within a chart, rotated by 0 degree.
{
Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
awt::Point aPosition = xCustomShape->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(8845, aPosition.X, 300);
CPPUNIT_ASSERT_DOUBLES_EQUAL(855, aPosition.Y, 300);
awt::Size aSize = xCustomShape->getSize();
CPPUNIT_ASSERT_DOUBLES_EQUAL(4831, aSize.Width, 300);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aSize.Height, 300);
}
// test position and size of a custom shape within a chart, rotated by 90 degree.
{
Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
awt::Point aPosition = xCustomShape->getPosition();
CPPUNIT_ASSERT_DOUBLES_EQUAL(1658, aPosition.X, 300);
CPPUNIT_ASSERT_DOUBLES_EQUAL(6119, aPosition.Y, 300);
awt::Size aSize = xCustomShape->getSize();
CPPUNIT_ASSERT_DOUBLES_EQUAL(4165, aSize.Width, 300);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1334, aSize.Height, 300);
}
}
void Chart2ImportTest2::testTdf121281()
{
load(u"/chart2/qa/extras/data/xlsx/", u"incorrect_label_position.xlsx");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
Reference<drawing::XShape> xDataPointLabel(
getShapeByName(xShapes,
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
UNO_SET_THROW);
CPPUNIT_ASSERT(xDataPointLabel.is());
awt::Point aLabelPosition = xDataPointLabel->getPosition();
// This failed, if the data label flowed out of the chart area.
CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), aLabelPosition.Y);
}
void Chart2ImportTest2::testTdf139658()
{
load(u"/chart2/qa/extras/data/docx/", u"tdf139658.docx");
uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XInternalDataProvider> xInternalProvider(xChartDoc->getDataProvider(),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xInternalProvider.is());
Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, uno::UNO_QUERY);
CPPUNIT_ASSERT(xDescAccess.is());
// Get the category labels.
Sequence<OUString> aCategories = xDescAccess->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aCategories.getLength());
CPPUNIT_ASSERT_EQUAL(OUString("category1"), aCategories[0]);
CPPUNIT_ASSERT_EQUAL(OUString("\"category2\""), aCategories[1]);
CPPUNIT_ASSERT_EQUAL(OUString("category\"3"), aCategories[2]);
}
void Chart2ImportTest2::testTdf146066()
{
load(u"/chart2/qa/extras/data/ods/", u"tdf146066.ods");
Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
UNO_QUERY_THROW);
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xShapes.is());
uno::Reference<drawing::XShape> xYAxisShape = getShapeByName(
xShapes, "CID/D=0:CS=0:Axis=1,0", // Y Axis
// Axis occurs twice in chart xshape representation so need to get the one related to labels
[](const uno::Reference<drawing::XShape>& rXShape) -> bool {
uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY);
CPPUNIT_ASSERT(xAxisShapes.is());
uno::Reference<drawing::XShape> xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY);
uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xChildShape,
uno::UNO_QUERY_THROW);
return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape");
});
CPPUNIT_ASSERT(xYAxisShape.is());
// Check label count
uno::Reference<container::XIndexAccess> xIndexAccess(xYAxisShape, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(8), xIndexAccess->getCount());
// Check text
uno::Reference<text::XTextRange> xLabel0(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("0"), xLabel0->getString());
uno::Reference<text::XTextRange> xLabel1(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("5"), xLabel1->getString());
uno::Reference<text::XTextRange> xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("10"), xLabel2->getString());
uno::Reference<text::XTextRange> xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("15"), xLabel3->getString());
uno::Reference<text::XTextRange> xLabel4(xIndexAccess->getByIndex(4), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("20"), xLabel4->getString());
uno::Reference<text::XTextRange> xLabel5(xIndexAccess->getByIndex(5), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("25"), xLabel5->getString());
uno::Reference<text::XTextRange> xLabel6(xIndexAccess->getByIndex(6), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("30"), xLabel6->getString());
uno::Reference<text::XTextRange> xLabel7(xIndexAccess->getByIndex(7), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("35"), xLabel7->getString());
}
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest2);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|