1 /***************************************************************************
2 * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3 * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 ***************************************************************************/
6 /** @file
7 * This file is a test for SKGTableWithGraph component.
8 *
9 * @author Stephane MANKOWSKI / Guillaume DE BURE
10 */
11 #include "skgtesttablewithgraph.h"
12 #include "skgtablewithgraph.h"
13 #include "skgtestmacro.h"
14
Test()15 void SKGTESTTableWithGraph::Test()
16 {
17 SKGTableWithGraph graph(nullptr);
18
19 SKGStringListList data;
20
21 data.append(QStringList() << QStringLiteral("Category") << QStringLiteral("2013-01") << QStringLiteral("2013-02") << QStringLiteral("2013-03") << QStringLiteral("2013-04") << QStringLiteral("2013-05") << QStringLiteral("2013-06"));
22 data.append(QStringList() << QStringLiteral("Auto") << QStringLiteral("-50") << QStringLiteral("-40.5") << QStringLiteral("-40") << QStringLiteral("-60") << QStringLiteral("-70") << QStringLiteral("-100"));
23 data.append(QStringList() << QStringLiteral("Food") << QStringLiteral("-510.0") << QStringLiteral("-520") << QStringLiteral("-530.55") << QLatin1String("") << QStringLiteral("-535") << QStringLiteral("-520"));
24 data.append(QStringList() << QStringLiteral("s1") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
25 data.append(QStringList() << QStringLiteral("s2") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
26 data.append(QStringList() << QStringLiteral("s3") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
27 data.append(QStringList() << QStringLiteral("s4") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
28 data.append(QStringList() << QStringLiteral("s5") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
29 data.append(QStringList() << QStringLiteral("s6") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
30 data.append(QStringList() << QStringLiteral("s7") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
31 data.append(QStringList() << QStringLiteral("s8") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
32 data.append(QStringList() << QStringLiteral("s9") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
33 data.append(QStringList() << QStringLiteral("s10") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
34 data.append(QStringList() << QStringLiteral("s11") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
35 data.append(QStringList() << QStringLiteral("s12") << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3") << QLatin1String("") << QStringLiteral("4") << QStringLiteral("5"));
36
37 SKGServices::SKGUnitInfo info1;
38 info1.Symbol = 'P';
39 info1.Name = 'P';
40 info1.Date = QDate::currentDate();
41 info1.NbDecimal = 2;
42 info1.Value = 1;
43
44 SKGServices::SKGUnitInfo info2;
45 info2.Symbol = 'S';
46 info2.Name = 'S';
47 info2.Date = QDate::currentDate();
48 info2.NbDecimal = 4;
49 info2.Value = 0.5;
50 graph.setData(data, info1, info2);
51
52 graph.setBackgroundColor(Qt::black);
53 QCOMPARE(graph.isGraphVisible(), true);
54 QCOMPARE(graph.isTableVisible(), true);
55 QCOMPARE(graph.isTextReportVisible(), false);
56 QCOMPARE(graph.isGraphTypeSelectorVisible(), true);
57
58 QCOMPARE(graph.switchLegendVisibility(), true);
59
60 QCOMPARE(graph.switchLinearRegressionVisibility(), false);
61 QCOMPARE(graph.switchLinearRegressionVisibility(), true);
62
63 QCOMPARE(graph.switchLimitsVisibility(), false);
64 QCOMPARE(graph.switchLimitsVisibility(), true);
65
66 QCOMPARE(graph.swithOriginVisibility(), false);
67 QCOMPARE(graph.swithOriginVisibility(), true);
68
69 QCOMPARE(graph.getAdditionalDisplayMode(), SKGTableWithGraph::ALL);
70
71 graph.setShadowVisible(true);
72 QCOMPARE(graph.isShadowVisible(), true);
73
74 graph.setShadowVisible(false);
75 QCOMPARE(graph.isShadowVisible(), false);
76
77 graph.setSelectable(true);
78 QCOMPARE(graph.isSelectable(), true);
79
80 graph.setSelectable(false);
81 QCOMPARE(graph.isSelectable(), false);
82
83 for (int i = 0; i < 9; ++i) {
84 graph.setGraphType(static_cast<SKGTableWithGraph::GraphType>(i));
85 QCOMPARE(graph.getGraphType(), static_cast<SKGTableWithGraph::GraphType>(i));
86 QTest::qWait(1000);
87 graph.graph()->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGGraphicsView_" + SKGServices::intToString(i) + ".png");
88 }
89
90 // Graph
91 QTest::qWait(2000);
92
93 graph.resetColors();
94 SKGGraphicsView* g = graph.graph();
95 g->onCopy();
96 g->onSwitchToolBarVisibility();
97 g->onSwitchToolBarVisibility();
98 g->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGGraphicsView.svg");
99 g->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGGraphicsView.pdf");
100 g->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGGraphicsView.jpeg");
101 g->setAntialiasing(false);
102 g->setAntialiasing(true);
103
104 SKGShow* show = graph.getShowWidget();
105 show->setState(QStringLiteral("text"));
106 show->getMode();
107 show->setDisplayTitle(true);
108 QCOMPARE(show->getDisplayTitle(), true);
109 show->setDisplayTitle(false);
110 QCOMPARE(show->getDisplayTitle(), false);
111
112 /*QCOMPARE(graph.isGraphVisible(), true);
113 QCOMPARE(graph.isTableVisible(), true);
114 QCOMPARE(graph.isTextReportVisible(), true);*/
115
116 SKGWebView* t = graph.textReport();
117 QTest::qWait(2000);
118 t->onZoomIn();
119 t->onZoomOriginal();
120 t->onZoomOut();
121 t->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGWebView.odt");
122 t->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGWebView.pdf");
123 t->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGWebView.html");
124 t->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGWebView.htm");
125 t->exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGWebView.png");
126
127 graph.exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGTableWithGraph.csv");
128 graph.exportInFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtesttablewithgraph/SKGTableWithGraph.txt");
129
130 graph.getTable();
131 }
132
133 QTEST_MAIN(SKGTESTTableWithGraph)
134
135