# HG changeset patch
# Node ID bf224036e27713c55e75a8fdd5fa64617a53f902
# Parent  ca4993ee1fcc1efa1763f4a26e0645d972a5e649
diff --git a/seagull/tests/migrations/meson.build b/seagull/tests/migrations/meson.build
--- a/seagull/tests/migrations/meson.build
+++ b/seagull/tests/migrations/meson.build
@@ -11,6 +11,6 @@
 test_migrations = executable(
 	'test_migrations',
 	TEST_MIGRATIONS_SOURCES,
-	dependencies : [glib_dep, seagull_dep, sqlite3_dep])
+	dependencies : [glib_dep, seagull_dep])
 
 test('migrations', test_migrations)
diff --git a/seagull/tests/migrations/test_migrations.c b/seagull/tests/migrations/test_migrations.c
--- a/seagull/tests/migrations/test_migrations.c
+++ b/seagull/tests/migrations/test_migrations.c
@@ -21,8 +21,6 @@
 
 #include <glib.h>
 
-#include <sqlite3.h>
-
 #include <seagull.h>
 
 /******************************************************************************
@@ -35,7 +33,11 @@
 		int version = 0;
 
 		version = seagull_migrations_get_schema_version(NULL, &error);
-		g_assert_error(error, SEAGULL_MIGRATIONS_ERROR, 0);
+
+		/* This code is never actually run, it's here for completeness. */
+		g_assert_error(error,
+		               SEAGULL_MIGRATIONS_ERROR,
+		               SEAGULL_MIGRATIONS_ERROR_EXECUTION_FAILED);
 		g_clear_error(&error);
 		g_assert_cmpint(version, ==, -1);
 	}
@@ -47,21 +49,22 @@
 
 static void
 test_seagull_migrations_get_schema_version_new(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	int rc = 0;
 	int version = 0;
+	gboolean result = FALSE;
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 0);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 /******************************************************************************
@@ -70,18 +73,22 @@
 static void
 test_seagull_migrations_run_from_string_null(void) {
 	if(g_test_subprocess()) {
+		SeagullSqlite3 *db = NULL;
 		GError *error = NULL;
-		sqlite3 *db = NULL;
-		gboolean res = FALSE;
-		int rc = 0;
+		gboolean result = FALSE;
+
+		db = seagull_db_new_in_memory(&error);
+		g_assert_no_error(error);
+		g_assert_nonnull(db);
 
-		rc = sqlite3_open(":memory:", &db);
-		g_assert_nonnull(db);
-		g_assert_cmpint(rc, ==, SQLITE_OK);
+		result = seagull_migrations_run_from_strings(db, NULL, &error);
+		g_assert_no_error(error);
+		g_assert_false(result);
 
-		res = seagull_migrations_run_from_strings(db, NULL, &error);
+		/* This code will never be reached, it's just here for completeness. */
+		result = seagull_db_close(db, &error);
 		g_assert_no_error(error);
-		g_assert_false(res);
+		g_assert_true(result);
 	}
 
 	g_test_trap_subprocess(NULL, 0, 0);
