File indexing completed on 2024-10-13 06:30:12

0001 /*
0002     File                 : ProjectImportTest.cpp
0003     Project              : LabPlot
0004     Description          : Tests for project imports
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2018-2023 Alexander Semke <alexander.semke@web.de>
0007     SPDX-FileCopyrightText: 2022 Stefan Gerlach <stefan.gerlach@uni.kn>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #include "ProjectImportTest.h"
0013 #ifdef HAVE_LIBORIGIN
0014 #include "backend/datasources/projects/OriginProjectParser.h"
0015 #endif
0016 #include "backend/core/Project.h"
0017 #include "backend/core/Workbook.h"
0018 #include "backend/matrix/Matrix.h"
0019 #include "backend/spreadsheet/Spreadsheet.h"
0020 #include "backend/worksheet/Line.h"
0021 #include "backend/worksheet/Worksheet.h"
0022 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
0023 #include "backend/worksheet/plots/cartesian/CartesianPlotLegend.h"
0024 #include "backend/worksheet/plots/cartesian/Symbol.h"
0025 #include "backend/worksheet/plots/cartesian/XYCurve.h"
0026 // ##############################################################################
0027 // #####################  import of LabPlot projects ############################
0028 // ##############################################################################
0029 
0030 // TODO
0031 
0032 #ifdef HAVE_LIBORIGIN
0033 // ##############################################################################
0034 // ######################  import of Origin projects ############################
0035 // ##############################################################################
0036 //  project tree of the file "origin8_test_tree_import.opj"
0037 /*
0038 test_tree_import\
0039                     \Book3
0040                     \Folder
0041                         \Book2
0042                             \Sheet1
0043                             \Sheet2
0044                         \MBook2
0045                             \MSheet1
0046                             \MSheet2
0047                     \Folder1
0048                         \MBook1
0049                             \Sheet1
0050                         \Book1
0051                             \Sheet1
0052                         \Book4
0053                             \MSheet1
0054                         \Graph2
0055                     \Excel1
0056 */
0057 
0058 void ProjectImportTest::testOrigin01() {
0059     // import the opj file into LabPlot's project object
0060     OriginProjectParser parser;
0061     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_tree_import.opj")));
0062     Project project;
0063     parser.importTo(&project, QStringList());
0064 
0065     // check the project tree for the imported project
0066 
0067     // first child of the root folder, spreadsheet "Book3"
0068     auto* aspect = project.child<AbstractAspect>(0);
0069     QCOMPARE(aspect != nullptr, true);
0070     if (aspect != nullptr)
0071         QCOMPARE(aspect->name(), QLatin1String("Book3"));
0072     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0073 
0074     // first child of the root folder, folder "Folder" -> import into a Folder
0075     aspect = project.child<AbstractAspect>(1);
0076     QCOMPARE(aspect != nullptr, true);
0077     if (aspect != nullptr)
0078         QCOMPARE(aspect->name(), QLatin1String("Folder"));
0079     QCOMPARE(dynamic_cast<Folder*>(aspect) != nullptr, true);
0080 
0081     // first child of "Folder", workbook "Book2" with two sheets -> import into a Workbook with two Spreadsheets
0082     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(0);
0083     QCOMPARE(aspect != nullptr, true);
0084     if (aspect != nullptr)
0085         QCOMPARE(aspect->name(), QLatin1String("Book2"));
0086     QCOMPARE(dynamic_cast<Workbook*>(aspect) != nullptr, true);
0087 
0088     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(0)->child<AbstractAspect>(0);
0089     QCOMPARE(aspect != nullptr, true);
0090     if (aspect != nullptr)
0091         QCOMPARE(aspect->name(), QLatin1String("Sheet1"));
0092     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0093 
0094     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(0)->child<AbstractAspect>(1);
0095     QCOMPARE(aspect != nullptr, true);
0096     if (aspect != nullptr)
0097         QCOMPARE(aspect->name(), QLatin1String("Sheet2"));
0098     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0099 
0100     // second child of "Folder", matrixbook "MBook" with two matrix sheets -> import into a Workbook with two Matrices
0101     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(1);
0102     QCOMPARE(aspect != nullptr, true);
0103     if (aspect != nullptr)
0104         QCOMPARE(aspect->name(), QLatin1String("MBook2"));
0105     QCOMPARE(dynamic_cast<Workbook*>(aspect) != nullptr, true);
0106 
0107     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(1)->child<AbstractAspect>(0);
0108     QCOMPARE(aspect != nullptr, true);
0109     if (aspect != nullptr)
0110         QCOMPARE(aspect->name(), QLatin1String("MSheet1"));
0111     QCOMPARE(dynamic_cast<Matrix*>(aspect) != nullptr, true);
0112 
0113     aspect = project.child<AbstractAspect>(1)->child<AbstractAspect>(1)->child<AbstractAspect>(1);
0114     QCOMPARE(aspect != nullptr, true);
0115     if (aspect != nullptr)
0116         QCOMPARE(aspect->name(), QLatin1String("MSheet2"));
0117     QCOMPARE(dynamic_cast<Matrix*>(aspect) != nullptr, true);
0118 
0119     // second child of the root folder, folder "Folder1" -> import into a Folder
0120     aspect = project.child<AbstractAspect>(2);
0121     QCOMPARE(aspect != nullptr, true);
0122     if (aspect != nullptr)
0123         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0124     QCOMPARE(dynamic_cast<Folder*>(aspect) != nullptr, true);
0125 
0126     // first child of "Folder1", matrix "MBook1"
0127     aspect = project.child<AbstractAspect>(2)->child<AbstractAspect>(0);
0128     QCOMPARE(aspect != nullptr, true);
0129     if (aspect != nullptr)
0130         QCOMPARE(aspect->name(), QLatin1String("MBook1"));
0131     QCOMPARE(dynamic_cast<Matrix*>(aspect) != nullptr, true);
0132 
0133     // second child of "Folder1", workbook "Book1" with on sheet -> import into a Spreadsheet
0134     aspect = project.child<AbstractAspect>(2)->child<AbstractAspect>(1);
0135     QCOMPARE(aspect != nullptr, true);
0136     if (aspect != nullptr)
0137         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0138     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0139 
0140     // second child of "Folder1", workbook "Book4" with on sheet -> import into a Spreadsheet
0141     aspect = project.child<AbstractAspect>(2)->child<AbstractAspect>(2);
0142     QCOMPARE(aspect != nullptr, true);
0143     if (aspect != nullptr)
0144         QCOMPARE(aspect->name(), QLatin1String("Book4"));
0145     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0146 
0147     // third child of "Folder1", graph "Graph"-> import into a Worksheet
0148     aspect = project.child<AbstractAspect>(2)->child<AbstractAspect>(3);
0149     QCOMPARE(aspect != nullptr, true);
0150     if (aspect != nullptr)
0151         QCOMPARE(aspect->name(), QLatin1String("Graph2"));
0152     QCOMPARE(dynamic_cast<Worksheet*>(aspect) != nullptr, true);
0153     // TODO: check the created plot in the worksheet
0154 
0155     // TODO: loose window: spreadsheet "Excel1"
0156     // aspect = project.child<AbstractAspect>(3);
0157     // QCOMPARE(aspect != nullptr, true);
0158     // QCOMPARE(aspect->name(), QLatin1String("Excel1"));
0159     // QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0160 }
0161 
0162 /*
0163  * import one single folder child
0164  */
0165 void ProjectImportTest::testOrigin02() {
0166     // import one single object
0167     OriginProjectParser parser;
0168     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_tree_import.opj")));
0169     Project project;
0170     QStringList selectedPathes = {QLatin1String("test_tree_import/Folder1/Book1"),
0171                                   QLatin1String("test_tree_import/Folder1"),
0172                                   QLatin1String("test_tree_import")};
0173     parser.importTo(&project, selectedPathes);
0174 
0175     // check the project tree for the imported project
0176 
0177     // first child of the root folder, folder "Folder1" -> import into a Folder
0178     auto* aspect = project.child<AbstractAspect>(0);
0179     QCOMPARE(aspect != nullptr, true);
0180     if (aspect != nullptr)
0181         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0182     QCOMPARE(dynamic_cast<Folder*>(aspect) != nullptr, true);
0183     if (aspect != nullptr)
0184         QCOMPARE(aspect->childCount<AbstractAspect>(), 1);
0185 
0186     // first child of "Folder", workbook "Book" with one sheet -> import into a Spreadsheet
0187     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0188     QCOMPARE(aspect != nullptr, true);
0189     if (aspect != nullptr)
0190         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0191     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0192 }
0193 
0194 /*
0195  * 1. import one single folder child
0196  * 2. import another folder child
0197  * 3. check that both children are available after the second import
0198  */
0199 void ProjectImportTest::testOrigin03() {
0200     // import one single object
0201     OriginProjectParser parser;
0202     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_tree_import.opj")));
0203     Project project;
0204 
0205     // import one single child in "Folder1"
0206     QStringList selectedPathes = {QLatin1String("test_tree_import/Folder1/Book1"),
0207                                   QLatin1String("test_tree_import/Folder1"),
0208                                   QLatin1String("test_tree_import")};
0209     parser.importTo(&project, selectedPathes);
0210 
0211     // first child of the root folder, folder "Folder1" -> import into a Folder
0212     auto* aspect = project.child<AbstractAspect>(0);
0213     QCOMPARE(aspect != nullptr, true);
0214     if (aspect != nullptr)
0215         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0216     QCOMPARE(dynamic_cast<Folder*>(aspect) != nullptr, true);
0217     if (aspect != nullptr)
0218         QCOMPARE(aspect->childCount<AbstractAspect>(), 1);
0219 
0220     // first child of "Folder", workbook "Book1" with one sheet -> import into a Spreadsheet
0221     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0222     QCOMPARE(aspect != nullptr, true);
0223     if (aspect != nullptr)
0224         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0225     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0226 
0227     // import another child in "Folder1"
0228     selectedPathes.clear();
0229     selectedPathes << QLatin1String("test_tree_import/Folder1/Book4") << QLatin1String("test_tree_import/Folder1") << QLatin1String("test_tree_import");
0230     parser.importTo(&project, selectedPathes);
0231 
0232     // the first child should still be available in the project -> check it
0233     aspect = project.child<AbstractAspect>(0);
0234     QCOMPARE(aspect != nullptr, true);
0235     if (aspect != nullptr)
0236         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0237     QCOMPARE(dynamic_cast<Folder*>(aspect) != nullptr, true);
0238 
0239     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0240     QCOMPARE(aspect != nullptr, true);
0241     if (aspect != nullptr)
0242         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0243     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0244 
0245     // check the second child, workbook "Book4" with one sheet -> import into a Spreadsheet
0246     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(1);
0247     QCOMPARE(aspect != nullptr, true);
0248     if (aspect != nullptr)
0249         QCOMPARE(aspect->name(), QLatin1String("Book4"));
0250     QCOMPARE(dynamic_cast<Spreadsheet*>(aspect) != nullptr, true);
0251 
0252     if (aspect != nullptr)
0253         QCOMPARE(aspect->childCount<AbstractAspect>(), 2);
0254 }
0255 
0256 /*
0257  * 1. import a spreadsheet
0258  * 2. modify a cell in it
0259  * 3. import the same spreadsheet once more
0260  * 4. check that the changes were really over-written
0261  */
0262 void ProjectImportTest::testOrigin04() {
0263     OriginProjectParser parser;
0264     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_tree_import.opj")));
0265     Project project;
0266 
0267     // import "Book1"
0268     QStringList selectedPathes = {QLatin1String("test_tree_import/Folder1/Book1"),
0269                                   QLatin1String("test_tree_import/Folder1"),
0270                                   QLatin1String("test_tree_import")};
0271     parser.importTo(&project, selectedPathes);
0272 
0273     // first child of folder "Folder1", workbook "Book1" with one sheet -> import into a spreadsheet
0274     auto* aspect = project.child<AbstractAspect>(0);
0275     QCOMPARE(aspect != nullptr, true);
0276     if (aspect != nullptr)
0277         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0278     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0279     QCOMPARE(aspect != nullptr, true);
0280     if (aspect != nullptr)
0281         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0282     auto* spreadsheet = dynamic_cast<Spreadsheet*>(aspect);
0283     QCOMPARE(spreadsheet != nullptr, true);
0284 
0285     // the (0,0)-cell has the value 1.0
0286     if (spreadsheet != nullptr) {
0287         QCOMPARE(spreadsheet->column(0)->valueAt(0), 1.0);
0288 
0289         // set the value to 5.0
0290         spreadsheet->column(0)->setValueAt(0, 5.0);
0291         QCOMPARE(spreadsheet->column(0)->valueAt(0), 5.0);
0292     }
0293 
0294     // re-import
0295     parser.importTo(&project, selectedPathes);
0296 
0297     // check the folder structure and the value of the (0,0)-cell again
0298     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0299     QCOMPARE(aspect != nullptr, true);
0300     if (aspect != nullptr)
0301         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0302     spreadsheet = dynamic_cast<Spreadsheet*>(aspect);
0303     QCOMPARE(spreadsheet != nullptr, true);
0304     if (spreadsheet != nullptr)
0305         QCOMPARE(spreadsheet->column(0)->valueAt(0), 1.0);
0306 }
0307 
0308 void ProjectImportTest::testOriginTextNumericColumns() {
0309     OriginProjectParser parser;
0310     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_workbook.opj")));
0311     Project project;
0312 
0313     // import "Book1"
0314     QStringList selectedPathes = {QLatin1String("origin8_test_workbook/Folder1/Book1"),
0315                                   QLatin1String("origin8_test_workbook/Folder1"),
0316                                   QLatin1String("origin8_test_workbook")};
0317     parser.importTo(&project, selectedPathes);
0318 
0319     // first child of folder "Folder1", workbook "Book1" with one sheet -> import into a spreadsheet
0320     auto* aspect = project.child<AbstractAspect>(0);
0321     QCOMPARE(aspect != nullptr, true);
0322     if (aspect != nullptr)
0323         QCOMPARE(aspect->name(), QLatin1String("Folder1"));
0324     aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0);
0325     QCOMPARE(aspect != nullptr, true);
0326     if (aspect != nullptr)
0327         QCOMPARE(aspect->name(), QLatin1String("Book1"));
0328     auto* spreadsheet = dynamic_cast<Spreadsheet*>(aspect);
0329     QCOMPARE(spreadsheet != nullptr, true);
0330 
0331     // additional pointer check for static code analysis tools like Coverity that are not aware of QCOMPARE above
0332     if (!spreadsheet)
0333         return;
0334 
0335     // check the values in the imported columns
0336     QCOMPARE(spreadsheet->columnCount(), 6);
0337 
0338     // 1st column, Origin::TextNumeric:
0339     // first non-empty value is numerical, column is set to Numeric, empty or text values in the column a set to NAN
0340     Column* column = spreadsheet->column(0);
0341     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double);
0342     QCOMPARE(!std::isnan(column->valueAt(0)), false);
0343     QCOMPARE(column->valueAt(1), 1.1);
0344     QCOMPARE(column->valueAt(2), 2.2);
0345     QCOMPARE(!std::isnan(column->valueAt(3)), false);
0346     QCOMPARE(!std::isnan(column->valueAt(4)), false);
0347 
0348     // 2nd column, Origin::TextNumeric:
0349     // first non-empty value is string, the column is set to Text, numerical values are converted to strings
0350     column = spreadsheet->column(1);
0351     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Text);
0352     QCOMPARE(column->textAt(0).isEmpty(), true);
0353     QCOMPARE(column->textAt(1), QLatin1String("a"));
0354     QCOMPARE(column->textAt(2), QLatin1String("b"));
0355     QCOMPARE(column->textAt(3), QLatin1String("1.1"));
0356     QCOMPARE(column->textAt(4), QLatin1String("2.2"));
0357 
0358     // 3rd column, Origin::TextNumeric:
0359     // first is numerical, column is set to Numeric, empty or text values in the column a set to NAN
0360     column = spreadsheet->column(2);
0361     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double);
0362     QCOMPARE(column->valueAt(0), 1.1);
0363     QCOMPARE(column->valueAt(1), 2.2);
0364     QCOMPARE(!std::isnan(column->valueAt(2)), false);
0365     QCOMPARE(!std::isnan(column->valueAt(3)), false);
0366     QCOMPARE(column->valueAt(4), 3.3);
0367 
0368     // 4th column, Origin::TextNumeric:
0369     // first value is string, the column is set to Text, numerical values are converted to strings
0370     column = spreadsheet->column(3);
0371     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Text);
0372     QCOMPARE(column->textAt(0), QLatin1String("a"));
0373     QCOMPARE(column->textAt(1), QLatin1String("b"));
0374     QCOMPARE(column->textAt(2), QLatin1String("1.1"));
0375     QCOMPARE(column->textAt(3), QLatin1String("2.2"));
0376     QCOMPARE(column->textAt(4), QLatin1String("c"));
0377 
0378     // 5th column, Origin::Numeric
0379     // column is set to Numeric, empty values in the column a set to NAN
0380     column = spreadsheet->column(4);
0381     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double);
0382     QCOMPARE(!std::isnan(column->valueAt(0)), false);
0383     QCOMPARE(column->valueAt(1), 1.1);
0384     QCOMPARE(column->valueAt(2), 2.2);
0385     QCOMPARE(column->valueAt(3), 3.3);
0386     QCOMPARE(!std::isnan(column->valueAt(4)), false);
0387 
0388     // 6th column, Origin::Numeric
0389     // column is set to Numeric, empty values in the column a set to NAN
0390     column = spreadsheet->column(5);
0391     QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double);
0392     QCOMPARE(column->valueAt(0), 1.1);
0393     QCOMPARE(column->valueAt(1), 2.2);
0394     QCOMPARE(column->valueAt(2), 3.3);
0395     QCOMPARE(!std::isnan(column->valueAt(3)), false);
0396     QCOMPARE(!std::isnan(column->valueAt(4)), false);
0397 }
0398 
0399 void ProjectImportTest::testOrigin_2folder_with_graphs() {
0400     OriginProjectParser parser;
0401     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/2folder-with-graphs.opj")));
0402     Project project;
0403     parser.importTo(&project, QStringList());
0404 
0405     // check the project tree for the imported project
0406 
0407     // Folder 1
0408     auto* f1 = dynamic_cast<Folder*>(project.child<AbstractAspect>(0));
0409     QVERIFY(f1 != nullptr);
0410     QCOMPARE(f1->name(), QLatin1String("Folder1"));
0411 
0412     auto* s1 = dynamic_cast<Spreadsheet*>(f1->child<AbstractAspect>(0));
0413     QVERIFY(s1 != nullptr);
0414     QCOMPARE(s1->name(), QLatin1String("Book1"));
0415 
0416     QCOMPARE(s1->columnCount(), 2);
0417     QCOMPARE(s1->rowCount(), 32);
0418 
0419     auto* c1 = dynamic_cast<Column*>(s1->child<AbstractAspect>(0));
0420     QVERIFY(c1 != nullptr);
0421     QCOMPARE(c1->name(), QLatin1String("A"));
0422     auto* c2 = dynamic_cast<Column*>(s1->child<AbstractAspect>(1));
0423     QVERIFY(c2 != nullptr);
0424     QCOMPARE(c2->name(), QLatin1String("B"));
0425 
0426     auto* w1 = dynamic_cast<Worksheet*>(f1->child<AbstractAspect>(1));
0427     QVERIFY(w1 != nullptr);
0428     QCOMPARE(w1->name(), QLatin1String("Graph1"));
0429 
0430     auto* plot = dynamic_cast<CartesianPlot*>(w1->child<CartesianPlot>(0));
0431     QVERIFY(plot != nullptr);
0432 
0433     QCOMPARE(plot->name(), QLatin1String("Plot1"));
0434 
0435     auto* xAxis = dynamic_cast<Axis*>(plot->child<Axis>(0));
0436     QVERIFY(xAxis != nullptr);
0437     QCOMPARE(xAxis->name(), QStringLiteral("x"));
0438     auto* yAxis = dynamic_cast<Axis*>(plot->child<Axis>(1));
0439     QVERIFY(yAxis != nullptr);
0440     QCOMPARE(yAxis->name(), QStringLiteral("y"));
0441 
0442     auto* legend = dynamic_cast<CartesianPlotLegend*>(plot->child<CartesianPlotLegend>(0));
0443     QVERIFY(legend != nullptr);
0444     QCOMPARE(legend->name(), QStringLiteral("legend"));
0445 
0446     auto* curve = dynamic_cast<XYCurve*>(plot->child<XYCurve>(0));
0447     QVERIFY(curve != nullptr);
0448     QCOMPARE(curve->name(), QStringLiteral("Length"));
0449 
0450     CHECK_RANGE(plot, curve, Dimension::X, 0., 9.);
0451     CHECK_RANGE(plot, curve, Dimension::Y, 0., 9.);
0452 
0453     QCOMPARE(curve->xColumnPath(), QLatin1String("2folder-with-graphs/Folder1/Book1/A"));
0454     QCOMPARE(curve->yColumnPath(), QLatin1String("2folder-with-graphs/Folder1/Book1/B"));
0455     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0456     QCOMPARE(curve->legendVisible(), true);
0457     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0458     QCOMPARE(curve->lineSkipGaps(), false);
0459     QCOMPARE(curve->line()->opacity(), 1);
0460     QCOMPARE(curve->dropLine()->dropLineType(), XYCurve::DropLineType::NoDropLine);
0461     QCOMPARE(curve->valuesType(), XYCurve::ValuesType::NoValues);
0462     // TODO: check more curve properties
0463 
0464     auto* symbol = curve->symbol();
0465     QVERIFY(symbol != nullptr);
0466     QCOMPARE(symbol->style(), Symbol::Style::SquareHalf);
0467     QCOMPARE(symbol->size(), 89.8842169409);
0468     // TODO: more symbol props
0469 
0470     // Folder 2
0471     auto* f2 = dynamic_cast<Folder*>(project.child<AbstractAspect>(1));
0472     QVERIFY(f2 != nullptr);
0473     QCOMPARE(f2->name(), QLatin1String("Folder2"));
0474 
0475     auto* s2 = dynamic_cast<Spreadsheet*>(f2->child<AbstractAspect>(0));
0476     QVERIFY(s2 != nullptr);
0477     QCOMPARE(s2->name(), QLatin1String("Book2"));
0478 
0479     QCOMPARE(s1->columnCount(), 2);
0480     QCOMPARE(s1->rowCount(), 32);
0481 
0482     auto* w2 = dynamic_cast<Worksheet*>(f2->child<AbstractAspect>(1));
0483     QVERIFY(w2 != nullptr);
0484     QCOMPARE(w2->name(), QLatin1String("Graph2"));
0485 
0486     plot = dynamic_cast<CartesianPlot*>(w2->child<CartesianPlot>(0));
0487     QVERIFY(plot != nullptr);
0488 
0489     QCOMPARE(plot->name(), QLatin1String("Plot1"));
0490 
0491     xAxis = dynamic_cast<Axis*>(plot->child<Axis>(0));
0492     QVERIFY(xAxis != nullptr);
0493     QCOMPARE(xAxis->name(), QStringLiteral("x"));
0494     yAxis = dynamic_cast<Axis*>(plot->child<Axis>(1));
0495     QVERIFY(yAxis != nullptr);
0496     QCOMPARE(yAxis->name(), QStringLiteral("y"));
0497 
0498     legend = dynamic_cast<CartesianPlotLegend*>(plot->child<CartesianPlotLegend>(0));
0499     QVERIFY(legend != nullptr);
0500     QCOMPARE(legend->name(), QStringLiteral("legend"));
0501 
0502     curve = dynamic_cast<XYCurve*>(plot->child<XYCurve>(0));
0503     QVERIFY(curve != nullptr);
0504     QCOMPARE(curve->name(), QStringLiteral("B"));
0505 
0506     CHECK_RANGE(plot, curve, Dimension::X, .5, 5.5);
0507     CHECK_RANGE(plot, curve, Dimension::Y, .5, 5.5);
0508 
0509     QCOMPARE(curve->xColumnPath(), QLatin1String("2folder-with-graphs/Folder2/Book2/A"));
0510     QCOMPARE(curve->yColumnPath(), QLatin1String("2folder-with-graphs/Folder2/Book2/B"));
0511     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0512     QCOMPARE(curve->legendVisible(), true);
0513     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0514     QCOMPARE(curve->lineSkipGaps(), false);
0515     QCOMPARE(curve->line()->opacity(), 1);
0516     QCOMPARE(curve->dropLine()->dropLineType(), XYCurve::DropLineType::NoDropLine);
0517     QCOMPARE(curve->valuesType(), XYCurve::ValuesType::NoValues);
0518     // TODO: check more curve properties
0519 
0520     symbol = curve->symbol();
0521     QVERIFY(symbol != nullptr);
0522     QCOMPARE(symbol->style(), Symbol::Style::Hexagon);
0523     QCOMPARE(symbol->size(), 89.8842169409);
0524     // TODO: more symbol props
0525 }
0526 
0527 void ProjectImportTest::testOrigin_2graphs() {
0528     OriginProjectParser parser;
0529     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/2graphs.opj")));
0530     Project project;
0531     parser.importTo(&project, QStringList());
0532 
0533     // check the project tree for the imported project
0534     //  Book 2
0535     auto* s2 = dynamic_cast<Spreadsheet*>(project.child<AbstractAspect>(0));
0536     QVERIFY(s2 != nullptr);
0537     QCOMPARE(s2->name(), QLatin1String("Book2"));
0538 
0539     QCOMPARE(s2->columnCount(), 2);
0540     QCOMPARE(s2->rowCount(), 32);
0541 
0542     auto* c1 = dynamic_cast<Column*>(s2->child<AbstractAspect>(0));
0543     QVERIFY(c1 != nullptr);
0544     QCOMPARE(c1->name(), QLatin1String("A"));
0545     auto* c2 = dynamic_cast<Column*>(s2->child<AbstractAspect>(1));
0546     QVERIFY(c2 != nullptr);
0547     QCOMPARE(c2->name(), QLatin1String("B"));
0548 
0549     // Graph 2
0550     auto* w2 = dynamic_cast<Worksheet*>(project.child<AbstractAspect>(1));
0551     QVERIFY(w2 != nullptr);
0552     QCOMPARE(w2->name(), QLatin1String("Graph2"));
0553 
0554     auto* plot = dynamic_cast<CartesianPlot*>(w2->child<CartesianPlot>(0));
0555     QVERIFY(plot != nullptr);
0556 
0557     QCOMPARE(plot->name(), QLatin1String("Plot1"));
0558 
0559     auto* xAxis = dynamic_cast<Axis*>(plot->child<Axis>(0));
0560     QVERIFY(xAxis != nullptr);
0561     QCOMPARE(xAxis->name(), QStringLiteral("x"));
0562     auto* yAxis = dynamic_cast<Axis*>(plot->child<Axis>(1));
0563     QVERIFY(yAxis != nullptr);
0564     QCOMPARE(yAxis->name(), QStringLiteral("y"));
0565 
0566     auto* legend = dynamic_cast<CartesianPlotLegend*>(plot->child<CartesianPlotLegend>(0));
0567     QVERIFY(legend != nullptr);
0568     QCOMPARE(legend->name(), QStringLiteral("legend"));
0569 
0570     auto* curve = dynamic_cast<XYCurve*>(plot->child<XYCurve>(0));
0571     QVERIFY(curve != nullptr);
0572     QCOMPARE(curve->name(), QStringLiteral("B")); // TODO: Origin uses Comments as curve name: "Length"
0573     QCOMPARE(curve->coordinateSystemIndex(), plot->defaultCoordinateSystemIndex());
0574 
0575     CHECK_RANGE(plot, curve, Dimension::X, .5, 5.5);
0576     CHECK_RANGE(plot, curve, Dimension::Y, .5, 5.5);
0577 
0578     QCOMPARE(curve->xColumnPath(), QLatin1String("2graphs/Book2/A"));
0579     QCOMPARE(curve->yColumnPath(), QLatin1String("2graphs/Book2/B"));
0580     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0581     QCOMPARE(curve->legendVisible(), true);
0582     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0583     QCOMPARE(curve->lineSkipGaps(), false);
0584     QCOMPARE(curve->line()->opacity(), 1);
0585     QCOMPARE(curve->dropLine()->dropLineType(), XYCurve::DropLineType::NoDropLine);
0586     QCOMPARE(curve->valuesType(), XYCurve::ValuesType::NoValues);
0587     // TODO: more curve properties
0588 
0589     auto* symbol = curve->symbol();
0590     QVERIFY(symbol != nullptr);
0591     QCOMPARE(symbol->style(), Symbol::Style::Hexagon);
0592     QCOMPARE(symbol->size(), 89.8842169409);
0593     // TODO: more symbol props
0594 
0595     // Graph 1
0596     auto* w1 = dynamic_cast<Worksheet*>(project.child<AbstractAspect>(2));
0597     QVERIFY(w1 != nullptr);
0598     QCOMPARE(w1->name(), QLatin1String("Graph1"));
0599 
0600     plot = dynamic_cast<CartesianPlot*>(w1->child<CartesianPlot>(0));
0601     QVERIFY(plot != nullptr);
0602 
0603     QCOMPARE(plot->name(), QLatin1String("Plot1"));
0604 
0605     xAxis = dynamic_cast<Axis*>(plot->child<Axis>(0));
0606     QVERIFY(xAxis != nullptr);
0607     QCOMPARE(xAxis->name(), QStringLiteral("x"));
0608     yAxis = dynamic_cast<Axis*>(plot->child<Axis>(1));
0609     QVERIFY(yAxis != nullptr);
0610     QCOMPARE(yAxis->name(), QStringLiteral("y"));
0611 
0612     legend = dynamic_cast<CartesianPlotLegend*>(plot->child<CartesianPlotLegend>(0));
0613     QVERIFY(legend != nullptr);
0614     QCOMPARE(legend->name(), QStringLiteral("legend"));
0615 
0616     curve = dynamic_cast<XYCurve*>(plot->child<XYCurve>(0));
0617     QVERIFY(curve != nullptr);
0618     QCOMPARE(curve->name(), QStringLiteral("Length"));
0619     QCOMPARE(curve->coordinateSystemIndex(), plot->defaultCoordinateSystemIndex());
0620 
0621     CHECK_RANGE(plot, curve, Dimension::X, 0., 9.);
0622     CHECK_RANGE(plot, curve, Dimension::Y, 0., 9.);
0623 
0624     QCOMPARE(curve->xColumnPath(), QLatin1String("2graphs/Book1/A"));
0625     QCOMPARE(curve->yColumnPath(), QLatin1String("2graphs/Book1/B"));
0626     QCOMPARE(curve->legendVisible(), true);
0627     QCOMPARE(curve->lineType(), XYCurve::LineType::Line);
0628     QCOMPARE(curve->lineSkipGaps(), false);
0629     QCOMPARE(curve->line()->opacity(), 1);
0630     QCOMPARE(curve->dropLine()->dropLineType(), XYCurve::DropLineType::NoDropLine);
0631     QCOMPARE(curve->valuesType(), XYCurve::ValuesType::NoValues);
0632     // TODO: more curve properties
0633 
0634     symbol = curve->symbol();
0635     QVERIFY(symbol != nullptr);
0636     QCOMPARE(symbol->style(), Symbol::Style::SquareHalf);
0637     QCOMPARE(symbol->size(), 89.8842169409);
0638     // TODO: more symbol props
0639 
0640     // Book 1
0641     auto* s1 = dynamic_cast<Spreadsheet*>(project.child<AbstractAspect>(3));
0642     QVERIFY(s1 != nullptr);
0643     QCOMPARE(s1->name(), QLatin1String("Book1"));
0644 
0645     QCOMPARE(s2->columnCount(), 2);
0646     QCOMPARE(s2->rowCount(), 32);
0647 
0648     c1 = dynamic_cast<Column*>(s1->child<AbstractAspect>(0));
0649     QVERIFY(c1 != nullptr);
0650     QCOMPARE(c1->name(), QLatin1String("A"));
0651     c2 = dynamic_cast<Column*>(s1->child<AbstractAspect>(1));
0652     QVERIFY(c2 != nullptr);
0653     QCOMPARE(c2->name(), QLatin1String("B"));
0654 }
0655 
0656 /*!
0657  * read a project file containing one plot area/layer with one single coordinate system with 4 axes and one curve.
0658  */
0659 void ProjectImportTest::testOriginSingleLayerTwoAxes() {
0660     // import the opj file into LabPlot's project object
0661     OriginProjectParser parser;
0662     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/single_layer_two_axes.opj")));
0663     parser.setGraphLayerAsPlotArea(true); // read every layer as a new plot area
0664     Project project;
0665     parser.importTo(&project, QStringList());
0666 
0667     const auto& plots = project.children<CartesianPlot>(AbstractAspect::ChildIndexFlag::Recursive);
0668     QCOMPARE(plots.count(), 1);
0669 
0670     // check the plot area
0671     const auto* plot1 = plots.first();
0672     QVERIFY(plot1 != nullptr);
0673 
0674     // ranges and axes - there should be one single coordinate system and 4 axes on the plot area
0675     QCOMPARE(plot1->rangeCount(Dimension::X), 1);
0676     QCOMPARE(plot1->rangeCount(Dimension::Y), 1);
0677     QCOMPARE(plot1->coordinateSystemCount(), 1);
0678 
0679     const auto& rangeX1 = plot1->range(Dimension::X, 0);
0680     QCOMPARE(rangeX1.start(), 1.5);
0681     QCOMPARE(rangeX1.end(), 8.5);
0682     QCOMPARE(rangeX1.scale(), RangeT::Scale::Linear);
0683     QCOMPARE(rangeX1.format(), RangeT::Format::Numeric);
0684 
0685     const auto& rangeY1 = plot1->range(Dimension::Y, 0);
0686     QCOMPARE(rangeY1.start(), 3.5);
0687     QCOMPARE(rangeY1.end(), 8.5);
0688     QCOMPARE(rangeY1.scale(), RangeT::Scale::Linear);
0689     QCOMPARE(rangeY1.format(), RangeT::Format::Numeric);
0690 
0691     // axes
0692     const auto& axes = plot1->children<Axis>();
0693     QCOMPARE(axes.count(), 4);
0694 
0695     // curve
0696     const auto& curves1 = plot1->children<XYCurve>();
0697     QCOMPARE(curves1.count(), 1);
0698     QCOMPARE(curves1.constFirst()->coordinateSystemIndex(), 0);
0699 }
0700 
0701 /*!
0702  * read a project file containing one plot area/layer with one single coordinate system with 4 axes and one curve.
0703  * the line of the second axes is hidden, only the labels are shown - we still have to create for axes objects after the import.
0704  */
0705 void ProjectImportTest::testOriginSingleLayerTwoAxesWithoutLines() {
0706     // import the opj file into LabPlot's project object
0707     OriginProjectParser parser;
0708     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/single_layer_two_axes_without_lines.opj")));
0709     parser.setGraphLayerAsPlotArea(true); // read every layer as a new plot area
0710     Project project;
0711     parser.importTo(&project, QStringList());
0712 
0713     const auto& plots = project.children<CartesianPlot>(AbstractAspect::ChildIndexFlag::Recursive);
0714     QCOMPARE(plots.count(), 1);
0715 
0716     // check the plot area
0717     const auto* plot1 = plots.first();
0718     QVERIFY(plot1 != nullptr);
0719 
0720     // ranges and axes - there should be one single coordinate system and 4 axes on the plot area
0721     QCOMPARE(plot1->rangeCount(Dimension::X), 1);
0722     QCOMPARE(plot1->rangeCount(Dimension::Y), 1);
0723     QCOMPARE(plot1->coordinateSystemCount(), 1);
0724 
0725     const auto& rangeX1 = plot1->range(Dimension::X, 0);
0726     QCOMPARE(rangeX1.start(), 1.5);
0727     QCOMPARE(rangeX1.end(), 8.5);
0728     QCOMPARE(rangeX1.scale(), RangeT::Scale::Linear);
0729     QCOMPARE(rangeX1.format(), RangeT::Format::Numeric);
0730 
0731     const auto& rangeY1 = plot1->range(Dimension::Y, 0);
0732     QCOMPARE(rangeY1.start(), 3.5);
0733     QCOMPARE(rangeY1.end(), 8.5);
0734     QCOMPARE(rangeY1.scale(), RangeT::Scale::Linear);
0735     QCOMPARE(rangeY1.format(), RangeT::Format::Numeric);
0736 
0737     // axes
0738     const auto& axes = plot1->children<Axis>();
0739     QCOMPARE(axes.count(), 4);
0740 
0741     // curve
0742     const auto& curves1 = plot1->children<XYCurve>();
0743     QCOMPARE(curves1.count(), 1);
0744     QCOMPARE(curves1.constFirst()->coordinateSystemIndex(), 0);
0745 }
0746 
0747 /*!
0748  * read a project file containing two plot areas with one single coordinate system and one curve in each the plot area.
0749  */
0750 void ProjectImportTest::testOriginMultiLayersAsPlotAreas() {
0751     // import the opj file into LabPlot's project object
0752     OriginProjectParser parser;
0753     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/two_layers_as_two_plot_areas.opj")));
0754     parser.setGraphLayerAsPlotArea(true); // read every layer as a new plot area
0755     Project project;
0756     parser.importTo(&project, QStringList());
0757 
0758     const auto& plots = project.children<CartesianPlot>(AbstractAspect::ChildIndexFlag::Recursive);
0759     QCOMPARE(plots.count(), 2);
0760 
0761     // check the first plot area
0762     const auto* plot1 = plots.first();
0763     QVERIFY(plot1 != nullptr);
0764 
0765     // ranges
0766     QCOMPARE(plot1->rangeCount(Dimension::X), 1);
0767     QCOMPARE(plot1->rangeCount(Dimension::Y), 1);
0768     QCOMPARE(plot1->coordinateSystemCount(), 1);
0769 
0770     const auto& rangeX1 = plot1->range(Dimension::X, 0);
0771     QCOMPARE(rangeX1.start(), 1.5);
0772     QCOMPARE(rangeX1.end(), 8.5);
0773     QCOMPARE(rangeX1.scale(), RangeT::Scale::Linear);
0774     QCOMPARE(rangeX1.format(), RangeT::Format::Numeric);
0775 
0776     const auto& rangeY1 = plot1->range(Dimension::Y, 0);
0777     QCOMPARE(rangeY1.start(), 3.5);
0778     QCOMPARE(rangeY1.end(), 8.5);
0779     QCOMPARE(rangeY1.scale(), RangeT::Scale::Linear);
0780     QCOMPARE(rangeY1.format(), RangeT::Format::Numeric);
0781 
0782     // curve
0783     const auto& curves1 = plot1->children<XYCurve>();
0784     QCOMPARE(curves1.count(), 1);
0785     QCOMPARE(curves1.constFirst()->coordinateSystemIndex(), 0);
0786 
0787     // check the second plot area
0788     const auto* plot2 = plots.at(1);
0789     QVERIFY(plot2 != nullptr);
0790 
0791     // ranges
0792     QCOMPARE(plot2->rangeCount(Dimension::X), 1);
0793     QCOMPARE(plot2->rangeCount(Dimension::Y), 1);
0794     QCOMPARE(plot2->coordinateSystemCount(), 1);
0795 
0796     const auto& rangeX2 = plot2->range(Dimension::X, 0);
0797     QCOMPARE(rangeX2.start(), 1.5);
0798     QCOMPARE(rangeX2.end(), 8.5);
0799     QCOMPARE(rangeX2.scale(), RangeT::Scale::Linear);
0800     QCOMPARE(rangeX2.format(), RangeT::Format::Numeric);
0801 
0802     const auto& rangeY2 = plot2->range(Dimension::Y, 0);
0803     QCOMPARE(rangeY2.start(), 8.);
0804     QCOMPARE(rangeY2.end(), 18.);
0805     QCOMPARE(rangeY2.scale(), RangeT::Scale::Linear);
0806     QCOMPARE(rangeY2.format(), RangeT::Format::Numeric);
0807 
0808     // curve
0809     const auto& curves2 = plot1->children<XYCurve>();
0810     QCOMPARE(curves2.count(), 1);
0811     QCOMPARE(curves2.constFirst()->coordinateSystemIndex(), 0);
0812 }
0813 
0814 /*!
0815  * read a project file containing one plot area with two coordinate systems ("two axes") and one curve per each coordinate system.
0816  */
0817 void ProjectImportTest::testOriginMultiLayersAsCoordinateSystems() {
0818     // import the opj file into LabPlot's project object
0819     OriginProjectParser parser;
0820     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/two_layers_as_two_coordinate_systems.opj")));
0821     parser.setGraphLayerAsPlotArea(false); // read every layer as a new coordinate system
0822     Project project;
0823     parser.importTo(&project, QStringList());
0824 
0825     // check the ranges of the CartesianPlot in the project
0826     const auto& plots = project.children<CartesianPlot>(AbstractAspect::ChildIndexFlag::Recursive);
0827     QCOMPARE(plots.count(), 1);
0828 
0829     const auto* plot = plots.first();
0830     QVERIFY(plot != nullptr);
0831 
0832     // ranges
0833     QCOMPARE(plot->rangeCount(Dimension::X), 1);
0834     QCOMPARE(plot->rangeCount(Dimension::Y), 2);
0835 
0836     const auto& rangeX = plot->range(Dimension::X, 0);
0837     QCOMPARE(rangeX.start(), 1.);
0838     QCOMPARE(rangeX.end(), 12.);
0839     QCOMPARE(rangeX.scale(), RangeT::Scale::Linear);
0840     QCOMPARE(rangeX.format(), RangeT::Format::Numeric);
0841 
0842     const auto& rangeY1 = plot->range(Dimension::Y, 0);
0843     QCOMPARE(rangeY1.start(), 1.75);
0844     QCOMPARE(rangeY1.end(), 5.25);
0845     QCOMPARE(rangeY1.scale(), RangeT::Scale::Linear);
0846     QCOMPARE(rangeY1.format(), RangeT::Format::Numeric);
0847 
0848     const auto& rangeY2 = plot->range(Dimension::Y, 1);
0849     QCOMPARE(rangeY2.start(), 20);
0850     QCOMPARE(rangeY2.end(), 47.5);
0851     QCOMPARE(rangeY2.scale(), RangeT::Scale::Linear);
0852     QCOMPARE(rangeY2.format(), RangeT::Format::Numeric);
0853 
0854     // coordinate systems
0855     QCOMPARE(plot->coordinateSystemCount(), 2);
0856 
0857     // curves, two curves in total, one curve for every layer/coordinate system
0858     const auto& curves = plot->children<XYCurve>();
0859     QCOMPARE(curves.count(), 2);
0860     QCOMPARE(curves.at(0)->coordinateSystemIndex(), 0);
0861     QCOMPARE(curves.at(1)->coordinateSystemIndex(), 1);
0862 }
0863 
0864 /*!
0865  * read a project file containing one plot area with two coordinate systems ("two axes") and one curve per each coordinate system.
0866  * the test project was created with a newer version of Origin and has a legend defined via an annotation that we need to
0867  * properly interpret.
0868  */
0869 void ProjectImportTest::testOriginMultiLayersAsCoordinateSystemsWithLegend() {
0870     // import the opj file into LabPlot's project object
0871     OriginProjectParser parser;
0872     parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/two_layers_as_two_coordinate_systems_with_legend.opj")));
0873     parser.setGraphLayerAsPlotArea(false); // read every layer as a new coordinate system
0874     Project project;
0875     parser.importTo(&project, QStringList());
0876 
0877     // check the ranges of the CartesianPlot in the project
0878     const auto& plots = project.children<CartesianPlot>(AbstractAspect::ChildIndexFlag::Recursive);
0879     QCOMPARE(plots.count(), 1);
0880 
0881     const auto* plot = plots.first();
0882     QVERIFY(plot != nullptr);
0883 
0884     // ranges
0885     QCOMPARE(plot->rangeCount(Dimension::X), 1);
0886     QCOMPARE(plot->rangeCount(Dimension::Y), 2);
0887 
0888     const auto& rangeX = plot->range(Dimension::X, 0);
0889     QCOMPARE(rangeX.start(), 1.);
0890     QCOMPARE(rangeX.end(), 12.);
0891     QCOMPARE(rangeX.scale(), RangeT::Scale::Linear);
0892     QCOMPARE(rangeX.format(), RangeT::Format::Numeric);
0893 
0894     const auto& rangeY1 = plot->range(Dimension::Y, 0);
0895     QCOMPARE(rangeY1.start(), 1.75);
0896     QCOMPARE(rangeY1.end(), 5.25);
0897     QCOMPARE(rangeY1.scale(), RangeT::Scale::Linear);
0898     QCOMPARE(rangeY1.format(), RangeT::Format::Numeric);
0899 
0900     const auto& rangeY2 = plot->range(Dimension::Y, 1);
0901     QCOMPARE(rangeY2.start(), 20);
0902     QCOMPARE(rangeY2.end(), 47.5);
0903     QCOMPARE(rangeY2.scale(), RangeT::Scale::Linear);
0904     QCOMPARE(rangeY2.format(), RangeT::Format::Numeric);
0905 
0906     // coordinate systems
0907     QCOMPARE(plot->coordinateSystemCount(), 2);
0908 
0909     // curves, two curves in total, one curve for every layer/coordinate system
0910     const auto& curves = plot->children<XYCurve>();
0911     QCOMPARE(curves.count(), 2);
0912     QCOMPARE(curves.at(0)->coordinateSystemIndex(), 0);
0913     QCOMPARE(curves.at(1)->coordinateSystemIndex(), 1);
0914 
0915     // legend
0916     const auto& legends = plot->children<CartesianPlotLegend>();
0917     QCOMPARE(legends.count(), 1);
0918 }
0919 
0920 void ProjectImportTest::testParseOriginTags_data() {
0921     QTest::addColumn<QString>("originTag");
0922     QTest::addColumn<QString>("labPlotHTML");
0923 
0924     QTest::newRow("bold") << "\\b(bold)"
0925                           << "<b>bold</b>";
0926 
0927     QTest::newRow("italic") << "\\i(italic)"
0928                             << "<i>italic</i>";
0929 
0930     QTest::newRow("strike through") << "\\s(strike through)"
0931                                     << "<s>strike through</s>";
0932 
0933     QTest::newRow("underlined") << "\\u(underlined)"
0934                                 << "<u>underlined</u>";
0935 
0936     QTest::newRow("greek char") << "\\g(a)"
0937                                 << "&alpha;";
0938 
0939     QTest::newRow("sub-script") << "a\\-(b)"
0940                                 << "a<sub>b</sub>";
0941 
0942     QTest::newRow("super-script") << "a\\+(b)"
0943                                   << "a<sup>b</sup>";
0944 
0945     QTest::newRow("set-font") << "\\f:dejavu sans(text)"
0946                               << "<font face=\"dejavu sans\">text</font>";
0947 
0948     QTest::newRow("font-size") << "some \\p200(big) text"
0949                                << "some <span style=\"font-size: 200%\">big</span> text";
0950 
0951     QTest::newRow("color") << "some \\c15(colored) text"
0952                            << "some <span style=\"color: #8000ff\">colored</span> text";
0953 
0954     QTest::newRow("nested-non-tag-parenthesis") << "\\b(text (c) and (fh) and a(t) and empty ())"
0955                                                 << "<b>text (c) and (fh) and a(t) and empty ()</b>";
0956 
0957     QTest::newRow("nested-tags") << "\\b(bold text with some \\i(italic) bits and some \\c15(color)) "
0958                                     "then a change of \\f:dejavu sans(font)"
0959                                  << "<b>bold text with some <i>italic</i> bits and some "
0960                                     "<span style=\"color: #8000ff\">color</span></b> "
0961                                     "then a change of <font face=\"dejavu sans\">font</font>";
0962 
0963     QTest::newRow("nested-tags-with-extra-spaces") << "\\ b (bold text with some \\ i(italic) bits and some \\c 15 (color)) "
0964                                                       "then a change of \\ f:dejavu sans( font)"
0965                                                    << "<b>bold text with some <i>italic</i> bits and some "
0966                                                       "<span style=\"color: #8000ff\">color</span></b> "
0967                                                       "then a change of <font face=\"dejavu sans\"> font</font>";
0968 }
0969 
0970 void ProjectImportTest::testParseOriginTags() {
0971     QFETCH(QString, originTag);
0972     QFETCH(QString, labPlotHTML);
0973 
0974     OriginProjectParser parser;
0975     QCOMPARE(parser.parseOriginTags(originTag), labPlotHTML);
0976 }
0977 
0978 #endif
0979 
0980 QTEST_MAIN(ProjectImportTest)