| 1 |
import QtQuick 2.4 |
| 2 |
import QtQuick.Window 2.1 |
| 3 |
import QtTest 1.0 |
| 4 |
import MazDB 1.0 |
| 5 |
|
| 6 |
TestCase { |
| 7 |
id: test |
| 8 |
width: 500; height: width |
| 9 |
name: "MazDB::ListModel" |
| 10 |
property string source: Qt.resolvedUrl("~/.maztest.db") |
| 11 |
|
| 12 |
MazDB { |
| 13 |
id: db |
| 14 |
} |
| 15 |
|
| 16 |
MazDBListModel { |
| 17 |
id: dbModel |
| 18 |
} |
| 19 |
|
| 20 |
function initTestCase() { |
| 21 |
db.source = source |
| 22 |
dbModel.source = source |
| 23 |
} |
| 24 |
|
| 25 |
function cleanupTestCase() { |
| 26 |
dbModel.close() |
| 27 |
db.destroyDB(test.source) |
| 28 |
} |
| 29 |
|
| 30 |
function init() { |
| 31 |
compare( |
| 32 |
db.batch() |
| 33 |
.put("/comics/","asdf") |
| 34 |
.put("/comics/~", "asdf") |
| 35 |
.put("list", ["asdf"]) |
| 36 |
.put("/comics/abc", {"a": "b"}) |
| 37 |
.write(), true, "Batch Operation Failed" |
| 38 |
) |
| 39 |
} |
| 40 |
|
| 41 |
function cleanup() { |
| 42 |
dbModel.range.start = "" |
| 43 |
dbModel.range.end = "" |
| 44 |
dbModel.excludeKeys = [] |
| 45 |
dbModel.filter = "" |
| 46 |
} |
| 47 |
|
| 48 |
function test_add_remove_values() { |
| 49 |
compare(db.opened, true, db.errorString) |
| 50 |
compare(dbModel.count, 4, "Epic fail") |
| 51 |
compare(db.del("list"), true) |
| 52 |
compare(dbModel.count, 3, " list Should have been removed") |
| 53 |
compare(db.del("/comics/"), true) |
| 54 |
compare(dbModel.count, 2, "/comics/ Should have been removed") |
| 55 |
} |
| 56 |
|
| 57 |
function test_filter() { |
| 58 |
compare(db.opened, true, db.errorString) |
| 59 |
compare(dbModel.count, 4, "Epic fail") |
| 60 |
dbModel.setFilter("/comics/") |
| 61 |
compare(dbModel.count, 3, "Should only be 1 row") |
| 62 |
dbModel.setFilterPolicy(MazDBListModel.ExactMatch) |
| 63 |
dbModel.setFilter("/comics/") |
| 64 |
compare(dbModel.count, 1, "Should only be 1 now") |
| 65 |
} |
| 66 |
|
| 67 |
/* FIXME broken, dbModel.count is 0 |
| 68 |
function test_range() { |
| 69 |
compare(db.opened, true, db.errorString) |
| 70 |
dbModel.range.start = "/comics/" |
| 71 |
dbModel.range.end = "/comics/~" |
| 72 |
dbModel.setExcludeKeys([dbModel.range.start, dbModel.range.end]) |
| 73 |
compare(dbModel.count, 1, "/comics/abc Should be the only one") |
| 74 |
} |
| 75 |
*/ |
| 76 |
} |