@@ -91,35 +98,34 @@
 
 static void
 test_seagull_migrations_run_from_string_null_terminator(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {NULL};
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_strings(db, migrations, &error);
+	result = seagull_migrations_run_from_strings(db, migrations, &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 0);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_string_multiple(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {
 		"CREATE TABLE foo(a TEXT); CREATE TABLE bar(b TEXT);",
@@ -127,66 +133,68 @@
 		NULL
 	};
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_strings(db, migrations, &error);
+	result = seagull_migrations_run_from_strings(db, migrations, &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
 	/* Run the migrations again and make sure we remain at schema version 2. */
-	res = seagull_migrations_run_from_strings(db, migrations, &error);
+	result = seagull_migrations_run_from_strings(db, migrations, &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_string_syntax_error(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {
 		"CREATE TABLE broke(a TEXT",
 		NULL
 	};
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_strings(db, migrations, &error);
-	g_assert_error(error, SEAGULL_MIGRATIONS_ERROR, 0);
+	result = seagull_migrations_run_from_strings(db, migrations, &error);
+	g_assert_error(error,
+	               SEAGULL_MIGRATIONS_ERROR,
+	               SEAGULL_MIGRATIONS_ERROR_EXECUTION_FAILED);
 	g_clear_error(&error);
-	g_assert_false(res);
+	g_assert_false(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 0);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_string_older(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations1[] = {
 		"CREATE TABLE foo(a TEXT); CREATE TABLE bar(b TEXT);",
@@ -198,32 +206,33 @@
 		NULL
 	};
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_strings(db, migrations1, &error);
+	result = seagull_migrations_run_from_strings(db, migrations1, &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
 	/* Run the older migrations now and verify we get a failure. */
-	res = seagull_migrations_run_from_strings(db, migrations2, &error);
+	result = seagull_migrations_run_from_strings(db, migrations2, &error);
 	g_assert_error(error,
 	               SEAGULL_MIGRATIONS_ERROR,
 	               SEAGULL_MIGRATIONS_ERROR_SCHEMA_TOO_NEW);
 	g_clear_error(&error);
-	g_assert_false(res);
+	g_assert_false(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 /******************************************************************************
@@ -232,21 +241,21 @@
 static void
 test_seagull_migrations_run_from_resource_null_path(void) {
 	if(g_test_subprocess()) {
+		SeagullSqlite3 *db = NULL;
 		GError *error = NULL;
-		sqlite3 *db = NULL;
-		gboolean res = FALSE;
-		int rc = 0;
+		gboolean result = FALSE;
 
-		rc = sqlite3_open(":memory:", &db);
+		db = seagull_db_new_in_memory(&error);
+		g_assert_no_error(error);
 		g_assert_nonnull(db);
-		g_assert_cmpint(rc, ==, SQLITE_OK);
 
-		res = seagull_migrations_run_from_resources(db, NULL, NULL, &error);
+		result = seagull_migrations_run_from_resources(db, NULL, NULL, &error);
 		g_assert_no_error(error);
-		g_assert_false(res);
+		g_assert_false(result);
 
-		rc = sqlite3_close(db);
-		g_assert_cmpint(rc, ==, SQLITE_OK);
+		result = seagull_db_close(db, &error);
+		g_assert_no_error(error);
+		g_assert_true(result);
 	}
 
 	g_test_trap_subprocess(NULL, 0, 0);
@@ -257,23 +266,22 @@
 static void
 test_seagull_migrations_run_from_resource_null_migrations(void) {
 	if(g_test_subprocess()) {
+		SeagullSqlite3 *db = NULL;
 		GError *error = NULL;
-		sqlite3 *db = NULL;
-		gboolean res = FALSE;
+		gboolean result = FALSE;
 		const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
-		int rc = 0;
 
-		rc = sqlite3_open(":memory:", &db);
+		db = seagull_db_new_in_memory(&error);
+		g_assert_no_error(error);
 		g_assert_nonnull(db);
-		g_assert_cmpint(rc, ==, SQLITE_OK);
 
-		res = seagull_migrations_run_from_resources(db, path, NULL,
-		                                                   &error);
+		result = seagull_migrations_run_from_resources(db, path, NULL, &error);
 		g_assert_no_error(error);
-		g_assert_false(res);
+		g_assert_false(result);
 
-		rc = sqlite3_close(db);
-		g_assert_cmpint(rc, ==, SQLITE_OK);
+		result = seagull_db_close(db, &error);
+		g_assert_no_error(error);
+		g_assert_true(result);
 	}
 
 	g_test_trap_subprocess(NULL, 0, 0);
@@ -283,162 +291,166 @@
 
 static void
 test_seagull_migrations_run_from_resource_null_terminator(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {NULL};
 	const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_resources(db, path, migrations,
-	                                                   &error);
+	result = seagull_migrations_run_from_resources(db, path, migrations,
+	                                               &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 0);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_resource_multiple(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {"initial.sql", "secondary.sql", NULL};
 	const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_resources(db, path, migrations,
-	                                                   &error);
+	result = seagull_migrations_run_from_resources(db, path, migrations,
+	                                               &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
 	/* Run the migrations again and make sure we remain at schema version 2. */
-	res = seagull_migrations_run_from_strings(db, migrations, &error);
+	result = seagull_migrations_run_from_strings(db, migrations, &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_resource_missing(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {"initial.sql", "imaginary.sql", NULL};
 	const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_resources(db, path, migrations,
-	                                                   &error);
-	g_assert_error(error, G_RESOURCE_ERROR, 0);
+	result = seagull_migrations_run_from_resources(db, path, migrations,
+	                                               &error);
+	g_assert_error(error,
+	               G_RESOURCE_ERROR,
+	               G_RESOURCE_ERROR_NOT_FOUND);
 	g_clear_error(&error);
-	g_assert_false(res);
+	g_assert_false(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 1);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_resource_syntax_error(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations[] = {"malformed.sql", NULL};
 	const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_resources(db, path, migrations,
-	                                                   &error);
-	g_assert_error(error, SEAGULL_MIGRATIONS_ERROR, 0);
+	result = seagull_migrations_run_from_resources(db, path, migrations,
+	                                               &error);
+	g_assert_error(error,
+	               SEAGULL_MIGRATIONS_ERROR,
+	               SEAGULL_MIGRATIONS_ERROR_EXECUTION_FAILED);
 	g_clear_error(&error);
-	g_assert_false(res);
+	g_assert_false(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 0);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 static void
 test_seagull_migrations_run_from_resource_older(void) {
+	SeagullSqlite3 *db = NULL;
 	GError *error = NULL;
-	sqlite3 *db = NULL;
-	gboolean res = FALSE;
-	int rc = 0;
+	gboolean result = FALSE;
 	int version = -1;
 	const char *migrations1[] = {"initial.sql", "secondary.sql", NULL};
 	const char *migrations2[] = {"initial.sql", NULL};
 	const char *path = "/org/imfreedom/keep/seagull/seagull/tests/migrations/";
 
-	rc = sqlite3_open(":memory:", &db);
+	db = seagull_db_new_in_memory(&error);
+	g_assert_no_error(error);
 	g_assert_nonnull(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
 
-	res = seagull_migrations_run_from_resources(db, path, migrations1,
-	                                                   &error);
+	result = seagull_migrations_run_from_resources(db, path, migrations1,
+	                                               &error);
 	g_assert_no_error(error);
-	g_assert_true(res);
+	g_assert_true(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
 	/* Run the older migrations now and verify we get a failure. */
-	res = seagull_migrations_run_from_resources(db, path, migrations2,
-	                                                   &error);
+	result = seagull_migrations_run_from_resources(db, path, migrations2,
+	                                               &error);
 	g_assert_error(error,
 	               SEAGULL_MIGRATIONS_ERROR,
 	               SEAGULL_MIGRATIONS_ERROR_SCHEMA_TOO_NEW);
 	g_clear_error(&error);
-	g_assert_false(res);
+	g_assert_false(result);
 
 	version = seagull_migrations_get_schema_version(db, &error);
 	g_assert_no_error(error);
 	g_assert_cmpint(version, ==, 2);
 
-	rc = sqlite3_close(db);
-	g_assert_cmpint(rc, ==, SQLITE_OK);
+	result = seagull_db_close(db, &error);
+	g_assert_no_error(error);
+	g_assert_true(result);
 }
 
 /******************************************************************************
