summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGabriel Ivascu <gabrielivascu@gnome.org>2017-10-03 17:56:11 +0200
committerGabriel Ivascu <gabrielivascu@gnome.org>2017-10-03 18:29:53 +0200
commitb015f75398c10dbf86ba20016e361a35b398bfc0 (patch)
treeeee6d08385dcb892922c2856a4d620363089f265 /tests
parent2e686fba88016d0265bf3fa1252f21b01bb0408a (diff)
downloadepiphany-b015f75398c10dbf86ba20016e361a35b398bfc0.tar.gz
sqlite-connection: Add function to delete database filewip/google-safe-browsing
EphySQLiteConnection now stores the path to the database file. This removes the duplicate code in EphyHistoryService and EphyGSBStorage and also removes the need of ensure_empty_database() in ephy-sqlite-test.c
Diffstat (limited to 'tests')
-rw-r--r--tests/ephy-sqlite-test.c93
1 files changed, 57 insertions, 36 deletions
diff --git a/tests/ephy-sqlite-test.c b/tests/ephy-sqlite-test.c
index c5ffc4693..9576a5139 100644
--- a/tests/ephy-sqlite-test.c
+++ b/tests/ephy-sqlite-test.c
@@ -23,53 +23,51 @@
#include "ephy-sqlite-connection.h"
#include "ephy-sqlite-statement.h"
#include <glib.h>
-#include <glib/gstdio.h>
#include <gtk/gtk.h>
-static EphySQLiteConnection *
-ensure_empty_database (const char *filename)
-{
- EphySQLiteConnection *connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE);
- GError *error = NULL;
-
- if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
- g_unlink (filename);
-
- g_assert (ephy_sqlite_connection_open (connection, filename, &error));
- g_assert (!error);
- return connection;
-}
-
static void
test_create_connection (void)
{
+ gchar *temporary_file;
+ EphySQLiteConnection *connection;
GError *error = NULL;
- gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
-
- EphySQLiteConnection *connection = ensure_empty_database (temporary_file);
- ephy_sqlite_connection_close (connection);
+ temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (ephy_sqlite_connection_open (connection, &error));
+ g_assert (!error);
g_assert (g_file_test (temporary_file, G_FILE_TEST_IS_REGULAR));
- g_unlink (temporary_file);
+
+ ephy_sqlite_connection_close (connection);
+ ephy_sqlite_connection_delete_database (connection);
g_assert (!g_file_test (temporary_file, G_FILE_TEST_IS_REGULAR));
+
g_free (temporary_file);
+ g_object_unref (connection);
temporary_file = g_build_filename (g_get_tmp_dir (), "directory-that-does-not-exist", "epiphany_sqlite_test.db", NULL);
- g_assert (!ephy_sqlite_connection_open (connection, temporary_file, &error));
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (!ephy_sqlite_connection_open (connection, &error));
g_assert (error);
g_assert (!g_file_test (temporary_file, G_FILE_TEST_IS_REGULAR));
+
+ g_free (temporary_file);
g_object_unref (connection);
}
-
static void
test_create_statement (void)
{
- gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
- EphySQLiteConnection *connection = ensure_empty_database (temporary_file);
+ gchar *temporary_file;
+ EphySQLiteConnection *connection;
GError *error = NULL;
EphySQLiteStatement *statement = NULL;
+ temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (ephy_sqlite_connection_open (connection, &error));
+ g_assert (!error);
+
statement = ephy_sqlite_connection_create_statement (connection, "CREATE TABLE TEST (id INTEGER)", &error);
g_assert (statement);
g_assert (!error);
@@ -80,9 +78,9 @@ test_create_statement (void)
g_assert (error);
ephy_sqlite_connection_close (connection);
- g_unlink (temporary_file);
- g_free (temporary_file);
+ ephy_sqlite_connection_delete_database (connection);
+ g_free (temporary_file);
g_object_unref (connection);
}
@@ -131,24 +129,37 @@ create_table_and_insert_row (EphySQLiteConnection *connection)
static void
test_create_table_and_insert_row (void)
{
- gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
- EphySQLiteConnection *connection = ensure_empty_database (temporary_file);
+ gchar *temporary_file;
+ EphySQLiteConnection *connection;
+ GError *error = NULL;
+
+ temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (ephy_sqlite_connection_open (connection, &error));
+ g_assert (!error);
create_table_and_insert_row (connection);
- g_object_unref (connection);
- g_unlink (temporary_file);
+ ephy_sqlite_connection_close (connection);
+ ephy_sqlite_connection_delete_database (connection);
+
g_free (temporary_file);
+ g_object_unref (connection);
}
static void
test_bind_data (void)
{
- gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
- EphySQLiteConnection *connection = ensure_empty_database (temporary_file);
+ gchar *temporary_file;
+ EphySQLiteConnection *connection;
GError *error = NULL;
EphySQLiteStatement *statement = NULL;
+ temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (ephy_sqlite_connection_open (connection, &error));
+ g_assert (!error);
+
ephy_sqlite_connection_execute (connection, "CREATE TABLE test (id INTEGER, text LONGVARCHAR)", &error);
statement = ephy_sqlite_connection_create_statement (connection, "INSERT INTO test (id, text) VALUES (?, ?)", &error);
@@ -174,16 +185,24 @@ test_bind_data (void)
g_assert_cmpint (ephy_sqlite_statement_get_column_as_int (statement, 0), ==, 3);
g_assert_cmpstr (ephy_sqlite_statement_get_column_as_string (statement, 1), ==, "foo");
+ ephy_sqlite_connection_close (connection);
+ ephy_sqlite_connection_delete_database (connection);
+
g_object_unref (connection);
- g_unlink (temporary_file);
g_free (temporary_file);
}
static void
test_table_exists (void)
{
- gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
- EphySQLiteConnection *connection = ensure_empty_database (temporary_file);
+ gchar *temporary_file;
+ EphySQLiteConnection *connection;
+ GError *error = NULL;
+
+ temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-sqlite-test.db", NULL);
+ connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE, temporary_file);
+ g_assert (ephy_sqlite_connection_open (connection, &error));
+ g_assert (!error);
g_assert (!ephy_sqlite_connection_table_exists (connection, "test"));
g_assert (!ephy_sqlite_connection_table_exists (connection, "something_fakey"));
@@ -191,8 +210,10 @@ test_table_exists (void)
g_assert (ephy_sqlite_connection_table_exists (connection, "test"));
g_assert (!ephy_sqlite_connection_table_exists (connection, "something_fakey"));
+ ephy_sqlite_connection_close (connection);
+ ephy_sqlite_connection_delete_database (connection);
+
g_object_unref (connection);
- g_unlink (temporary_file);
g_free (temporary_file);
}