File: db-versioned-database-test.vala

package info (click to toggle)
geary 46.0-12
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 15,092 kB
  • sloc: javascript: 972; ansic: 722; sql: 247; xml: 183; python: 30; makefile: 28; sh: 24
file content (53 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (5)
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
/*
 * 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.VersionedDatabaseTest : TestCase {


    public VersionedDatabaseTest() {
        base("Geary.Db.VersionedDatabaseTest");
        add_test("open_new", open_new);
    }

    public void open_new() throws Error {
        GLib.File tmp_dir = GLib.File.new_for_path(
            GLib.DirUtils.make_tmp("geary-db-database-test-XXXXXX")
        );

        GLib.File sql1 = tmp_dir.get_child("version-001.sql");
        sql1.create(
            GLib.FileCreateFlags.NONE
        ).write("CREATE TABLE TestTable (id INTEGER PRIMARY KEY, col TEXT);".data);

        GLib.File sql2 = tmp_dir.get_child("version-002.sql");
        sql2.create(
            GLib.FileCreateFlags.NONE
        ).write("INSERT INTO TestTable (col) VALUES ('value');".data);

        VersionedDatabase db = new VersionedDatabase.persistent(
            tmp_dir.get_child("test.db"), tmp_dir
        );

        db.open.begin(
            Geary.Db.DatabaseFlags.CREATE_FILE, null, this.async_completion
        );
        db.open.end(async_result());

        Geary.Db.Result result = db.query("SELECT * FROM TestTable;");
        assert_false(result.finished, "Row not inserted");
        assert_equal(result.string_for("col"), "value");
        assert_false(result.next(), "Multiple rows inserted");

        db.file.delete();
        sql1.delete();
        sql2.delete();
        tmp_dir.delete();
    }


}