| 1601 | } |
| 1602 | |
| 1603 | void LiveDataTest::testLoadSaveLiveDataLinkedFile_FileNotExists() { |
| 1604 | QString savePath; |
| 1605 | QString importFilename; |
| 1606 | { |
| 1607 | // create a temp file and write some data into it |
| 1608 | QTemporaryFile tempFile; |
| 1609 | if (!tempFile.open()) |
| 1610 | QFAIL("failed to create the temp file for writing"); |
| 1611 | |
| 1612 | importFilename = tempFile.fileName(); |
| 1613 | QFile file(importFilename); |
| 1614 | if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) |
| 1615 | QFAIL("failed to open the temp file for writing"); |
| 1616 | |
| 1617 | file.write("1,2\n3,4\n"); |
| 1618 | file.flush(); |
| 1619 | |
| 1620 | Project project; |
| 1621 | CREATE_DUMMY_LIVEDATA_PROJECT(project, importFilename); |
| 1622 | dataSource->setFileLinked(true); // Not linked, the column data is stored in the file |
| 1623 | |
| 1624 | SAVE_PROJECT("testLoadSaveLiveDataSource"); |
| 1625 | } |
| 1626 | |
| 1627 | Project project; |
| 1628 | project.load(savePath); |
| 1629 | const auto curves = project.children<XYCurve>(AbstractAspect::ChildIndexFlag::Recursive); |
| 1630 | QCOMPARE(curves.count(), 1); |
| 1631 | const auto* curve = curves.first(); |
| 1632 | |
| 1633 | const auto children = project.children<LiveDataSource>(); |
| 1634 | QCOMPARE(children.count(), 1); |
| 1635 | const auto* dataSource = children.first(); |
| 1636 | |
| 1637 | QCOMPARE(dataSource->columnCount(), 0); |
| 1638 | QCOMPARE(dataSource->rowCount(), 0); |
| 1639 | QCOMPARE(curve->xColumn(), nullptr); |
| 1640 | QCOMPARE(curve->yColumn(), nullptr); |
| 1641 | |
| 1642 | // Create file again |
| 1643 | QFile file(importFilename); |
| 1644 | if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) |
| 1645 | QFAIL("failed to open the temp file for writing"); |
| 1646 | |
| 1647 | file.write("1,2\n3,4\n"); |
| 1648 | file.flush(); |
| 1649 | file.close(); |
| 1650 | |
| 1651 | waitForSignal(dataSource, &LiveDataSource::readOnUpdateCalled); |
| 1652 | |
| 1653 | QCOMPARE(dataSource->columnCount(), 2); |
| 1654 | QCOMPARE(dataSource->rowCount(), 2); |
| 1655 | |
| 1656 | QVERIFY(dataSource->column(0)); |
| 1657 | QVERIFY(dataSource->column(1)); |
| 1658 | QCOMPARE(curve->xColumn(), dataSource->column(0)); |
| 1659 | QCOMPARE(curve->yColumn(), dataSource->column(1)); |
| 1660 | } |
nothing calls this directly
no test coverage detected