diff --git a/qdlt/qdltexporter.cpp b/qdlt/qdltexporter.cpp index ae2aba93..8fc52382 100644 --- a/qdlt/qdltexporter.cpp +++ b/qdlt/qdltexporter.cpp @@ -70,7 +70,7 @@ void QDltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg) text += escapeCSVValue(QString("%1").arg(msg.getModeString())).append(delimiter); text += escapeCSVValue(QString("%1").arg(msg.getNumberOfArguments())).append(delimiter); QString payload = msg.toStringPayload().simplified().remove(QChar::Null); - if(from) from->applyRegExString(payload); + if(from) from->applyRegExString(msg,payload); text += escapeCSVValue(payload); text += "\n"; @@ -99,12 +99,12 @@ bool QDltExporter::start() { if(!to->open(QIODevice::WriteOnly | QIODevice::Text)) { - if ( true == QDltOptManager::getInstance()->issilentMode() ) - { - qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); - } - else - ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + if (QDltOptManager::getInstance()->issilentMode()) + { + qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); + } + //else + //QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), // QString("Cannot open the export file %1").arg(to->fileName())); return false; } @@ -113,12 +113,12 @@ bool QDltExporter::start() { if(!to->open(QIODevice::WriteOnly)) { - if ( true == QDltOptManager::getInstance()->issilentMode() ) - { - qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); - } - else - ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + if (QDltOptManager::getInstance()->issilentMode() ) + { + qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); + } + //else + //QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), // QString("Cannot open the export file %1").arg(to->fileName())); return false; } @@ -130,12 +130,12 @@ bool QDltExporter::start() /* Write the first line of CSV file */ if(!writeCSVHeader(to)) { - if ( true == QDltOptManager::getInstance()->issilentMode() ) - { - qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); - } - else - ;//QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), + if(QDltOptManager::getInstance()->issilentMode()) + { + qDebug() << QString("ERROR - cannot open the export file %1").arg(to->fileName()); + } + //else + //QMessageBox::critical(qobject_cast(parent()), QString("DLT Viewer"), // QString("Cannot open the export file %1").arg(to->fileName())); return false; } @@ -283,7 +283,7 @@ bool QDltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &bu text += " "; } QString payload = msg.toStringPayload().simplified().remove(QChar::Null); - if(from) from->applyRegExString(payload); + if(from) from->applyRegExString(msg,payload); text += payload; text += "\n"; try @@ -331,7 +331,7 @@ bool QDltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &bu else text += "|" + QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0')); QString payload = msg.toStringPayload().simplified().remove(QChar::Null); - if(from) from->applyRegExString(payload); + if(from) from->applyRegExString(msg,payload); text += "|" + QString("%1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0')) + "|" + msg.getEcuid() + "|" + msg.getApid() + @@ -440,8 +440,9 @@ void QDltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager * { //FIXME: The following does not work for non verbose messages, must be fixed to enable RegEx for DLT Export again //msg.setNumberOfArguments(msg.sizeArguments()); - //if(from) from->applyRegExStringMsg(msg); - //msg.getMsg(buf,true); + bool isApplied = false; + if(from) isApplied = from->applyRegExStringMsg(msg); + if(isApplied) msg.getMsg(buf,true); } // export message diff --git a/qdlt/qdltfile.cpp b/qdlt/qdltfile.cpp index e0ef1748..1b97144e 100644 --- a/qdlt/qdltfile.cpp +++ b/qdlt/qdltfile.cpp @@ -755,12 +755,13 @@ void QDltFile::setIndexFilter(QVector _indexFilter) indexFilter = _indexFilter; } -bool QDltFile::applyRegExString(QString &text) +bool QDltFile::applyRegExString(QDltMsg &msg,QString &text) { - return filterList.applyRegExString(text); + + return filterList.applyRegExString(msg,text); } bool QDltFile::applyRegExStringMsg(QDltMsg &msg) -{ +{ return filterList.applyRegExStringMsg(msg); } diff --git a/qdlt/qdltfile.h b/qdlt/qdltfile.h index b6a4e399..c07963d8 100644 --- a/qdlt/qdltfile.h +++ b/qdlt/qdltfile.h @@ -302,7 +302,7 @@ class QDLT_EXPORT QDltFile : public QDlt //! Apply RegEx Replace to the string, if any active in the filters /*! */ - bool applyRegExString(QString &text); + bool applyRegExString(QDltMsg &msg,QString &text); //! Apply RegEx Replace to the arguments of a message, if any active in the filters /*! diff --git a/qdlt/qdltfilterlist.cpp b/qdlt/qdltfilterlist.cpp index c5a976e6..0152585c 100644 --- a/qdlt/qdltfilterlist.cpp +++ b/qdlt/qdltfilterlist.cpp @@ -124,7 +124,7 @@ QString QDltFilterList::checkMarker(QDltMsg &msg) #endif -bool QDltFilterList::applyRegExString(QString &text) +bool QDltFilterList::applyRegExString(QDltMsg &msg,QString &text) { QDltFilter *filter; bool result = false; @@ -133,7 +133,7 @@ bool QDltFilterList::applyRegExString(QString &text) { filter = pfilters[numfilter]; - if(filter->enableFilter && filter->enableRegexSearchReplace) + if(filter->enableFilter && filter->enableRegexSearchReplace && filter->match(msg)) { text.replace(QRegularExpression(filter->regex_search), filter->regex_replace); result = true; @@ -151,7 +151,7 @@ bool QDltFilterList::applyRegExStringMsg(QDltMsg &msg) { filter = pfilters[numfilter]; - if(filter->enableFilter && filter->enableRegexSearchReplace) + if(filter->enableFilter && filter->enableRegexSearchReplace && filter->match(msg)) { for(int num=0;num #include -// Global static pointer used to ensure a single instance of the class. -QDltOptManager* QDltOptManager::instance; - -QDltOptManager::QDltOptManager() -{ - project = false; - silent_mode = false; - terminate=false; - convertionmode = e_ASCI; - commandline_mode = false; - delimiter=','; -} - QDltOptManager* QDltOptManager::getInstance() { - if (!instance) - instance = new QDltOptManager; - - return instance; -} - -QDltOptManager::QDltOptManager(QDltOptManager const&) -{ + static QDltOptManager instance; + return &instance; } const QStringList &QDltOptManager::getMf4Files() const @@ -81,32 +62,8 @@ void QDltOptManager::printVersion(QString appname) void QDltOptManager::printUsage() { -#if (WIN32) - qDebug()<<"Usage: dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; -#else - qDebug()<<"Usage: dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; -#endif + qDebug().noquote() << getHelpText(); - qDebug()<<"\nOptions:"; - qDebug()<<" [logfile]\tLoading one or more logfiles on startup (must end with .dlt)"; - qDebug()<<" [projectfile]\tLoading project file on startup (must end with .dlp)"; - qDebug()<<" [filterfile]\tLoading filterfile on startup (must end with .dlf)"; - qDebug()<<" [pcapfile]\tImporting DLT/IPC from pcap file on startup (must end with .pcap)"; - qDebug()<<" [mf4file]\tImporting DLT/IPC from mf4 file on startup (must end with .mf4)"; - qDebug()<<" -h or --help\tPrint usage"; - qDebug()<<" -c textfile\tConvert logfile file to textfile"; - qDebug()<<" -u\tConversion will be done in UTF8 instead of ASCII"; - qDebug()<<" -csv\tConversion will be done in CSV format"; - qDebug()<<" -d\tConversion will NOT be done, save in dlt file format again instead"; - qDebug()<<" -dd\tConversion will NOT be done, save as decoded messages in dlt format"; - qDebug()<<" -b \"plugin|command|param1|..|param\"\tExecute a plugin command with parameters before loading log file."; - qDebug()<<" -e \"plugin|command|param1|..|param\"\tExecute a plugin command with parameters after loading log file."; - qDebug()<<" -s or --silent\tEnable silent mode without any GUI. Ideal for commandline usage."; - qDebug()<<" -stream\tTreat the input logfiles as DLT stream instead of DLT files."; - qDebug()<<" -t or --terminate\tTerminate DLT Viewer after command line execution."; - qDebug()<<" -v or --version\tOnly show version and buildtime information"; - qDebug()<<" -w workingdirectory\tSet the working directory"; - qDebug()<<" -delimiter \tThe used delimiter for CSV export (Default: ,)."; qDebug()<<"\nExamples:"; qDebug()<<" dlt-viewer.exe -t -c output.txt input.dlt"; qDebug()<<" dlt-viewer.exe -t -s -u -c output.txt input.dlt"; @@ -120,42 +77,37 @@ void QDltOptManager::printUsage() qDebug()<<" dlt-viewer.exe -t -c output.txt input1.mf4 input2.mf4"; } -void QDltOptManager::parse(QStringList *opt) +void QDltOptManager::parse(QStringList&& opt) { - QString str; - qDebug() << "### Starting DLT Viewer"; - printVersion(opt->at(0)); + printVersion(opt.at(0)); qDebug() << "### Parsing Options"; /* the default parameter - exactly one parameter - should either be * a dlt or a dlp file, so this enables the "doubleclick" feature */ - //str = opt->at(0); && ( str.compare("-h)") != 0 || str.compare("-v") !=0 ) - if(opt->size()==2 ) - { - if(opt->at(1).endsWith(".dlp") || opt->at(1).endsWith(".DLP")) - { - projectFile = QString("%1").arg(opt->at(1)); - project = true; - qDebug()<< "Project filename:" << projectFile; - return; - } - if(opt->at(1).endsWith(".dlt") || opt->at(1).endsWith(".DLT")) - { - const QString logFile = QString("%1").arg(opt->at(1)); - logFiles += logFile; - qDebug()<< "DLT filename:" << logFile; - return; - } - } + //str = opt.at(0); && ( str.compare("-h)") != 0 || str.compare("-v") !=0 ) + if (opt.size() == 2) { + if (opt.at(1).endsWith(".dlp") || opt.at(1).endsWith(".DLP")) { + projectFile = QString("%1").arg(opt.at(1)); + project = true; + qDebug() << "Project filename:" << projectFile; + return; + } + if (opt.at(1).endsWith(".dlt") || opt.at(1).endsWith(".DLT")) { + const QString logFile = QString("%1").arg(opt.at(1)); + logFiles += logFile; + qDebug() << "DLT filename:" << logFile; + return; + } + } // 0==Binary 1==First Argument - for (int i = 0; i < opt->size(); ++i) + for (int i = 0; i < opt.size(); ++i) { - str = opt->at(i); + QString str = opt.at(i); if(str.compare("-h") == 0 || str.compare("--help") == 0) { @@ -172,7 +124,7 @@ void QDltOptManager::parse(QStringList *opt) } else if(str.compare("-v") == 0 || str.compare("--version") == 0) { - printVersion(opt->at(0)); + // version has already been printed above, just exit exit(0); } else if(str.compare("-t") == 0 || str.compare("--terminate") == 0) @@ -182,7 +134,7 @@ void QDltOptManager::parse(QStringList *opt) } else if(str.compare("-c")==0) { - QString c1 = opt->value(i+1); + QString c1 = opt.value(i+1); convertDestFile = QString("%1").arg(c1); // check here already if the selected file exists @@ -194,7 +146,7 @@ void QDltOptManager::parse(QStringList *opt) } else if(str.compare("-delimiter")==0) { - QString c1 = opt->value(i+1); + QString c1 = opt.value(i+1); delimiter = QString("%1").arg(c1).front().toLatin1(); @@ -224,30 +176,30 @@ void QDltOptManager::parse(QStringList *opt) } else if(str.compare("-e")==0) { - QString c = opt->value(i+1); + QString c = opt.value(i+1); postPluginCommands += c; commandline_mode = true; ++i; } else if(str.compare("-b")==0) { - QString c = opt->value(i+1); + QString c = opt.value(i+1); prePluginCommands += c; commandline_mode = true; ++i; } else if (str.compare("-w") == 0) { - workingDirectory = opt->value(i+1); + workingDirectory = opt.value(i+1); ++i; } - else if(opt->at(i).endsWith(".dlt") || opt->at(i).endsWith(".DLT")) + else if(opt.at(i).endsWith(".dlt") || opt.at(i).endsWith(".DLT")) { - const QString logFile = QString("%1").arg(opt->at(i)); + const QString logFile = QString("%1").arg(opt.at(i)); logFiles += logFile; qDebug()<< "DLT filename:" << logFile; } - else if(opt->at(i).endsWith(".dlp") || opt->at(i).endsWith(".DLP")) + else if(opt.at(i).endsWith(".dlp") || opt.at(i).endsWith(".DLP")) { if (project == true) { @@ -256,24 +208,24 @@ void QDltOptManager::parse(QStringList *opt) exit(-1); } - projectFile = QString("%1").arg(opt->at(i)); + projectFile = QString("%1").arg(opt.at(i)); project = true; qDebug()<< "Project filename:" << projectFile; } - else if(opt->at(i).endsWith(".dlf") || opt->at(i).endsWith(".DLF")) + else if(opt.at(i).endsWith(".dlf") || opt.at(i).endsWith(".DLF")) { - filterFiles += QString("%1").arg(opt->at(i)); - qDebug()<< "Filter filename:" << QString("%1").arg(opt->at(i)); + filterFiles += QString("%1").arg(opt.at(i)); + qDebug()<< "Filter filename:" << QString("%1").arg(opt.at(i)); } - else if(opt->at(i).endsWith(".pcap") || opt->at(i).endsWith(".PCAP")) + else if(opt.at(i).endsWith(".pcap") || opt.at(i).endsWith(".PCAP")) { - const QString pcapFile = QString("%1").arg(opt->at(i)); + const QString pcapFile = QString("%1").arg(opt.at(i)); pcapFiles += pcapFile; qDebug()<< "Pcap filename:" << pcapFile; } - else if(opt->at(i).endsWith(".mf4") || opt->at(i).endsWith(".MF4")) + else if(opt.at(i).endsWith(".mf4") || opt.at(i).endsWith(".MF4")) { - const QString mf4File = QString("%1").arg(opt->at(i)); + const QString mf4File = QString("%1").arg(opt.at(i)); mf4Files += mf4File; qDebug()<< "MF4 filename:" << mf4File; } @@ -315,3 +267,57 @@ QString QDltOptManager::getCommandName(){return commandName;} QStringList QDltOptManager::getCommandParams(){return commandParams;} QString QDltOptManager::getWorkingDirectory() const { return workingDirectory; } char QDltOptManager::getDelimiter(){return delimiter;} + +QString QDltOptManager::getHelpText() const { + QStringList helpText; +#if (WIN32) + helpText << "Usage: dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; +#else + helpText << "Usage: dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]"; +#endif + + helpText << "\nOptions:"; + helpText << " [logfile]\tLoading one or more logfiles on startup (must end with .dlt)"; + helpText << " [projectfile]\tLoading project file on startup (must end with .dlp)"; + helpText << " [filterfile]\tLoading filterfile on startup (must end with .dlf)"; + helpText << " [pcapfile]\tImporting DLT/IPC from pcap file on startup (must end with .pcap)"; + helpText << " [mf4file]\tImporting DLT/IPC from mf4 file on startup (must end with .mf4)"; + helpText << " -h or --help\tPrint usage"; + helpText << " -c textfile\tConvert logfile file to textfile"; + helpText << " -u\tConversion will be done in UTF8 instead of ASCII"; + helpText << " -csv\tConversion will be done in CSV format"; + helpText << " -d\tConversion will NOT be done, save in dlt file format again instead"; + helpText << " -dd\tConversion will NOT be done, save as decoded messages in dlt format"; + helpText << " -b \"plugin|command|param1|..|param\"\tExecute a plugin command with parameters before loading log file."; + helpText << " -e \"plugin|command|param1|..|param\"\tExecute a plugin command with parameters after loading log file."; + helpText << " -s or --silent\tEnable silent mode without any GUI. Ideal for commandline usage."; + helpText << " -stream\tTreat the input logfiles as DLT stream instead of DLT files."; + helpText << " -t or --terminate\tTerminate DLT Viewer after command line execution."; + helpText << " -v or --version\tOnly show version and buildtime information"; + helpText << " -w workingdirectory\tSet the working directory"; + helpText << " -delimiter \tThe used delimiter for CSV export (Default: ,)."; + + return helpText.join('\n'); +} + +void QDltOptManager::reset() { + project = false; + terminate = false; + silent_mode = false; + commandline_mode = false; + convertionmode = e_ASCI; + inputmode = e_inputmode::DLT; + projectFile.clear(); + logFiles.clear(); + filterFiles.clear(); + convertDestFile.clear(); + pluginName.clear(); + commandName.clear(); + commandParams.clear(); + prePluginCommands.clear(); + postPluginCommands.clear(); + workingDirectory.clear(); + delimiter = ','; + pcapFiles.clear(); + mf4Files.clear(); +} diff --git a/qdlt/qdltoptmanager.h b/qdlt/qdltoptmanager.h index 6cdda7e1..f1fccd71 100644 --- a/qdlt/qdltoptmanager.h +++ b/qdlt/qdltoptmanager.h @@ -46,7 +46,7 @@ class QDLT_EXPORT QDltOptManager static QDltOptManager* getInstance(); void printUsage(); void printVersion(QString appname); - void parse(QStringList *opt); + void parse(QStringList&& opt); bool isProjectFile(); bool isTerminate(); @@ -71,16 +71,17 @@ class QDLT_EXPORT QDltOptManager const QStringList &getMf4Files() const; char getDelimiter(); + QString getHelpText() const; + + // only testing relevant + void reset(); + private: - QDltOptManager(); - QDltOptManager(QDltOptManager const&); - static QDltOptManager *instance; - - bool project; - bool terminate; - bool silent_mode; - bool commandline_mode; - e_convertionmode convertionmode; + bool project{false}; + bool terminate{false}; + bool silent_mode{false}; + bool commandline_mode{false}; + e_convertionmode convertionmode{e_ASCI}; e_inputmode inputmode{e_inputmode::DLT}; QString projectFile; @@ -97,7 +98,7 @@ class QDLT_EXPORT QDltOptManager QStringList postPluginCommands; // command after loading log file QString workingDirectory; - char delimiter; + char delimiter{','}; }; #endif //QDLTOPTMANAGER_H diff --git a/qdlt/tests/CMakeLists.txt b/qdlt/tests/CMakeLists.txt index beccd1f3..7b65fda1 100644 --- a/qdlt/tests/CMakeLists.txt +++ b/qdlt/tests/CMakeLists.txt @@ -1,15 +1,31 @@ -add_executable(test_tools +add_executable(test_dltmessagematcher test_dltmessagematcher.cpp ) target_link_libraries( - test_tools + test_dltmessagematcher PRIVATE GTest::gtest_main qdlt ) add_test( - NAME test_tools - COMMAND $ + NAME test_dltmessagematcher + COMMAND $ ) + +add_executable(test_dltoptmanager + test_dltoptmanager.cpp +) + +target_link_libraries( + test_dltoptmanager + PRIVATE + GTest::gtest_main + qdlt +) + +add_test( + NAME test_dltoptmanager + COMMAND $ +) diff --git a/qdlt/tests/test_dltoptmanager.cpp b/qdlt/tests/test_dltoptmanager.cpp new file mode 100644 index 00000000..116d19c9 --- /dev/null +++ b/qdlt/tests/test_dltoptmanager.cpp @@ -0,0 +1,191 @@ +#include + +#include + +#include + + +QString logMessageSink; + +void messageHandler(QtMsgType type, const QMessageLogContext &, + const QString &msg) { + if (type == QtDebugMsg) { + logMessageSink.append(msg); + } +} + +class OptManagerTest : public ::testing::Test { +protected: + static void SetUpTestSuite() { + m_manager = QDltOptManager::getInstance(); + + qInstallMessageHandler(messageHandler); + } + + void SetUp() override { + m_manager->reset(); + } + + void TearDown() override { + logMessageSink.clear(); + } + + static QDltOptManager* m_manager; +}; + +QDltOptManager* OptManagerTest::m_manager = nullptr; + +TEST_F(OptManagerTest, txtConversion) { + auto args = QStringList() << "executable" << "-t" << "-c" << "output.txt" << "input.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.txt"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, txtConversionSilentUtf8Mode) { + auto args = QStringList() << "executable" << "-t" << "-s" << "-u" << "-c" << "output.txt" << "input.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_TRUE(m_manager->issilentMode()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.txt"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_EQ(m_manager->get_convertionmode(), e_UTF8); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, txtConversionSilentAsciiMode) { + auto args = QStringList() << "executable" << "-t" << "-s" << "-d" << "-c" << "output.txt" << "input.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_TRUE(m_manager->issilentMode()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.txt"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_EQ(m_manager->get_convertionmode(), e_DLT); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, csvConversionSilentMode) { + auto args = QStringList() << "executable" << "-t" << "-s" << "-csv" << "-c" << "output.csv" << "input.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_TRUE(m_manager->issilentMode()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.csv"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_EQ(m_manager->get_convertionmode(), e_CSV); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, txtConversionSilentDdlMode) { + auto args = QStringList() << "executable" << "-t" << "-s" << "decoded.dlp" << "-dd" << "-c" << "output.dlt" << "input.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_TRUE(m_manager->issilentMode()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.dlt"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_EQ(m_manager->get_convertionmode(), e_DDLT); + EXPECT_TRUE(m_manager->isCommandlineMode()); + EXPECT_EQ(m_manager->getProjectFile(), "decoded.dlp"); +} + +TEST_F(OptManagerTest, pluginPostCommands) { + auto args = QStringList() << "executable" + << "-p" + << "export.dlp" + << "-e" + << "\"Filetransfer Plugin|export|ftransferdir\"" + << "input.dlt"; + m_manager->parse(std::move(args)); + + EXPECT_EQ(m_manager->getProjectFile(), "export.dlp"); + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_TRUE(m_manager->getPostPluginCommands().contains("\"Filetransfer Plugin|export|ftransferdir\"")); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, pluginPreCommands) { + auto args = QStringList() << "executable" + << "-b" + << "\"Filetransfer Plugin|export|ftransferdir\"" + << "input.dlt"; + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_TRUE(m_manager->getPrePluginCommands().contains("\"Filetransfer Plugin|export|ftransferdir\"")); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, multipleLogFiles) { + auto args = QStringList() << "executable" << "input1.dlt" << "input2.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->getLogFiles().contains("input1.dlt")); + EXPECT_TRUE(m_manager->getLogFiles().contains("input2.dlt")); +} + +TEST_F(OptManagerTest, pcapFile) { + auto args = QStringList() << "executable" << "-t" << "-c" << "output.txt" << "input.pcap"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.txt"); + EXPECT_TRUE(m_manager->getPcapFiles().contains("input.pcap")); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, mf4Files) { + auto args = QStringList() << "executable" << "-t" << "-c" << "output.txt" << "input1.mf4" << "input2.mf4"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_EQ(m_manager->getConvertDestFile(), "output.txt"); + EXPECT_TRUE(m_manager->getMf4Files().contains("input1.mf4")); + EXPECT_TRUE(m_manager->getMf4Files().contains("input2.mf4")); + EXPECT_TRUE(m_manager->isCommandlineMode()); +} + +TEST_F(OptManagerTest, filterFile) { + auto args = QStringList() << "executable" + << "input.dlt" + << "filter.dlf" + << "-c" + << "out.dlt" + << "-d" + << "-s" + << "-t"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(m_manager->getLogFiles().contains("input.dlt")); + EXPECT_TRUE(m_manager->getFilterFiles().contains("filter.dlf")); + EXPECT_EQ(m_manager->getConvertDestFile(), "out.dlt"); + EXPECT_TRUE(m_manager->isCommandlineMode()); + EXPECT_TRUE(m_manager->isTerminate()); + EXPECT_TRUE(m_manager->issilentMode()); +} + +TEST_F(OptManagerTest, version) { + // impossible to check just version because there is a call to exit(0) in the qdltoptmanager + // but any output will be enough to check the version call because it is always printed + auto args = QStringList() << "executable" << "some.dlt"; + + m_manager->parse(std::move(args)); + + EXPECT_TRUE(logMessageSink.contains("Executable Name:")); + EXPECT_TRUE(logMessageSink.contains("Build time:")); + EXPECT_TRUE(logMessageSink.contains("Version:")); +} diff --git a/src/main.cpp b/src/main.cpp index dc8b8db5..e3ac3cac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,10 +45,7 @@ int main(int argc, char *argv[]) } QApplication a(argc, argv); - - QStringList arguments = a.arguments(); - QDltOptManager *opt = QDltOptManager::getInstance(); - opt->parse(&arguments); + QDltOptManager::getInstance()->parse(a.arguments()); MainWindow w; w.show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 984adb70..83702fcf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -17,7 +17,6 @@ * @licence end@ */ -#include #include #include #include @@ -5721,39 +5720,10 @@ void MainWindow::on_action_menuHelp_Info_triggered() } -void MainWindow::on_action_menuHelp_Command_Line_triggered() -{ - // Please copy changes to QDltOptManager::getInstance().cpp - printUsage() - - QMessageBox::information(0, QString("DLT Viewer - Command line usage\t\t\t\t\t"), // tabs used to expand mesage box ! - #ifdef WIN32 - QString("Usage: dlt-viewer.exe [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]\n\n")+ - QString("Options:\n")+ - #else - QString("Usage: dlt-viewer [OPTIONS] [logfile] [projectfile] [filterfile] [mf4file] [pcapfile]\n\n")+ - QString("Options:\n")+ - #endif - QString(" [logfile]\t\t\tLoading one or more logfiles on startup (must end with .dlt)\n")+ - QString(" [projectfile]\t\tLoading project file on startup (must end with .dlp)\n")+ - QString(" [filterfile]\t\tLoading filterfile on startup (must end with .dlf)\n")+ - QString(" [pcapfile]\tImporting DLT/IPC from pcap file on startup (must end with .pcap)\n")+ - QString(" [mf4file]\tImporting DLT/IPC from mf4 file on startup (must end with .mf4)\n")+ - QString(" -h\t\t\tPrint usage\n")+ - QString(" -s\t\t\tEnable silent mode without any GUI. Ideal for commandline usage.\n")+ - QString(" -stream\tTreat the input logfiles as DLT stream instead of DLT files.\n")+ - QString(" -v\t\t\tShow version and buildtime information\n")+ - QString(" -c \tConvert logfile to ASCII textfile\n")+ - QString(" -u\t\t\tExport logfile to UTF8 instead\n")+ - QString(" -csv\t\t\tExport logfile to csv ( Excel ) instead\n")+ - QString(" -d\t\t\tExport logfile to DLT format\n")+ - QString(" -dd\t\t\tExport logfile to decoded DLT format\n")+ - QString(" -b |command|param1|..|param\n\t\t\tExecute a command plugin with parameters before loading log file\n")+ - QString(" -e |command|param1|..|param\n\t\t\tExecute a command plugin with parameters after loading log file\n")+ - QString(" -t\t\t\tTerminate DLT Viewer after command line execution\n")+ - QString(" -v\t\t\tShow version and buildtime information\n")+ - QString(" -w workingdirectory\tSet the working directory\n")+ - QString(" -delimiter \tThe used delimiter for CSV export (Default: ,)\n") - ); +void MainWindow::on_action_menuHelp_Command_Line_triggered() { + QMessageBox::information( + 0, "DLT Viewer - Command line usage\t\t\t\t\t", // tabs used to expand message box ! + QDltOptManager::getInstance()->getHelpText()); } void MainWindow::on_pluginWidget_itemSelectionChanged() diff --git a/src/searchtablemodel.cpp b/src/searchtablemodel.cpp index e0abba56..443872db 100644 --- a/src/searchtablemodel.cpp +++ b/src/searchtablemodel.cpp @@ -163,7 +163,8 @@ QVariant SearchTableModel::data(const QModelIndex &index, int role) const case FieldNames::Payload: /* display payload */ visu_data = msg.toStringPayload().simplified().remove(QChar::Null); - if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool())) + if(qfile) qfile->applyRegExString(msg,visu_data); + /*if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool())) { for(int num = 0; num < project->filter->topLevelItemCount (); num++) { FilterItem *item = (FilterItem*)project->filter->topLevelItem(num); @@ -171,7 +172,7 @@ QVariant SearchTableModel::data(const QModelIndex &index, int role) const visu_data.replace(QRegularExpression(item->filter.regex_search), item->filter.regex_replace); } } - } + }*/ return visu_data; case FieldNames::MessageId: return QString::asprintf(project->settings->msgIdFormat.toUtf8(),msg.getMessageId()); diff --git a/src/tablemodel.cpp b/src/tablemodel.cpp index 1018ff28..c4cf1a0d 100644 --- a/src/tablemodel.cpp +++ b/src/tablemodel.cpp @@ -248,8 +248,8 @@ TableModel::TableModel(const QString & /*data*/, QObject *parent) } /* display payload */ visu_data = msg.toStringPayload().simplified().remove(QChar::Null); - - if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool())) + if(qfile) qfile->applyRegExString(msg,visu_data); + /*if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool())) { for(int num = 0; num < project->filter->topLevelItemCount (); num++) { FilterItem *item = (FilterItem*)project->filter->topLevelItem(num); @@ -257,7 +257,7 @@ TableModel::TableModel(const QString & /*data*/, QObject *parent) visu_data.replace(QRegularExpression(item->filter.regex_search), item->filter.regex_replace); } } - } + }*/ /* limit size of string to 1000 characters to speed up scrolling */ if(visu_data.size()>1000)