Skip to content
Snippets Groups Projects
Commit 1db18330 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3757] Add unit test for loading a wavefile

parent 7137ce6f
Branches
Tags
No related merge requests found
...@@ -191,7 +191,23 @@ WavFile::~WavFile() ...@@ -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; std::fstream file;
...@@ -274,6 +290,7 @@ bool WavFile::loadFile (const std::string& filename, AudioCodec* codec , unsigne ...@@ -274,6 +290,7 @@ bool WavFile::loadFile (const std::string& filename, AudioCodec* codec , unsigne
else if (dt == 32) else if (dt == 32)
_dataType = 3; // SINT32; _dataType = 3; // SINT32;
} }
/* /*
else if ( formatTag == 3 ) else if ( formatTag == 3 )
{ {
......
...@@ -155,6 +155,8 @@ private: ...@@ -155,6 +155,8 @@ private:
// Assignment Operator // Assignment Operator
WavFile& operator=( const AudioFile& rh); WavFile& operator=( const AudioFile& rh);
bool isFileExist(const std::string& filename);
/** The absolute path to the sound file */ /** The absolute path to the sound file */
std::string _filename; std::string _filename;
......
...@@ -26,7 +26,9 @@ test_SOURCES = \ ...@@ -26,7 +26,9 @@ test_SOURCES = \
rtptest.h \ rtptest.h \
rtptest.cpp \ rtptest.cpp \
sdesnegotiatortest.h \ sdesnegotiatortest.h \
sdesnegotiatortest.cpp sdesnegotiatortest.cpp \
ringtonetest.h \
ringtonetest.cpp
LLIBS=$(CPPUNIT_LIBS) \ LLIBS=$(CPPUNIT_LIBS) \
../src/sflphoned-logger.o \ ../src/sflphoned-logger.o \
......
/*
* 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;
}
/*
* 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
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment