1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/*
* Copyright 2018 Michael Gratton <mike@vee.net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Db.DatabaseTest : TestCase {
public DatabaseTest() {
base("Geary.Db.DatabaseTest");
add_test("transient_open", transient_open);
add_test("open_existing", open_existing);
add_test("open_create_file", open_create_file);
add_test("open_create_dir", open_create_dir);
add_test("open_create_dir_existing", open_create_dir_existing);
add_test("open_check_corruption", open_check_corruption);
add_test("open_create_check", open_create_check);
}
public void transient_open() throws Error {
Database db = new Geary.Db.Database.transient();
db.open.begin(Geary.Db.DatabaseFlags.NONE, null, this.async_completion);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
}
public void open_existing() throws Error {
GLib.FileIOStream stream;
GLib.File tmp_file = GLib.File.new_tmp(
"geary-db-database-test-XXXXXX", out stream
);
Database db = new Geary.Db.Database.persistent(tmp_file);
db.open.begin(Geary.Db.DatabaseFlags.NONE, null, this.async_completion);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
tmp_file.delete();
}
public void open_create_file() throws Error {
GLib.File tmp_dir = GLib.File.new_for_path(
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
);
Database db = new Geary.Db.Database.persistent(
tmp_dir.get_child("test.db")
);
db.open.begin(
Geary.Db.DatabaseFlags.CREATE_FILE, null, this.async_completion
);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
db.file.delete();
tmp_dir.delete();
}
public void open_create_dir() throws Error {
GLib.File tmp_dir = GLib.File.new_for_path(
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
);
Database db = new Geary.Db.Database.persistent(
tmp_dir.get_child("nonexistent").get_child("test.db")
);
db.open.begin(
Geary.Db.DatabaseFlags.CREATE_DIRECTORY |
Geary.Db.DatabaseFlags.CREATE_FILE,
null,
this.async_completion
);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
db.file.delete();
db.file.get_parent().delete();
tmp_dir.delete();
}
public void open_create_dir_existing() throws Error {
GLib.File tmp_dir = GLib.File.new_for_path(
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
);
Database db = new Geary.Db.Database.persistent(
tmp_dir.get_child("test.db")
);
db.open.begin(
Geary.Db.DatabaseFlags.CREATE_DIRECTORY |
Geary.Db.DatabaseFlags.CREATE_FILE,
null,
this.async_completion
);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
db.file.delete();
tmp_dir.delete();
}
public void open_check_corruption() throws Error {
GLib.File tmp_dir = GLib.File.new_for_path(
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
);
Database db = new Geary.Db.Database.persistent(
tmp_dir.get_child("test.db")
);
db.open.begin(
Geary.Db.DatabaseFlags.CREATE_FILE |
Geary.Db.DatabaseFlags.CHECK_CORRUPTION,
null,
this.async_completion
);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
db.file.delete();
tmp_dir.delete();
}
public void open_create_check() throws Error {
GLib.File tmp_dir = GLib.File.new_for_path(
GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
);
Database db = new Geary.Db.Database.persistent(
tmp_dir.get_child("nonexistent").get_child("test.db")
);
db.open.begin(
Geary.Db.DatabaseFlags.CREATE_DIRECTORY |
Geary.Db.DatabaseFlags.CREATE_FILE |
Geary.Db.DatabaseFlags.CHECK_CORRUPTION,
null,
this.async_completion
);
db.open.end(async_result());
// Need to get a connection since the database doesn't
// actually get created until then
db.get_primary_connection();
db.file.delete();
db.file.get_parent().delete();
tmp_dir.delete();
}
}
|