tests/icles/: Add a dumb little test for textoverlay alignments.
authorTim-Philipp Müller <tim@centricular.net>
Mon, 13 Aug 2007 15:37:29 +0000 (15:37 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Mon, 13 Aug 2007 15:37:29 +0000 (15:37 +0000)
Original commit message from CVS:
* tests/icles/.cvsignore:
* tests/icles/Makefile.am:
* tests/icles/test-textoverlay.c:
Add a dumb little test for textoverlay alignments.

ChangeLog
tests/icles/.gitignore
tests/icles/Makefile.am
tests/icles/test-textoverlay.c [new file with mode: 0644]

index 368f019..2bbb204 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2007-08-13  Tim-Philipp Müller  <tim at centricular dot net>
 
+       * tests/icles/.cvsignore:
+       * tests/icles/Makefile.am:
+       * tests/icles/test-textoverlay.c:
+         Add a dumb little test for textoverlay alignments.
+
+2007-08-13  Tim-Philipp Müller  <tim at centricular dot net>
+
        Patch by: Dan Williams  <dcbw redhat com>
 
        * ext/pango/gsttextoverlay.c:
index 103a124..afaa386 100644 (file)
@@ -1 +1,2 @@
 stress-xoverlay
+test-textoverlay
index f5835b9..7934753 100644 (file)
@@ -10,5 +10,15 @@ else
 X_TESTS =
 endif
 
-noinst_PROGRAMS = $(X_TESTS)
+if USE_PANGO
+PANGO_TESTS = test-textoverlay
 
+test_textoverlay_SOURCES = test-textoverlay.c
+test_textoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
+test_textoverlay_LDFLAGS = $(GST_LIBS) $(LIBM)
+
+else
+PANGO_TESTS = 
+endif
+
+noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS)
diff --git a/tests/icles/test-textoverlay.c b/tests/icles/test-textoverlay.c
new file mode 100644 (file)
index 0000000..c206e80
--- /dev/null
@@ -0,0 +1,107 @@
+/* GStreamer interactive textoverlay test
+ * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+static void
+set_enum_property_by_name (gpointer object, const gchar * prop,
+    const gchar * value)
+{
+  GParamSpec *pspec;
+  GValue val = { 0, };
+  GEnumClass *eclass;
+  GEnumValue *eval;
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), prop);
+  g_return_if_fail (pspec != NULL);
+
+  g_value_init (&val, pspec->value_type);
+  g_object_get_property (G_OBJECT (object), prop, &val);
+  eclass = G_ENUM_CLASS (g_type_class_peek (G_VALUE_TYPE (&val)));
+  g_return_if_fail (eclass != NULL);
+  eval = g_enum_get_value_by_name (eclass, value);
+  if (eval == NULL)
+    eval = g_enum_get_value_by_nick (eclass, value);
+  g_return_if_fail (eval != NULL);
+  g_value_set_enum (&val, eval->value);
+  g_object_set_property (G_OBJECT (object), prop, &val);
+  g_value_unset (&val);
+}
+
+static void
+show_text (GstElement * textoverlay, const gchar * txt, const gchar * valign,
+    const gchar * halign, const gchar * line_align)
+{
+  GstElement *pipe;
+
+  g_object_set (textoverlay, "text", txt, NULL);
+
+  set_enum_property_by_name (textoverlay, "valignment", valign);
+  set_enum_property_by_name (textoverlay, "halignment", halign);
+  set_enum_property_by_name (textoverlay, "line-alignment", line_align);
+
+  pipe = textoverlay;
+  while (GST_ELEMENT_PARENT (pipe))
+    pipe = GST_ELEMENT_PARENT (pipe);
+
+  gst_element_set_state (pipe, GST_STATE_PLAYING);
+  gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 2 * GST_SECOND);
+  gst_element_set_state (pipe, GST_STATE_NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+  GstElement *pipe, *toverlay;
+  const gchar *valigns[] = { /* "baseline", */ "bottom", "top" };
+  const gchar *haligns[] = { "left", "center", "right" };
+  const gchar *linealigns[] = { "left", "center", "right" };
+  gint a, b, c;
+
+  gst_init (&argc, &argv);
+
+  pipe = gst_parse_launch ("videotestsrc pattern=black ! textoverlay name=t ! "
+      " ffmpegcolorspace ! videoscale ! autovideosink", NULL);
+  g_assert (pipe);
+
+  toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t");
+  g_assert (toverlay);
+
+  g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL);
+
+  for (a = 0; a < G_N_ELEMENTS (valigns); ++a) {
+    for (b = 0; b < G_N_ELEMENTS (haligns); ++b) {
+      for (c = 0; c < G_N_ELEMENTS (linealigns); ++c) {
+        gchar *s;
+
+        s = g_strdup_printf ("line-alignment = %s\n"
+            "&lt;----- halignment = %s -----&gt;\nvalignment = %s",
+            linealigns[c], haligns[b], valigns[a]);
+        show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]);
+        g_free (s);
+      }
+    }
+  }
+
+  return 0;
+}