added more unit tests

This commit is contained in:
maroy 2005-06-19 16:29:22 +00:00
parent 3d85980181
commit b3914736a4
10 changed files with 138 additions and 49 deletions

View file

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.3 $
# Version : $Revision: 1.4 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/etc/Makefile.in,v $
#
# @configure_input@
@ -139,14 +139,15 @@ SWITCHER_LIB_OBJS = ${TMP_DIR}/smil-util.o \
${TMP_DIR}/switcher.o
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/seek.o \
${TMP_DIR}/util.o \
${TMP_DIR}/seek-pack.o \
${TMP_DIR}/SeekTest.o \
${TMP_DIR}/SwitcherTest.o \
${TMP_DIR}/SeekPackTest.o \
${TMP_DIR}/PartialPlayTest.o \
${TMP_DIR}/OneshotReaderTest.o \
${TMP_DIR}/MinimalAudioSmilTest.o \
${TMP_DIR}/seek.o \
${TMP_DIR}/util.o \
${TMP_DIR}/seek-pack.o
${TMP_DIR}/MinimalAudioSmilTest.o
TEST_RUNNER_LIBS = -l${CORE_LIB} -lcppunit -ldl -lxmlrpc++

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/MinimalAudioSmilTest.cxx,v $
------------------------------------------------------------------------------*/
@ -94,7 +94,7 @@ MinimalAudioSmilTest :: tearDown(void) throw ()
/*------------------------------------------------------------------------------
* Play a SMIL file.
*----------------------------------------------------------------------------*/
void
gint64
MinimalAudioSmilTest :: playSmilFile(const char * smilFile)
throw (CPPUNIT_NS::Exception)
{
@ -102,6 +102,8 @@ MinimalAudioSmilTest :: playSmilFile(const char * smilFile)
GstElement * filesrc;
GstElement * smil;
GstElement * sink;
GstFormat format;
gint64 timePlayed;
/* initialization */
gst_init(0, 0);
@ -122,9 +124,14 @@ MinimalAudioSmilTest :: playSmilFile(const char * smilFile)
gst_element_set_state(pipeline, GST_STATE_PLAYING);
while (gst_bin_iterate(GST_BIN(pipeline)));
format = GST_FORMAT_TIME;
gst_element_query(sink, GST_QUERY_POSITION, &format, &timePlayed);
/* clean up */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return timePlayed;
}
@ -135,7 +142,11 @@ void
MinimalAudioSmilTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
playSmilFile(simpleFile);
gint64 timePlayed;
timePlayed = playSmilFile(simpleFile);
CPPUNIT_ASSERT(timePlayed > 2.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 3.1 * GST_SECOND);
}
@ -146,6 +157,10 @@ void
MinimalAudioSmilTest :: parallelTest(void)
throw (CPPUNIT_NS::Exception)
{
playSmilFile(parallelFile);
gint64 timePlayed;
timePlayed = playSmilFile(parallelFile);
CPPUNIT_ASSERT(timePlayed > 7.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 8.1 * GST_SECOND);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/MinimalAudioSmilTest.h,v $
------------------------------------------------------------------------------*/
@ -58,7 +58,7 @@ namespace GstreamerElements {
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class MinimalAudioSmilTest : public CPPUNIT_NS::TestFixture
{
@ -73,9 +73,10 @@ class MinimalAudioSmilTest : public CPPUNIT_NS::TestFixture
* Play a smil file.
*
* @param smilFile the name of the smil file to play.
* @return the number of milliseconds played.
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
gint64
playSmilFile(const char * smilFile)
throw (CPPUNIT_NS::Exception);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/PartialPlayTest.cxx,v $
------------------------------------------------------------------------------*/
@ -53,7 +53,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PartialPlayTest);
/**
* A test file.
*/
static const char * testFile = "var/1minutecounter.mp3";
static const char * testFile = "var/5seccounter.mp3";
/* =============================================== local function prototypes */
@ -92,7 +92,7 @@ PartialPlayTest :: tearDown(void) throw ()
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
gint64
PartialPlayTest :: playFile(const char * audioFile,
const char * config)
throw (CPPUNIT_NS::Exception)
@ -100,6 +100,8 @@ PartialPlayTest :: playFile(const char * audioFile,
GstElement * pipeline;
GstElement * filter;
GstElement * sink;
GstFormat format;
gint64 timePlayed;
/* initialize GStreamer */
gst_init(0, 0);
@ -124,9 +126,14 @@ PartialPlayTest :: playFile(const char * audioFile,
while (gst_bin_iterate(GST_BIN(pipeline)));
format = GST_FORMAT_TIME;
gst_element_query(sink, GST_QUERY_POSITION, &format, &timePlayed);
/* clean up nicely */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT (pipeline));
return timePlayed;
}
@ -154,7 +161,11 @@ void
PartialPlayTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
playFile(testFile, "3s;10s-13s");
gint64 timePlayed;
timePlayed = playFile(testFile, "2s;1s-4s");
CPPUNIT_ASSERT(timePlayed > 4.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 5.1 * GST_SECOND);
}
@ -165,6 +176,10 @@ void
PartialPlayTest :: openEndedTest(void)
throw (CPPUNIT_NS::Exception)
{
playFile(testFile, "3s;10s-");
gint64 timePlayed;
timePlayed = playFile(testFile, "2s;2s-");
CPPUNIT_ASSERT(timePlayed > 4.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 5.1 * GST_SECOND);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/PartialPlayTest.h,v $
------------------------------------------------------------------------------*/
@ -58,7 +58,7 @@ namespace GstreamerElements {
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class PartialPlayTest : public CPPUNIT_NS::TestFixture
{
@ -74,9 +74,10 @@ class PartialPlayTest : public CPPUNIT_NS::TestFixture
*
* @param audioFile the file to play
* @param config the partial play config to use when playing the file
* @return the number of milliseconds played.
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
gint64
playFile(const char * audioFile,
const char * config)
throw (CPPUNIT_NS::Exception);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/SwitcherTest.cxx,v $
------------------------------------------------------------------------------*/
@ -90,16 +90,16 @@ SwitcherTest :: tearDown(void) throw ()
* Play an audio file
*----------------------------------------------------------------------------*/
gint64
SwitcherTest :: playFile(const char * audioFile,
const char * sourceConfig)
SwitcherTest :: playFiles(const char ** audioFiles,
unsigned int noFiles,
const char * sourceConfig)
throw (CPPUNIT_NS::Exception)
{
GstElement * pipeline;
GstElement * source;
GstElement * decoder;
GstElement * sw;
GstElement * switcher;
GstElement * sink;
unsigned int i;
GstFormat format;
gint64 timePlayed;
@ -108,22 +108,38 @@ SwitcherTest :: playFile(const char * audioFile,
/* create elements */
pipeline = gst_pipeline_new("audio-player");
source = gst_element_factory_make("filesrc", "source");
decoder = gst_element_factory_make("mad", "decoder");
sw = gst_element_factory_make("switch", "sw");
switcher = gst_element_factory_make("switcher", "switcher");
sink = gst_element_factory_make("alsasink", "alsa-output");
/* set filename property on the file source */
g_object_set(G_OBJECT(source), "location", audioFile, NULL);
gst_element_link_many(sw, switcher, sink, NULL);
gst_bin_add_many(GST_BIN(pipeline), sw, switcher, sink, NULL);
for (i = 0; i < noFiles; ++i) {
GstElement * source;
GstElement * decoder;
char str[256];
gboolean ret;
g_snprintf(str, 256, "source_%d", i);
source = gst_element_factory_make("filesrc", str);
CPPUNIT_ASSERT(source);
g_snprintf(str, 256, "decoder_%d", i);
decoder = gst_element_factory_make("mad", str);
CPPUNIT_ASSERT(decoder);
g_object_set(G_OBJECT(source), "location", audioFiles[i], NULL);
ret = gst_element_link_many(source, decoder, sw, NULL);
CPPUNIT_ASSERT(ret);
gst_bin_add_many(GST_BIN(pipeline), source, decoder, NULL);
}
g_object_set(G_OBJECT(switcher), "source-config", sourceConfig, NULL);
/* listen for the eos event on switcher, so the pipeline can be stopped */
g_signal_connect(switcher, "eos", G_CALLBACK(eos_signal_handler), pipeline);
gst_element_link_many(source, decoder, sw, switcher, sink, NULL);
gst_bin_add_many(GST_BIN(pipeline),
source, decoder, sw, switcher, sink, NULL);
gst_element_set_state(sink, GST_STATE_READY);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
@ -166,7 +182,7 @@ SwitcherTest :: firstTest(void)
{
gint64 timePlayed;
timePlayed = playFile(testFile, "0[3s]");
timePlayed = playFiles(&testFile, 1, "0[3s]");
CPPUNIT_ASSERT(timePlayed > 2.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 3.1 * GST_SECOND);
}
@ -181,9 +197,25 @@ SwitcherTest :: openEndedTest(void)
{
gint64 timePlayed;
timePlayed = playFile(testFile, "0[]");
timePlayed = playFiles(&testFile, 1, "0[]");
CPPUNIT_ASSERT(timePlayed > 4.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 5.1 * GST_SECOND);
}
/*------------------------------------------------------------------------------
* Play a file until its end.
*----------------------------------------------------------------------------*/
void
SwitcherTest :: multipleTest(void)
throw (CPPUNIT_NS::Exception)
{
const char * testFiles[2] = { testFile, testFile };
gint64 timePlayed;
timePlayed = playFiles(testFiles, 2, "0[2s];1[2s]");
CPPUNIT_ASSERT(timePlayed > 3.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 4.1 * GST_SECOND);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/SwitcherTest.h,v $
------------------------------------------------------------------------------*/
@ -58,28 +58,31 @@ namespace GstreamerElements {
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class SwitcherTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SwitcherTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(openEndedTest);
CPPUNIT_TEST(multipleTest);
CPPUNIT_TEST_SUITE_END();
private:
/**
* Play a specific file, with a specific switcher configuration.
* Play audio files, with a specific switcher configuration.
*
* @param audioFile the name of the audio file to play.
* @param audioFiles an array of file names to play
* @param noFiles the size of the audioFiles array.
* @param sourceConfig the source config to use.
* @return the number of milliseconds played.
* @exception CPPUNIT_NS::Exception on test failures.
*/
gint64
playFile(const char * audioFile,
const char * sourceConfig)
playFiles(const char ** audioFiles,
unsigned int noFiles,
const char * sourceConfig)
throw (CPPUNIT_NS::Exception);
@ -101,6 +104,14 @@ class SwitcherTest : public CPPUNIT_NS::TestFixture
void
openEndedTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the switcher with multiple inputs.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
multipleTest(void) throw (CPPUNIT_NS::Exception);
public:

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/seek-pack.c,v $
------------------------------------------------------------------------------*/
@ -190,9 +190,14 @@ livesupport_seek_pack_init(LivesupportSeekPack * seekPack,
seekPack->realEndTime = 0LL;
g_value_init(&gvalue, G_TYPE_STRING);
g_snprintf(str, 256, "0[%lfs];1[%lfs]",
seekPack->silenceDuration / NSEC_PER_SEC_FLOAT,
seekPack->duration / NSEC_PER_SEC_FLOAT);
if (seekPack->endTime >= 0) {
g_snprintf(str, 256, "0[%lfs];1[%lfs]",
seekPack->silenceDuration / NSEC_PER_SEC_FLOAT,
seekPack->duration / NSEC_PER_SEC_FLOAT);
} else {
g_snprintf(str, 256, "0[%lfs];1[]",
seekPack->silenceDuration / NSEC_PER_SEC_FLOAT);
}
g_value_set_string(&gvalue, str);
gst_element_set_property(seekPack->switcher, "source-config", &gvalue);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/seek.h,v $
------------------------------------------------------------------------------*/
@ -34,9 +34,13 @@
* Utility functions to help seeking in gstreamer elements.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================ include files */
@ -79,5 +83,9 @@ livesupport_seek_seconds(GstElement * element,
gint64 seconds);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* Seek_h */

View file

@ -2,8 +2,8 @@
<smil xmlns="http://www.w3.org/2001/SMIL20/Language" >
<body>
<par>
<audio src = "file:var/1minutecounter.mp3"
begin = "3s"
<audio src = "file:var/5seccounter.mp3"
begin = "2s"
/>
</par>
</body>