! * read from the end of the new data, read 1 sample, keep 2 samples only */
| 809 | * read from the end of the new data, read 1 sample, keep 2 samples only |
| 810 | */ |
| 811 | void LiveDataTest::testReadFromEnd02() { |
| 812 | // create a temp file and write some data into it |
| 813 | QTemporaryFile tempFile; |
| 814 | if (!tempFile.open()) |
| 815 | QFAIL("failed to create the temp file for writing"); |
| 816 | |
| 817 | QFile file(tempFile.fileName()); |
| 818 | if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) |
| 819 | QFAIL("failed to open the temp file for writing"); |
| 820 | |
| 821 | file.write("1,2\n3,4\n"); |
| 822 | file.flush(); |
| 823 | |
| 824 | // initialize the live data source |
| 825 | LiveDataSource dataSource(QStringLiteral("test"), false); |
| 826 | dataSource.setSourceType(LiveDataSource::SourceType::FileOrPipe); |
| 827 | dataSource.setFileType(AbstractFileFilter::FileType::Ascii); |
| 828 | dataSource.setFileName(file.fileName()); |
| 829 | dataSource.setReadingType(LiveDataSource::ReadingType::FromEnd); |
| 830 | dataSource.setSampleSize(1); |
| 831 | dataSource.setKeepNValues(2); |
| 832 | dataSource.setUpdateType(LiveDataSource::UpdateType::NewData); |
| 833 | |
| 834 | // initialize the ASCII filter |
| 835 | auto* filter = new AsciiFilter(); |
| 836 | auto properties = filter->defaultProperties(); |
| 837 | properties.headerEnabled = false; |
| 838 | properties.intAsDouble = false; |
| 839 | properties.columnNamesRaw = QStringLiteral("x, y"); |
| 840 | properties.columnModesString = QStringLiteral("Int, Int"); |
| 841 | properties.automaticSeparatorDetection = false; |
| 842 | properties.separator = QStringLiteral(","); |
| 843 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); |
| 844 | dataSource.setFilter(filter); |
| 845 | |
| 846 | // read the data and perform checks, after the initial read all data is read |
| 847 | dataSource.read(); |
| 848 | |
| 849 | QCOMPARE(dataSource.columnCount(), 2); |
| 850 | QCOMPARE(dataSource.rowCount(), 1); |
| 851 | |
| 852 | QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 853 | QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 854 | |
| 855 | QCOMPARE(dataSource.column(0)->integerAt(0), 1); |
| 856 | QCOMPARE(dataSource.column(1)->integerAt(0), 2); |
| 857 | |
| 858 | dataSource.read(); |
| 859 | |
| 860 | QCOMPARE(dataSource.columnCount(), 2); |
| 861 | QCOMPARE(dataSource.rowCount(), 2); |
| 862 | |
| 863 | QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 864 | QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 865 | |
| 866 | QCOMPARE(dataSource.column(0)->integerAt(0), 1); |
| 867 | QCOMPARE(dataSource.column(1)->integerAt(0), 2); |
| 868 |
nothing calls this directly
no test coverage detected