| 1276 | } |
| 1277 | |
| 1278 | void LiveDataTest::testPlotting() { |
| 1279 | Project project; |
| 1280 | auto* worksheet = new Worksheet(QStringLiteral("worksheet")); |
| 1281 | project.addChild(worksheet); |
| 1282 | |
| 1283 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 1284 | worksheet->addChild(plot); |
| 1285 | |
| 1286 | auto* curve = new XYCurve(QStringLiteral("curve")); |
| 1287 | plot->addChild(curve); |
| 1288 | |
| 1289 | auto* dataSource = new LiveDataSource(QStringLiteral("test"), false); |
| 1290 | dataSource->setColumnCount(2); |
| 1291 | dataSource->setRowCount(11); |
| 1292 | project.addChild(dataSource); |
| 1293 | |
| 1294 | auto* c1 = static_cast<Column*>(dataSource->child<Column>(0)); |
| 1295 | QVERIFY(c1 != nullptr); |
| 1296 | QCOMPARE(c1->name(), QLatin1String("1")); |
| 1297 | QVERIFY(c1->columnMode() == AbstractColumn::ColumnMode::Double); |
| 1298 | auto* c2 = static_cast<Column*>(dataSource->child<Column>(1)); |
| 1299 | QVERIFY(c2 != nullptr); |
| 1300 | QCOMPARE(c2->name(), QLatin1String("2")); |
| 1301 | QVERIFY(c2->columnMode() == AbstractColumn::ColumnMode::Double); |
| 1302 | for (int i = 0; i < dataSource->rowCount(); i++) { |
| 1303 | c1->setValueAt(i, i); |
| 1304 | c2->setValueAt(i, i); |
| 1305 | } |
| 1306 | curve->setXColumn(c1); |
| 1307 | curve->setYColumn(c2); |
| 1308 | |
| 1309 | CHECK_RANGE(plot, curve, Dimension::X, 0., 10.); |
| 1310 | CHECK_RANGE(plot, curve, Dimension::Y, 0., 10.); |
| 1311 | |
| 1312 | QStringList fileContent = { |
| 1313 | QStringLiteral("100,200"), |
| 1314 | QStringLiteral("200,300"), |
| 1315 | QStringLiteral("300,400"), |
| 1316 | }; |
| 1317 | QString savePath; |
| 1318 | SAVE_FILE("testfile", fileContent); |
| 1319 | |
| 1320 | // initialize the live data source |
| 1321 | dataSource->setSourceType(LiveDataSource::SourceType::FileOrPipe); |
| 1322 | dataSource->setFileType(AbstractFileFilter::FileType::Ascii); |
| 1323 | dataSource->setFileName(savePath); |
| 1324 | dataSource->setReadingType(LiveDataSource::ReadingType::WholeFile); |
| 1325 | dataSource->setUpdateType(LiveDataSource::UpdateType::NewData); |
| 1326 | |
| 1327 | // initialize the ASCII filter |
| 1328 | auto* filter = new AsciiFilter(); |
| 1329 | auto properties = filter->defaultProperties(); |
| 1330 | properties.headerEnabled = false; |
| 1331 | properties.columnNamesRaw = QStringLiteral("1, 2"); |
| 1332 | properties.columnModesString = QStringLiteral("Double, Double"); |
| 1333 | properties.automaticSeparatorDetection = false; |
| 1334 | properties.separator = QStringLiteral(","); |
| 1335 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); |
nothing calls this directly
no test coverage detected