From dac2f489c7c3243cb8db1e3e57b736ed021bdff9 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 2 Aug 2016 15:19:16 -0400 Subject: [PATCH] 2016-08-02 Fred Gleason * Added wav_chunk_test(1) in 'tests/wav_chunk_test/'. --- .gitignore | 1 + ChangeLog | 2 + tests/Makefile.am | 7 +- tests/wav_chunk_test.cpp | 169 +++++++++++++++++++++++++++++++++++++++ tests/wav_chunk_test.h | 44 ++++++++++ 5 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 tests/wav_chunk_test.cpp create mode 100644 tests/wav_chunk_test.h diff --git a/.gitignore b/.gitignore index 128a26c0..9f92a11d 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ tests/stringcode_test tests/test_pam tests/timer_test tests/upload_test +tests/wav_chunk_test utils/rdhpiinfo/rdhpiinfo utils/rddgimport/rddgimport utils/rddiscimport/rddiscimport diff --git a/ChangeLog b/ChangeLog index bbc338d3..28707d1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15439,3 +15439,5 @@ * Fixed a bug in 'rdadmin/createdb.cpp' that caused the 'SERVICE_CLOCKS' table to fail to be created when generating a new database. +2016-08-02 Fred Gleason + * Added wav_chunk_test(1) in 'tests/wav_chunk_test/'. diff --git a/tests/Makefile.am b/tests/Makefile.am index b2f89c11..cea921ca 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,7 +40,8 @@ noinst_PROGRAMS = audio_convert_test\ stringcode_test\ test_pam\ timer_test\ - upload_test + upload_test\ + wav_chunk_test dist_audio_convert_test_SOURCES = audio_convert_test.cpp audio_convert_test.h audio_convert_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @@ -81,10 +82,12 @@ dist_timer_test_SOURCES = timer_test.cpp timer_test.h nodist_timer_test_SOURCES = moc_timer_test.cpp timer_test_LDADD = -lqui - dist_upload_test_SOURCES = upload_test.cpp upload_test.h upload_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ +dist_wav_chunk_test_SOURCES = wav_chunk_test.cpp wav_chunk_test.h +wav_chunk_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ + EXTRA_DIST = rivendell_standard.txt\ visualtraffic.txt diff --git a/tests/wav_chunk_test.cpp b/tests/wav_chunk_test.cpp new file mode 100644 index 00000000..3e97fc9a --- /dev/null +++ b/tests/wav_chunk_test.cpp @@ -0,0 +1,169 @@ +// wav_chunk_test.cpp +// +// Test Rivendell file uploading. +// +// (C) Copyright 2010,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. +// + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "wav_chunk_test.h" + +MainObject::MainObject(QObject *parent) + :QObject(parent) +{ + file_fd=-1; + payload_length=0; + chunk_length=0; + + QString filename; + char buffer[1024]; + + // + // Read Command Options + // + RDCmdSwitch *cmd= + new RDCmdSwitch(qApp->argc(),qApp->argv(),"wav_chunk_test", + WAV_CHUNK_TEST_USAGE); + for(unsigned i=0;ikeys();i++) { + if(cmd->key(i)=="--filename") { + filename=cmd->value(i); + cmd->setProcessed(i,true); + } + if(!cmd->processed(i)) { + fprintf(stderr,"wav_chunk_test: invalid option\n"); + exit(256); + } + } + if(filename.isEmpty()) { + fprintf(stderr,"wav_chunk_test: missing filename\n"); + exit(256); + } + + // + // Open File + // + if((file_fd=open(filename,O_RDONLY))<0) { + fprintf(stderr,"wav_chunk_test: unable to open file [%s]\n", + strerror(errno)); + exit(256); + } + + // + // Get File Stats + // + struct stat stat; + memset(&stat,0,sizeof(stat)); + if(fstat(file_fd,&stat)!=0) { + fprintf(stderr,"wav_chunk_test: unable to stat file [%s]\n", + strerror(errno)); + exit(256); + } + file_length=stat.st_size; + + // + // Read Header + // + memset(buffer,0,1024); + if(read(file_fd,buffer,4)!=4) { + fprintf(stderr,"wav_chunk_test: file truncated\n"); + exit(256); + } + if(strncmp(buffer,"RIFF",4)!=0) { + fprintf(stderr,"wav_chunk_test: not a RIFF file\n"); + exit(256); + } + if(read(file_fd,buffer,4)!=4) { + fprintf(stderr,"wav_chunk_test: file truncated\n"); + exit(256); + } + payload_length=((((uint32_t)buffer[3])&0xFF)<<24)+ + ((((uint32_t)buffer[2])&0xFF)<<16)+ + ((((uint32_t)buffer[1])&0xFF)<<8)+ + ((((uint32_t)buffer[0])&0xFF)<<0); + if(read(file_fd,buffer,4)!=4) { + fprintf(stderr,"wav_chunk_test: file truncated\n"); + exit(256); + } + if(strncmp(buffer,"WAVE",4)!=0) { + fprintf(stderr,"wav_chunk_test: not a WAVE file\n"); + exit(256); + } + printf(" File Length: %u\n",file_length); + printf(" Payload Length: %u\n",payload_length); + if(file_length!=(payload_length+8)) { + printf("WARNING: Payload and file sizes disagree!\n"); + } + + // + // Enumerate Chunks + // + QString name; + uint32_t start_pos; + while((start_pos=NextChunk(name,&chunk_length))>0) { + printf("Chunk: %s Start: %u Length: %u\n",(const char *)name,start_pos,chunk_length); + lseek(file_fd,chunk_length,SEEK_CUR); + } + + // + // Clean Up + // + close(file_fd); + exit(0); +} + + +uint32_t MainObject::NextChunk(QString &name,uint32_t *len) +{ + char buffer[8]; + uint32_t pos; + + if((pos=lseek(file_fd,0,SEEK_CUR))>file_length) { + printf("WARNING: chunk size points beyond end of file!\n"); + return 0; + } + + if(read(file_fd,buffer,8)!=8) { + return 0; + } + *len=((((uint32_t)buffer[7])&0xFF)<<24)+ + ((((uint32_t)buffer[6])&0xFF)<<16)+ + ((((uint32_t)buffer[5])&0xFF)<<8)+ + ((((uint32_t)buffer[4])&0xFF)<<0); + buffer[4]=0; + name=buffer; + + return pos; +} + + +int main(int argc,char *argv[]) +{ + QApplication a(argc,argv,false); + new MainObject(); + return a.exec(); +} diff --git a/tests/wav_chunk_test.h b/tests/wav_chunk_test.h new file mode 100644 index 00000000..216f746c --- /dev/null +++ b/tests/wav_chunk_test.h @@ -0,0 +1,44 @@ +// wav_chunk_test.h +// +// Check consistency of chunk layout in a WAV file +// +// (C) Copyright 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 WAV_CHUNK_TEST_H +#define WAV_CHUNK_TEST_H + +#include + +#include + +#define WAV_CHUNK_TEST_USAGE "--filename=\n\n" + +class MainObject : public QObject +{ + public: + MainObject(QObject *parent=0); + + private: + uint32_t NextChunk(QString &name,uint32_t *len); + int file_fd; + uint32_t file_length; + uint32_t payload_length; + uint32_t chunk_length; +}; + + +#endif // WAV_CHUNK_TEST_H