[gstreamermm: 127/167] added some functions for testing



commit b3a2a0b6b6e70e52622675f75e107ae03ca4a045
Author: Marcin Kolny [loganek] <marcin kolny gmail com>
Date:   Sat Aug 3 18:16:07 2013 +0200

    added some functions for testing

 gstreamer/gstreamermm.h           |    1 +
 gstreamer/gstreamermm/check.cc    |   80 +++++++++++++++++++++++++++++++++++++
 gstreamer/gstreamermm/check.h     |   74 ++++++++++++++++++++++++++++++++++
 gstreamer/gstreamermm/filelist.am |    1 +
 4 files changed, 156 insertions(+), 0 deletions(-)
---
diff --git a/gstreamer/gstreamermm.h b/gstreamer/gstreamermm.h
index 733cd47..60f9d9e 100644
--- a/gstreamer/gstreamermm.h
+++ b/gstreamer/gstreamermm.h
@@ -58,6 +58,7 @@
  * @endcode
  */
 
+#include <gstreamermm/check.h>
 #include <gstreamermm/init.h>
 #include <gstreamermm/version.h>
 #include <gstreamermm/register.h>
diff --git a/gstreamer/gstreamermm/check.cc b/gstreamer/gstreamermm/check.cc
new file mode 100644
index 0000000..b44aa49
--- /dev/null
+++ b/gstreamer/gstreamermm/check.cc
@@ -0,0 +1,80 @@
+/*
+ * check.cc
+ *
+ *  Created on: 3 sie 2013
+ *      Author: loganek
+ */
+
+#include <gstreamermm/check.h>
+#include <gstreamermm/elementfactory.h>
+#include <algorithm>
+#include <string>
+
+using namespace Gst;
+using Glib::RefPtr;
+using Glib::ustring;
+
+void ThrowIf (bool condition, const ustring& message)
+{
+    if (condition)
+        throw Exception (message);
+}
+
+void ThrowIfNot (bool condition, const ustring& message)
+{
+    if (!condition)
+        throw Exception (message);
+}
+
+template<typename T>
+std::string ToString (const T& obj)
+{
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    return std::to_string(obj);
+#else
+    std::ostringstream convert;
+    convert << obj;
+    return convert.str ();
+#endif
+}
+
+template<typename T>
+void CheckRefCount (T* object, const ustring& name, int expected_refcount)
+{
+    int refcount = GST_OBJECT_REFCOUNT_VALUE (object);
+
+    ThrowIf ((refcount == expected_refcount),
+            name + " refcount is " + ToString(refcount) +
+            " instead of " + ToString(expected_refcount));
+}
+
+RefPtr<Element> Check::_Check::setup_element (const ustring& factory)
+{
+    RefPtr<Element> element;
+
+    element = ElementFactory::create_element (factory, factory);
+
+    ThrowIf (element, "Could not create a '" + factory + "' element");
+    CheckRefCount (element->gobj(), factory, 1);
+
+    return element;
+}
+
+void Check::_Check::caps_equal (RefPtr<Caps> caps1, RefPtr<Caps> caps2)
+{
+    ThrowIf (caps1->equals(caps2),
+            "caps ('" + caps1->to_string() + "') is"
+                    " not equal to caps ('" + caps2->to_string() + "')");
+}
+
+void buffer_data (RefPtr<Buffer> buffer, gconstpointer data, gsize size)
+{
+    RefPtr<MapInfo> info;
+
+    ThrowIfNot (buffer->map(info, MAP_READ), "Error occurs during mapping.");
+    ThrowIf ((std::equal (info->get_data(), info->get_data() + size,
+            static_cast<const guint8*>(data)) != 0), "Buffer data not equals.");
+    // TODO: using gst_util to display/throw/return dump of memory
+
+    buffer->unmap (info);
+}
diff --git a/gstreamer/gstreamermm/check.h b/gstreamer/gstreamermm/check.h
new file mode 100644
index 0000000..d759ce2
--- /dev/null
+++ b/gstreamer/gstreamermm/check.h
@@ -0,0 +1,74 @@
+/*
+ * check.h
+ *
+ *  Created on: 3 sie 2013
+ *      Author: loganek
+ */
+
+#ifndef _GSTREAMERMM_CHECK_H
+#define _GSTREAMERMM_CHECK_H
+
+#include <glibmm/ustring.h>
+#include <gstreamermm/element.h>
+#include <gstreamermm/pad.h>
+#include <gstreamermm/caps.h>
+#include <gstreamermm/buffer.h>
+#include <stdexcept>
+
+#define THROW_IF(condition, message) \
+        if (condition) \
+            throw Exception(message);
+
+namespace Gst
+{
+class Exception : std::runtime_error
+{
+public:
+    Exception(const std::string& message)
+        : std::runtime_error(message)
+    {}
+};
+
+class Check
+{
+    class _Check
+    {
+    public:
+        /**
+         * Setup an element.
+         *
+         * @param factory Factory.
+         * @return a new element.
+         * @throw Gst::Exception if creating element fails.
+         */
+        Glib::RefPtr<Gst::Element> setup_element (const Glib::ustring& factory);
+
+        /**
+         * Compare two caps with.
+         *
+         * @param caps1 First caps to compare.
+         * @param caps2: Second caps to compare.
+         * @throw Gst::Exception if caps are not equal.
+         */
+        void caps_equal (Glib::RefPtr<Gst::Caps> caps1, Glib::RefPtr<Gst::Caps> caps2);;
+    };
+
+    Check();
+    Check(const Check&);
+    Check& operator=(const Check&);
+
+    virtual ~Check(){}
+public:
+    static _Check& Instance()
+    {
+        static _Check instance;
+
+        return instance;
+    }
+};
+
+#define Checker Check::Instance()
+
+}
+
+#endif
diff --git a/gstreamer/gstreamermm/filelist.am b/gstreamer/gstreamermm/filelist.am
index 5ca3e57..9d7c409 100644
--- a/gstreamer/gstreamermm/filelist.am
+++ b/gstreamer/gstreamermm/filelist.am
@@ -4,6 +4,7 @@ files_built_cc = $(files_hg:.hg=.cc) wrap_init.cc
 files_built_h  = $(files_hg:.hg=.h)
 files_built_ph = $(patsubst %.hg,private/%_p.h,$(files_hg))
 files_extra_cc =                \
+        check.cc                \
         init.cc                 \
         handle_error.cc         \
         version.cc


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