From 18dd09378be73868751b2ecf0463edc41ff3ee0e Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sat, 23 May 2020 10:02:45 -0400 Subject: [PATCH] 2020-05-23 Fred Gleason * Added a 'cmdline_parser_test' test harness. * Fixed a bug in 'RDCmdSwitch' that caused value-only arguments containing '=' characters to be incorrectly parsed. Signed-off-by: Fred Gleason --- .gitignore | 1 + ChangeLog | 4 +++ lib/rdcmd_switch.cpp | 22 +++++++++------ tests/Makefile.am | 4 +++ tests/cmdline_parser_test.cpp | 52 +++++++++++++++++++++++++++++++++++ tests/cmdline_parser_test.h | 35 +++++++++++++++++++++++ 6 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 tests/cmdline_parser_test.cpp create mode 100644 tests/cmdline_parser_test.h diff --git a/.gitignore b/.gitignore index c01fc77e..d44a1ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,7 @@ tests/audio_export_test tests/audio_import_test tests/audio_metadata_test tests/audio_peaks_test +tests/cmdline_parser_test tests/datedecode_test tests/dateparse_test tests/db_charset_test diff --git a/ChangeLog b/ChangeLog index d14c87a7..c6aba459 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19843,3 +19843,7 @@ enumeration. * Fixed a bug in rdlibrary(1) that caused cuts to be incorrectly sorted when scheduled 'By Specified Order'. +2020-05-23 Fred Gleason + * Added a 'cmdline_parser_test' test harness. + * Fixed a bug in 'RDCmdSwitch' that caused value-only arguments + containing '=' characters to be incorrectly parsed. diff --git a/lib/rdcmd_switch.cpp b/lib/rdcmd_switch.cpp index 3bdf0ea4..c106916e 100644 --- a/lib/rdcmd_switch.cpp +++ b/lib/rdcmd_switch.cpp @@ -44,17 +44,23 @@ RDCmdSwitch::RDCmdSwitch(int argc,char *argv[],const char *modname, if(value=="-d") { switch_debug=true; } - QStringList f0=value.split("="); + QStringList f0=value.split("=",QString::KeepEmptyParts); if(f0.size()>=2) { - switch_keys.push_back(f0[0]); - for(int i=2;i +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include +#include + +#include + +#include + +#include "cmdline_parser_test.h" + +MainObject::MainObject(QObject *parent) + :QObject(parent) +{ + // + // Read Command Options + // + RDCmdSwitch *cmd= + new RDCmdSwitch(qApp->argc(),qApp->argv(),"cmdline_parser_test", + CMDLINE_PARSER_TEST_USAGE); + for(unsigned i=0;ikeys();i++) { + printf(" key[%d]: %s\n",i,cmd->key(i).utf8().constData()); + printf("value[%d]: %s\n",i,cmd->value(i).toUtf8().constData()); + } + exit(0); +} + + +int main(int argc,char *argv[]) +{ + QApplication a(argc,argv,false); + new MainObject(); + return a.exec(); +} diff --git a/tests/cmdline_parser_test.h b/tests/cmdline_parser_test.h new file mode 100644 index 00000000..a0fc265e --- /dev/null +++ b/tests/cmdline_parser_test.h @@ -0,0 +1,35 @@ +// cmdline_parser_test.h +// +// Test the Rivendell command-line parser routines. +// +// (C) Copyright 2020 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef CMDLINE_PARSER_TEST_H +#define CMDLINE_PARSER_TEST_H + +#include + +#define CMDLINE_PARSER_TEST_USAGE " ...\n\n" + +class MainObject : public QObject +{ + public: + MainObject(QObject *parent=0); +}; + + +#endif // CMDLINE_PARSER_TEST_H