[gstreamermm: 150/167] added test - checking plugin based on a Gst::Bin



commit 8a700618f90039134dc7872db5960d9fba81ecbf
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Thu Aug 8 11:57:32 2013 +0200

    added test - checking plugin based on a Gst::Bin

 .gitignore                                    |    2 +
 tests/Makefile.am                             |    3 +-
 tests/regression/pluginbin.h                  |   75 ++++++++++++++++++++++++
 tests/regression/test-regression-binplugin.cc |   76 +++++++++++++++++++++++++
 4 files changed, 155 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b79b74f..1b39491 100644
--- a/.gitignore
+++ b/.gitignore
@@ -480,12 +480,14 @@ test-plugin-pushsrc
 test-plugin-register
 
 test-regression-bininpipeline
+test-regression-binplugin
 test-regression-rewritefile
 test-regression-seekonstartup
 test-regression-videoduration
 
 #tests/resources/
 tests/resources/test-regression-bininpipeline-output-image.jpg
+tests/resources/test-regression-binplugin-output-image.jpg
 
 # tools/
 /tools/extra_defs_gen/generate_defs_gst
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 68d9c08..55f620b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,7 +24,7 @@ check_PROGRAMS = test-caps test-buffer test-bus test-caps test-pad \
                  test-ghostpad \
                  test-query test-structure test-taglist test-plugin-appsink \
                  test-plugin-appsrc test-plugin-register test-plugin-pushsrc \ 
-                 test-regression-bininpipeline \
+                 test-regression-bininpipeline test-regression-binplugin \
                  test-regression-rewritefile test-regression-seekonstartup \
                  test-regression-videoduration
 
