Skip to content
Browse files

Add test-view to test MexViewModel

  • Loading branch information...
1 parent c29c72d commit 5c23e09e9db1f4e710282d8db4fc1bdec00367a6 @thos thos committed
Showing with 126 additions and 0 deletions.
  1. +1 −0 tests/.gitignore
  2. +4 −0 tests/Makefile.am
  3. +121 −0 tests/test-view.c
View
1 tests/.gitignore
@@ -3,3 +3,4 @@ test-config
test-core
test-epg
test-keys
+test-view
View
4 tests/Makefile.am
@@ -42,3 +42,7 @@ test_config_LDADD = $(progs_ldadd)
test_keys_SOURCES = test-keys.c
test_keys_LDADD = $(progs_ldadd)
+
+TEST_PROGS += test-view
+test_view_SOURCES = test-view.c
+test_view_LDADD = $(progs_ldadd)
View
121 tests/test-view.c
@@ -0,0 +1,121 @@
+#include <mex/mex.h>
+#include <mex/mex-view-model.h>
+#include <glib/gprintf.h>
+
+static MexModel *videos_model;
+static MexModel *music_model;
+static GMainLoop *mainloop;
+
+static void
+print_titles (MexModel *model)
+{
+ MexContent *content;
+ gint i = 0;
+
+ while ((content = mex_model_get_content (model, i++)))
+ {
+ g_printf (" %d\t%s", i,
+ mex_content_get_metadata (content, MEX_CONTENT_METADATA_TITLE));
+ if (mex_content_get_metadata (content, MEX_CONTENT_METADATA_MIMETYPE))
+ g_printf (" (%s)\n",
+ mex_content_get_metadata (content, MEX_CONTENT_METADATA_MIMETYPE));
+ else
+ g_printf ("\n");
+ }
+ g_printf ("%d items in total\n", mex_model_get_length (model));
+ g_printf ("\n");
+}
+
+static void
+test_view (MexViewModel *view)
+{
+ MexContent *start_at;
+
+ g_debug ("Group by MIMETYPE");
+ mex_view_model_set_group_by (view, MEX_CONTENT_METADATA_MIMETYPE);
+ print_titles (MEX_MODEL (view));
+ mex_view_model_set_group_by (view, MEX_CONTENT_METADATA_NONE);
+
+ g_debug ("Order by TITLE ASCENDING");
+ mex_view_model_set_order_by (view, MEX_CONTENT_METADATA_TITLE, FALSE);
+ print_titles (MEX_MODEL (view));
+
+ g_debug ("Order by TITLE DESCENDING LIMIT 10");
+ mex_view_model_set_limit (view, 10);
+ mex_view_model_set_order_by (view, MEX_CONTENT_METADATA_TITLE, TRUE);
+ print_titles (MEX_MODEL (view));
+
+ start_at = mex_model_get_content (MEX_MODEL (view), 2);
+ g_debug ("Start at %s LIMIT 5, LOOP",
+ mex_content_get_metadata (start_at, MEX_CONTENT_METADATA_TITLE));
+ mex_view_model_set_order_by (view, MEX_CONTENT_METADATA_TITLE, FALSE);
+ mex_view_model_set_limit (view, 5);
+ mex_view_model_set_loop (view, TRUE);
+ mex_view_model_set_start_content (view, start_at);
+ print_titles (MEX_MODEL (view));
+
+ g_debug ("Filter by MIMETYPE on \"video/ogg\"");
+ mex_view_model_set_limit (view, 0);
+ mex_view_model_set_start_content (view, NULL);
+ mex_view_model_set_order_by (view, MEX_CONTENT_METADATA_TITLE, FALSE);
+ mex_view_model_set_filter_by (view, MEX_CONTENT_METADATA_MIMETYPE, "video/ogg");
+ print_titles (MEX_MODEL (view));
+}
+
+static gboolean
+start (gpointer model)
+{
+ const GList *models, *l;
+ gchar *category;
+
+ models = mex_aggregate_model_get_models (model);
+
+ /* find the music and video models */
+ for (l = models; l; l = g_list_next (l))
+ {
+ g_object_get (l->data, "category", &category, NULL);
+
+ g_debug ("Found %s model", category);
+
+ if (!g_strcmp0 (category, "videos"))
+ videos_model = l->data;
+ else if (!g_strcmp0 (category, "music"))
+ music_model = l->data;
+
+ g_free (category);
+ }
+ g_printf ("\n");
+
+ g_debug ("Testing Videos View");
+ g_printf ("\n");
+ test_view (MEX_VIEW_MODEL (mex_view_model_new (videos_model)));
+
+ g_main_loop_quit (mainloop);
+
+ return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ MexModel *root;
+ MexPluginManager *pmanager;
+
+ mex_init (&argc, &argv);
+
+ root = mex_get_root_model ();
+
+ /* load plugins */
+ pmanager = mex_plugin_manager_get_default ();
+ mex_plugin_manager_refresh (pmanager);
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ g_debug ("Waiting for content...");
+ /* wait two seconds for content to be added */
+ g_timeout_add_seconds (1, start, root);
+
+ g_main_loop_run (mainloop);
+
+ return 0;
+}

0 comments on commit 5c23e09

Please sign in to comment.
Something went wrong with that request. Please try again.