[libgda] unit-tests: improved test for SQLite metadata
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] unit-tests: improved test for SQLite metadata
- Date: Mon, 8 Oct 2018 19:48:48 +0000 (UTC)
commit 5ce00a2fe22ae3e2f36a0a1f0a2b97866d103a6e
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Oct 8 14:47:11 2018 -0500
unit-tests: improved test for SQLite metadata
Using random file names in order to avoid collisions
when running multiple parallel tests.
tests/meta-store/check_meta_store_sqlite.c | 51 +++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/tests/meta-store/check_meta_store_sqlite.c b/tests/meta-store/check_meta_store_sqlite.c
index d97a48c85..837108908 100644
--- a/tests/meta-store/check_meta_store_sqlite.c
+++ b/tests/meta-store/check_meta_store_sqlite.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -18,30 +19,70 @@
#include <libgda/libgda.h>
#include <stdio.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include "common.h"
int
main(int argc, char ** argv)
{
GdaMetaStore *store;
+ GFile *pdir;
+ GFile *fstore;
gda_init ();
+ gchar **penv = g_get_environ ();
+ const gchar *dir = g_environ_getenv (penv, "GDA_TOP_BUILD_DIR");
+ GRand *rand = g_rand_new ();
+ pdir = g_file_new_for_path (dir);
+ if (!g_file_query_exists (pdir, NULL)) {
+ return 1;
+ }
+
+ gchar *duri = g_file_get_uri (pdir);
+ gchar *db = g_strdup_printf ("%s/tests/meta-store/test%d.db", duri, g_rand_int (rand));
+ g_free (duri);
+ fstore = g_file_new_for_uri (db);
+ g_free (db);
+ gchar *furi = g_file_get_uri (fstore);
+ g_print ("Try to use file for metastore: %s\n", furi);
+ g_free (furi);
+ while (g_file_query_exists (fstore, NULL)) {
+ g_print ("File exists for metastore\n");
+ g_free (db);
+ duri = g_file_get_uri (pdir);
+ db = g_strdup_printf ("%s/tests/meta-store/test%d.db", duri, g_rand_int (rand));
+ g_free (duri);
+ g_object_unref (fstore);
+ fstore = g_file_new_for_uri (db);
+ g_free (db);
+ furi = g_file_get_uri (fstore);
+ g_print ("Tes for new file: %s\n", furi);
+ g_free (furi);
+ }
+
/* Clean eveything which might exist in the store */
- store = gda_meta_store_new_with_file ("test.db");
+ gchar *pfstore = g_file_get_path (fstore);
+ store = gda_meta_store_new_with_file (pfstore);
common_drop_all_tables (store);
g_object_unref (store);
/* Test store setup*/
- store = gda_meta_store_new_with_file ("test.db");
+ store = gda_meta_store_new_with_file (pfstore);
g_print ("STORE: %p, version: %d\n", store, store ? gda_meta_store_get_version (store) : 0);
-
+
/* Tests */
tests_group_1 (store);
g_object_unref (store);
-
+ g_free (pfstore);
+ if (g_file_query_exists (fstore, NULL)) {
+ g_file_delete (fstore, NULL, NULL);
+ }
+ g_object_unref (fstore);
+ g_strfreev (penv);
+
g_print ("Test Ok.\n");
-
+
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]