[grilo-plugins] vimeo: Add testsuite



commit 7b3318619c78d6249c78515b298d5629d6c93930
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Fri Aug 23 16:57:57 2013 +0200

    vimeo: Add testsuite

 configure.ac                      |    1 +
 src/vimeo/Makefile.am             |    8 ++
 tests/Makefile.am                 |    7 +-
 tests/vimeo/Makefile.am           |   40 ++++++++
 tests/vimeo/data/empty.data       |    4 +
 tests/vimeo/data/network-data.ini |    9 ++
 tests/vimeo/data/results.data     |   87 +++++++++++++++++
 tests/vimeo/test_vimeo.c          |  192 +++++++++++++++++++++++++++++++++++++
 8 files changed, 347 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a14828a..f5545c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1193,6 +1193,7 @@ AC_CONFIG_FILES([
   tests/apple-trailers/Makefile
   tests/bliptv/Makefile
   tests/tmdb/Makefile
+  tests/vimeo/Makefile
 ])
 
 AC_OUTPUT
diff --git a/src/vimeo/Makefile.am b/src/vimeo/Makefile.am
index 05ce0e1..01e2e24 100644
--- a/src/vimeo/Makefile.am
+++ b/src/vimeo/Makefile.am
@@ -30,6 +30,14 @@ extdir                       = $(GRL_PLUGINS_DIR)
 vimeoxmldir            = $(GRL_PLUGINS_DIR)
 vimeoxml_DATA  = $(VIMEO_PLUGIN_ID).xml
 
+# This lets us test the plugin without installing it,
+# because grilo expects the .so and .xml files to be in
+# the same directory:
+copy-xml-to-libs-dir: libgrlvimeo.la
+       cp -f $(srcdir)/$(vimeoxml_DATA) $(builddir)/.libs/
+
+all-local: copy-xml-to-libs-dir
+
 EXTRA_DIST = $(vimeoxml_DATA)
 
 MAINTAINERCLEANFILES = \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b39cd0c..7667679 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,10 +21,15 @@ if TMDB_PLUGIN
 SUBDIRS += tmdb
 endif
 
+if VIMEO_PLUGIN
+SUBDIRS += vimeo
+endif
+
 DIST_SUBDIRS =    \
    apple-trailers \
    bliptv         \
-   tmdb
+   tmdb           \
+   vimeo
 
 MAINTAINERCLEANFILES =  \
    *.in                 \
