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

Method testReadWholeFile00

tests/livedata/LiveDataTest.cpp:1068–1134  ·  view source on GitHub ↗

! * comma separated ASCII data, read whole file on changes, without header, append new data */

Source from the content-addressed store, hash-verified

1066 * comma separated ASCII data, read whole file on changes, without header, append new data
1067 */
1068void LiveDataTest::testReadWholeFile00() {
1069 // create a temp file and write some data into it
1070 QTemporaryFile tempFile;
1071 if (!tempFile.open())
1072 QFAIL("failed to create the temp file for writing");
1073
1074 QFile file(tempFile.fileName());
1075 if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text))
1076 QFAIL("failed to open the temp file for writing");
1077
1078 file.write("1,2\n");
1079 file.flush();
1080
1081 // initialize the live data source
1082 LiveDataSource dataSource(QStringLiteral("test"), false);
1083 dataSource.setSourceType(LiveDataSource::SourceType::FileOrPipe);
1084 dataSource.setFileType(AbstractFileFilter::FileType::Ascii);
1085 dataSource.setFileName(file.fileName());
1086 dataSource.setReadingType(LiveDataSource::ReadingType::WholeFile);
1087 dataSource.setUpdateType(LiveDataSource::UpdateType::NewData);
1088
1089 // initialize the ASCII filter
1090 auto* filter = new AsciiFilter();
1091 auto properties = filter->defaultProperties();
1092 properties.headerEnabled = false;
1093 properties.intAsDouble = false;
1094 properties.columnNamesRaw = QStringLiteral("x, y");
1095 properties.columnModesString = QStringLiteral("Int, Int");
1096 properties.automaticSeparatorDetection = false;
1097 properties.separator = QStringLiteral(",");
1098 QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success);
1099 dataSource.setFilter(filter);
1100
1101 // read the data and perform checks
1102 dataSource.read();
1103
1104 QCOMPARE(dataSource.columnCount(), 2);
1105 QCOMPARE(dataSource.rowCount(), 1);
1106
1107 QCOMPARE(dataSource.column(0)->columnMode(), AbstractColumn::ColumnMode::Integer);
1108 QCOMPARE(dataSource.column(1)->columnMode(), AbstractColumn::ColumnMode::Integer);
1109
1110 QCOMPARE(dataSource.column(0)->integerAt(0), 1);
1111 QCOMPARE(dataSource.column(1)->integerAt(0), 2);
1112
1113// currently fails on Windows (waitForSignal()?)
1114#ifdef HAVE_WINDOWS
1115 return;
1116#endif
1117 // write out more data to the file
1118 file.write("3,4\n");
1119 file.close();
1120 waitForSignal(&dataSource, &LiveDataSource::readOnUpdateCalled);
1121
1122 // checks
1123 QCOMPARE(dataSource.columnCount(), 2);
1124 QCOMPARE(dataSource.rowCount(), 2);
1125

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
initializeMethod · 0.45
setFilterMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected