2025-04-29 Fred Gleason <fredg@paravelsystems.com>

* Cleaned up deprecation warnings in 'lib/rdhash.cpp'.
	* Added a 'sha1_test' test harness in 'tests/'.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2025-04-29 14:46:57 -04:00
parent edaaca80cd
commit 31b79ae952
7 changed files with 202 additions and 41 deletions

View File

@@ -53,6 +53,7 @@ noinst_PROGRAMS = audio_convert_test\
reserve_carts_test\
rml_torture_test\
sendmail_test\
sha1_test\
stringcode_test\
tempdir_test\
test_hash\
@@ -154,6 +155,10 @@ rml_torture_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@
dist_sendmail_test_SOURCES = sendmail_test.cpp sendmail_test.h
sendmail_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
dist_sha1_test_SOURCES = sha1_test.cpp sha1_test.h
nodist_sha1_test_SOURCES = moc_sha1_test.cpp
sha1_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
dist_stringcode_test_SOURCES = stringcode_test.cpp stringcode_test.h
stringcode_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@

103
tests/sha1_test.cpp Normal file
View File

@@ -0,0 +1,103 @@
// sha1_test.h
//
// Test Rivendell SHA1 methods.
//
// (C) Copyright 2025 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 <stdio.h>
#include <stdlib.h>
#include <QCoreApplication>
#include <rdcmd_switch.h>
#include <rdconf.h>
#include <rdhash.h>
#include "sha1_test.h"
MainObject::MainObject(QObject *parent)
: QObject(parent)
{
QString verify_filename;
QString verify_password;
QString verify_string;
QString verify_hash;
RDCmdSwitch *cmd=new RDCmdSwitch("sha1_test",SHA1_TEST_USAGE);
for(unsigned i=0;i<cmd->keys();i++) {
if(cmd->key(i)=="--verify-hash") {
verify_hash=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--verify-filename") {
verify_filename=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--verify-password") {
verify_password=cmd->value(i);
cmd->setProcessed(i,true);
}
if(cmd->key(i)=="--verify-string") {
verify_string=cmd->value(i);
cmd->setProcessed(i,true);
}
if(!cmd->processed(i)) {
fprintf(stderr,"sha1_test: unknown option\n");
exit(1);
}
}
if(!verify_password.isEmpty()) {
if(verify_hash.isEmpty()) {
QString hash=RDSha1HashPassword(verify_password);
printf("HASH: %s\n",hash.toUtf8().constData());
printf("VERIFIED: %s\n",
RDYesNo(RDSha1HashCheckPassword(verify_password,hash)).
toUtf8().constData());
}
else {
printf("VERIFIED: %s\n",
RDYesNo(RDSha1HashCheckPassword(verify_password,verify_hash)).
toUtf8().constData());
}
exit(0);
}
if(!verify_string.isEmpty()) {
printf("STRING: %s\n",verify_string.toUtf8().constData());
printf("HASH: %s\n",RDSha1HashData(verify_string.toUtf8()).
toUtf8().constData());
exit(0);
}
if(!verify_filename.isEmpty()) {
printf("FILE: %s\n",verify_filename.toUtf8().constData());
printf("HASH: %s\n",RDSha1HashFile(verify_filename.toUtf8()).
toUtf8().constData());
exit(0);
}
exit(0);
}
int main(int argc,char *argv[])
{
QCoreApplication a(argc,argv);
new MainObject();
return a.exec();
}

36
tests/sha1_test.h Normal file
View File

@@ -0,0 +1,36 @@
// sha1_test.h
//
// Test Rivendell SHA1 methods.
//
// (C) Copyright 2025 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 SHA1_TEST_H
#define SHA1_TEST_H
#include <QObject>
#define SHA1_TEST_USAGE "--verify-password=<passwd> --verify-string=<str> --verify-file=<filename> --verify-hash=<sha1-hash>"
class MainObject : public QObject
{
Q_OBJECT
public:
MainObject(QObject *parent=0);
};
#endif // SHA1_TEST_H