added another test to check event listening

This commit is contained in:
fgerlits 2005-07-06 15:53:51 +00:00
parent 53893a3e50
commit 0d75c4e499
2 changed files with 103 additions and 7 deletions

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.6 $
Author : $Author: fgerlits $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayerTest.cxx,v $
------------------------------------------------------------------------------*/
@ -506,6 +506,73 @@ GstreamerPlayerTest :: eventListenerTest(void)
}
/*------------------------------------------------------------------------------
* Another, more realistic test of the event listener mechanism.
*----------------------------------------------------------------------------*/
void
GstreamerPlayerTest :: eventListenerOnStopTest(void)
throw (CPPUNIT_NS::Exception)
{
CPPUNIT_ASSERT_NO_THROW(player->initialize());
player->attachListener(this);
// start the first clip
CPPUNIT_ASSERT_NO_THROW(
player->open("file:var/test-short.mp3");
);
CPPUNIT_ASSERT(!player->isPlaying());
CPPUNIT_ASSERT_NO_THROW(
player->start();
);
CPPUNIT_ASSERT(player->isPlaying());
startNewClipFlag = true;
// sleep for a while; in the meantime, onStop() starts the second clip
Ptr<time_duration>::Ref sleepT(new time_duration(seconds(7)));
TimeConversion::sleep(sleepT);
// the second clip should be over by now
CPPUNIT_ASSERT(!player->isPlaying());
player->close();
player->detachListener(this);
player->deInitialize();
}
/*------------------------------------------------------------------------------
* Another, more realistic test of the event listener mechanism.
*----------------------------------------------------------------------------*/
void
GstreamerPlayerTest :: onStop(void)
throw ()
{
if (!startNewClipFlag) {
return;
}
try {
CPPUNIT_ASSERT_NO_THROW(
player->close();
);
CPPUNIT_ASSERT_NO_THROW(
player->open("file:var/test-short.mp3");
);
CPPUNIT_ASSERT(!player->isPlaying());
CPPUNIT_ASSERT_NO_THROW(
player->start();
);
CPPUNIT_ASSERT(player->isPlaying());
} catch (CPPUNIT_NS::Exception &e) {
std::cerr << "Exception in onStop(): " << e.what() << std::endl;
}
startNewClipFlag = false;
}
/*------------------------------------------------------------------------------
* Time how long it takes to open, play and close files.
*----------------------------------------------------------------------------*/

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.7 $
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayerTest.h,v $
------------------------------------------------------------------------------*/
@ -57,11 +57,12 @@ namespace PlaylistExecutor {
/**
* Unit test for the GstreamerPlayer class.
*
* @author $Author: maroy $
* @version $Revision: 1.7 $
* @author $Author: fgerlits $
* @version $Revision: 1.8 $
* @see GstreamerPlayer
*/
class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture,
public AudioPlayerEventListener
{
CPPUNIT_TEST_SUITE(GstreamerPlayerTest);
CPPUNIT_TEST(firstTest);
@ -73,6 +74,7 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(checkErrorConditions);
CPPUNIT_TEST(eventListenerAttachTest);
CPPUNIT_TEST(eventListenerTest);
CPPUNIT_TEST(eventListenerOnStopTest);
CPPUNIT_TEST(openTimeTest);
CPPUNIT_TEST_SUITE_END();
@ -93,6 +95,11 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
timeSteps(const std::string fileName)
throw (CPPUNIT_NS::Exception);
/**
* A flag set to true if onStop() should start playing a new clip.
*/
bool startNewClipFlag;
protected:
@ -168,6 +175,14 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
void
eventListenerTest(void) throw (CPPUNIT_NS::Exception);
/**
* Another, more realistic test of the event listener mechanism.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
eventListenerOnStopTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test how long it takes to open and play files.
*
@ -179,6 +194,14 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
public:
/**
* A virtual destructor, necessary because of onStop().
*/
virtual
~GstreamerPlayerTest(void) throw ()
{
}
/**
* Set up the environment for the test case.
*/
@ -190,6 +213,12 @@ class GstreamerPlayerTest : public CPPUNIT_NS::TestFixture
*/
void
tearDown(void) throw ();
/**
* Event handler for the "player has stopped" event.
*/
virtual void
onStop(void) throw ();
};