[gstreamermm: 111/167] added tests for registering plugins
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm: 111/167] added tests for registering plugins
- Date: Tue, 3 Sep 2013 19:28:24 +0000 (UTC)
commit 4eefafb8be411e09a22e5bba8fba4910b30d05e9
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date: Thu Aug 1 13:33:54 2013 +0200
added tests for registering plugins
tests/plugins/test-foo.h | 67 ++++++++++++++++++++++++
tests/plugins/test-plugin-register.cc | 91 +++++++++++++++++++++++++++++++++
2 files changed, 158 insertions(+), 0 deletions(-)
---
diff --git a/tests/plugins/test-foo.h b/tests/plugins/test-foo.h
new file mode 100644
index 0000000..7175843
--- /dev/null
+++ b/tests/plugins/test-foo.h
@@ -0,0 +1,67 @@
+/*
+ * test-foo.h
+ *
+ * Created on: Aug 1, 2013
+ * Author: m.kolny
+ */
+
+#ifndef TEST_FOO_H_
+#define TEST_FOO_H_
+
+#include <gstreamermm.h>
+#include <gstreamermm/private/element_p.h>
+#include <assert.h>
+
+using namespace Gst;
+
+class Foo : public Element
+{
+ Glib::RefPtr<Pad> sinkpad;
+ Glib::RefPtr<Pad> srcpad;
+
+public:
+ static void base_init(BaseClassType *klass)
+ {
+ /* This is another hack.
+ * For now it uses pure C functions, which should be wrapped then.
+ */
+ gst_element_class_set_details_simple(klass, "foo_longname",
+ "foo_classification", "foo_detail_description", "foo_detail_author");
+
+ gst_element_class_add_pad_template(klass,
+ Gst::PadTemplate::create("sink", Gst::PAD_SINK, Gst::PAD_ALWAYS,
+ Gst::Caps::create_any())->gobj());
+ gst_element_class_add_pad_template(klass,
+ Gst::PadTemplate::create("src", Gst::PAD_SRC, Gst::PAD_ALWAYS,
+ Gst::Caps::create_any())->gobj());
+ }
+
+ FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, Glib::RefPtr<Gst::Buffer> &buf)
+ {
+ buf = buf->create_writable();
+ assert(buf->gobj()->mini_object.refcount==1);
+ Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+ buf->map(mapinfo, Gst::MAP_WRITE);
+ std::sort(mapinfo->get_data(), mapinfo->get_data() + mapinfo->get_size());
+ buf->unmap(mapinfo);
+ assert(buf->gobj()->mini_object.refcount==1);
+ return srcpad->push(buf);
+ }
+
+ explicit Foo(GstElement *gobj)
+ : Gst::Element(gobj)
+ {
+ add_pad(sinkpad = Gst::Pad::create(get_pad_template("sink"), "sink"));
+ add_pad(srcpad = Gst::Pad::create(get_pad_template("src"), "src"));
+ sinkpad->set_chain_function(sigc::mem_fun(*this, &Foo::chain));
+ }
+
+ static bool register_foo(Glib::RefPtr<Gst::Plugin> plugin)
+ {
+ ElementFactory::register_element(plugin, "foomm", 10, register_mm_type<Foo>("foomm"));
+
+ return true;
+ }
+};
+
+#endif /* TEST_FOO_H_ */
diff --git a/tests/plugins/test-plugin-register.cc b/tests/plugins/test-plugin-register.cc
new file mode 100644
index 0000000..4fb0104
--- /dev/null
+++ b/tests/plugins/test-plugin-register.cc
@@ -0,0 +1,91 @@
+/*
+ * test-plugin-register.cc
+ *
+ * Created on: Aug 1, 2013
+ * Author: m.kolny
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/appsink.h>
+#include <gstreamermm/appsrc.h>
+#include <vector>
+#include "test-foo.h"
+
+using namespace Gst;
+using Glib::RefPtr;
+
+class RegisterPluginTest : public ::testing::Test
+{
+protected:
+ RefPtr<AppSrc> source;
+ RefPtr<Element> filter;
+ RefPtr<AppSink> sink;
+ RefPtr<Gst::Pipeline> pipeline;
+
+ virtual void SetUp()
+ {
+ Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "foo",
+ "foo is example of C++ element", sigc::ptr_fun(&Foo::register_foo), "0.123",
+ "LGPL", "source?", "package?", "http://example.com");
+ }
+
+ void CreatePipelineWithElements()
+ {
+ pipeline = Gst::Pipeline::create("my-pipeline");
+
+ source = AppSrc::create("source");
+ filter = ElementFactory::create_element("foomm", "filter");
+ sink = AppSink::create("sink");
+
+ ASSERT_TRUE(source);
+ ASSERT_TRUE(filter);
+ ASSERT_TRUE(sink);
+
+ EXPECT_NO_THROW(pipeline->add(source)->add(filter)->add(sink));
+ EXPECT_NO_THROW(source->link(filter)->link(sink));
+ }
+};
+
+TEST_F(RegisterPluginTest, CreateRegisteredElement)
+{
+ filter = Gst::ElementFactory::create_element("foomm", "filter");
+
+ ASSERT_TRUE(filter);
+}
+
+TEST_F(RegisterPluginTest, CreatePipelineWithRegisteredElement)
+{
+ CreatePipelineWithElements();
+}
+
+TEST_F(RegisterPluginTest, CheckDataFlowThroughCreatedElement)
+{
+ CreatePipelineWithElements();
+
+ pipeline->set_state(STATE_PLAYING);
+
+ std::vector<guint8> data = {4, 5, 2, 7, 1};
+ RefPtr<Buffer> buf = Buffer::create(data.size());
+ RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+
+ buf->map(mapinfo, MAP_WRITE);
+ std::copy(data.begin(), data.end(), mapinfo->get_data());
+ source->push_buffer(buf);
+ buf->unmap(mapinfo);
+
+ RefPtr<Gst::Buffer> buf_out;
+ RefPtr<Gst::Sample> samp = sink->pull_preroll();
+
+ buf_out = samp->get_buffer();
+ buf_out->map(mapinfo, MAP_READ);
+ ASSERT_TRUE(mapinfo->get_data());
+ std::sort(data.begin(), data.end());
+ ASSERT_TRUE(std::equal(data.begin(), data.end(), mapinfo->get_data()));
+ buf_out->unmap(mapinfo);
+ source->end_of_stream();
+
+ pipeline->set_state(Gst::STATE_NULL);
+ pipeline.reset();
+ filter.reset();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]