From 2619f77eeebbfc11621a886fe5ef7555c3bcec8f Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 11 Apr 2024 17:53:25 -0400 Subject: [PATCH] 2024-04-11 Fred Gleason * Added a 'tempdir_test' test harness. Signed-off-by: Fred Gleason --- .gitignore | 1 + ChangeLog | 2 + tests/Makefile.am | 4 ++ tests/tempdir_test.cpp | 100 +++++++++++++++++++++++++++++++++++++++++ tests/tempdir_test.h | 40 +++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 tests/tempdir_test.cpp create mode 100644 tests/tempdir_test.h diff --git a/.gitignore b/.gitignore index af9fd0ed..7c0e1833 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/ChangeLog b/ChangeLog index e5f207c5..2740bde6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24705,3 +24705,5 @@ 2024-04-11 Fred Gleason * Fixed a bug in 'RDTempDirectory' that failed to remove a temporary directory after use. +2024-04-11 Fred Gleason + * Added a 'tempdir_test' test harness. diff --git a/tests/Makefile.am b/tests/Makefile.am index 4e69daa2..f98cf840 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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@ diff --git a/tests/tempdir_test.cpp b/tests/tempdir_test.cpp new file mode 100644 index 00000000..55d6b918 --- /dev/null +++ b/tests/tempdir_test.cpp @@ -0,0 +1,100 @@ +// tempdir_test.cpp +// +// Test the Rivendell string encoder routines. +// +// (C) Copyright 2013-2021 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 "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;ikeys();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(); +} diff --git a/tests/tempdir_test.h b/tests/tempdir_test.h new file mode 100644 index 00000000..f706480b --- /dev/null +++ b/tests/tempdir_test.h @@ -0,0 +1,40 @@ +// tempdir_test.h +// +// Test the Rivendell string encoder routines. +// +// (C) Copyright 2013,2016 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 TEMPDIR_TEST_H +#define TEMPDIR_TEST_H + +#include + +#include + +#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