| 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 |
name: "MazDB::ReadStream" |
| 9 |
property string source: Qt.resolvedUrl("~/.maztest.db") |
| 10 |
|
| 11 |
MazDB { |
| 12 |
id: db |
| 13 |
} |
| 14 |
|
| 15 |
function initTestCase() { |
| 16 |
db.source = test.source |
| 17 |
} |
| 18 |
|
| 19 |
function cleanupTestCase() { |
| 20 |
db.destroyDB(test.source) |
| 21 |
} |
| 22 |
|
| 23 |
function test_read_stream(){ |
| 24 |
var data = { |
| 25 |
"asdf":"asdf", |
| 26 |
"string": "asdf2", |
| 27 |
"list": ["asdf"], |
| 28 |
"object": {"a": "b"}, |
| 29 |
"c": "c", |
| 30 |
"d": "d" |
| 31 |
} |
| 32 |
|
| 33 |
db.source = "read_stream.db" |
| 34 |
compare(db.opened, true, db.errorString) |
| 35 |
Object.keys(data).forEach(function (key){ |
| 36 |
db.put(key, data[key]) |
| 37 |
}) |
| 38 |
db.readStream(function (key,value){ |
| 39 |
compare(value, data[key], "Inconsistent data") |
| 40 |
return true; |
| 41 |
}) |
| 42 |
db.source = "" |
| 43 |
compare(db.destroyDB("read_stream.db"), true, db.errorString) |
| 44 |
} |
| 45 |
|
| 46 |
function test_read_stream_with_key(){ |
| 47 |
var data = { |
| 48 |
"asdf":"asdf", |
| 49 |
"string": "asdf2", |
| 50 |
"list": ["asdf"], |
| 51 |
"object": {"a": "b"}, |
| 52 |
"c": "c", |
| 53 |
"d": "d" |
| 54 |
} |
| 55 |
|
| 56 |
db.source = "read_stream.db" |
| 57 |
compare(db.opened, true, db.errorString) |
| 58 |
Object.keys(data).forEach(function (key){ |
| 59 |
db.put(key, data[key]) |
| 60 |
}) |
| 61 |
db.readStream(function (key,value){ |
| 62 |
compare(value, data["string"], "Inconsistent data") |
| 63 |
return true; |
| 64 |
}, "string") // we only expect the "string" value to be returned. |
| 65 |
db.source = "" |
| 66 |
compare(db.destroyDB("read_stream.db"), true, db.errorString) |
| 67 |
} |
| 68 |
} |
| 69 |
|