2020-02-19 Fred Gleason <fredg@paravelsystems.com>

* 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.
This commit is contained in:
Fred Gleason 2020-02-19 11:52:40 -05:00
parent 4ccf01f029
commit 1a88bcb999
7 changed files with 157 additions and 2 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -19653,3 +19653,7 @@
* Removed the 'RDLabel' widget.
2020-02-19 Fred Gleason <fredg@paravelsystems.com>
* Added a 'Disconnect All Jack Ports' ['JZ'] RML.
2020-02-19 Fred Gleason <fredg@paravelsystems.com>
* 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.

View File

@ -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:

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,99 @@
// metadata_wildcard_test.cpp
//
// Test the Rivendell multicast receiver routines
//
// (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <stdint.h>
#include <stdlib.h>
#include <qapplication.h>
#include <rd.h>
#include <rdapplication.h>
#include <rdcmd_switch.h>
#include <rdlog_line.h>
#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;i<rda->cmdSwitch()->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();
}

View File

@ -0,0 +1,38 @@
// metadata_wildcard_test.h
//
// Test the Rivendell multicast receiver routines
//
// (C) Copyright 2018-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <qobject.h>
#include <rdmulticaster.h>
#define METADATA_WILDCARD_TEST_USAGE "[options]\n\nTest the Rivendell metadata wildcard routines\n\nOptions are:\n--cart=<cart-num>\n Cart number.\n\n--cut=<cut-num>\n Cut number [optional].\n\n--code=<str>\n Encoded string to resolve.\n"
class MainObject : public QObject
{
Q_OBJECT;
public:
MainObject(QObject *parent=0);
};
#endif // METADATA_WILDCARD_TEST_H