! * read from the beginning of the new data, read 1 sample, keep 2 samples only */
| 248 | * read from the beginning of the new data, read 1 sample, keep 2 samples only |
| 249 | */ |
| 250 | void LiveDataTest::testReadContinuousFixed02() { |
| 251 | // create a temp file and write some data into it |
| 252 | QTemporaryFile tempFile; |
| 253 | if (!tempFile.open()) |
| 254 | QFAIL("failed to create the temp file for writing"); |
| 255 | |
| 256 | QFile file(tempFile.fileName()); |
| 257 | if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) |
| 258 | QFAIL("failed to open the temp file for writing"); |
| 259 | |
| 260 | file.write("1,2\n3,4\n"); |
| 261 | file.flush(); |
| 262 | |
| 263 | // initialize the live data source |
| 264 | LiveDataSource dataSource(QStringLiteral("test"), false); |
| 265 | dataSource.setSourceType(LiveDataSource::SourceType::FileOrPipe); |
| 266 | dataSource.setFileType(AbstractFileFilter::FileType::Ascii); |
| 267 | dataSource.setFileName(file.fileName()); |
| 268 | dataSource.setReadingType(LiveDataSource::ReadingType::ContinuousFixed); |
| 269 | dataSource.setSampleSize(1); |
| 270 | dataSource.setKeepNValues(2); |
| 271 | dataSource.setUpdateType(LiveDataSource::UpdateType::NewData); |
| 272 | |
| 273 | // initialize the ASCII filter |
| 274 | auto* filter = new AsciiFilter(); |
| 275 | auto properties = filter->defaultProperties(); |
| 276 | properties.headerEnabled = false; |
| 277 | properties.intAsDouble = false; |
| 278 | properties.columnNamesRaw = QStringLiteral("x, y"); |
| 279 | properties.columnModesString = QStringLiteral("Int, Int"); |
| 280 | properties.automaticSeparatorDetection = false; |
| 281 | properties.separator = QStringLiteral(","); |
| 282 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); |
| 283 | dataSource.setFilter(filter); |
| 284 | |
| 285 | // read the data and perform checks, after the initial read all data is read |
| 286 | dataSource.read(); |
| 287 | |
| 288 | QCOMPARE(dataSource.columnCount(), 2); |
| 289 | QCOMPARE(dataSource.rowCount(), 1); |
| 290 | |
| 291 | QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 292 | QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 293 | |
| 294 | QCOMPARE(dataSource.column(0)->integerAt(0), 1); |
| 295 | QCOMPARE(dataSource.column(1)->integerAt(0), 2); |
| 296 | |
| 297 | dataSource.read(); |
| 298 | |
| 299 | QCOMPARE(dataSource.columnCount(), 2); |
| 300 | QCOMPARE(dataSource.rowCount(), 2); |
| 301 | |
| 302 | QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 303 | QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer); |
| 304 | |
| 305 | QCOMPARE(dataSource.column(0)->integerAt(0), 1); |
| 306 | QCOMPARE(dataSource.column(1)->integerAt(0), 2); |
| 307 |
nothing calls this directly
no test coverage detected