File indexing completed on 2024-10-13 06:30:13
0001 /* 0002 File : AsciiFilterTest.cpp 0003 Project : LabPlot 0004 Description : Tests for the ascii filter 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2017 Alexander Semke <alexander.semke@web.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "SpiceFilterTest.h" 0012 #include "src/backend/datasources/filters/SpiceFilter.h" 0013 #include "src/backend/spreadsheet/Spreadsheet.h" 0014 0015 #include <data/ltspice/AC/LowPassFilter_AC.raw.h> 0016 #include <data/ltspice/DCTransfer/DCTransfer.raw.h> 0017 #include <data/ltspice/FFT/FFT.raw.h> 0018 #include <data/ltspice/Windows/Wakeup.raw.h> 0019 #include <data/ltspice/transient/LowPassFilter.raw.h> 0020 #include <data/ltspice/transientDouble/LowPassFilter_transient_doubleFlag.raw.h> 0021 #include <data/ngspice/ac_ascii.raw.h> 0022 #include <data/ngspice/ac_binary.raw.h> 0023 #include <data/ngspice/dc_ascii.raw.h> 0024 #include <data/ngspice/dc_binary.raw.h> 0025 0026 #include <QFile> 0027 0028 const QString ngspicePath = QStringLiteral("data/ngspice"); // relative path 0029 const QString ltspicePath = QStringLiteral("data/ltspice"); // relative path 0030 0031 #define NGSpiceFile QFINDTESTDATA(ngspicePath + QStringLiteral("/") + filename) // filename comes from the namespace 0032 #define LTSpiceFile QFINDTESTDATA(ltspicePath + QStringLiteral("/") + filename) // filename comes from the namespace 0033 #define NGSpiceRefDataFile QFINDTESTDATA(ngspicePath + QStringLiteral("/") + filename + QStringLiteral(".refdata")) // filename comes from the namespace 0034 #define LTSpiceRefDataFile QFINDTESTDATA(ltspicePath + QStringLiteral("/") + filename + QStringLiteral(".refdata")) // filename comes from the namespace 0035 0036 #define READ_REFDATA(filename) \ 0037 auto filepath = QFINDTESTDATA(filename); \ 0038 QFile f(filepath); \ 0039 QCOMPARE(f.open(QIODevice::ReadOnly), true); \ 0040 QVector<QStringList> refData; \ 0041 while (!f.atEnd()) { \ 0042 QString line = QLatin1String(f.readLine().simplified()); \ 0043 refData.append(line.split(QLatin1Char(','))); \ 0044 } \ 0045 QVERIFY(refData.count() > 0); 0046 0047 // Compare that the columns in the spreadsheet have the correct name and columnMode 0048 #define COMPARE_COLUMN_NAMES_MODE(spreadsheet, columnNames, refColumnCount) \ 0049 QCOMPARE(spreadsheet.columnCount(), refColumnCount); \ 0050 for (int i = 0; i < refColumnCount; i++) { \ 0051 QCOMPARE(spreadsheet.column(i)->columnMode(), AbstractColumn::ColumnMode::Double); \ 0052 QCOMPARE(spreadsheet.column(i)->name(), columnNames.at(i)); \ 0053 } 0054 0055 // Compare all data in the spreadsheet with the reference data 0056 #define COMPARE_ROW_VALUES_START_END_ROW(spreadsheet, refData, refDataRowCount, refColumnCount, startRow, endRow) \ 0057 ; \ 0058 QCOMPARE(spreadsheet.columnCount(), refColumnCount); \ 0059 QCOMPARE(spreadsheet.rowCount(), endRow - startRow + 1); \ 0060 for (int row = startRow - 1; row < endRow; row++) { \ 0061 for (int col = 0; col < refColumnCount; col++) { \ 0062 QCOMPARE(spreadsheet.column(col)->valueAt(row - startRow + 1), refData.at(row).at(col).toDouble()); \ 0063 } \ 0064 } 0065 0066 // Compare all data in the spreadsheet with the reference data 0067 #define COMPARE_ROW_VALUES(spreadsheet, refData, refDataRowCount, refColumnCount) \ 0068 ; \ 0069 QCOMPARE(spreadsheet.columnCount(), refColumnCount); \ 0070 QCOMPARE(spreadsheet.rowCount(), refDataRowCount); \ 0071 for (int row = 0; row < refData.count(); row++) { \ 0072 for (int col = 0; col < refColumnCount; col++) { \ 0073 QCOMPARE(spreadsheet.column(col)->valueAt(row), refData.at(row).at(col).toDouble()); \ 0074 } \ 0075 } 0076 0077 // Float version 0078 // Compare all data in the spreadsheet with the reference data 0079 #define COMPARE_ROW_VALUES_FLOAT(spreadsheet, refData, refDataRowCount, refColumnCount) \ 0080 ; \ 0081 QCOMPARE(spreadsheet.columnCount(), refColumnCount); \ 0082 QCOMPARE(spreadsheet.rowCount(), refDataRowCount); \ 0083 for (int row = 0; row < refData.count(); row++) { \ 0084 for (int col = 0; col < refColumnCount; col++) { \ 0085 QVERIFY(qFuzzyCompare(static_cast<float>(spreadsheet.column(col)->valueAt(row)), refData.at(row).at(col).toFloat())); \ 0086 } \ 0087 } 0088 0089 void SpiceFilterTest::initTestCase() { 0090 // needed in order to have the signals triggered by SignallingUndoCommand, see LabPlot.cpp 0091 qRegisterMetaType<const AbstractAspect*>("const AbstractAspect*"); 0092 qRegisterMetaType<const AbstractColumn*>("const AbstractColumn*"); 0093 } 0094 0095 void SpiceFilterTest::NgSpiceAsciiFileToBinaryFilter() { 0096 using namespace dc_ascii; 0097 0098 const QString& ngFile = NGSpiceFile; 0099 bool binary; 0100 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0101 QCOMPARE(binary, false); 0102 } 0103 0104 void SpiceFilterTest::NgSpiceBinaryFileToAsciiFilter() { 0105 using namespace dc_binary; 0106 0107 const QString& ngFile = NGSpiceFile; 0108 bool binary; 0109 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0110 QCOMPARE(binary, true); 0111 } 0112 0113 void SpiceFilterTest::NgSpiceDCAscii() { 0114 using namespace dc_ascii; 0115 0116 READ_REFDATA(NGSpiceRefDataFile); 0117 const QString& ngFile = NGSpiceFile; 0118 const int refColumnCount = refData.at(0).count(); 0119 0120 bool binary; 0121 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0122 QCOMPARE(binary, false); 0123 0124 SpiceFilter filter; 0125 auto res = filter.preview(ngFile, refData.count()); 0126 0127 QCOMPARE(res.length(), refData.length()); 0128 for (int i = 0; i < res.length(); i++) 0129 QCOMPARE(res.at(i), refData.at(i)); 0130 0131 QString resFileInfoString = filter.fileInfoString(ngFile); 0132 QCOMPARE(resFileInfoString, refFileInfoString); 0133 0134 Spreadsheet sheet(QStringLiteral("Test"), false); 0135 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0136 0137 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0138 0139 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0140 } 0141 0142 void SpiceFilterTest::NgSpiceDCBinary() { 0143 using namespace dc_binary; 0144 0145 READ_REFDATA(NGSpiceRefDataFile); 0146 const QString& ngFile = NGSpiceFile; 0147 const int refColumnCount = refData.at(0).count(); 0148 0149 bool binary; 0150 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0151 QCOMPARE(binary, true); 0152 0153 SpiceFilter filter; 0154 auto res = filter.preview(ngFile, numberPreviewData); 0155 0156 QCOMPARE(res.length(), numberPreviewData); 0157 for (int i = 0; i < res.length(); i++) 0158 QCOMPARE(res.at(i), refData.at(i)); 0159 0160 QString resFileInfoString = filter.fileInfoString(ngFile); 0161 QCOMPARE(resFileInfoString, refFileInfoString); 0162 0163 Spreadsheet sheet(QStringLiteral("Test"), false); 0164 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0165 0166 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0167 0168 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0169 } 0170 0171 void SpiceFilterTest::NgSpiceACAscii() { 0172 using namespace ac_ascii; 0173 0174 READ_REFDATA(NGSpiceRefDataFile); 0175 const QString& ngFile = NGSpiceFile; 0176 bool binary; 0177 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0178 QCOMPARE(binary, false); 0179 0180 const int refColumnCount = refData.at(0).count(); 0181 0182 SpiceFilter filter; 0183 auto res = filter.preview(ngFile, refData.count()); 0184 0185 QCOMPARE(res.length(), refData.length()); 0186 for (int i = 0; i < res.length(); i++) 0187 QCOMPARE(res.at(i), refData.at(i)); 0188 0189 QString resFileInfoString = filter.fileInfoString(ngFile); 0190 QCOMPARE(resFileInfoString, refFileInfoString); 0191 0192 Spreadsheet sheet(QStringLiteral("Test"), false); 0193 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0194 0195 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0196 0197 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0198 } 0199 0200 void SpiceFilterTest::NgSpiceACBinary() { 0201 using namespace ac_binary; 0202 0203 READ_REFDATA(NGSpiceRefDataFile); 0204 const QString& ngFile = NGSpiceFile; 0205 const int refColumnCount = refData.at(0).count(); 0206 0207 bool binary; 0208 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0209 QCOMPARE(binary, true); 0210 0211 SpiceFilter filter; 0212 auto res = filter.preview(ngFile, numberPreviewData); 0213 0214 QCOMPARE(res.length(), numberPreviewData); 0215 for (int i = 0; i < res.length(); i++) 0216 QCOMPARE(res.at(i), refData.at(i)); 0217 0218 QString resFileInfoString = filter.fileInfoString(ngFile); 0219 QCOMPARE(resFileInfoString, refFileInfoString); 0220 0221 Spreadsheet sheet(QStringLiteral("Test"), false); 0222 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0223 0224 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0225 0226 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0227 } 0228 0229 // ###################################################################################################### 0230 // Startrow not zero 0231 // ###################################################################################################### 0232 void SpiceFilterTest::NgSpiceDCAsciiStartRowNotZero() { 0233 using namespace dc_ascii; 0234 0235 READ_REFDATA(NGSpiceRefDataFile); 0236 const QString& ngFile = NGSpiceFile; 0237 const int refColumnCount = refData.at(0).count(); 0238 0239 bool binary; 0240 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0241 QCOMPARE(binary, false); 0242 0243 SpiceFilter filter; 0244 const int startRow = 2; 0245 const int endRow = 4; 0246 filter.setStartRow(startRow); 0247 filter.setEndRow(endRow); 0248 auto res = filter.preview(ngFile, numberPreviewData); 0249 0250 QCOMPARE(res.length(), numberPreviewData); 0251 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) 0252 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0253 0254 QString resFileInfoString = filter.fileInfoString(ngFile); 0255 QCOMPARE(resFileInfoString, refFileInfoString); 0256 0257 Spreadsheet sheet(QStringLiteral("Test"), false); 0258 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0259 0260 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0261 0262 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0263 } 0264 0265 void SpiceFilterTest::NgSpiceDCBinaryStartRowNotZero() { 0266 using namespace dc_binary; 0267 0268 READ_REFDATA(NGSpiceRefDataFile); 0269 const QString& ngFile = NGSpiceFile; 0270 const int refColumnCount = refData.at(0).count(); 0271 0272 bool binary; 0273 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0274 QCOMPARE(binary, true); 0275 0276 SpiceFilter filter; 0277 const int startRow = 31; 0278 const int endRow = 433; 0279 filter.setStartRow(startRow); 0280 filter.setEndRow(endRow); 0281 auto res = filter.preview(ngFile, numberPreviewData); 0282 0283 QCOMPARE(res.length(), numberPreviewData); 0284 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) 0285 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0286 0287 QString resFileInfoString = filter.fileInfoString(ngFile); 0288 QCOMPARE(resFileInfoString, refFileInfoString); 0289 0290 Spreadsheet sheet(QStringLiteral("Test"), false); 0291 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0292 0293 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0294 0295 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0296 } 0297 0298 void SpiceFilterTest::NgSpiceACAsciiStartRowNotZero() { 0299 using namespace ac_ascii; 0300 0301 READ_REFDATA(NGSpiceRefDataFile); 0302 const QString& ngFile = NGSpiceFile; 0303 bool binary; 0304 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0305 QCOMPARE(binary, false); 0306 0307 const int refColumnCount = refData.at(0).count(); 0308 0309 SpiceFilter filter; 0310 const int startRow = 2; 0311 const int endRow = 4; 0312 filter.setStartRow(startRow); 0313 filter.setEndRow(endRow); 0314 auto res = filter.preview(ngFile, numberPreviewData); 0315 0316 QCOMPARE(res.length(), numberPreviewData); 0317 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) 0318 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0319 0320 QString resFileInfoString = filter.fileInfoString(ngFile); 0321 QCOMPARE(resFileInfoString, refFileInfoString); 0322 0323 Spreadsheet sheet(QStringLiteral("Test"), false); 0324 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0325 0326 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0327 0328 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0329 } 0330 0331 void SpiceFilterTest::NgSpiceACBinaryStartRowNotZero() { 0332 using namespace ac_binary; 0333 0334 READ_REFDATA(NGSpiceRefDataFile); 0335 const QString& ngFile = NGSpiceFile; 0336 const int refColumnCount = refData.at(0).count(); 0337 0338 bool binary; 0339 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0340 QCOMPARE(binary, true); 0341 0342 SpiceFilter filter; 0343 const int startRow = 2; 0344 const int endRow = 198; 0345 filter.setStartRow(startRow); 0346 filter.setEndRow(endRow); 0347 auto res = filter.preview(ngFile, numberPreviewData); 0348 0349 QCOMPARE(res.length(), numberPreviewData); 0350 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) 0351 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0352 0353 QString resFileInfoString = filter.fileInfoString(ngFile); 0354 QCOMPARE(resFileInfoString, refFileInfoString); 0355 0356 Spreadsheet sheet(QStringLiteral("Test"), false); 0357 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0358 0359 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0360 0361 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0362 } 0363 0364 // ######################################################################################################## 0365 // 0366 // ######################################################################################################## 0367 0368 void SpiceFilterTest::NgSpiceDCBinaryBulkReadNumberLines() { 0369 using namespace dc_binary; 0370 0371 READ_REFDATA(NGSpiceRefDataFile); 0372 const QString& ngFile = NGSpiceFile; 0373 const int refColumnCount = refData.at(0).count(); 0374 0375 bool binary; 0376 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0377 QCOMPARE(binary, true); 0378 0379 SpiceFilter filter; 0380 const int startRow = 31; 0381 const int endRow = 433; 0382 filter.setReaderBulkLineCount(100); 0383 filter.setStartRow(startRow); 0384 filter.setEndRow(endRow); 0385 auto res = filter.preview(ngFile, numberPreviewData); 0386 0387 QCOMPARE(res.length(), numberPreviewData); 0388 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) { 0389 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0390 } 0391 0392 QString resFileInfoString = filter.fileInfoString(ngFile); 0393 QCOMPARE(resFileInfoString, refFileInfoString); 0394 0395 Spreadsheet sheet(QStringLiteral("Test"), false); 0396 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0397 0398 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0399 0400 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0401 } 0402 0403 void SpiceFilterTest::NgSpiceACBinaryBulkReadNumberLines() { 0404 using namespace ac_binary; 0405 0406 READ_REFDATA(NGSpiceRefDataFile); 0407 const QString& ngFile = NGSpiceFile; 0408 const int refColumnCount = refData.at(0).count(); 0409 0410 bool binary; 0411 QCOMPARE(SpiceFilter::isSpiceFile(ngFile, &binary), true); 0412 QCOMPARE(binary, true); 0413 0414 SpiceFilter filter; 0415 filter.setReaderBulkLineCount(100); 0416 const int startRow = 2; 0417 const int endRow = 198; 0418 filter.setStartRow(startRow); 0419 filter.setEndRow(endRow); 0420 auto res = filter.preview(ngFile, numberPreviewData); 0421 0422 QCOMPARE(res.length(), numberPreviewData); 0423 for (int i = startRow - 1; i < startRow - 1 + numberPreviewData; i++) 0424 QCOMPARE(res.at(i - startRow + 1), refData.at(i)); 0425 0426 QString resFileInfoString = filter.fileInfoString(ngFile); 0427 QCOMPARE(resFileInfoString, refFileInfoString); 0428 0429 Spreadsheet sheet(QStringLiteral("Test"), false); 0430 filter.readDataFromFile(ngFile, &sheet, AbstractFileFilter::ImportMode::Replace); 0431 0432 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0433 0434 COMPARE_ROW_VALUES_START_END_ROW(sheet, refData, refDataRowCount, refColumnCount, startRow, endRow); 0435 } 0436 0437 // ########################################################################################################### 0438 // #### LTSpice ############################################################################################ 0439 // ########################################################################################################### 0440 0441 void SpiceFilterTest::LtSpiceACBinary() { 0442 using namespace LowPassFilter_AC; 0443 0444 READ_REFDATA(LTSpiceRefDataFile); 0445 const QString& file = LTSpiceFile; 0446 const int refColumnCount = refData.at(0).count(); 0447 0448 bool binary; 0449 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0450 QCOMPARE(binary, true); 0451 0452 SpiceFilter filter; 0453 auto res = filter.preview(file, numberPreviewData); 0454 0455 QCOMPARE(res.length(), numberPreviewData); 0456 for (int i = 0; i < res.length(); i++) 0457 QCOMPARE(res.at(i), refData.at(i)); 0458 0459 QString resFileInfoString = filter.fileInfoString(file); 0460 QCOMPARE(resFileInfoString, refFileInfoString); 0461 0462 Spreadsheet sheet(QStringLiteral("Test"), false); 0463 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0464 0465 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0466 0467 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0468 } 0469 0470 void SpiceFilterTest::LtSpiceTranBinary() { 0471 using namespace LowPassFilter_Transient; 0472 0473 READ_REFDATA(LTSpiceRefDataFile); 0474 const QString& file = LTSpiceFile; 0475 const int refColumnCount = refData.at(0).count(); 0476 0477 bool binary; 0478 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0479 QCOMPARE(binary, true); 0480 0481 SpiceFilter filter; 0482 auto res = filter.preview(file, numberPreviewData); 0483 0484 QCOMPARE(res.length(), numberPreviewData); 0485 for (int i = 0; i < res.length(); i++) { 0486 for (int j = 0; j < columnNames.length(); j++) 0487 QVERIFY(qFuzzyCompare(res.at(i).at(j).toFloat(), refData.at(i).at(j).toFloat())); 0488 } 0489 0490 QString resFileInfoString = filter.fileInfoString(file); 0491 QCOMPARE(resFileInfoString, refFileInfoString); 0492 0493 Spreadsheet sheet(QStringLiteral("Test"), false); 0494 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0495 0496 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0497 0498 // Because the read data are floats, a float comparsion must be done, because 0499 // comparing float and double will not work properly 0500 COMPARE_ROW_VALUES_FLOAT(sheet, refData, refDataRowCount, refColumnCount); 0501 } 0502 0503 void SpiceFilterTest::LtSpiceTranDoubleBinary() { 0504 using namespace LowPassFilter_transient_doubleFlag; 0505 0506 READ_REFDATA(LTSpiceRefDataFile); 0507 const QString& file = LTSpiceFile; 0508 const int refColumnCount = refData.at(0).count(); 0509 0510 bool binary; 0511 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0512 QCOMPARE(binary, true); 0513 0514 SpiceFilter filter; 0515 auto res = filter.preview(file, numberPreviewData); 0516 0517 QCOMPARE(res.length(), numberPreviewData); 0518 for (int i = 0; i < res.length(); i++) 0519 QCOMPARE(res.at(i), refData.at(i)); 0520 0521 QString resFileInfoString = filter.fileInfoString(file); 0522 QCOMPARE(resFileInfoString, refFileInfoString); 0523 0524 Spreadsheet sheet(QStringLiteral("Test"), false); 0525 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0526 0527 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0528 0529 COMPARE_ROW_VALUES(sheet, refData, refDataRowCount, refColumnCount); 0530 } 0531 0532 void SpiceFilterTest::LtSpiceWakeup() { 0533 // The Spice file contains an additional option called 0534 // Backannotation which was not handled 0535 using namespace Wakeup; 0536 0537 READ_REFDATA(LTSpiceRefDataFile); 0538 const QString& file = LTSpiceFile; 0539 const int refColumnCount = refData.at(0).count(); 0540 0541 bool binary; 0542 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0543 QCOMPARE(binary, true); 0544 0545 SpiceFilter filter; 0546 auto res = filter.preview(file, numberPreviewData); 0547 0548 QCOMPARE(res.length(), numberPreviewData); 0549 for (int i = 0; i < res.length(); i++) { 0550 for (int j = 0; j < columnNames.length(); j++) 0551 QVERIFY(qFuzzyCompare(res.at(i).at(j).toFloat(), refData.at(i).at(j).toFloat())); 0552 } 0553 0554 QString resFileInfoString = filter.fileInfoString(file); 0555 // // For debugging purpose 0556 // for (int i=0; i < resFileInfoString.length(); i++) { 0557 // qDebug() << i << resFileInfoString.at(i) << refFileInfoString.at(i); 0558 // QCOMPARE(resFileInfoString.at(i), refFileInfoString.at(i)); 0559 // } 0560 QCOMPARE(resFileInfoString, refFileInfoString); 0561 0562 Spreadsheet sheet(QStringLiteral("Test"), false); 0563 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0564 0565 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0566 0567 // Because the read data are floats, a float comparsion must be done, because 0568 // comparing float and double will not work properly 0569 COMPARE_ROW_VALUES_FLOAT(sheet, refData, refDataRowCount, refColumnCount); 0570 } 0571 0572 void SpiceFilterTest::DCTransfer() { 0573 // The Spice file contains an additional option called 0574 // Backannotation which was not handled 0575 using namespace DCTransfer; 0576 0577 READ_REFDATA(LTSpiceRefDataFile); 0578 const QString& file = LTSpiceFile; 0579 const int refColumnCount = refData.at(0).count(); 0580 0581 bool binary; 0582 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0583 QCOMPARE(binary, true); 0584 0585 SpiceFilter filter; 0586 auto res = filter.preview(file, numberPreviewData); 0587 0588 QCOMPARE(res.length(), numberPreviewData); 0589 for (int i = 0; i < res.length(); i++) { 0590 for (int j = 0; j < columnNames.length(); j++) 0591 QVERIFY(qFuzzyCompare(res.at(i).at(j).toFloat(), refData.at(i).at(j).toFloat())); 0592 } 0593 0594 QString resFileInfoString = filter.fileInfoString(file); 0595 QCOMPARE(resFileInfoString, refFileInfoString); 0596 0597 Spreadsheet sheet(QStringLiteral("Test"), false); 0598 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0599 0600 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0601 0602 // Because the read data are floats, a float comparsion must be done, because 0603 // comparing float and double will not work properly 0604 COMPARE_ROW_VALUES_FLOAT(sheet, refData, refDataRowCount, refColumnCount); 0605 } 0606 0607 void SpiceFilterTest::FFT_From_TransientAnalysis() { 0608 // The Spice file contains an additional option called 0609 // Backannotation which was not handled 0610 using namespace FFT; 0611 0612 READ_REFDATA(LTSpiceRefDataFile); 0613 const QString& file = LTSpiceFile; 0614 const int refColumnCount = refData.at(0).count(); 0615 0616 bool binary; 0617 QCOMPARE(SpiceFilter::isSpiceFile(file, &binary), true); 0618 QCOMPARE(binary, true); 0619 0620 SpiceFilter filter; 0621 auto res = filter.preview(file, numberPreviewData); 0622 0623 QCOMPARE(res.length(), numberPreviewData); 0624 for (int i = 0; i < res.length(); i++) { 0625 for (int j = 0; j < columnNames.length(); j++) 0626 QVERIFY(qFuzzyCompare(res.at(i).at(j).toFloat(), refData.at(i).at(j).toFloat())); 0627 } 0628 0629 QString resFileInfoString = filter.fileInfoString(file); 0630 // // For debugging purpose 0631 for (int i = 0; i < resFileInfoString.length(); i++) { 0632 qDebug() << i << resFileInfoString.at(i) << refFileInfoString.at(i); 0633 QCOMPARE(resFileInfoString.at(i), refFileInfoString.at(i)); 0634 } 0635 QCOMPARE(resFileInfoString, refFileInfoString); 0636 0637 Spreadsheet sheet(QStringLiteral("Test"), false); 0638 filter.readDataFromFile(file, &sheet, AbstractFileFilter::ImportMode::Replace); 0639 0640 COMPARE_COLUMN_NAMES_MODE(sheet, columnNames, refColumnCount); 0641 0642 // Because the read data are floats, a float comparsion must be done, because 0643 // comparing float and double will not work properly 0644 COMPARE_ROW_VALUES_FLOAT(sheet, refData, refDataRowCount, refColumnCount); 0645 } 0646 0647 QTEST_MAIN(SpiceFilterTest)