@@ -48,6 +48,7 @@ test_plugin_pushsrc_SOURCES                   = plugins/test-plugin-pushsrc.cc 
$(TEST_MAIN_SOURC
 test_plugin_register_SOURCES           = plugins/test-plugin-register.cc $(TEST_MAIN_SOURCE)
 
 test_regression_bininpipeline_SOURCES = regression/test-regression-bininpipeline.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
+test_regression_binplugin_SOURCES = regression/test-regression-binplugin.cc $(TEST_MAIN_SOURCE) 
 test_regression_rewritefile_SOURCES = regression/test-regression-rewritefile.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
 test_regression_seekonstartup_SOURCES = regression/test-regression-seekonstartup.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
 test_regression_videoduration_SOURCES = regression/test-regression-videoduration.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
diff --git a/tests/regression/pluginbin.h b/tests/regression/pluginbin.h
new file mode 100644
index 0000000..865969f
--- /dev/null
+++ b/tests/regression/pluginbin.h
@@ -0,0 +1,75 @@
+/*
+ * pluginbin.h
+ *
+ *  Created on: 8 sie 2013
+ *      Author: loganek
+ */
+
+#ifndef CUSTOMBIN_H_
+#define CUSTOMBIN_H_
+
+#include <gstreamermm.h>
+#include <gstreamermm/private/bin_p.h>
+#include <gstreamermm/filesrc.h>
+#include <gstreamermm/filesink.h>
+#include <glibmm.h>
+#include <cstdio>
+#include <sys/stat.h>
+
+class PluginBin: public Gst::Bin
+{
+private:
+    Glib::RefPtr<Gst::GhostPad> srcpad;
+    Glib::Property<Glib::ustring> location;
+
+public:
+    static void base_init(BaseClassType *klass)
+    {
+        GstElementClass* element_klass = (GstElementClass*)klass;
+        gst_element_class_set_details_simple(element_klass, "Custom test bin",
+                "test/bins", "test bin", "author");
+    }
+
+    explicit PluginBin(GstBin *gobj)
+    : Glib::ObjectBase(typeid (PluginBin)),
+      Gst::Bin(gobj),
+      location(*this, "location")
+    {
+        add_pad(srcpad = Gst::GhostPad::create( Gst::PadTemplate::create("src", Gst::PAD_SRC, 
Gst::PAD_ALWAYS,
+                                Gst::Caps::create_any()), "src"));
+    }
+
+    static bool register_pluginbin(Glib::RefPtr<Gst::Plugin> plugin)
+    {
+        Gst::ElementFactory::register_element(plugin, "pluginbin", 10,
+                Gst::register_mm_type<PluginBin>("pluginbin"));
+
+        return true;
+    }
+
+    virtual ~PluginBin() { }
+
+    virtual Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition)
+    {
+        if (transition == Gst::STATE_CHANGE_NULL_TO_READY)
+        {
+            Glib::RefPtr<Gst::FileSrc> source_file = Gst::FileSrc::create("source-file");
+            Glib::RefPtr<Gst::Element> png_decoder = Gst::ElementFactory::create_element("pngdec");
+            Glib::ustring str = "resources/input-image.png";
+            source_file->property_location() = location.get_value();
+
+            add(source_file);
+            add(png_decoder);
+            source_file->link(png_decoder);
+
+            srcpad->set_target(png_decoder->get_static_pad("src"));
+        }
+
+        return Bin::change_state_vfunc(transition);
+    }
+
+};
+
+
+
+#endif /* CUSTOMBIN_H_ */
diff --git a/tests/regression/test-regression-binplugin.cc b/tests/regression/test-regression-binplugin.cc
new file mode 100644
index 0000000..779e695
--- /dev/null
+++ b/tests/regression/test-regression-binplugin.cc
@@ -0,0 +1,76 @@
+/*
+ * test-regression-binplugin.cc
+ *
+ *  Created on: 8 sie 2013
+ *      Author: loganek
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <glibmm.h>
+
+#include "pluginbin.h"
+
+using namespace Gst;
+using Glib::RefPtr;
+
+RefPtr<Glib::MainLoop> mainloop;
+
+bool on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message)
+{
+    switch(message->get_message_type())
+    {
+        case MESSAGE_EOS:
+            mainloop->quit();
+            return false;
+        case MESSAGE_ERROR:
+        {
+            mainloop->quit();
+            return false;
+        }
+        default:
+            break;
+    }
+
+    return true;
+}
+
+TEST(BinPluginRegressionTest, ShouldDecodeAndEncodeFile)
+{
+    Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "pluginbin",
+                "pluginbin is example of C++ element", sigc::ptr_fun(&PluginBin::register_pluginbin), "0.1",
+                "LGPL", "source?", "package?", "http://example.com";);
+
+    Glib::ustring input_png = "resources/input-image.png",
+            output_jpg = "resources/test-regression-binplugin-output-image.jpg";
+
+    mainloop = Glib::MainLoop::create();
+    ASSERT_TRUE(mainloop);
+    RefPtr<Element> pluginbin = Gst::ElementFactory::create_element("pluginbin", "sample-pluginbin");
+    ASSERT_TRUE(pluginbin);
+    RefPtr<Element> jpg_encoder = ElementFactory::create_element("jpegenc");
+    ASSERT_TRUE(jpg_encoder);
+    RefPtr<FileSink> file_sink = FileSink::create("file-sink");
+    ASSERT_TRUE(file_sink);
+    RefPtr<Pipeline> pipeline = Pipeline::create("image-converter-pipeline");
+    ASSERT_TRUE(pipeline);
+
+    ASSERT_NO_THROW(pipeline->add(pluginbin)->add(jpg_encoder)->add(file_sink));
+    ASSERT_NO_THROW(pluginbin->link(jpg_encoder)->link(file_sink));
+
+    Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus();
+    ASSERT_TRUE(bus);
+    bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+    pluginbin->set_property("location", input_png);
+    file_sink->property_location() = output_jpg;
+
+    pipeline->set_state(STATE_PLAYING);
+    mainloop->run();
+
+    pipeline->set_state(Gst::STATE_NULL);
+
+    struct stat st;
+    stat(output_jpg.c_str(), &st);
+    ASSERT_TRUE( st.st_size > 0 ); // weak checking
+}


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