[maemo-commits] [maemo-commits] r8907 - projects/haf/trunk/libossomime/tests
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Jan 2 14:27:43 EET 2007
- Next message: [maemo-commits] r8908 - in projects/haf/trunk/libossomime: . libossomime tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: martyn
Date: 2007-01-02 14:27:42 +0200 (Tue, 02 Jan 2007)
New Revision: 8907
Added:
projects/haf/trunk/libossomime/tests/test-mime-default-app.c
Modified:
projects/haf/trunk/libossomime/tests/test-uri.c
Log:
Updated tests
Added: projects/haf/trunk/libossomime/tests/test-mime-default-app.c
===================================================================
--- projects/haf/trunk/libossomime/tests/test-mime-default-app.c 2007-01-02 12:26:59 UTC (rev 8906)
+++ projects/haf/trunk/libossomime/tests/test-mime-default-app.c 2007-01-02 12:27:42 UTC (rev 8907)
@@ -0,0 +1,66 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006 Nokia Corporation.
+ *
+ * This program 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 of the
+ * License.
+ *
+ * This program 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 program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* Test file to test the GnomeVFS default app. */
+
+#include <config.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-mime-handlers.h>
+
+int
+main (int argc, char **argv)
+{
+ GnomeVFSMimeApplication *mime_application;
+
+ gnome_vfs_init ();
+
+ if (argc < 2) {
+ g_printerr ("Usage: %s <mime-type>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (!strchr (argv[1], '/')) {
+ g_printerr ("Mime type must be in the form:'image/png'\n");
+ return EXIT_FAILURE;
+ }
+
+ mime_application = gnome_vfs_mime_get_default_application (argv[1]);
+ if (!mime_application) {
+ g_printerr ("No mime details associated with:'%s'\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ g_print ("Mime details for:'%s'\n", argv[1]);
+ g_print ("\tid:'%s'\n", mime_application->id);
+ g_print ("\tname:'%s'\n", mime_application->name);
+ g_print ("\tcommand:'%s'\n", mime_application->command);
+
+ gnome_vfs_mime_application_free (mime_application);
+
+ gnome_vfs_shutdown ();
+
+ return EXIT_SUCCESS;
+}
+
+
Modified: projects/haf/trunk/libossomime/tests/test-uri.c
===================================================================
--- projects/haf/trunk/libossomime/tests/test-uri.c 2007-01-02 12:26:59 UTC (rev 8906)
+++ projects/haf/trunk/libossomime/tests/test-uri.c 2007-01-02 12:27:42 UTC (rev 8907)
@@ -6,39 +6,63 @@
static gboolean use_default = FALSE;
static gchar *get_actions = NULL;
+static gchar *get_actions_by_uri = NULL;
+static gchar *action_type = NULL;
static gchar *is_default = NULL;
static gchar *get_default = NULL;
+static gchar *get_default_by_uri = NULL;
static gchar *set_default = NULL;
+static gchar *set_default_by_uri = NULL;
static gchar *set_default_to_nothing = NULL;
static gchar *get_scheme = NULL;
static gchar **open_uris = NULL;
static GOptionEntry entries[] =
{
+ { "get-actions", 0,
+ 0, G_OPTION_ARG_STRING,
+ &get_actions,
+ "Get a list of actions for a scheme like \"http\" [DEPRECATED]",
+ NULL },
+ { "get-default", 0,
+ 0, G_OPTION_ARG_STRING,
+ &get_default,
+ "Get the default action for a scheme like \"http\" [DEPRECATED]",
+ NULL },
+ { "set-default", 0,
+ 0, G_OPTION_ARG_STRING,
+ &set_default,
+ "Set the default action for a scheme like \"http\" (used WITH --get-default) [DEPRECATED]",
+ NULL },
{ "use-default", 'd',
0, G_OPTION_ARG_NONE,
&use_default,
"Use the no action when opening a URI, this means we do NOT get the default action first.",
NULL },
- { "get-actions", 'a',
+ { "get-actions-by-uri", 'a',
0, G_OPTION_ARG_STRING,
- &get_actions,
- "Get a list of actions for a scheme like \"http\"",
+ &get_actions_by_uri,
+ "Get a list of actions by uri (can be used with --action-type)",
NULL },
+ { "action-type", 't',
+ 0, G_OPTION_ARG_STRING,
+ &action_type,
+ "The action type (\"Normal\", \"Neutral\" or \"Fallback\"), used with --get-actions-by-uri",
+ NULL },
{ "is-default", 'i',
0, G_OPTION_ARG_STRING,
&is_default,
"Return TRUE or FALSE for an action name (this is used WITH --get-actions)",
NULL },
- { "get-default", 'g',
+ { "get-default-by-uri", 'g',
0, G_OPTION_ARG_STRING,
- &get_default,
- "Get the default action for a scheme like \"http\"",
+ &get_default_by_uri,
+ "Get the default action by uri",
NULL },
- { "set-default", 's',
+ { "set-default-by-uri", 's',
0, G_OPTION_ARG_STRING,
- &set_default,
- "Set the default action for a scheme like \"http\" (this is used WITH --get-default)",
+ &set_default_by_uri,
+ "Set the default action by uri (used WITH --get-default-by-uri)",
NULL },
{ "set-default-to-nothing", 'n',
0, G_OPTION_ARG_STRING,
@@ -69,8 +93,9 @@
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
- if ((!use_default && !get_actions && !get_default &&
- !set_default && !set_default_to_nothing &&
+ if ((!use_default && !get_actions && !get_actions_by_uri &&
+ !get_default && !get_default_by_uri &&
+ !set_default && !set_default_by_uri && !set_default_to_nothing &&
!get_scheme && !open_uris) ||
(set_default && !get_default) ||
(is_default && !get_actions)) {
@@ -85,7 +110,6 @@
if (error != NULL) {
g_printerr ("Could not set default to nothing for scheme:'%s', error:%d->'%s'\n",
set_default_to_nothing, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -100,7 +124,6 @@
if (error != NULL) {
g_printerr ("Could not get default action for scheme:'%s', error:%d->'%s'\n",
get_default, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -109,7 +132,6 @@
if (error != NULL) {
g_printerr ("Could not set default action for scheme:'%s', error:%d->'%s'\n",
set_default, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -130,7 +152,6 @@
if (error != NULL) {
g_printerr ("Could not get actions for scheme:'%s', error:%d->'%s'\n",
get_actions, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -166,6 +187,76 @@
}
}
+ if (get_default_by_uri && set_default_by_uri) {
+ OssoURIAction *default_action;
+
+ default_action = osso_uri_get_default_action_by_uri (get_default_by_uri, &error);
+ if (error != NULL) {
+ g_printerr ("Could not get default action by uri:'%s', error:%d->'%s'\n",
+ get_default_by_uri, error->code, error->message);
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ osso_uri_set_default_action_by_uri (set_default_by_uri, default_action, &error);
+ if (error != NULL) {
+ g_printerr ("Could not set default action by uri:'%s', error:%d->'%s'\n",
+ set_default_by_uri, error->code, error->message);
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ if (default_action) {
+ osso_uri_action_unref (default_action);
+ }
+
+ g_print ("Default for:'%s' set for '%s' too.\n",
+ get_default_by_uri, set_default_by_uri);
+ }
+
+ if (get_actions_by_uri && is_default) {
+ GSList *actions;
+ GSList *l;
+
+ actions = osso_uri_get_actions_by_uri (get_actions_by_uri, -1, &error);
+ if (error != NULL) {
+ g_printerr ("Could not get actions by uri:'%s', error:%d->'%s'\n",
+ get_actions_by_uri, error->code, error->message);
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ if (actions) {
+ OssoURIAction *action;
+ const gchar *name = NULL;
+ gboolean found = FALSE;
+
+ for (l = actions; l && !found; l = l->next) {
+ action = l->data;
+ name = osso_uri_action_get_name (action);
+
+ if (name && strcmp (name, is_default) == 0) {
+ found = TRUE;
+ }
+ }
+
+ if (found) {
+ gboolean is_default_action;
+
+ is_default_action = osso_uri_is_default_action (action, NULL);
+
+ g_print ("Action:'%s' %s the default action\n",
+ is_default, is_default_action ? "is" : "is NOT");
+ } else {
+ g_print ("Action:'%s' was not found\n", is_default);
+ }
+
+ osso_uri_free_actions (actions);
+ } else {
+ g_print ("No actions for uri:'%s'\n", get_actions_by_uri);
+ }
+ }
+
if (get_default) {
OssoURIAction *default_action;
@@ -173,7 +264,6 @@
if (error != NULL) {
g_printerr ("Could not get default action for scheme:'%s', error:%d->'%s'\n",
get_default, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -188,15 +278,36 @@
}
}
+ if (get_default_by_uri) {
+ OssoURIAction *default_action;
+
+ default_action = osso_uri_get_default_action_by_uri (get_default_by_uri, &error);
+ if (error != NULL) {
+ g_printerr ("Could not get default action for uri:'%s', error:%d->'%s'\n",
+ get_default_by_uri, error->code, error->message);
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ if (default_action) {
+ g_print ("Default action for uri:'%s' is '%s'\n",
+ get_default_by_uri, osso_uri_action_get_name (default_action));
+ osso_uri_action_unref (default_action);
+ } else {
+ g_print ("No default action for uri:'%s'\n",
+ get_default_by_uri);
+ }
+ }
+
if (get_actions) {
- GSList *actions;
+ GSList *actions = NULL;
GSList *l;
actions = osso_uri_get_actions (get_actions, &error);
+
if (error != NULL) {
g_printerr ("Could not get actions for scheme:'%s', error:%d->'%s'\n",
get_actions, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
@@ -218,6 +329,52 @@
}
}
+ if (get_actions_by_uri) {
+ GSList *actions = NULL;
+ GSList *l;
+
+ if (!action_type) {
+ actions = osso_uri_get_actions_by_uri (get_actions_by_uri, -1, &error);
+ } else {
+ OssoURIActionType type;
+
+ type = OSSO_URI_ACTION_NORMAL;
+
+ if (action_type) {
+ if (g_ascii_strcasecmp (action_type, "Neutral") == 0) {
+ type = OSSO_URI_ACTION_NEUTRAL;
+ } else if (g_ascii_strcasecmp (action_type, "Fallback") == 0) {
+ type = OSSO_URI_ACTION_FALLBACK;
+ }
+ }
+
+ actions = osso_uri_get_actions_by_uri (get_actions_by_uri, type, &error);
+ }
+
+ if (error != NULL) {
+ g_printerr ("Could not get actions for uri:'%s', error:%d->'%s'\n",
+ get_actions_by_uri, error->code, error->message);
+ g_clear_error (&error);
+ return EXIT_FAILURE;
+ }
+
+ if (actions) {
+ g_print ("Actions for uri:'%s' are:\n", get_actions_by_uri);
+
+ for (l = actions; l; l = l->next) {
+ OssoURIAction *action;
+
+ action = l->data;
+
+ g_print ("\t%s\n", osso_uri_action_get_name (action));
+ }
+
+ osso_uri_free_actions (actions);
+ } else {
+ g_print ("No actions for uri:'%s'\n", get_actions_by_uri);
+ }
+ }
+
if (get_scheme) {
gchar *scheme;
@@ -225,7 +382,6 @@
if (error != NULL) {
g_printerr ("Could not get scheme from uri:'%s', error:%d->'%s'\n",
get_scheme, error->code, error->message);
-
g_clear_error (&error);
return EXIT_FAILURE;
}
- Next message: [maemo-commits] r8908 - in projects/haf/trunk/libossomime: . libossomime tests
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
