From 1a88bcb9998aa8ba1a29111e3735b9934724821d Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 19 Feb 2020 11:52:40 -0500 Subject: [PATCH] 2020-02-19 Fred Gleason * Fixed a bug with the '%y' metadata wildcard where garbage would be returned if a valid year had not been set. * Added a 'metadata_wildcard_test' harness. --- .gitignore | 1 + ChangeLog | 4 ++ apis/pypad/api/pypad.py | 5 +- lib/rdlog_line.cpp | 7 ++- tests/Makefile.am | 5 ++ tests/metadata_wildcard_test.cpp | 99 ++++++++++++++++++++++++++++++++ tests/metadata_wildcard_test.h | 38 ++++++++++++ 7 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 tests/metadata_wildcard_test.cpp create mode 100644 tests/metadata_wildcard_test.h diff --git a/.gitignore b/.gitignore index 707c2efd..c01fc77e 100644 --- a/.gitignore +++ b/.gitignore @@ -112,6 +112,7 @@ tests/download_test tests/getpids_test tests/log_unlink_test tests/mcast_recv_test +tests/metadata_wildcard_test tests/notification_test tests/rdxml_parse_test tests/readcd_test diff --git a/ChangeLog b/ChangeLog index fd86541f..8cb28365 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19653,3 +19653,7 @@ * Removed the 'RDLabel' widget. 2020-02-19 Fred Gleason * Added a 'Disconnect All Jack Ports' ['JZ'] RML. +2020-02-19 Fred Gleason + * Fixed a bug with the '%y' metadata wildcard where garbage would + be returned if a valid year had not been set. + * Added a 'metadata_wildcard_test' harness. diff --git a/apis/pypad/api/pypad.py b/apis/pypad/api/pypad.py index fd38e976..b75e4df9 100644 --- a/apis/pypad/api/pypad.py +++ b/apis/pypad/api/pypad.py @@ -122,7 +122,10 @@ class Update(object): if isinstance(self.__fields['padUpdate'][stype][sfield],str): string=string.replace('%'+wildcard,self.escape(self.__fields['padUpdate'][stype][sfield],esc)) else: - string=string.replace('%'+wildcard,str(self.__fields['padUpdate'][stype][sfield])) + if self.__fields['padUpdate'][stype][sfield] is None: + string=string.replace('%'+wildcard,'') + else : + string=string.replace('%'+wildcard,str(self.__fields['padUpdate'][stype][sfield])) except TypeError: string=string.replace('%'+wildcard,'') except KeyError: diff --git a/lib/rdlog_line.cpp b/lib/rdlog_line.cpp index 05987c1e..7e666b40 100644 --- a/lib/rdlog_line.cpp +++ b/lib/rdlog_line.cpp @@ -1619,7 +1619,12 @@ QString RDLogLine::resolveWildcards(QString pattern,int log_id) else { pattern.replace("%x",QString().sprintf("%d",log_id)); } - pattern.replace("%y",QString().sprintf("%d",year().year())); + if(year().isValid()) { + pattern.replace("%y",QString().sprintf("%d",year().year())); + } + else { + pattern.replace("%y",""); + } // %z Log Line Number return pattern; diff --git a/tests/Makefile.am b/tests/Makefile.am index 3efd85f7..7e7e932b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -38,6 +38,7 @@ noinst_PROGRAMS = audio_convert_test\ getpids_test\ log_unlink_test\ mcast_recv_test\ + metadata_wildcard_test\ notification_test\ rdxml_parse_test\ readcd_test\ @@ -83,6 +84,10 @@ dist_log_unlink_test_SOURCES = log_unlink_test.cpp log_unlink_test.h nodist_log_unlink_test_SOURCES = moc_log_unlink_test.cpp log_unlink_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support +dist_metadata_wildcard_test_SOURCES = metadata_wildcard_test.cpp metadata_wildcard_test.h +nodist_metadata_wildcard_test_SOURCES = moc_metadata_wildcard_test.cpp +metadata_wildcard_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support + dist_mcast_recv_test_SOURCES = mcast_recv_test.cpp mcast_recv_test.h nodist_mcast_recv_test_SOURCES = moc_mcast_recv_test.cpp mcast_recv_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support diff --git a/tests/metadata_wildcard_test.cpp b/tests/metadata_wildcard_test.cpp new file mode 100644 index 00000000..ac8359c4 --- /dev/null +++ b/tests/metadata_wildcard_test.cpp @@ -0,0 +1,99 @@ +// metadata_wildcard_test.cpp +// +// Test the Rivendell multicast receiver routines +// +// (C) Copyright 2018 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. +// + +#include +#include + +#include + +#include +#include +#include +#include + +#include "metadata_wildcard_test.h" + +MainObject::MainObject(QObject *parent) + : QObject(parent) +{ + unsigned cartnum=0; + int cutnum=-1; + QString code; + bool ok=false; + QString err_msg; + + // + // Open the Database + // + rda=new RDApplication("metadata_wildcard_test","metadata_wildcard_test", + METADATA_WILDCARD_TEST_USAGE,this); + if(!rda->open(&err_msg)) { + fprintf(stderr,"metadata_wildcard_test: %s\n",(const char *)err_msg.toUtf8()); + exit(1); + } + for(unsigned i=0;icmdSwitch()->keys();i++) { + if(rda->cmdSwitch()->key(i)=="--cart") { + cartnum=rda->cmdSwitch()->value(i).toUInt(&ok); + if((!ok)||(cartnum==0)||(cartnum>RD_MAX_CART_NUMBER)) { + fprintf(stderr,"metadata_wildcard_test: invalid cart number\n"); + exit(1); + } + rda->cmdSwitch()->setProcessed(i,true); + } + if(rda->cmdSwitch()->key(i)=="--cut") { + cutnum=rda->cmdSwitch()->value(i).toInt(&ok); + if((!ok)||(cutnum<=0)||(cartnum>RD_MAX_CUT_NUMBER)) { + fprintf(stderr,"metadata_wildcard_test: invalid cut number\n"); + exit(1); + } + rda->cmdSwitch()->setProcessed(i,true); + } + if(rda->cmdSwitch()->key(i)=="--code") { + code=rda->cmdSwitch()->value(i); + rda->cmdSwitch()->setProcessed(i,true); + } + if(!rda->cmdSwitch()->processed(i)) { + fprintf(stderr,"metadata_wildcard_test: unknown option \"%s\"\n", + (const char *)rda->cmdSwitch()->value(i)); + exit(256); + } + } + if(cartnum==0) { + fprintf(stderr,"metadata_wildcard_test: you must provide a --cart\n"); + exit(1); + } + if(code.isEmpty()) { + fprintf(stderr,"metadata_wildcard_test: you must provide a --code\n"); + exit(1); + } + + printf("Result: %s\n", + (const char *)RDLogLine::resolveWildcards(cartnum,code,cutnum).toUtf8()); + + exit(0); +} + + +int main(int argc,char *argv[]) +{ + QApplication a(argc,argv,false); + new MainObject(); + return a.exec(); +} diff --git a/tests/metadata_wildcard_test.h b/tests/metadata_wildcard_test.h new file mode 100644 index 00000000..eddae108 --- /dev/null +++ b/tests/metadata_wildcard_test.h @@ -0,0 +1,38 @@ +// metadata_wildcard_test.h +// +// Test the Rivendell multicast receiver routines +// +// (C) Copyright 2018-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 METADATA_WILDCARD_TEST_H +#define METADATA_WILDCARD_TEST_H + +#include + +#include + +#define METADATA_WILDCARD_TEST_USAGE "[options]\n\nTest the Rivendell metadata wildcard routines\n\nOptions are:\n--cart=\n Cart number.\n\n--cut=\n Cut number [optional].\n\n--code=\n Encoded string to resolve.\n" + +class MainObject : public QObject +{ + Q_OBJECT; + public: + MainObject(QObject *parent=0); +}; + + +#endif // METADATA_WILDCARD_TEST_H