! * read till the end of the new data, read all data, keep 2 samples only */
| 987 | * read till the end of the new data, read all data, keep 2 samples only |
| 988 | */ |
| 989 | void LiveDataTest::testReadTillEnd01() { |
| 990 | // create a temp file and write some data into it |
| 991 | QTemporaryFile tempFile; |
| 992 | if (!tempFile.open()) |
| 993 | QFAIL("failed to create the temp file for writing"); |
| 994 | |
| 995 | QFile file(tempFile.fileName()); |
| 996 | if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) |
| 997 | QFAIL("failed to open the temp file for writing"); |
| 998 | |
| 999 | file.write("1,2\n3,4\n"); |
| 1000 | file.flush(); |
| 1001 | |
| 1002 | // initialize the live data source |
| 1003 | LiveDataSource dataSource(QStringLiteral("test"), false); |
| 1004 | dataSource.setSourceType(LiveDataSource::SourceType::FileOrPipe); |
| 1005 | dataSource.setFileType(AbstractFileFilter::FileType::Ascii); |
| 1006 | dataSource.setFileName(file.fileName()); |
| 1007 | dataSource.setReadingType(LiveDataSource::ReadingType::TillEnd); |
| 1008 | dataSource.setKeepNValues(2); |
| 1009 | dataSource.setUpdateType(LiveDataSource::UpdateType::NewData); |
| 1010 | |
| 1011 | // initialize the ASCII filter |
| 1012 | auto* filter = new AsciiFilter(); |
| 1013 | auto properties = filter->defaultProperties(); |
| 1014 | properties.headerEnabled = false; |
| 1015 | properties.intAsDouble = false; |
| 1016 | properties.columnNamesRaw = QStringLiteral("x, y"); |
| 1017 | properties.columnModesString = QStringLiteral("Int, Int"); |
| 1018 | properties.automaticSeparatorDetection = false; |
| 1019 | properties.separator = QStringLiteral(","); |
| 1020 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); |
| 1021 | dataSource.setFilter(filter); |
| 1022 | |
| 1023 | // read the data and perform checks |
| 1024 | dataSource.read(); |
| 1025 | |
| 1026 | QCOMPARE(dataSource.columnCount(), 2); |
| 1027 | QCOMPARE(dataSource.rowCount(), 2); |
| 1028 | |
| 1029 | QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 1030 | QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 1031 | |
| 1032 | QCOMPARE(dataSource.column(0)->integerAt(0), 1); |
| 1033 | QCOMPARE(dataSource.column(1)->integerAt(0), 2); |
| 1034 | |
| 1035 | QCOMPARE(dataSource.column(0)->integerAt(1), 3); |
| 1036 | QCOMPARE(dataSource.column(1)->integerAt(1), 4); |
| 1037 | |
| 1038 | // currently fails on Windows (waitForSignal()?) |
| 1039 | #ifdef HAVE_WINDOWS |
| 1040 | return; |
| 1041 | #endif |
| 1042 | // write out more data to the file |
| 1043 | file.write("5,6\n7,8\n"); |
| 1044 | file.close(); |
| 1045 | waitForSignal(&dataSource, &LiveDataSource::readOnUpdateCalled); |
| 1046 |
nothing calls this directly
no test coverage detected