| 310 | } |
| 311 | |
| 312 | void ProjectImportTest::testOriginTextNumericColumns() { |
| 313 | OriginProjectParser parser; |
| 314 | parser.setProjectFileName(QFINDTESTDATA(QLatin1String("data/origin8_test_workbook.opj"))); |
| 315 | Project project; |
| 316 | |
| 317 | // import "Book1" |
| 318 | QStringList selectedPathes = {QLatin1String("origin8_test_workbook/Folder1/Book1"), |
| 319 | QLatin1String("origin8_test_workbook/Folder1"), |
| 320 | QLatin1String("origin8_test_workbook")}; |
| 321 | parser.importTo(&project, selectedPathes); |
| 322 | |
| 323 | // first child of folder "Folder1", workbook "Book1" with one sheet -> import into a spreadsheet |
| 324 | auto* aspect = project.child<AbstractAspect>(0); |
| 325 | QCOMPARE(aspect != nullptr, true); |
| 326 | if (aspect != nullptr) |
| 327 | QCOMPARE(aspect->name(), QLatin1String("Folder1")); |
| 328 | aspect = project.child<AbstractAspect>(0)->child<AbstractAspect>(0); |
| 329 | QCOMPARE(aspect != nullptr, true); |
| 330 | if (aspect != nullptr) |
| 331 | QCOMPARE(aspect->name(), QLatin1String("Book1")); |
| 332 | auto* spreadsheet = dynamic_cast<Spreadsheet*>(aspect); |
| 333 | QCOMPARE(spreadsheet != nullptr, true); |
| 334 | |
| 335 | // additional pointer check for static code analysis tools like Coverity that are not aware of QCOMPARE above |
| 336 | if (!spreadsheet) |
| 337 | return; |
| 338 | |
| 339 | // check the values in the imported columns |
| 340 | QCOMPARE(spreadsheet->columnCount(), 6); |
| 341 | |
| 342 | // 1st column, Origin::TextNumeric: |
| 343 | // first non-empty value is numerical, column is set to Numeric, empty or text values in the column a set to NAN |
| 344 | Column* column = spreadsheet->column(0); |
| 345 | QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); |
| 346 | QCOMPARE(!std::isnan(column->valueAt(0)), false); |
| 347 | QCOMPARE(column->valueAt(1), 1.1); |
| 348 | QCOMPARE(column->valueAt(2), 2.2); |
| 349 | QCOMPARE(!std::isnan(column->valueAt(3)), false); |
| 350 | QCOMPARE(!std::isnan(column->valueAt(4)), false); |
| 351 | |
| 352 | // 2nd column, Origin::TextNumeric: |
| 353 | // first non-empty value is string, the column is set to Text, numerical values are converted to strings |
| 354 | column = spreadsheet->column(1); |
| 355 | QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Text); |
| 356 | QCOMPARE(column->textAt(0).isEmpty(), true); |
| 357 | QCOMPARE(column->textAt(1), QLatin1String("a")); |
| 358 | QCOMPARE(column->textAt(2), QLatin1String("b")); |
| 359 | QCOMPARE(column->textAt(3), QLatin1String("1.1")); |
| 360 | QCOMPARE(column->textAt(4), QLatin1String("2.2")); |
| 361 | |
| 362 | // 3rd column, Origin::TextNumeric: |
| 363 | // first is numerical, column is set to Numeric, empty or text values in the column a set to NAN |
| 364 | column = spreadsheet->column(2); |
| 365 | QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); |
| 366 | QCOMPARE(column->valueAt(0), 1.1); |
| 367 | QCOMPARE(column->valueAt(1), 2.2); |
| 368 | QCOMPARE(!std::isnan(column->valueAt(2)), false); |
| 369 | QCOMPARE(!std::isnan(column->valueAt(3)), false); |
nothing calls this directly
no test coverage detected