[gstreamermm: 112/167] added tests for AppSrc plugin



commit 436b0953849c53f417ab1b0f38add6037527e820
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Thu Aug 1 14:24:54 2013 +0200

    added tests for AppSrc plugin

 tests/plugins/test-plugin-appsrc.cc |   75 +++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/tests/plugins/test-plugin-appsrc.cc b/tests/plugins/test-plugin-appsrc.cc
new file mode 100644
index 0000000..ebbf303
--- /dev/null
+++ b/tests/plugins/test-plugin-appsrc.cc
@@ -0,0 +1,75 @@
+/*
+ * test-plugin-appsrc.cc
+ *
+ *  Created on: Aug 1, 2013
+ *      Author: m.kolny
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/appsrc.h>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+class AppSrcPluginTest : public ::testing::Test
+{
+protected:
+    RefPtr<Element> source_element;
+    RefPtr<Pipeline> pipeline;
+
+    void CreatePipelineWithElements()
+    {
+        RefPtr<Element> sink = Gst::ElementFactory::create_element("fakesink", "sink");
+        source_element = ElementFactory::create_element("appsrc", "source");
+
+        ASSERT_NO_THROW(pipeline->add(source_element)->add(sink));
+        ASSERT_NO_THROW(source_element->link(sink));
+    }
+};
+
+TEST_F(AppSrcPluginTest, CorrectCreatedAppSrcElement)
+{
+    RefPtr<AppSrc> source = AppSrc::create("source");
+    ASSERT_TRUE(source);
+
+    source_element = ElementFactory::create_element("appsrc", "source");
+    ASSERT_TRUE(source_element);
+
+    source = source.cast_dynamic(source_element);
+    ASSERT_TRUE(source);
+}
+
+TEST_F(AppSrcPluginTest, CreatePipelineWithAppSrcElement)
+{
+    CreatePipelineWithElements();
+}
+
+TEST_F(AppSrcPluginTest, SimpleDataFlowInPipelineWitAppSrcElement)
+{
+    pipeline->set_state(Gst::STATE_PLAYING);
+
+    std::string data = "hello world";
+    RefPtr<Buffer> buf = Buffer::create(data.length() + 1);
+    RefPtr<MapInfo> mapinfo(new Gst::MapInfo());
+    buf->map(mapinfo, Gst::MapFlags());
+    strcpy((char *)mapinfo->get_data(), data.c_str());
+
+    RefPtr<AppSrc> appsrc;
+    appsrc = appsrc.cast_dynamic(source_element);
+    appsrc->push_buffer(buf);
+
+    {
+        State state;
+        StateChangeReturn ret=pipeline->get_state(state, state, 1*SECOND);
+        ASSERT_EQ(ret, STATE_CHANGE_SUCCESS);
+    }
+
+    appsrc->end_of_stream();
+
+    RefPtr<Gst::Message> msg = pipeline->get_bus()->poll((Gst::MessageType)(Gst::MESSAGE_EOS | 
Gst::MESSAGE_ERROR) , 1*Gst::SECOND);
+    ASSERT_TRUE(msg);
+    ASSERT_EQ(msg->get_message_type(), Gst::MESSAGE_EOS);
+    pipeline->set_state(Gst::STATE_NULL);
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]