MCPcopy Create free account
hub / github.com/KDE/labplot / testReadFromEnd00

Method testReadFromEnd00

tests/livedata/LiveDataTest.cpp:620–696  ·  view source on GitHub ↗

############################################################################## From End - read fixed number of samples from the end of the new data ################# reading the whole file on changes ######################### ############################################################################## ! * read from the end of the new data, read all data, keep all data */

Source from the content-addressed store, hash-verified

618 * read from the end of the new data, read all data, keep all data
619 */
620void LiveDataTest::testReadFromEnd00() {
621 // create a temp file and write some data into it
622 QTemporaryFile tempFile;
623 if (!tempFile.open())
624 QFAIL("failed to create the temp file for writing");
625
626 QFile file(tempFile.fileName());
627 if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text))
628 QFAIL("failed to open the temp file for writing");
629
630 file.write("1,2\n3,4\n");
631 file.flush();
632
633 // initialize the live data source
634 LiveDataSource dataSource(QStringLiteral("test"), false);
635 dataSource.setSourceType(LiveDataSource::SourceType::FileOrPipe);
636 dataSource.setFileType(AbstractFileFilter::FileType::Ascii);
637 dataSource.setFileName(file.fileName());
638 dataSource.setReadingType(LiveDataSource::ReadingType::FromEnd);
639 dataSource.setUpdateType(LiveDataSource::UpdateType::NewData);
640 dataSource.setSampleSize(100); // big number of samples, more then the new data has, meaning we read all new data
641
642 // initialize the ASCII filter
643 auto* filter = new AsciiFilter();
644 auto properties = filter->defaultProperties();
645 properties.headerEnabled = false;
646 properties.intAsDouble = false;
647 properties.columnNamesRaw = QStringLiteral("x, y");
648 properties.columnModesString = QStringLiteral("Int, Int");
649 properties.automaticSeparatorDetection = false;
650 properties.separator = QStringLiteral(",");
651 QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success);
652 dataSource.setFilter(filter);
653
654 // read the data and perform checks, after the initial read all data is read
655 dataSource.read();
656
657 QCOMPARE(dataSource.columnCount(), 2);
658 QCOMPARE(dataSource.rowCount(), 2);
659
660 QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer);
661 QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer);
662
663 QCOMPARE(dataSource.column(0)->integerAt(0), 1);
664 QCOMPARE(dataSource.column(1)->integerAt(0), 2);
665
666 QCOMPARE(dataSource.column(0)->integerAt(1), 3);
667 QCOMPARE(dataSource.column(1)->integerAt(1), 4);
668
669// currently fails on Windows (waitForSignal()?)
670#ifdef HAVE_WINDOWS
671 return;
672#endif
673 // write out more data to the file
674 file.write("5,6\n7,8\n");
675 file.close();
676 waitForSignal(&dataSource, &LiveDataSource::readOnUpdateCalled);
677

Callers

nothing calls this directly

Calls 15

setSourceTypeMethod · 0.80
setFileTypeMethod · 0.80
defaultPropertiesMethod · 0.80
openMethod · 0.45
fileNameMethod · 0.45
writeMethod · 0.45
setFileNameMethod · 0.45
setReadingTypeMethod · 0.45
setUpdateTypeMethod · 0.45
setSampleSizeMethod · 0.45
initializeMethod · 0.45
setFilterMethod · 0.45

Tested by

no test coverage detected