[Xfce4-commits] <midori:master> Consistent xdg and tmp folder setup for unit tests
Christian Dywan
noreply at xfce.org
Sat Nov 10 22:10:04 CET 2012
Updating branch refs/heads/master
to ee61bc25745534948b699d8558703036832ad808 (commit)
from 3da86255afd9273e10d428c4e7564f117bd51b00 (commit)
commit ee61bc25745534948b699d8558703036832ad808
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat Nov 10 18:03:07 2012 +0100
Consistent xdg and tmp folder setup for unit tests
katze/katze-utils.c | 57 +---------------------------------------------
katze/midori-paths.vala | 20 ++++++++++++++++
midori/main.c | 1 -
tests/bookmarks.c | 11 +++-----
tests/speeddial.vala | 3 --
wscript | 6 +++++
6 files changed, 32 insertions(+), 66 deletions(-)
diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index e2ba19a..8fc174f 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1356,70 +1356,17 @@ katze_object_get_object (gpointer object,
* Create a directory if it doesn't already exist. Create intermediate
* parent directories as needed, too.
*
- * Similar to g_mkdir_with_parents() but returning early if the
- * @pathname refers to an existing directory.
- *
* Returns: 0 if the directory already exists, or was successfully
* created. Returns -1 if an error occurred, with errno set.
*
* Since: 0.2.1
*/
-/* Creating directories recursively
- Copyright 2000 Red Hat, Inc.
- Originally copied from Glib 2.20, coding style adjusted
- Modified to determine file existence early and pathname must be != NULL */
int
katze_mkdir_with_parents (const gchar* pathname,
int mode)
{
- gchar* fn, *p;
-
- /* Use g_access instead of g_file_test for better performance */
- if (g_access (pathname, F_OK) == 0)
- return 0;
-
- fn = g_strdup (pathname);
-
- if (g_path_is_absolute (fn))
- p = (gchar *) g_path_skip_root (fn);
- else
- p = fn;
-
- do
- {
- while (*p && !G_IS_DIR_SEPARATOR (*p))
- p++;
-
- if (!*p)
- p = NULL;
- else
- *p = '\0';
-
- if (g_access (fn, F_OK) != 0)
- {
- if (g_mkdir (fn, mode) == -1)
- {
- g_free (fn);
- return -1;
- }
- }
- else if (!g_file_test (fn, G_FILE_TEST_IS_DIR))
- {
- g_free (fn);
- return -1;
- }
- if (p)
- {
- *p++ = G_DIR_SEPARATOR;
- while (*p && G_IS_DIR_SEPARATOR (*p))
- p++;
- }
- }
- while (p);
-
- g_free (fn);
-
- return 0;
+ midori_paths_mkdir_with_parents (pathname, mode);
+ return 0;
}
/**
diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
index 585067c..992cb88 100644
--- a/katze/midori-paths.vala
+++ b/katze/midori-paths.vala
@@ -104,8 +104,28 @@ namespace Midori {
}
}
+ public static void mkdir_with_parents (string path, int mode = 0700) {
+ /* Use g_access instead of g_file_test for better performance */
+ if (Posix.access (path, Posix.F_OK) == 0)
+ return;
+ int i = path.index_of_char (Path.DIR_SEPARATOR, 0);
+ do {
+ string fn = path.substring (i, -1);
+ if (Posix.access (fn, Posix.F_OK) != 0) {
+ if (DirUtils.create (fn, mode) == -1)
+ return; /* Failed */
+ }
+ else if (!FileUtils.test (fn, FileTest.IS_SYMLINK))
+ return; /* Failed */
+
+ i = path.index_of_char (Path.DIR_SEPARATOR, i);
+ }
+ while (i != -1);
+ }
+
public static unowned string get_config_dir_for_writing () {
assert (config_dir != null);
+ mkdir_with_parents (config_dir);
return config_dir;
}
diff --git a/midori/main.c b/midori/main.c
index 32e5800..dc85aab 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -2259,7 +2259,6 @@ main (int argc,
}
katze_assign (config, g_strdup (midori_paths_get_config_dir_for_writing ()));
- katze_mkdir_with_parents (config, 0700);
/* Load configuration file */
error_messages = g_string_new (NULL);
error = NULL;
diff --git a/tests/bookmarks.c b/tests/bookmarks.c
index eaf11da..732b3c8 100644
--- a/tests/bookmarks.c
+++ b/tests/bookmarks.c
@@ -20,7 +20,6 @@ typedef struct
typedef struct
{
- char *dbfile; /* usually ":memory:" */
gboolean verbose; /* print debug stuff if TRUE */
char* infile; /* (e.g. to test import), usually NULL */
char* outfile; /* (e.g. to test export), if it can be avoided it's
@@ -40,8 +39,7 @@ fixture_setup (BookmarksFixture* fixture,
gchar *errmsg = NULL;
fixture->db_bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
- db = NULL; /* FIXME midori_bookmarks_initialize (fixture->db_bookmarks, params->dbfile, &errmsg); */
- if (db == NULL)
+ if ((db = midori_bookmarks_initialize (fixture->db_bookmarks, &errmsg)) == NULL)
g_error ("Bookmarks couldn't be loaded: %s\n", errmsg);
g_assert (errmsg == NULL);
g_object_set_data ( G_OBJECT (fixture->db_bookmarks), "db", db);
@@ -190,13 +188,12 @@ int
main (int argc,
char** argv)
{
- //TestParameters default_params = {"/a/path/unlikely/to/exists/bookmarks.db", TRUE, NULL, NULL};
- //TestParameters default_params = {"/tmp/bookmarks.db", TRUE, NULL, NULL};
- //TestParameters default_params = {":memory:", TRUE, NULL, NULL};
- TestParameters default_params = {":memory:", FALSE, NULL, NULL};
+ /* TestParameters default_params = { TRUE, NULL, NULL }; */
+ TestParameters default_params = { FALSE, NULL, NULL };
g_test_init (&argc, &argv, NULL);
midori_app_setup (&argc, &argv, NULL, NULL);
+ midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, NULL);
g_test_add ("/bookmarks/simple test",
BookmarksFixture, &default_params,
diff --git a/tests/speeddial.vala b/tests/speeddial.vala
index 813ccc0..487da66 100644
--- a/tests/speeddial.vala
+++ b/tests/speeddial.vala
@@ -81,12 +81,9 @@ static void speeddial_load () {
}
void main (string[] args) {
- string temporary_cache = DirUtils.make_tmp ("cacheXXXXXX");
- Environment.set_variable ("XDG_CACHE_HOME", temporary_cache, true);
Test.init (ref args);
Midori.Paths.init (Midori.RuntimeMode.NORMAL, null);
Test.add_func ("/speeddial/load", speeddial_load);
Test.run ();
- DirUtils.remove (temporary_cache);
}
diff --git a/wscript b/wscript
index cd5f181..03178c9 100644
--- a/wscript
+++ b/wscript
@@ -546,6 +546,12 @@ def shutdown ():
Utils.pprint ('YELLOW', "gtk-update-icon-cache -q -f -t %s" % dir)
elif Options.commands['check']:
+ import tempfile, shutil
+ base = os.path.join (tempfile.gettempdir (), 'midori-test', '%s')
+ shutil.rmtree (base % '')
+ for x in ['XDG_CONFIG_HOME', 'XDG_CACHE_HOME', 'XDG_DATA_HOME', 'TMPDIR']:
+ os.environ[x] = (base % x).lower ()
+ Utils.check_dir (os.environ[x])
test = UnitTest.unit_test ()
test.change_to_testfile_dir = True
test.want_to_see_test_output = True
More information about the Xfce4-commits
mailing list