diff --git a/tests/vimeo/Makefile.am b/tests/vimeo/Makefile.am
new file mode 100644
index 0000000..4eddbf3
--- /dev/null
+++ b/tests/vimeo/Makefile.am
@@ -0,0 +1,40 @@
+#
+# Makefile.am
+#
+# Author: Juan A. Suarez Romero <jasuarez igalia com>
+#
+# Copyright (C) 2013 Igalia S.L.
+
+include $(top_srcdir)/gtester.mk
+
+INCLUDES = @DEPS_CFLAGS@
+
+TEST_PROGS +=  \
+   test_vimeo
+
+test_vimeo_defines =                                              \
+   -DVIMEO_PLUGIN_PATH=\""$(abs_top_builddir)/src/vimeo/.libs/"\" \
+   -DVIMEO_DATA_PATH=\""$(abs_top_srcdir)/tests/vimeo/data/"\"
+
+test_vimeo_SOURCES =   \
+       test_vimeo.c
+
+test_vimeo_LDADD =     \
+       @DEPS_LIBS@
+
+test_vimeo_CFLAGS =    \
+       $(test_vimeo_defines)
+
+# Distribute the tests data:
+dist_noinst_DATA =         \
+   data/network-data.ini   \
+   data/empty.data         \
+   data/results.data
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+MAINTAINERCLEANFILES =  \
+   *.in                 \
+   *~
+
+DISTCLEANFILES = $(MAINTAINERCLEANFILES)
diff --git a/tests/vimeo/data/empty.data b/tests/vimeo/data/empty.data
new file mode 100644
index 0000000..75bc8d2
--- /dev/null
+++ b/tests/vimeo/data/empty.data
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rsp generated_in="0.0117" stat="ok">
+  <videos on_this_page="0" page="1" perpage="50" total="0"></videos>
+</rsp>
diff --git a/tests/vimeo/data/network-data.ini b/tests/vimeo/data/network-data.ini
new file mode 100644
index 0000000..662a387
--- /dev/null
+++ b/tests/vimeo/data/network-data.ini
@@ -0,0 +1,9 @@
+[default]
+version=1
+ignored-parameters=oauth_nonce;oauth_timestamp;oauth_signature_method;oauth_signature
+
+[http://vimeo.com/api/rest/v2?full_response=yes&method=vimeo.videos.search&oauth_consumer_key=TEST_VIMEO_KEY&oauth_token=&page=1&per_page=2&query=gnome]
+data=results.data
+
+[http://vimeo.com/api/rest/v2?full_response=yes&method=vimeo.videos.search&oauth_consumer_key=TEST_VIMEO_KEY&oauth_token=&page=1&per_page=2&query=invalidfoo]
+data=empty.data
diff --git a/tests/vimeo/data/results.data b/tests/vimeo/data/results.data
new file mode 100644
index 0000000..dee3bd4
--- /dev/null
+++ b/tests/vimeo/data/results.data
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rsp generated_in="0.0573" stat="ok">
+  <videos on_this_page="2" page="1" perpage="2" total="605">
+    <video allow_adds="1" embed_privacy="anywhere" id="31110838" is_hd="1" is_transcoding="0" license="0" 
privacy="anybody">
+      <title>Mound by Allison Schulnik</title>
+      <description>Please allow 1 minute to load before viewing.  Credits: Film by Allison Schulnik 
Cinematography by Helder K. Sun. &quot;It's Raining Today&quot; written by Noel Scott Engel  4:23 min 
Copyright Allison Schulnik 2011 allisonschulnik.com</description>
+      <upload_date>2011-10-25 17:28:37</upload_date>
+      <modified_date>2013-08-23 06:17:32</modified_date>
+      <number_of_likes>3566</number_of_likes>
+      <number_of_plays>217134</number_of_plays>
+      <number_of_comments>139</number_of_comments>
+      <width>1280</width>
+      <height>720</height>
+      <duration>263</duration>
+      <owner display_name="garaco taco" id="9030794" is_plus="0" is_pro="0" is_staff="0" 
profileurl="http://vimeo.com/user9030794"; realname="garaco taco" username="user9030794" 
videosurl="http://vimeo.com/user9030794/videos";>
+        <portraits>
+          <portrait height="30" width="30">http://b.vimeocdn.com/ps/270/881/2708811_30.jpg</portrait>
+          <portrait height="75" width="75">http://b.vimeocdn.com/ps/270/881/2708811_75.jpg</portrait>
+          <portrait height="100" width="100">http://b.vimeocdn.com/ps/270/881/2708811_100.jpg</portrait>
+          <portrait height="300" width="300">http://b.vimeocdn.com/ps/270/881/2708811_300.jpg</portrait>
+        </portraits>
+      </owner>
+      <tags>
+        <tag author="9030794" id="68583916" normalized="allison" 
url="http://vimeo.com/tag:allison";>allison</tag>
+        <tag author="9030794" id="68583917" normalized="schulnik" 
url="http://vimeo.com/tag:schulnik";>schulnik</tag>
+        <tag author="9030794" id="68583918" normalized="scott" url="http://vimeo.com/tag:scott";>scott</tag>
+        <tag author="9030794" id="68583919" normalized="walker" 
url="http://vimeo.com/tag:walker";>walker</tag>
+        <tag author="9030794" id="68583920" normalized="claymation" 
url="http://vimeo.com/tag:claymation";>claymation</tag>
+        <tag author="9030794" id="68583921" normalized="video" url="http://vimeo.com/tag:video";>video</tag>
+        <tag author="9030794" id="68583922" normalized="stop-motion" 
url="http://vimeo.com/tag:stop-motion";>stop-motion</tag>
+        <tag author="9030794" id="68583923" normalized="experimental" 
url="http://vimeo.com/tag:experimental";>experimental</tag>
+        <tag author="9030794" id="68583924" normalized="animation" 
url="http://vimeo.com/tag:animation";>animation</tag>
+        <tag author="9030794" id="68583925" normalized="itapostrophesrainingtoday" 
url="http://vimeo.com/tag:It%26%23039%3Bs+Raining+Today";>It's Raining Today</tag>
+        <tag author="9030794" id="68583926" normalized="calarts" 
url="http://vimeo.com/tag:CalArts";>CalArts</tag>
+        <tag author="9030794" id="68583927" normalized="art" url="http://vimeo.com/tag:art";>art</tag>
+        <tag author="9030794" id="68583928" normalized="artist" 
url="http://vimeo.com/tag:artist";>artist</tag>
+        <tag author="9030794" id="68583929" normalized="clown" url="http://vimeo.com/tag:clown";>clown</tag>
+        <tag author="9030794" id="68583930" normalized="hobo" url="http://vimeo.com/tag:hobo";>hobo</tag>
+        <tag author="9030794" id="68583931" normalized="gnome" url="http://vimeo.com/tag:gnome";>gnome</tag>
+      </tags>
+      <cast>
+        <member display_name="garaco taco" id="9030794" role="" username="user9030794"/>
+      </cast>
+      <urls>
+        <url type="video">http://vimeo.com/31110838</url>
+        <url type="mobile">http://vimeo.com/m/31110838</url>
+      </urls>
+      <thumbnails>
+        <thumbnail height="75" width="100">http://b.vimeocdn.com/ts/209/404/209404005_100.jpg</thumbnail>
+        <thumbnail height="150" width="200">http://b.vimeocdn.com/ts/209/404/209404005_200.jpg</thumbnail>
+        <thumbnail height="360" width="640">http://b.vimeocdn.com/ts/209/404/209404005_640.jpg</thumbnail>
+      </thumbnails>
+    </video>
+    <video allow_adds="1" embed_privacy="anywhere" id="13797705" is_hd="0" is_transcoding="0" 
license="by-sa" privacy="anybody">
+      <title>Shell Yes! motion design mockup</title>
+      <description></description>
+      <upload_date>2010-08-01 05:41:20</upload_date>
+      <modified_date>2013-08-20 03:33:11</modified_date>
+      <number_of_likes>37</number_of_likes>
+      <number_of_plays>38941</number_of_plays>
+      <number_of_comments>9</number_of_comments>
+      <width>640</width>
+      <height>480</height>
+      <duration>13</duration>
+      <owner display_name="GNOME Shell" id="2664247" is_plus="0" is_pro="0" is_staff="0" 
profileurl="http://vimeo.com/user2664247"; realname="GNOME Shell" username="user2664247" 
videosurl="http://vimeo.com/user2664247/videos";>
+        <portraits>
+          <portrait height="30" width="30">http://b.vimeocdn.com/ps/159/159264_30.jpg</portrait>
+          <portrait height="75" width="75">http://b.vimeocdn.com/ps/159/159264_75.jpg</portrait>
+          <portrait height="100" width="100">http://b.vimeocdn.com/ps/159/159264_100.jpg</portrait>
+          <portrait height="300" width="300">http://b.vimeocdn.com/ps/159/159264_300.jpg</portrait>
+        </portraits>
+      </owner>
+      <cast>
+        <member display_name="GNOME Shell" id="2664247" role="" username="user2664247"/>
+      </cast>
+      <urls>
+        <url type="video">http://vimeo.com/13797705</url>
+        <url type="mobile">http://vimeo.com/m/13797705</url>
+      </urls>
+      <thumbnails>
+        <thumbnail height="75" width="100">http://b.vimeocdn.com/ts/798/198/79819832_100.jpg</thumbnail>
+        <thumbnail height="150" width="200">http://b.vimeocdn.com/ts/798/198/79819832_200.jpg</thumbnail>
+        <thumbnail height="480" width="640">http://b.vimeocdn.com/ts/798/198/79819832_640.jpg</thumbnail>
+      </thumbnails>
+    </video>
+  </videos>
+</rsp>
diff --git a/tests/vimeo/test_vimeo.c b/tests/vimeo/test_vimeo.c
new file mode 100644
index 0000000..1bee0e4
--- /dev/null
+++ b/tests/vimeo/test_vimeo.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * Author: Juan A. Suarez Romero <jasuarez igalia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <grilo.h>
+
+#define VIMEO_ID "grl-vimeo"
+
+#define VIMEO_KEY      "TEST_VIMEO_KEY"
+#define VIMEO_SECRET   "TEST_VIMEO_SECRET"
+
+static void
+test_setup (void)
+{
+  GError *error = NULL;
+  GrlConfig *config;
+  GrlRegistry *registry;
+
+  registry = grl_registry_get_default ();
+
+  config = grl_config_new (VIMEO_ID, NULL);
+  grl_config_set_api_key (config, VIMEO_KEY);
+  grl_config_set_api_secret (config, VIMEO_SECRET);
+  grl_registry_add_config (registry, config, NULL);
+
+  grl_registry_load_all_plugins (registry, &error);
+  g_assert_no_error (error);
+}
+
+static void
+test_search_normal (void)
+{
+  GError *error = NULL;
+  GList *medias;
+  GrlMedia *media;
+  GrlOperationOptions *options;
+  GrlRegistry *registry;
+  GrlSource *source;
+
+  registry = grl_registry_get_default ();
+  source = grl_registry_lookup_source (registry, VIMEO_ID);
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  grl_operation_options_set_count (options, 2);
+  grl_operation_options_set_flags (options, GRL_RESOLVE_FAST_ONLY);
+  g_assert (options);
+
+  medias = grl_source_search_sync (source,
+                                   "gnome",
+                                   grl_source_supported_keys (source),
+                                   options,
+                                   &error);
+
+  g_assert_cmpint (g_list_length(medias), ==, 2);
+  g_assert_no_error (error);
+
+  media = g_list_nth_data (medias, 0);
+
+  g_assert (GRL_IS_MEDIA_VIDEO (media));
+  g_assert_cmpstr (grl_media_get_id (media),
+                   ==,
+                   "31110838");
+  g_assert_cmpstr (grl_media_get_title (media),
+                   ==,
+                   "Mound by Allison Schulnik");
+  g_assert_cmpstr (grl_media_get_author (media),
+                   ==,
+                   "garaco taco");
+  g_assert_cmpstr (grl_media_get_thumbnail (media),
+                   ==,
+                   "http://b.vimeocdn.com/ts/209/404/209404005_100.jpg";);
+
+  media = g_list_nth_data (medias, 1);
+
+  g_assert (GRL_IS_MEDIA_VIDEO (media));
+  g_assert_cmpstr (grl_media_get_id (media),
+                   ==,
+                   "13797705");
+  g_assert_cmpstr (grl_media_get_title (media),
+                   ==,
+                   "Shell Yes! motion design mockup");
+  g_assert_cmpstr (grl_media_get_author (media),
+                   ==,
+                   "GNOME Shell");
+  g_assert_cmpstr (grl_media_get_thumbnail (media),
+                   ==,
+                   "http://b.vimeocdn.com/ts/798/198/79819832_100.jpg";);
+
+  g_list_free_full (medias, g_object_unref);
+  g_object_unref (options);
+}
+
+static void
+test_search_null (void)
+{
+  GError *error = NULL;
+  GList *medias;
+  GrlOperationOptions *options;
+  GrlRegistry *registry;
+  GrlSource *source;
+
+  registry = grl_registry_get_default ();
+  source = grl_registry_lookup_source (registry, VIMEO_ID);
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  grl_operation_options_set_count (options, 2);
+  grl_operation_options_set_flags (options, GRL_RESOLVE_FAST_ONLY);
+  g_assert (options);
+
+  medias = grl_source_search_sync (source,
+                                   NULL,
+                                   grl_source_supported_keys (source),
+                                   options,
+                                   &error);
+
+  g_assert_cmpint (g_list_length(medias), ==, 0);
+  g_assert_error (error,
+                  GRL_CORE_ERROR,
+                  GRL_CORE_ERROR_SEARCH_NULL_UNSUPPORTED);
+
+  g_object_unref (options);
+}
+
+static void
+test_search_empty (void)
+{
+  GError *error = NULL;
+  GList *medias;
+  GrlOperationOptions *options;
+  GrlRegistry *registry;
+  GrlSource *source;
+
+  registry = grl_registry_get_default ();
+  source = grl_registry_lookup_source (registry, VIMEO_ID);
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  grl_operation_options_set_count (options, 2);
+  grl_operation_options_set_flags (options, GRL_RESOLVE_FAST_ONLY);
+  g_assert (options);
+
+  medias = grl_source_search_sync (source,
+                                   "invalidfoo",
+                                   grl_source_supported_keys (source),
+                                   options,
+                                   &error);
+
+  g_assert_cmpint (g_list_length(medias), ==, 0);
+  g_assert_no_error (error);
+
+  g_object_unref (options);
+}
+
+int
+main (int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_PATH", VIMEO_PLUGIN_PATH, TRUE);
+  g_setenv ("GRL_PLUGIN_LIST", VIMEO_ID, TRUE);
+  g_setenv ("GRL_NET_MOCKED", VIMEO_DATA_PATH "network-data.ini", TRUE);
+
+  grl_init (&argc, &argv);
+  g_test_init (&argc, &argv, NULL);
+
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test_setup ();
+
+  g_test_add_func ("/vimeo/search/normal", test_search_normal);
+  g_test_add_func ("/vimeo/search/null", test_search_null);
+  g_test_add_func ("/vimeo/search/empty", test_search_empty);
+
+  return g_test_run ();
+}


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