r18901 - gnucash/trunk/src - Complete unit tests for gnc-uri-utils api and fix bug found by running the tests.

Geert Janssens gjanssens at code.gnucash.org
Sat Mar 13 10:48:10 EST 2010


Author: gjanssens
Date: 2010-03-13 10:48:09 -0500 (Sat, 13 Mar 2010)
New Revision: 18901
Trac: http://svn.gnucash.org/trac/changeset/18901

Modified:
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
   gnucash/trunk/src/core-utils/gnc-uri-utils.c
   gnucash/trunk/src/core-utils/gnc-uri-utils.h
   gnucash/trunk/src/core-utils/test/test-gnc-uri-utils.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
Log:
Complete unit tests for gnc-uri-utils api and fix bug found by running the tests.

Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2010-03-13 13:16:02 UTC (rev 18900)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2010-03-13 15:48:09 UTC (rev 18901)
@@ -420,7 +420,7 @@
     /* Split the book-id
      * Format is protocol://username:password@hostname:port/dbname
        where username, password and port are optional) */
-    gnc_uri_get_components ( book_id, &protocol, &host, portnum,
+    gnc_uri_get_components ( book_id, &protocol, &host, &portnum,
                              &username, &password, &dbname );
 
     // Try to connect to the db.  If it doesn't exist and the create_if_nonexistent
@@ -579,7 +579,7 @@
     /* Split the book-id
      * Format is protocol://username:password@hostname:port/dbname
        where username, password and port are optional) */
-    gnc_uri_get_components ( book_id, &protocol, &host, portnum,
+    gnc_uri_get_components ( book_id, &protocol, &host, &portnum,
                              &username, &password, &dbname );
     if ( portnum == 0 )
         portnum = PGSQL_DEFAULT_PORT;

Modified: gnucash/trunk/src/core-utils/gnc-uri-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-uri-utils.c	2010-03-13 13:16:02 UTC (rev 18900)
+++ gnucash/trunk/src/core-utils/gnc-uri-utils.c	2010-03-13 15:48:09 UTC (rev 18901)
@@ -57,7 +57,7 @@
 void gnc_uri_get_components (const gchar *uri,
                              gchar **protocol,
                              gchar **hostname,
-                             guint32 port,
+                             gint32 *port,
                              gchar **username,
                              gchar **password,
                              gchar **path)
@@ -68,7 +68,7 @@
 
     *protocol = NULL;
     *hostname = NULL;
-    port      = 0;
+    *port      = 0;
     *username = NULL;
     *password = NULL;
     *path     = NULL;
@@ -135,19 +135,19 @@
     delimiter = g_strstr_len ( tmphostname, -1, "/" );
     if ( delimiter != NULL )
     {
-         delimiter[0] = '\0';
-         if ( gnc_uri_is_file_protocol ( *protocol ) ) /* always return absolute file paths */
+        delimiter[0] = '\0';
+        if ( gnc_uri_is_file_protocol ( *protocol ) ) /* always return absolute file paths */
              *path = gnc_resolve_file_path ( (const gchar*)(delimiter+1) );
-         else /* path is no file path, so copy it as is */
-             *path = g_strdup ( (const gchar*)(delimiter+1) );
+        else /* path is no file path, so copy it as is */
+            *path = g_strdup ( (const gchar*)(delimiter+1) );
     }
 
     /* Check for a port specifier */
     delimiter = g_strstr_len ( tmphostname, -1, ":" );
     if ( delimiter != NULL )
     {
-         delimiter[0] = '\0';
-         port = g_ascii_strtoll ( (const gchar*)(delimiter+1), NULL, 0 );
+        delimiter[0] = '\0';
+        *port = g_ascii_strtoll ( delimiter+1, NULL, 0 );
     }
 
     *hostname = g_strdup ( (const gchar*)tmphostname );
@@ -162,12 +162,12 @@
 {
     gchar *protocol = NULL;
     gchar *hostname = NULL;
-    guint32 port = 0;
+    gint32 port     = 0;
     gchar *username = NULL;
     gchar *password = NULL;
     gchar *path     = NULL;
 
-    gnc_uri_get_components ( uri, &protocol, &hostname, port,
+    gnc_uri_get_components ( uri, &protocol, &hostname, &port,
                              &username, &password, &path );
 
     g_free (hostname);
@@ -182,12 +182,12 @@
 {
     gchar *protocol = NULL;
     gchar *hostname = NULL;
-    guint32 port = 0;
+    gint32 port = 0;
     gchar *username = NULL;
     gchar *password = NULL;
     gchar *path     = NULL;
 
-    gnc_uri_get_components ( uri, &protocol, &hostname, port,
+    gnc_uri_get_components ( uri, &protocol, &hostname, &port,
                              &username, &password, &path );
 
     g_free (protocol);
@@ -201,12 +201,12 @@
 /* Generates a normalized uri from the separate components */
 gchar *gnc_uri_create_uri (const gchar *protocol,
                            const gchar *hostname,
-                           guint32 port,
+                           gint32 port,
                            const gchar *username,
                            const gchar *password,
                            const gchar *path)
 {
-    gchar *userpass=NULL, *uri=NULL;
+    gchar *userpass=NULL, *portstr=NULL, *uri=NULL;
 
     g_return_val_if_fail( path != 0, NULL );
 
@@ -233,16 +233,24 @@
     if ( username != NULL )
     {
         if ( password != NULL )
-            userpass = g_strdup_printf ( "%s:%s@", username, password);
+            userpass = g_strdup_printf ( "%s:%s@", username, password );
         else
-            userpass = g_strdup_printf ( "%s@", username);
+            userpass = g_strdup_printf ( "%s@", username );
     }
+    else
+        userpass = g_strdup ( "" );
 
+    if ( port != 0 )
+        portstr = g_strdup_printf ( ":%d", port );
+    else
+        portstr = g_strdup ( "" );
+
     // XXX Do I have to add the slash always or are there situations
     //     it is in the path already ?
-    uri = g_strconcat ( protocol, "://", userpass, hostname, "/", path, NULL );
+    uri = g_strconcat ( protocol, "://", userpass, hostname, portstr, "/", path, NULL );
 
     g_free ( userpass );
+    g_free ( portstr );
 
     return uri;
 
@@ -252,13 +260,13 @@
 {
     gchar *protocol = NULL;
     gchar *hostname = NULL;
-    guint32 port = 0;
+    gint32 port = 0;
     gchar *username = NULL;
     gchar *password = NULL;
     gchar *path     = NULL;
     gchar *newuri   = NULL;
 
-    gnc_uri_get_components ( uri, &protocol, &hostname, port,
+    gnc_uri_get_components ( uri, &protocol, &hostname, &port,
                              &username, &password, &path );
     if (allow_password)
         newuri = gnc_uri_create_uri ( protocol, hostname, port,

Modified: gnucash/trunk/src/core-utils/gnc-uri-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-uri-utils.h	2010-03-13 13:16:02 UTC (rev 18900)
+++ gnucash/trunk/src/core-utils/gnc-uri-utils.h	2010-03-13 15:48:09 UTC (rev 18901)
@@ -72,7 +72,7 @@
 void gnc_uri_get_components (const gchar *uri,
                              gchar **protocol,
                              gchar **hostname,
-                             guint32 port,
+                             gint32 *port,
                              gchar **username,
                              gchar **password,
                              gchar **path);
@@ -128,7 +128,7 @@
  *  Only the components that are provided will be inserted in the uri. However
  *  if no protocol has been provided, 'file' will be used as default protocol.
  *
- *  The function allocates memory for for the uri. The calling function should
+ *  The function allocates memory for the uri. The calling function should
  *  free this memory with g_free the uri is no longer needed.
  *
 *  @param protocol The protocol for this uri. If NULL,, 'file' will be used
@@ -149,7 +149,7 @@
 
 gchar *gnc_uri_create_uri (const gchar *protocol,
                            const gchar *hostname,
-                           guint32 port,
+                           gint32 port,
                            const gchar *username,
                            const gchar *password,
                            const gchar *path);
@@ -166,10 +166,10 @@
  *  returned uri when available.
  *  If no protocol has been provided, 'file' will be used as default protocol.
  *
- *  The function allocates memory for for the uri. The calling function should
+ *  The function allocates memory for the uri. The calling function should
  *  free this memory with g_free the uri is no longer needed.
  *
-*  @param uri The uri that schould be converted into a normalized uri
+ *  @param uri The uri that schould be converted into a normalized uri
  *  @param allow_password If set to TRUE, the normalized uri and the input uri
  *  has a password, this passworld will also be set in the normalized uri.
  *  Otherwise no password will be set in the normalized uri.

Modified: gnucash/trunk/src/core-utils/test/test-gnc-uri-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/test/test-gnc-uri-utils.c	2010-03-13 13:16:02 UTC (rev 18900)
+++ gnucash/trunk/src/core-utils/test/test-gnc-uri-utils.c	2010-03-13 15:48:09 UTC (rev 18901)
@@ -33,14 +33,16 @@
 struct test_strings_struct
 {
     gchar *uri;
+    gboolean want_password;
     gchar *protocol;
     gchar *hostname;
     gchar *username;
     gchar *password;
     gchar *path;
     guint32 port;
-    gchar *norm_uri;
-    gboolean want_password;
+    gchar *created_uri;
+    gchar *normalized_uri;
+    gboolean is_file_protocol;
 };
 
 typedef struct test_strings_struct test_strings;
@@ -50,118 +52,146 @@
 #ifndef G_OS_WIN32
     /* basic file tests in posix like environment */
     {
-        "/test/path/file.xacc",
+        "/test/path/file.xacc", FALSE,
         "file", NULL, NULL, NULL, "/test/path/file.xacc", 0,
-        "file:///test/path/file.xacc", FALSE
+        "file:///test/path/file.xacc",
+        "file:///test/path/file.xacc", TRUE
     },
     {
+        "file:///test/path/file.xacc", FALSE,
+        "file", NULL, NULL, NULL, "/test/path/file.xacc", 0,
         "file:///test/path/file.xacc",
-        "file", NULL, NULL, NULL, "/test/path/file.xacc", 0,
-        "file:///test/path/file.xacc", FALSE
+        "file:///test/path/file.xacc", TRUE
     },
     {
+        "xml:///test/path/file.xacc", FALSE,
+        "xml", NULL, NULL, NULL, "/test/path/file.xacc", 0,
         "xml:///test/path/file.xacc",
-        "xml", NULL, NULL, NULL, "/test/path/file.xacc", 0,
-        "xml:///test/path/file.xacc", FALSE
+        "xml:///test/path/file.xacc", TRUE
     },
     {
+        "sqlite3:///test/path/file.xacc", FALSE,
+        "sqlite3", NULL, NULL, NULL, "/test/path/file.xacc", 0,
         "sqlite3:///test/path/file.xacc",
-        "sqlite3", NULL, NULL, NULL, "/test/path/file.xacc", 0,
-        "sqlite3:///test/path/file.xacc", FALSE
+        "sqlite3:///test/path/file.xacc", TRUE
     },
 #else
     /* basic file tests in windows environment */
     {
-        "c:\\test\\path\\file.gnucash",
+        "c:\\test\\path\\file.gnucash", FALSE,
         "file", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
-        "file://c:\\test\\path\\file.gnucash", FALSE
+        "file://c:\\test\\path\\file.gnucash",
+        "file://c:\\test\\path\\file.gnucash", TRUE
     },
     {
+        "file://c:\\test\\path\\file.gnucash", FALSE,
+        "file", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
         "file://c:\\test\\path\\file.gnucash",
-        "file", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
-        "file://c:\\test\\path\\file.gnucash", FALSE
+        "file://c:\\test\\path\\file.gnucash", TRUE
     },
     {
+        "xml://c:\\test\\path\\file.gnucash", FALSE,
+        "xml", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
         "xml://c:\\test\\path\\file.gnucash",
-        "xml", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
-        "xml://c:\\test\\path\\file.gnucash", FALSE
+        "xml://c:\\test\\path\\file.gnucash", TRUE
     },
     {
+        "sqlite3://c:\\test\\path\\file.gnucash", FALSE,
+        "sqlite3", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
         "sqlite3://c:\\test\\path\\file.gnucash",
-        "sqlite3", NULL, NULL, NULL, "c:\\test\\path\\file.gnucash", 0,
-        "sqlite3://c:\\test\\path\\file.gnucash", FALSE
+        "sqlite3://c:\\test\\path\\file.gnucash", TRUE
     },
 #endif
     /* basic database tests */
     {
+        "mysql://www.gnucash.org/gnucash", FALSE,
+        "mysql", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "mysql://www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "mysql://www.gnucash.org/gnucash", FALSE
     },
     {
+        "mysql://www.gnucash.org/gnucash", TRUE,
+        "mysql", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "mysql://www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", NULL, NULL, "gnucash", 0,
-        "mysql://www.gnucash.org/gnucash", TRUE
+        "mysql://www.gnucash.org/gnucash", FALSE
     },
     {
+        "mysql://dbuser@www.gnucash.org/gnucash", FALSE,
+        "mysql", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "mysql://dbuser@www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "mysql://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "mysql://dbuser@www.gnucash.org/gnucash", TRUE,
+        "mysql", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "mysql://dbuser@www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
-        "mysql://dbuser@www.gnucash.org/gnucash", TRUE
+        "mysql://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "mysql://dbuser:dbpass@www.gnucash.org/gnucash", FALSE,
+        "mysql", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "mysql://dbuser:dbpass@www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "mysql://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "mysql://dbuser:dbpass@www.gnucash.org/gnucash", TRUE,
+        "mysql", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "mysql://dbuser:dbpass@www.gnucash.org/gnucash",
-        "mysql", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
-        "mysql://dbuser:dbpass@www.gnucash.org/gnucash", TRUE
+        "mysql://dbuser:dbpass@www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://www.gnucash.org/gnucash", FALSE,
+        "postgres", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "postgres://www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "postgres://www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://www.gnucash.org/gnucash", TRUE,
+        "postgres", "www.gnucash.org", NULL, NULL, "gnucash", 0,
         "postgres://www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", NULL, NULL, "gnucash", 0,
-        "postgres://www.gnucash.org/gnucash", TRUE
+        "postgres://www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://dbuser@www.gnucash.org/gnucash", FALSE,
+        "postgres", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "postgres://dbuser@www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "postgres://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://dbuser@www.gnucash.org/gnucash", TRUE,
+        "postgres", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
         "postgres://dbuser@www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", "dbuser", NULL, "gnucash", 0,
-        "postgres://dbuser@www.gnucash.org/gnucash", TRUE
+        "postgres://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://dbuser:dbpass@www.gnucash.org/gnucash", FALSE,
+        "postgres", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "postgres://dbuser:dbpass@www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "postgres://dbuser@www.gnucash.org/gnucash", FALSE
     },
     {
+        "postgres://dbuser:dbpass@www.gnucash.org/gnucash", TRUE,
+        "postgres", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
         "postgres://dbuser:dbpass@www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 0,
-        "postgres://dbuser:dbpass@www.gnucash.org/gnucash", TRUE
+        "postgres://dbuser:dbpass@www.gnucash.org/gnucash", FALSE
     },
-    /* password with lots of ugly characters in it test */
+    /* password with lots of ugly characters in it (potentially conflicting with uri syntax) */
     {
+        "postgres://dbuser:*#bad35:@xx@www.gnucash.org/gnucash", TRUE,
+        "postgres", "www.gnucash.org", "dbuser", "*#bad35:@xx", "gnucash", 0,
         "postgres://dbuser:*#bad35:@xx@www.gnucash.org/gnucash",
-        "postgres", "www.gnucash.org", "dbuser", "*#bad35:@xx", "gnucash", 0,
-        "postgres://dbuser:*#bad35:@xx@www.gnucash.org/gnucash", TRUE
+        "postgres://dbuser:*#bad35:@xx@www.gnucash.org/gnucash", FALSE
     },
+    /* uri with custom port number, and hide password in normalized uri */
+    {
+        "postgres://dbuser:dbpass@www.gnucash.org:744/gnucash", FALSE,
+        "postgres", "www.gnucash.org", "dbuser", "dbpass", "gnucash", 744,
+        "postgres://dbuser:dbpass@www.gnucash.org:744/gnucash",
+        "postgres://dbuser@www.gnucash.org:744/gnucash", FALSE
+    },
     /* TODO Figure out how to write tests that actually verify the relative
      * pathname resolution. The above tests only test absolute pathnames */
-    { NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, FALSE },
+    { NULL, FALSE, NULL, NULL, NULL, NULL, NULL, 0, NULL, FALSE },
 };
 
 int
@@ -171,7 +201,7 @@
 
     qof_init();
 
-    /* gnc_uri_get_components */
+    /* TEST: gnc_uri_get_components */
     for (i = 0; strs[i].uri != NULL; i++)
     {
         gchar *tprotocol = NULL;
@@ -183,7 +213,7 @@
         gboolean testresult;
 
         gnc_uri_get_components( strs[i].uri, &tprotocol, &thostname,
-                                tport, &tusername, &tpassword, &tpath );
+                                &tport, &tusername, &tpassword, &tpath );
         testresult = ( safe_strcmp ( tprotocol, strs[i].protocol ) == 0 ) &
                      ( safe_strcmp ( thostname, strs[i].hostname ) == 0 ) &
                      ( safe_strcmp ( tusername, strs[i].username ) == 0 ) &
@@ -205,6 +235,116 @@
         g_free(tpassword);
         g_free(tpath);
     }
+
+    /* TEST: gnc_uri_get_protocol */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gchar *tprotocol = NULL;
+        gboolean testresult;
+
+        tprotocol = gnc_uri_get_protocol( strs[i].uri );
+        testresult = ( safe_strcmp ( tprotocol, strs[i].protocol ) == 0 );
+        do_test_args(testresult,
+                     "gnc_uri_get_protocol",
+                     __FILE__, __LINE__,
+                     "\n  %s:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].uri, strs[i].protocol, tprotocol );
+        g_free(tprotocol);
+    }
+
+    /* TEST: gnc_uri_get_path */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gchar *tpath = NULL;
+        gboolean testresult;
+
+        tpath = gnc_uri_get_path( strs[i].uri );
+        testresult = ( safe_strcmp ( tpath, strs[i].path ) == 0 );
+        do_test_args(testresult,
+                     "gnc_uri_get_path",
+                     __FILE__, __LINE__,
+                     "\n  %s:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].uri, strs[i].path, tpath );
+        g_free(tpath);
+    }
+
+    /* TEST: gnc_uri_create_uri */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gchar *turi = NULL;
+        gboolean testresult;
+
+        turi = gnc_uri_create_uri( strs[i].protocol, strs[i].hostname, strs[i].port,
+                                   strs[i].username, strs[i].password, strs[i].path );
+        testresult = ( safe_strcmp ( turi, strs[i].created_uri ) == 0 );
+        do_test_args(testresult,
+                     "gnc_uri_create_uri",
+                     __FILE__, __LINE__,
+                     "\n  %s, %s, %s, %s, %s, %d:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].protocol, strs[i].hostname,
+                     strs[i].username, strs[i].password, strs[i].path, strs[i].port,
+                     strs[i].created_uri, turi);
+        g_free(turi);
+    }
+
+    /* TEST: gnc_uri_normalize_uri */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gchar *turi = NULL;
+        gboolean testresult;
+
+        turi = gnc_uri_normalize_uri( strs[i].uri, strs[i].want_password );
+        testresult = ( safe_strcmp ( turi, strs[i].normalized_uri ) == 0 );
+        do_test_args(testresult,
+                     "gnc_uri_normalize_uri",
+                     __FILE__, __LINE__,
+                     "\n  %s:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].uri, strs[i].normalized_uri, turi );
+        g_free(turi);
+    }
+
+    /* TEST: gnc_uri_is_file_protocol */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gboolean tis_file_protocol;
+        gboolean testresult;
+
+        tis_file_protocol = gnc_uri_is_file_protocol( strs[i].protocol );
+        testresult = ( tis_file_protocol == strs[i].is_file_protocol );
+        do_test_args(testresult,
+                     "gnc_uri_is_file_protocol",
+                     __FILE__, __LINE__,
+                     "\n  %s:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].uri, strs[i].is_file_protocol, tis_file_protocol );
+    }
+
+    /* TEST: gnc_uri_is_file_uri */
+    for (i = 0; strs[i].uri != NULL; i++)
+    {
+        gboolean tis_file_uri;
+        gboolean testresult;
+
+        tis_file_uri = gnc_uri_is_file_uri( strs[i].uri );
+        testresult = ( tis_file_uri == strs[i].is_file_protocol );
+        do_test_args(testresult,
+                     "gnc_uri_is_file_uri",
+                     __FILE__, __LINE__,
+                     "\n  %s:\n"
+                     "    Expected: %s\n"
+                     "    Got     : %s\n",
+                     strs[i].uri, strs[i].is_file_protocol, tis_file_uri );
+    }
+
     print_test_results();
     return get_rv();
 }

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2010-03-13 13:16:02 UTC (rev 18900)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2010-03-13 15:48:09 UTC (rev 18901)
@@ -1387,21 +1387,13 @@
         filename = g_strdup(_("Unsaved Book"));
     else
     {
-        gchar *protocol = NULL;
-        gchar *hostname = NULL;
-        gchar *username = NULL;
-        gchar *password = NULL;
-        gchar *path = NULL;
-        guint32 port = 0;
-
-        gnc_uri_get_components (book_id, &protocol, &hostname,
-                                port, &username, &password, &path);
-
-        if ( gnc_uri_is_file_protocol ( (const gchar*) protocol ) )
+        if ( gnc_uri_is_file_uri ( book_id ) )
         {
             /* The filename is a true file.
              * The Gnome HIG 2.0 recommends only the file name (no path) be used. (p15) */
+            gchar *path = gnc_uri_get_path ( book_id );
             filename = g_path_get_basename ( path );
+            g_free ( path );
         }
         else
         {
@@ -1409,11 +1401,6 @@
              * For this we will show access_method://username@database[:port] */
             filename = gnc_uri_normalize_uri (book_id, FALSE);
         }
-        g_free(protocol);
-        g_free(hostname);
-        g_free(username);
-        g_free(password);
-        g_free(path);
     }
 
     priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);



More information about the gnucash-changes mailing list