Skip to content

Commit

Permalink
2024-04-11 Fred Gleason <[email protected]>
Browse files Browse the repository at this point in the history
	* Added a 'tempdir_test' test harness.

Signed-off-by: Fred Gleason <[email protected]>
  • Loading branch information
ElvishArtisan committed Apr 11, 2024
1 parent 6858a47 commit 2619f77
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24705,3 +24705,5 @@
2024-04-11 Fred Gleason <[email protected]>
* Fixed a bug in 'RDTempDirectory' that failed to remove a temporary
directory after use.
2024-04-11 Fred Gleason <[email protected]>
* Added a 'tempdir_test' test harness.
4 changes: 4 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ noinst_PROGRAMS = audio_convert_test\
rml_torture_test\
sendmail_test\
stringcode_test\
tempdir_test\
test_hash\
test_pam\
timer_test\
Expand Down Expand Up @@ -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@

Expand Down
100 changes: 100 additions & 0 deletions tests/tempdir_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// tempdir_test.cpp
//
// Test the Rivendell string encoder routines.
//
// (C) Copyright 2013-2021 Fred Gleason <[email protected]>
//
// 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 changes: 40 additions & 0 deletions tests/tempdir_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// tempdir_test.h
//
// Test the Rivendell string encoder routines.
//
// (C) Copyright 2013,2016 Fred Gleason <[email protected]>
//
// 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

0 comments on commit 2619f77

Please sign in to comment.