[maemo-commits] [maemo-commits] r9073 - in projects/haf/trunk/libossomime: . libossomime tests
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Jan 11 19:14:28 EET 2007
- Previous message: [maemo-commits] r9071 - projects/haf/branches/maemo-af-desktop/hildon-desktop/src
- Next message: [maemo-commits] r9074 - projects/haf/trunk/python-osso/examples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: martyn Date: 2007-01-11 19:14:25 +0200 (Thu, 11 Jan 2007) New Revision: 9073 Modified: projects/haf/trunk/libossomime/ChangeLog projects/haf/trunk/libossomime/libossomime/osso-uri.c projects/haf/trunk/libossomime/tests/test-all.c Log: * osso-uri.c: (osso_uri_get_actions), (osso_uri_get_actions_by_uri), (osso_uri_get_default_action), (osso_uri_get_default_action_by_uri), (osso_uri_set_default_action), (osso_uri_set_default_action_by_uri), (osso_uri_open): * tests/test-all.c: Added tests for failure conditions for all functions. Modified: projects/haf/trunk/libossomime/ChangeLog =================================================================== --- projects/haf/trunk/libossomime/ChangeLog 2007-01-11 16:20:13 UTC (rev 9072) +++ projects/haf/trunk/libossomime/ChangeLog 2007-01-11 17:14:25 UTC (rev 9073) @@ -1,5 +1,13 @@ 2007-01-11 Martyn Russell <martyn at imendio.com> + * tests/test-all.c: Added tests for failure conditions for all + functions. + + * libossomime/osso-uri.c: Check for empty scheme strings and empty + uri strings. Removed some unnecessary debugging. + +2007-01-11 Martyn Russell <martyn at imendio.com> + * tests/test-all.c: Finished the tests for setting a default normal, neutral and fallback action and added 3 more tests for setting the 3 types of new action but by the old API and checking Modified: projects/haf/trunk/libossomime/libossomime/osso-uri.c =================================================================== --- projects/haf/trunk/libossomime/libossomime/osso-uri.c 2007-01-11 16:20:13 UTC (rev 9072) +++ projects/haf/trunk/libossomime/libossomime/osso-uri.c 2007-01-11 17:14:25 UTC (rev 9073) @@ -1354,7 +1354,7 @@ GSList *l; gchar *filename; - g_return_val_if_fail (scheme != NULL, NULL); + g_return_val_if_fail (scheme != NULL && scheme[0] != '\0', NULL); desktop_files = uri_get_desktop_files (scheme); @@ -1390,7 +1390,7 @@ gchar *scheme = NULL; gchar *mime_type = NULL; - g_return_val_if_fail (uri_str != NULL, NULL); + g_return_val_if_fail (uri_str != NULL && uri_str[0] != '\0', NULL); uri = gnome_vfs_uri_new (uri_str); if (!uri) { @@ -1403,6 +1403,13 @@ /* Get scheme */ scheme = g_strdup (gnome_vfs_uri_get_scheme (uri)); + if (!scheme || scheme[0] == '\0') { + g_set_error (error, + OSSO_URI_ERROR, + OSSO_URI_INVALID_URI, + "The scheme could not be obtained from the uri."); + return NULL; + } /* Get mime type */ info = gnome_vfs_file_info_new (); @@ -1437,42 +1444,10 @@ } } -#ifdef EXTRA_DEBUGGING - { - gint count = 0; - - DEBUG_MSG (("URI: Actions found:")); - - for (l = actions; l; l = l->next) { - OssoURIAction *action; - - action = l->data; - DEBUG_MSG (("URI: \tAction %2.2d:'%s', type:'%s'", - ++count, action->name, - uri_action_type_to_string (action->type))); - } - } -#endif - actions = uri_get_desktop_file_actions_filtered (actions, action_type, mime_type); -#ifdef EXTRA_DEBUGGING - { - gint count = 0; - - DEBUG_MSG (("URI: Actions returned:")); - - for (l = actions; l; l = l->next) { - OssoURIAction *action; - - action = l->data; - DEBUG_MSG (("URI: \tAction %2.2d:'%s'", ++count, action->name)); - } - } -#endif - g_slist_foreach (desktop_files, (GFunc) g_free, NULL); g_slist_free (desktop_files); @@ -1706,7 +1681,7 @@ * still works. */ - if (!scheme) { + if (!scheme || scheme[0] == '\0') { g_set_error (error, OSSO_URI_ERROR, OSSO_URI_INVALID_SCHEME, @@ -1768,6 +1743,8 @@ gchar *full_path = NULL; gboolean ok; + g_return_val_if_fail (uri_str != NULL && uri_str[0] != '\0', NULL); + uri = gnome_vfs_uri_new (uri_str); if (!uri) { g_set_error (error, @@ -1779,7 +1756,7 @@ /* Get scheme */ scheme = g_strdup (gnome_vfs_uri_get_scheme (uri)); - if (!scheme) { + if (!scheme || scheme[0] == '\0') { gnome_vfs_uri_unref (uri); g_set_error (error, OSSO_URI_ERROR, @@ -1878,7 +1855,7 @@ gchar *scheme_lower; gboolean ok; - if (!scheme || strlen (scheme) < 1) { + if (!scheme || scheme[0] == '\0') { g_set_error (error, OSSO_URI_ERROR, OSSO_URI_INVALID_SCHEME, @@ -1925,6 +1902,8 @@ const gchar *action_id = NULL; gboolean ok; + g_return_val_if_fail (uri_str != NULL && uri_str[0] != '\0', FALSE); + /* If we are a neutral or fallback action we just use the old * API because that only needs the scheme. */ @@ -1945,7 +1924,7 @@ /* Get scheme */ scheme = g_strdup (gnome_vfs_uri_get_scheme (uri)); - if (!scheme) { + if (!scheme || scheme[0] == '\0') { gnome_vfs_uri_unref (uri); g_set_error (error, OSSO_URI_ERROR, @@ -2028,7 +2007,7 @@ } scheme = osso_uri_get_scheme_from_uri (uri, error); - if (!scheme) { + if (!scheme || scheme[0] == '\0') { /* Error is filled in by _get_scheme_from_uri(). */ return FALSE; } Modified: projects/haf/trunk/libossomime/tests/test-all.c =================================================================== --- projects/haf/trunk/libossomime/tests/test-all.c 2007-01-11 16:20:13 UTC (rev 9072) +++ projects/haf/trunk/libossomime/tests/test-all.c 2007-01-11 17:14:25 UTC (rev 9073) @@ -221,6 +221,89 @@ } static void +test_failure_conditions (void) +{ + GSList *actions; + OssoURIAction *action; + const gchar *str; + gboolean bool; + + print_header ("Testing failure conditions"); + + /* Ref functions */ + action = osso_uri_action_ref (NULL); + assert_expr (action == NULL); + + /* Actions functions */ + str = osso_uri_action_get_name (NULL); + assert_expr (str == NULL); + + str = osso_uri_action_get_translation_domain (NULL); + assert_expr (str == NULL); + + str = osso_uri_action_get_service (NULL); + assert_expr (str == NULL); + + str = osso_uri_action_get_method (NULL); + assert_expr (str == NULL); + + /* Get actions */ + actions = osso_uri_get_actions (NULL, NULL); + assert_expr (actions == NULL); + + actions = osso_uri_get_actions ("foo", NULL); + assert_expr (actions == NULL); + + actions = osso_uri_get_actions_by_uri (NULL, -1, NULL); + assert_expr (actions == NULL); + + /* Misc functions */ + str = osso_uri_get_scheme_from_uri (NULL, NULL); + assert_expr (str == NULL); + + str = osso_uri_get_scheme_from_uri ("foo", NULL); + assert_expr (str == NULL); + + /* Default actions */ + bool = osso_uri_is_default_action (NULL, NULL); + assert_bool (bool == FALSE); + + bool = osso_uri_is_default_action_by_uri (NULL, NULL, NULL); + assert_bool (bool == FALSE); + + action = osso_uri_get_default_action (NULL, NULL); + assert_expr (action == NULL); + + action = osso_uri_get_default_action ("", NULL); + assert_expr (action == NULL); + + action = osso_uri_get_default_action_by_uri (NULL, NULL); + assert_expr (action == NULL); + + action = osso_uri_get_default_action_by_uri ("foo", NULL); + assert_expr (action == NULL); + + bool = osso_uri_set_default_action (NULL, NULL, NULL); + assert_bool (bool == FALSE); + + bool = osso_uri_set_default_action ("", NULL, NULL); + assert_bool (bool == FALSE); + + bool = osso_uri_set_default_action_by_uri (NULL, NULL, NULL); + assert_bool (bool == FALSE); + + bool = osso_uri_set_default_action_by_uri ("foo", NULL, NULL); + assert_bool (bool == FALSE); + + /* Open URI */ + bool = osso_uri_open (NULL, NULL, NULL); + assert_bool (bool == FALSE); + + bool = osso_uri_open ("foo", NULL, NULL); + assert_bool (bool == FALSE); +} + +static void test_system_default_actions (void) { GSList *actions; @@ -548,6 +631,7 @@ test_get_actions (); } + test_failure_conditions (); test_system_default_actions (); test_local_default_actions ();
- Previous message: [maemo-commits] r9071 - projects/haf/branches/maemo-af-desktop/hildon-desktop/src
- Next message: [maemo-commits] r9074 - projects/haf/trunk/python-osso/examples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]