tests: add basic unit tests for discoverer
authorStefan Kost <ensonic@users.sf.net>
Tue, 5 Apr 2011 15:14:49 +0000 (18:14 +0300)
committerStefan Kost <ensonic@users.sf.net>
Tue, 5 Apr 2011 15:16:25 +0000 (18:16 +0300)
tests/check/Makefile.am
tests/check/libs/.gitignore
tests/check/libs/discoverer.c [new file with mode: 0644]

index 8a7c7cd..9a9a962 100644 (file)
@@ -140,6 +140,7 @@ check_PROGRAMS = \
        libs/libsabi \
        libs/audio \
        libs/cddabasesrc \
+       libs/discoverer \
        libs/fft \
        libs/mixer \
        libs/navigation \
@@ -235,6 +236,14 @@ libs_cddabasesrc_LDADD = \
        $(GST_BASE_LIBS) \
        $(LDADD)
 
+libs_discoverer_CFLAGS = \
+       $(GST_PLUGINS_BASE_CFLAGS) \
+       $(AM_CFLAGS) \
+       -DGST_TEST_FILE="\"$(abs_top_srcdir)/tests/files/partialframe.mjpeg\""
+libs_discoverer_LDADD = \
+       $(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-@GST_MAJORMINOR@.la \
+       $(GST_BASE_LIBS) $(LDADD)
+
 libs_fft_CFLAGS = \
        $(GST_PLUGINS_BASE_CFLAGS) \
        $(GST_BASE_CFLAGS) \
index 4628357..4972a9a 100644 (file)
@@ -1,6 +1,7 @@
 .dirstamp
 audio
 cddabasesrc
+discoverer
 fft
 gstlibscpp
 libsabi
diff --git a/tests/check/libs/discoverer.c b/tests/check/libs/discoverer.c
new file mode 100644 (file)
index 0000000..2d20576
--- /dev/null
@@ -0,0 +1,94 @@
+/* GStreamer unit tests for discoverer
+ *
+ * Copyright (C) 2011 Stefan Kost <ensonic@users.sf.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/check/gstcheck.h>
+#include <gst/pbutils/pbutils.h>
+
+#include <stdio.h>
+#include <glib/gstdio.h>
+#include <glib/gprintf.h>
+
+
+GST_START_TEST (test_disco_init)
+{
+  GError *err = NULL;
+  GstDiscoverer *dc;
+
+  dc = gst_discoverer_new (GST_SECOND, &err);
+  fail_unless (dc != NULL);
+  fail_unless (err == NULL);
+
+  g_object_unref (dc);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_disco_sync)
+{
+  GError *err = NULL;
+  GstDiscoverer *dc;
+  GstDiscovererInfo *info;
+  GstDiscovererResult result;
+  gchar *uri;
+
+  dc = gst_discoverer_new (GST_SECOND, &err);
+  fail_unless (dc != NULL);
+  fail_unless (err == NULL);
+
+  /* GST_TEST_FILE comes from makefile CFLAGS */
+  GST_INFO ("discovering file '%s'", GST_TEST_FILE);
+  uri = g_filename_to_uri (GST_TEST_FILE, NULL, &err);
+  fail_unless (err == NULL);
+  GST_INFO ("discovering uri '%s'", uri);
+
+  info = gst_discoverer_discover_uri (dc, uri, &err);
+  result = gst_discoverer_info_get_result (info);
+  GST_INFO ("result: %d", result);
+  gst_discoverer_info_unref (info);
+  g_free (uri);
+
+  if (err) {
+    /* we won't have the codec for the jpeg */
+    g_error_free (err);
+  }
+
+  g_object_unref (dc);
+}
+
+GST_END_TEST;
+
+
+static Suite *
+discoverer_suite (void)
+{
+  Suite *s = suite_create ("discoverer");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_disco_init);
+  tcase_add_test (tc_chain, test_disco_sync);
+  return s;
+}
+
+GST_CHECK_MAIN (discoverer);