2024-04-11 Fred Gleason <fredg@paravelsystems.com>

* Added a 'tempdir_test' test harness.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2024-04-11 17:53:25 -04:00
parent 6858a4751a
commit 2619f77eee
5 changed files with 147 additions and 0 deletions

1
.gitignore vendored
View File

@@ -163,6 +163,7 @@ tests/sas_switch_torture
tests/sas_torture
tests/sendmail_test
tests/stringcode_test
tests/tempdir_test
tests/test_hash
tests/test_pam
tests/timeengine_test

View File

@@ -24705,3 +24705,5 @@
2024-04-11 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in 'RDTempDirectory' that failed to remove a temporary
directory after use.
2024-04-11 Fred Gleason <fredg@paravelsystems.com>
* Added a 'tempdir_test' test harness.

View File

@@ -52,6 +52,7 @@ noinst_PROGRAMS = audio_convert_test\
rml_torture_test\
sendmail_test\
stringcode_test\
tempdir_test\
test_hash\
test_pam\
timer_test\
@@ -146,6 +147,9 @@ sendmail_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT5_LIBS@ @MUSICBRAINZ_LIBS@ @IM
dist_stringcode_test_SOURCES = stringcode_test.cpp stringcode_test.h
stringcode_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT5_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
dist_tempdir_test_SOURCES = tempdir_test.cpp tempdir_test.h
tempdir_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT5_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
dist_test_hash_SOURCES = test_hash.cpp test_hash.h
test_hash_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT5_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@

100
tests/tempdir_test.cpp Normal file
View File

@@ -0,0 +1,100 @@
// tempdir_test.cpp
//
// Test the Rivendell string encoder routines.
//
// (C) Copyright 2013-2021 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 <signal.h>
#include <QApplication>
#include <rdcmd_switch.h>
#include "tempdir_test.h"
RDTempDirectory *d_temp_directory=NULL;
void SigHandler(int signo)
{
exit(0);
}
void __Cleanup()
{
printf("__Cleanup() - 1\n");
delete d_temp_directory;
printf("__Cleanup() - 2\n");
}
MainObject::MainObject(QObject *parent)
:QObject(parent)
{
//
// Read Command Options
//
RDCmdSwitch *cmd=new RDCmdSwitch("tempdir_test",TEMPDIR_TEST_USAGE);
for(unsigned i=0;i<cmd->keys();i++) {
if(!cmd->processed(i)) {
fprintf(stderr,"tempdir_test: unknown option \"%s\"\n",
cmd->key(i).toUtf8().constData());
exit(256);
}
}
atexit(__Cleanup);
::signal(SIGINT,SigHandler);
QString err_msg;
d_temp_directory=new RDTempDirectory("tempdir_test");
if(!d_temp_directory->create(&err_msg)) {
fprintf(stderr,"tempdir_test: directory creation failed [%s]\n",
err_msg.toUtf8().constData());
exit(1);
}
printf("created directory \"%s\"...\n",d_temp_directory->path().toUtf8().constData());
WriteFile("file1.txt");
WriteFile("file2.txt");
WriteFile("file3.txt");
}
void MainObject::WriteFile(const QString &filename)
{
FILE *f=NULL;
QString pathname=d_temp_directory->path()+"/"+filename;
if((f=fopen(pathname.toUtf8(),"w"))==NULL) {
fprintf(stderr,"tempdir_test: file creation failed [%s]\n",strerror(errno));
exit(1);
}
fprintf(f,"Hello World!\n");
fclose(f);
printf("created file \"%s\"...\n",pathname.toUtf8().constData());
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new MainObject();
return a.exec();
}

40
tests/tempdir_test.h Normal file
View File

@@ -0,0 +1,40 @@
// tempdir_test.h
//
// Test the Rivendell string encoder routines.
//
// (C) Copyright 2013,2016 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 TEMPDIR_TEST_H
#define TEMPDIR_TEST_H
#include <QObject>
#include <rdtempdirectory.h>
#define TEMPDIR_TEST_USAGE "[options]\n\nTest the Rivendell temporary directory routines in RDTempDirectory\n\n"
class MainObject : public QObject
{
public:
MainObject(QObject *parent=0);
private:
void WriteFile(const QString &filename);
};
#endif // TEMPDIR_TEST_H