Skip to content

Commit

Permalink
Implementated audio_event::get_state() and put_state() (and unit test…
Browse files Browse the repository at this point in the history
…s for same)
  • Loading branch information
Josh Glover committed Apr 2, 2010
1 parent 80701e3 commit 1dcc0cd
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/audio/audio_event.cc
@@ -1,5 +1,6 @@
/*
Copyright (C) 2005 Tyler Nielsen <tyler.nielsen@gmail.com>
Copyright (C) 2010 Josh Glover <jmglov@jmglov.net>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -32,12 +33,14 @@ using audio::audio_event;
// Save time event to file
void audio_event::put_state (base::flat & file) const
{
//TODO Fill this in...
Sample->put_state(file);
}

// load time event from file
bool audio_event::get_state (base::flat & file)
{
//TODO Fill this in...
Sample = new sound();
Sample->get_state(file);

return file.success ();
}
4 changes: 2 additions & 2 deletions src/audio/audio_event.h
Expand Up @@ -49,7 +49,7 @@ namespace audio
*
* @param sample The sample to trigger on
*/
audio_event (const sound *sample): event ()
audio_event (sound *sample): event ()
{
Sample = sample;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace audio

private:
/// time when the event shall be triggered
const sound *Sample;
sound *Sample;
};
}

Expand Down
99 changes: 99 additions & 0 deletions src/audio/test_audio_event.cc
@@ -0,0 +1,99 @@
/*
Copyright (C) 2010 Josh Glover <jmglov@jmglov.net>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell 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 2 of the License, or
(at your option) any later version.
Adonthell 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 Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/**
* @file test/audio/audio_event.cc
* @author Josh Glover <jmglov@jmglov.net>
*
* @brief Unit tests for the audio_event class.
*
*
*/


#include "audio/audio_event.h"
#include "audio/test_sound.h"

#include <gtest/gtest.h>

namespace audio
{
class audio_event_Test : public ::testing::Test {

protected:
audio_event_Test() {
s = new sound_noop("foo.ogg");
ev = new audio_event(s);
}

virtual ~audio_event_Test() {
delete ev;
delete s;
}

// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:

virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
}

virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
}

audio_event *ev;
sound_noop *s;
}; // class{}

TEST_F(audio_event_Test, constructor_Default) {
EXPECT_EQ("foo.ogg", ae->sample()->getfilename());
}

TEST_F(audio_event_Test, put_state_Filename) {
EXPECT_EQ("foo.ogg", ae->sample()->getfilename());

base::flat f;
ae->put_state(f);

sound_noop *s2 = new sound_noop("bar.ogg");
audio_event *ae2 = new audio_event(s2);

EXPECT_EQ("bar.ogg", ae2->sample()->getfilename());

ae2->get_state(f);

EXPECT_EQ("foo.ogg", ae2->sample()->getfilename());

delete ae2;
delete s2;
}

} // namespace{}


int main(int argc, char **argv) {
google::InitGoogleLogging(argv[0]);

::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
20 changes: 1 addition & 19 deletions src/audio/test_sound.cc
Expand Up @@ -28,30 +28,12 @@


#include "audio/sound.h"
#include "audio/test_sound.h"

#include <gtest/gtest.h>

// No-op to allow constructor to succeed
void *audio_open(const char *filename) {
return NULL;
}

namespace audio
{
class sound_noop : public sound {
public:
static void init() {
sound::m_open = audio_open;
}

sound_noop(const std::string &filename) : sound(filename) {}
sound_noop() {}

void * get_sample() { return m_sample; }
int get_channel() { return m_channel; }
bool get_forcedhalt() { return m_forcedhalt; }
};

class sound_Test : public ::testing::Test {

protected:
Expand Down
52 changes: 52 additions & 0 deletions src/audio/test_sound.h
@@ -0,0 +1,52 @@
/*
Copyright (C) 2010 Josh Glover <jmglov@jmglov.net>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell 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 2 of the License, or
(at your option) any later version.
Adonthell 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 Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/**
* @file test/audio/sound.h
* @author Josh Glover <jmglov@jmglov.net>
*
* @brief Defines a sound_noop{} class for unit tests
*
*
*/


#include "audio/sound.h"

// No-op to allow constructor to succeed
void *audio_open(const char *filename) {
return NULL;
}

namespace audio
{
class sound_noop : public sound {
public:
static void init() {
sound::m_open = audio_open;
}

sound_noop(const std::string &filename) : sound(filename) {}
sound_noop() {}

void * get_sample() { return m_sample; }
int get_channel() { return m_channel; }
bool get_forcedhalt() { return m_forcedhalt; }
};
} // namespace{}

0 comments on commit 1dcc0cd

Please sign in to comment.