diff --git a/sflphone-common/src/audio/sound/audiofile.cpp b/sflphone-common/src/audio/sound/audiofile.cpp index fbdd3bcfd24ffc98b5c12f038ac7bd3ab67cb66d..9bde16aea379a854e4fcc092b920a4bb01e6a3c9 100644 --- a/sflphone-common/src/audio/sound/audiofile.cpp +++ b/sflphone-common/src/audio/sound/audiofile.cpp @@ -191,7 +191,23 @@ WavFile::~WavFile() } -bool WavFile::loadFile (const std::string& filename, AudioCodec* codec , unsigned int sampleRate) { +bool WavFile::isFileExist(const std::string& filename) +{ + + std::fstream fs(filename.c_str(), std::ios_base::in); + if(!fs) { + _debug("WavFile: File \"%s\" doesn't exist", filename.c_str()); + return false; + } + + return true; + +} + +bool WavFile::loadFile (const std::string& filename, AudioCodec* codec , unsigned int sampleRate) +{ + if(!isFileExist(filename)) + return false; std::fstream file; @@ -274,6 +290,7 @@ bool WavFile::loadFile (const std::string& filename, AudioCodec* codec , unsigne else if (dt == 32) _dataType = 3; // SINT32; } + /* else if ( formatTag == 3 ) { diff --git a/sflphone-common/src/audio/sound/audiofile.h b/sflphone-common/src/audio/sound/audiofile.h index ed3d0f9ac84e5e72889cc2248663caf88487b555..cb96561ff2b6f3a748d830442ffa72de9cedfc64 100644 --- a/sflphone-common/src/audio/sound/audiofile.h +++ b/sflphone-common/src/audio/sound/audiofile.h @@ -155,6 +155,8 @@ private: // Assignment Operator WavFile& operator=( const AudioFile& rh); + bool isFileExist(const std::string& filename); + /** The absolute path to the sound file */ std::string _filename; diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index 9da8e2f60349f9304800235277ac1158142b6d92..41ab80fea2453830f84bd5d492b22f7165d03d5a 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -26,7 +26,9 @@ test_SOURCES = \ rtptest.h \ rtptest.cpp \ sdesnegotiatortest.h \ - sdesnegotiatortest.cpp + sdesnegotiatortest.cpp \ + ringtonetest.h \ + ringtonetest.cpp LLIBS=$(CPPUNIT_LIBS) \ ../src/sflphoned-logger.o \ diff --git a/sflphone-common/test/ringtonetest.cpp b/sflphone-common/test/ringtonetest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49501d2f576747ba753b75e1035b5855fcb35796 --- /dev/null +++ b/sflphone-common/test/ringtonetest.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#include "ringtonetest.h" + +void RingtoneTest::testLoadWavefile() +{ + WavFile *wav = new WavFile(); + + // Test initial values + CPPUNIT_ASSERT(wav->isStarted() == false); + CPPUNIT_ASSERT(wav->getSize() == 0); + + // Test protection against wrong file name + CPPUNIT_ASSERT(wav->loadFile(std::string("wrongfilename.wav"), NULL, 44100) == false); + + + + delete wav; wav = NULL; +} diff --git a/sflphone-common/test/ringtonetest.h b/sflphone-common/test/ringtonetest.h new file mode 100644 index 0000000000000000000000000000000000000000..bef2e16662626648dde785a22e17e7652c73c6f4 --- /dev/null +++ b/sflphone-common/test/ringtonetest.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +/* + * @file ringtonetest.cpp + * @brief Regroups unitary tests related to the ringtones. + * Check if the wave file has been successfully loaded + */ + +#ifndef _RINGTONE_TEST_ +#define _RINGTONE_TEST_ + +// Cppunit import +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestCase.h> +#include <cppunit/TestSuite.h> + +#include <assert.h> + +// Application import +#include "manager.h" +#include "audio/sound/audiofile.h" +#include "global.h" +#include "user_cfg.h" + +class RingtoneTest: public CppUnit::TestFixture { + + /* + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE( RingtoneTest ); + CPPUNIT_TEST( testLoadWavefile ); + CPPUNIT_TEST_SUITE_END(); + +public: + /* + * Unit tests related to the audio preferences + */ + void testLoadWavefile(); + +}; +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RingtoneTest, "RingtoneTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( RingtoneTest ); + +#endif diff --git a/sflphone-common/test/waveSample/M1F1-int16WE-AFsp.wav b/sflphone-common/test/waveSample/M1F1-int16WE-AFsp.wav new file mode 100644 index 0000000000000000000000000000000000000000..6df1c305809b5cee7a8fa4b07e28ee4dcbe524cb Binary files /dev/null and b/sflphone-common/test/waveSample/M1F1-int16WE-AFsp.wav differ