[gstreamermm: 140/167] added test - create custom bin, and check how does it works



commit e89b31204ea19563a31aed9ff13cfed3da9a3e82
Author: Marcin Kolny [loganek] <marcin kolny gmail com>
Date:   Tue Aug 6 00:53:14 2013 +0200

    added test - create custom bin, and check how does it works

 .gitignore                                        |    4 +
 tests/Makefile.am                                 |    4 +-
 tests/regression/test-regression-bininpipeline.cc |  103 +++++++++++++++++++++
 tests/resources/input-image.png                   |  Bin 0 -> 2578 bytes
 4 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 2f0a742..b79b74f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -479,10 +479,14 @@ test-plugin-appsrc
 test-plugin-pushsrc
 test-plugin-register
 
+test-regression-bininpipeline
 test-regression-rewritefile
 test-regression-seekonstartup
 test-regression-videoduration
 
+#tests/resources/
+tests/resources/test-regression-bininpipeline-output-image.jpg
+
 # tools/
 /tools/extra_defs_gen/generate_defs_gst
 /tools/extra_defs_gen/generate_plugin_gmmproc_file
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7a8f368..68d9c08 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,8 @@ LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm) -lgtest
 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-plugin-appsrc test-plugin-register test-plugin-pushsrc \ 
+                 test-regression-bininpipeline \
                  test-regression-rewritefile test-regression-seekonstartup \
                  test-regression-videoduration
 
@@ -46,6 +47,7 @@ test_plugin_appsrc_SOURCES                    = plugins/test-plugin-appsrc.cc 
$(TEST_MAIN_SOURCE)
 test_plugin_pushsrc_SOURCES                    = plugins/test-plugin-pushsrc.cc $(TEST_MAIN_SOURCE)
 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_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/test-regression-bininpipeline.cc 
b/tests/regression/test-regression-bininpipeline.cc
new file mode 100644
index 0000000..11c6e7f
--- /dev/null
+++ b/tests/regression/test-regression-bininpipeline.cc
@@ -0,0 +1,103 @@
+/*
+ * test-regression-bininpipeline.cc
+ *
+ *  Created on: 5 sie 2013
+ *      Author: loganek
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/filesrc.h>
+#include <gstreamermm/filesink.h>
+#include <glibmm.h>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+class CustomBin : public Bin
+{
+private:
+    RefPtr<FileSrc> source_file;
+    RefPtr<Element> png_decoder;
+    RefPtr<GhostPad> src_pad;
+protected:
+    explicit CustomBin(const Glib::ustring& name)
+    : Bin(name)
+    {
+        source_file = FileSrc::create("source-file");
+        png_decoder = ElementFactory::create_element("pngdec");
+
+        add(source_file);
+        add(png_decoder);
+        source_file->link(png_decoder);
+
+        src_pad = add_ghost_pad(png_decoder, "src", "src");
+        src_pad->set_active(true);
+    }
+public:
+    virtual ~CustomBin() {}
+
+    static RefPtr<CustomBin> create(const Glib::ustring& name)
+    {
+        return RefPtr<CustomBin>(new CustomBin(name));
+    }
+
+    void set_location(const Glib::ustring& filename)
+    {
+        source_file->property_location() = filename;
+    }
+};
+
+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(BinInPipelineRegressionTest, 
CustomBinShouldCorrectEncodeImageAndOtherElementsShouldEncodeItToJPGAndWriteToFile)
+{
+    Glib::ustring input_png = "resources/input-image.png",
+            output_jpg = "resources/test-regression-bininpipeline-output-image.jpg";
+
+    mainloop = Glib::MainLoop::create();
+    ASSERT_TRUE(mainloop);
+    RefPtr<CustomBin> custom_bin = CustomBin::create("file-png-decoder");
+    ASSERT_TRUE(custom_bin);
+    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(custom_bin);
+
+    ASSERT_NO_THROW(pipeline->add(custom_bin)->add(jpg_encoder)->add(file_sink));
+    ASSERT_NO_THROW(custom_bin->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));
+
+    custom_bin->set_location(input_png);
+
+    file_sink->property_location() = output_jpg;
+
+    pipeline->set_state(STATE_PLAYING);
+    mainloop->run();
+
+    pipeline->set_state(Gst::STATE_NULL);
+}
diff --git a/tests/resources/input-image.png b/tests/resources/input-image.png
new file mode 100644
index 0000000..01af2a7
Binary files /dev/null and b/tests/resources/input-image.png differ


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