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

Method testObjectImport04

tests/import_export/JSON/JSONFilterTest.cpp:212–270  ·  view source on GitHub ↗

! * import objects with an additional datetime column for the object names */

Source from the content-addressed store, hash-verified

210 * import objects with an additional datetime column for the object names
211 */
212void JSONFilterTest::testObjectImport04() {
213 Spreadsheet spreadsheet(QStringLiteral("test"), false);
214 JsonFilter filter;
215
216 const QString& fileName = QFINDTESTDATA(QLatin1String("data/intraday.json"));
217 AbstractFileFilter::ImportMode mode = AbstractFileFilter::ImportMode::Replace;
218 QVector<int> rows{0, 1};
219 filter.setModelRows(rows);
220 filter.setDataRowType(QJsonValue::Object);
221 filter.setImportObjectNames(true);
222
223 QString dateTimeFormat(QStringLiteral("yyyy-MM-dd hh:mm:ss"));
224 filter.setDateTimeFormat(dateTimeFormat);
225 filter.setStartRow(1);
226 filter.setEndRow(2);
227 filter.readDataFromFile(fileName, &spreadsheet, mode);
228
229 QCOMPARE(spreadsheet.columnCount(), 6);
230 QCOMPARE(spreadsheet.rowCount(), 2);
231 QCOMPARE(spreadsheet.column(0)->columnMode(), AbstractColumn::ColumnMode::DateTime);
232 QCOMPARE(spreadsheet.column(1)->columnMode(), AbstractColumn::ColumnMode::Double);
233 QCOMPARE(spreadsheet.column(2)->columnMode(), AbstractColumn::ColumnMode::Double);
234 QCOMPARE(spreadsheet.column(3)->columnMode(), AbstractColumn::ColumnMode::Double);
235 QCOMPARE(spreadsheet.column(4)->columnMode(), AbstractColumn::ColumnMode::Double);
236 QCOMPARE(spreadsheet.column(5)->columnMode(), AbstractColumn::ColumnMode::Integer);
237
238 QCOMPARE(spreadsheet.column(0)->plotDesignation(), AbstractColumn::PlotDesignation::X);
239 QCOMPARE(spreadsheet.column(1)->plotDesignation(), AbstractColumn::PlotDesignation::Y);
240 QCOMPARE(spreadsheet.column(2)->plotDesignation(), AbstractColumn::PlotDesignation::Y);
241 QCOMPARE(spreadsheet.column(3)->plotDesignation(), AbstractColumn::PlotDesignation::Y);
242 QCOMPARE(spreadsheet.column(4)->plotDesignation(), AbstractColumn::PlotDesignation::Y);
243 QCOMPARE(spreadsheet.column(5)->plotDesignation(), AbstractColumn::PlotDesignation::Y);
244
245 QCOMPARE(spreadsheet.column(0)->name(), i18n("timestamp"));
246 QCOMPARE(spreadsheet.column(1)->name(), QLatin1String("1. open"));
247 QCOMPARE(spreadsheet.column(2)->name(), QLatin1String("2. high"));
248 QCOMPARE(spreadsheet.column(3)->name(), QLatin1String("3. low"));
249 QCOMPARE(spreadsheet.column(4)->name(), QLatin1String("4. close"));
250 QCOMPARE(spreadsheet.column(5)->name(), QLatin1String("5. volume"));
251
252 // TODO: the values are sorted with respect to the names of the objects, i.e. to the timestamp. Why?
253 QCOMPARE(spreadsheet.column(0)->dateTimeAt(0).toString(dateTimeFormat), QStringLiteral("2018-06-14 15:56:00"));
254 QCOMPARE(spreadsheet.column(0)->dateTimeAt(1).toString(dateTimeFormat), QStringLiteral("2018-06-14 15:57:00"));
255
256 QCOMPARE(spreadsheet.column(1)->valueAt(0), 101.2700);
257 QCOMPARE(spreadsheet.column(1)->valueAt(1), 101.2700);
258
259 QCOMPARE(spreadsheet.column(2)->valueAt(0), 101.2800);
260 QCOMPARE(spreadsheet.column(2)->valueAt(1), 101.3350);
261
262 QCOMPARE(spreadsheet.column(3)->valueAt(0), 101.2600);
263 QCOMPARE(spreadsheet.column(3)->valueAt(1), 101.2550);
264
265 QCOMPARE(spreadsheet.column(4)->valueAt(0), 101.2600);
266 QCOMPARE(spreadsheet.column(4)->valueAt(1), 101.3300);
267
268 QCOMPARE(spreadsheet.column(5)->integerAt(0), 27960);
269 QCOMPARE(spreadsheet.column(5)->integerAt(1), 127830);

Callers

nothing calls this directly

Calls 15

setImportObjectNamesMethod · 0.80
setModelRowsMethod · 0.45
setDataRowTypeMethod · 0.45
setDateTimeFormatMethod · 0.45
setStartRowMethod · 0.45
setEndRowMethod · 0.45
readDataFromFileMethod · 0.45
columnCountMethod · 0.45
rowCountMethod · 0.45
columnModeMethod · 0.45
columnMethod · 0.45
plotDesignationMethod · 0.45

Tested by

no test coverage detected