[gstreamermm: 133/167] added first regression test



commit f593f80cfc1215da52046782d1cfcf06e27f0938
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Mon Aug 5 10:14:44 2013 +0200

    added first regression test

 .gitignore                                      |    2 +
 examples/ogg_rewriter/main.cc                   |    2 +-
 tests/Makefile.am                               |    6 ++-
 tests/regression/test-regression-rewritefile.cc |   73 +++++++++++++++++++++
 tests/regression/utils.cc                       |   80 +++++++++++++++++++++++
 tests/regression/utils.h                        |   16 +++++
 6 files changed, 177 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 50d1b2b..b8e0859 100644
--- a/.gitignore
+++ b/.gitignore
@@ -479,6 +479,8 @@ test-plugin-appsrc
 test-plugin-pushsrc
 test-plugin-register
 
+test-regression-rewritefile
+
 # tools/
 /tools/extra_defs_gen/generate_defs_gst
 /tools/extra_defs_gen/generate_plugin_gmmproc_file
diff --git a/examples/ogg_rewriter/main.cc b/examples/ogg_rewriter/main.cc
index 6a18211..138031a 100644
--- a/examples/ogg_rewriter/main.cc
+++ b/examples/ogg_rewriter/main.cc
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
 
   if(!filesrc)
   {
-    std::cerr << "The playbin2 element could not be created." << std::endl;
+    std::cerr << "The FileSrc element could not be created." << std::endl;
     return EXIT_FAILURE;
   }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8238f99..1e34858 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,11 +23,13 @@ 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-rewritefile
 
 # Include run of test programs in check:
 TESTS = $(check_PROGRAMS)
 TEST_MAIN_SOURCE = main.cc
+TEST_REGRESSION_UTILS = regression/utils.cc
 
 test_caps_SOURCES                      = test-caps.cc $(TEST_MAIN_SOURCE)
 test_buffer_SOURCES                    = test-buffer.cc $(TEST_MAIN_SOURCE)
@@ -42,3 +44,5 @@ test_plugin_appsink_SOURCES                   = plugins/test-plugin-appsink.cc 
$(TEST_MAIN_SOURC
 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_rewritefile_SOURCES = regression/test-regression-rewritefile.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
diff --git a/tests/regression/test-regression-rewritefile.cc b/tests/regression/test-regression-rewritefile.cc
new file mode 100644
index 0000000..41935fa
--- /dev/null
+++ b/tests/regression/test-regression-rewritefile.cc
@@ -0,0 +1,73 @@
+/*
+ * test-rewritefile.cc
+ *
+ *  Created on: Aug 5, 2013
+ *      Author: m.kolny
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <glibmm.h>
+#include <cstdio>
+#include "utils.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 Gst::MESSAGE_EOS:
+            mainloop->quit();
+            return false;
+        case Gst::MESSAGE_ERROR:
+        {
+            mainloop->quit();
+            return false;
+        }
+        default:
+            break;
+    }
+
+    return true;
+}
+
+TEST(RegressionRewriteFileTest, CreateAndRewriteFile)
+{
+    Glib::ustring input_filename = "test.ogg",
+            output_filename = "output.ogg";
+
+    GenerateSampleOggFile(20, input_filename);
+
+    Glib::RefPtr<Gst::Pipeline> pipeline;
+    RefPtr<FileSrc> filesrc = Gst::FileSrc::create();
+    ASSERT_TRUE(filesrc);
+
+    filesrc->property_location() = input_filename;
+
+    mainloop = Glib::MainLoop::create();
+    pipeline = Gst::Pipeline::create("rewriter");
+    Glib::RefPtr<Gst::FileSink> filesink = Gst::FileSink::create();
+    ASSERT_TRUE(filesink);
+
+    filesink->property_location() = output_filename;
+
+    Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus();
+    bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+    pipeline->add(filesrc)->add(filesink);
+
+    pipeline->set_state(Gst::STATE_PLAYING);
+    filesrc->link(filesink);
+    mainloop->run();
+
+    pipeline->set_state(Gst::STATE_NULL);
+
+    EXPECT_TRUE(FilesEqual(input_filename, output_filename));
+
+    remove(input_filename.c_str());
+    remove(output_filename.c_str());
+}
diff --git a/tests/regression/utils.cc b/tests/regression/utils.cc
new file mode 100644
index 0000000..95308dc
--- /dev/null
+++ b/tests/regression/utils.cc
@@ -0,0 +1,80 @@
+/*
+ * utils.cc
+ *
+ *  Created on: Aug 5, 2013
+ *      Author: m.kolny
+ */
+
+#include <gstreamermm.h>
+#include <gstreamermm/videotestsrc.h>
+#include <gstreamermm/filesink.h>
+#include <glibmm.h>
+#include "utils.h"
+
+using Glib::RefPtr;
+using namespace Gst;
+using namespace std;
+
+RefPtr<Glib::MainLoop> utils_mainloop;
+
+bool utils_on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message)
+{
+    switch(message->get_message_type())
+    {
+        case Gst::MESSAGE_EOS:
+            utils_mainloop->quit();
+            return false;
+        case Gst::MESSAGE_ERROR:
+        {
+            utils_mainloop->quit();
+            return false;
+        }
+        default:
+            break;
+  }
+
+  return true;
+}
+
+void GenerateSampleOggFile(int num_buffers, const Glib::ustring& filename)
+{
+    RefPtr<Pipeline> pipeline = Pipeline::create("create-ogg");
+    RefPtr<VideoTestSrc> source = VideoTestSrc::create("testsource");
+    RefPtr<Element> encoder = ElementFactory::create_element("theoraenc"),
+            muxer = ElementFactory::create_element("oggmux");
+    RefPtr<FileSink> sink = FileSink::create("fsink");
+    //RefPtr<Element> sink = ElementFactory::create_element("xvimagesink");
+
+    Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus();
+    bus->add_watch(sigc::ptr_fun(&utils_on_bus_message));
+
+    utils_mainloop = Glib::MainLoop::create();
+
+    pipeline->add(source)->add(encoder)->add(muxer)->add(sink);
+
+    source->property_num_buffers() = num_buffers;
+    sink->property_location() = filename;
+
+    muxer->link(sink);
+    source->link(encoder);
+    encoder->link(muxer);
+
+    pipeline->set_state(Gst::STATE_PLAYING);
+
+    utils_mainloop->run();
+    pipeline->set_state(Gst::STATE_NULL);
+}
+
+bool FilesEqual(const string& filename1, const string& filename2)
+{
+    std::ifstream f1(filename1, ios::binary),
+            f2(filename2, ios::binary);
+
+    string buf(istreambuf_iterator<char>(f1),
+                (istreambuf_iterator<char>()));
+
+    return equal(buf.begin(), buf.end(),
+            string(istreambuf_iterator<char>(f2),
+                    (istreambuf_iterator<char>())).begin());
+}
+
diff --git a/tests/regression/utils.h b/tests/regression/utils.h
new file mode 100644
index 0000000..d92a757
--- /dev/null
+++ b/tests/regression/utils.h
@@ -0,0 +1,16 @@
+/*
+ * utils.h
+ *
+ *  Created on: Aug 5, 2013
+ *      Author: m.kolny
+ */
+
+#ifndef UTILS_H_
+#define UTILS_H_
+
+#include <gstreamermm.h>
+#include <fstream>
+
+void GenerateSampleOggFile(int num_buffers, const Glib::ustring& filename);
+bool FilesEqual(const std::string& filename1, const std::string& filename2);
+#endif /* UTILS_H_ */


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