summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2012-04-11 15:59:00 +0200
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2012-04-11 16:54:46 +0200
commit6b7df60a752422b1f6ff07bb2682c21e18a43985 (patch)
tree3e56bd3f4ee34a228777d00ff328ef1c53cb1df1 /tests/auto
parent20549eedb5b5e852c0e384cd76bfbff14168dbda (diff)
parent7ef36e3c5a88560eb4e3a81c2c9f14059739108b (diff)
Merge remote-tracking branch 'gerrit/master' into hbtreehbtree
Conflicts: src/daemon/daemon.pri src/daemon/jsondbview.cpp src/partition/jsondbindex.cpp src/partition/jsondbindex.h src/partition/jsondbindexquery.h src/partition/jsondbmanagedbtree.cpp src/partition/jsondbmanagedbtree.h src/partition/jsondbmanagedbtreetxn.cpp src/partition/jsondbmanagedbtreetxn.h src/partition/jsondbobjecttable.cpp src/partition/jsondbobjecttable.h src/partition/jsondbpartition.cpp src/partition/jsondbpartition.h tests/auto/auto.pro tests/auto/partition/testpartition.cpp tests/benchmarks/benchmarks.pro Change-Id: I963adefd6d32fca9b3537981306b67538c759034
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/accesscontrol/accesscontrol.pro4
-rw-r--r--tests/auto/accesscontrol/json/capabilities-indexes.json24
-rw-r--r--tests/auto/accesscontrol/json/index-test.json25
-rw-r--r--tests/auto/accesscontrol/testjsondb.cpp162
-rw-r--r--tests/auto/auto.pro5
-rw-r--r--tests/auto/client/client.pro4
-rw-r--r--tests/auto/client/json/index-test.json2
-rw-r--r--tests/auto/client/partitions.json5
-rw-r--r--tests/auto/client/test-jsondb-client.cpp91
-rw-r--r--tests/auto/daemon/daemon.pro17
-rw-r--r--tests/auto/jsondb-listmodel/jsondb-listmodel.pro1
-rw-r--r--tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp28
-rw-r--r--tests/auto/jsondb-listmodel/test-jsondb-listmodel.h1
-rw-r--r--tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro11
-rw-r--r--tests/auto/jsondbcachinglistmodel/partitions.json4
-rw-r--r--tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp945
-rw-r--r--tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h64
-rw-r--r--tests/auto/jsondbchangessinceobject/jsondbchangessinceobject.pro17
-rw-r--r--tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.cpp332
-rw-r--r--tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.h108
-rw-r--r--tests/auto/jsondblistmodel/jsondblistmodel.pro11
-rw-r--r--tests/auto/jsondblistmodel/partitions.json3
-rw-r--r--tests/auto/jsondblistmodel/testjsondblistmodel.cpp342
-rw-r--r--tests/auto/jsondblistmodel/testjsondblistmodel.h39
-rw-r--r--tests/auto/jsondbnotification/jsondbnotification.pro11
-rw-r--r--tests/auto/jsondbnotification/partitions.json3
-rw-r--r--tests/auto/jsondbnotification/testjsondbnotification.cpp156
-rw-r--r--tests/auto/jsondbnotification/testjsondbnotification.h31
-rw-r--r--tests/auto/jsondbpartition/jsondbpartition.pro11
-rw-r--r--tests/auto/jsondbpartition/partitions.json3
-rw-r--r--tests/auto/jsondbpartition/testjsondbpartition.cpp95
-rw-r--r--tests/auto/jsondbpartition/testjsondbpartition.h27
-rw-r--r--tests/auto/jsondbqueryobject/jsondbqueryobject.pro11
-rw-r--r--tests/auto/jsondbqueryobject/partitions.json3
-rw-r--r--tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp101
-rw-r--r--tests/auto/jsondbqueryobject/testjsondbqueryobject.h31
-rw-r--r--tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro11
-rw-r--r--tests/auto/jsondbsortinglistmodel/partitions.json4
-rw-r--r--tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp542
-rw-r--r--tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.h52
-rw-r--r--tests/auto/jsonstream/jsonstream.pro2
-rw-r--r--tests/auto/jsonstream/test-jsonstream.cpp15
-rw-r--r--tests/auto/partition/json-validation.qrc (renamed from tests/auto/daemon/json-validation.qrc)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-schema.json (renamed from tests/auto/daemon/json-validation/array-boundaries-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrLess-empty-valid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrLess-empty-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrLess-five-invalid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrLess-five-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrLess-two-valid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrLess-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrMore-empty-invalid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrMore-empty-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrMore-five-valid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrMore-five-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrMore-one-invalid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrMore-one-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-boundaries-twoOrMore-two-valid.json (renamed from tests/auto/daemon/json-validation/array-boundaries-twoOrMore-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-empty-empty-valid.json (renamed from tests/auto/daemon/json-validation/array-items-empty-empty-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-empty-mixed-valid.json (renamed from tests/auto/daemon/json-validation/array-items-empty-mixed-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-empty-numbers-valid.json (renamed from tests/auto/daemon/json-validation/array-items-empty-numbers-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-empty-valid.json (renamed from tests/auto/daemon/json-validation/array-items-number-empty-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-highnumbers-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-number-highnumbers-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-mixed-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-number-mixed-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-numbers-valid.json (renamed from tests/auto/daemon/json-validation/array-items-number-numbers-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-object-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-number-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-number-string-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-number-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-empty-valid.json (renamed from tests/auto/daemon/json-validation/array-items-object-empty-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-missingfoo-valid.json (renamed from tests/auto/daemon/json-validation/array-items-object-missingfoo-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-missingid-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-object-missingid-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-numbers-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-object-numbers-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-std-valid.json (renamed from tests/auto/daemon/json-validation/array-items-object-std-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-object-strings-invalid.json (renamed from tests/auto/daemon/json-validation/array-items-object-strings-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/array-items-schema.json (renamed from tests/auto/daemon/json-validation/array-items-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-lessThenOne-one-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-one-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-lessThenOne-two-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-two-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-lessThenOne-zero-valid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-zero-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-moreThenOne-one-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-one-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-moreThenOne-two-valid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-moreThenOne-zero-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-zero-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-oneOrLess-one-valid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-one-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-oneOrLess-two-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-two-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-oneOrMore-one-valid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-one-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-oneOrMore-two-valid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-oneOrMore-zero-invalid.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-zero-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/integer-boundaries-schema.json (renamed from tests/auto/daemon/json-validation/integer-boundaries-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-one-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-one-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-two-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-two-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-zero-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-zero-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-one-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-one-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-two-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-one-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-one-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-two-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-two-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-zero-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-zero-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-one-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-one-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-two-valid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-two-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/numbers-boundaries-schema.json (renamed from tests/auto/daemon/json-validation/numbers-boundaries-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/required-missing-invalid.json (renamed from tests/auto/daemon/json-validation/required-missing-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/required-nested-valid.json (renamed from tests/auto/daemon/json-validation/required-nested-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/required-notimportent-number-invalid.json (renamed from tests/auto/daemon/json-validation/required-notimportent-number-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/required-number-valid.json (renamed from tests/auto/daemon/json-validation/required-number-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/required-object-valid.json (renamed from tests/auto/daemon/json-validation/required-object-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/required-schema.json (renamed from tests/auto/daemon/json-validation/required-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-max5chars-silo-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-max5chars-silo-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-max5chars-silos-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-max5chars-silos-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-max5chars-toolong-invalid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-max5chars-toolong-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-min5chars-silo-invalid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-min5chars-silo-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-min5chars-silos-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-min5chars-silos-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-min5chars-toolong-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-min5chars-toolong-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-pattern-a-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-pattern-a-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-pattern-aaa-valid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-pattern-aaa-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-pattern-ab-invalid.json (renamed from tests/auto/daemon/json-validation/string-boundaries-pattern-ab-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/string-boundaries-schema.json (renamed from tests/auto/daemon/json-validation/string-boundaries-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-array-valid.json (renamed from tests/auto/daemon/json-validation/type-array-array-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-bool-invalid.json (renamed from tests/auto/daemon/json-validation/type-array-bool-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-integer-invalid.json (renamed from tests/auto/daemon/json-validation/type-array-integer-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-number-invalid.json (renamed from tests/auto/daemon/json-validation/type-array-number-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-array-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-array-string-invalid.json (renamed from tests/auto/daemon/json-validation/type-array-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-bool-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-false-valid.json (renamed from tests/auto/daemon/json-validation/type-bool-false-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-integer-invalid.json (renamed from tests/auto/daemon/json-validation/type-bool-integer-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-number-invalid.json (renamed from tests/auto/daemon/json-validation/type-bool-number-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-bool-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-string-invalid.json (renamed from tests/auto/daemon/json-validation/type-bool-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-bool-true-valid.json (renamed from tests/auto/daemon/json-validation/type-bool-true-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-integer-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-bool-invalid.json (renamed from tests/auto/daemon/json-validation/type-integer-bool-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-double-invalid.json (renamed from tests/auto/daemon/json-validation/type-integer-double-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-integer-valid.json (renamed from tests/auto/daemon/json-validation/type-integer-integer-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-integer-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-integer-string-invalid.json (renamed from tests/auto/daemon/json-validation/type-integer-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-mixed-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-mixed-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-mixed-double-invalid.json (renamed from tests/auto/daemon/json-validation/type-mixed-double-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-mixed-number-valid.json (renamed from tests/auto/daemon/json-validation/type-mixed-number-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-mixed-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-mixed-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-mixed-string-valid.json (renamed from tests/auto/daemon/json-validation/type-mixed-string-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-number-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-bool-invalid.json (renamed from tests/auto/daemon/json-validation/type-number-bool-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-double-valid.json (renamed from tests/auto/daemon/json-validation/type-number-double-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-number-valid.json (renamed from tests/auto/daemon/json-validation/type-number-number-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-number-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-number-string-invalid.json (renamed from tests/auto/daemon/json-validation/type-number-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-object-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-bool-invalid.json (renamed from tests/auto/daemon/json-validation/type-object-bool-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-double-invalid.json (renamed from tests/auto/daemon/json-validation/type-object-double-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-number-invalid.json (renamed from tests/auto/daemon/json-validation/type-object-number-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-object-valid.json (renamed from tests/auto/daemon/json-validation/type-object-object-valid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-object-string-invalid.json (renamed from tests/auto/daemon/json-validation/type-object-string-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-schema.json (renamed from tests/auto/daemon/json-validation/type-schema.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-array-invalid.json (renamed from tests/auto/daemon/json-validation/type-string-array-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-bool-invalid.json (renamed from tests/auto/daemon/json-validation/type-string-bool-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-double-invalid.json (renamed from tests/auto/daemon/json-validation/type-string-double-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-integer-invalid.json (renamed from tests/auto/daemon/json-validation/type-string-integer-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-object-invalid.json (renamed from tests/auto/daemon/json-validation/type-string-object-invalid.json)0
-rw-r--r--tests/auto/partition/json-validation/type-string-string-valid.json (renamed from tests/auto/daemon/json-validation/type-string-string-valid.json)0
-rw-r--r--tests/auto/partition/json/array.json (renamed from tests/auto/daemon/json/array.json)0
-rw-r--r--tests/auto/partition/json/index-casepreference.json (renamed from tests/auto/daemon/json/index-casepreference.json)0
-rw-r--r--tests/auto/partition/json/index-casesensitive.json (renamed from tests/auto/daemon/json/index-casesensitive.json)0
-rw-r--r--tests/auto/partition/json/largeContactsTest.json (renamed from tests/auto/daemon/json/largeContactsTest.json)0
-rw-r--r--tests/auto/partition/json/largeContactsTest10k.json (renamed from tests/auto/daemon/json/largeContactsTest10k.json)0
-rw-r--r--tests/auto/partition/json/largeContactsTest1k.json (renamed from tests/auto/daemon/json/largeContactsTest1k.json)0
-rw-r--r--tests/auto/partition/json/largeContactsTest33k.json (renamed from tests/auto/daemon/json/largeContactsTest33k.json)0
-rw-r--r--tests/auto/partition/json/map-array-conversion.json (renamed from tests/auto/daemon/json/map-array-conversion.json)0
-rw-r--r--tests/auto/partition/json/map-join-sourceuuids.json (renamed from tests/auto/daemon/json/map-join-sourceuuids.json)0
-rw-r--r--tests/auto/partition/json/map-join.json (renamed from tests/auto/daemon/json/map-join.json)0
-rw-r--r--tests/auto/partition/json/map-reduce-schema.json (renamed from tests/auto/daemon/json/map-reduce-schema.json)0
-rw-r--r--tests/auto/partition/json/map-reduce.json (renamed from tests/auto/daemon/json/map-reduce.json)0
-rw-r--r--tests/auto/partition/json/map-sametarget.json (renamed from tests/auto/daemon/json/map-sametarget.json)0
-rw-r--r--tests/auto/partition/json/pk-capability.json (renamed from tests/auto/daemon/json/pk-capability.json)0
-rw-r--r--tests/auto/partition/json/reduce-array.json (renamed from tests/auto/daemon/json/reduce-array.json)0
-rw-r--r--tests/auto/partition/json/reduce-data.json (renamed from tests/auto/daemon/json/reduce-data.json)0
-rw-r--r--tests/auto/partition/json/reduce-subprop.json (renamed from tests/auto/daemon/json/reduce-subprop.json)0
-rw-r--r--tests/auto/partition/json/reduce.json (renamed from tests/auto/daemon/json/reduce.json)0
-rw-r--r--tests/auto/partition/partition.pro32
-rw-r--r--tests/auto/partition/partition.qrc (renamed from tests/auto/daemon/daemon.qrc)2
-rw-r--r--tests/auto/partition/schemas/TestView.json (renamed from tests/auto/daemon/schemas/TestView.json)0
-rw-r--r--tests/auto/partition/schemas/address.json (renamed from tests/auto/daemon/schemas/address.json)0
-rw-r--r--tests/auto/partition/schemas/contact.json (renamed from tests/auto/daemon/schemas/contact.json)0
-rw-r--r--tests/auto/partition/schemas/ephemeral.json (renamed from tests/auto/daemon/schemas/ephemeral.json)0
-rw-r--r--tests/auto/partition/testpartition.cpp (renamed from tests/auto/daemon/testjsondb.cpp)943
-rw-r--r--tests/auto/qjsondbflushrequest/qjsondbflushrequest.pro13
-rw-r--r--tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp88
-rw-r--r--tests/auto/qjsondbrequest/partitions.json3
-rw-r--r--tests/auto/qjsondbrequest/qjsondbrequest.pro17
-rw-r--r--tests/auto/qjsondbrequest/testqjsondbrequest.cpp197
-rw-r--r--tests/auto/qjsondbwatcher/qjsondbwatcher.pro2
-rw-r--r--tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp597
-rw-r--r--tests/auto/queries/queries.pro5
-rw-r--r--tests/auto/queries/testjsondbqueries.cpp56
-rw-r--r--tests/auto/tests.xml20
186 files changed, 3143 insertions, 2186 deletions
diff --git a/tests/auto/accesscontrol/accesscontrol.pro b/tests/auto/accesscontrol/accesscontrol.pro
index e15c1c62..83bfadfc 100644
--- a/tests/auto/accesscontrol/accesscontrol.pro
+++ b/tests/auto/accesscontrol/accesscontrol.pro
@@ -1,16 +1,14 @@
TARGET = tst_accesscontrol
CONFIG += debug
-QT = network qml testlib
+QT = network qml testlib jsondbpartition
CONFIG -= app_bundle
CONFIG += testcase
-INCLUDEPATH += $$PWD/../../../src/daemon
LIBS += -L$$QT.jsondb.libs
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-include($$PWD/../../../src/daemon/daemon.pri)
RESOURCES+= accesscontrol.qrc
SOURCES += \
testjsondb.cpp \
diff --git a/tests/auto/accesscontrol/json/capabilities-indexes.json b/tests/auto/accesscontrol/json/capabilities-indexes.json
new file mode 100644
index 00000000..777329fb
--- /dev/null
+++ b/tests/auto/accesscontrol/json/capabilities-indexes.json
@@ -0,0 +1,24 @@
+[
+ {
+ "_type": "Capability",
+ "name": "indexes",
+ "partition": "all",
+ "accessRules": {
+ "rw": {
+ "read": ["[?_type startsWith \"Phone\"]", "[?_type = \"Contact\"]", "[?_type = \"Index\"]"],
+ "write": ["[?_type = \"Index\"]"]
+ }
+ }
+ },
+{
+ "_type": "Capability",
+ "name": "noindexes",
+ "partition": "all",
+ "accessRules": {
+ "rw": {
+ "read": ["[?_type startsWith \"Phone\"]", "[?_type = \"Index\"]"],
+ "write": ["[?_type = \"Index\"]"]
+ }
+ }
+}
+]
diff --git a/tests/auto/accesscontrol/json/index-test.json b/tests/auto/accesscontrol/json/index-test.json
new file mode 100644
index 00000000..1fca6652
--- /dev/null
+++ b/tests/auto/accesscontrol/json/index-test.json
@@ -0,0 +1,25 @@
+[
+{
+ "_type": "Index",
+ "objectType": "Phone",
+ "name": "name",
+ "propertyName": "name",
+ "propertyType": "string"
+},
+{
+ "_type": "Index",
+ "name": "another",
+ "objectType": ["Phone", "Contact"],
+ "propertyName": "field",
+ "propertyType": "string",
+ "locale": "en_US",
+ "collation": "default",
+ "casePreference": "IgnoreCase"
+},
+{
+ "_type": "Index",
+ "name": "noObjectType",
+ "propertyName": "field",
+ "propertyType": "string"
+}
+]
diff --git a/tests/auto/accesscontrol/testjsondb.cpp b/tests/auto/accesscontrol/testjsondb.cpp
index 43399343..3f18ff58 100644
--- a/tests/auto/accesscontrol/testjsondb.cpp
+++ b/tests/auto/accesscontrol/testjsondb.cpp
@@ -47,13 +47,12 @@
#include <QDir>
#include <QTime>
-#include "json.h"
#include "jsondbpartition.h"
#include "jsondbsettings.h"
#include "../../shared/util.h"
-QT_USE_NAMESPACE_JSONDB
+QT_USE_NAMESPACE_JSONDB_PARTITION
/*
Ensure that a good result object contains the correct fields
@@ -103,6 +102,7 @@ private slots:
void testAccessControl();
void testFindAccessControl();
void testViewAccessControl();
+ void testIndexAccessControl();
private:
JsonDbQueryResult find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings = QJsonObject());
@@ -110,15 +110,13 @@ private:
JsonDbWriteResult update(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode = JsonDbPartition::OptimisticWrite);
JsonDbWriteResult remove(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode = JsonDbPartition::OptimisticWrite);
- QJsonValue readJsonFile(const QString &filename);
- QJsonValue readJson(const QByteArray& json);
void removeDbFiles();
private:
JsonDbPartition *mJsonDbPartition;
QStringList mNotificationsReceived;
QList<JsonDbObject> mContactList;
- JsonDbOwner *mOwner;
+ QScopedPointer<JsonDbOwner> mOwner;
};
const char *kFilename = "testdatabase";
@@ -151,10 +149,10 @@ void TestJsonDb::initTestCase()
QCoreApplication::setApplicationVersion("1.0");
removeDbFiles();
- mOwner = new JsonDbOwner(this);
+ mOwner.reset (new JsonDbOwner(this));
mOwner->setOwnerId(QStringLiteral("com.example.JsonDbTest"));
- mJsonDbPartition = new JsonDbPartition(kFilename, QStringLiteral("com.example.JsonDbTest"), mOwner, this);
+ mJsonDbPartition = new JsonDbPartition(kFilename, QStringLiteral("com.example.JsonDbTest"), mOwner.data(), this);
mJsonDbPartition->open();
}
@@ -175,7 +173,8 @@ void TestJsonDb::cleanup()
JsonDbQueryResult TestJsonDb::find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings)
{
- return mJsonDbPartition->queryObjects(owner, JsonDbQuery::parse(query, bindings));
+ QScopedPointer<JsonDbQuery> q(JsonDbQuery::parse(query, bindings));
+ return mJsonDbPartition->queryObjects(owner, q.data());
}
JsonDbWriteResult TestJsonDb::create(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
@@ -220,7 +219,7 @@ void TestJsonDb::capabilities()
QJsonObject capabilities(object.value("capabilities").toObject());
owner->setCapabilities(capabilities, mJsonDbPartition);
} else {
- JsonDbWriteResult result = create(mOwner, object);
+ JsonDbWriteResult result = create(mOwner.data(), object);
verifyGoodResult(result);
}
}
@@ -235,7 +234,7 @@ void TestJsonDb::allowAll()
// can delete me when this goes away
jsondbSettings->setEnforceAccessControl(true);
- JsonDbOwner *owner = new JsonDbOwner();
+ QScopedPointer<JsonDbOwner> owner(new JsonDbOwner());
owner->setAllowedObjects(QLatin1String("all"), QLatin1String("read"), QStringList());
owner->setAllowedObjects(QLatin1String("all"), QLatin1String("write"), QStringList());
owner->setStorageQuota(-1);
@@ -243,14 +242,14 @@ void TestJsonDb::allowAll()
JsonDbObject toPut;
toPut.insert("_type", QLatin1String("TestObject"));
- JsonDbWriteResult result = create(owner, toPut);
+ JsonDbWriteResult result = create(owner.data(), toPut);
verifyErrorResult(result);
JsonDbObject toPut2;
toPut2.insert("_type", QLatin1String("TestObject"));
- owner->setAllowAll(true);
- result = create(owner, toPut2);
+ owner.data()->setAllowAll(true);
+ result = create(owner.data(), toPut2);
verifyGoodResult(result);
mJsonDbPartition->removeIndex("TestObject");
@@ -276,7 +275,7 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("create-test-type"));
item.insert("access-control-test", 22);
- JsonDbWriteResult result = create(mOwner, item);
+ JsonDbWriteResult result = create(mOwner.data(), item);
verifyErrorResult(result);
@@ -284,14 +283,14 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("Contact"));
item.insert("access-control-test", 23);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
item.insert("access-control-test", 24);
- result = update(mOwner, item);
+ result = update(mOwner.data(), item);
verifyGoodResult(result);
- result = remove(mOwner, item);
+ result = remove(mOwner.data(), item);
verifyGoodResult(result);
// Test some %owner and %typeDomain horror
@@ -304,7 +303,7 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.foo.bar.FooType"));
item.insert("access-control-test", 25);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
QJsonValue uuid = item.value(JsonDbString::kUuidStr);
@@ -321,7 +320,7 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.foo.bar.FooType"));
item.insert("access-control-test", 26);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyErrorResult(result);
@@ -329,12 +328,12 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kUuidStr, uuid);
item.insert("access-control-test", 27);
- result = update(mOwner, item);
+ result = update(mOwner.data(), item);
verifyErrorResult(result);
// .. or remove
item.insert(JsonDbString::kUuidStr, uuid);
- result = remove(mOwner, item);
+ result = remove(mOwner.data(), item);
verifyErrorResult(result);
// Positive tests
@@ -344,10 +343,10 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.foo.FooType"));
item.insert("access-control-test", 28);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
- result = remove(mOwner, item);
+ result = remove(mOwner.data(), item);
verifyGoodResult(result);
item.remove(JsonDbString::kUuidStr);
@@ -356,14 +355,14 @@ void TestJsonDb::testAccessControl()
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.FooType"));
item.insert("access-control-test", 29);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
item.insert("access-control-test", 30);
- result = update(mOwner, item);
+ result = update(mOwner.data(), item);
verifyGoodResult(result);
- result = remove(mOwner, item);
+ result = remove(mOwner.data(), item);
verifyGoodResult(result);
jsondbSettings->setEnforceAccessControl(false);
}
@@ -375,12 +374,12 @@ void TestJsonDb::testFindAccessControl()
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QLatin1String("find-access-control-test-type"));
item.insert("find-access-control-test", 50);
- JsonDbWriteResult result = create(mOwner, item);
+ JsonDbWriteResult result = create(mOwner.data(), item);
verifyGoodResult(result);
item.remove(JsonDbString::kUuidStr);
item.insert(JsonDbString::kTypeStr, QLatin1String("Contact"));
item.insert("find-access-control-test", 51);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
QJsonObject contactsCapabilities;
@@ -390,12 +389,12 @@ void TestJsonDb::testFindAccessControl()
mOwner->setAllowAll(false);
mOwner->setCapabilities(contactsCapabilities, mJsonDbPartition);
- JsonDbQueryResult queryResult = find(mOwner, QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("find-access-control-test-type"));
+ JsonDbQueryResult queryResult = find(mOwner.data(), QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("find-access-control-test-type"));
verifyGoodQueryResult(queryResult);
QVERIFY(queryResult.length.toDouble() < 1);
- queryResult= find(mOwner, QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("Contact"));
+ queryResult= find(mOwner.data(), QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("Contact"));
verifyGoodQueryResult(queryResult);
QVERIFY(queryResult.length.toDouble() > 0);
@@ -405,13 +404,13 @@ void TestJsonDb::testFindAccessControl()
item.remove(JsonDbString::kUuidStr);
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.foo.bar.FooType"));
item.insert("find-access-control-test", 55);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
item.remove(JsonDbString::kUuidStr);
item.insert(JsonDbString::kTypeStr, QLatin1String("com.example.foo.FooType"));
item.insert("find-access-control-test", 56);
- result = create(mOwner, item);
+ result = create(mOwner.data(), item);
verifyGoodResult(result);
mOwner->setOwnerId(QStringLiteral("com.example.foo.App"));
@@ -423,12 +422,12 @@ void TestJsonDb::testFindAccessControl()
mOwner->setAllowAll(false);
mOwner->setCapabilities(ownDomainCapabilities, mJsonDbPartition);
- queryResult = find(mOwner, QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("com.example.foo.bar.FooType"));
+ queryResult = find(mOwner.data(), QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("com.example.foo.bar.FooType"));
verifyGoodQueryResult(queryResult);
QVERIFY(queryResult.length.toDouble() < 1);
- queryResult= find(mOwner, QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("com.example.foo.FooType"));
+ queryResult= find(mOwner.data(), QString("[?%1=\"%2\"]").arg(JsonDbString::kTypeStr).arg("com.example.foo.FooType"));
verifyGoodQueryResult(queryResult);
QVERIFY(queryResult.length.toDouble() > 0);
@@ -445,7 +444,7 @@ void TestJsonDb::testViewAccessControl()
QJsonArray defs(readJsonFile(":/security/json/capabilities-view.json").toArray());
for (int i = 0; i < defs.size(); ++i) {
JsonDbObject object(defs.at(i).toObject());
- JsonDbWriteResult result = create(mOwner, object);
+ JsonDbWriteResult result = create(mOwner.data(), object);
verifyGoodResult(result);
}
@@ -460,7 +459,7 @@ void TestJsonDb::testViewAccessControl()
defs = readJsonFile(":/security/json/view-test.json").toArray();
for (int i = 0; i < defs.size(); ++i) {
JsonDbObject object(defs.at(i).toObject());
- JsonDbWriteResult result = create(mOwner, object);
+ JsonDbWriteResult result = create(mOwner.data(), object);
verifyGoodResult(result);
}
@@ -474,48 +473,73 @@ void TestJsonDb::testViewAccessControl()
defs = readJsonFile(":/security/json/view-test2.json").toArray();
for (int i = 0; i < defs.size(); ++i) {
JsonDbObject object(defs.at(i).toObject());
- JsonDbWriteResult result = create(mOwner, object);
+ JsonDbWriteResult result = create(mOwner.data(), object);
verifyErrorResult(result);
}
}
-QStringList strings = (QStringList()
- << "abc"
- << "def"
- << "deaf"
- << "leaf"
- << "DEAF"
- << "LEAF"
- << "ghi"
- << "foo/bar");
-
-QStringList patterns = (QStringList()
- );
+/*
+ * Create Index objects and check access control
+ */
-QJsonValue TestJsonDb::readJsonFile(const QString& filename)
+void TestJsonDb::testIndexAccessControl()
{
- QString filepath = filename;
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString() << json;
+ jsondbSettings->setEnforceAccessControl(false);
+ QJsonArray defs(readJsonFile(":/security/json/capabilities-indexes.json").toArray());
+ for (int i = 0; i < defs.size(); ++i) {
+ JsonDbObject object(defs.at(i).toObject());
+ JsonDbWriteResult result = create(mOwner.data(), object);
+ verifyGoodResult(result);
}
- QVariant v = parser.result();
- return QJsonValue::fromVariant(v);
-}
-QJsonValue TestJsonDb::readJson(const QByteArray& json)
-{
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << parser.errorString();
+ JsonDbWriteResult result;
+
+ defs = readJsonFile(":/security/json/index-test.json").toArray();
+ for (int i = 0; i < defs.size(); ++i) {
+ JsonDbObject object(defs.at(i).toObject());
+ result = create(mOwner.data(), object);
+ verifyGoodResult(result);
+ result = remove(mOwner.data(), object);
+ }
+
+ jsondbSettings->setEnforceAccessControl(true);
+ QJsonObject indexCapabilities;
+ QJsonArray value;
+ value.append (QLatin1String("rw"));
+ indexCapabilities.insert (QLatin1String("indexes"), value);
+ mOwner->setAllowAll(false);
+ mOwner->setCapabilities(indexCapabilities, mJsonDbPartition);
+
+ for (int i = 0; i < defs.size(); ++i) {
+ JsonDbObject object(defs.at(i).toObject());
+ result = create(mOwner.data(), object);
+ if (i<2){
+ verifyGoodResult(result);
+ result = remove(mOwner.data(), object);
+ } else {
+ // Third one should fail as there is no objectType given
+ verifyErrorResult(result);
+ }
+ }
+
+ QJsonObject indexCapabilities2;
+ QJsonArray value2;
+ value2.append (QLatin1String("rw"));
+ indexCapabilities2.insert (QLatin1String("noindexes"), value2);
+ mOwner->setAllowAll(false);
+ mOwner->setCapabilities(indexCapabilities2, mJsonDbPartition);
+
+ for (int i = 0; i < defs.size(); ++i) {
+ JsonDbObject object(defs.at(i).toObject());
+ result = create(mOwner.data(), object);
+ if (i<1){
+ verifyGoodResult(result);
+ result = remove(mOwner.data(), object);
+ } else {
+ // Second & Third should fail as there is no objectType given
+ verifyErrorResult(result);
+ }
}
- QVariant v = parser.result();
- return QJsonObject::fromVariantMap(v.toMap());
}
void TestJsonDb::notified(const QString nid, const JsonDbObject &o, const QString action)
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index dc243370..9d3ad2e2 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,7 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = \
client \
- daemon \
+ partition \
accesscontrol \
qbtree \
jsondb-listmodel \
@@ -11,8 +11,9 @@ SUBDIRS = \
jsondbpartition \
jsondbnotification \
jsondbqueryobject \
- jsondbchangessinceobject \
queries \
+ qjsondbrequest \
qjsondbwatcher \
+ qjsondbflushrequest \
jsonstream \
hbtree
diff --git a/tests/auto/client/client.pro b/tests/auto/client/client.pro
index 8ea5097f..765bdbc1 100644
--- a/tests/auto/client/client.pro
+++ b/tests/auto/client/client.pro
@@ -5,7 +5,6 @@ CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
@@ -15,3 +14,6 @@ NSS_PREFIX = $$(NSS_PREFIX)
DEFINES += NSS_PREFIX=\\\"$$NSS_PREFIX\\\"
SOURCES += test-jsondb-client.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/client/json/index-test.json b/tests/auto/client/json/index-test.json
index 102d85eb..5b4579ea 100644
--- a/tests/auto/client/json/index-test.json
+++ b/tests/auto/client/json/index-test.json
@@ -1,11 +1,13 @@
[
{
"_type": "Index",
+ "objectType": "com.test.indextest",
"propertyName": "test1",
"propertyType": "string"
},
{
"_type": "Index",
+ "objectType": "com.test.indextest",
"propertyName": "test2.nested",
"propertyType": "string"
},
diff --git a/tests/auto/client/partitions.json b/tests/auto/client/partitions.json
new file mode 100644
index 00000000..05222ec7
--- /dev/null
+++ b/tests/auto/client/partitions.json
@@ -0,0 +1,5 @@
+[
+ { "name" : "test-jsondb-client" },
+ { "name" : "com.example.autotest.Partition1" },
+ { "name" : "com.example.autotest.Partition2" }
+]
diff --git a/tests/auto/client/test-jsondb-client.cpp b/tests/auto/client/test-jsondb-client.cpp
index 81290c56..13d353a5 100644
--- a/tests/auto/client/test-jsondb-client.cpp
+++ b/tests/auto/client/test-jsondb-client.cpp
@@ -67,8 +67,6 @@
#include "jsondb-object.h"
#include "jsondb-error.h"
-#include "json.h"
-
#include "util.h"
#include "clientwrapper.h"
@@ -90,6 +88,8 @@ public:
private slots:
void initTestCase();
void cleanupTestCase();
+ void init();
+ void cleanup();
void connectionStatus();
@@ -248,7 +248,7 @@ void TestJsonDbClient::initTestCase()
arg_list << "-enforce-access-control";
arg_list << "-base-name";
arg_list << QString::fromLatin1(dbfileprefix);
- mProcess = launchJsonDbDaemonDetached(JSONDB_DAEMON_BASE, QString("testjsondb_%1").arg(getpid()), arg_list);
+ mProcess = launchJsonDbDaemonDetached(JSONDB_DAEMON_BASE, QString("testjsondb_%1").arg(getpid()), arg_list, __FILE__);
#endif
#if !defined(Q_OS_MAC)
if (wasRoot) {
@@ -256,7 +256,7 @@ void TestJsonDbClient::initTestCase()
JsonDbObject capa_obj;
capa_obj.insert(QLatin1String("_type"), QLatin1String("Capability"));
capa_obj.insert(QLatin1String("name"), QLatin1String("User"));
- capa_obj.insert(QLatin1String("partition"), QLatin1String(dbfileprefix) + QLatin1String(".System"));
+ capa_obj.insert(QLatin1String("partition"), QLatin1String("default"));
QVariantMap access_rules;
QVariantMap rw_rule;
rw_rule.insert(QLatin1String("read"), (QStringList() << QLatin1String("[*]")));
@@ -348,14 +348,7 @@ void TestJsonDbClient::initTestCase()
waitForResponse1(id);
// Add a schemaValidation tests object (must be done as root)
- QFile schemaFile(findFile("create-test.json"));
- schemaFile.open(QIODevice::ReadOnly);
- QByteArray json = schemaFile.readAll();
- schemaFile.close();
- JsonReader parser;
- bool ok = parser.parse(json);
- QVERIFY2(ok, parser.errorString().toLocal8Bit());
- QVariantMap schemaBody = parser.result().toMap();
+ QVariantMap schemaBody = readJsonFile(findFile("create-test.json")).toObject().toVariantMap();
//qDebug() << "schemaBody" << schemaBody;
QVariantMap schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
@@ -462,7 +455,6 @@ void TestJsonDbClient::initTestCase()
}
}
#endif
- connectToServer();
}
void TestJsonDbClient::cleanupTestCase()
@@ -516,6 +508,19 @@ void TestJsonDbClient::cleanupTestCase()
#endif
}
+void TestJsonDbClient::init()
+{
+ connectToServer();
+}
+
+void TestJsonDbClient::cleanup()
+{
+ if (mClient) {
+ delete mClient;
+ mClient = NULL;
+ }
+}
+
void TestJsonDbClient::connectionStatus()
{
JsonDbConnection *connection = new JsonDbConnection;
@@ -672,15 +677,15 @@ void TestJsonDbClient::update()
item[QLatin1String("name")] = QLatin1String("fail");
id = mClient->update(item1);
- // Should fail because of access control (error code 13)
- waitForResponse2(id, 13);
+ // Should fail because of access control
+ waitForResponse2(id, JsonDbError::OperationNotPermitted);
item1.insert(QLatin1String("_type"), QLatin1String("com.test.FooType"));
id = mClient->update(item1);
- // Should fail because of access control (error code 13)
+ // Should fail because of access control
// The new _type is ok, but the old _type is not
- waitForResponse2(id, 13);
+ waitForResponse2(id, JsonDbError::OperationNotPermitted);
}
}
@@ -785,14 +790,7 @@ void TestJsonDbClient::find()
void TestJsonDbClient::index()
{
- QFile dataFile(":/json/client/index-test.json");
- dataFile.open(QIODevice::ReadOnly);
- QByteArray json = dataFile.readAll();
- dataFile.close();
- JsonReader parser;
- bool ok = parser.parse(json);
- QVERIFY2(ok, parser.errorString().toLocal8Bit());
- QVariantList data = parser.result().toList();
+ QVariantList data = readJsonFile(":/json/client/index-test.json").toArray().toVariantList();
int id = mClient->create(data);
waitForResponse1(id);
@@ -1160,14 +1158,7 @@ void TestJsonDbClient::schemaValidation()
{
int id;
if (!wasRoot) {
- QFile schemaFile(findFile("create-test.json"));
- schemaFile.open(QIODevice::ReadOnly);
- QByteArray json = schemaFile.readAll();
- schemaFile.close();
- JsonReader parser;
- bool ok = parser.parse(json);
- QVERIFY2(ok, parser.errorString().toLocal8Bit());
- QVariantMap schemaBody = parser.result().toMap();
+ QVariantMap schemaBody = readJsonFile(findFile("create-test.json")).toObject().toVariantMap();
//qDebug() << "schemaBody" << schemaBody;
QVariantMap schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
@@ -1307,17 +1298,11 @@ void TestJsonDbClient::notifyMultiple()
void TestJsonDbClient::mapNotification()
{
- QFile jsonFile(":/json/auto/daemon/json/map-reduce.json");
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- QVERIFY(ok);
-
+ QVariantList list = readJsonFile(":/json/auto/partition/json/map-reduce.json").toArray().toVariantList();
QList<QVariantMap> mapsReduces;
QList<QVariantMap> schemas;
QMap<QString, QVariantMap> toDelete;
- waitForResponse1(mClient->create(parser.result().toList()));
+ waitForResponse1(mClient->create(list));
QVariantList created = mData.toList();
foreach (const QVariant &c, created) {
@@ -1406,9 +1391,6 @@ void TestJsonDbClient::changesSince()
QVariantList results(data["changes"].toList());
QCOMPARE(results.count(), 2);
- JsonWriter writer;
- //qDebug() << writer.toByteArray(results[0]);
- //qDebug() << writer.toByteArray(results[1]);
QVERIFY(results[0].toMap()["before"].toMap().isEmpty());
QVERIFY(results[1].toMap()["before"].toMap().isEmpty());
@@ -1590,24 +1572,7 @@ void TestJsonDbClient::partition()
const QString firstPartitionName = "com.example.autotest.Partition1";
const QString secondPartitionName = "com.example.autotest.Partition2";
- QVariantMap item;
- item.insert(JsonDbString::kTypeStr, "Partition");
- item.insert("name", firstPartitionName);
- id = mClient->create(item);
- waitForResponse1(id);
- QVERIFY(mData.toMap().contains("_uuid"));
- QVariant firstPartitionUuid = mData.toMap().value("_uuid");
-
- item = QVariantMap();
- item.insert(JsonDbString::kTypeStr, "Partition");
- item.insert("name", secondPartitionName);
- id = mClient->create(item);
- waitForResponse1(id);
- QVERIFY(mData.toMap().contains("_uuid"));
- QVariant secondPartitionUuid = mData.toMap().value("_uuid");
-
-
- item = QVariantMap();
+ QVariantMap item = QVariantMap();
item.insert(JsonDbString::kTypeStr, "Foobar");
item.insert("one", "one");
id = mClient->create(item, firstPartitionName);
@@ -1829,7 +1794,7 @@ void TestJsonDbClient::sigstop()
QStringList argList = QStringList() << "-sigstop";
argList << QString::fromLatin1("sigstop.db");
- QProcess *jsondb = launchJsonDbDaemon(JSONDB_DAEMON_BASE, QString("testjsondb_sigstop%1").arg(getpid()), argList);
+ QProcess *jsondb = launchJsonDbDaemon(JSONDB_DAEMON_BASE, QString("testjsondb_sigstop%1").arg(getpid()), argList, __FILE__);
int status;
::waitpid(jsondb->pid(), &status, WUNTRACED);
QVERIFY(WIFSTOPPED(status));
diff --git a/tests/auto/daemon/daemon.pro b/tests/auto/daemon/daemon.pro
deleted file mode 100644
index ec251ea2..00000000
--- a/tests/auto/daemon/daemon.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-TARGET = tst_daemon
-CONFIG += debug
-
-QT = network qml testlib
-CONFIG -= app_bundle
-CONFIG += testcase
-
-INCLUDEPATH += $$PWD/../../../src/daemon
-LIBS += -L$$QT.jsondb.libs
-
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-include($$PWD/../../../src/daemon/daemon.pri)
-RESOURCES += json-validation.qrc daemon.qrc
-
-SOURCES += \
- testjsondb.cpp \
diff --git a/tests/auto/jsondb-listmodel/jsondb-listmodel.pro b/tests/auto/jsondb-listmodel/jsondb-listmodel.pro
index 07d4eafc..fceabaaf 100644
--- a/tests/auto/jsondb-listmodel/jsondb-listmodel.pro
+++ b/tests/auto/jsondb-listmodel/jsondb-listmodel.pro
@@ -8,7 +8,6 @@ CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
diff --git a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
index 257b4323..f0ba021a 100644
--- a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
+++ b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
@@ -48,7 +48,6 @@
#include <QQmlComponent>
#include <QQmlContext>
#include <QDir>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-listmodel";
ModelData::ModelData(): engine(0), component(0), model(0)
@@ -89,20 +88,6 @@ void TestJsonDbListModel::deleteDbFiles()
}
}
-QVariant TestJsonDbListModel::readJsonFile(const QString& filename)
-{
- QString filepath = findFile(filename);
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- return parser.result();
-}
-
void TestJsonDbListModel::connectListModel(JsonDbListModel *model)
{
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)));
@@ -119,7 +104,7 @@ void TestJsonDbListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
mClient = new JsonDbClient(this);
connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
@@ -230,12 +215,13 @@ void TestJsonDbListModel::createItem()
waitForExitOrTimeout();
QCOMPARE(listModel->count(), 1);
+ mItemsCreated = 0;
item.insert("_type", __FUNCTION__);
item.insert("name", "Baker");
id = mClient->create(item);
waitForResponse1(id);
-
- waitForExitOrTimeout();;
+ if (!mItemsCreated)
+ waitForExitOrTimeout();;
QCOMPARE(listModel->count(), 2);
deleteModel(listModel);
}
@@ -382,10 +368,12 @@ void TestJsonDbListModel::deleteItem()
waitForExitOrTimeout();
QCOMPARE(listModel->rowCount(), 1);
+ mItemsCreated = 0;
item.insert("name", "Baker");
id = mClient->create(item);
waitForResponse1(id);
- waitForExitOrTimeout();
+ if (!mItemsCreated)
+ waitForExitOrTimeout();;
QCOMPARE(listModel->rowCount(), 2);
mWaitingForRowsRemoved = true;
@@ -677,7 +665,7 @@ void TestJsonDbListModel::totalRowCount()
void TestJsonDbListModel::listProperty()
{
- QVariant jsonData = readJsonFile("list-objects.json");
+ QVariant jsonData = readJsonFile(findFile("list-objects.json")).toVariant();
QVariantList itemList = jsonData.toList();
int id = 0;
for (int i = 0; i < itemList.count(); i++) {
diff --git a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h
index 96813049..a9d699f6 100644
--- a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h
+++ b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h
@@ -114,7 +114,6 @@ private:
QStringList getOrderValues(const JsonDbListModel *listModel);
JsonDbListModel *createModel();
void deleteModel(JsonDbListModel *model);
- QVariant readJsonFile(const QString &filename);
private:
QProcess *mProcess;
diff --git a/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro b/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
index eff7faa3..01e0ae4e 100644
--- a/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
+++ b/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbcachinglistmodel
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbcachinglistmodel.h
+HEADERS += testjsondbcachinglistmodel.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbcachinglistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbcachinglistmodel/partitions.json b/tests/auto/jsondbcachinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/auto/jsondbcachinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
index c11f048b..e7f534cd 100644
--- a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
+++ b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
@@ -45,7 +45,6 @@
#include "../../shared/util.h"
#include <QQmlListReference>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-cached-listmodel";
ModelData::ModelData(): engine(0), component(0), model(0)
@@ -56,18 +55,8 @@ ModelData::~ModelData()
{
if (model)
delete model;
- if (partition1)
- delete partition1;
- if (partition2)
- delete partition2;
-
if (component)
delete component;
- if (partitionComponent1)
- delete partitionComponent1;
- if (partitionComponent2)
- delete partitionComponent2;
-
if (engine)
delete engine;
}
@@ -75,12 +64,15 @@ ModelData::~ModelData()
const QString qmlProgram = QLatin1String(
"import QtQuick 2.0 \n"
"import QtJsonDb 1.0 as JsonDb \n"
- "signal callbackSignal(variant index, variant response)"
- "function updateItemCallback(index, response) { callbackSignal( index, response); }");
-
+ "JsonDb.JsonDbCachingListModel {"
+ "id: contactsModel; cacheSize: 200;"
+ "partitions: ["
+ "JsonDb.Partition {name: \"com.nokia.shared.1\"},"
+ "JsonDb.Partition {name: \"com.nokia.shared.2\"}"
+ "]"
+ "}");
TestJsonDbCachingListModel::TestJsonDbCachingListModel()
- : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false)
{
}
@@ -97,26 +89,11 @@ void TestJsonDbCachingListModel::deleteDbFiles()
nameFilter << "objectFile.bin" << "objectFile2.bin";
QFileInfoList databaseFiles = currentDir.entryInfoList(nameFilter, QDir::Files);
foreach (QFileInfo fileInfo, databaseFiles) {
- //qDebug() << "Deleted : " << fileInfo.fileName();
QFile file(fileInfo.fileName());
file.remove();
}
}
-QVariant TestJsonDbCachingListModel::readJsonFile(const QString& filename)
-{
- QString filepath = findFile(filename);
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- return parser.result();
-}
-
void TestJsonDbCachingListModel::connectListModel(QAbstractListModel *model)
{
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)));
@@ -135,31 +112,14 @@ void TestJsonDbCachingListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.1");
- int id = mClient->create(item);
- waitForResponse1(id);
-
- item.clear();
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.2");
- id = mClient->create(item);
- waitForResponse1(id);
-
+ if (mPluginPath.isEmpty())
+ qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
}
QAbstractListModel *TestJsonDbCachingListModel::createModel()
@@ -173,37 +133,12 @@ QAbstractListModel *TestJsonDbCachingListModel::createModel()
return 0;
}
newModel->component = new QQmlComponent(newModel->engine);
- newModel->component->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.JsonDbCachingListModel {signal callbackSignal(variant index, variant response); id: contactsModel; cacheSize: 200;}",
- QUrl());
+ newModel->component->setData(qmlProgram.toLocal8Bit(), QUrl());
+
newModel->model = newModel->component->create();
if (newModel->component->isError())
qDebug() << newModel->component->errors();
- QObject::connect(newModel->model, SIGNAL(callbackSignal(QVariant, QVariant)),
- this, SLOT(callbackSlot(QVariant, QVariant)));
-
- newModel->partitionComponent1 = new QQmlComponent(newModel->engine);
- newModel->partitionComponent1->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.Partition {name: \"com.nokia.shared.1\"}",
- QUrl());
- newModel->partition1 = newModel->partitionComponent1->create();
- if (newModel->partitionComponent1->isError())
- qDebug() << newModel->partitionComponent1->errors();
-
-
- newModel->partitionComponent2 = new QQmlComponent(newModel->engine);
- newModel->partitionComponent2->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.Partition {name: \"com.nokia.shared.2\"}",
- QUrl());
- newModel->partition2 = newModel->partitionComponent2->create();
- if (newModel->partitionComponent2->isError())
- qDebug() << newModel->partitionComponent2->errors();
-
- QQmlListReference partitions(newModel->model, "partitions", newModel->engine);
- partitions.append(newModel->partition1);
- partitions.append(newModel->partition2);
-
mModels.append(newModel);
return (QAbstractListModel*)(newModel->model);
}
@@ -230,26 +165,17 @@ void TestJsonDbCachingListModel::cleanupTestCase()
deleteDbFiles();
}
-void TestJsonDbCachingListModel::callbackSlot(QVariant error, QVariant response)
-{
- mCallbackReceived = true;
- callbackError = error.isValid();
- callbackMeta = response;
- callbackResponse = response.toMap().value("object");
- mEventLoop.quit();
-}
-
-void TestJsonDbCachingListModel::getIndex(int index)
+QVariant TestJsonDbCachingListModel::getIndex(QAbstractListModel *model, int index, int role)
{
- mCallbackReceived = false;
-
- const QString createString = QString("get(%1, function (error, response) {callbackSignal(error, response);});");
- const QString getString = QString(createString).arg(index);
- QQmlExpression expr(mModels.last()->engine->rootContext(), mModels.last()->model, getString);
- expr.evaluate().toInt();
-
- if (!mCallbackReceived)
- waitForCallback();
+ mWaitingForIndexChanged = true;
+ mWaitingForChanged = false;
+ mIndexWaited = index;
+ QVariant val = model->data(model->index(index), role);
+ while (!val.isValid()) {
+ waitForIndexChanged();
+ val = model->data(model->index(index), role);
+ }
+ return val;
}
int indexOf(QObject* object, const QString &uuid)
@@ -269,21 +195,21 @@ void TestJsonDbCachingListModel::createIndex(const QString &property, const QStr
item.insert("propertyName", property);
item.insert("propertyType", propertyType);
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
- id = mClient->create(item, "com.nokia.shared.2");
+ id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
}
-
// Create items in the model.
void TestJsonDbCachingListModel::createItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Arnie");
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
createIndex("name", "string");
@@ -301,25 +227,36 @@ void TestJsonDbCachingListModel::createItem()
// now start it working
QCOMPARE(listModel->rowCount(), 0);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+
QCOMPARE(listModel->rowCount(), 1);
QCOMPARE(listModel->property("cacheSize").toInt(), 200);
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), QLatin1String(__FUNCTION__));
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QLatin1String("Arnie"));
+ QVariant val = getIndex(listModel, 0, 0);
+ QCOMPARE(val.toString(), QLatin1String(__FUNCTION__));
+ val = getIndex(listModel, 0, 2);
+ QCOMPARE(val.toString(), QLatin1String("Arnie"));
item.clear();
item.insert("_type", __FUNCTION__);
item.insert("name", "Barney");
- id = mClient->create(item, "com.nokia.shared.1");
- waitForItemChanged();
+ mItemsCreated = 0;
+ id = create(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsCreated) {
+ mWaitingForRowsInserted = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRowsInserted, false);
QCOMPARE(listModel->rowCount(), 2);
- getIndex(1);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), QLatin1String(__FUNCTION__));
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QLatin1String("Barney"));
+ val = getIndex(listModel, 1, 0);
+ QCOMPARE(val.toString(), QLatin1String(__FUNCTION__));
+ val = getIndex(listModel, 1, 2);
+ QCOMPARE(val.toString(), QLatin1String("Barney"));
deleteModel(listModel);
}
@@ -327,132 +264,171 @@ void TestJsonDbCachingListModel::createItem()
// Populate model of 300 items two partitions.
void TestJsonDbCachingListModel::createModelTwoPartitions()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 300; i = i+2) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
for (int i=1; i < 300; i = i+2) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.2");
+ int id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
}
- createIndex("name", "string");
-
QAbstractListModel *listModel = createModel();
if (!listModel) return;
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("sortOrder", "[/name]");
+ listModel->setProperty("cacheSize", 50);
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
// now start it working
QCOMPARE(listModel->rowCount(), 0);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 300);
deleteModel(listModel);
}
-
-
// Create an item and then update it.
void TestJsonDbCachingListModel::updateItemClient()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item,"com.nokia.shared.1");
+ int id = create(item,"com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
if (!listModel) return;
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("sortOrder", "[/name]");
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
// now start it working
QCOMPARE(listModel->rowCount(), 0);
- waitForStateOrTimeout();
- QCOMPARE(listModel->rowCount(), 1);
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), QLatin1String(__FUNCTION__));
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QLatin1String("Charlie"));
+ QCOMPARE(listModel->rowCount(), 1);
- item.insert("_uuid", mLastUuid);
+ QVariant val = getIndex(listModel, 0, 0);
+ QCOMPARE(val.toString(), QLatin1String(__FUNCTION__));
+ val = getIndex(listModel, 0, 2);
+ QCOMPARE(val.toString(), QLatin1String("Charlie"));
+
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
item.insert("name", "Baker");
- mWaitingForDataChange = true;
-
- id = mClient->update(item, "com.nokia.shared.1");
- waitForItemChanged();
+ mItemsUpdated = 0;
+ id = update(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
QCOMPARE(listModel->rowCount(), 1);
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), QLatin1String(__FUNCTION__));
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QLatin1String("Baker"));
+ val = getIndex(listModel, 0, 0);
+ QCOMPARE(val.toString(), QLatin1String(__FUNCTION__));
+ val = getIndex(listModel, 0, 2);
+ QCOMPARE(val.toString(), QLatin1String("Baker"));
deleteModel(listModel);
}
void TestJsonDbCachingListModel::deleteItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
if (!listModel) return;
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("sortOrder", "[/name]");
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
// now start it working
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+
QCOMPARE(listModel->rowCount(), 1);
item.insert("name", "Baker");
- id = mClient->create(item, "com.nokia.shared.2");
+ mItemsCreated = 0;
+ id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
+ waitForItemsCreated(1);
QCOMPARE(listModel->rowCount(), 2);
- mWaitingForRowsRemoved = true;
- item.insert("_uuid", mLastUuid);
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged(true);
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
+ mItemsRemoved = 0;
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ while (!mItemsRemoved) {
+ mWaitingForRemoved = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRemoved, false);
QCOMPARE(listModel->rowCount(), 1);
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), QLatin1String(__FUNCTION__));
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QLatin1String("Charlie"));
+ QVariant val = getIndex(listModel, 0, 0);
+ QCOMPARE(val.toString(), QLatin1String(__FUNCTION__));
+ val = getIndex(listModel, 0, 2);
+ QCOMPARE(val.toString(), QLatin1String("Charlie"));
deleteModel(listModel);
}
void TestJsonDbCachingListModel::sortedQuery()
{
+ resetWaitFlags();
int id = 0;
for (int i = 0; i < 1000; i++) {
QVariantMap item;
item.insert("_type", "RandNumber");
item.insert("number", i);
- id = mClient->create(item,"com.nokia.shared.2");
+ id = create(item,"com.nokia.shared.2");
waitForResponse1(id);
}
@@ -467,27 +443,32 @@ void TestJsonDbCachingListModel::sortedQuery()
rolenames << "_uuid" << "_type" << "number";
listModel->setProperty("roleNames", rolenames);
listModel->setProperty("sortOrder", "[/number]");
+ listModel->setProperty("cacheSize", 100);
listModel->setProperty("query", "[?_type=\"RandNumber\"]");
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
- QCOMPARE(listModel->property("sortOrder").toString(), QString("[/number]"));
QCOMPARE(listModel->rowCount(), 1000);
+
for (int i = 0; i < 1000; i++) {
- getIndex(i);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), i);
+ QVariant num = getIndex(listModel, i, 2);
+ QCOMPARE(num.toInt(), i);
}
listModel->setProperty("sortOrder", "[\\number]");
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("sortOrder").toString(), QString("[\\number]"));
QCOMPARE(listModel->rowCount(), 1000);
for (int i = 0; i < 1000; i++) {
- getIndex(i);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 999-i);
+ QVariant num = getIndex(listModel, i, 2);
+ QCOMPARE(num.toInt(), 999-i);
}
listModel->setProperty("query", QString());
@@ -509,12 +490,13 @@ bool greaterThan(const QString &s1, const QString &s2)
void TestJsonDbCachingListModel::ordering()
{
+ resetWaitFlags();
for (int i = 9; i >= 1; --i) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("ordering", QString::number(i));
- int id = mClient->create(item, "com.nokia.shared.2");
+ int id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
}
@@ -524,22 +506,24 @@ void TestJsonDbCachingListModel::ordering()
createIndex("ordering", "string");
listModel->setProperty("sortOrder", "[/ordering]");
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "ordering");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
// now start it working
QCOMPARE(listModel->rowCount(), 0);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+ mItemsUpdated = 0;
QStringList expectedOrder = QStringList() << "1" << "2" << "3" << "4" <<
"5" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
{
- getIndex(4);
- QVariant uuid = callbackResponse.toMap().value("_uuid");
+ QVariant uuid = getIndex(listModel, 4, 1);
QVERIFY(!uuid.toString().isEmpty());
QVariantMap item;
@@ -547,16 +531,22 @@ void TestJsonDbCachingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("ordering", "99"); // move it to the end
- mClient->update(item, "com.nokia.shared.2");
+ int id = update(item, "com.nokia.shared.2");
+ waitForResponse1(id);
}
- waitForItemChanged();
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
+
+ mItemsUpdated = 0;
expectedOrder = QStringList() << "1" << "2" << "3" <<
"4" << "6" << "7" << "8" << "9" << "99";
QCOMPARE(getOrderValues(listModel), expectedOrder);
{
- getIndex(8);
- QVariant uuid =callbackResponse.toMap().value("_uuid");
+ QVariant uuid = getIndex(listModel, 8, 1);
QVERIFY(!uuid.toString().isEmpty());
QVariantMap item;
@@ -564,16 +554,21 @@ void TestJsonDbCachingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("ordering", "22"); // move it after "2"
- mClient->update(item, "com.nokia.shared.2");
+ int id = update(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ }
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
}
- waitForItemChanged();
+ QCOMPARE(mWaitingForChanged, false);
+ mItemsUpdated = 0;
expectedOrder = QStringList() << "1" << "2" << "22" << "3" <<
"4" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
{
- getIndex(5);
- QVariant uuid =callbackResponse.toMap().value("_uuid");
+ QVariant uuid = getIndex(listModel, 5, 1);
QVERIFY(!uuid.toString().isEmpty());
QVariantMap item;
@@ -581,9 +576,14 @@ void TestJsonDbCachingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("ordering", "0"); // move it to the beginning
- mClient->update(item, "com.nokia.shared.2");
+ int id = update(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ }
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
}
- waitForItemChanged();
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "0" << "1" << "2" << "22" << "3" <<
"4" << "7" << "8" << "9";
@@ -591,7 +591,9 @@ void TestJsonDbCachingListModel::ordering()
listModel->setProperty("sortOrder", "[\\ordering]");
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QStringList reverseOrder = expectedOrder;
qSort(reverseOrder.begin(), reverseOrder.end(), greaterThan);
@@ -599,17 +601,18 @@ void TestJsonDbCachingListModel::ordering()
QCOMPARE(getOrderValues(listModel), reverseOrder);
listModel->setProperty("sortOrder", "[/ordering]");
- waitForStateOrTimeout();
-
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(getOrderValues(listModel), expectedOrder);
deleteModel(listModel);
-
}
void TestJsonDbCachingListModel::checkRemoveNotification()
{
+ resetWaitFlags();
QVariantList itemList;
for (int i = 0; i < 50; i++) {
QVariantMap item;
@@ -618,7 +621,7 @@ void TestJsonDbCachingListModel::checkRemoveNotification()
item.insert("order", i);
itemList << item;
}
- int id = mClient->create(itemList,"com.nokia.shared.2");
+ int id = create(itemList,"com.nokia.shared.2");
waitForResponse1(id);
{
@@ -629,56 +632,63 @@ void TestJsonDbCachingListModel::checkRemoveNotification()
connectListModel(listModel);
listModel->setProperty("sortOrder", "[/order]");
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "_version"<< "name" << "order");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 50);
- getIndex(0);
- QVariant result = callbackResponse.toMap().value("order");
+ QVariant result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 0);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 9);
//Remove item at 0
QVariantMap item;
- getIndex(0);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_version", callbackResponse.toMap().value("_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged(true);
+ QVariant uuid = getIndex(listModel, 0, 1);
+ item.insert("_uuid", uuid);
+ QVariant version = getIndex(listModel, 0, 2);
+ item.insert("_version", version);
+ mItemsRemoved = 0;
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForItemsRemoved(1);
QCOMPARE(listModel->rowCount(), 49);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 10);
//Remove item at 9
- getIndex(9);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_version", callbackResponse.toMap().value("_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged(true);
+ uuid = getIndex(listModel, 9, 1);
+ item.insert("_uuid", uuid);
+ version = getIndex(listModel, 9, 2);
+ item.insert("_version", version);
+ mItemsRemoved = 0;
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForItemsRemoved(1);
QCOMPARE(listModel->rowCount(), 48);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 11);
//Remove item at 4
- getIndex(4);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_version", callbackResponse.toMap().value("_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged(true);
+ uuid = getIndex(listModel, 4, 1);
+ item.insert("_uuid", uuid);
+ version = getIndex(listModel, 9, 2);
+ item.insert("_version", version);
+ mItemsRemoved = 0;
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForItemsRemoved(1);
QCOMPARE(listModel->rowCount(), 47);
- getIndex(4);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 4, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 6);
@@ -688,6 +698,7 @@ void TestJsonDbCachingListModel::checkRemoveNotification()
void TestJsonDbCachingListModel::checkUpdateNotification()
{
+ resetWaitFlags();
QVariantList itemList;
for (int i = 0; i < 50; i++) {
if (i%2)
@@ -698,7 +709,7 @@ void TestJsonDbCachingListModel::checkUpdateNotification()
item.insert("order", i);
itemList << item;
}
- int id = mClient->create(itemList, "com.nokia.shared.1");
+ int id = create(itemList, "com.nokia.shared.1");
waitForResponse1(id);
{
@@ -713,106 +724,138 @@ void TestJsonDbCachingListModel::checkUpdateNotification()
listModel->setProperty("roleNames", roleNames);
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 25);
- getIndex(0);
- QVariant result = callbackResponse.toMap().value("order");
+ QVariant result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 0);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 18);
//Update item at 0
QVariantMap item;
- getIndex(0);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_type", callbackResponse.toMap().value("_type"));
- item.insert("name", callbackResponse.toMap().value("name"));
+ QVariant uuid = getIndex(listModel, 0, 1);
+ item.insert("_uuid", uuid);
+ QVariant _type = getIndex(listModel, 0, 0);
+ item.insert("_type", _type);
+ QVariant _version = getIndex(listModel, 0, 2);
+ item.insert("_version", _version);
+ QVariant name = getIndex(listModel, 0, 3);
+ item.insert("name", name);
item.insert("order", 1);
- id = mClient->update(item, "com.nokia.shared.1");
- waitForItemChanged();
+ mItemsUpdated = 0;
+ id = update(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
QCOMPARE(listModel->rowCount(), 25);
- getIndex(0);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 1);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 18);
//Update item at 9
item.clear();
- getIndex(9);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_type", callbackResponse.toMap().value("_type"));
- item.insert("name", callbackResponse.toMap().value("name"));
+ uuid = getIndex(listModel, 9, 1);
+ item.insert("_uuid", uuid);
+ _type = getIndex(listModel, 9, 0);
+ item.insert("_type", _type);
+ _version = getIndex(listModel, 9, 2);
+ item.insert("_version", _version);
+ name = getIndex(listModel, 9, 3);
+ item.insert("name", name);
item.insert("order", 19);
- id = mClient->update(item,"com.nokia.shared.1");
- waitForItemChanged();
+ mItemsUpdated = 0;
+ id = update(item,"com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
item.clear();
- getIndex(9);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_type", callbackResponse.toMap().value("_type"));
- item.insert("name", callbackResponse.toMap().value("name"));
+ uuid = getIndex(listModel, 9, 1);
+ item.insert("_uuid", uuid);
+ _type = getIndex(listModel, 9, 0);
+ item.insert("_type", _type);
+ name = getIndex(listModel, 9, 3);
+ item.insert("name", name);
+ _version = getIndex(listModel, 9, 2);
+ item.insert("_version", _version);
item.insert("order", 19);
- id = mClient->update(item,"com.nokia.shared.1");
- waitForItemChanged();
+ mItemsUpdated = 0;
+ id = update(item,"com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
QCOMPARE(listModel->rowCount(), 25);
- getIndex(0);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 1);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 19);
//Update item at 9
- getIndex(9);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_type", callbackResponse.toMap().value("_type"));
- item.insert("name", callbackResponse.toMap().value("name"));
+ item.clear();
+ uuid = getIndex(listModel, 9, 1);
+ item.insert("_uuid", uuid);
+ _type = getIndex(listModel, 9, 0);
+ item.insert("_type", _type);
+ name = getIndex(listModel, 9, 3);
+ item.insert("name", name);
item.insert("order", 59);
- id = mClient->update(item, "com.nokia.shared.1");
- waitForItemChanged();
-
+ mItemsUpdated = 0;
+ id = update(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
QCOMPARE(listModel->rowCount(), 25);
- getIndex(0);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 1);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 20);
//Update item at 8
- getIndex(8);
- item.insert("_uuid", callbackResponse.toMap().value("_uuid"));
- item.insert("_type", callbackResponse.toMap().value("_type"));
- item.insert("name", callbackResponse.toMap().value("name"));
+ item.clear();
+ uuid = getIndex(listModel, 8, 1);
+ item.insert("_uuid", uuid);
+ _type = getIndex(listModel, 8, 0);
+ item.insert("_type", _type);
+ name = getIndex(listModel, 8, 3);
+ item.insert("name", name);
item.insert("order", 17);
- id = mClient->update(item, "com.nokia.shared.1");
- waitForItemChanged();
-
+ mItemsUpdated = 0;
+ id = update(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
QCOMPARE(listModel->rowCount(), 25);
- getIndex(8);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 8, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 17);
- getIndex(0);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 0, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 1);
- getIndex(9);
- result = callbackResponse.toMap().value("order");
+ result = getIndex(listModel, 9, 4);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 20);
@@ -822,15 +865,16 @@ void TestJsonDbCachingListModel::checkUpdateNotification()
void TestJsonDbCachingListModel::totalRowCount()
{
+ resetWaitFlags();
int id = 0;
QVariantList insertedItems;
for (int i = 0; i < 10; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- id = mClient->create(item, "com.nokia.shared.1");
+ id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
- insertedItems << mData;
+ insertedItems << lastResult;
}
QAbstractListModel *listModel = createModel();
@@ -839,55 +883,120 @@ void TestJsonDbCachingListModel::totalRowCount()
connectListModel(listModel);
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "order");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("sortOrder", "[/order]");
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 10);
+ mItemsCreated = 0;
for (int i = 10; i < 50; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- mClient->create(item, "com.nokia.shared.2");
+ id = create(item, "com.nokia.shared.2");
+ waitForResponse1(id);
}
waitForItemsCreated(40);
+ //wait for the last one
+ if (id != lastRequestId)
+ waitForResponse1(id);
QCOMPARE(listModel->rowCount(), 50);
-
- createIndex("order", "number");
-
// Change sort order
listModel->setProperty("sortOrder", "[\\order]");
+
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 50);
// Delete the first 10 items
+ mItemsRemoved = 0;
foreach (QVariant item, insertedItems) {
- mWaitingForRowsRemoved = true;
- id = mClient->remove(item.toMap(), "com.nokia.shared.1");
- waitForItemChanged(true);
+ id = remove(item.toMap(), "com.nokia.shared.1");
+ waitForResponse1(id);
}
+ waitForItemsRemoved(10);
QCOMPARE(listModel->rowCount(), 40);
deleteModel(listModel);
}
+void TestJsonDbCachingListModel::checkAddNotification()
+{
+ resetWaitFlags();
+ int id = 0;
+ QVariantList insertedItems;
+ for (int i = 0; i < 10; i++) {
+ QVariantMap item;
+ item.insert("_type", __FUNCTION__);
+ item.insert("order", i);
+ id = create(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ }
+
+ QAbstractListModel *listModel = createModel();
+ if (!listModel)
+ return;
+
+ connectListModel(listModel);
+
+ QStringList roleNames = (QStringList() << "_type" << "_uuid" << "order");
+ listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("sortOrder", "[/order]");
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
+
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+
+ QCOMPARE(listModel->rowCount(), 10);
+
+ mItemsCreated = 0;
+ QVariantList items;
+ for (int i = 0; i < 50; i++) {
+ QVariantMap item;
+ item.insert("_type", __FUNCTION__);
+ item.insert("order", i);
+ items << item;
+ }
+ id = create(items, "com.nokia.shared.2");
+ items.clear();
+ waitForResponse1(id);
+ for (int i = 0; i < 50; i++) {
+ QVariantMap item;
+ item.insert("_type", __FUNCTION__);
+ item.insert("order", i);
+ items << item;
+ }
+ id = create(items, "com.nokia.shared.1");
+ waitForResponse1(id);
+ waitForItemsCreated(100);
+ QCOMPARE(listModel->rowCount(), 110);
+
+ deleteModel(listModel);
+}
+
void TestJsonDbCachingListModel::listProperty()
{
- QVariant jsonData = readJsonFile("list-objects.json");
+ resetWaitFlags();
+ QVariant jsonData = readJsonFile(findFile("list-objects.json")).toVariant();
QVariantList itemList = jsonData.toList();
int id = 0;
for (int i = 0; i < itemList.count()/2; i++) {
- id = mClient->create(itemList[i].toMap(), "com.nokia.shared.1");
+ id = create(itemList[i].toMap(), "com.nokia.shared.1");
waitForResponse1(id);
}
for (int i = itemList.count()/2; i < itemList.count(); i++) {
- id = mClient->create(itemList[i].toMap(), "com.nokia.shared.2");
+ id = create(itemList[i].toMap(), "com.nokia.shared.2");
waitForResponse1(id);
}
@@ -900,21 +1009,28 @@ void TestJsonDbCachingListModel::listProperty()
connectListModel(listModel);
QString type = itemList[0].toMap()["_type"].toString();
listModel->setProperty("sortOrder", "[/features.0.properties.0.description]");
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(type));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "features.0.properties.0.description"<< "features.0.feature");
listModel->setProperty("roleNames", roleNames);
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(type));
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), itemList.count());
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), type);
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("properties").toList().at(0).toMap().value("description").toString(), QLatin1String("Facebook account provider"));
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("feature").toString(), QLatin1String("provide Facebook"));
- getIndex(1);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), type);
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("properties").toList().at(0).toMap().value("description").toString(), QLatin1String("Gmail account provider"));
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("feature").toString(), QLatin1String("provide Gmail"));
+ QVariant _type = getIndex(listModel, 0, 0);
+ QCOMPARE(_type.toString(), type);
+ QVariant featuresDesc = getIndex(listModel, 0, 2);
+ QCOMPARE(featuresDesc.toString(), QLatin1String("Facebook account provider"));
+ QVariant features = getIndex(listModel, 0, 3);
+ QCOMPARE(features.toString(), QLatin1String("provide Facebook"));
+
+ _type = getIndex(listModel, 1, 0);
+ QCOMPARE(_type.toString(), type);
+ featuresDesc = getIndex(listModel, 1, 2);
+ QCOMPARE(featuresDesc.toString(), QLatin1String("Gmail account provider"));
+ features = getIndex(listModel, 1, 3);
+ QCOMPARE(features.toString(), QLatin1String("provide Gmail"));
deleteModel(listModel);
@@ -924,33 +1040,42 @@ void TestJsonDbCachingListModel::listProperty()
connectListModel(listModel);
type = itemList[0].toMap()["_type"].toString();
listModel->setProperty("sortOrder", "[/features.0.properties.0.description]");
- listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(type));
roleNames.clear();
roleNames = (QStringList() << "_type" << "_uuid" << "features[0].properties[0].description"<< "features[0].supported[0]");
listModel->setProperty("roleNames", roleNames);
- waitForStateOrTimeout();
+ listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(type));
+
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), itemList.count());
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), type);
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("properties").toList().at(0).toMap().value("description").toString(), QLatin1String("Facebook account provider"));
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("supported").toList().at(0).toString(), QLatin1String("share"));
- getIndex(1);
- QCOMPARE(callbackResponse.toMap().value("_type").toString(), type);
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("properties").toList().at(0).toMap().value("description").toString(), QLatin1String("Gmail account provider"));
- QCOMPARE(callbackResponse.toMap().value("features").toList().at(0).toMap().value("supported").toList().at(0).toString(), QLatin1String("share"));
+ _type = getIndex(listModel, 0, 0);
+ QCOMPARE(_type.toString(), type);
+ featuresDesc = getIndex(listModel, 0, 2);
+ QCOMPARE(featuresDesc.toString(), QLatin1String("Facebook account provider"));
+ features = getIndex(listModel, 0, 3);
+ QCOMPARE(features.toString(), QLatin1String("share"));
+
+ _type = getIndex(listModel, 1, 0);
+ QCOMPARE(_type.toString(), type);
+ featuresDesc = getIndex(listModel, 1, 2);
+ QCOMPARE(featuresDesc.toString(), QLatin1String("Gmail account provider"));
+ features = getIndex(listModel, 1, 3);
+ QCOMPARE(features.toString(), QLatin1String("share"));
deleteModel(listModel);
}
void TestJsonDbCachingListModel::changeQuery()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 10; i++) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
@@ -965,7 +1090,9 @@ void TestJsonDbCachingListModel::changeQuery()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 10);
QCOMPARE(listModel->property("query").toString(), QString("[?_type=\"%1\"]").arg(__FUNCTION__));
@@ -981,7 +1108,10 @@ void TestJsonDbCachingListModel::changeQuery()
QCOMPARE(listModel->property("query").toString(), QString(""));
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
- waitForStateOrTimeout();
+
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 10);
QCOMPARE(listModel->property("query").toString(), QString("[?_type=\"%1\"]").arg(__FUNCTION__));
@@ -991,10 +1121,11 @@ void TestJsonDbCachingListModel::changeQuery()
void TestJsonDbCachingListModel::indexOfUuid()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_0"));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
createIndex("name", "string");
@@ -1008,23 +1139,28 @@ void TestJsonDbCachingListModel::indexOfUuid()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 1);
- getIndex(0);
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QString("Arnie_0"));
- QCOMPARE(indexOf(listModel, callbackResponse.toMap().value("_uuid").toString()), 0);
+ QVariant name = getIndex(listModel, 0, 2);
+ QCOMPARE(name.toString(), QString("Arnie_0"));
+ QVariant uuid = getIndex(listModel, 0, 1);
+ QCOMPARE(indexOf(listModel, uuid.toString()), 0);
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_1"));
- id = mClient->create(item, "com.nokia.shared.1");
-
+ mItemsCreated = 0;
+ id = create(item, "com.nokia.shared.1");
+ waitForResponse1(id);
waitForItemsCreated(1);
QCOMPARE(listModel->rowCount(), 2);
- getIndex(1);
- QCOMPARE(callbackResponse.toMap().value("name").toString(), QString("Arnie_1"));
- QCOMPARE(indexOf(listModel, callbackResponse.toMap().value("_uuid").toString()), 1);
+ name = getIndex(listModel, 1, 2);
+ QCOMPARE(name.toString(), QString("Arnie_1"));
+ uuid = getIndex(listModel, 1, 1);
+ QCOMPARE(indexOf(listModel, uuid.toString()), 1);
QCOMPARE(indexOf(listModel, "notValid"), -1);
deleteModel(listModel);
@@ -1032,15 +1168,15 @@ void TestJsonDbCachingListModel::indexOfUuid()
void TestJsonDbCachingListModel::roleNames()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie"));
item.insert("friend", QString("Bert"));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
-
QAbstractListModel *listModel = createModel();
if (!listModel) return;
@@ -1049,7 +1185,9 @@ void TestJsonDbCachingListModel::roleNames()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
- waitForStateOrTimeout();
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->rowCount(), 1);
@@ -1073,11 +1211,12 @@ void TestJsonDbCachingListModel::roleNames()
void TestJsonDbCachingListModel::getItemNotInCache()
{
+ resetWaitFlags();
QVariantMap item;
- for (int i=0; i < 300; i++) {
+ for (int i=0; i < 3000; i++) {
item.insert("_type", __FUNCTION__);
item.insert("number", i);
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
@@ -1085,7 +1224,7 @@ void TestJsonDbCachingListModel::getItemNotInCache()
QAbstractListModel *listModel = createModel();
if (!listModel) return;
- listModel->setProperty("cacheSize", 100);
+ listModel->setProperty("cacheSize", 50);
listModel->setProperty("sortOrder", "[/number]");
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "number");
listModel->setProperty("roleNames", roleNames);
@@ -1095,47 +1234,54 @@ void TestJsonDbCachingListModel::getItemNotInCache()
// now start it working
QCOMPARE(listModel->rowCount(), 0);
- waitForStateOrTimeout();
- QCOMPARE(listModel->rowCount(), 300);
- QCOMPARE(listModel->property("cacheSize").toInt(), 100);
-
- getIndex(100);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 100);
- getIndex(151);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 151);
- getIndex(202);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 202);
- getIndex(255);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 255);
- getIndex(20);
- QCOMPARE(callbackResponse.toMap().value("number").toInt(), 20);
+ mWaitingForReset = true;
+ waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+
+ QCOMPARE(listModel->rowCount(), 3000);
- deleteModel(listModel);
-}
+ QVariant number = getIndex(listModel, 2967, 2);
+ QCOMPARE(number.toInt(), 2967);
+ number = getIndex(listModel, 100, 2);
+ QCOMPARE(number.toInt(), 100);
+ number = getIndex(listModel, 1701, 2);
+ QCOMPARE(number.toInt(), 1701);
+ number = getIndex(listModel, 20, 2);
+ QCOMPARE(number.toInt(), 20);
+ deleteModel(listModel);
+}
QStringList TestJsonDbCachingListModel::getOrderValues(QAbstractListModel *listModel)
{
QStringList vals;
for (int i = 0; i < listModel->rowCount(); ++i) {
- getIndex(i);
- vals << callbackResponse.toMap().value("ordering").toString();
+ vals << getIndex(listModel, i, 3).toString();
}
return vals;
}
void TestJsonDbCachingListModel::modelReset()
{
- mWaitingForReset = false;
- mEventLoop2.exit(0);
+ if (mWaitingForReset) {
+ mWaitingForReset = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbCachingListModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
- mWaitingForDataChange = false;
+ mItemsUpdated++;
+ if (mWaitingForChanged) {
+ mWaitingForChanged = false;
+ eventLoop1.exit(0);
+ } else if (mWaitingForIndexChanged && mIndexWaited >= topLeft.row() && mIndexWaited <= bottomRight.row()) {
+ mWaitingForIndexChanged = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbCachingListModel::rowsInserted(const QModelIndex &parent, int first, int last)
@@ -1143,8 +1289,11 @@ void TestJsonDbCachingListModel::rowsInserted(const QModelIndex &parent, int fir
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
- mItemsCreated++;
- mEventLoop2.exit(0);
+ mItemsCreated += last-first+1;
+ if (mWaitingForRowsInserted) {
+ mWaitingForRowsInserted = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbCachingListModel::rowsRemoved(const QModelIndex &parent, int first, int last)
@@ -1152,7 +1301,11 @@ void TestJsonDbCachingListModel::rowsRemoved(const QModelIndex &parent, int firs
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
- mWaitingForRowsRemoved = false;
+ mItemsRemoved += last-first+1;
+ if (mWaitingForRemoved) {
+ mWaitingForRemoved = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbCachingListModel::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row )
@@ -1168,83 +1321,141 @@ void TestJsonDbCachingListModel::stateChanged()
{
// only exit on ready state.
QAbstractListModel *model = qobject_cast<QAbstractListModel *>(sender());
- if (model->property("state") == 2) {
+ if (model->property("state").toInt() == 2 && mWaitingForStateChanged) {
mWaitingForStateChanged = false;
- mEventLoop2.exit(0);
+ eventLoop1.exit(0);
}
}
void TestJsonDbCachingListModel::waitForItemsCreated(int items)
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mItemsCreated = 0;
- while (mItemsCreated != items && !mTimeoutCalled)
- mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout);
+ while (!mTimedOut && mItemsCreated != items) {
+ mWaitingForRowsInserted = true;
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+ if (mTimedOut)
+ qDebug () << "waitForItemsCreated Timed out";
+}
+
+void TestJsonDbCachingListModel::waitForIndexChanged()
+{
+
+ mTimedOut = false;
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+
+ while (!mTimedOut && mWaitingForIndexChanged) {
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+ if (mTimedOut)
+ qDebug () << "waitForIndexChanged Timed out";
+}
+
+void TestJsonDbCachingListModel::waitForItemsRemoved(int items)
+{
+ mTimedOut = false;
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+
+ while (!mTimedOut && mItemsRemoved != items) {
+ mWaitingForRemoved = true;
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+ if (mTimedOut)
+ qDebug () << "waitForItemsRemoved Timed out";
}
void TestJsonDbCachingListModel::waitForExitOrTimeout()
{
- mTimeoutCalled = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
- mEventLoop2.exec(QEventLoop::AllEvents);
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+ eventLoop1.exec(QEventLoop::AllEvents);
}
void TestJsonDbCachingListModel::waitForStateOrTimeout()
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mWaitingForStateChanged = true;
- while (mWaitingForStateChanged && !mTimeoutCalled)
- mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout);
+ while (mWaitingForStateChanged && !mTimedOut) {
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+ if (mTimedOut)
+ qDebug () << "waitForStateOrTimeout Timed out";
}
void TestJsonDbCachingListModel::timeout()
{
- ClientWrapper::timeout();
- mTimeoutCalled = true;
+ qDebug () << "TestJsonDbCachingListModel::timeout()";
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
+}
+
+void TestJsonDbCachingListModel::resetWaitFlags()
+{
+ mItemsCreated = 0;
+ mItemsUpdated = 0;
+ mItemsRemoved = 0;
+ mWaitingForStateChanged = false;
+ mWaitingForRowsInserted = false;
+ mWaitingForReset = false;
+ mWaitingForChanged = false;
+ mWaitingForRemoved = false;
}
void TestJsonDbCachingListModel::waitForItemChanged(bool waitForRemove)
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mWaitingForRowsRemoved = true;
- mWaitingForDataChange = true;
+ mWaitingForRemoved = true;
+ mWaitingForChanged = true;
mItemsCreated = 0;
mWaitingForReset = true;
+ mWaitingForStateChanged = true;
bool waitMore = true;
- while (waitMore && !mTimeoutCalled) {
- if (!mWaitingForDataChange)
+ while (waitMore && !mTimedOut) {
+ if (!mWaitingForChanged) {
+ //qDebug() << "waitForItemChanged: mWaitingForChanged";
break;
- if (mItemsCreated)
+ }
+ if (!mWaitingForStateChanged) {
+ //qDebug() << "waitForItemChanged: mWaitingForStateChanged";
break;
- if (!mWaitingForReset)
+ }
+ if (mItemsCreated){
+ //qDebug() << "waitForItemChanged: mItemsCreated";
break;
- if (waitForRemove && !mWaitingForRowsRemoved)
+ }
+ if (!mWaitingForReset){
+ //qDebug() << "waitForItemChanged: mWaitingForReset";
break;
- mEventLoop2.processEvents(QEventLoop::AllEvents);
+ }
+ if (waitForRemove && !mWaitingForRemoved){
+ //qDebug() << "waitForItemChanged: mWaitingForRemoved";
+ break;
+ }
+ eventLoop1.exec(QEventLoop::AllEvents);
}
}
QTEST_MAIN(TestJsonDbCachingListModel)
diff --git a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h
index 695efaf1..02bb0521 100644
--- a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h
+++ b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.h
@@ -41,22 +41,9 @@
#ifndef TestJsonDbCachingListModel_H
#define TestJsonDbCachingListModel_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractListModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_BEGIN_NAMESPACE
class QQmlEngine;
@@ -73,14 +60,10 @@ public:
~ModelData();
QQmlEngine *engine;
QQmlComponent *component;
- QQmlComponent *partitionComponent1;
- QQmlComponent *partitionComponent2;
QObject *model;
- QObject *partition1;
- QObject *partition2;
};
-class TestJsonDbCachingListModel: public ClientWrapper
+class TestJsonDbCachingListModel: public RequestWrapper
{
Q_OBJECT
public:
@@ -98,15 +81,10 @@ public slots:
void modelReset();
void stateChanged();
- void callbackSlot(QVariant error, QVariant response);
-
-
-protected slots:
- void timeout();
-
private slots:
void initTestCase();
void cleanupTestCase();
+
void createItem();
void createModelTwoPartitions();
void updateItemClient();
@@ -116,46 +94,46 @@ private slots:
void checkRemoveNotification();
void checkUpdateNotification();
void totalRowCount();
+ void checkAddNotification();
void listProperty();
void changeQuery();
void indexOfUuid();
void roleNames();
void getItemNotInCache();
-
+public:
+ void timeout();
private:
void waitForExitOrTimeout();
void waitForItemsCreated(int items);
+ void waitForItemsRemoved(int items);
void waitForStateOrTimeout();
void waitForItemChanged(bool waitForRemove = false);
+ void waitForIndexChanged();
QStringList getOrderValues(QAbstractListModel *listModel);
- void getIndex(int index);
+ QVariant getIndex(QAbstractListModel *model, int index, int role);
void createIndex(const QString &property, const QString &propertyType);
QAbstractListModel *createModel();
void deleteModel(QAbstractListModel *model);
- QVariant readJsonFile(const QString &filename);
+ void resetWaitFlags();
private:
QProcess *mProcess;
- QStringList mNotificationsReceived;
+ //QStringList mNotificationsReceived;
QList<ModelData*> mModels;
QString mPluginPath;
- QEventLoop mEventLoop2; // for all listmodel slots
// Response values
+ bool mTimedOut;
int mItemsCreated;
- bool mWaitingForNotification;
- bool mWaitingForDataChange;
- bool mWaitingForRowsRemoved;
- bool mTimeoutCalled;
- bool mWaitingForReset;
+ int mItemsUpdated;
+ int mItemsRemoved;
bool mWaitingForStateChanged;
-
- bool mTimedOut;
- bool callbackError;
- bool mCallbackReceived;
- QVariant callbackMeta;
- QVariant callbackResponse;
-
+ bool mWaitingForRowsInserted;
+ bool mWaitingForReset;
+ bool mWaitingForChanged;
+ bool mWaitingForIndexChanged;
+ int mIndexWaited;
+ bool mWaitingForRemoved;
};
#endif
diff --git a/tests/auto/jsondbchangessinceobject/jsondbchangessinceobject.pro b/tests/auto/jsondbchangessinceobject/jsondbchangessinceobject.pro
deleted file mode 100644
index cb94df5d..00000000
--- a/tests/auto/jsondbchangessinceobject/jsondbchangessinceobject.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-TEMPLATE = app
-TARGET = tst_jsondbchangessinceobject
-DEPENDPATH += .
-INCLUDEPATH += .
-
-QT = core network testlib gui qml jsondbcompat-private
-CONFIG -= app_bundle
-CONFIG += testcase
-
-include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
-
-DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
-
-HEADERS += testjsondbchangessinceobject.h
-SOURCES += testjsondbchangessinceobject.cpp
diff --git a/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.cpp b/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.cpp
deleted file mode 100644
index 8ad35d50..00000000
--- a/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QJSEngine>
-#include "testjsondbchangessinceobject.h"
-#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
-
-static const char dbfile[] = "dbFile-jsondb-partition";
-
-const QString qmlProgram = QLatin1String(
- "import QtQuick 2.0 \n"
- "import QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.ChangesSince { "
- "id:changessinceObject;"
- "partition :JsonDb.Partition { "
- "name: \"com.nokia.shared\";"
- "}"
- "}");
-
-const QString qmlProgramForPartition = QLatin1String(
- "import QtQuick 2.0 \n"
- "import QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.Partition { "
- "id: sharedPartition;"
- "name: \"com.nokia.shared\";"
- "}");
-
-TestJsonDbChangesSinceObject::TestJsonDbChangesSinceObject()
- : mTimedOut(false)
-{
- qsrand(QTime::currentTime().msec());
-}
-
-TestJsonDbChangesSinceObject::~TestJsonDbChangesSinceObject()
-{
-}
-
-void TestJsonDbChangesSinceObject::timeout()
-{
- ClientWrapper::timeout();
- mTimedOut = true;
-}
-
-void TestJsonDbChangesSinceObject::deleteDbFiles()
-{
- // remove all the test files.
- QDir currentDir;
- QStringList nameFilter;
- nameFilter << QString("*.db");
- nameFilter << "objectFile.bin" << "objectFile2.bin";
- QFileInfoList databaseFiles = currentDir.entryInfoList(nameFilter, QDir::Files);
- foreach (QFileInfo fileInfo, databaseFiles) {
- QFile file(fileInfo.fileName());
- file.remove();
- }
-}
-
-void TestJsonDbChangesSinceObject::initTestCase()
-{
- // make sure there is no old db files.
- deleteDbFiles();
-
- QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
-
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
-
- mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = mClient->create(item);
- waitForResponse1(id);
-
-}
-
-ComponentData *TestJsonDbChangesSinceObject::createComponent()
-{
- ComponentData *componentData = new ComponentData();
- componentData->engine = new QQmlEngine();
- QString error;
- if (!componentData->engine->importPlugin(mPluginPath, QString("QtJsonDb"), &error)) {
- qDebug()<<"Unable to load the plugin :"<<error;
- delete componentData->engine;
- return 0;
- }
- componentData->component = new QQmlComponent(componentData->engine);
- componentData->component->setData(qmlProgram.toUtf8(), QUrl());
- componentData->qmlElement = componentData->component->create();
- if (componentData->component->isError())
- qDebug() << componentData->component->errors();
- QObject::connect(componentData->qmlElement, SIGNAL(finished()),
- this, SLOT(finishedSlot()));
- QObject::connect(componentData->qmlElement, SIGNAL(errorChanged(const QVariantMap&)),
- this, SLOT(errorSlot(const QVariantMap&)));
- mComponents.append(componentData);
- return componentData;
-}
-
-ComponentData *TestJsonDbChangesSinceObject::createPartitionComponent()
-{
- ComponentData *componentData = new ComponentData();
- componentData->engine = new QQmlEngine();
- QString error;
- if (!componentData->engine->importPlugin(mPluginPath, QString("QtJsonDb"), &error)) {
- qDebug()<<"Unable to load the plugin :"<<error;
- delete componentData->engine;
- return 0;
- }
- componentData->component = new QQmlComponent(componentData->engine);
- componentData->component->setData(qmlProgramForPartition.toUtf8(), QUrl());
- componentData->qmlElement = componentData->component->create();
- if (componentData->component->isError())
- qDebug() << componentData->component->errors();
- mComponents.append(componentData);
- return componentData;
-}
-
-void TestJsonDbChangesSinceObject::deleteComponent(ComponentData *componentData)
-{
- mComponents.removeOne(componentData);
- if (componentData)
- delete componentData;
-}
-
-void TestJsonDbChangesSinceObject::cleanupTestCase()
-{
- if (mProcess) {
- mProcess->kill();
- mProcess->waitForFinished();
- delete mProcess;
- }
-
- deleteDbFiles();
-}
-
-void TestJsonDbChangesSinceObject::errorSlot(const QVariantMap &newError)
-{
- int code = newError.value("code").toInt();
- QString message = newError.value("message").toString();
- callbackError = true;
- callbackErrorCode = code;
- callbackErrorMessage = message;
- mEventLoop2.quit();
-}
-
-void TestJsonDbChangesSinceObject::finishedSlot()
-{
- QMetaObject::invokeMethod(currentQmlElement, "takeResults", Qt::DirectConnection,
- Q_RETURN_ARG(QVariantList, cbData));
- mEventLoop2.quit();
-}
-
-bool posLessThan(const QVariant &v1, const QVariant &v2)
-{
- QVariantMap v1Map = v1.toMap();
- QVariantMap v2Map = v2.toMap();
-
- return v1Map.value("pos").toInt() < v2Map.value("pos").toInt();
-}
-
-void TestJsonDbChangesSinceObject::singleType()
-{
- ComponentData *changesSinceObject = createComponent();
- if (!changesSinceObject || !changesSinceObject->qmlElement) return;
-
- const QString typeString( __FUNCTION__ );
- changesSinceObject->qmlElement->setProperty("types", QStringList(typeString));
- currentQmlElement = changesSinceObject->qmlElement;
-
- //Create an object
- QVariantMap item = createObject(__FUNCTION__).toMap();
- int id = mClient->create(item, "com.nokia.shared");
- waitForResponse1(id);
- const QString expression("start();");
- QQmlExpression *expr;
- expr = new QQmlExpression(changesSinceObject->engine->rootContext(), changesSinceObject->qmlElement, expression);
- expr->evaluate();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- QCOMPARE(callbackError, false);
- delete expr;
- deleteComponent(changesSinceObject);
-}
-
-void TestJsonDbChangesSinceObject::multipleObjects()
-{
- ComponentData *changesSinceObject = createComponent();
- if (!changesSinceObject || !changesSinceObject->qmlElement) return;
-
- const QString typeString( __FUNCTION__ );
- changesSinceObject->qmlElement->setProperty("types", QStringList(typeString));
- currentQmlElement = changesSinceObject->qmlElement;
-
- //Create objects
- QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- int id = mClient->create(QVariant(items), "com.nokia.shared");
- waitForResponse1(id);
- qSort(items.begin(), items.end(), posLessThan);
- const QString expression("start();");
- QQmlExpression *expr;
- expr = new QQmlExpression(changesSinceObject->engine->rootContext(), changesSinceObject->qmlElement, expression);
- expr->evaluate();
- waitForCallback2();
- QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 10);
- QVariantList result;
- for (int i = 0; i<10; i++) {
- QVariantMap obj = cbData[i].toMap();
- result.append(obj.value("after"));
- }
- qSort(result.begin(), result.end(), posLessThan);
- for (int i = 0; i<10; i++) {
- QVariantMap item = items[i].toMap();
- QVariantMap obj = result[i].toMap();
- QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
- }
-
- delete expr;
- deleteComponent(changesSinceObject);
-}
-
-void TestJsonDbChangesSinceObject::multipleTypes()
-{
- ComponentData *changesSinceObject = createComponent();
- if (!changesSinceObject || !changesSinceObject->qmlElement) return;
-
- QStringList types;
- types << __FUNCTION__
- <<QString(__FUNCTION__)+".2";
- changesSinceObject->qmlElement->setProperty("types", types);
- currentQmlElement = changesSinceObject->qmlElement;
-
- //Create an object
- QVariantMap item = createObject(types[0]).toMap();
- int id = mClient->create(item, "com.nokia.shared");
- waitForResponse1(id);
- item = createObject(types[1]).toMap();
- id = mClient->create(item, "com.nokia.shared");
- waitForResponse1(id);
- const QString expression("start();");
- QQmlExpression *expr;
- expr = new QQmlExpression(changesSinceObject->engine->rootContext(), changesSinceObject->qmlElement, expression);
- expr->evaluate();
- waitForCallback2();
- QCOMPARE(cbData.size(), 2);
- QCOMPARE(callbackError, false);
- delete expr;
- deleteComponent(changesSinceObject);
-}
-
-void TestJsonDbChangesSinceObject::createChangesSince()
-{
- const QString createString = QString("createChangesSince(0, [\"%1\"]);");
- ComponentData *partition = createPartitionComponent();
- if (!partition || !partition->qmlElement) return;
- QString expression;
-
- expression = QString(createString).arg(__FUNCTION__);
- QQmlExpression *expr;
- expr = new QQmlExpression(partition->engine->rootContext(), partition->qmlElement, expression);
- QPointer<QObject> queryObject = expr->evaluate().value<QObject*>();
- QVERIFY(!queryObject.isNull());
- queryObject->setParent(partition->qmlElement);
- currentQmlElement = queryObject;
- QObject::connect(currentQmlElement, SIGNAL(finished()),
- this, SLOT(finishedSlot()));
- QObject::connect(currentQmlElement, SIGNAL(errorChanged(const QVariantMap&)),
- this, SLOT(errorSlot(const QVariantMap&)));
- //Create an object
- QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
- QMetaObject::invokeMethod(currentQmlElement, "start", Qt::DirectConnection);
- cbData.clear();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- QCOMPARE(callbackError, false);
- delete expr;
- deleteComponent(partition);
-}
-
-QTEST_MAIN(TestJsonDbChangesSinceObject)
-
diff --git a/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.h b/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.h
deleted file mode 100644
index 5e98bdce..00000000
--- a/tests/auto/jsondbchangessinceobject/testjsondbchangessinceobject.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef TESTJSONDBCHANGESSINCEOBJECT_H
-#define TESTJSONDBCHANGESSINCEOBJECT_H
-
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-#include <QJSValue>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
-#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
-
-QT_USE_NAMESPACE_JSONDB
-
-class TestJsonDbChangesSinceObject: public ClientWrapper
-{
- Q_OBJECT
-public:
- TestJsonDbChangesSinceObject();
- ~TestJsonDbChangesSinceObject();
- void deleteDbFiles();
-
-private slots:
- void initTestCase();
- void cleanupTestCase();
-
- void singleType();
- void multipleObjects();
- void multipleTypes();
- void createChangesSince();
-
-public slots:
- void errorSlot(const QVariantMap &newError);
- void finishedSlot();
-
-protected slots:
- void timeout();
-
-private:
- ComponentData *createComponent();
- ComponentData *createPartitionComponent();
- void deleteComponent(ComponentData *componentData);
-
-private:
- QProcess *mProcess;
- QStringList mNotificationsReceived;
- QList<ComponentData*> mComponents;
- QString mPluginPath;
- bool mTimedOut;
- bool callbackError;
- int callbackErrorCode;
- QString callbackErrorMessage;
- QVariantList cbData;
- QEventLoop mEventLoop2;
- QObject *currentQmlElement;
-
-};
-
-#endif
diff --git a/tests/auto/jsondblistmodel/jsondblistmodel.pro b/tests/auto/jsondblistmodel/jsondblistmodel.pro
index 7aafd6ad..1001c605 100644
--- a/tests/auto/jsondblistmodel/jsondblistmodel.pro
+++ b/tests/auto/jsondblistmodel/jsondblistmodel.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondblistmodel
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondblistmodel.h
+HEADERS += testjsondblistmodel.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondblistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondblistmodel/partitions.json b/tests/auto/jsondblistmodel/partitions.json
new file mode 100644
index 00000000..c312e702
--- /dev/null
+++ b/tests/auto/jsondblistmodel/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.example.shared.1" }
+]
diff --git a/tests/auto/jsondblistmodel/testjsondblistmodel.cpp b/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
index 598353ca..bd0e40d7 100644
--- a/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
+++ b/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
@@ -43,7 +43,6 @@
#include <QJSEngine>
#include "testjsondblistmodel.h"
#include "../../shared/util.h"
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-listmodel";
ModelData::ModelData(): engine(0), component(0), model(0)
@@ -60,6 +59,14 @@ ModelData::~ModelData()
delete engine;
}
+const QString qmlProgram = QLatin1String(
+ "import QtQuick 2.0\n"
+ "import QtJsonDb 1.0 as JsonDb\n"
+ "JsonDb.JsonDbListModel {"
+ "id: contactsModel;"
+ "partition: JsonDb.Partition {name: \"com.example.shared.1\"}"
+ "}");
+
QVariant get(QObject* object, int index, QString propertyName)
{
QVariant retVal;
@@ -86,7 +93,6 @@ void listSetProperty(QObject* object, int index, QString propertyName, QVariant
}
TestJsonDbListModel::TestJsonDbListModel()
- : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false)
{
}
@@ -108,20 +114,6 @@ void TestJsonDbListModel::deleteDbFiles()
}
}
-QVariant TestJsonDbListModel::readJsonFile(const QString& filename)
-{
- QString filepath = findFile(filename);
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- return parser.result();
-}
-
void TestJsonDbListModel::connectListModel(QAbstractItemModel *model)
{
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)));
@@ -138,27 +130,14 @@ void TestJsonDbListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
if (mPluginPath.isEmpty())
qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.example.shared.1");
- int id = mClient->create(item);
- waitForResponse1(id);
-
}
QAbstractItemModel *TestJsonDbListModel::createModel()
@@ -173,7 +152,7 @@ QAbstractItemModel *TestJsonDbListModel::createModel()
return 0;
}
newModel->component = new QQmlComponent(newModel->engine);
- newModel->component->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n JsonDb.JsonDbListModel {id: contactsModel; partition: JsonDb.Partition {name: \"com.example.shared.1\"}}", QUrl());
+ newModel->component->setData(qmlProgram.toLocal8Bit(), QUrl());
newModel->model = newModel->component->create();
if (newModel->component->isError())
qDebug() << newModel->component->errors();
@@ -203,31 +182,56 @@ void TestJsonDbListModel::cleanupTestCase()
deleteDbFiles();
}
+void TestJsonDbListModel::timeout()
+{
+ RequestWrapper::timeout();
+ mTimedOut = true;
+ eventLoop1.quit();
+}
+
void TestJsonDbListModel::waitForItemsCreated(int items)
{
+ mTimedOut = false;
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+
mItemsCreated = 0;
- while(mItemsCreated != items)
- mEventLoop.processEvents(QEventLoop::AllEvents, mClientTimeout);
+ while (!mTimedOut && mItemsCreated != items) {
+ mWaitingForRowsInserted = true;
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
}
void TestJsonDbListModel::waitForExitOrTimeout()
{
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
- mEventLoop.exec(QEventLoop::AllEvents);
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+ eventLoop1.exec(QEventLoop::AllEvents);
+}
+
+void TestJsonDbListModel::resetWaitFlags()
+{
+ mItemsCreated = 0;
+ mItemsUpdated = 0;
+ mItemsRemoved = 0;
+ mWaitingForRowsInserted = false;
+ mWaitingForReset = false;
+ mWaitingForChanged = false;
+ mWaitingForRemoved = false;
}
// Create items in the model.
void TestJsonDbListModel::createItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.example.shared.1");
-
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
QAbstractItemModel *listModel = createModel();
@@ -239,17 +243,21 @@ void TestJsonDbListModel::createItem()
// now start it working
QCOMPARE(listModel->property("count").toInt(), 0);
-
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
item.insert("_type", __FUNCTION__);
item.insert("name", "Baker");
mItemsCreated = 0;
- id = mClient->create(item, "com.example.shared.1");
+ id = create(item, "com.example.shared.1");
waitForResponse1(id);
- if (!mItemsCreated)
+ while (!mItemsCreated) {
+ mWaitingForRowsInserted = true;
waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRowsInserted, false);
QCOMPARE(listModel->property("count").toInt(), 2);
deleteModel(listModel);
@@ -258,12 +266,12 @@ void TestJsonDbListModel::createItem()
// Create an item and then update it.
void TestJsonDbListModel::updateItemClient()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
-
QAbstractItemModel *listModel = createModel();
if (!listModel) return;
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
@@ -273,36 +281,45 @@ void TestJsonDbListModel::updateItemClient()
// now start it working
QCOMPARE(listModel->property("count").toInt(), 0);
-
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
- item.insert("_uuid", mLastUuid);
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
+ item.insert("_version", lastVersion);
item.insert("name", "Baker");
-
- mWaitingForDataChange = true;
- id = mClient->update(item, "com.example.shared.1");
+ id = update(item, "com.example.shared.1");
waitForResponse1(id);
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
QCOMPARE(listModel->property("count").toInt(), 1);
- QCOMPARE(get(listModel, 0, "_uuid").toString(), mLastUuid);
+ QCOMPARE(get(listModel, 0, "_uuid").toString(), lastUuid);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
QCOMPARE(get(listModel, 0, "name").toString(), QLatin1String("Baker"));
deleteModel(listModel);
}
-
// Create an item and then update it.
void TestJsonDbListModel::updateItemSet()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("phone", "123456789");
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
QAbstractItemModel *listModel = createModel();
@@ -314,8 +331,9 @@ void TestJsonDbListModel::updateItemSet()
// now start it working
QCOMPARE(listModel->property("count").toInt(), 0);
-
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
QJSEngine engine;
@@ -324,12 +342,12 @@ void TestJsonDbListModel::updateItemSet()
value.setProperty("name", "Baker");
value.setProperty("phone", "987654321");
- mWaitingForDataChange = true;
-
set(listModel, 0, value);
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
QCOMPARE(listModel->property("count").toInt(), 1);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
@@ -337,13 +355,15 @@ void TestJsonDbListModel::updateItemSet()
QCOMPARE(get(listModel, 0, "phone").toString(), QLatin1String("987654321"));
deleteModel(listModel);
}
+
void TestJsonDbListModel::updateItemSetProperty()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("phone", "123456789");
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
QAbstractItemModel *listModel = createModel();
@@ -355,16 +375,17 @@ void TestJsonDbListModel::updateItemSetProperty()
// now start it working
QCOMPARE(listModel->property("count").toInt(), 0);
-
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
- mWaitingForDataChange = true;
-
listSetProperty(listModel, 0, QString("phone"), QVariant("987654321"));
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
QCOMPARE(listModel->property("count").toInt(), 1);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
@@ -375,10 +396,11 @@ void TestJsonDbListModel::updateItemSetProperty()
void TestJsonDbListModel::deleteItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
QAbstractItemModel *listModel = createModel();
@@ -389,24 +411,38 @@ void TestJsonDbListModel::deleteItem()
connectListModel(listModel);
// now start it working
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
item.insert("name", "Baker");
mItemsCreated = 0;
- id = mClient->create(item,"com.example.shared.1");
+ id = create(item,"com.example.shared.1");
waitForResponse1(id);
- if (!mItemsCreated)
+ while (!mItemsCreated) {
+ mWaitingForRowsInserted = true;
waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRowsInserted, false);
QCOMPARE(listModel->property("count").toInt(), 2);
- mWaitingForRowsRemoved = true;
- item.insert("_uuid", mLastUuid);
- id = mClient->remove(item, "com.example.shared.1");
-
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
+ item.insert("_version", lastVersion);
+ id = remove(item, "com.example.shared.1");
waitForResponse1(id);
- while (mWaitingForRowsRemoved)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsRemoved) {
+ mWaitingForRemoved = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRemoved, false);
QCOMPARE(listModel->property("count").toInt(), 1);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
@@ -414,9 +450,9 @@ void TestJsonDbListModel::deleteItem()
deleteModel(listModel);
}
-
void TestJsonDbListModel::sortedQuery()
{
+ resetWaitFlags();
int id = 0;
QVariantMap index;
@@ -424,14 +460,14 @@ void TestJsonDbListModel::sortedQuery()
index.insert("name", "number");
index.insert("propertyName", "number");
index.insert("propertyType", "number");
- id = mClient->create(index, "com.example.shared.1");
+ id = create(index, "com.example.shared.1");
waitForResponse1(id);
for (int i = 0; i < 1000; i++) {
QVariantMap item;
item.insert("_type", "RandNumber");
item.insert("number", i);
- id = mClient->create(item, "com.example.shared.1");
+ id = create(item, "com.example.shared.1");
waitForResponse1(id);
}
@@ -445,29 +481,36 @@ void TestJsonDbListModel::sortedQuery()
listModel->setProperty("roleNames", rolenames);
listModel->setProperty("query", "[?_type=\"RandNumber\"][/number]");
+ QCOMPARE(listModel->property("count").toInt(), 0);
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1000);
+
for (int i = 0; i < 1000; i++)
QCOMPARE(get(listModel, i,"number").toInt(), i);
-
listModel->setProperty("query","[?_type=\"RandNumber\"][\\number]");
+ mWaitingForReset = true;
waitForExitOrTimeout();
- for (int i = 0; i < 1000; i++)
+ QCOMPARE(mWaitingForReset, false);
+ QCOMPARE(listModel->property("count").toInt(), 1000);
+ for (int i = 0; i < 1000; i++) {
QCOMPARE(get(listModel, i,"number").toInt(), 999-i);
+ }
QCoreApplication::instance()->processEvents();
deleteModel(listModel);
}
-
void TestJsonDbListModel::ordering()
{
+ resetWaitFlags();
for (int i = 9; i >= 1; --i) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", QString::number(i));
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
}
@@ -480,13 +523,13 @@ void TestJsonDbListModel::ordering()
// now start it working
QCOMPARE(listModel->property("count").toInt(), 0);
-
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QStringList expectedOrder = QStringList() << "1" << "2" << "3" << "4" <<
"5" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
- mWaitingForDataChange = true;
{
QVariant uuid = get(listModel, 4, "_uuid");
QVERIFY(!uuid.toString().isEmpty());
@@ -496,17 +539,19 @@ void TestJsonDbListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "99"); // move it to the end
- int id = mClient->update(item, "com.example.shared.1");
+ int id = update(item, "com.example.shared.1");
waitForResponse1(id);
}
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "1" << "2" << "3" <<
"4" << "6" << "7" << "8" << "9" << "99";
QCOMPARE(getOrderValues(listModel), expectedOrder);
- mWaitingForDataChange = true;
+ mItemsUpdated = 0;
{
QVariant uuid = get(listModel, 8, "_uuid");
QVERIFY(!uuid.toString().isEmpty());
@@ -516,17 +561,19 @@ void TestJsonDbListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "22"); // move it after "2"
- int id = mClient->update(item, "com.example.shared.1");
+ int id = update(item, "com.example.shared.1");
waitForResponse1(id);
}
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "1" << "2" << "22" << "3" <<
"4" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
- mWaitingForDataChange = true;
+ mItemsUpdated = 0;
{
QVariant uuid = get(listModel, 5, "_uuid");
QVERIFY(!uuid.toString().isEmpty());
@@ -536,29 +583,30 @@ void TestJsonDbListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "0"); // move it to the beginning
- int id = mClient->update(item, "com.example.shared.1");
+ int id = update(item, "com.example.shared.1");
waitForResponse1(id);
}
-
- while (mWaitingForDataChange)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "0" << "1" << "2" << "22" << "3" <<
"4" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
deleteModel(listModel);
-
}
void TestJsonDbListModel::itemNotInCache()
{
+ resetWaitFlags();
QVariantMap index;
index.insert("_type", "Index");
index.insert("name", "order");
index.insert("propertyName", "order");
index.insert("propertyType", "number");
- //index.insert("partition", "com.example.shared.1");
- int indexId = mClient->create(index, "com.example.shared.1");
+ int indexId = create(index, "com.example.shared.1");
waitForResponse1(indexId);
QVariantList itemList;
@@ -569,7 +617,7 @@ void TestJsonDbListModel::itemNotInCache()
item.insert("order", i);
itemList << item;
}
- int id = mClient->create(itemList, "com.example.shared.1");
+ int id = create(itemList, "com.example.shared.1");
waitForResponse1(id);
QAbstractItemModel *listModel = createModel();
@@ -579,14 +627,16 @@ void TestJsonDbListModel::itemNotInCache()
listModel->setProperty("query", QString("[?_type=\"%1\"][/order]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "order");
listModel->setProperty("roleNames",roleNames);
+ mWaitingForReset = true;
waitForExitOrTimeout();
-
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1000);
// Make sure that the first items in the list is in the cache.
QVariant result = listModel->data(listModel->index(10,0), 3);
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 10);
+
// This item should not be in the cache now.
QVariant res = listModel->data(listModel->index(960,0), 3);
QCOMPARE(res.toInt(), 960);
@@ -595,11 +645,12 @@ void TestJsonDbListModel::itemNotInCache()
void TestJsonDbListModel::roles()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("phone", "123456789");
- int id = mClient->create(item, "com.example.shared.1");
+ int id = create(item, "com.example.shared.1");
waitForResponse1(id);
@@ -612,7 +663,9 @@ void TestJsonDbListModel::roles()
connectListModel(listModel);
// now start it working
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 1);
QVariantMap roles = listModel->property("roleNames").toMap();
@@ -624,17 +677,17 @@ void TestJsonDbListModel::roles()
void TestJsonDbListModel::totalRowCount()
{
+ resetWaitFlags();
int id = 0;
QVariantList insertedItems;
for (int i = 0; i < 10; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- id = mClient->create(item, "com.example.shared.1");
+ id = create(item, "com.example.shared.1");
waitForResponse1(id);
- insertedItems << mData;
+ insertedItems << lastResult;
}
-
QAbstractItemModel *listModel = createModel();
if (!listModel)
return;
@@ -645,14 +698,16 @@ void TestJsonDbListModel::totalRowCount()
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "order");
listModel->setProperty("roleNames",roleNames);
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 10);
for (int i = 10; i < 50; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- mClient->create(item, "com.example.shared.1");
+ create(item, "com.example.shared.1");
}
waitForItemsCreated(40);
@@ -660,15 +715,22 @@ void TestJsonDbListModel::totalRowCount()
// Change query
listModel->setProperty("query", QString("[?_type=\"%1\"][\\order]").arg(__FUNCTION__));
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), 50);
// Delete the first 10 items
foreach (QVariant item, insertedItems) {
- mWaitingForRowsRemoved = true;
- id = mClient->remove(item.toMap(), "com.example.shared.1");
- while(mWaitingForRowsRemoved)
- mEventLoop.processEvents(QEventLoop::AllEvents);
+ mItemsRemoved = 0;
+ id = remove(item.toMap(), "com.example.shared.1");
+ waitForResponse1(id);
+
+ while (!mTimedOut && !mItemsRemoved) {
+ mWaitingForRemoved = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRemoved, false);
}
QCOMPARE(listModel->property("count").toInt(), 40);
@@ -678,11 +740,13 @@ void TestJsonDbListModel::totalRowCount()
void TestJsonDbListModel::listProperty()
{
- QVariant jsonData = readJsonFile("list-objects.json");
+ resetWaitFlags();
+ QVariant jsonData = readJsonFile(findFile("list-objects.json")).toVariant();
QVariantList itemList = jsonData.toList();
+
int id = 0;
for (int i = 0; i < itemList.count(); i++) {
- id = mClient->create(itemList[i].toMap(), "com.example.shared.1");
+ id = create(itemList[i].toMap(), "com.example.shared.1");
waitForResponse1(id);
}
@@ -695,13 +759,23 @@ void TestJsonDbListModel::listProperty()
listModel->setProperty("query", QString("[?_type=\"%1\"][/features.0.properties.0.description]").arg(type));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "features.0.properties.0.description"<< "features.0.feature");
listModel->setProperty("roleNames",roleNames);
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
+
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
QCOMPARE(listModel->property("count").toInt(), itemList.count());
QCOMPARE(get(listModel, 0, "_type").toString(), type);
QCOMPARE(get(listModel, 0, "features.0.properties.0.description").toString(), QLatin1String("Facebook account provider"));
QCOMPARE(get(listModel, 0, "features.0.feature").toString(), QLatin1String("provide Facebook"));
- QCOMPARE(get(listModel, 1, "_uuid").toString(), mLastUuid);
+ QCOMPARE(get(listModel, 1, "_uuid").toString(), lastUuid);
QCOMPARE(get(listModel, 1, "_type").toString(), type);
QCOMPARE(get(listModel, 1, "features.0.properties.0.description").toString(), QLatin1String("Gmail account provider"));
QCOMPARE(get(listModel, 1, "features.0.feature").toString(), QLatin1String("provide Gmail"));
@@ -718,7 +792,9 @@ void TestJsonDbListModel::listProperty()
roleNames.clear();
roleNames = (QStringList() << "_type" << "_uuid" << "features[0].properties[0].description"<< "features[0].supported[0]");
listModel->setProperty("roleNames",roleNames);
+ mWaitingForReset = true;
waitForExitOrTimeout();
+ QCOMPARE(mWaitingForReset, false);
QCOMPARE(listModel->property("count").toInt(), itemList.count());
QCOMPARE(get(listModel, 0, "_type").toString(), type);
@@ -739,18 +815,22 @@ QStringList TestJsonDbListModel::getOrderValues(QAbstractItemModel *listModel)
return vals;
}
-
void TestJsonDbListModel::modelReset()
{
- //qDebug() << "TestJsonDbListModel::modelReset";
- mEventLoop.exit(0);
+ if (mWaitingForReset) {
+ mWaitingForReset = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbListModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
- //qDebug() << "TestJsonDbListModel::dataChanged";
- mWaitingForDataChange = false;
+ mItemsUpdated++;
+ if (mWaitingForChanged) {
+ mWaitingForChanged = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbListModel::rowsInserted(const QModelIndex &parent, int first, int last)
{
@@ -758,16 +838,21 @@ void TestJsonDbListModel::rowsInserted(const QModelIndex &parent, int first, int
Q_UNUSED(first);
Q_UNUSED(last);
mItemsCreated++;
- //qDebug() << "TestJsonDbListModel::rowsInserted";
- mEventLoop.exit(0);
+ if (mWaitingForRowsInserted) {
+ mWaitingForRowsInserted = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbListModel::rowsRemoved(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
- mWaitingForRowsRemoved = false;
- //qDebug() << "TestJsonDbListModel::rowsRemoved";
+ mItemsRemoved++;
+ if (mWaitingForRemoved) {
+ mWaitingForRemoved = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbListModel::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row )
{
@@ -776,7 +861,6 @@ void TestJsonDbListModel::rowsMoved( const QModelIndex &parent, int start, int e
Q_UNUSED(end);
Q_UNUSED(destination);
Q_UNUSED(row);
- //qDebug() << "TestJsonDbListModel::rowsMoved";
}
QTEST_MAIN(TestJsonDbListModel)
diff --git a/tests/auto/jsondblistmodel/testjsondblistmodel.h b/tests/auto/jsondblistmodel/testjsondblistmodel.h
index 79b8b851..8be75759 100644
--- a/tests/auto/jsondblistmodel/testjsondblistmodel.h
+++ b/tests/auto/jsondblistmodel/testjsondblistmodel.h
@@ -41,22 +41,9 @@
#ifndef TestJsonDbListModel_H
#define TestJsonDbListModel_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_BEGIN_NAMESPACE
class QQmlEngine;
@@ -76,7 +63,7 @@ public:
QObject *model;
};
-class TestJsonDbListModel: public ClientWrapper
+class TestJsonDbListModel: public RequestWrapper
{
Q_OBJECT
public:
@@ -108,26 +95,30 @@ private slots:
void roles();
void totalRowCount();
void listProperty();
-
+public:
+ void timeout();
private:
void waitForExitOrTimeout();
void waitForItemsCreated(int items);
QStringList getOrderValues(QAbstractItemModel *listModel);
QAbstractItemModel *createModel();
void deleteModel(QAbstractItemModel *model);
- QVariant readJsonFile(const QString &filename);
+ void resetWaitFlags();
private:
- QProcess *mProcess;
- QStringList mNotificationsReceived;
+ QProcess *mProcess;
QList<ModelData*> mModels;
QString mPluginPath;
// Response values
- int mItemsCreated;
- bool mWaitingForNotification;
- bool mWaitingForDataChange;
- bool mWaitingForRowsRemoved;
+ bool mTimedOut;
+ int mItemsCreated;
+ int mItemsUpdated;
+ int mItemsRemoved;
+ bool mWaitingForRowsInserted;
+ bool mWaitingForReset;
+ bool mWaitingForChanged;
+ bool mWaitingForRemoved;
};
#endif
diff --git a/tests/auto/jsondbnotification/jsondbnotification.pro b/tests/auto/jsondbnotification/jsondbnotification.pro
index f4e1fd67..1703343d 100644
--- a/tests/auto/jsondbnotification/jsondbnotification.pro
+++ b/tests/auto/jsondbnotification/jsondbnotification.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbnotification
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbnotification.h
+HEADERS += testjsondbnotification.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbnotification.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbnotification/partitions.json b/tests/auto/jsondbnotification/partitions.json
new file mode 100644
index 00000000..c77651a0
--- /dev/null
+++ b/tests/auto/jsondbnotification/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbnotification/testjsondbnotification.cpp b/tests/auto/jsondbnotification/testjsondbnotification.cpp
index 6e3610f5..418b1100 100644
--- a/tests/auto/jsondbnotification/testjsondbnotification.cpp
+++ b/tests/auto/jsondbnotification/testjsondbnotification.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QJSValueIterator>
#include "testjsondbnotification.h"
#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-partition";
@@ -71,6 +70,20 @@ const QString qmlProgramForPartition = QLatin1String(
"name: \"com.nokia.shared\";"
"}");
+#define waitForReadyStatus(obj) \
+ { \
+ int status = 0; \
+ while ((status = obj->property("status").toInt()) < 2) { \
+ waitForCallback1(); \
+ } \
+ }
+
+#define waitForCallbackNId(id) \
+ { \
+ waitForCallback1(); \
+ if (id != lastRequestId) \
+ waitForResponse1(id); \
+ }
TestJsonDbNotification::TestJsonDbNotification()
: mTimedOut(false)
@@ -84,8 +97,9 @@ TestJsonDbNotification::~TestJsonDbNotification()
void TestJsonDbNotification::timeout()
{
- ClientWrapper::timeout();
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
}
void TestJsonDbNotification::deleteDbFiles()
@@ -108,25 +122,12 @@ void TestJsonDbNotification::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = mClient->create(item);
- waitForResponse1(id);
-
}
ComponentData *TestJsonDbNotification::createComponent()
@@ -146,6 +147,8 @@ ComponentData *TestJsonDbNotification::createComponent()
qDebug() << componentData->component->errors();
QObject::connect(componentData->qmlElement, SIGNAL(notificationSignal(QVariant, int, int)),
this, SLOT(notificationSlot(QVariant, int, int)));
+ QObject::connect(componentData->qmlElement, SIGNAL(statusChanged(JsonDbNotify::Status)),
+ this, SLOT(statusChangedSlot2()));
mComponents.append(componentData);
return componentData;
}
@@ -193,8 +196,8 @@ void TestJsonDbNotification::notificationSlot(QVariant result, int action, int s
data.result = result.toMap();
data.action = action;
data.stateNumber = stateNumber;
- cbData.append(data);
- mEventLoop2.quit();
+ callbackData.append(data);
+ eventLoop1.quit();
}
void TestJsonDbNotification::errorSlot(int code, const QString &message)
@@ -202,7 +205,7 @@ void TestJsonDbNotification::errorSlot(int code, const QString &message)
callbackError = true;
callbackErrorCode = code;
callbackErrorMessage = message;
- mEventLoop2.quit();
+ eventLoop1.quit();
}
void TestJsonDbNotification::notificationSlot2(QJSValue result, Actions action, int stateNumber)
@@ -211,8 +214,13 @@ void TestJsonDbNotification::notificationSlot2(QJSValue result, Actions action,
data.result = result.toVariant().toMap();
data.action = action;
data.stateNumber = stateNumber;
- cbData.append(data);
- mEventLoop2.quit();
+ callbackData.append(data);
+ eventLoop1.quit();
+}
+
+void TestJsonDbNotification::statusChangedSlot2()
+{
+ eventLoop1.quit();
}
void TestJsonDbNotification::singleObjectNotifications()
@@ -227,31 +235,35 @@ void TestJsonDbNotification::singleObjectNotifications()
actionsList.append(2);
actionsList.append(4);
notification->qmlElement->setProperty("actions", actionsList);
+ waitForReadyStatus(notification->qmlElement);
CallbackData data;
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ int id = create(item, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 1);
QCOMPARE(data.result.value("alphabet"), item.value("alphabet"));
QString uuid = data.result.value("_uuid").toString();
//update the object
QString newAlphabet = data.result.value("alphabet").toString()+QString("**");
data.result.insert("alphabet", newAlphabet);
- mClient->update(data.result, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ id = update(data.result, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 2);
QCOMPARE(data.result.value("alphabet").toString(), newAlphabet);
//Remove the object
- mClient->remove(data.result, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ id = remove(data.result, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 4);
QCOMPARE(data.result.value("_uuid").toString(), uuid);
deleteComponent(notification);
@@ -269,62 +281,72 @@ void TestJsonDbNotification::multipleObjectNotifications()
actionsList.append(2);
actionsList.append(4);
notification->qmlElement->setProperty("actions", actionsList);
+ waitForReadyStatus(notification->qmlElement);
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ int id = create(items, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
QVariantList objList;
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 1);
+ QCOMPARE(callbackData[i].action, 1);
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
- QString newAlphabet = cbData[i].result.value("alphabet").toString()+QString("**");
+ QString newAlphabet = callbackData[i].result.value("alphabet").toString()+QString("**");
obj.insert("alphabet", newAlphabet);
objList.append(obj);
}
- cbData.clear();
+ callbackData.clear();
//update the object
- mClient->update(QVariant(objList), "com.nokia.shared");
+ id = update(objList, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
QVariantList lst = objList;
objList.clear();
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 2);
+ QCOMPARE(callbackData[i].action, 2);
QVariantMap item = lst[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
objList.append(obj);
}
- cbData.clear();
+ callbackData.clear();
//Remove the object
- mClient->remove(objList, "com.nokia.shared");
+ id = remove(objList, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 4);
+ QCOMPARE(callbackData[i].action, 4);
QVariantMap item = objList[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("_uuid"), item.value("_uuid"));
}
- cbData.clear();
+ callbackData.clear();
deleteComponent(notification);
}
@@ -341,15 +363,21 @@ void TestJsonDbNotification::createNotification()
QPointer<QObject> notification = expr->evaluate().value<QObject*>();
QVERIFY(!notification.isNull());
notification->setParent(partition->qmlElement);
- QObject::connect(notification, SIGNAL(notification(QJSValue, Actions, int)),
- this, SLOT(notificationSlot2(QJSValue, Actions, int)));
+ QObject::connect(notification, SIGNAL(notification(QJSValue,Actions,int)),
+ this, SLOT(notificationSlot2(QJSValue,Actions,int)));
+ QObject::connect(notification, SIGNAL(statusChanged(JsonDbNotify::Status)),
+ this, SLOT(statusChangedSlot2()));
+ waitForReadyStatus(notification);
+
+
CallbackData data;
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ int id = create(item, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 1);
QCOMPARE(data.result.value("alphabet"), item.value("alphabet"));
diff --git a/tests/auto/jsondbnotification/testjsondbnotification.h b/tests/auto/jsondbnotification/testjsondbnotification.h
index 9b728a61..158eba59 100644
--- a/tests/auto/jsondbnotification/testjsondbnotification.h
+++ b/tests/auto/jsondbnotification/testjsondbnotification.h
@@ -41,23 +41,9 @@
#ifndef TESTJSONDBNOTIFICATION_H
#define TESTJSONDBNOTIFICATION_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-#include <QJSValue>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_USE_NAMESPACE_JSONDB
@@ -67,7 +53,7 @@ struct CallbackData {
QVariantMap result;
};
-class TestJsonDbNotification: public ClientWrapper
+class TestJsonDbNotification: public RequestWrapper
{
Q_OBJECT
public:
@@ -91,8 +77,9 @@ public slots:
void notificationSlot(QVariant result, int action, int stateNumber);
void errorSlot(int code, const QString &message);
void notificationSlot2(QJSValue result, Actions action, int stateNumber);
+ void statusChangedSlot2();
-protected slots:
+public:
void timeout();
private:
@@ -105,12 +92,10 @@ private:
QStringList mNotificationsReceived;
QList<ComponentData*> mComponents;
QString mPluginPath;
+
+ // Response values
bool mTimedOut;
- bool callbackError;
- int callbackErrorCode;
- QString callbackErrorMessage;
- QList<CallbackData> cbData;
- QEventLoop mEventLoop2;
+ QList<CallbackData> callbackData;
};
#endif
diff --git a/tests/auto/jsondbpartition/jsondbpartition.pro b/tests/auto/jsondbpartition/jsondbpartition.pro
index 09433e1f..be202eb4 100644
--- a/tests/auto/jsondbpartition/jsondbpartition.pro
+++ b/tests/auto/jsondbpartition/jsondbpartition.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbpartition
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbpartition.h
+HEADERS += testjsondbpartition.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbpartition.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbpartition/partitions.json b/tests/auto/jsondbpartition/partitions.json
new file mode 100644
index 00000000..9788d134
--- /dev/null
+++ b/tests/auto/jsondbpartition/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared.1" }
+]
diff --git a/tests/auto/jsondbpartition/testjsondbpartition.cpp b/tests/auto/jsondbpartition/testjsondbpartition.cpp
index bfdafa62..2f275434 100644
--- a/tests/auto/jsondbpartition/testjsondbpartition.cpp
+++ b/tests/auto/jsondbpartition/testjsondbpartition.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QJSValueIterator>
#include "testjsondbpartition.h"
#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-partition";
@@ -69,8 +68,9 @@ TestJsonDbPartition::~TestJsonDbPartition()
void TestJsonDbPartition::timeout()
{
- ClientWrapper::timeout();
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
}
void TestJsonDbPartition::deleteDbFiles()
@@ -87,45 +87,20 @@ void TestJsonDbPartition::deleteDbFiles()
}
}
-QVariant TestJsonDbPartition::readJsonFile(const QString& filename)
-{
- QString filepath = findFile(filename);
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- return parser.result();
-}
-
void TestJsonDbPartition::initTestCase()
{
// make sure there is no old db files.
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.1");
- int id = mClient->create(item);
- waitForResponse1(id);
-
+ if (mPluginPath.isEmpty())
+ qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
}
ComponentData *TestJsonDbPartition::createComponent()
@@ -173,7 +148,7 @@ void TestJsonDbPartition::callbackSlot(QVariant error, QVariant response)
callbackError = error.isValid();
callbackMeta = response;
callbackResponse = response.toMap().value("items").toList();
- mEventLoop.quit();
+ eventLoop1.quit();
}
// JsonDb.Partition.create()
@@ -192,7 +167,7 @@ void TestJsonDbPartition::create()
int id = 0;
expr = new QQmlExpression(partition->engine->rootContext(), partition->qmlElement, expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -201,7 +176,7 @@ void TestJsonDbPartition::create()
expression = QString(createString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -210,7 +185,7 @@ void TestJsonDbPartition::create()
expression = QString(createString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
@@ -238,7 +213,7 @@ void TestJsonDbPartition::update()
int id = 0;
expr = new QQmlExpression(partition->engine->rootContext(), partition->qmlElement, expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -250,7 +225,7 @@ void TestJsonDbPartition::update()
expression = QString(updateString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -259,7 +234,7 @@ void TestJsonDbPartition::update()
expression = QString(createString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
@@ -275,7 +250,7 @@ void TestJsonDbPartition::update()
expression = QString(updateString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
@@ -303,17 +278,26 @@ void TestJsonDbPartition::remove()
int id = 0;
expr = new QQmlExpression(partition->engine->rootContext(), partition->qmlElement, expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
//Remove this object
- obj = callbackResponse.toList();
+ {
+ QVariantList newList;
+ QVariantList list = callbackResponse.toList();
+ for (int i = 0; i<list.count(); i++) {
+ QVariantMap objMap = list[i].toMap();
+ objMap.insert("_type", __FUNCTION__);
+ newList.append(objMap);
+ }
+ obj = newList;
+ }
expression = QString(removeString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -322,17 +306,26 @@ void TestJsonDbPartition::remove()
expression = QString(createString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
//Remove all objects
- obj = callbackResponse.toList();
+ {
+ QVariantList newList;
+ QVariantList list = callbackResponse.toList();
+ for (int i = 0; i<list.count(); i++) {
+ QVariantMap objMap = list[i].toMap();
+ objMap.insert("_type", __FUNCTION__);
+ newList.append(objMap);
+ }
+ obj = newList;
+ }
expression = QString(removeString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
@@ -359,7 +352,7 @@ void TestJsonDbPartition::find()
int id = 0;
expr = new QQmlExpression(partition->engine->rootContext(), partition->qmlElement, expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -368,7 +361,7 @@ void TestJsonDbPartition::find()
expression = findString;
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 1);
@@ -377,7 +370,7 @@ void TestJsonDbPartition::find()
expression = QString(createString).arg(objectString(QString(), obj));
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 5);
@@ -386,7 +379,7 @@ void TestJsonDbPartition::find()
expression = findString;
expr->setExpression(expression);
id = expr->evaluate().toInt();
- waitForCallback();
+ waitForCallback1();
QCOMPARE(callbackError, false);
QCOMPARE(callbackMeta.toMap()["id"].toInt(), id);
QCOMPARE(callbackResponse.toList().size(), 6);
diff --git a/tests/auto/jsondbpartition/testjsondbpartition.h b/tests/auto/jsondbpartition/testjsondbpartition.h
index 74896a8a..5ab757bf 100644
--- a/tests/auto/jsondbpartition/testjsondbpartition.h
+++ b/tests/auto/jsondbpartition/testjsondbpartition.h
@@ -41,26 +41,13 @@
#ifndef TESTJSONDBPARTITION_H
#define TESTJSONDBPARTITION_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_USE_NAMESPACE_JSONDB
-class TestJsonDbPartition: public ClientWrapper
+class TestJsonDbPartition: public RequestWrapper
{
Q_OBJECT
public:
@@ -80,23 +67,21 @@ private slots:
public slots:
void callbackSlot(QVariant error, QVariant response);
-protected slots:
+public:
void timeout();
private:
ComponentData *createComponent();
void deleteComponent(ComponentData *componentData);
- QVariant readJsonFile(const QString &filename);
private:
QProcess *mProcess;
QStringList mNotificationsReceived;
QList<ComponentData*> mComponents;
QString mPluginPath;
+
+ // Response values
bool mTimedOut;
- bool callbackError;
- QVariant callbackMeta;
- QVariant callbackResponse;
};
#endif
diff --git a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
index 62157bb2..717acef4 100644
--- a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
+++ b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbqueryobject
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbqueryobject.h
+HEADERS += testjsondbqueryobject.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbqueryobject.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbqueryobject/partitions.json b/tests/auto/jsondbqueryobject/partitions.json
new file mode 100644
index 00000000..c77651a0
--- /dev/null
+++ b/tests/auto/jsondbqueryobject/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
index 8205a18f..2a214dbb 100644
--- a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
+++ b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QJSValueIterator>
#include "testjsondbqueryobject.h"
#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-partition";
@@ -86,8 +85,9 @@ TestJsonDbQueryObject::~TestJsonDbQueryObject()
void TestJsonDbQueryObject::timeout()
{
- ClientWrapper::timeout();
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
}
void TestJsonDbQueryObject::deleteDbFiles()
@@ -110,25 +110,14 @@ void TestJsonDbQueryObject::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = mClient->create(item);
- waitForResponse1(id);
-
+ if (mPluginPath.isEmpty())
+ qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
}
ComponentData *TestJsonDbQueryObject::createComponent(const QString &qml)
@@ -201,14 +190,14 @@ void TestJsonDbQueryObject::errorSlot(const QVariantMap &newError)
callbackError = true;
callbackErrorCode = code;
callbackErrorMessage = message;
- mEventLoop2.quit();
+ eventLoop1.quit();
}
void TestJsonDbQueryObject::finishedSlot()
{
QMetaObject::invokeMethod(currentQmlElement, "takeResults", Qt::DirectConnection,
- Q_RETURN_ARG(QVariantList, cbData));
- mEventLoop2.quit();
+ Q_RETURN_ARG(QVariantList, callbackData));
+ eventLoop1.quit();
}
bool posLessThan(const QVariant &v1, const QVariant &v2)
@@ -230,13 +219,14 @@ void TestJsonDbQueryObject::singleObject()
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
+ create(item, "com.nokia.shared");
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
+ callbackData.clear();
+ waitForCallback1();
+ QCOMPARE(callbackData.size(), 1);
QCOMPARE(callbackError, false);
delete expr;
deleteComponent(queryObject);
@@ -252,7 +242,8 @@ void TestJsonDbQueryObject::multipleObjects()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index, "com.nokia.shared");
+ int id = create(index, "com.nokia.shared");
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -260,18 +251,19 @@ void TestJsonDbQueryObject::multipleObjects()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 10);
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -299,11 +291,13 @@ void TestJsonDbQueryObject::createQuery()
this, SLOT(errorSlot(QVariantMap)));
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
+ int id = create(item, "com.nokia.shared");
+ waitForResponse1(id);
+
QMetaObject::invokeMethod(currentQmlElement, "start", Qt::DirectConnection);
- cbData.clear();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
+ callbackData.clear();
+ waitForCallback1();
+ QCOMPARE(callbackData.size(), 1);
QCOMPARE(callbackError, false);
delete expr;
deleteComponent(partition);
@@ -319,7 +313,8 @@ void TestJsonDbQueryObject::queryWithoutPartition()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index);
+ int id = create(index);
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -327,18 +322,19 @@ void TestJsonDbQueryObject::queryWithoutPartition()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items));
+ create(items);
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 10);
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -361,19 +357,20 @@ void TestJsonDbQueryObject::queryBinding()
queryObject->qmlElement->setProperty("bindings", bindingMap);
currentQmlElement = queryObject->qmlElement;
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 1);
+ QCOMPARE(callbackData.size(), 1);
QVariantMap item = items[0].toMap();
- QVariantMap obj = cbData[0].toMap();
+ QVariantMap obj = callbackData[0].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
delete expr;
deleteComponent(queryObject);
@@ -394,13 +391,14 @@ void TestJsonDbQueryObject::queryError()
queryObject->qmlElement->setProperty("bindings", bindingMap);
currentQmlElement = queryObject->qmlElement;
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, true);
delete expr;
@@ -417,7 +415,8 @@ void TestJsonDbQueryObject::queryLimit()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index, "com.nokia.shared");
+ int id = create(index, "com.nokia.shared");
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -426,18 +425,19 @@ void TestJsonDbQueryObject::queryLimit()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 5);
+ QCOMPARE(callbackData.size(), 5);
for (int i = 0; i<5; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -445,6 +445,5 @@ void TestJsonDbQueryObject::queryLimit()
deleteComponent(queryObject);
}
-
QTEST_MAIN(TestJsonDbQueryObject)
diff --git a/tests/auto/jsondbqueryobject/testjsondbqueryobject.h b/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
index c79745a3..4c2645f6 100644
--- a/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
+++ b/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
@@ -41,27 +41,13 @@
#ifndef TESTJSONDBQUERYOBJECT_H
#define TESTJSONDBQUERYOBJECT_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-#include <QJSValue>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_USE_NAMESPACE_JSONDB
-class TestJsonDbQueryObject: public ClientWrapper
+class TestJsonDbQueryObject: public RequestWrapper
{
Q_OBJECT
public:
@@ -85,7 +71,7 @@ public slots:
void errorSlot(const QVariantMap &newError);
void finishedSlot();
-protected slots:
+public:
void timeout();
private:
@@ -95,17 +81,12 @@ private:
private:
QProcess *mProcess;
- QStringList mNotificationsReceived;
QList<ComponentData*> mComponents;
QString mPluginPath;
+
bool mTimedOut;
- bool callbackError;
- int callbackErrorCode;
- QString callbackErrorMessage;
- QVariantList cbData;
- QEventLoop mEventLoop2;
QObject *currentQmlElement;
-
+ QVariantList callbackData;
};
#endif
diff --git a/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro b/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
index cea282e6..7d1b4f74 100644
--- a/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
+++ b/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbsortinglistmodel
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbsortinglistmodel.h
+HEADERS += testjsondbsortinglistmodel.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbsortinglistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbsortinglistmodel/partitions.json b/tests/auto/jsondbsortinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/auto/jsondbsortinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
index 762ce59b..f9edeedb 100644
--- a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
+++ b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
@@ -41,11 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QQmlListReference>
#include "testjsondbsortinglistmodel.h"
-
#include "../../shared/util.h"
-#include <QQmlListReference>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-listmodel";
ModelData::ModelData(): engine(0), component(0), model(0)
@@ -56,22 +54,20 @@ ModelData::~ModelData()
{
if (model)
delete model;
- if (parttion1)
- delete parttion1;
- if (parttion2)
- delete parttion2;
-
if (component)
delete component;
- if (partitionComponent1)
- delete partitionComponent1;
- if (partitionComponent2)
- delete partitionComponent2;
-
if (engine)
delete engine;
}
+const QString qmlProgram = QLatin1String(
+ "import QtQuick 2.0\n"
+ "import QtJsonDb 1.0 as JsonDb \n"
+ "JsonDb.JsonDbSortingListModel {"
+ "id: contactsModel;"
+ "partitions: [JsonDb.Partition {name: \"com.nokia.shared.1\"}, JsonDb.Partition {name: \"com.nokia.shared.2\"}]"
+ "}");
+
QVariant get(QObject* object, int index, QString propertyName)
{
QVariant retVal;
@@ -101,7 +97,6 @@ int indexOf(QObject* object, const QString &uuid)
}
TestJsonDbSortingListModel::TestJsonDbSortingListModel()
- : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false)
{
}
@@ -118,26 +113,11 @@ void TestJsonDbSortingListModel::deleteDbFiles()
nameFilter << "objectFile.bin" << "objectFile2.bin";
QFileInfoList databaseFiles = currentDir.entryInfoList(nameFilter, QDir::Files);
foreach (QFileInfo fileInfo, databaseFiles) {
- //qDebug() << "Deleted : " << fileInfo.fileName();
QFile file(fileInfo.fileName());
file.remove();
}
}
-QVariant TestJsonDbSortingListModel::readJsonFile(const QString& filename)
-{
- QString filepath = findFile(filename);
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- return parser.result();
-}
-
void TestJsonDbSortingListModel::connectListModel(QAbstractListModel *model)
{
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)));
@@ -147,7 +127,7 @@ void TestJsonDbSortingListModel::connectListModel(QAbstractListModel *model)
connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(rowsMoved(QModelIndex,int,int,QModelIndex,int)));
connect(model, SIGNAL(stateChanged(State)),
- this, SLOT(stateChanged()));
+ this, SLOT(stateChanged(State)));
}
void TestJsonDbSortingListModel::initTestCase()
@@ -156,31 +136,27 @@ void TestJsonDbSortingListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
+ if (mPluginPath.isEmpty())
+ qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
// Create the shared Partitions
QVariantMap item;
item.insert("_type", "Partition");
item.insert("name", "com.nokia.shared.1");
- int id = mClient->create(item);
+ int id = create(item);
waitForResponse1(id);
item.clear();
item.insert("_type", "Partition");
item.insert("name", "com.nokia.shared.2");
- id = mClient->create(item);
+ id = create(item);
waitForResponse1(id);
-
}
QAbstractListModel *TestJsonDbSortingListModel::createModel()
@@ -188,40 +164,17 @@ QAbstractListModel *TestJsonDbSortingListModel::createModel()
ModelData *newModel = new ModelData();
newModel->engine = new QQmlEngine();
QString error;
+ Q_ASSERT(!mPluginPath.isEmpty());
if (!newModel->engine->importPlugin(mPluginPath, QString("QtJsonDb"), &error)) {
qDebug()<<"Unable to load the plugin :"<<error;
delete newModel->engine;
return 0;
}
newModel->component = new QQmlComponent(newModel->engine);
- newModel->component->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.JsonDbSortingListModel {id: contactsModel}",
- QUrl());
+ newModel->component->setData(qmlProgram.toLocal8Bit(), QUrl());
newModel->model = newModel->component->create();
if (newModel->component->isError())
qDebug() << newModel->component->errors();
-
- newModel->partitionComponent1 = new QQmlComponent(newModel->engine);
- newModel->partitionComponent1->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.Partition {name: \"com.nokia.shared.1\"}",
- QUrl());
- newModel->parttion1 = newModel->partitionComponent1->create();
- if (newModel->partitionComponent1->isError())
- qDebug() << newModel->partitionComponent1->errors();
-
-
- newModel->partitionComponent2 = new QQmlComponent(newModel->engine);
- newModel->partitionComponent2->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n"
- "JsonDb.Partition {name: \"com.nokia.shared.2\"}",
- QUrl());
- newModel->parttion2 = newModel->partitionComponent2->create();
- if (newModel->partitionComponent2->isError())
- qDebug() << newModel->partitionComponent2->errors();
-
- QQmlListReference partitions(newModel->model, "partitions", newModel->engine);
- partitions.append(newModel->parttion1);
- partitions.append(newModel->parttion2);
-
mModels.append(newModel);
return (QAbstractListModel*)(newModel->model);
}
@@ -251,33 +204,39 @@ void TestJsonDbSortingListModel::cleanupTestCase()
// Create items in the model.
void TestJsonDbSortingListModel::createItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.nokia.shared.1");
-
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
if (!listModel) return;
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
-
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name");
listModel->setProperty("roleNames", roleNames);
connectListModel(listModel);
// now start it working
QCOMPARE(listModel->rowCount(), 0);
-
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 1);
QCOMPARE(listModel->property("state").toInt(), 2);
item.clear();
item.insert("_type", __FUNCTION__);
item.insert("name", "Baker");
- id = mClient->create(item, "com.nokia.shared.1");
- waitForItemChanged();
+ mItemsCreated = 0;
+ id = create(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsCreated) {
+ mWaitingForRowsInserted = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRowsInserted, false);
QCOMPARE(listModel->rowCount(), 2);
deleteModel(listModel);
@@ -286,10 +245,11 @@ void TestJsonDbSortingListModel::createItem()
// Create an item and then update it.
void TestJsonDbSortingListModel::updateItemClient()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item,"com.nokia.shared.1");
+ int id = create(item,"com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
@@ -301,20 +261,31 @@ void TestJsonDbSortingListModel::updateItemClient()
// now start it working
QCOMPARE(listModel->rowCount(), 0);
-
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 1);
- item.insert("_uuid", mLastUuid);
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
+ item.insert("_version", lastVersion);
item.insert("name", "Baker");
-
- mWaitingForDataChange = true;
-
- id = mClient->update(item, "com.nokia.shared.1");
- waitForItemChanged();
+ id = update(item, "com.nokia.shared.1");
+ waitForResponse1(id);
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
QCOMPARE(listModel->rowCount(), 1);
- QCOMPARE(get(listModel, 0, "_uuid").toString(), mLastUuid);
+ QCOMPARE(get(listModel, 0, "_uuid").toString(), lastUuid);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
QCOMPARE(get(listModel,0, "name").toString(), QLatin1String("Baker"));
deleteModel(listModel);
@@ -322,10 +293,11 @@ void TestJsonDbSortingListModel::updateItemClient()
void TestJsonDbSortingListModel::deleteItem()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
@@ -336,19 +308,38 @@ void TestJsonDbSortingListModel::deleteItem()
connectListModel(listModel);
// now start it working
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 1);
item.insert("name", "Baker");
- id = mClient->create(item, "com.nokia.shared.2");
+ mItemsCreated = 0;
+ id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
-
+ while (!mItemsCreated) {
+ mWaitingForRowsInserted = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRowsInserted, false);
QCOMPARE(listModel->rowCount(), 2);
- mWaitingForRowsRemoved = true;
- item.insert("_uuid", mLastUuid);
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged(true);
+ QString lastUuid,lastVersion;
+ QVariantMap lastItem;
+ if (lastResult.count()) {
+ lastItem = lastResult[0].toMap();
+ lastUuid = lastItem.value("_uuid").toString();
+ lastVersion = lastItem.value("_version").toString();
+ }
+ item.insert("_uuid", lastUuid);
+ item.insert("_version", lastVersion);
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ while (!mItemsRemoved) {
+ mWaitingForRemoved = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForRemoved, false);
QCOMPARE(listModel->rowCount(), 1);
QCOMPARE(get(listModel, 0, "_type").toString(), QLatin1String(__FUNCTION__));
@@ -358,12 +349,13 @@ void TestJsonDbSortingListModel::deleteItem()
void TestJsonDbSortingListModel::sortedQuery()
{
+ resetWaitFlags();
int id = 0;
for (int i = 0; i < 1000; i++) {
QVariantMap item;
item.insert("_type", "RandNumber");
item.insert("number", i);
- id = mClient->create(item,"com.nokia.shared.2");
+ id = create(item,"com.nokia.shared.2");
waitForResponse1(id);
}
@@ -377,7 +369,9 @@ void TestJsonDbSortingListModel::sortedQuery()
listModel->setProperty("roleNames", rolenames);
listModel->setProperty("sortOrder", "[/number]");
listModel->setProperty("query", "[?_type=\"RandNumber\"]");
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->property("sortOrder").toString(), QString("[/number]"));
@@ -408,12 +402,13 @@ bool greaterThan(const QString &s1, const QString &s2)
void TestJsonDbSortingListModel::ordering()
{
+ resetWaitFlags();
for (int i = 9; i >= 1; --i) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", QString::number(i));
- int id = mClient->create(item, "com.nokia.shared.2");
+ int id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
}
@@ -427,7 +422,9 @@ void TestJsonDbSortingListModel::ordering()
// now start it working
QCOMPARE(listModel->rowCount(), 0);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QStringList expectedOrder = QStringList() << "1" << "2" << "3" << "4" <<
"5" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
@@ -440,13 +437,18 @@ void TestJsonDbSortingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "99"); // move it to the end
- mClient->update(item, "com.nokia.shared.2");
+ update(item, "com.nokia.shared.2");
}
- waitForItemChanged();
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "1" << "2" << "3" <<
"4" << "6" << "7" << "8" << "9" << "99";
QCOMPARE(getOrderValues(listModel), expectedOrder);
+ mItemsUpdated = 0;
{
QVariant uuid = get(listModel, 8, "_uuid");
QVERIFY(!uuid.toString().isEmpty());
@@ -456,13 +458,18 @@ void TestJsonDbSortingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "22"); // move it after "2"
- mClient->update(item, "com.nokia.shared.2");
+ update(item, "com.nokia.shared.2");
+ }
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
}
- waitForItemChanged();
+ QCOMPARE(mWaitingForChanged, false);
expectedOrder = QStringList() << "1" << "2" << "22" << "3" <<
"4" << "6" << "7" << "8" << "9";
QCOMPARE(getOrderValues(listModel), expectedOrder);
+ mItemsUpdated = 0;
{
QVariant uuid = get(listModel, 5, "_uuid");
QVERIFY(!uuid.toString().isEmpty());
@@ -472,9 +479,13 @@ void TestJsonDbSortingListModel::ordering()
item.insert("_type", __FUNCTION__);
item.insert("name", "Charlie");
item.insert("order", "0"); // move it to the beginning
- mClient->update(item, "com.nokia.shared.2");
+ update(item, "com.nokia.shared.2");
}
- waitForItemChanged();
+ while (!mItemsUpdated) {
+ mWaitingForChanged = true;
+ waitForExitOrTimeout();
+ }
+ QCOMPARE(mWaitingForChanged, false);
// Check for order and togther with queryLimit
expectedOrder = QStringList() << "0" << "1" << "2" << "22" << "3" <<
@@ -489,23 +500,27 @@ void TestJsonDbSortingListModel::ordering()
QCOMPARE(getOrderValues(listModel), expectedOrder);
listModel->setProperty("queryLimit", 5);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 5);
QCOMPARE(getOrderValues(listModel), QStringList(expectedOrder.mid(0, 5)));
listModel->setProperty("sortOrder", "[\\order]");
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 5);
QCOMPARE(getOrderValues(listModel), QStringList(reverseOrder.mid(0, 5)));
deleteModel(listModel);
-
}
void TestJsonDbSortingListModel::checkRemoveNotification()
{
+ resetWaitFlags();
QVariantList itemList;
for (int i = 0; i < 50; i++) {
QVariantMap item;
@@ -514,7 +529,7 @@ void TestJsonDbSortingListModel::checkRemoveNotification()
item.insert("order", i);
itemList << item;
}
- int id = mClient->create(itemList,"com.nokia.shared.2");
+ int id = create(itemList,"com.nokia.shared.2");
waitForResponse1(id);
{
@@ -526,9 +541,12 @@ void TestJsonDbSortingListModel::checkRemoveNotification()
listModel->setProperty("sortOrder", "[/order]");
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "_version"<< "name" << "order");
listModel->setProperty("roleNames", roleNames);
- waitForStateOrTimeout();
+ mWaitingForStateChanged = true;
+ waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
+
QVariant result = get(listModel, 0, "order");
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 0);
@@ -540,8 +558,10 @@ void TestJsonDbSortingListModel::checkRemoveNotification()
QVariantMap item;
item.insert("_uuid", get(listModel, 0, "_uuid"));
item.insert("_version", get(listModel, 0, "_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged();
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForStateChanged(listModel);
+
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 9, "order");
QVERIFY(result.isValid());
@@ -550,8 +570,10 @@ void TestJsonDbSortingListModel::checkRemoveNotification()
//Remove item at 9
item.insert("_uuid", get(listModel, 9, "_uuid"));
item.insert("_version", get(listModel, 9, "_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged();
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForStateChanged(listModel);
+
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 9, "order");
QVERIFY(result.isValid());
@@ -560,8 +582,10 @@ void TestJsonDbSortingListModel::checkRemoveNotification()
//Remove item at 4
item.insert("_uuid", get(listModel, 4, "_uuid"));
item.insert("_version", get(listModel, 4, "_version"));
- id = mClient->remove(item, "com.nokia.shared.2");
- waitForItemChanged();
+ id = remove(item, "com.nokia.shared.2");
+ waitForResponse1(id);
+ waitForStateChanged(listModel);
+
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 4, "order");
QVERIFY(result.isValid());
@@ -583,7 +607,7 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
item.insert("order", i);
itemList << item;
}
- int id = mClient->create(itemList, "com.nokia.shared.1");
+ int id = create(itemList, "com.nokia.shared.1");
waitForResponse1(id);
{
@@ -595,9 +619,12 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
listModel->setProperty("sortOrder", "[/order]");
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "_version"<< "name" << "order");
listModel->setProperty("roleNames", roleNames);
- waitForStateOrTimeout();
+ mWaitingForStateChanged = true;
+ waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
+
QVariant result = get(listModel, 0, "order");
QVERIFY(result.isValid());
QCOMPARE(result.toInt(), 0);
@@ -611,8 +638,10 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
item.insert("_type", get(listModel, 0, "_type"));
item.insert("name", get(listModel, 0, "name"));
item.insert("order", 1);
- id = mClient->update(item, "com.nokia.shared.1");
+ id = update(item, "com.nokia.shared.1");
+
waitForItemChanged();
+ QCOMPARE(mWaitingForChanged, false);
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 0, "order");
@@ -628,16 +657,11 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
item.insert("_type", get(listModel, 9, "_type"));
item.insert("name", get(listModel, 9, "name"));
item.insert("order", 19);
- id = mClient->update(item,"com.nokia.shared.1");
- waitForItemChanged();
+ id = update(item,"com.nokia.shared.1");
- item.clear();
- item.insert("_uuid", get(listModel, 9, "_uuid"));
- item.insert("_type", get(listModel, 9, "_type"));
- item.insert("name", get(listModel, 9, "name"));
- item.insert("order", 19);
- id = mClient->update(item,"com.nokia.shared.1");
waitForItemChanged();
+ QCOMPARE(mWaitingForStateChanged, false);
+ waitForStateChanged(listModel);
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 0, "order");
@@ -652,8 +676,11 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
item.insert("_type", get(listModel, 9, "_type"));
item.insert("name", get(listModel, 9, "name"));
item.insert("order", 59);
- id = mClient->update(item, "com.nokia.shared.1");
+ id = update(item, "com.nokia.shared.1");
+
waitForItemChanged();
+ QCOMPARE(mWaitingForStateChanged, false);
+ waitForStateChanged(listModel);
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 0, "order");
@@ -668,8 +695,11 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
item.insert("_type", get(listModel, 8, "_type"));
item.insert("name", get(listModel, 8, "name"));
item.insert("order", 17);
- id = mClient->update(item, "com.nokia.shared.1");
+ id = update(item, "com.nokia.shared.1");
+
waitForItemChanged();
+ QCOMPARE(mWaitingForStateChanged, false);
+ waitForStateChanged(listModel);
QCOMPARE(listModel->rowCount(), 10);
result = get(listModel, 8, "order");
@@ -688,15 +718,16 @@ void TestJsonDbSortingListModel::checkUpdateNotification()
void TestJsonDbSortingListModel::totalRowCount()
{
+ resetWaitFlags();
int id = 0;
QVariantList insertedItems;
for (int i = 0; i < 10; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- id = mClient->create(item, "com.nokia.shared.1");
+ id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
- insertedItems << mData;
+ insertedItems << lastResult;
}
QAbstractListModel *listModel = createModel();
@@ -704,34 +735,50 @@ void TestJsonDbSortingListModel::totalRowCount()
return;
connectListModel(listModel);
- listModel->setProperty("queryLimit", 50);
+ listModel->setProperty("queryLimit", 100);
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "order");
listModel->setProperty("roleNames", roleNames);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
+ mItemsCreated = 0;
for (int i = 10; i < 50; i++) {
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("order", i);
- mClient->create(item, "com.nokia.shared.2");
+ id = create(item, "com.nokia.shared.2");
+ waitForResponse1(id);
}
- waitForItemsCreated(40);
+ waitForItemsCreated(40); // will set mWaitingForRowsInserted = true for you
+ if (id != lastRequestId)
+ waitForResponse1(id);
+ QCOMPARE(mWaitingForRowsInserted, false);
+ QCOMPARE(mItemsCreated, 40);
QCOMPARE(listModel->rowCount(), 50);
// Change sort order
+ mWaitingForReadyState = true;
listModel->setProperty("sortOrder", "[\\order]");
- waitForStateOrTimeout();
+ QVariant state = listModel->property("state");
+ if (state.toInt() != 2) {
+ waitForReadyStateOrTimeout();
+ QCOMPARE(mWaitingForReadyState, false);
+ }
+ else
+ mWaitingForReadyState = false;
QCOMPARE(listModel->rowCount(), 50);
// Delete the first 10 items
foreach (QVariant item, insertedItems) {
- mWaitingForRowsRemoved = true;
- id = mClient->remove(item.toMap(), "com.nokia.shared.1");
- waitForItemChanged(true);
+ mItemsRemoved = 0;
+ id = remove(item.toMap(), "com.nokia.shared.1");
+ waitForResponse1(id);
+ waitForItemsRemoved(1);
}
QCOMPARE(listModel->rowCount(), 40);
@@ -741,15 +788,16 @@ void TestJsonDbSortingListModel::totalRowCount()
void TestJsonDbSortingListModel::listProperty()
{
- QVariant jsonData = readJsonFile("list-objects.json");
+ resetWaitFlags();
+ QVariant jsonData = readJsonFile(findFile("list-objects.json")).toVariant();
QVariantList itemList = jsonData.toList();
int id = 0;
for (int i = 0; i < itemList.count()/2; i++) {
- id = mClient->create(itemList[i].toMap(), "com.nokia.shared.1");
+ id = create(itemList[i].toMap(), "com.nokia.shared.1");
waitForResponse1(id);
}
for (int i = itemList.count()/2; i < itemList.count(); i++) {
- id = mClient->create(itemList[i].toMap(), "com.nokia.shared.2");
+ id = create(itemList[i].toMap(), "com.nokia.shared.2");
waitForResponse1(id);
}
@@ -763,13 +811,17 @@ void TestJsonDbSortingListModel::listProperty()
listModel->setProperty("sortOrder", "[/features.0.properties.0.description]");
QStringList roleNames = (QStringList() << "_type" << "_uuid" << "features.0.properties.0.description"<< "features.0.feature");
listModel->setProperty("roleNames", roleNames);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), itemList.count());
+
QCOMPARE(get(listModel, 0, "_type").toString(), type);
QCOMPARE(get(listModel, 0, "features.0.properties.0.description").toString(), QLatin1String("Facebook account provider"));
QCOMPARE(get(listModel, 0, "features.0.feature").toString(), QLatin1String("provide Facebook"));
- QCOMPARE(get(listModel, 1, "_uuid").toString(), mLastUuid);
+ //Liang: todo or not?
+ //QCOMPARE(get(listModel, 1, "_uuid").toString(), mLastUuid);
QCOMPARE(get(listModel, 1, "_type").toString(), type);
QCOMPARE(get(listModel, 1, "features.0.properties.0.description").toString(), QLatin1String("Gmail account provider"));
QCOMPARE(get(listModel, 1, "features.0.feature").toString(), QLatin1String("provide Gmail"));
@@ -787,7 +839,9 @@ void TestJsonDbSortingListModel::listProperty()
roleNames.clear();
roleNames = (QStringList() << "_type" << "_uuid" << "features[0].properties[0].description"<< "features[0].supported[0]");
listModel->setProperty("roleNames", roleNames);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), itemList.count());
QCOMPARE(get(listModel, 0, "_type").toString(), type);
@@ -800,23 +854,23 @@ void TestJsonDbSortingListModel::listProperty()
deleteModel(listModel);
}
-
// Populate model of 300 items two partitions.
void TestJsonDbSortingListModel::twoPartitions()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 300; i = i+2) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
for (int i=1; i < 300; i = i+2) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.2");
+ int id = create(item, "com.nokia.shared.2");
waitForResponse1(id);
}
@@ -829,7 +883,9 @@ void TestJsonDbSortingListModel::twoPartitions()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 300);
QCOMPARE(get(listModel, 0, "name").toString(), QString("Arnie_0"));
@@ -842,12 +898,13 @@ void TestJsonDbSortingListModel::twoPartitions()
void TestJsonDbSortingListModel::changeQuery()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 10; i++) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
@@ -860,7 +917,9 @@ void TestJsonDbSortingListModel::changeQuery()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
QCOMPARE(listModel->property("query").toString(), QString("[?_type=\"%1\"]").arg(__FUNCTION__));
@@ -876,7 +935,10 @@ void TestJsonDbSortingListModel::changeQuery()
QCOMPARE(listModel->property("query").toString(), QString(""));
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
+
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
QCOMPARE(listModel->property("query").toString(), QString("[?_type=\"%1\"]").arg(__FUNCTION__));
@@ -886,12 +948,13 @@ void TestJsonDbSortingListModel::changeQuery()
void TestJsonDbSortingListModel::getQJSValue()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 10; i++) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
@@ -904,7 +967,9 @@ void TestJsonDbSortingListModel::getQJSValue()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 10);
QCOMPARE(get(listModel, 0).property("object").property("name").toString(), QString("Arnie_0"));
@@ -913,13 +978,13 @@ void TestJsonDbSortingListModel::getQJSValue()
deleteModel(listModel);
}
-
void TestJsonDbSortingListModel::indexOfUuid()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_0"));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
QAbstractListModel *listModel = createModel();
@@ -931,7 +996,9 @@ void TestJsonDbSortingListModel::indexOfUuid()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 1);
QCOMPARE(get(listModel, 0, "name").toString(), QString("Arnie_0"));
@@ -939,9 +1006,14 @@ void TestJsonDbSortingListModel::indexOfUuid()
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_1"));
- id = mClient->create(item, "com.nokia.shared.1");
+ id = create(item, "com.nokia.shared.1");
+ waitForResponse1(id);
- waitForItemsCreated(1);
+ waitForItemsCreated(1); // will set mWaitingForRowsInserted = true for you
+ if (id != lastRequestId)
+ waitForResponse1(id);
+ QCOMPARE(mWaitingForRowsInserted, false);
+ QCOMPARE(mItemsCreated, 1);
QCOMPARE(listModel->rowCount(), 2);
QCOMPARE(get(listModel, 1, "name").toString(), QString("Arnie_1"));
@@ -953,12 +1025,13 @@ void TestJsonDbSortingListModel::indexOfUuid()
void TestJsonDbSortingListModel::queryLimit()
{
+ resetWaitFlags();
QVariantMap item;
for (int i=0; i < 300; i++) {
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie_%1").arg(i));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
}
@@ -972,7 +1045,9 @@ void TestJsonDbSortingListModel::queryLimit()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 100);
QCOMPARE(listModel->property("overflow").toBool(), true);
@@ -983,7 +1058,10 @@ void TestJsonDbSortingListModel::queryLimit()
listModel->setProperty("queryLimit", 500);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
+
QCOMPARE(listModel->rowCount(), 300);
QCOMPARE(listModel->property("overflow").toBool(), false);
@@ -992,15 +1070,15 @@ void TestJsonDbSortingListModel::queryLimit()
void TestJsonDbSortingListModel::roleNames()
{
+ resetWaitFlags();
QVariantMap item;
item.insert("_type", __FUNCTION__);
item.insert("name", QString("Arnie"));
item.insert("friend", QString("Bert"));
- int id = mClient->create(item, "com.nokia.shared.1");
+ int id = create(item, "com.nokia.shared.1");
waitForResponse1(id);
-
QAbstractListModel *listModel = createModel();
if (!listModel) return;
@@ -1009,7 +1087,9 @@ void TestJsonDbSortingListModel::roleNames()
listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__));
connectListModel(listModel);
+ mWaitingForStateChanged = true;
waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
QCOMPARE(listModel->rowCount(), 1);
@@ -1031,7 +1111,6 @@ void TestJsonDbSortingListModel::roleNames()
deleteModel(listModel);
}
-
QStringList TestJsonDbSortingListModel::getOrderValues(QAbstractListModel *listModel)
{
QStringList vals;
@@ -1042,15 +1121,23 @@ QStringList TestJsonDbSortingListModel::getOrderValues(QAbstractListModel *listM
void TestJsonDbSortingListModel::modelReset()
{
- mWaitingForReset = false;
- mEventLoop2.exit(0);
+ //qDebug() << "modelReset";
+ if (mWaitingForReset) {
+ mWaitingForReset = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbSortingListModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
- mWaitingForDataChange = false;
+ mItemsUpdated++;
+ //qDebug() << "mItemsUpdated++" << mItemsUpdated;
+ if (mWaitingForChanged) {
+ mWaitingForChanged = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbSortingListModel::rowsInserted(const QModelIndex &parent, int first, int last)
@@ -1059,7 +1146,11 @@ void TestJsonDbSortingListModel::rowsInserted(const QModelIndex &parent, int fir
Q_UNUSED(first);
Q_UNUSED(last);
mItemsCreated++;
- mEventLoop2.exit(0);
+ //qDebug() << "mItemsCreated++" << mItemsCreated;
+ if (mWaitingForRowsInserted) {
+ mWaitingForRowsInserted = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbSortingListModel::rowsRemoved(const QModelIndex &parent, int first, int last)
@@ -1067,95 +1158,176 @@ void TestJsonDbSortingListModel::rowsRemoved(const QModelIndex &parent, int firs
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
- mWaitingForRowsRemoved = false;
+ mItemsRemoved++;
+ //qDebug() << "mItemsRemoved++" << mItemsRemoved;
+ if (mWaitingForRemoved) {
+ mWaitingForRemoved = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbSortingListModel::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row )
{
Q_UNUSED(parent);
+
Q_UNUSED(start);
Q_UNUSED(end);
Q_UNUSED(destination);
Q_UNUSED(row);
}
-void TestJsonDbSortingListModel::stateChanged()
+void TestJsonDbSortingListModel::stateChanged(State state)
{
- mWaitingForStateChanged = false;
- mEventLoop2.exit(0);
+ if (mWaitingForStateChanged) {
+ mWaitingForStateChanged = false;
+ eventLoop1.exit(0);
+ }
+ else if (mWaitingForReadyState && state == Ready) {
+ mWaitingForReadyState = false;
+ eventLoop1.exit(0);
+ }
}
void TestJsonDbSortingListModel::waitForItemsCreated(int items)
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mItemsCreated = 0;
- while (mItemsCreated != items && !mTimeoutCalled)
- mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout);
+ while (!mTimedOut && mItemsCreated != items) {
+ mWaitingForRowsInserted = true;
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+}
+
+void TestJsonDbSortingListModel::waitForItemsRemoved(int items)
+{
+ mTimedOut = false;
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+
+ while (!mTimedOut && mItemsRemoved != items) {
+ mWaitingForRemoved = true;
+ eventLoop1.exec(QEventLoop::AllEvents);
+ }
+ if (mTimedOut)
+ qDebug () << "waitForItemsRemoved Timed out";
}
void TestJsonDbSortingListModel::waitForExitOrTimeout()
{
- mTimeoutCalled = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
- mEventLoop2.exec(QEventLoop::AllEvents);
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+ eventLoop1.exec(QEventLoop::AllEvents);
+}
+
+void TestJsonDbSortingListModel::waitForReadyStateOrTimeout()
+{
+ mTimedOut = false;
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.start(clientTimeout);
+ elapsedTimer.start();
+
+ while (mWaitingForReadyState && !mTimedOut)
+ eventLoop1.exec(QEventLoop::AllEvents);
}
void TestJsonDbSortingListModel::waitForStateOrTimeout()
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mWaitingForStateChanged = true;
- while (mWaitingForStateChanged && !mTimeoutCalled)
- mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout);
+ while (mWaitingForStateChanged && !mTimedOut)
+ eventLoop1.exec(QEventLoop::AllEvents);
}
void TestJsonDbSortingListModel::timeout()
{
- ClientWrapper::timeout();
- mTimeoutCalled = true;
+ RequestWrapper::timeout();
+ mTimedOut = true;
+ eventLoop1.quit();
+}
+
+void TestJsonDbSortingListModel::resetWaitFlags()
+{
+ mItemsCreated = 0;
+ mItemsUpdated = 0;
+ mItemsRemoved = 0;
+ mWaitingForRowsInserted = false;
+ mWaitingForReset = false;
+ mWaitingForChanged = false;
+ mWaitingForRemoved = false;
+ mWaitingForStateChanged = false;
+}
+
+void TestJsonDbSortingListModel::waitForStateChanged(QAbstractListModel *listModel)
+{
+ int currentState;
+ currentState = listModel->property("state").toInt();
+ //1: JsonDbSortingListModel::Querying
+ if (currentState != 1) {
+ mWaitingForStateChanged = true;
+ waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
+ currentState = listModel->property("state").toInt();
+ }
+ if (currentState == 1) {
+ mWaitingForStateChanged = true;
+ waitForStateOrTimeout();
+ QCOMPARE(mWaitingForStateChanged, false);
+ currentState = listModel->property("state").toInt();
+ }
}
void TestJsonDbSortingListModel::waitForItemChanged(bool waitForRemove)
{
- mTimeoutCalled = false;
+ mTimedOut = false;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit()));
- timer.start(mClientTimeout);
- mElapsedTimer.start();
+ timer.start(clientTimeout);
+ elapsedTimer.start();
- mWaitingForRowsRemoved = true;
- mWaitingForDataChange = true;
+ mWaitingForRemoved = true;
+ mWaitingForChanged = true;
mItemsCreated = 0;
mWaitingForReset = true;
+ mWaitingForStateChanged = true;
bool waitMore = true;
- while (waitMore && !mTimeoutCalled) {
- if (!mWaitingForDataChange)
+ while (waitMore && !mTimedOut) {
+ if (!mWaitingForChanged) {
+ //qDebug() << "waitForItemChanged: mWaitingForChanged";
+ break;
+ }
+ if (!mWaitingForStateChanged) {
+ //qDebug() << "waitForItemChanged: mWaitingForStateChanged";
break;
- if (mItemsCreated)
+ }
+ if (mItemsCreated){
+ //qDebug() << "waitForItemChanged: mItemsCreated";
break;
- if (!mWaitingForReset)
+ }
+ if (!mWaitingForReset){
+ //qDebug() << "waitForItemChanged: mWaitingForReset";
break;
- if (waitForRemove && !mWaitingForRowsRemoved)
+ }
+ if (waitForRemove && !mWaitingForRemoved){
+ //qDebug() << "waitForItemChanged: mWaitingForRemoved";
break;
- mEventLoop2.processEvents(QEventLoop::AllEvents);
+ }
+ eventLoop1.exec(QEventLoop::AllEvents);
}
}
+
QTEST_MAIN(TestJsonDbSortingListModel)
diff --git a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.h b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.h
index 752eb9a7..dcbad13b 100644
--- a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.h
+++ b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.h
@@ -41,22 +41,9 @@
#ifndef TestJsonDbListModel_H
#define TestJsonDbListModel_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractListModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_BEGIN_NAMESPACE
class QQmlEngine;
@@ -65,7 +52,8 @@ QT_END_NAMESPACE
QT_USE_NAMESPACE_JSONDB
-class JsonDbListModel;
+//class JsonDbListModel;
+enum State { None, Querying, Ready };
class ModelData {
public:
@@ -73,14 +61,10 @@ public:
~ModelData();
QQmlEngine *engine;
QQmlComponent *component;
- QQmlComponent *partitionComponent1;
- QQmlComponent *partitionComponent2;
QObject *model;
- QObject *parttion1;
- QObject *parttion2;
};
-class TestJsonDbSortingListModel: public ClientWrapper
+class TestJsonDbSortingListModel: public RequestWrapper
{
Q_OBJECT
public:
@@ -96,12 +80,12 @@ public slots:
void rowsRemoved(const QModelIndex &parent, int first, int last);
void rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row );
void modelReset();
- void stateChanged();
- void timeout();
+ void stateChanged(State);
private slots:
void initTestCase();
void cleanupTestCase();
+
void createItem();
void updateItemClient();
void deleteItem();
@@ -117,33 +101,37 @@ private slots:
void indexOfUuid();
void queryLimit();
void roleNames();
-
+public:
+ void timeout();
private:
void waitForExitOrTimeout();
void waitForItemsCreated(int items);
+ void waitForItemsRemoved(int items);
void waitForStateOrTimeout();
+ void waitForReadyStateOrTimeout();
+ void waitForStateChanged(QAbstractListModel *listModel);
void waitForItemChanged(bool waitForRemove = false);
QStringList getOrderValues(QAbstractListModel *listModel);
QAbstractListModel *createModel();
void deleteModel(QAbstractListModel *model);
- QVariant readJsonFile(const QString &filename);
+ void resetWaitFlags();
private:
QProcess *mProcess;
- QStringList mNotificationsReceived;
QList<ModelData*> mModels;
QString mPluginPath;
- QEventLoop mEventLoop2; // for all listmodel slots
// Response values
+ bool mTimedOut;
int mItemsCreated;
- bool mWaitingForNotification;
- bool mWaitingForDataChange;
- bool mWaitingForRowsRemoved;
- bool mTimeoutCalled;
+ int mItemsUpdated;
+ int mItemsRemoved;
+ bool mWaitingForRowsInserted;
bool mWaitingForReset;
+ bool mWaitingForChanged;
+ bool mWaitingForRemoved;
bool mWaitingForStateChanged;
-
+ bool mWaitingForReadyState;
};
#endif
diff --git a/tests/auto/jsonstream/jsonstream.pro b/tests/auto/jsonstream/jsonstream.pro
index 172fc7b2..f2f75c2f 100644
--- a/tests/auto/jsonstream/jsonstream.pro
+++ b/tests/auto/jsonstream/jsonstream.pro
@@ -4,7 +4,7 @@ QT = qml network testlib
CONFIG -= app_bundle
CONFIG += testcase
-include($$PWD/../../../src/common/common.pri)
+include($$PWD/../../../src/jsonstream/jsonstream.pri)
SOURCES += \
test-jsonstream.cpp
diff --git a/tests/auto/jsonstream/test-jsonstream.cpp b/tests/auto/jsonstream/test-jsonstream.cpp
index 4eac182e..15639241 100644
--- a/tests/auto/jsonstream/test-jsonstream.cpp
+++ b/tests/auto/jsonstream/test-jsonstream.cpp
@@ -40,14 +40,15 @@
****************************************************************************/
#include <QtTest/QtTest>
-#include <jsonstream.h>
+#include "jsonstream.h"
+
#include <QLocalServer>
#include <QLocalSocket>
#include <QBuffer>
#include <QDebug>
-QT_ADDON_JSONDB_USE_NAMESPACE
+using QtJsonDbJsonStream::JsonStream;
class TestJsonStream: public QObject
{
@@ -81,10 +82,9 @@ void TestJsonStream::testJsonStream()
QVERIFY(device->waitForConnected());
QVERIFY(device->state() == QLocalSocket::ConnectedState);
- JsonStream *stream = new JsonStream(device, this);
-
- connect(stream, SIGNAL(receive(QJsonObject)),
- this, SLOT(receiveStream(QJsonObject)));
+ JsonStream *stream = new JsonStream(this);
+ stream->setDevice(device);
+ connect(stream, SIGNAL(receive(QJsonObject)), this, SLOT(receiveStream(QJsonObject)));
qApp->processEvents();
qApp->processEvents();
@@ -99,7 +99,8 @@ void TestJsonStream::handleSocketConnection()
{
qDebug() << "handleSocketConnection";
serverOk = true;
- JsonStream sender(server->nextPendingConnection());
+ JsonStream sender;
+ sender.setDevice(server->nextPendingConnection());
QJsonObject json1;
json1.insert("hello", QString("world"));
diff --git a/tests/auto/daemon/json-validation.qrc b/tests/auto/partition/json-validation.qrc
index 5153c741..5153c741 100644
--- a/tests/auto/daemon/json-validation.qrc
+++ b/tests/auto/partition/json-validation.qrc
diff --git a/tests/auto/daemon/json-validation/array-boundaries-schema.json b/tests/auto/partition/json-validation/array-boundaries-schema.json
index 59f001b9..59f001b9 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-schema.json
+++ b/tests/auto/partition/json-validation/array-boundaries-schema.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-empty-valid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-empty-valid.json
index 0b99c24e..0b99c24e 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-empty-valid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-empty-valid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-five-invalid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-five-invalid.json
index 93d0ec31..93d0ec31 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-five-invalid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-five-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-two-valid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-two-valid.json
index 697c5bed..697c5bed 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrLess-two-valid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrLess-two-valid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-empty-invalid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-empty-invalid.json
index b5f2d19b..b5f2d19b 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-empty-invalid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-empty-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-five-valid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-five-valid.json
index 133961dd..133961dd 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-five-valid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-five-valid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-one-invalid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-one-invalid.json
index 62a898f6..62a898f6 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-one-invalid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-one-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-two-valid.json b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-two-valid.json
index 4547d4cb..4547d4cb 100644
--- a/tests/auto/daemon/json-validation/array-boundaries-twoOrMore-two-valid.json
+++ b/tests/auto/partition/json-validation/array-boundaries-twoOrMore-two-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-empty-empty-valid.json b/tests/auto/partition/json-validation/array-items-empty-empty-valid.json
index 49950992..49950992 100644
--- a/tests/auto/daemon/json-validation/array-items-empty-empty-valid.json
+++ b/tests/auto/partition/json-validation/array-items-empty-empty-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-empty-mixed-valid.json b/tests/auto/partition/json-validation/array-items-empty-mixed-valid.json
index e1a0d8f3..e1a0d8f3 100644
--- a/tests/auto/daemon/json-validation/array-items-empty-mixed-valid.json
+++ b/tests/auto/partition/json-validation/array-items-empty-mixed-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-empty-numbers-valid.json b/tests/auto/partition/json-validation/array-items-empty-numbers-valid.json
index 712e146e..712e146e 100644
--- a/tests/auto/daemon/json-validation/array-items-empty-numbers-valid.json
+++ b/tests/auto/partition/json-validation/array-items-empty-numbers-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-empty-valid.json b/tests/auto/partition/json-validation/array-items-number-empty-valid.json
index 5ffae678..5ffae678 100644
--- a/tests/auto/daemon/json-validation/array-items-number-empty-valid.json
+++ b/tests/auto/partition/json-validation/array-items-number-empty-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-highnumbers-invalid.json b/tests/auto/partition/json-validation/array-items-number-highnumbers-invalid.json
index fc2347e4..fc2347e4 100644
--- a/tests/auto/daemon/json-validation/array-items-number-highnumbers-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-number-highnumbers-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-mixed-invalid.json b/tests/auto/partition/json-validation/array-items-number-mixed-invalid.json
index 2b7d65e2..2b7d65e2 100644
--- a/tests/auto/daemon/json-validation/array-items-number-mixed-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-number-mixed-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-numbers-valid.json b/tests/auto/partition/json-validation/array-items-number-numbers-valid.json
index 00986d93..00986d93 100644
--- a/tests/auto/daemon/json-validation/array-items-number-numbers-valid.json
+++ b/tests/auto/partition/json-validation/array-items-number-numbers-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-object-invalid.json b/tests/auto/partition/json-validation/array-items-number-object-invalid.json
index 3dd8b867..3dd8b867 100644
--- a/tests/auto/daemon/json-validation/array-items-number-object-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-number-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-number-string-invalid.json b/tests/auto/partition/json-validation/array-items-number-string-invalid.json
index d5ccf425..d5ccf425 100644
--- a/tests/auto/daemon/json-validation/array-items-number-string-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-number-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-empty-valid.json b/tests/auto/partition/json-validation/array-items-object-empty-valid.json
index 9a2f07d9..9a2f07d9 100644
--- a/tests/auto/daemon/json-validation/array-items-object-empty-valid.json
+++ b/tests/auto/partition/json-validation/array-items-object-empty-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-missingfoo-valid.json b/tests/auto/partition/json-validation/array-items-object-missingfoo-valid.json
index 94ee005f..94ee005f 100644
--- a/tests/auto/daemon/json-validation/array-items-object-missingfoo-valid.json
+++ b/tests/auto/partition/json-validation/array-items-object-missingfoo-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-missingid-invalid.json b/tests/auto/partition/json-validation/array-items-object-missingid-invalid.json
index e1f13cdc..e1f13cdc 100644
--- a/tests/auto/daemon/json-validation/array-items-object-missingid-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-object-missingid-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-numbers-invalid.json b/tests/auto/partition/json-validation/array-items-object-numbers-invalid.json
index 98949560..98949560 100644
--- a/tests/auto/daemon/json-validation/array-items-object-numbers-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-object-numbers-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-std-valid.json b/tests/auto/partition/json-validation/array-items-object-std-valid.json
index b8d3ffe2..b8d3ffe2 100644
--- a/tests/auto/daemon/json-validation/array-items-object-std-valid.json
+++ b/tests/auto/partition/json-validation/array-items-object-std-valid.json
diff --git a/tests/auto/daemon/json-validation/array-items-object-strings-invalid.json b/tests/auto/partition/json-validation/array-items-object-strings-invalid.json
index 35c1a0c4..35c1a0c4 100644
--- a/tests/auto/daemon/json-validation/array-items-object-strings-invalid.json
+++ b/tests/auto/partition/json-validation/array-items-object-strings-invalid.json
diff --git a/tests/auto/daemon/json-validation/array-items-schema.json b/tests/auto/partition/json-validation/array-items-schema.json
index c155ccd9..c155ccd9 100644
--- a/tests/auto/daemon/json-validation/array-items-schema.json
+++ b/tests/auto/partition/json-validation/array-items-schema.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-one-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-one-invalid.json
index 929d80a1..929d80a1 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-one-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-one-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-two-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-two-invalid.json
index fb694b0b..fb694b0b 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-two-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-two-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-zero-valid.json b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-zero-valid.json
index 8ab8beea..8ab8beea 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-lessThenOne-zero-valid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-lessThenOne-zero-valid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-one-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-one-invalid.json
index 9197c7df..9197c7df 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-one-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-one-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-two-valid.json b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-two-valid.json
index 4eeb4bbc..4eeb4bbc 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-two-valid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-two-valid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-zero-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-zero-invalid.json
index c60214f4..c60214f4 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-moreThenOne-zero-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-moreThenOne-zero-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-one-valid.json b/tests/auto/partition/json-validation/integer-boundaries-oneOrLess-one-valid.json
index c18da6ca..c18da6ca 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-one-valid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-oneOrLess-one-valid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-two-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-oneOrLess-two-invalid.json
index 27468647..27468647 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-oneOrLess-two-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-oneOrLess-two-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-one-valid.json b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-one-valid.json
index 1eecd48a..1eecd48a 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-one-valid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-one-valid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-two-valid.json b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-two-valid.json
index e1bbfe04..e1bbfe04 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-two-valid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-two-valid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-zero-invalid.json b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-zero-invalid.json
index 848f6dc5..848f6dc5 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-oneOrMore-zero-invalid.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-oneOrMore-zero-invalid.json
diff --git a/tests/auto/daemon/json-validation/integer-boundaries-schema.json b/tests/auto/partition/json-validation/integer-boundaries-schema.json
index 5575d28e..5575d28e 100644
--- a/tests/auto/daemon/json-validation/integer-boundaries-schema.json
+++ b/tests/auto/partition/json-validation/integer-boundaries-schema.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-one-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-one-invalid.json
index 515feadc..515feadc 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-one-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-one-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-two-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-two-invalid.json
index b353576e..b353576e 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-two-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-two-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-zero-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-zero-valid.json
index c3dc2ed0..c3dc2ed0 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-lessThenOne-zero-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-lessThenOne-zero-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-one-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-one-invalid.json
index 16d07ce9..16d07ce9 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-one-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-one-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-two-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-two-valid.json
index bdc4068f..bdc4068f 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-two-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-two-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json
index 5e5d8962..5e5d8962 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-moreThenOne-zero-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-one-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-one-valid.json
index 42600228..42600228 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-one-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-one-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-two-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-two-invalid.json
index 2ebecfcf..2ebecfcf 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-two-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-two-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-zero-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-zero-valid.json
index e554507a..e554507a 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrLess-zero-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrLess-zero-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-one-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-one-valid.json
index f7ce9d88..f7ce9d88 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-one-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-one-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-two-valid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-two-valid.json
index 5ef0d9e3..5ef0d9e3 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-two-valid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-two-valid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json
index 4730c400..4730c400 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-oneOrMore-zero-invalid.json
diff --git a/tests/auto/daemon/json-validation/numbers-boundaries-schema.json b/tests/auto/partition/json-validation/numbers-boundaries-schema.json
index 74c02d96..74c02d96 100644
--- a/tests/auto/daemon/json-validation/numbers-boundaries-schema.json
+++ b/tests/auto/partition/json-validation/numbers-boundaries-schema.json
diff --git a/tests/auto/daemon/json-validation/required-missing-invalid.json b/tests/auto/partition/json-validation/required-missing-invalid.json
index b4453061..b4453061 100644
--- a/tests/auto/daemon/json-validation/required-missing-invalid.json
+++ b/tests/auto/partition/json-validation/required-missing-invalid.json
diff --git a/tests/auto/daemon/json-validation/required-nested-valid.json b/tests/auto/partition/json-validation/required-nested-valid.json
index f7571492..f7571492 100644
--- a/tests/auto/daemon/json-validation/required-nested-valid.json
+++ b/tests/auto/partition/json-validation/required-nested-valid.json
diff --git a/tests/auto/daemon/json-validation/required-notimportent-number-invalid.json b/tests/auto/partition/json-validation/required-notimportent-number-invalid.json
index a7325db0..a7325db0 100644
--- a/tests/auto/daemon/json-validation/required-notimportent-number-invalid.json
+++ b/tests/auto/partition/json-validation/required-notimportent-number-invalid.json
diff --git a/tests/auto/daemon/json-validation/required-number-valid.json b/tests/auto/partition/json-validation/required-number-valid.json
index 78b039a7..78b039a7 100644
--- a/tests/auto/daemon/json-validation/required-number-valid.json
+++ b/tests/auto/partition/json-validation/required-number-valid.json
diff --git a/tests/auto/daemon/json-validation/required-object-valid.json b/tests/auto/partition/json-validation/required-object-valid.json
index 6acfbdc1..6acfbdc1 100644
--- a/tests/auto/daemon/json-validation/required-object-valid.json
+++ b/tests/auto/partition/json-validation/required-object-valid.json
diff --git a/tests/auto/daemon/json-validation/required-schema.json b/tests/auto/partition/json-validation/required-schema.json
index 881e295b..881e295b 100644
--- a/tests/auto/daemon/json-validation/required-schema.json
+++ b/tests/auto/partition/json-validation/required-schema.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-max5chars-silo-valid.json b/tests/auto/partition/json-validation/string-boundaries-max5chars-silo-valid.json
index 368f132f..368f132f 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-max5chars-silo-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-max5chars-silo-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-max5chars-silos-valid.json b/tests/auto/partition/json-validation/string-boundaries-max5chars-silos-valid.json
index d1c98da8..d1c98da8 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-max5chars-silos-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-max5chars-silos-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-max5chars-toolong-invalid.json b/tests/auto/partition/json-validation/string-boundaries-max5chars-toolong-invalid.json
index c7bdfe18..c7bdfe18 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-max5chars-toolong-invalid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-max5chars-toolong-invalid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-min5chars-silo-invalid.json b/tests/auto/partition/json-validation/string-boundaries-min5chars-silo-invalid.json
index dc085e9b..dc085e9b 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-min5chars-silo-invalid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-min5chars-silo-invalid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-min5chars-silos-valid.json b/tests/auto/partition/json-validation/string-boundaries-min5chars-silos-valid.json
index 6663c273..6663c273 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-min5chars-silos-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-min5chars-silos-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-min5chars-toolong-valid.json b/tests/auto/partition/json-validation/string-boundaries-min5chars-toolong-valid.json
index f1d60b45..f1d60b45 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-min5chars-toolong-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-min5chars-toolong-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-pattern-a-valid.json b/tests/auto/partition/json-validation/string-boundaries-pattern-a-valid.json
index 1231c734..1231c734 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-pattern-a-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-pattern-a-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-pattern-aaa-valid.json b/tests/auto/partition/json-validation/string-boundaries-pattern-aaa-valid.json
index 8dc140af..8dc140af 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-pattern-aaa-valid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-pattern-aaa-valid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-pattern-ab-invalid.json b/tests/auto/partition/json-validation/string-boundaries-pattern-ab-invalid.json
index 253168fd..253168fd 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-pattern-ab-invalid.json
+++ b/tests/auto/partition/json-validation/string-boundaries-pattern-ab-invalid.json
diff --git a/tests/auto/daemon/json-validation/string-boundaries-schema.json b/tests/auto/partition/json-validation/string-boundaries-schema.json
index 3aea2432..3aea2432 100644
--- a/tests/auto/daemon/json-validation/string-boundaries-schema.json
+++ b/tests/auto/partition/json-validation/string-boundaries-schema.json
diff --git a/tests/auto/daemon/json-validation/type-array-array-valid.json b/tests/auto/partition/json-validation/type-array-array-valid.json
index 34425f30..34425f30 100644
--- a/tests/auto/daemon/json-validation/type-array-array-valid.json
+++ b/tests/auto/partition/json-validation/type-array-array-valid.json
diff --git a/tests/auto/daemon/json-validation/type-array-bool-invalid.json b/tests/auto/partition/json-validation/type-array-bool-invalid.json
index 437a46bc..437a46bc 100644
--- a/tests/auto/daemon/json-validation/type-array-bool-invalid.json
+++ b/tests/auto/partition/json-validation/type-array-bool-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-array-integer-invalid.json b/tests/auto/partition/json-validation/type-array-integer-invalid.json
index 41f67e4b..41f67e4b 100644
--- a/tests/auto/daemon/json-validation/type-array-integer-invalid.json
+++ b/tests/auto/partition/json-validation/type-array-integer-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-array-number-invalid.json b/tests/auto/partition/json-validation/type-array-number-invalid.json
index 15fca625..15fca625 100644
--- a/tests/auto/daemon/json-validation/type-array-number-invalid.json
+++ b/tests/auto/partition/json-validation/type-array-number-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-array-object-invalid.json b/tests/auto/partition/json-validation/type-array-object-invalid.json
index af4ab14d..af4ab14d 100644
--- a/tests/auto/daemon/json-validation/type-array-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-array-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-array-string-invalid.json b/tests/auto/partition/json-validation/type-array-string-invalid.json
index 01fb9038..01fb9038 100644
--- a/tests/auto/daemon/json-validation/type-array-string-invalid.json
+++ b/tests/auto/partition/json-validation/type-array-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-array-invalid.json b/tests/auto/partition/json-validation/type-bool-array-invalid.json
index c9bb7920..c9bb7920 100644
--- a/tests/auto/daemon/json-validation/type-bool-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-bool-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-false-valid.json b/tests/auto/partition/json-validation/type-bool-false-valid.json
index 7f809e1a..7f809e1a 100644
--- a/tests/auto/daemon/json-validation/type-bool-false-valid.json
+++ b/tests/auto/partition/json-validation/type-bool-false-valid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-integer-invalid.json b/tests/auto/partition/json-validation/type-bool-integer-invalid.json
index 1f6e88c5..1f6e88c5 100644
--- a/tests/auto/daemon/json-validation/type-bool-integer-invalid.json
+++ b/tests/auto/partition/json-validation/type-bool-integer-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-number-invalid.json b/tests/auto/partition/json-validation/type-bool-number-invalid.json
index 2943012f..2943012f 100644
--- a/tests/auto/daemon/json-validation/type-bool-number-invalid.json
+++ b/tests/auto/partition/json-validation/type-bool-number-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-object-invalid.json b/tests/auto/partition/json-validation/type-bool-object-invalid.json
index c763630d..c763630d 100644
--- a/tests/auto/daemon/json-validation/type-bool-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-bool-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-string-invalid.json b/tests/auto/partition/json-validation/type-bool-string-invalid.json
index 678468c0..678468c0 100644
--- a/tests/auto/daemon/json-validation/type-bool-string-invalid.json
+++ b/tests/auto/partition/json-validation/type-bool-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-bool-true-valid.json b/tests/auto/partition/json-validation/type-bool-true-valid.json
index a65bb225..a65bb225 100644
--- a/tests/auto/daemon/json-validation/type-bool-true-valid.json
+++ b/tests/auto/partition/json-validation/type-bool-true-valid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-array-invalid.json b/tests/auto/partition/json-validation/type-integer-array-invalid.json
index 75046728..75046728 100644
--- a/tests/auto/daemon/json-validation/type-integer-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-integer-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-bool-invalid.json b/tests/auto/partition/json-validation/type-integer-bool-invalid.json
index c5c25ed9..c5c25ed9 100644
--- a/tests/auto/daemon/json-validation/type-integer-bool-invalid.json
+++ b/tests/auto/partition/json-validation/type-integer-bool-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-double-invalid.json b/tests/auto/partition/json-validation/type-integer-double-invalid.json
index 50c93d7a..50c93d7a 100644
--- a/tests/auto/daemon/json-validation/type-integer-double-invalid.json
+++ b/tests/auto/partition/json-validation/type-integer-double-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-integer-valid.json b/tests/auto/partition/json-validation/type-integer-integer-valid.json
index f6922f01..f6922f01 100644
--- a/tests/auto/daemon/json-validation/type-integer-integer-valid.json
+++ b/tests/auto/partition/json-validation/type-integer-integer-valid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-object-invalid.json b/tests/auto/partition/json-validation/type-integer-object-invalid.json
index a3f1ee6a..a3f1ee6a 100644
--- a/tests/auto/daemon/json-validation/type-integer-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-integer-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-integer-string-invalid.json b/tests/auto/partition/json-validation/type-integer-string-invalid.json
index 4fcdc391..4fcdc391 100644
--- a/tests/auto/daemon/json-validation/type-integer-string-invalid.json
+++ b/tests/auto/partition/json-validation/type-integer-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-mixed-array-invalid.json b/tests/auto/partition/json-validation/type-mixed-array-invalid.json
index 0214a9bf..0214a9bf 100644
--- a/tests/auto/daemon/json-validation/type-mixed-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-mixed-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-mixed-double-invalid.json b/tests/auto/partition/json-validation/type-mixed-double-invalid.json
index 98683900..98683900 100644
--- a/tests/auto/daemon/json-validation/type-mixed-double-invalid.json
+++ b/tests/auto/partition/json-validation/type-mixed-double-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-mixed-number-valid.json b/tests/auto/partition/json-validation/type-mixed-number-valid.json
index 8a5ff6a7..8a5ff6a7 100644
--- a/tests/auto/daemon/json-validation/type-mixed-number-valid.json
+++ b/tests/auto/partition/json-validation/type-mixed-number-valid.json
diff --git a/tests/auto/daemon/json-validation/type-mixed-object-invalid.json b/tests/auto/partition/json-validation/type-mixed-object-invalid.json
index 87597e2d..87597e2d 100644
--- a/tests/auto/daemon/json-validation/type-mixed-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-mixed-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-mixed-string-valid.json b/tests/auto/partition/json-validation/type-mixed-string-valid.json
index abc8f382..abc8f382 100644
--- a/tests/auto/daemon/json-validation/type-mixed-string-valid.json
+++ b/tests/auto/partition/json-validation/type-mixed-string-valid.json
diff --git a/tests/auto/daemon/json-validation/type-number-array-invalid.json b/tests/auto/partition/json-validation/type-number-array-invalid.json
index 8afa6212..8afa6212 100644
--- a/tests/auto/daemon/json-validation/type-number-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-number-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-number-bool-invalid.json b/tests/auto/partition/json-validation/type-number-bool-invalid.json
index f1407060..f1407060 100644
--- a/tests/auto/daemon/json-validation/type-number-bool-invalid.json
+++ b/tests/auto/partition/json-validation/type-number-bool-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-number-double-valid.json b/tests/auto/partition/json-validation/type-number-double-valid.json
index 74b549a2..74b549a2 100644
--- a/tests/auto/daemon/json-validation/type-number-double-valid.json
+++ b/tests/auto/partition/json-validation/type-number-double-valid.json
diff --git a/tests/auto/daemon/json-validation/type-number-number-valid.json b/tests/auto/partition/json-validation/type-number-number-valid.json
index 27a667fa..27a667fa 100644
--- a/tests/auto/daemon/json-validation/type-number-number-valid.json
+++ b/tests/auto/partition/json-validation/type-number-number-valid.json
diff --git a/tests/auto/daemon/json-validation/type-number-object-invalid.json b/tests/auto/partition/json-validation/type-number-object-invalid.json
index 68c2e512..68c2e512 100644
--- a/tests/auto/daemon/json-validation/type-number-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-number-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-number-string-invalid.json b/tests/auto/partition/json-validation/type-number-string-invalid.json
index e19b9c88..e19b9c88 100644
--- a/tests/auto/daemon/json-validation/type-number-string-invalid.json
+++ b/tests/auto/partition/json-validation/type-number-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-object-array-invalid.json b/tests/auto/partition/json-validation/type-object-array-invalid.json
index 69e69855..69e69855 100644
--- a/tests/auto/daemon/json-validation/type-object-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-object-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-object-bool-invalid.json b/tests/auto/partition/json-validation/type-object-bool-invalid.json
index 1ee40176..1ee40176 100644
--- a/tests/auto/daemon/json-validation/type-object-bool-invalid.json
+++ b/tests/auto/partition/json-validation/type-object-bool-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-object-double-invalid.json b/tests/auto/partition/json-validation/type-object-double-invalid.json
index 5728ac01..5728ac01 100644
--- a/tests/auto/daemon/json-validation/type-object-double-invalid.json
+++ b/tests/auto/partition/json-validation/type-object-double-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-object-number-invalid.json b/tests/auto/partition/json-validation/type-object-number-invalid.json
index bd527110..bd527110 100644
--- a/tests/auto/daemon/json-validation/type-object-number-invalid.json
+++ b/tests/auto/partition/json-validation/type-object-number-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-object-object-valid.json b/tests/auto/partition/json-validation/type-object-object-valid.json
index f6b61530..f6b61530 100644
--- a/tests/auto/daemon/json-validation/type-object-object-valid.json
+++ b/tests/auto/partition/json-validation/type-object-object-valid.json
diff --git a/tests/auto/daemon/json-validation/type-object-string-invalid.json b/tests/auto/partition/json-validation/type-object-string-invalid.json
index 7f5a952a..7f5a952a 100644
--- a/tests/auto/daemon/json-validation/type-object-string-invalid.json
+++ b/tests/auto/partition/json-validation/type-object-string-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-schema.json b/tests/auto/partition/json-validation/type-schema.json
index 4aad2acd..4aad2acd 100644
--- a/tests/auto/daemon/json-validation/type-schema.json
+++ b/tests/auto/partition/json-validation/type-schema.json
diff --git a/tests/auto/daemon/json-validation/type-string-array-invalid.json b/tests/auto/partition/json-validation/type-string-array-invalid.json
index 10c491d9..10c491d9 100644
--- a/tests/auto/daemon/json-validation/type-string-array-invalid.json
+++ b/tests/auto/partition/json-validation/type-string-array-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-string-bool-invalid.json b/tests/auto/partition/json-validation/type-string-bool-invalid.json
index d19d1048..d19d1048 100644
--- a/tests/auto/daemon/json-validation/type-string-bool-invalid.json
+++ b/tests/auto/partition/json-validation/type-string-bool-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-string-double-invalid.json b/tests/auto/partition/json-validation/type-string-double-invalid.json
index af4b6ed3..af4b6ed3 100644
--- a/tests/auto/daemon/json-validation/type-string-double-invalid.json
+++ b/tests/auto/partition/json-validation/type-string-double-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-string-integer-invalid.json b/tests/auto/partition/json-validation/type-string-integer-invalid.json
index 681e09b6..681e09b6 100644
--- a/tests/auto/daemon/json-validation/type-string-integer-invalid.json
+++ b/tests/auto/partition/json-validation/type-string-integer-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-string-object-invalid.json b/tests/auto/partition/json-validation/type-string-object-invalid.json
index 5f7702c5..5f7702c5 100644
--- a/tests/auto/daemon/json-validation/type-string-object-invalid.json
+++ b/tests/auto/partition/json-validation/type-string-object-invalid.json
diff --git a/tests/auto/daemon/json-validation/type-string-string-valid.json b/tests/auto/partition/json-validation/type-string-string-valid.json
index 5122b734..5122b734 100644
--- a/tests/auto/daemon/json-validation/type-string-string-valid.json
+++ b/tests/auto/partition/json-validation/type-string-string-valid.json
diff --git a/tests/auto/daemon/json/array.json b/tests/auto/partition/json/array.json
index 9eff59fa..9eff59fa 100644
--- a/tests/auto/daemon/json/array.json
+++ b/tests/auto/partition/json/array.json
diff --git a/tests/auto/daemon/json/index-casepreference.json b/tests/auto/partition/json/index-casepreference.json
index 42b811a8..42b811a8 100644
--- a/tests/auto/daemon/json/index-casepreference.json
+++ b/tests/auto/partition/json/index-casepreference.json
diff --git a/tests/auto/daemon/json/index-casesensitive.json b/tests/auto/partition/json/index-casesensitive.json
index bcccd562..bcccd562 100644
--- a/tests/auto/daemon/json/index-casesensitive.json
+++ b/tests/auto/partition/json/index-casesensitive.json
diff --git a/tests/auto/daemon/json/largeContactsTest.json b/tests/auto/partition/json/largeContactsTest.json
index 7666c68f..7666c68f 100644
--- a/tests/auto/daemon/json/largeContactsTest.json
+++ b/tests/auto/partition/json/largeContactsTest.json
diff --git a/tests/auto/daemon/json/largeContactsTest10k.json b/tests/auto/partition/json/largeContactsTest10k.json
index bd9f91f0..bd9f91f0 100644
--- a/tests/auto/daemon/json/largeContactsTest10k.json
+++ b/tests/auto/partition/json/largeContactsTest10k.json
diff --git a/tests/auto/daemon/json/largeContactsTest1k.json b/tests/auto/partition/json/largeContactsTest1k.json
index 7666c68f..7666c68f 100644
--- a/tests/auto/daemon/json/largeContactsTest1k.json
+++ b/tests/auto/partition/json/largeContactsTest1k.json
diff --git a/tests/auto/daemon/json/largeContactsTest33k.json b/tests/auto/partition/json/largeContactsTest33k.json
index 5c6d37b2..5c6d37b2 100644
--- a/tests/auto/daemon/json/largeContactsTest33k.json
+++ b/tests/auto/partition/json/largeContactsTest33k.json
diff --git a/tests/auto/daemon/json/map-array-conversion.json b/tests/auto/partition/json/map-array-conversion.json
index b51aab00..b51aab00 100644
--- a/tests/auto/daemon/json/map-array-conversion.json
+++ b/tests/auto/partition/json/map-array-conversion.json
diff --git a/tests/auto/daemon/json/map-join-sourceuuids.json b/tests/auto/partition/json/map-join-sourceuuids.json
index 24ad24e7..24ad24e7 100644
--- a/tests/auto/daemon/json/map-join-sourceuuids.json
+++ b/tests/auto/partition/json/map-join-sourceuuids.json
diff --git a/tests/auto/daemon/json/map-join.json b/tests/auto/partition/json/map-join.json
index 75d5fb28..75d5fb28 100644
--- a/tests/auto/daemon/json/map-join.json
+++ b/tests/auto/partition/json/map-join.json
diff --git a/tests/auto/daemon/json/map-reduce-schema.json b/tests/auto/partition/json/map-reduce-schema.json
index 726d0cc0..726d0cc0 100644
--- a/tests/auto/daemon/json/map-reduce-schema.json
+++ b/tests/auto/partition/json/map-reduce-schema.json
diff --git a/tests/auto/daemon/json/map-reduce.json b/tests/auto/partition/json/map-reduce.json
index 2736a9cd..2736a9cd 100644
--- a/tests/auto/daemon/json/map-reduce.json
+++ b/tests/auto/partition/json/map-reduce.json
diff --git a/tests/auto/daemon/json/map-sametarget.json b/tests/auto/partition/json/map-sametarget.json
index f94c7843..f94c7843 100644
--- a/tests/auto/daemon/json/map-sametarget.json
+++ b/tests/auto/partition/json/map-sametarget.json
diff --git a/tests/auto/daemon/json/pk-capability.json b/tests/auto/partition/json/pk-capability.json
index eea7caeb..eea7caeb 100644
--- a/tests/auto/daemon/json/pk-capability.json
+++ b/tests/auto/partition/json/pk-capability.json
diff --git a/tests/auto/daemon/json/reduce-array.json b/tests/auto/partition/json/reduce-array.json
index 144513a4..144513a4 100644
--- a/tests/auto/daemon/json/reduce-array.json
+++ b/tests/auto/partition/json/reduce-array.json
diff --git a/tests/auto/daemon/json/reduce-data.json b/tests/auto/partition/json/reduce-data.json
index 810bf973..810bf973 100644
--- a/tests/auto/daemon/json/reduce-data.json
+++ b/tests/auto/partition/json/reduce-data.json
diff --git a/tests/auto/daemon/json/reduce-subprop.json b/tests/auto/partition/json/reduce-subprop.json
index a5002853..a5002853 100644
--- a/tests/auto/daemon/json/reduce-subprop.json
+++ b/tests/auto/partition/json/reduce-subprop.json
diff --git a/tests/auto/daemon/json/reduce.json b/tests/auto/partition/json/reduce.json
index 5939fb71..5939fb71 100644
--- a/tests/auto/daemon/json/reduce.json
+++ b/tests/auto/partition/json/reduce.json
diff --git a/tests/auto/partition/partition.pro b/tests/auto/partition/partition.pro
new file mode 100644
index 00000000..36bd18b7
--- /dev/null
+++ b/tests/auto/partition/partition.pro
@@ -0,0 +1,32 @@
+TARGET = tst_partition
+CONFIG += debug
+
+QT = network qml testlib jsondbpartition
+CONFIG -= app_bundle
+CONFIG += testcase
+
+LIBS += -L$$QT.jsondb.libs
+
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+RESOURCES += json-validation.qrc partition.qrc
+
+unix:!mac:contains(QT_CONFIG,icu) {
+ LIBS += -licuuc -licui18n
+} else {
+ DEFINES += NO_COLLATION_SUPPORT
+}
+
+# HACK, remove when jsondbpartition separates private api from public api
+include(../../../src/3rdparty/btree/btree.pri)
+include(../../../src/hbtree/hbtree.pri)
+
+SOURCES += \
+ testpartition.cpp \
+
+contains(config_test_icu, yes) {
+ LIBS += -licuuc -licui18n
+} else {
+ DEFINES += NO_COLLATION_SUPPORT
+}
+
diff --git a/tests/auto/daemon/daemon.qrc b/tests/auto/partition/partition.qrc
index 5ee38b61..a4332b49 100644
--- a/tests/auto/daemon/daemon.qrc
+++ b/tests/auto/partition/partition.qrc
@@ -1,5 +1,5 @@
<RCC>
- <qresource prefix="/daemon">
+ <qresource prefix="/partition">
<file>json</file>
<file>schemas</file>
</qresource>
diff --git a/tests/auto/daemon/schemas/TestView.json b/tests/auto/partition/schemas/TestView.json
index 9f37750e..9f37750e 100644
--- a/tests/auto/daemon/schemas/TestView.json
+++ b/tests/auto/partition/schemas/TestView.json
diff --git a/tests/auto/daemon/schemas/address.json b/tests/auto/partition/schemas/address.json
index 76f5bdce..76f5bdce 100644
--- a/tests/auto/daemon/schemas/address.json
+++ b/tests/auto/partition/schemas/address.json
diff --git a/tests/auto/daemon/schemas/contact.json b/tests/auto/partition/schemas/contact.json
index 168ef20b..168ef20b 100644
--- a/tests/auto/daemon/schemas/contact.json
+++ b/tests/auto/partition/schemas/contact.json
diff --git a/tests/auto/daemon/schemas/ephemeral.json b/tests/auto/partition/schemas/ephemeral.json
index a065a976..a065a976 100644
--- a/tests/auto/daemon/schemas/ephemeral.json
+++ b/tests/auto/partition/schemas/ephemeral.json
diff --git a/tests/auto/daemon/testjsondb.cpp b/tests/auto/partition/testpartition.cpp
index ce2781ed..f08fb1e1 100644
--- a/tests/auto/daemon/testjsondb.cpp
+++ b/tests/auto/partition/testpartition.cpp
@@ -45,18 +45,17 @@
#include <QFile>
#include <QFileInfo>
#include <QDir>
+#include <QMessageHandler>
#include <QTime>
#include <QUuid>
-#include "json.h"
-
#include "jsondbbtree.h"
#include "jsondbobjecttable.h"
#include "jsondbpartition.h"
#include "jsondbindex.h"
#include "jsondbsettings.h"
-#include "jsondb-strings.h"
-#include "jsondb-error.h"
+#include "jsondbstrings.h"
+#include "jsondberrors.h"
#include <qjsonobject.h>
@@ -68,7 +67,7 @@
#define DBG() if (0) qDebug()
#endif
-QT_USE_NAMESPACE_JSONDB
+QT_USE_NAMESPACE_JSONDB_PARTITION
static QString kContactStr = "com.example.unittest.contact";
@@ -116,12 +115,11 @@ private:
T mValue;
};
-class TestJsonDb: public QObject
+class TestPartition: public QObject
{
Q_OBJECT
public:
- TestJsonDb();
-
+ TestPartition();
private slots:
void initTestCase();
@@ -175,6 +173,7 @@ private slots:
void mapSchemaViolation();
void mapMultipleEmitNoTargetKeyName();
void mapArrayConversion();
+ void mapConsole();
void reduce();
void reduceFlattened();
void reduceSourceKeyFunction();
@@ -234,6 +233,13 @@ private slots:
void settings();
+ void typeChangeIndex();
+ void typeChangeMap();
+ void typeChangeReduce();
+ void typeChangeMapSource();
+ void typeChangeReduceSource();
+ void typeChangeSchema();
+
private:
void createContacts();
JsonDbQueryResult find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings = QJsonObject());
@@ -245,8 +251,6 @@ private:
void addSchema(const QString &schemaName, JsonDbObject &schemaObject);
void addIndex(const QString &propertyName, const QString &propertyType=QString(), const QString &objectType=QString());
- QJsonValue readJsonFile(const QString &filename);
- QJsonValue readJson(const QByteArray& json);
void removeDbFiles();
private:
@@ -261,13 +265,13 @@ const QString kReplica1Name = QString("replica1");
const QString kReplica2Name = QString("replica2");
const QStringList kReplicaNames = (QStringList() << kReplica1Name << kReplica2Name);
-TestJsonDb::TestJsonDb() :
+TestPartition::TestPartition() :
mJsonDbPartition(0)
, mOwner(0)
{
}
-void TestJsonDb::removeDbFiles()
+void TestPartition::removeDbFiles()
{
QStringList filters;
filters << QLatin1String("*.db")
@@ -277,7 +281,7 @@ void TestJsonDb::removeDbFiles()
QFile::remove(fileName);
}
-void TestJsonDb::initTestCase()
+void TestPartition::initTestCase()
{
qsrand(QDateTime::currentDateTime().toTime_t());
QCoreApplication::setOrganizationName("Example");
@@ -294,22 +298,26 @@ void TestJsonDb::initTestCase()
mJsonDbPartition->open();
}
-void TestJsonDb::cleanupTestCase()
+void TestPartition::cleanupTestCase()
{
if (mJsonDbPartition) {
mJsonDbPartition->close();
delete mJsonDbPartition;
mJsonDbPartition = 0;
}
+ if (mOwner) {
+ delete mOwner;
+ mOwner = 0;
+ }
removeDbFiles();
}
-void TestJsonDb::cleanup()
+void TestPartition::cleanup()
{
QCOMPARE(mJsonDbPartition->mTransactionDepth, 0);
}
-void TestJsonDb::reopen()
+void TestPartition::reopen()
{
int counter = 1;
for (int i = 0; i < 10; ++i, ++counter) {
@@ -324,27 +332,19 @@ void TestJsonDb::reopen()
mJsonDbPartition = new JsonDbPartition(kFilename, QStringLiteral("com.example.JsonDbTest"), mOwner, this);
mJsonDbPartition->open();
- JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner,
- JsonDbQuery::parse(QLatin1String("[?_type=\"reopentest\"]")));
+ JsonDbQuery *parsedQuery = JsonDbQuery::parse(QLatin1String("[?_type=\"reopentest\"]"));
+ JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery);
+ delete parsedQuery;
QCOMPARE(queryResult.data.size(), counter);
}
}
-void TestJsonDb::createContacts()
+void TestPartition::createContacts()
{
if (!mContactList.isEmpty())
return;
- QFile contactsFile(":/daemon/json/largeContactsTest.json");
- QVERIFY2(contactsFile.exists(), "Err: largeContactsTest.json doesn't exist!");
-
- contactsFile.open(QIODevice::ReadOnly);
- QByteArray json = contactsFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok)
- qDebug() << parser.errorString();
- QVariantList contactList = parser.result().toList();
+ QVariantList contactList = readJsonFile(":/partition/json/largeContactsTest.json").toArray().toVariantList();
QList<JsonDbObject> newContactList;
foreach (QVariant v, contactList) {
JsonDbObject contact(JsonDbObject::fromVariantMap(v.toMap()));
@@ -367,12 +367,15 @@ void TestJsonDb::createContacts()
}
-JsonDbQueryResult TestJsonDb::find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings)
+JsonDbQueryResult TestPartition::find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings)
{
- return mJsonDbPartition->queryObjects(owner, JsonDbQuery::parse(query, bindings));
+ JsonDbQuery *parsedQuery = JsonDbQuery::parse(query, bindings);
+ JsonDbQueryResult result = mJsonDbPartition->queryObjects(owner, parsedQuery);
+ delete parsedQuery;
+ return result;
}
-JsonDbWriteResult TestJsonDb::create(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
+JsonDbWriteResult TestPartition::create(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
{
JsonDbWriteResult result = mJsonDbPartition->updateObject(owner, object, mode);
if (result.code == JsonDbError::NoError) {
@@ -382,7 +385,7 @@ JsonDbWriteResult TestJsonDb::create(JsonDbOwner *owner, JsonDbObject &object, J
return result;
}
-JsonDbWriteResult TestJsonDb::update(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
+JsonDbWriteResult TestPartition::update(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
{
JsonDbWriteResult result = mJsonDbPartition->updateObject(owner, object, mode);
if (result.code == JsonDbError::NoError)
@@ -390,7 +393,7 @@ JsonDbWriteResult TestJsonDb::update(JsonDbOwner *owner, JsonDbObject &object, J
return result;
}
-JsonDbWriteResult TestJsonDb::remove(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
+JsonDbWriteResult TestPartition::remove(JsonDbOwner *owner, JsonDbObject &object, JsonDbPartition::WriteMode mode)
{
JsonDbObject toDelete = object;
toDelete.insert(JsonDbString::kDeletedStr, true);
@@ -403,16 +406,16 @@ JsonDbWriteResult TestJsonDb::remove(JsonDbOwner *owner, JsonDbObject &object, J
/*
* const version for all the cleanup code that doesn't care about updated properties
*/
-JsonDbWriteResult TestJsonDb::remove(JsonDbOwner *owner, const JsonDbObject &object, JsonDbPartition::WriteMode mode)
+JsonDbWriteResult TestPartition::remove(JsonDbOwner *owner, const JsonDbObject &object, JsonDbPartition::WriteMode mode)
{
JsonDbObject toDelete = object;
toDelete.insert(JsonDbString::kDeletedStr, true);
return mJsonDbPartition->updateObject(owner, toDelete, mode);
}
-void TestJsonDb::addSchema(const QString &schemaName, JsonDbObject &schemaObject)
+void TestPartition::addSchema(const QString &schemaName, JsonDbObject &schemaObject)
{
- QJsonValue schema = readJsonFile(QString(":/daemon/schemas/%1.json").arg(schemaName));
+ QJsonValue schema = readJsonFile(QString(":/partition/schemas/%1.json").arg(schemaName));
schemaObject = JsonDbObject();
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
schemaObject.insert("name", schemaName);
@@ -421,7 +424,7 @@ void TestJsonDb::addSchema(const QString &schemaName, JsonDbObject &schemaObject
verifyGoodResult(create(mOwner, schemaObject));
}
-void TestJsonDb::addIndex(const QString &propertyName, const QString &propertyType, const QString &objectType)
+void TestPartition::addIndex(const QString &propertyName, const QString &propertyType, const QString &objectType)
{
JsonDbObject index;
index.insert(JsonDbString::kTypeStr, JsonDbString::kIndexTypeStr);
@@ -433,7 +436,7 @@ void TestJsonDb::addIndex(const QString &propertyName, const QString &propertyTy
verifyGoodResult(create(mOwner, index));
}
-void TestJsonDb::computeVersion()
+void TestPartition::computeVersion()
{
JsonDbObject item0;
QCOMPARE(item0.version(), QString());
@@ -588,7 +591,7 @@ void TestJsonDb::computeVersion()
QCOMPARE(item9.version().mid(1), item1.version().mid(1));
}
-void TestJsonDb::updateVersionOptimistic()
+void TestPartition::updateVersionOptimistic()
{
JsonDbObject master;
master.generateUuid();
@@ -636,7 +639,7 @@ void TestJsonDb::updateVersionOptimistic()
}
-void TestJsonDb::updateVersionReplicating()
+void TestPartition::updateVersionReplicating()
{
JsonDbObject master;
master.generateUuid();
@@ -747,7 +750,7 @@ void TestJsonDb::updateVersionReplicating()
/*
* Create an item
*/
-void TestJsonDb::create()
+void TestPartition::create()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QString("create-test-type"));
@@ -778,7 +781,7 @@ void TestJsonDb::create()
* Insert an item and then update it.
*/
-void TestJsonDb::update()
+void TestPartition::update()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QLatin1String("update-test-type"));
@@ -801,7 +804,7 @@ void TestJsonDb::update()
* Update an item which doesn't exist
*/
-void TestJsonDb::update2()
+void TestPartition::update2()
{
JsonDbObject item;
item.insert("update2-test", 100);
@@ -817,7 +820,7 @@ void TestJsonDb::update2()
* Update an item which doesn't have a "uuid" field
*/
-void TestJsonDb::update3()
+void TestPartition::update3()
{
JsonDbObject item;
item.insert("update2-test", 100);
@@ -830,7 +833,7 @@ void TestJsonDb::update3()
* Update a stale copy of an item
*/
-void TestJsonDb::update4()
+void TestPartition::update4()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QLatin1String("update-test-type"));
@@ -891,7 +894,7 @@ void TestJsonDb::update4()
* Create an item and immediately remove it
*/
-void TestJsonDb::remove()
+void TestPartition::remove()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QLatin1String("remove-test-type"));
@@ -918,7 +921,7 @@ void TestJsonDb::remove()
* Try to remove an item which doesn't exist
*/
-void TestJsonDb::remove2()
+void TestPartition::remove2()
{
JsonDbObject item;
item.insert("remove2-test", 100);
@@ -933,7 +936,7 @@ void TestJsonDb::remove2()
* Don't include a 'uuid' field
*/
-void TestJsonDb::remove3()
+void TestPartition::remove3()
{
JsonDbObject item;
item.insert("remove3-test", 100);
@@ -945,7 +948,7 @@ void TestJsonDb::remove3()
/*
* Try to remove an item which existed before but was removed
*/
-void TestJsonDb::remove4()
+void TestPartition::remove4()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QLatin1String("remove-test-type"));
@@ -969,7 +972,7 @@ void TestJsonDb::remove4()
/*
* Remove a stale version of the object
*/
-void TestJsonDb::remove5()
+void TestPartition::remove5()
{
jsondbSettings->setRejectStaleUpdates(true);
@@ -990,7 +993,7 @@ void TestJsonDb::remove5()
jsondbSettings->setRejectStaleUpdates(false);
}
-void TestJsonDb::schemaValidation_data()
+void TestPartition::schemaValidation_data()
{
QTest::addColumn<QByteArray>("schema");
QTest::addColumn<QByteArray>("object");
@@ -1024,7 +1027,7 @@ void TestJsonDb::schemaValidation_data()
}
}
-void TestJsonDb::schemaValidation()
+void TestPartition::schemaValidation()
{
jsondbSettings->setValidateSchemas(true);
@@ -1036,7 +1039,7 @@ void TestJsonDb::schemaValidation()
id++;
QString schemaName = QLatin1String("schemaValidationSchema") + QString::number(id);
- QJsonObject schemaBody = readJson(schema).toObject();
+ QJsonObject schemaBody = QJsonDocument::fromJson(schema).object();
JsonDbObject schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
schemaObject.insert("name", schemaName);
@@ -1045,7 +1048,7 @@ void TestJsonDb::schemaValidation()
JsonDbWriteResult qResult = create(mOwner, schemaObject);
verifyGoodResult(qResult);
- JsonDbObject item = readJson(object).toObject();
+ JsonDbObject item = QJsonDocument::fromJson(object).object();
item.insert(JsonDbString::kTypeStr, schemaName);
// Create an item that matches the schema
@@ -1066,7 +1069,7 @@ void TestJsonDb::schemaValidation()
jsondbSettings->setValidateSchemas(false);
}
-void TestJsonDb::schemaValidationExtends_data()
+void TestPartition::schemaValidationExtends_data()
{
QTest::addColumn<QByteArray>("item");
QTest::addColumn<bool>("isPerson");
@@ -1086,7 +1089,7 @@ void TestJsonDb::schemaValidationExtends_data()
<< QByteArray("{ \"name\":\"Alice's great-grandmother\", \"age\": 130}") << false << false;
}
-void TestJsonDb::schemaValidationExtends()
+void TestPartition::schemaValidationExtends()
{
jsondbSettings->setValidateSchemas(true);
@@ -1117,8 +1120,8 @@ void TestJsonDb::schemaValidationExtends()
" \"properties\": {\"age\": {\"minimum\": 18}},"
" \"extends\": {\"$ref\":\"person%1\"}"
"}").arg(QString::number(id)).toLatin1();
- QJsonObject personSchemaBody = readJson(person).toObject();
- QJsonObject adultSchemaBody = readJson(adult).toObject();
+ QJsonObject personSchemaBody = QJsonDocument::fromJson(person).object();
+ QJsonObject adultSchemaBody = QJsonDocument::fromJson(adult).object();
JsonDbObject personSchemaObject;
personSchemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
@@ -1137,7 +1140,7 @@ void TestJsonDb::schemaValidationExtends()
}
{
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert("testingForPerson", isPerson);
object.insert(JsonDbString::kTypeStr, personSchemaName);
qResult = create(mOwner, object);
@@ -1149,7 +1152,7 @@ void TestJsonDb::schemaValidationExtends()
}
{
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert("testingForAdult", isAdult);
object.insert(JsonDbString::kTypeStr, adultSchemaName);
qResult = create(mOwner, object);
@@ -1164,7 +1167,7 @@ void TestJsonDb::schemaValidationExtends()
}
-void TestJsonDb::schemaValidationExtendsArray_data()
+void TestPartition::schemaValidationExtendsArray_data()
{
QTest::addColumn<QByteArray>("item");
QTest::addColumn<bool>("isValid");
@@ -1181,7 +1184,7 @@ void TestJsonDb::schemaValidationExtendsArray_data()
<< QByteArray("{ \"waterSpeed\":100, \"landSpeed\": 100, \"airSpeed\": 100}") << true;
}
-void TestJsonDb::schemaValidationExtendsArray()
+void TestPartition::schemaValidationExtendsArray()
{
jsondbSettings->setValidateSchemas(true);
@@ -1215,9 +1218,9 @@ void TestJsonDb::schemaValidationExtendsArray()
" \"extends\": [{\"$ref\":\"car%1\"}, {\"$ref\":\"boat%1\"}]"
"}").arg(QString::number(id)).toLatin1();
- QJsonObject amphibiousSchemaBody = readJson(amphibious).toObject();
- QJsonObject carSchemaBody = readJson(car).toObject();
- QJsonObject boatSchemaBody = readJson(boat).toObject();
+ QJsonObject amphibiousSchemaBody = QJsonDocument::fromJson(amphibious).object();
+ QJsonObject carSchemaBody = QJsonDocument::fromJson(car).object();
+ QJsonObject boatSchemaBody = QJsonDocument::fromJson(boat).object();
JsonDbObject carSchemaObject;
@@ -1244,7 +1247,7 @@ void TestJsonDb::schemaValidationExtendsArray()
}
{
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert("testingForAmphibious", isValid);
object.insert(JsonDbString::kTypeStr, amphibiousSchemaName);
qResult = create(mOwner, object);
@@ -1258,7 +1261,7 @@ void TestJsonDb::schemaValidationExtendsArray()
jsondbSettings->setValidateSchemas(false);
}
-void TestJsonDb::schemaValidationLazyInit()
+void TestPartition::schemaValidationLazyInit()
{
jsondbSettings->setValidateSchemas(true);
@@ -1281,8 +1284,8 @@ void TestJsonDb::schemaValidationLazyInit()
const QString personSchemaName = QString::fromLatin1("personLazyInit");
const QString adultSchemaName = QString::fromLatin1("adultLazyInit");
- QJsonObject personSchemaBody = readJson(person).toObject();
- QJsonObject adultSchemaBody = readJson(adult).toObject();
+ QJsonObject personSchemaBody = QJsonDocument::fromJson(person).object();
+ QJsonObject adultSchemaBody = QJsonDocument::fromJson(adult).object();
JsonDbObject personSchemaObject;
personSchemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
@@ -1305,35 +1308,35 @@ void TestJsonDb::schemaValidationLazyInit()
// Insert some objects to force full schema compilation
{
const QByteArray item = "{ \"name\":\"Nierob\", \"age\":99 }";
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert(JsonDbString::kTypeStr, adultSchemaName);
qResult = create(mOwner, object);
verifyGoodResult(qResult);
}
{
const QByteArray item = "{ \"name\":\"Nierob\", \"age\":12 }";
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert(JsonDbString::kTypeStr, adultSchemaName);
qResult = create(mOwner, object);
verifyErrorResult(qResult);
}
{
const QByteArray item = "{ \"age\":19 }";
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert(JsonDbString::kTypeStr, adultSchemaName);
qResult = create(mOwner, object);
verifyErrorResult(qResult);
}
{
const QByteArray item = "{ \"name\":\"Nierob\", \"age\":12 }";
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert(JsonDbString::kTypeStr, personSchemaName);
qResult = create(mOwner, object);
verifyGoodResult(qResult);
}
{
const QByteArray item = "{ \"age\":12 }";
- JsonDbObject object = readJson(item).toObject();
+ JsonDbObject object = QJsonDocument::fromJson(item).object();
object.insert(JsonDbString::kTypeStr, personSchemaName);
qResult = create(mOwner, object);
verifyErrorResult(qResult);
@@ -1349,7 +1352,7 @@ void TestJsonDb::schemaValidationLazyInit()
#define LIST_TEST_ITEMS 6
-void TestJsonDb::createList()
+void TestPartition::createList()
{
JsonDbObjectList list;
for (int i = 0 ; i < LIST_TEST_ITEMS ; i++ ) {
@@ -1367,7 +1370,7 @@ void TestJsonDb::createList()
* Create a list of items and then update them
*/
-void TestJsonDb::updateList()
+void TestPartition::updateList()
{
JsonDbObjectList list;
for (int i = 0 ; i < LIST_TEST_ITEMS ; i++ ) {
@@ -1387,7 +1390,7 @@ void TestJsonDb::updateList()
QCOMPARE(result.objectsWritten.count(), LIST_TEST_ITEMS);
}
-void TestJsonDb::mapDefinition()
+void TestPartition::mapDefinition()
{
// we need a schema that extends View for our targetType
JsonDbObject schema;
@@ -1413,7 +1416,7 @@ void TestJsonDb::mapDefinition()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::mapDefinitionInvalid()
+void TestPartition::mapDefinitionInvalid()
{
// we need a schema that extends View for our targetType
JsonDbObject schema;
@@ -1461,7 +1464,7 @@ void TestJsonDb::mapDefinitionInvalid()
verifyGoodResult(res);
}
-void TestJsonDb::reduceDefinition()
+void TestPartition::reduceDefinition()
{
// we need a schema that extends View for our targetType
JsonDbObject schema;
@@ -1488,7 +1491,7 @@ void TestJsonDb::reduceDefinition()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::reduceDefinitionInvalid()
+void TestPartition::reduceDefinitionInvalid()
{
// we need a schema that extends View for our targetType
JsonDbObject schema;
@@ -1573,7 +1576,7 @@ void TestJsonDb::reduceDefinitionInvalid()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::mapInvalidMapFunc()
+void TestPartition::mapInvalidMapFunc()
{
JsonDbObject schema;
schema.insert(JsonDbString::kTypeStr, QLatin1String("_schemaType"));
@@ -1599,7 +1602,7 @@ void TestJsonDb::mapInvalidMapFunc()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::reduceInvalidAddSubtractFuncs()
+void TestPartition::reduceInvalidAddSubtractFuncs()
{
JsonDbObject schema;
schema.insert(JsonDbString::kTypeStr, QLatin1String("_schemaType"));
@@ -1624,11 +1627,10 @@ void TestJsonDb::reduceInvalidAddSubtractFuncs()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::map()
+void TestPartition::map()
{
addIndex(QLatin1String("phoneNumber"));
-
- QJsonArray objects(readJsonFile(":/daemon/json/map-reduce.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce.json").toArray());
JsonDbObjectList mapsReduces;
JsonDbObjectList schemas;
@@ -1662,12 +1664,12 @@ void TestJsonDb::map()
// get results with getObjects()
GetObjectsResult getObjectsResult = mJsonDbPartition->getObjects(JsonDbString::kTypeStr, QLatin1String("Phone"));
- QCOMPARE(getObjectsResult.data.size(), 3);
if (jsondbSettings->verbose()) {
JsonDbObjectList vs = getObjectsResult.data;
for (int i = 0; i < vs.size(); i++)
qDebug() << " " << vs[i];
}
+ QCOMPARE(getObjectsResult.data.size(), 3);
// query for results
queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
@@ -1728,9 +1730,9 @@ void TestJsonDb::map()
}
-void TestJsonDb::mapDuplicateSourceAndTarget()
+void TestPartition::mapDuplicateSourceAndTarget()
{
- QJsonArray objects(readJsonFile(":/daemon/json/map-sametarget.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-sametarget.json").toArray());
JsonDbObjectList toDelete;
JsonDbObjectList maps;
@@ -1762,9 +1764,9 @@ void TestJsonDb::mapDuplicateSourceAndTarget()
mJsonDbPartition->removeIndex("ContactView");
}
-void TestJsonDb::mapRemoval()
+void TestPartition::mapRemoval()
{
- QJsonArray objects(readJsonFile(":/daemon/json/map-sametarget.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-sametarget.json").toArray());
QList<JsonDbObject> maps;
QList<JsonDbObject> toDelete;
@@ -1804,9 +1806,9 @@ void TestJsonDb::mapRemoval()
verifyGoodResult(remove(mOwner, toDelete.at(ii)));
}
-void TestJsonDb::mapUpdate()
+void TestPartition::mapUpdate()
{
- QJsonArray objects(readJsonFile(":/daemon/json/map-sametarget.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-sametarget.json").toArray());
JsonDbObjectList maps;
JsonDbObjectList toDelete;
@@ -1868,9 +1870,9 @@ void TestJsonDb::mapUpdate()
}
-void TestJsonDb::mapJoin()
+void TestPartition::mapJoin()
{
- QJsonArray objects(readJsonFile(":/daemon/json/map-join.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-join.json").toArray());
JsonDbObject join;
JsonDbObject schema;
@@ -1971,11 +1973,11 @@ void TestJsonDb::mapJoin()
mJsonDbPartition->removeIndex("value.foaf", "FoafPerson");
}
-void TestJsonDb::mapSelfJoinSourceUuids()
+void TestPartition::mapSelfJoinSourceUuids()
{
addIndex("magic", "string");
- QJsonArray objects(readJsonFile(":/daemon/json/map-join-sourceuuids.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-join-sourceuuids.json").toArray());
JsonDbObjectList toDelete;
JsonDbObject toUpdate;
@@ -2012,7 +2014,7 @@ void TestJsonDb::mapSelfJoinSourceUuids()
mJsonDbPartition->removeIndex("magic", "string");
}
-void TestJsonDb::mapMapFunctionError()
+void TestPartition::mapMapFunctionError()
{
JsonDbObject schema;
schema.insert(JsonDbString::kTypeStr, QString("_schemaType"));
@@ -2051,7 +2053,7 @@ void TestJsonDb::mapMapFunctionError()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::mapSchemaViolation()
+void TestPartition::mapSchemaViolation()
{
jsondbSettings->setValidateSchemas(true);
@@ -2061,7 +2063,7 @@ void TestJsonDb::mapSchemaViolation()
remove(mOwner, toRemove);
}
- QJsonArray objects(readJsonFile(":/daemon/json/map-reduce-schema.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce-schema.json").toArray());
JsonDbObjectList toDelete;
QJsonValue workingMap;
JsonDbObject map;
@@ -2130,7 +2132,7 @@ void TestJsonDb::mapSchemaViolation()
}
// verify that only one target object per source object is allowed without targetKeyName
-void TestJsonDb::mapMultipleEmitNoTargetKeyName()
+void TestPartition::mapMultipleEmitNoTargetKeyName()
{
jsondbSettings->setValidateSchemas(true);
@@ -2140,7 +2142,7 @@ void TestJsonDb::mapMultipleEmitNoTargetKeyName()
remove(mOwner, toRemove);
}
- QJsonArray objects(readJsonFile(":/daemon/json/map-reduce-schema.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce-schema.json").toArray());
JsonDbObjectList toDelete;
JsonDbObject map;
@@ -2178,15 +2180,19 @@ void TestJsonDb::mapMultipleEmitNoTargetKeyName()
jsondbSettings->setValidateSchemas(false);
}
-void TestJsonDb::mapArrayConversion()
+void TestPartition::mapArrayConversion()
{
- QJsonArray objects(readJsonFile(":/daemon/json/map-array-conversion.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-array-conversion.json").toArray());
JsonDbObjectList toDelete;
+ JsonDbObject mapDefinition;
for (int i = 0; i < objects.size(); i++) {
JsonDbObject object(objects.at(i).toObject());
JsonDbWriteResult result = create(mOwner, object);
verifyGoodResult(result);
- toDelete.append(object);
+ if (object.value(JsonDbString::kTypeStr) == JsonDbString::kMapTypeStr)
+ mapDefinition = object;
+ else
+ toDelete.append(object);
}
JsonDbObject testObject;
@@ -2199,11 +2205,99 @@ void TestJsonDb::mapArrayConversion()
QCOMPARE(queryResult.data.size(), 1);
JsonDbObject o = queryResult.data.at(0);
QVERIFY(o.value("result").isArray());
+
+ verifyGoodResult(remove(mOwner, mapDefinition));
+ for (int ii = 0; ii < toDelete.size(); ii++)
+ verifyGoodResult(remove(mOwner, toDelete.at(ii)));
}
-void TestJsonDb::reduce()
+static QHash<QString, QList<QString> > sDebugMessages;
+void logMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg)
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ Q_UNUSED(context);
+ switch (type) {
+ case QtDebugMsg:
+ sDebugMessages[QLatin1Literal("Debug")].append(msg);
+ break;
+ case QtWarningMsg:
+ sDebugMessages[QLatin1Literal("Warning")].append(msg);
+ break;
+ case QtCriticalMsg:
+ sDebugMessages[QLatin1Literal("Critical")].append(msg);
+ break;
+ case QtFatalMsg:
+ sDebugMessages[QLatin1Literal("Fatal")].append(msg);
+ break;
+ }
+}
+
+void TestPartition::mapConsole()
+{
+ bool wasVerbose = jsondbSettings->verbose();
+ bool wasDebug = jsondbSettings->debug();
+ sDebugMessages.clear();
+ QMessageHandler oldMessageHandler = qInstallMessageHandler(logMessageOutput);
+ jsondbSettings->setVerbose(true);
+ jsondbSettings->setDebug(true);
+
+ QJsonArray objects(readJsonFile(":/partition/json/map-array-conversion.json").toArray());
+ JsonDbObjectList toDelete;
+ JsonDbObject mapDefinition;
+ QLatin1Literal sourceType("com.test.Test");
+ for (int i = 0; i < objects.size(); i++) {
+ JsonDbObject object(objects.at(i).toObject());
+ if (object.value(JsonDbString::kTypeStr) == JsonDbString::kMapTypeStr) {
+ QJsonObject map = object.value(QLatin1Literal("map")).toObject();
+ // replace with a map that just calls console functions
+ map.insert(sourceType, QLatin1String("function(test) { console.warn('testing'); for (var i in test) { if (i.indexOf('_') < 0) console[i](test[i]); } }"));
+ object.insert(QLatin1Literal("map"), map);
+ }
+ JsonDbWriteResult result = create(mOwner, object);
+ verifyGoodResult(result);
+ if (object.value(JsonDbString::kTypeStr) == JsonDbString::kMapTypeStr)
+ mapDefinition = object;
+ else
+ toDelete.append(object);
+ }
+
+ QMap<QString,QString> levelMapping;
+ levelMapping["log"] = "Debug";
+ levelMapping["debug"] = "Debug";
+ levelMapping["info"] = "Debug";
+ levelMapping["warn"] = "Warning";
+ levelMapping["error"] = "Critical";
+
+ QStringList consoleMethods = levelMapping.keys();
+ JsonDbObject testObject;
+ testObject.insert(JsonDbString::kTypeStr, QLatin1String("com.test.Test"));
+ foreach (const QString &method, consoleMethods)
+ testObject.insert(method, QString("%1 message").arg(method));
+ JsonDbWriteResult result = create(mOwner, testObject);
+ verifyGoodResult(result);
+
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"com.test.TestView\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 0);
+
+ // revert to original settings
+ jsondbSettings->setVerbose(wasVerbose);
+ jsondbSettings->setDebug(wasDebug);
+ qInstallMessageHandler(oldMessageHandler);
+
+ // verify each method was invoked
+ foreach (const QString &method, consoleMethods) {
+ QVERIFY(sDebugMessages.contains(levelMapping[method]));
+ QVERIFY(sDebugMessages[levelMapping[method]].contains(QString("\"%1 message\" ").arg(method)));
+ }
+
+ verifyGoodResult(remove(mOwner, mapDefinition));
+ for (int ii = 0; ii < toDelete.size(); ii++)
+ verifyGoodResult(remove(mOwner, toDelete.at(ii)));
+}
+
+void TestPartition::reduce()
+{
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
JsonDbObjectList toDelete;
JsonDbObjectList reduces;
@@ -2217,7 +2311,7 @@ void TestJsonDb::reduce()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
JsonDbWriteResult result = create(mOwner, object);
@@ -2244,9 +2338,9 @@ void TestJsonDb::reduce()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceFlattened()
+void TestPartition::reduceFlattened()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
JsonDbObjectList toDelete;
JsonDbObjectList reduces;
@@ -2260,7 +2354,7 @@ void TestJsonDb::reduceFlattened()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kReduceTypeStr) {
@@ -2293,9 +2387,9 @@ void TestJsonDb::reduceFlattened()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceSourceKeyFunction()
+void TestPartition::reduceSourceKeyFunction()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
JsonDbObjectList toDelete;
JsonDbObjectList reduces;
@@ -2309,7 +2403,7 @@ void TestJsonDb::reduceSourceKeyFunction()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kReduceTypeStr) {
@@ -2342,9 +2436,9 @@ void TestJsonDb::reduceSourceKeyFunction()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceRemoval()
+void TestPartition::reduceRemoval()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
QJsonArray toDelete;
QHash<QString, int> firstNameCount;
@@ -2356,7 +2450,7 @@ void TestJsonDb::reduceRemoval()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
JsonDbObject reduce;
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
@@ -2384,9 +2478,9 @@ void TestJsonDb::reduceRemoval()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceUpdate()
+void TestPartition::reduceUpdate()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
QJsonArray toDelete;
QHash<QString, int> firstNameCount;
@@ -2400,7 +2494,7 @@ void TestJsonDb::reduceUpdate()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
JsonDbObject reduce;
JsonDbObject schema;
for (int ii = 0; ii < objects.size(); ii++) {
@@ -2447,9 +2541,9 @@ void TestJsonDb::reduceUpdate()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceDuplicate()
+void TestPartition::reduceDuplicate()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-data.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-data.json").toArray());
JsonDbObjectList toDelete;
QHash<QString, int> firstNameCount;
@@ -2463,7 +2557,7 @@ void TestJsonDb::reduceDuplicate()
toDelete.append(object);
}
- objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ objects = readJsonFile(":/partition/json/reduce.json").toArray();
JsonDbObject reduce;
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
@@ -2518,7 +2612,7 @@ void TestJsonDb::reduceDuplicate()
mJsonDbPartition->removeIndex("MyContactCount");
}
-void TestJsonDb::reduceFunctionError()
+void TestPartition::reduceFunctionError()
{
JsonDbObject schema;
QString viewTypeStr("ReduceFunctionErrorView");
@@ -2557,11 +2651,11 @@ void TestJsonDb::reduceFunctionError()
verifyGoodResult(remove(mOwner, schema));
}
-void TestJsonDb::reduceSchemaViolation()
+void TestPartition::reduceSchemaViolation()
{
jsondbSettings->setValidateSchemas(true);
- QJsonArray objects(readJsonFile(":/daemon/json/map-reduce-schema.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce-schema.json").toArray());
QJsonArray toDelete;
JsonDbObject map;
@@ -2632,9 +2726,9 @@ void TestJsonDb::reduceSchemaViolation()
jsondbSettings->setValidateSchemas(false);
}
-void TestJsonDb::reduceSubObjectProp()
+void TestPartition::reduceSubObjectProp()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-subprop.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-subprop.json").toArray());
QJsonArray toDelete;
JsonDbObject reduce;
@@ -2672,9 +2766,9 @@ void TestJsonDb::reduceSubObjectProp()
mJsonDbPartition->removeIndex("NameCount");
}
-void TestJsonDb::reduceArray()
+void TestPartition::reduceArray()
{
- QJsonArray objects(readJsonFile(":/daemon/json/reduce-array.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/reduce-array.json").toArray());
QJsonArray toDelete;
JsonDbObject human;
@@ -2720,7 +2814,7 @@ void TestJsonDb::reduceArray()
mJsonDbPartition->removeIndex("ArrayView");
}
-void TestJsonDb::changesSinceCreate()
+void TestPartition::changesSinceCreate()
{
QJsonObject csRes = mJsonDbPartition->changesSince(0);
QVERIFY(csRes.value(JsonDbString::kErrorStr).isNull());
@@ -2748,7 +2842,7 @@ void TestJsonDb::changesSinceCreate()
QCOMPARE(after.value("lastName").toString(), toCreate.value("lastName").toString());
}
-void TestJsonDb::addIndex()
+void TestPartition::addIndex()
{
addIndex(QLatin1String("subject"));
@@ -2763,16 +2857,16 @@ void TestJsonDb::addIndex()
remove(mOwner, indexObject);
}
-void TestJsonDb::addSchema()
+void TestPartition::addSchema()
{
JsonDbObject s;
addSchema("contact", s);
verifyGoodResult(remove(mOwner, s));
}
-void TestJsonDb::duplicateSchema()
+void TestPartition::duplicateSchema()
{
- QJsonValue schema = readJsonFile(":/daemon/schemas/address.json");
+ QJsonValue schema = readJsonFile(":/partition/schemas/address.json");
JsonDbObject schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
schemaObject.insert("name", QLatin1String("Address"));
@@ -2792,9 +2886,9 @@ void TestJsonDb::duplicateSchema()
verifyGoodResult(result);
}
-void TestJsonDb::removeSchema()
+void TestPartition::removeSchema()
{
- QJsonValue schema = readJsonFile(":/daemon/schemas/address.json");
+ QJsonValue schema = readJsonFile(":/partition/schemas/address.json");
JsonDbObject schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
schemaObject.insert("name", QLatin1String("Address"));
@@ -2821,9 +2915,9 @@ void TestJsonDb::removeSchema()
verifyGoodResult(result);
}
-void TestJsonDb::removeViewSchema()
+void TestPartition::removeViewSchema()
{
- QJsonArray objects = readJsonFile(":/daemon/json/reduce.json").toArray();
+ QJsonArray objects = readJsonFile(":/partition/json/reduce.json").toArray();
JsonDbObject schema;
JsonDbObject reduce;
for (int i = 0; i < objects.size(); ++i) {
@@ -2848,9 +2942,9 @@ void TestJsonDb::removeViewSchema()
verifyGoodResult(result);
}
-void TestJsonDb::updateSchema()
+void TestPartition::updateSchema()
{
- QJsonObject schema = readJsonFile(":/daemon/schemas/address.json").toObject();
+ QJsonObject schema = readJsonFile(":/partition/schemas/address.json").toObject();
QVERIFY(!schema.isEmpty());
JsonDbObject schemaObject;
schemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
@@ -2883,7 +2977,7 @@ void TestJsonDb::updateSchema()
verifyGoodResult(result);
}
-void TestJsonDb::unindexedFind()
+void TestPartition::unindexedFind()
{
JsonDbObject item;
item.insert("_type", QLatin1String("unindexedFind"));
@@ -2911,7 +3005,7 @@ void TestJsonDb::unindexedFind()
remove(mOwner, item);
}
-void TestJsonDb::find1()
+void TestPartition::find1()
{
JsonDbObject item;
item.insert(JsonDbString::kTypeStr, QString("Find1Type"));
@@ -2924,7 +3018,7 @@ void TestJsonDb::find1()
QVERIFY(queryResult.data.size() >= 1);
}
-void TestJsonDb::find2()
+void TestPartition::find2()
{
addIndex(QLatin1String("name"));
addIndex(QLatin1String("_type"));
@@ -3007,7 +3101,7 @@ QStringList strings = (QStringList()
QStringList patterns = (QStringList()
);
-void TestJsonDb::findLikeRegexp_data()
+void TestPartition::findLikeRegexp_data()
{
QTest::addColumn<QString>("pattern");
QTest::addColumn<QString>("modifiers");
@@ -3040,7 +3134,7 @@ void TestJsonDb::findLikeRegexp_data()
}
}
-void TestJsonDb::findLikeRegexp()
+void TestPartition::findLikeRegexp()
{
QFETCH(QString, pattern);
QFETCH(QString, modifiers);
@@ -3074,7 +3168,7 @@ void TestJsonDb::findLikeRegexp()
QCOMPARE(length, expectedMatches.size());
}
-void TestJsonDb::findInContains()
+void TestPartition::findInContains()
{
QList<QStringList> stringLists;
stringLists << (QStringList() << "fred" << "barney");
@@ -3112,7 +3206,7 @@ void TestJsonDb::findInContains()
mJsonDbPartition->removeIndex("i");
}
-void TestJsonDb::findFields()
+void TestPartition::findFields()
{
addIndex(QLatin1String("name"));
addIndex(QLatin1String("_type"));
@@ -3131,22 +3225,16 @@ void TestJsonDb::findFields()
QJsonObject query, result, map;
- JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?firstName=\"Wilma\"][=firstName]"));
- verifyGoodQueryResult(queryResult);
- QCOMPARE(queryResult.values.at(0).toString(), QString("Wilma"));
-
- queryResult = find(mOwner, QLatin1String("[?firstName=\"Wilma\"][= [firstName,lastName]]"));
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?firstName=\"Wilma\"][= {firstName:firstName,lastName:lastName}]"));
verifyGoodQueryResult(queryResult);
- QCOMPARE(queryResult.values.size(), 1);
- QJsonArray data = queryResult.values.at(0).toArray();
- QCOMPARE(data.at(0).toString(), QString("Wilma"));
- QCOMPARE(data.at(1).toString(), QString("Flintstone"));
+ QCOMPARE(queryResult.data.size(), 1);
+ QJsonObject data = queryResult.data.at(0);
+ QCOMPARE(data.value(QLatin1String("firstName")).toString(), QString("Wilma"));
+ QCOMPARE(data.value(QLatin1String("lastName")).toString(), QString("Flintstone"));
mJsonDbPartition->removeIndex(QLatin1String("firstName"));
- //mJsonDbPartition->removeIndex(QLatin1String("name"));
- //mJsonDbPartition->removeIndex(QLatin1String("_type")); //crash here
}
-void TestJsonDb::orderedFind1_data()
+void TestPartition::orderedFind1_data()
{
QTest::addColumn<QString>("order");
QTest::newRow("asc") << "/";
@@ -3171,7 +3259,7 @@ void TestJsonDb::orderedFind1_data()
create(mOwner, item3);
}
-void TestJsonDb::orderedFind1()
+void TestPartition::orderedFind1()
{
QFETCH(QString, order);
@@ -3200,7 +3288,7 @@ void TestJsonDb::orderedFind1()
mJsonDbPartition->removeIndex(QLatin1String("_type"));
}
-void TestJsonDb::orderedFind2_data()
+void TestPartition::orderedFind2_data()
{
QTest::addColumn<QString>("order");
QTest::addColumn<QString>("field");
@@ -3217,7 +3305,7 @@ void TestJsonDb::orderedFind2_data()
}
}
-void TestJsonDb::orderedFind2()
+void TestPartition::orderedFind2()
{
QFETCH(QString, order);
QFETCH(QString, field);
@@ -3250,7 +3338,7 @@ void TestJsonDb::orderedFind2()
}
}
-void TestJsonDb::wildcardIndex()
+void TestPartition::wildcardIndex()
{
addIndex("telephoneNumbers.*.number");
JsonDbObject item;
@@ -3270,12 +3358,12 @@ void TestJsonDb::wildcardIndex()
JsonDbQueryResult queryResult = find(mOwner, QString("[?telephoneNumbers.*.number=\"%1\"]").arg(mobileNumberString));
verifyGoodQueryResult(queryResult);
- queryResult = find(mOwner, QString("[?%1=\"%2\"][= .telephoneNumbers[*].number]").arg(JsonDbString::kTypeStr).arg(kContactStr));
+ queryResult = find(mOwner, QString("[?%1=\"%2\"][? telephoneNumbers[*].number exists ]").arg(JsonDbString::kTypeStr).arg(kContactStr));
verifyGoodQueryResult(queryResult);
mJsonDbPartition->removeIndex("telephoneNumbers.*.number");
}
-void TestJsonDb::uuidJoin()
+void TestPartition::uuidJoin()
{
addIndex("name");
addIndex("thumbnailUuid");
@@ -3324,22 +3412,9 @@ void TestJsonDb::uuidJoin()
QVERIFY(queryResult.data.size() > 0);
QCOMPARE(queryResult.data.at(0).value("thumbnailUuid").toString(), thumbnailUuid);
- queryResult = find(mOwner, QLatin1String("[?name=\"Betty\"][= [ name, thumbnailUuid->url ]]"));
- verifyGoodQueryResult(queryResult);
- QCOMPARE(queryResult.values.at(0).toArray().at(1).toString(), thumbnailUrl);
-
- queryResult = find(mOwner, QString("[?_type=\"%1\"][= [ name, thumbnailUuid->url ]]").arg(__FUNCTION__));
+ queryResult = find(mOwner, QLatin1String("[?name=\"Betty\"][= { name:name, url:thumbnailUuid->url }]"));
verifyGoodQueryResult(queryResult);
- QJsonArray values = queryResult.values;
- for (int ii = 0; ii < values.size(); ii++) {
- QJsonArray item = values.at(ii).toArray();
- QString name = item.at(0).toString();
- QString url = item.at(1).toString();
- if (name == "Pebbles")
- QVERIFY(url.isEmpty());
- else
- QCOMPARE(url, thumbnailUrl);
- }
+ QCOMPARE(queryResult.data.at(0).value(QLatin1String("url")).toString(), thumbnailUrl);
queryResult = find(mOwner, QString("[?_type=\"%1\"][= { name: name, url: thumbnailUuid->url } ]").arg(__FUNCTION__));
verifyGoodQueryResult(queryResult);
@@ -3355,22 +3430,22 @@ void TestJsonDb::uuidJoin()
QCOMPARE(url, thumbnailUrl);
}
-
- queryResult = find(mOwner, QLatin1String("[?bettyUuid exists][= bettyUuid->thumbnailUuid]"));
+ queryResult = find(mOwner, QLatin1String("[?bettyUuid exists][= { thumbnailUuid : bettyUuid->thumbnailUuid }]"));
verifyGoodQueryResult(queryResult);
- QCOMPARE(queryResult.values.at(0).toString(),
+ QCOMPARE(queryResult.data.at(0).value(QLatin1String("thumbnailUuid")).toString(),
thumbnailUuid);
- queryResult = find(mOwner, QLatin1String("[?bettyUuid exists][= bettyUuid->thumbnailUuid->url]"));
+ queryResult = find(mOwner, QLatin1String("[?bettyUuid exists][= { thumbnailUuid : bettyUuid->thumbnailUuid->url }]"));
verifyGoodQueryResult(queryResult);
- QCOMPARE(queryResult.values.at(0).toString(), thumbnail.value("url").toString());
+ QCOMPARE(queryResult.data.at(0).value(QLatin1String("thumbnailUuid")).toString(),
+ thumbnail.value("url").toString());
mJsonDbPartition->removeIndex("name");
mJsonDbPartition->removeIndex("thumbnailUuid");
mJsonDbPartition->removeIndex("url");
mJsonDbPartition->removeIndex("bettyUuid");
}
-void TestJsonDb::orQuery_data()
+void TestPartition::orQuery_data()
{
QTest::addColumn<QString>("field1");
QTest::addColumn<QString>("value1");
@@ -3423,7 +3498,7 @@ void TestJsonDb::orQuery_data()
mJsonDbPartition->removeIndex(QLatin1String("key2"));
}
-void TestJsonDb::orQuery()
+void TestPartition::orQuery()
{
QFETCH(QString, field1);
QFETCH(QString, value1);
@@ -3449,7 +3524,7 @@ void TestJsonDb::orQuery()
mJsonDbPartition->removeIndex("key2");
}
-void TestJsonDb::findByName()
+void TestPartition::findByName()
{
createContacts();
int count = mContactList.size();
@@ -3469,7 +3544,7 @@ void TestJsonDb::findByName()
verifyGoodQueryResult(queryResult);
}
-void TestJsonDb::findEQ()
+void TestPartition::findEQ()
{
createContacts();
int count = mContactList.size();
@@ -3488,7 +3563,7 @@ void TestJsonDb::findEQ()
mJsonDbPartition->removeIndex("name.last");
}
-void TestJsonDb::find10()
+void TestPartition::find10()
{
createContacts();
int count = mContactList.size();
@@ -3502,40 +3577,16 @@ void TestJsonDb::find10()
QString query = QString("[?name.first<=\"%1\"][?_type=\"contact\"]")
.arg(item.propertyLookup("name.first").toString());
- JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 10);
- verifyGoodQueryResult(queryResult);
+ JsonDbQuery *parsedQuery = JsonDbQuery::parse(query);
+ JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery, 10);
+ delete parsedQuery;
+ verifyGoodQueryResult(queryResult);
QCOMPARE(queryResult.data.size(), 10);
mJsonDbPartition->removeIndex("name.first");
mJsonDbPartition->removeIndex("contact");
}
-QJsonValue TestJsonDb::readJsonFile(const QString& filename)
-{
- QString filepath = filename;
- QFile jsonFile(filepath);
- jsonFile.open(QIODevice::ReadOnly);
- QByteArray json = jsonFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << filepath << parser.errorString();
- }
- QVariant v = parser.result();
- return QJsonValue::fromVariant(v);
-}
-
-QJsonValue TestJsonDb::readJson(const QByteArray& json)
-{
- JsonReader parser;
- bool ok = parser.parse(json);
- if (!ok) {
- qDebug() << parser.errorString();
- }
- QVariant v = parser.result();
- return QJsonObject::fromVariantMap(v.toMap());
-}
-
-void TestJsonDb::startsWith()
+void TestPartition::startsWith()
{
addIndex(QLatin1String("name"));
@@ -3578,11 +3629,11 @@ void TestJsonDb::startsWith()
queryResult = find(mOwner, QLatin1String("[?_type startsWith \"startsWith\"][/name]"));
QCOMPARE(queryResult.data.size(), 4);
- queryResult = find(mOwner, QLatin1String("[?_type startsWith \"startsWith\"][= _type ]"));
- QCOMPARE(queryResult.values.size(), 4);
+ queryResult = find(mOwner, QLatin1String("[?_type startsWith \"startsWith\"][= { _type: _type } ]"));
+ QCOMPARE(queryResult.data.size(), 4);
}
-void TestJsonDb::comparison()
+void TestPartition::comparison()
{
addIndex(QLatin1String("latitude"), QLatin1String("number"));
@@ -3625,7 +3676,7 @@ void TestJsonDb::comparison()
mJsonDbPartition->removeIndex(QLatin1String("latitude"));
}
-void TestJsonDb::removedObjects()
+void TestPartition::removedObjects()
{
addIndex(QLatin1String("foo"));
addIndex(QLatin1String("name"));
@@ -3671,11 +3722,11 @@ void TestJsonDb::removedObjects()
mJsonDbPartition->removeIndex(QLatin1String("name"));
}
-void TestJsonDb::arrayIndexQuery()
+void TestPartition::arrayIndexQuery()
{
addIndex(QLatin1String("phoneNumber"));
- QJsonArray objects(readJsonFile(":/daemon/json/array.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/array.json").toArray());
QMap<QString, JsonDbObject> toDelete;
for (int i = 0; i < objects.size(); ++i) {
JsonDbObject object = objects.at(i).toObject();
@@ -3728,7 +3779,7 @@ void TestJsonDb::arrayIndexQuery()
verifyGoodResult(remove(mOwner, object));
}
-void TestJsonDb::deindexError()
+void TestPartition::deindexError()
{
JsonDbWriteResult result;
@@ -3770,7 +3821,7 @@ void TestJsonDb::deindexError()
}
}
-void TestJsonDb::expectedOrder()
+void TestPartition::expectedOrder()
{
QStringList list;
QStringList uuids;
@@ -3813,7 +3864,7 @@ void TestJsonDb::expectedOrder()
}
}
-void TestJsonDb::indexQueryOnCommonValues()
+void TestPartition::indexQueryOnCommonValues()
{
// Specific indexing bug when you have records inserted that only differ
// by their _type
@@ -3853,7 +3904,7 @@ void TestJsonDb::indexQueryOnCommonValues()
QCOMPARE(queryResult.data.size(), 1);
}
-void TestJsonDb::removeIndexes()
+void TestPartition::removeIndexes()
{
addIndex("wacky_index");
QVERIFY(mJsonDbPartition->findObjectTable(JsonDbString::kSchemaTypeStr)->indexSpec("wacky_index") != 0);
@@ -3879,7 +3930,7 @@ void TestJsonDb::removeIndexes()
QVERIFY(mJsonDbPartition->findObjectTable("Index")->indexSpec("predicate") == 0);
}
-void TestJsonDb::setOwner()
+void TestPartition::setOwner()
{
jsondbSettings->setEnforceAccessControl(true);
@@ -3898,7 +3949,7 @@ void TestJsonDb::setOwner()
result = remove(mOwner, item);
verifyGoodResult(result);
- JsonDbOwner *unauthOwner = new JsonDbOwner(this);
+ QScopedPointer<JsonDbOwner> unauthOwner(new JsonDbOwner(this));
unauthOwner->setOwnerId("com.example.OtherOwner");
unauthOwner->setAllowAll(false);
unauthOwner->setAllowedObjects(QLatin1String("all"), "write", (QStringList() << QLatin1String("[*]")));
@@ -3907,19 +3958,19 @@ void TestJsonDb::setOwner()
item = JsonDbObject();
item.insert(JsonDbString::kTypeStr, QLatin1String("SetOwnerType2"));
item.insert(JsonDbString::kOwnerStr, fooOwnerStr);
- result = create(unauthOwner, item);
+ result = create(unauthOwner.data(), item);
verifyGoodResult(result);
getObjects = mJsonDbPartition->getObjects(JsonDbString::kTypeStr, QLatin1String("SetOwnerType2"));
QVERIFY(getObjects.data.at(0).value(JsonDbString::kOwnerStr).toString()
!= fooOwnerStr);
- result = remove(unauthOwner, item);
+ result = remove(unauthOwner.data(), item);
verifyGoodResult(result);
jsondbSettings->setEnforceAccessControl(false);
}
-void TestJsonDb::indexPropertyFunction()
+void TestPartition::indexPropertyFunction()
{
JsonDbObject index;
index.insert(JsonDbString::kTypeStr, QLatin1String("Index"));
@@ -3967,9 +4018,27 @@ void TestJsonDb::indexPropertyFunction()
queryResult = find(mOwner, QLatin1String("[?_type=\"IndexPropertyFunction\"][?propertyFunctionIndex < 0]"));
QCOMPARE(queryResult.data.size(), 1);
QCOMPARE(queryResult.data.at(0).value("to").toDouble(), (double)-64);
+
+ // verify we can fetch the index values
+ queryResult = find(mOwner, QLatin1String("[?_type=\"IndexPropertyFunction\"][/propertyFunctionIndex]"));
+ QCOMPARE(queryResult.data.size(), 4);
+ JsonDbObjectList data = queryResult.data;
+ for (int i = 0; i < data.size(); i++) {
+ JsonDbObject o = queryResult.data.at(i);
+ QVERIFY(o.contains("_indexValue"));
+ QCOMPARE(o.value("_indexValue").toDouble(), (o.contains("to") ? o.value("to").toDouble() : o.value("from").toDouble()));
+ }
+
+ // verify we can fetch the index values
+ queryResult = find(mOwner, QLatin1String("[?_type=\"IndexPropertyFunction\"][?propertyFunctionIndex > 10][/propertyFunctionIndex][= { _uuid: _uuid, indexValue: propertyFunctionIndex }]"));
+ QCOMPARE(queryResult.data.size(), 1);
+ QCOMPARE(queryResult.data.at(0).value("to").toDouble(), (double)42);
+ QVERIFY(queryResult.data.at(0).contains("_indexValue"));
+ QCOMPARE(queryResult.data.at(0).value("_indexValue").toDouble(), (double)42);
+
}
-void TestJsonDb::indexCollation()
+void TestPartition::indexCollation()
{
#ifndef NO_COLLATION_SUPPORT
JsonDbObject item;
@@ -4066,9 +4135,9 @@ void TestJsonDb::indexCollation()
#endif
}
-void TestJsonDb::indexCaseSensitive()
+void TestPartition::indexCaseSensitive()
{
- QJsonArray objects(readJsonFile(":/daemon/json/index-casesensitive.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/index-casesensitive.json").toArray());
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
JsonDbWriteResult result = create(mOwner, object);
@@ -4092,10 +4161,10 @@ void TestJsonDb::indexCaseSensitive()
QCOMPARE(queryResult2.data.at(6).value("field").toString(), QLatin1String("aBB"));
}
-void TestJsonDb::indexCasePreference()
+void TestPartition::indexCasePreference()
{
#ifndef NO_COLLATION_SUPPORT
- QJsonArray objects(readJsonFile(":/daemon/json/index-casepreference.json").toArray());
+ QJsonArray objects(readJsonFile(":/partition/json/index-casepreference.json").toArray());
for (int ii = 0; ii < objects.size(); ii++) {
JsonDbObject object(objects.at(ii).toObject());
JsonDbWriteResult result = create(mOwner, object);
@@ -4134,8 +4203,15 @@ void TestJsonDb::indexCasePreference()
#endif
}
-void TestJsonDb::settings()
+void TestPartition::settings()
{
+ JsonDbSettings currentSettings;
+ const QMetaObject *metaObject = jsondbSettings->metaObject();
+ for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
+ QByteArray property = metaObject->property(i).name();
+ currentSettings.setProperty(property, jsondbSettings->property(property));
+ }
+
// first explicitly set the values
jsondbSettings->setRejectStaleUpdates(true);
jsondbSettings->setDebug(true);
@@ -4198,7 +4274,388 @@ void TestJsonDb::settings()
QCOMPARE(jsondbSettings->syncInterval(), 6000);
QCOMPARE(jsondbSettings->indexSyncInterval(), 17000);
QVERIFY(jsondbSettings->debugQuery());
+
+ // restore settings
+ for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
+ QByteArray property = metaObject->property(i).name();
+ jsondbSettings->setProperty(property, currentSettings.property(property));
+ }
+}
+
+void TestPartition::typeChangeIndex()
+{
+ JsonDbObject test1;
+ test1.insert(JsonDbString::kTypeStr, QLatin1String("TestContactTCI"));
+ test1.insert(QLatin1String("firstName"), QLatin1String("adam"));
+ verifyGoodResult(create(mOwner, test1));
+
+ JsonDbObject test2;
+ test2.insert(JsonDbString::kTypeStr, QLatin1String("TestContactTCI"));
+ test2.insert(QLatin1String("firstName"), QLatin1String("Betty"));
+ verifyGoodResult(create(mOwner, test2));
+
+ // create an object that's not an index
+ QString uuid = QUuid::createUuid().toString();
+ JsonDbObject changing;
+ changing.insert(JsonDbString::kUuidStr, uuid);
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.an.index"));
+ verifyGoodResult(create(mOwner, changing));
+
+ // FIXME: I think this only works currently because we auto-create the index
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"TestContactTCI\"][/firstName]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.count(), 2);
+ QCOMPARE(queryResult.data.at(0).value(JsonDbString::kUuidStr).toString(),
+ test2.value(JsonDbString::kUuidStr).toString());
+ QCOMPARE(queryResult.data.at(1).value(JsonDbString::kUuidStr).toString(),
+ test1.value(JsonDbString::kUuidStr).toString());
+
+ // change the object into an Index
+ changing.insert(JsonDbString::kTypeStr, JsonDbString::kIndexTypeStr);
+ changing.insert(JsonDbString::kNameStr, QLatin1String("firstName"));
+ changing.insert(JsonDbString::kPropertyNameStr, QLatin1String("firstName"));
+ changing.insert(JsonDbString::kCaseSensitiveStr, false);
+ verifyGoodResult(update(mOwner, changing));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"TestContactTCI\"][/firstName]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.count(), 2);
+ QCOMPARE(queryResult.data.at(0).value(JsonDbString::kUuidStr).toString(),
+ test1.value(JsonDbString::kUuidStr).toString());
+ QCOMPARE(queryResult.data.at(1).value(JsonDbString::kUuidStr).toString(),
+ test2.value(JsonDbString::kUuidStr).toString());
+
+ // change it back into a non-Index
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.an.index"));
+ verifyGoodResult(update(mOwner, changing));
+
+ // make sure the old ordering is back
+ queryResult = find(mOwner, QLatin1String("[?_type=\"TestContactTCI\"][/firstName]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.count(), 2);
+ QCOMPARE(queryResult.data.at(0).value(JsonDbString::kUuidStr).toString(),
+ test2.value(JsonDbString::kUuidStr).toString());
+ QCOMPARE(queryResult.data.at(1).value(JsonDbString::kUuidStr).toString(),
+ test1.value(JsonDbString::kUuidStr).toString());
+
+ verifyGoodResult(remove(mOwner, changing));
+ verifyGoodResult(remove(mOwner, test1));
+ verifyGoodResult(remove(mOwner, test2));
+}
+
+void TestPartition::typeChangeMap()
+{
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce.json").toArray());
+
+ JsonDbObjectList schemas;
+ JsonDbObject map;
+
+ QMap<QString, JsonDbObject> toDelete;
+
+ for (int i = 0; i < objects.size(); ++i) {
+ QJsonObject object(objects.at(i).toObject());
+ JsonDbObject doc(object);
+
+ if (doc.type() == JsonDbString::kMapTypeStr)
+ doc.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Map"));
+
+ if (doc.type() != JsonDbString::kReduceTypeStr) {
+ JsonDbWriteResult result = create(mOwner, doc);
+ verifyGoodResult(result);
+
+ if (doc.value(JsonDbString::kTypeStr).toString() == QLatin1String("not.a.Map"))
+ map = doc;
+ else if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kSchemaTypeStr)
+ schemas.append(doc);
+ else
+ toDelete.insert(doc.value("_uuid").toString(), doc);
+ }
+ }
+
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 0);
+
+ // change the object into a Map and test the result
+ map.insert(JsonDbString::kTypeStr, JsonDbString::kMapTypeStr);
+ verifyGoodResult(update(mOwner, map));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 5);
+
+ // make it not a Map again and test the result
+ map.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Map"));
+ verifyGoodResult(update(mOwner, map));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 0);
+
+ verifyGoodResult(remove(mOwner, map));
+ foreach (JsonDbObject schema, schemas)
+ verifyGoodResult(remove(mOwner, schema));
+
+ foreach (JsonDbObject del, toDelete.values())
+ verifyGoodResult(remove(mOwner, del));
+}
+
+void TestPartition::typeChangeReduce()
+{
+ JsonDbObject test1;
+ test1.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ test1.insert(QLatin1String("firstName"), QLatin1String("Bill"));
+ verifyGoodResult(create(mOwner, test1));
+
+ JsonDbObject test2;
+ test2.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ test2.insert(QLatin1String("firstName"), QLatin1String("Alice"));
+ verifyGoodResult(create(mOwner, test2));
+
+ QJsonArray objects(readJsonFile(":/partition/json/reduce.json").toArray());
+
+ JsonDbObject reduce;
+ JsonDbObject schema;
+
+ for (int i = 0; i < objects.size(); ++i) {
+ QJsonObject object(objects.at(i).toObject());
+ JsonDbObject doc(object);
+
+ if (doc.type() == JsonDbString::kReduceTypeStr)
+ doc.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Reduce"));
+
+ JsonDbWriteResult result = create(mOwner, doc);
+ verifyGoodResult(result);
+
+ if (doc.value(JsonDbString::kTypeStr).toString() == QLatin1String("not.a.Reduce"))
+ reduce = doc;
+ else if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kSchemaTypeStr)
+ schema = doc;
+ }
+
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 0);
+
+ // make it into a Reduce and check the result
+ reduce.insert(JsonDbString::kTypeStr, JsonDbString::kReduceTypeStr);
+ verifyGoodResult(update(mOwner, reduce));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 2);
+
+ // make it not a Reduce again and check the result
+ reduce.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Reduce"));
+ verifyGoodResult(update(mOwner, reduce));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 0);
+
+ verifyGoodResult(remove(mOwner, reduce));
+ verifyGoodResult(remove(mOwner, schema));
+ verifyGoodResult(remove(mOwner, test1));
+ verifyGoodResult(remove(mOwner, test2));
+}
+
+void TestPartition::typeChangeMapSource()
+{
+ QJsonArray objects(readJsonFile(":/partition/json/map-reduce.json").toArray());
+
+ JsonDbObject map;
+ JsonDbObject schema;
+ QMap<QString, JsonDbObject> toDelete;
+
+ for (int i = 0; i < objects.size(); ++i) {
+ QJsonObject object(objects.at(i).toObject());
+ JsonDbObject doc(object);
+
+ if (doc.type() != JsonDbString::kReduceTypeStr) {
+ JsonDbWriteResult result = create(mOwner, doc);
+ verifyGoodResult(result);
+
+ if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kMapTypeStr)
+ map = doc;
+ else if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kSchemaTypeStr)
+ schema = doc;
+ else
+ toDelete.insert(doc.value("_uuid").toString(), doc);
+ }
+ }
+
+ JsonDbObject changing;
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Contact"));
+ QJsonObject phoneNumber1;
+ phoneNumber1.insert(QLatin1String("type"), QLatin1String("home"));
+ phoneNumber1.insert(QLatin1String("number"), QLatin1String("+4700112233"));
+ QJsonObject phoneNumber2;
+ phoneNumber2.insert(QLatin1String("type"), QLatin1String("work"));
+ phoneNumber2.insert(QLatin1String("number"), QLatin1String("+4711223344"));
+ QJsonArray phoneNumbers;
+ phoneNumbers.append(phoneNumber1);
+ phoneNumbers.append(phoneNumber2);
+ changing.insert(QLatin1String("phoneNumbers"), phoneNumbers);
+
+ verifyGoodResult(create(mOwner, changing));
+
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 5);
+
+ // change the _type to a source type of the Map
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("Contact"));
+ verifyGoodResult(update(mOwner, changing));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 7);
+
+ // change it back to a non-source type
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.a.Contact"));
+ verifyGoodResult(update(mOwner, changing));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"Phone\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 5);
+
+ verifyGoodResult(remove(mOwner, map));
+ verifyGoodResult(remove(mOwner, schema));
+
+ foreach (JsonDbObject del, toDelete.values())
+ verifyGoodResult(remove(mOwner, del));
+}
+
+void TestPartition::typeChangeReduceSource()
+{
+ JsonDbObject test1;
+ test1.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ test1.insert(QLatin1String("firstName"), QLatin1String("Bill"));
+ verifyGoodResult(create(mOwner, test1));
+
+ JsonDbObject test2;
+ test2.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ test2.insert(QLatin1String("firstName"), QLatin1String("Alice"));
+ verifyGoodResult(create(mOwner, test2));
+
+ QJsonArray objects(readJsonFile(":/partition/json/reduce.json").toArray());
+
+ JsonDbObject reduce;
+ JsonDbObject schema;
+
+ for (int i = 0; i < objects.size(); ++i) {
+ QJsonObject object(objects.at(i).toObject());
+ JsonDbObject doc(object);
+
+ JsonDbWriteResult result = create(mOwner, doc);
+ verifyGoodResult(result);
+
+ if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kReduceTypeStr)
+ reduce = doc;
+ else if (object.value(JsonDbString::kTypeStr).toString() == JsonDbString::kSchemaTypeStr)
+ schema = doc;
+ }
+
+ JsonDbObject changing;
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.a.MyContact"));
+ changing.insert(QLatin1String("firstName"), QLatin1String("Bob"));
+ verifyGoodResult(create(mOwner, changing));
+
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 2);
+
+ // change the object so it's the source type of the Reduce
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ verifyGoodResult(update(mOwner, changing));
+
+ // re-query to see if the Reduce picked it up
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 3);
+
+ // change the object back to not being a source type of the Reduce
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.a.MyContact"));
+ verifyGoodResult(update(mOwner, changing));
+
+ // re-query to see if the Reduce picked it up
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 2);
+
+ // one more time, but this time adding to an existing Reduce target object
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("MyContact"));
+ changing.insert(QLatin1String("firstName"), QLatin1String("Alice"));
+ verifyGoodResult(update(mOwner, changing));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 2);
+
+ foreach (const JsonDbObject &object, queryResult.data) {
+ if (object.value(QLatin1String("firstName")).toString() == QLatin1String("Alice")) {
+ QCOMPARE(static_cast<int>(object.value(QLatin1String("count")).toDouble()), 2);
+ } else {
+ QVERIFY(object.value(QLatin1String("firstName")).toString() == QLatin1String("Bill"));
+ QCOMPARE(static_cast<int>(object.value(QLatin1String("count")).toDouble()), 1);
+ }
+ }
+
+ // change the type again and make sure the count goes back down
+ changing.insert(JsonDbString::kTypeStr, QLatin1String("not.a.MyContact"));
+ verifyGoodResult(update(mOwner, changing));
+
+ queryResult = find(mOwner, QLatin1String("[?_type=\"MyContactCount\"]"));
+ verifyGoodQueryResult(queryResult);
+ QCOMPARE(queryResult.data.size(), 2);
+
+ foreach (const JsonDbObject &object, queryResult.data)
+ QCOMPARE(static_cast<int>(object.value(QLatin1String("count")).toDouble()), 1);
+
+ verifyGoodResult(remove(mOwner, reduce));
+ verifyGoodResult(remove(mOwner, schema));
+ verifyGoodResult(remove(mOwner, test1));
+ verifyGoodResult(remove(mOwner, test2));
+ verifyGoodResult(remove(mOwner, changing));
+}
+
+void TestPartition::typeChangeSchema()
+{
+ bool currentValidateSchemas = jsondbSettings->validateSchemas();
+ jsondbSettings->setValidateSchemas(true);
+ QJsonObject schemaDef(readJsonFile(":/json-validation/required-schema.json").toObject());
+ JsonDbObject schema;
+ schema.insert(JsonDbString::kTypeStr, QLatin1String("not.a._schemaType"));
+ schema.insert(JsonDbString::kSchemaStr, schemaDef);
+ schema.insert(JsonDbString::kNameStr, QLatin1String("TestObject"));
+ verifyGoodResult(create(mOwner, schema));
+
+ // test object which is missing the required "important" field
+ JsonDbObject test;
+ test.insert(JsonDbString::kTypeStr, QLatin1String("TestObject"));
+ verifyGoodResult(create(mOwner, test));
+
+ // change the object into a schema and try the invalid update
+ schema.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr);
+ verifyGoodResult(update(mOwner, schema));
+
+ test.insert(QLatin1String("notimportant"), QLatin1String("foo"));
+ JsonDbWriteResult result = update(mOwner, test);
+ verifyErrorResult(result);
+ QCOMPARE(result.code, JsonDbError::FailedSchemaValidation);
+ verifyGoodResult(remove(mOwner, test));
+
+ // change it back into a non-schema and make sure the update goes through
+ schema.insert(JsonDbString::kTypeStr, QLatin1String("not.a._schemaType"));
+ verifyGoodResult(update(mOwner, schema));
+
+ test.remove(JsonDbString::kDeletedStr);
+ verifyGoodResult(update(mOwner, test));
+
+ verifyGoodResult(remove(mOwner, test));
+ verifyGoodResult(remove(mOwner, schema));
+ jsondbSettings->setValidateSchemas(currentValidateSchemas);
}
-QTEST_MAIN(TestJsonDb)
-#include "testjsondb.moc"
+QTEST_MAIN(TestPartition)
+#include "testpartition.moc"
diff --git a/tests/auto/qjsondbflushrequest/qjsondbflushrequest.pro b/tests/auto/qjsondbflushrequest/qjsondbflushrequest.pro
new file mode 100644
index 00000000..f144050e
--- /dev/null
+++ b/tests/auto/qjsondbflushrequest/qjsondbflushrequest.pro
@@ -0,0 +1,13 @@
+TARGET = tst_qjsondbflushrequest
+
+QT = network testlib jsondb-private
+CONFIG -= app_bundle
+CONFIG += testcase
+
+include($$PWD/../../shared/shared.pri)
+
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+RESOURCES += ../partition/partition.qrc
+
+SOURCES += testqjsondbflushrequest.cpp
diff --git a/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp b/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp
new file mode 100644
index 00000000..929e0420
--- /dev/null
+++ b/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/
+ **
+ ** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+ ** GNU Lesser General Public License Usage
+ ** This file may be used under the terms of the GNU Lesser General Public
+ ** License version 2.1 as published by the Free Software Foundation and
+ ** appearing in the file LICENSE.LGPL included in the packaging of this
+ ** file. Please review the following information to ensure the GNU Lesser
+ ** General Public License version 2.1 requirements will be met:
+ ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ **
+ ** In addition, as a special exception, Nokia gives you certain additional
+ ** rights. These rights are described in the Nokia Qt LGPL Exception
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ **
+ ** GNU General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU General
+ ** Public License version 3.0 as published by the Free Software Foundation
+ ** and appearing in the file LICENSE.GPL included in the packaging of this
+ ** file. Please review the following information to ensure the GNU General
+ ** Public License version 3.0 requirements will be met:
+ ** http://www.gnu.org/copyleft/gpl.html.
+ **
+ ** Other Usage
+ ** Alternatively, this file may be used in accordance with the terms and
+ ** conditions contained in a signed written agreement between you and Nokia.
+ **
+ **
+ **
+ **
+ **
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include "qjsondbconnection.h"
+#include "testhelper.h"
+
+#include <QTest>
+
+QT_USE_NAMESPACE_JSONDB
+
+static const char dbfileprefix[] = "test-jsondb-flushrequest";
+
+class TestQJsonDbFlushRequest: public TestHelper
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+};
+
+void TestQJsonDbFlushRequest::initTestCase()
+{
+ removeDbFiles();
+
+ QStringList arg_list = QStringList() << "-validate-schemas";
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
+}
+
+void TestQJsonDbFlushRequest::cleanupTestCase()
+{
+ removeDbFiles();
+ stopDaemon();
+}
+
+void TestQJsonDbFlushRequest::init()
+{
+ connectToServer();
+}
+
+void TestQJsonDbFlushRequest::cleanup()
+{
+ disconnectFromServer();
+}
+
+QTEST_MAIN(TestQJsonDbFlushRequest)
+
+#include "testqjsondbflushrequest.moc"
diff --git a/tests/auto/qjsondbrequest/partitions.json b/tests/auto/qjsondbrequest/partitions.json
new file mode 100644
index 00000000..56139e6a
--- /dev/null
+++ b/tests/auto/qjsondbrequest/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.qt-project.shared", "default" : true }
+]
diff --git a/tests/auto/qjsondbrequest/qjsondbrequest.pro b/tests/auto/qjsondbrequest/qjsondbrequest.pro
new file mode 100644
index 00000000..9ac6f240
--- /dev/null
+++ b/tests/auto/qjsondbrequest/qjsondbrequest.pro
@@ -0,0 +1,17 @@
+TARGET = tst_qjsondbrequest
+
+QT = network testlib jsondb-private
+CONFIG -= app_bundle
+CONFIG += testcase
+
+include($$PWD/../../shared/shared.pri)
+
+DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+RESOURCES += ../partition/partition.qrc
+
+SOURCES += testqjsondbrequest.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/qjsondbrequest/testqjsondbrequest.cpp b/tests/auto/qjsondbrequest/testqjsondbrequest.cpp
new file mode 100644
index 00000000..2699d62d
--- /dev/null
+++ b/tests/auto/qjsondbrequest/testqjsondbrequest.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/
+ **
+ ** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+ ** GNU Lesser General Public License Usage
+ ** This file may be used under the terms of the GNU Lesser General Public
+ ** License version 2.1 as published by the Free Software Foundation and
+ ** appearing in the file LICENSE.LGPL included in the packaging of this
+ ** file. Please review the following information to ensure the GNU Lesser
+ ** General Public License version 2.1 requirements will be met:
+ ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ **
+ ** In addition, as a special exception, Nokia gives you certain additional
+ ** rights. These rights are described in the Nokia Qt LGPL Exception
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ **
+ ** GNU General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU General
+ ** Public License version 3.0 as published by the Free Software Foundation
+ ** and appearing in the file LICENSE.GPL included in the packaging of this
+ ** file. Please review the following information to ensure the GNU General
+ ** Public License version 3.0 requirements will be met:
+ ** http://www.gnu.org/copyleft/gpl.html.
+ **
+ ** Other Usage
+ ** Alternatively, this file may be used in accordance with the terms and
+ ** conditions contained in a signed written agreement between you and Nokia.
+ **
+ **
+ **
+ **
+ **
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include "qjsondbconnection.h"
+#include "qjsondbobject.h"
+#include "qjsondbreadrequest.h"
+#include "qjsondbwriterequest.h"
+#include "testhelper.h"
+
+#include <QDebug>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QProcess>
+#include <QTest>
+#include <QFile>
+
+#include <signal.h>
+
+QT_USE_NAMESPACE_JSONDB
+
+static const char dbfileprefix[] = "test-jsondb-request";
+
+class TestQJsonDbRequest: public TestHelper
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+ void modifyPartitions();
+};
+
+void TestQJsonDbRequest::initTestCase()
+{
+ removeDbFiles();
+
+ QStringList arg_list = QStringList() << "-validate-schemas";
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
+}
+
+void TestQJsonDbRequest::cleanupTestCase()
+{
+ removeDbFiles();
+ stopDaemon();
+}
+
+void TestQJsonDbRequest::init()
+{
+ connectToServer();
+}
+
+void TestQJsonDbRequest::cleanup()
+{
+ disconnectFromServer();
+}
+
+void TestQJsonDbRequest::modifyPartitions()
+{
+ // create a notification on Partitions
+ QJsonDbWatcher watcher;
+ watcher.setPartition(QLatin1String("Ephemeral"));
+ watcher.setQuery("[?_type=\"Partition\"]");
+ mConnection->addWatcher(&watcher);
+
+ // ensure that there's only one partition defined and that it's the default
+ QLatin1String defaultPartition("com.qt-project.shared");
+
+ QJsonDbReadRequest partitionQuery;
+ partitionQuery.setPartition(QLatin1String("Ephemeral"));
+ partitionQuery.setQuery(QLatin1String("[?_type=%type]"));
+ partitionQuery.bindValue(QLatin1String("type"), QLatin1String("Partition"));
+
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ QList<QJsonObject> results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("name")).toString(), defaultPartition);
+ QVERIFY(results[0].value(QLatin1String("default")).toBool());
+
+ // write a new partitions file
+ QJsonObject def1;
+ def1.insert(QLatin1String("name"), QLatin1String("com.qt-project.test1"));
+ QJsonObject def2;
+ def2.insert(QLatin1String("name"), QLatin1String("com.qt-project.test2"));
+ QJsonArray defs;
+ defs.append(def1);
+ defs.append(def2);
+
+ QFile partitionsFile(QLatin1String("partitions-test.json"));
+ partitionsFile.open(QFile::WriteOnly);
+ partitionsFile.write(QJsonDocument(defs).toJson());
+ partitionsFile.close();
+
+ // send the daemon a SIGHUP to get it to reload the partitions
+ kill(mProcess->pid(), SIGHUP);
+ waitForResponseAndNotifications(0, &watcher, 2);
+
+ // query for the new partitions
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 3);
+
+ // operate on the new partition to make sure it works
+ QJsonDbWriteRequest writeRequest;
+ QUuid testUuid = QJsonDbObject::createUuidFromString(QLatin1String("testobject1"));
+ QJsonDbObject toWrite;
+ toWrite.setUuid(testUuid);
+ toWrite.insert(QLatin1String("_type"), QLatin1String("TestObject"));
+ writeRequest.setObjects(QList<QJsonObject>() << toWrite);
+ mConnection->send(&writeRequest);
+ waitForResponse(&writeRequest);
+ QVERIFY(!mRequestErrors.contains(&writeRequest));
+
+ QJsonDbReadObjectRequest readRequest(testUuid);
+ mConnection->send(&readRequest);
+ waitForResponse(&readRequest);
+ QVERIFY(!mRequestErrors.contains(&readRequest));
+ results = readRequest.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("_type")).toString(), QLatin1String("TestObject"));
+
+ // remove the new partitions file
+ partitionsFile.remove();
+
+ // send the daemon a SIGHUP to get it to unload the partitions
+ kill(mProcess->pid(), SIGHUP);
+ waitForResponseAndNotifications(0, &watcher, 2);
+
+ // verify that we're back to just the origin partition
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("name")).toString(), defaultPartition);
+ QVERIFY(results[0].value(QLatin1String("default")).toBool());
+
+ // query one of the test partitions to ensure we get an InvalidPartition error
+ QJsonDbReadRequest failingRequest;
+ failingRequest.setPartition(QLatin1String("com.qt-project.test1"));
+ failingRequest.setQuery(QLatin1String("[*]"));
+ mConnection->send(&failingRequest);
+ waitForResponse(&failingRequest);
+
+ QVERIFY(mRequestErrors.contains(&failingRequest));
+ QCOMPARE(mRequestErrors[&failingRequest], QJsonDbRequest::InvalidPartition);
+
+ mConnection->removeWatcher(&watcher);
+}
+
+QTEST_MAIN(TestQJsonDbRequest)
+
+#include "testqjsondbrequest.moc"
diff --git a/tests/auto/qjsondbwatcher/qjsondbwatcher.pro b/tests/auto/qjsondbwatcher/qjsondbwatcher.pro
index 008fb2c5..344b9414 100644
--- a/tests/auto/qjsondbwatcher/qjsondbwatcher.pro
+++ b/tests/auto/qjsondbwatcher/qjsondbwatcher.pro
@@ -9,6 +9,6 @@ include($$PWD/../../shared/shared.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-RESOURCES += ../daemon/daemon.qrc
+RESOURCES += ../partition/partition.qrc
SOURCES += testqjsondbwatcher.cpp
diff --git a/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp b/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
index 61d4bc0c..06593c7e 100644
--- a/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
+++ b/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <QCoreApplication>
+#include <QFile>
#include <QList>
#include <QTest>
#include <QProcess>
@@ -54,19 +55,19 @@
#include "qjsondocument.h"
#include "qjsondbconnection.h"
+#include "qjsondbobject.h"
+#include "qjsondbreadrequest.h"
#include "qjsondbwatcher.h"
#include "qjsondbwriterequest.h"
#include "private/qjsondbstrings_p.h"
-#include "util.h"
+#include "testhelper.h"
QT_USE_NAMESPACE_JSONDB
// #define EXTRA_DEBUG
-// #define DONT_START_SERVER
-
-class TestQJsonDbWatcher: public QObject
+class TestQJsonDbWatcher: public TestHelper
{
Q_OBJECT
public:
@@ -76,63 +77,24 @@ class TestQJsonDbWatcher: public QObject
private slots:
void initTestCase();
void cleanupTestCase();
+ void init();
+ void cleanup();
+ void createAndRemove_data();
void createAndRemove();
+ void indexValue_data();
+ void indexValue();
void history();
void currentState();
void notificationTriggersView();
-
-public slots:
- // from mConnection
- void error(QtJsonDb::QJsonDbConnection::ErrorCode c, QString msg);
- void statusChanged(QtJsonDb::QJsonDbConnection::Status status);
- void disconnected();
-
- // from a request
- void onRequestFinished();
- void onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString);
- void onRequestStatusChanged(QtJsonDb::QJsonDbRequest::Status);
- // from a watcher
- void onWatcherNotificationsAvailable(int);
- void onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status);
- void onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString);
-private:
- void removeDbFiles();
-
-private:
-#ifndef DONT_START_SERVER
- QProcess *mProcess;
-#endif
- QJsonDbConnection *mConnection;
- QEventLoop mEventLoop;
- // what we're waiting for
- QJsonDbRequest *mRequest;
- int mNotificationCount;
- int mNotificationsReceived;
-
+ void notificationTriggersMapReduce();
+ void typeChangeEagerViewSource();
};
-#ifndef DONT_START_SERVER
static const char dbfileprefix[] = "test-jsondb-watcher";
-#endif
-
-// this should go into a new version of clientwrapper.h
-#define waitForResponseAndNotification(_request, _count) \
- { \
- mRequest = _request; \
- mNotificationCount = _count; \
- mNotificationsReceived = 0; \
- mEventLoop.exec(QEventLoop::AllEvents); \
- }
-#define waitForWatcherStatus(_watcher, _status) \
- { \
- while (_watcher.status() != _status) \
- mEventLoop.processEvents(QEventLoop::AllEvents); \
- }
TestQJsonDbWatcher::TestQJsonDbWatcher()
- : mProcess(0)
{
}
@@ -140,142 +102,138 @@ TestQJsonDbWatcher::~TestQJsonDbWatcher()
{
}
-void TestQJsonDbWatcher::error(QtJsonDb::QJsonDbConnection::ErrorCode c, QString msg)
+void TestQJsonDbWatcher::initTestCase()
{
- qCritical() << "Error from connection" << c << msg;
-}
+ removeDbFiles();
-void TestQJsonDbWatcher::statusChanged(QtJsonDb::QJsonDbConnection::Status status)
-{
- Q_UNUSED(status);
+ QStringList arg_list = QStringList() << "-validate-schemas";
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
}
-void TestQJsonDbWatcher::disconnected()
+void TestQJsonDbWatcher::cleanupTestCase()
{
- qCritical() << "Disconnected from jsondb";
+ removeDbFiles();
+ stopDaemon();
}
-// this should go into a new version of clientwrapper.h
-void TestQJsonDbWatcher::onRequestFinished()
+void TestQJsonDbWatcher::init()
{
- mRequest = 0;
- if (mNotificationCount <= mNotificationsReceived)
- mEventLoop.quit();
+ connectToServer();
}
-// this should go into a new version of clientwrapper.h
-void TestQJsonDbWatcher::onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, QString msg)
-{
- qCritical() << "onRequestError" << code << msg;
- mEventLoop.quit();
-}
-void TestQJsonDbWatcher::onRequestStatusChanged(QtJsonDb::QJsonDbRequest::Status status)
+void TestQJsonDbWatcher::cleanup()
{
- Q_UNUSED(status);
- //qDebug() << "onRequestStatusChanged" << status;
+ disconnectFromServer();
}
-// this should go into a new version of clientwrapper.h
-void TestQJsonDbWatcher::onWatcherNotificationsAvailable(int count)
+void TestQJsonDbWatcher::createAndRemove_data()
{
- mNotificationsReceived = count;
- if (mRequest == 0 && mNotificationCount <= mNotificationsReceived)
- mEventLoop.quit();
-}
+ QTest::addColumn<QString>("partition");
-void TestQJsonDbWatcher::onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status status)
-{
- Q_UNUSED(status);
+ QTest::newRow("persistent") << "";
+ QTest::newRow("ephemeral") << "Ephemeral";
}
-// this should go into a new version of clientwrapper.h
-void TestQJsonDbWatcher::onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode code, QString message)
-{
- qCritical() << "onWatcherError" << code << message;
- mEventLoop.quit();
-}
+/*
+ * Watch for an item creation
+ */
-void TestQJsonDbWatcher::removeDbFiles()
+void TestQJsonDbWatcher::createAndRemove()
{
-#ifndef DONT_START_SERVER
- QStringList lst = QDir().entryList(QStringList() << QLatin1String("*.db"));
- lst << "objectFile.bin" << "objectFile2.bin";
- foreach (const QString &fileName, lst)
- QFile::remove(fileName);
-#else
- qDebug("Don't forget to clean database files before running the test!");
-#endif
-}
+ QVERIFY(mConnection);
+ QFETCH(QString, partition);
-void TestQJsonDbWatcher::initTestCase()
-{
- removeDbFiles();
+ // create a watcher
+ QJsonDbWatcher watcher;
+ watcher.setWatchedActions(QJsonDbWatcher::All);
+ watcher.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"]"));
+ watcher.setPartition(partition);
+ mConnection->addWatcher(&watcher);
+ waitForStatus(&watcher, QJsonDbWatcher::Active);
+
+ QJsonObject item;
+ item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
+ item.insert(QLatin1String("create-test"), 22);
+
+ // Create an item
+ QJsonDbCreateRequest request(item);
+ request.setPartition(partition);
+ mConnection->send(&request);
+ waitForResponseAndNotifications(&request, &watcher, 1);
+
+ QList<QJsonObject> results = request.takeResults();
+ QCOMPARE(results.size(), 1);
+ QJsonObject info = results.at(0);
+ item.insert(JsonDbStrings::Property::uuid(), info.value(JsonDbStrings::Property::uuid()));
+ item.insert(JsonDbStrings::Property::version(), info.value(JsonDbStrings::Property::version()));
+
+ QList<QJsonDbNotification> notifications = watcher.takeNotifications();
+ QCOMPARE(notifications.size(), 1);
+
+ // remove the object
+ item.remove(QLatin1String("create-test"));
+ QJsonDbRemoveRequest remove(item);
+ remove.setPartition(partition);
+ mConnection->send(&remove);
+ waitForResponseAndNotifications(&remove, &watcher, 1);
-#ifndef DONT_START_SERVER
- QStringList arg_list = (QStringList()
- << "-validate-schemas");
- arg_list << "-base-name";
- arg_list << QString::fromLatin1(dbfileprefix);
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, QString("testjsondb_%1").arg(getpid()), arg_list);
-#endif
- mConnection = new QJsonDbConnection(this);
- connect(mConnection, SIGNAL(disconnected()), this, SLOT(disconnected()));
- connect(mConnection, SIGNAL(statusChanged(QtJsonDb::QJsonDbConnection::Status)),
- this, SLOT(statusChanged(QtJsonDb::QJsonDbConnection::Status)));
+ notifications = watcher.takeNotifications();
+ QCOMPARE(notifications.size(), 1);
+ QJsonDbNotification n = notifications[0];
+ QJsonObject o = n.object();
- connect(mConnection, SIGNAL(error(QtJsonDb::QJsonDbConnection::ErrorCode,QString)),
- this, SLOT(error(QtJsonDb::QJsonDbConnection::ErrorCode,QString)));
+ // make sure we got notified on the right object
+ QCOMPARE(o.value(JsonDbStrings::Property::uuid()), info.value(JsonDbStrings::Property::uuid()));
+ QCOMPARE(o.value(QLatin1String("create-test")).toDouble(), 22.);
- mConnection->connectToServer();
+ // we do now expect a tombstone
+ QVERIFY(o.contains(JsonDbStrings::Property::deleted()));
+ mConnection->removeWatcher(&watcher);
}
-void TestQJsonDbWatcher::cleanupTestCase()
+void TestQJsonDbWatcher::indexValue_data()
{
- if (mConnection) {
- delete mConnection;
- mConnection = NULL;
- }
+ QTest::addColumn<QString>("partition");
-#ifndef DONT_START_SERVER
- if (mProcess) {
- mProcess->close();
- delete mProcess;
- }
- removeDbFiles();
-#endif
+ QTest::newRow("persistent") << "";
+ QTest::newRow("ephemeral") << "Ephemeral";
}
-/*
- * Watch for an item creation
- */
-
-void TestQJsonDbWatcher::createAndRemove()
+void TestQJsonDbWatcher::indexValue()
{
QVERIFY(mConnection);
+ QFETCH(QString, partition);
+
+ // create an index
+ QJsonObject index;
+ index.insert(JsonDbStrings::Property::type(), QLatin1String("Index"));
+ index.insert(QLatin1String("name"), QLatin1String("create-test"));
+ index.insert(QLatin1String("propertyName"), QLatin1String("create-test"));
+ index.insert(QLatin1String("propertyType"), QLatin1String("string"));
+ index.insert(QLatin1String("objectType"), QLatin1String("com.test.qjsondbwatcher-test"));
+ QJsonDbCreateRequest create(index);
+ mConnection->send(&create);
+ waitForResponse(&create);
+ QList<QJsonObject> toDelete = create.takeResults();
// create a watcher
QJsonDbWatcher watcher;
watcher.setWatchedActions(QJsonDbWatcher::All);
- watcher.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"]"));
- connect(&watcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(onWatcherNotificationsAvailable(int)));
- connect(&watcher, SIGNAL(statusChanged(QtJsonDb::QJsonDbWatcher::Status)),
- this, SLOT(onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status)));
- connect(&watcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)), this, SLOT(onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
+ watcher.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"][/create-test]"));
+ watcher.setPartition(partition);
mConnection->addWatcher(&watcher);
+ waitForStatus(&watcher, QJsonDbWatcher::Active);
QJsonObject item;
item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
- item.insert("create-test", 22);
+ item.insert(QLatin1String("create-test"), 22);
// Create an item
QJsonDbCreateRequest request(item);
- connect(&request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(&request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
+ request.setPartition(partition);
mConnection->send(&request);
- waitForResponseAndNotification(&request, 1);
+ waitForResponseAndNotifications(&request, &watcher, 1);
QList<QJsonObject> results = request.takeResults();
QCOMPARE(results.size(), 1);
@@ -285,21 +243,34 @@ void TestQJsonDbWatcher::createAndRemove()
QList<QJsonDbNotification> notifications = watcher.takeNotifications();
QCOMPARE(notifications.size(), 1);
+ QJsonDbNotification n = notifications[0];
+ QJsonObject o = n.object();
+ // verify _indexValue was set unless partition was Ephemeral
+ if (partition != QLatin1String("Ephemeral")) {
+ QVERIFY(o.contains(QLatin1String("_indexValue")));
+ QCOMPARE(o.value(QLatin1String("_indexValue")), item.value(QLatin1String("create-test")));
+ }
// remove the object
QJsonDbRemoveRequest remove(item);
- connect(&remove, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(&remove, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
+ remove.setPartition(partition);
mConnection->send(&remove);
- waitForResponseAndNotification(&remove, 1);
+ waitForResponseAndNotifications(&remove, &watcher, 1);
notifications = watcher.takeNotifications();
QCOMPARE(notifications.size(), 1);
- QJsonDbNotification n = notifications[0];
- QJsonObject o = n.object();
+ n = notifications[0];
+ o = n.object();
+
// make sure we got notified on the right object
QCOMPARE(o.value(JsonDbStrings::Property::uuid()), info.value(JsonDbStrings::Property::uuid()));
+ QCOMPARE(o.value(QLatin1String("create-test")).toDouble(), 22.);
+
+ // verify the index value was set unless partition was Ephemeral
+ if (partition != QLatin1String("Ephemeral")) {
+ QVERIFY(o.contains(QLatin1String("_indexValue")));
+ QCOMPARE(o.value(QLatin1String("_indexValue")), item.value(QLatin1String("create-test")));
+ }
// we do now expect a tombstone
QVERIFY(o.contains(JsonDbStrings::Property::deleted()));
@@ -311,7 +282,7 @@ void TestQJsonDbWatcher::history()
{
QVERIFY(mConnection);
- QFile dataFile(":/daemon/json/largeContactsTest.json");
+ QFile dataFile(":/partition/json/largeContactsTest.json");
QVERIFY(dataFile.exists());
dataFile.open(QIODevice::ReadOnly);
QByteArray json = dataFile.readAll();
@@ -322,21 +293,14 @@ void TestQJsonDbWatcher::history()
QJsonArray array = doc.array();
// make a request and connect it
quint32 firstStateNumber = 0;
- quint32 lastStateNumber = 0;
// pass the empty object list to make the constructor happy
QList<QJsonObject> objects;
QJsonDbCreateRequest request(objects);
- connect(&request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(&request, SIGNAL(statusChanged(QtJsonDb::QJsonDbRequest::Status)),
- this, SLOT(onRequestStatusChanged(QtJsonDb::QJsonDbRequest::Status)));
- connect(&request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
for (int i = 0; i < qMin(100, array.size()); i++) {
QJsonObject item = array.at(i).toObject();
- // why does QJsonDbCreate request require me to set the Uuid? /me thinks it's a bug
item.insert(JsonDbStrings::Property::uuid(), QUuid::createUuid().toString());
item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
objects.append(item);
@@ -345,10 +309,9 @@ void TestQJsonDbWatcher::history()
// Create the item
mConnection->send(&request);
- waitForResponseAndNotification(&request, 0);
+ waitForResponse(&request);
if (!firstStateNumber)
firstStateNumber = request.stateNumber();
- lastStateNumber = request.stateNumber();
}
QVERIFY(firstStateNumber);
@@ -356,27 +319,22 @@ void TestQJsonDbWatcher::history()
QJsonDbWatcher watcher;
watcher.setWatchedActions(QJsonDbWatcher::All);
watcher.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"]"));
- connect(&watcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(onWatcherNotificationsAvailable(int)));
- connect(&watcher, SIGNAL(statusChanged(QtJsonDb::QJsonDbWatcher::Status)),
- this, SLOT(onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status)));
- connect(&watcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)), this, SLOT(onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
// set the starting state
watcher.setInitialStateNumber(firstStateNumber-1);
mConnection->addWatcher(&watcher);
- // expecting one notification per create and one state change
- waitForResponseAndNotification(0, objects.size()+1);
- waitForWatcherStatus(watcher, QJsonDbWatcher::Active);
+ // expecting one notification per create
+ waitForResponseAndNotifications(0, &watcher, objects.size());
+ waitForStatus(&watcher, QJsonDbWatcher::Active);
QList<QJsonDbNotification> notifications = watcher.takeNotifications();
- QCOMPARE(notifications.size(), objects.size()+1);
+ QCOMPARE(notifications.size(), objects.size());
// we received one Create notification per object
- foreach (const QJsonDbNotification n, notifications.mid(0, objects.size()))
+ foreach (const QJsonDbNotification n, notifications.mid(0, objects.size())) {
QCOMPARE(n.action(), QJsonDbWatcher::Created);
- // we received one StateChanged notification
- QCOMPARE(notifications.at(objects.size()).action(), QJsonDbWatcher::StateChanged);
+ QVERIFY(n.stateNumber() >= firstStateNumber);
+ }
mConnection->removeWatcher(&watcher);
@@ -384,81 +342,77 @@ void TestQJsonDbWatcher::history()
QJsonDbWatcher watcher2;
watcher2.setWatchedActions(QJsonDbWatcher::All);
watcher2.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"]"));
- connect(&watcher2, SIGNAL(notificationsAvailable(int)),
- this, SLOT(onWatcherNotificationsAvailable(int)));
- connect(&watcher2, SIGNAL(statusChanged(QtJsonDb::QJsonDbWatcher::Status)),
- this, SLOT(onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status)));
- connect(&watcher2, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)), this, SLOT(onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
- watcher2.setInitialStateNumber(-1);
+ watcher2.setInitialStateNumber(0);
mConnection->addWatcher(&watcher2);
- waitForResponseAndNotification(0, objects.size() + 1);
- waitForWatcherStatus(watcher2, QJsonDbWatcher::Active);
+ waitForResponseAndNotifications(0, &watcher2, objects.size());
QList<QJsonDbNotification> notifications2 = watcher2.takeNotifications();
- QCOMPARE(notifications2.size(), objects.size()+1);
+ QCOMPARE(notifications2.size(), objects.size());
// we received one Create notification per object
foreach (const QJsonDbNotification n, notifications2.mid(0, objects.size()))
QCOMPARE(n.action(), QJsonDbWatcher::Created);
- // we received one StateChanged notification
- QCOMPARE(notifications2.at(objects.size()).action(), QJsonDbWatcher::StateChanged);
+ // create another one
+ {
+ QJsonObject item;
+ item.insert(JsonDbStrings::Property::uuid(), QUuid::createUuid().toString());
+ item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
+ item.insert("another one", true);
+ QJsonDbCreateRequest request(item);
+ mConnection->send(&request);
+ // wait for response from request, one create notification
+ waitForResponseAndNotifications(&request, &watcher2, 1);
+ }
mConnection->removeWatcher(&watcher2);
+
+ QJsonDbRemoveRequest remove(objects);
+ mConnection->send(&remove);
+ waitForResponse(&remove);
}
+
void TestQJsonDbWatcher::currentState()
{
QJsonDbWatcher watcher;
watcher.setWatchedActions(QJsonDbWatcher::All);
watcher.setQuery(QLatin1String("[?_type=\"com.test.qjsondbwatcher-test\"]"));
- connect(&watcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(onWatcherNotificationsAvailable(int)));
- connect(&watcher, SIGNAL(statusChanged(QtJsonDb::QJsonDbWatcher::Status)),
- this, SLOT(onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status)));
- connect(&watcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)), this, SLOT(onWatcherError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
-
- // set the starting state to -1 to get the current state
- watcher.setInitialStateNumber(static_cast<quint32>(-1));
+
+ // set the starting state to 0 to get the current state
+ watcher.setInitialStateNumber(0);
mConnection->addWatcher(&watcher);
- // expecting one notification per create and one state change
- bool stateChanged = false;
- while (!stateChanged) {
- // wait for a notification
- waitForResponseAndNotification(0, 1);
- QList<QJsonDbNotification> notifications = watcher.takeNotifications();
- foreach (const QJsonDbNotification n, notifications)
- if (n.action() == QJsonDbWatcher::StateChanged)
- stateChanged = true;
- }
+ // expecting one notification per create
+ waitForResponseAndNotifications(0, &watcher, 1, 1);
+ watcher.takeNotifications();
// now create another object
- {
- QJsonObject item;
- item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
- item.insert("create-test", 22);
+ QJsonObject item;
+ item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.qjsondbwatcher-test"));
+ item.insert("create-test", 22);
+
+ // Create an item
+ QJsonDbCreateRequest request(item);
+ mConnection->send(&request);
+ waitForResponseAndNotifications(&request, &watcher, 1);
- // Create an item
- QJsonDbCreateRequest request(item);
- connect(&request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(&request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- mConnection->send(&request);
- waitForResponseAndNotification(&request, 1);
- }
QList<QJsonDbNotification> notifications = watcher.takeNotifications();
QCOMPARE(notifications.size(), 1);
mConnection->removeWatcher(&watcher);
+
+ QJsonDbRemoveRequest remove(request.takeResults());
+ mConnection->send(&remove);
+ waitForResponse(&remove);
}
void TestQJsonDbWatcher::notificationTriggersView()
{
QVERIFY(mConnection);
- QJsonParseError error;
- QJsonArray array(readJsonFile(":/daemon/json/map-array-conversion.json", &error).array());
- QVERIFY(error.error == QJsonParseError::NoError);
+ QLatin1String query("[?_type=\"com.test.TestView\"]");
+ QJsonArray array(readJsonFile(":/partition/json/map-array-conversion.json").array());
+
QList<QJsonObject> objects;
foreach (const QJsonValue v, array)
objects.append(v.toObject());
@@ -468,32 +422,215 @@ void TestQJsonDbWatcher::notificationTriggersView()
// create the objects
QJsonDbCreateRequest request(objects);
- connect(&request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
- connect(&request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
mConnection->send(&request);
- waitForResponseAndNotification(&request, 0);
+ waitForResponse(&request);
+ QList<QJsonObject> toDelete;
+ foreach (const QJsonObject result, request.takeResults())
+ toDelete.prepend(result);
+
+ {
+ QJsonDbReadRequest read(query);
+ mConnection->send(&read);
+ waitForResponse(&read);
+ QList<QJsonObject> objects = read.takeResults();
+ int numObjects = objects.size();
+ QCOMPARE(numObjects, 1);
+ }
+
+ // create a watcher
+ QJsonDbWatcher watcher;
+ watcher.setWatchedActions(QJsonDbWatcher::All);
+ watcher.setQuery(QLatin1String(query));
+ mConnection->addWatcher(&watcher);
+ waitForStatus(&watcher, QJsonDbWatcher::Active);
+
+ {
+ QJsonObject item;
+ item.insert(JsonDbStrings::Property::type(), QLatin1String("com.test.Test"));
+ QJsonDbCreateRequest request(item);
+ mConnection->send(&request);
+ waitForResponseAndNotifications(&request, &watcher, 1);
+
+ QList<QJsonDbNotification> notifications = watcher.takeNotifications();
+ QCOMPARE(notifications.size(), 1);
+ QJsonDbNotification n = notifications[0];
+ QJsonObject o = n.object();
+ // make sure we got notified on the right object
+ //QCOMPARE(o.value(JsonDbStrings::Property::uuid()), info.value(JsonDbStrings::Property::uuid()));
+ }
+ mConnection->removeWatcher(&watcher);
+
+ foreach (const QJsonObject &object, request.takeResults())
+ toDelete.prepend(object);
+
+ QJsonDbRemoveRequest remove(toDelete);
+ mConnection->send(&remove);
+ waitForResponse(&remove);
+}
+
+void TestQJsonDbWatcher::notificationTriggersMapReduce()
+{
+ QVERIFY(mConnection);
+
+ QJsonParseError error;
+ QJsonArray array(readJsonFile(":/partition/json/map-reduce.json", &error).array());
+ QVERIFY(error.error == QJsonParseError::NoError);
+ QList<QJsonObject> objects;
+ foreach (const QJsonValue v, array)
+ objects.append(v.toObject());
+
+ // create the objects
+ QJsonDbCreateRequest request(objects);
+ mConnection->send(&request);
+ waitForResponse(&request);
+ QList<QJsonObject> toDelete;
+ foreach (const QJsonObject result, request.takeResults())
+ toDelete.prepend(result);
+
+ QString query = QLatin1String("[?_type=\"PhoneCount\"]");
+
+ {
+ QJsonDbReadRequest read(query);
+ mConnection->send(&read);
+ waitForResponse(&read);
+ int numObjects = read.takeResults().size();
+ QCOMPARE(numObjects, 5);
+ }
+
+ {
+ const char json[] = "{\"_type\":\"Contact\",\"displayName\":\"Will Robinson\",\"phoneNumbers\":[{\"type\":\"satellite\",\"number\":\"+614159\"}]}";
+ QJsonObject object(QJsonDocument::fromJson(json).object());
+
+ QJsonDbCreateRequest write(object);
+ mConnection->send(&write);
+ waitForResponse(&write);
+ }
+
+ // create a watcher
+ QJsonDbWatcher watcher;
+ watcher.setWatchedActions(QJsonDbWatcher::All);
+ watcher.setQuery(query);
+ mConnection->addWatcher(&watcher);
+
+ waitForResponseAndNotifications(0, &watcher, 1);
+ int numNotifications = watcher.takeNotifications().size();
+ QCOMPARE(numNotifications, 1);
+
+ {
+ QJsonDbReadRequest read(query);
+ mConnection->send(&read);
+ waitForResponse(&read);
+
+ QList<QJsonObject> results = read.takeResults();
+ QCOMPARE(results.size(), 6);
+ }
+
+ // now write another one
+ {
+ const char json[] = "{\"_type\":\"Contact\",\"displayName\":\"Jeffrey Goines\",\"phoneNumbers\":[{\"type\":\"satellite\",\"number\":\"+2718281828\"}]}";
+ QJsonObject object(QJsonDocument::fromJson(json).object());
+
+ QJsonDbCreateRequest write(object);
+ mConnection->send(&write);
+ waitForResponseAndNotifications(&write, &watcher, 1);
+
+ int numNotifications = watcher.takeNotifications().size();
+ QCOMPARE(numNotifications, 1);
+ }
+
+ mConnection->removeWatcher(&watcher);
+ {
+ QJsonDbReadRequest read("[?_type=\"Contact\"]");
+ mConnection->send(&read);
+ waitForResponse(&read);
+ QJsonDbRemoveRequest remove(read.takeResults());
+ mConnection->send(&remove);
+ waitForResponse(&remove);
+ }
+
+ QJsonDbRemoveRequest remove(toDelete);
+ mConnection->send(&remove);
+ waitForResponse(&remove);
+}
+
+void TestQJsonDbWatcher::typeChangeEagerViewSource()
+{
+ QVERIFY(mConnection);
+
+ QJsonParseError error;
+ QJsonArray array(readJsonFile(":/partition/json/map-reduce.json", &error).array());
+ QVERIFY(error.error == QJsonParseError::NoError);
+ QList<QJsonObject> objects;
+ foreach (const QJsonValue v, array)
+ objects.append(v.toObject());
+
+ // create the objects
+ QJsonDbCreateRequest request(objects);
+ mConnection->send(&request);
+ waitForResponse(&request);
+ QList<QJsonObject> toDelete;
+ foreach (const QJsonObject result, request.takeResults())
+ toDelete.prepend(result);
+
+ QString query = QLatin1String("[?_type=\"PhoneCount\"]");
+
+ // verify that we get what we expect
+ {
+ QJsonDbReadRequest read(query);
+ mConnection->send(&read);
+ waitForResponse(&read);
+ int numObjects = read.takeResults().size();
+ QCOMPARE(numObjects, 5);
+ }
+
+ // create an object that's not of the source type of the view
+ const char json[] = "{\"_type\":\"not.a.Contact\",\"displayName\":\"Will Robinson\",\"phoneNumbers\":[{\"type\":\"satellite\",\"number\":\"+614159\"}]}";
+ QJsonDbObject object(QJsonDocument::fromJson(json).object());
+ object.setUuid(QJsonDbObject::createUuidFromString("typeChangeEagerViewSource"));
+
+ QJsonDbWriteRequest write;
+ write.setObjects(QList<QJsonObject>() << object);
+ mConnection->send(&write);
+ waitForResponse(&write);
+
+ // verify that the view didn't change
+ {
+ QJsonDbReadRequest read(query);
+ mConnection->send(&read);
+ waitForResponse(&read);
+ int numObjects = read.takeResults().size();
+ QCOMPARE(numObjects, 5);
+ }
// create a watcher
QJsonDbWatcher watcher;
watcher.setWatchedActions(QJsonDbWatcher::All);
- watcher.setQuery(QLatin1String("[?_type=\"com.test.TestView\"]"));
- connect(&watcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(onWatcherNotificationsAvailable(int)));
- connect(&watcher, SIGNAL(statusChanged(QtJsonDb::QJsonDbWatcher::Status)),
- this, SLOT(onWatcherStatusChanged(QtJsonDb::QJsonDbWatcher::Status)));
- connect(&watcher, SIGNAL(error(int,QString)), this, SLOT(onWatcherError(int,QString)));
+ watcher.setQuery(query);
mConnection->addWatcher(&watcher);
- waitForResponseAndNotification(0, 1);
+ waitForStatus(&watcher, QJsonDbWatcher::Active);
+ // change the object so that it's now a source type of the view
+ object.insert(QLatin1String("_type"), QLatin1String("Contact"));
+ write.setObjects(QList<QJsonObject>() << object);
+ mConnection->send(&write);
+ waitForResponseAndNotifications(&write, &watcher, 1);
QList<QJsonDbNotification> notifications = watcher.takeNotifications();
- QCOMPARE(notifications.size(), 1);
- QJsonDbNotification n = notifications[0];
- QJsonObject o = n.object();
- // make sure we got notified on the right object
- //QCOMPARE(o.value(JsonDbStrings::Property::uuid()), info.value(JsonDbStrings::Property::uuid()));
+ QCOMPARE(notifications.count(), 1);
+ QCOMPARE(notifications[0].action(), QJsonDbWatcher::Created);
+
+ // change it back, which should result in a remove notification
+ object.insert(QLatin1String("_type"), QLatin1String("not.a.Contact"));
+ write.setObjects(QList<QJsonObject>() << object);
+ mConnection->send(&write);
+ waitForResponseAndNotifications(&write, &watcher, 1);
+ notifications = watcher.takeNotifications();
+ QCOMPARE(notifications.count(), 1);
+ QCOMPARE(notifications[0].action(), QJsonDbWatcher::Removed);
mConnection->removeWatcher(&watcher);
+ QJsonDbRemoveRequest remove(toDelete);
+ mConnection->send(&remove);
+ waitForResponse(&remove);
}
QTEST_MAIN(TestQJsonDbWatcher)
diff --git a/tests/auto/queries/queries.pro b/tests/auto/queries/queries.pro
index 620406bc..7a3a89ac 100644
--- a/tests/auto/queries/queries.pro
+++ b/tests/auto/queries/queries.pro
@@ -1,16 +1,13 @@
TARGET = tst_queries
-QT = network qml testlib
+QT = network qml testlib jsondbpartition
CONFIG -= app_bundle
CONFIG += testcase
-INCLUDEPATH += $$PWD/../../../src/daemon
LIBS += -L$$QT.jsondb.libs
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-include($$PWD/../../../src/daemon/daemon.pri)
-
RESOURCES = queries.qrc
SOURCES += \
diff --git a/tests/auto/queries/testjsondbqueries.cpp b/tests/auto/queries/testjsondbqueries.cpp
index d5218b6d..3e9837c8 100644
--- a/tests/auto/queries/testjsondbqueries.cpp
+++ b/tests/auto/queries/testjsondbqueries.cpp
@@ -48,12 +48,11 @@
#include <QTime>
#include <QUuid>
-#include "json.h"
#include "jsondbowner.h"
#include "jsondbpartition.h"
#include "jsondbquery.h"
-#include "jsondb-strings.h"
-#include "jsondb-error.h"
+#include "jsondbstrings.h"
+#include "jsondberrors.h"
#include "../../shared/util.h"
@@ -71,7 +70,7 @@
__result.error.toObject().value("message").toString().toLocal8Bit()); \
}
-QT_USE_NAMESPACE_JSONDB
+QT_USE_NAMESPACE_JSONDB_PARTITION
class TestJsonDbQueries: public QObject
{
@@ -100,6 +99,7 @@ private slots:
void querySortedByIndexName();
void queryContains();
void queryInvalid();
+ void queryRegExp();
private:
void removeDbFiles();
@@ -199,7 +199,8 @@ void TestJsonDbQueries::removeDbFiles()
JsonDbQueryResult TestJsonDbQueries::find(JsonDbOwner *owner, const QString &query, const QJsonObject bindings)
{
- return mJsonDbPartition->queryObjects(owner, JsonDbQuery::parse(query, bindings));
+ QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query, bindings));
+ return mJsonDbPartition->queryObjects(owner, parsedQuery.data());
}
void TestJsonDbQueries::initTestCase()
@@ -216,15 +217,7 @@ void TestJsonDbQueries::initTestCase()
mJsonDbPartition = new JsonDbPartition(kFilename, QStringLiteral("com.example.JsonDbTestQueries"), mOwner, this);
mJsonDbPartition->open();
- QFile contactsFile(":/queries/dataset.json");
- QVERIFY2(contactsFile.exists(), "Err: dataset.json doesn't exist!");
-
- contactsFile.open(QIODevice::ReadOnly);
- QByteArray json = contactsFile.readAll();
- JsonReader parser;
- bool ok = parser.parse(json);
- QVERIFY2(ok, parser.errorString().toAscii());
- QVariantList contactList = parser.result().toList();
+ QVariantList contactList = readJsonFile(":/queries/dataset.json").toArray().toVariantList();
foreach (QVariant v, contactList) {
JsonDbObject object(QJsonObject::fromVariantMap(v.toMap()));
QString type = object.value("_type").toString();
@@ -381,14 +374,20 @@ void TestJsonDbQueries::queryQuotedProperties()
QVERIFY(confirmEachObject(queryResult.data, CheckObjectFieldEqualTo<QString>("_type", "dragon")));
queryResult = find(mOwner, QLatin1String("[?_type = \"dragon\"][?\"eye-color\" = \"red\"][= \"eye-color\"]"));
- // single values are returned in queryResult.values
- QCOMPARE(queryResult.values.size(), mDataStats["num-red-eyes"].toInt());
- QCOMPARE(queryResult.values.at(0).toString(), QString("red"));
-
- queryResult = find(mOwner, QLatin1String("[?\"eye-color\" = \"red\"][= [\"eye-color\", age ]]"));
- // array values are returned in queryResult.values
- QCOMPARE(queryResult.values.size(), mDataStats["num-red-eyes"].toInt());
- QCOMPARE(queryResult.values.at(0).toArray().at(0).toString(), QString("red"));
+ // no longer supported
+ QCOMPARE(queryResult.data.size(), 0);
+ QVERIFY(queryResult.error.isObject());
+ QVERIFY(queryResult.error.toObject().contains(QLatin1String("code")));
+ QCOMPARE((int)queryResult.error.toObject().value(QLatin1String("code")).toDouble(),
+ (int)JsonDbError::MissingQuery);
+
+ queryResult = find(mOwner, QLatin1String("[?\"eye-color\" = \"red\"][= [\"eye-color\", age ]]"));
+ // no longer supported
+ QCOMPARE(queryResult.data.size(), 0);
+ QVERIFY(queryResult.error.isObject());
+ QVERIFY(queryResult.error.toObject().contains(QLatin1String("code")));
+ QCOMPARE((int)queryResult.error.toObject().value(QLatin1String("code")).toDouble(),
+ (int)JsonDbError::MissingQuery);
queryResult = find(mOwner, QLatin1String("[?_type=\"dragon\"][/_type][?\"eye-color\" = \"red\"][= {\"color-of-eyes\": \"eye-color\" }]"));
// object values are returned in queryResult.data
@@ -455,5 +454,18 @@ void TestJsonDbQueries::queryInvalid()
QVERIFY(!queryResult.error.isNull());
}
+void TestJsonDbQueries::queryRegExp()
+{
+ JsonDbQueryResult queryResult = find(mOwner, QLatin1String("[?_type = \"dog\"][?name =~ \"/*ov*/w\" ]"));
+ QVERIFY(queryResult.error.isNull());
+ QCOMPARE(queryResult.data.count(), 1);
+
+ QJsonObject bindings;
+ bindings.insert(QLatin1String("regexp"), QLatin1String("/*ov*/w"));
+ queryResult = find(mOwner, QLatin1String("[?_type = \"dog\"][?name =~ %regexp ]"), bindings);
+ QVERIFY(queryResult.error.isNull());
+ QCOMPARE(queryResult.data.count(), 1);
+}
+
QTEST_MAIN(TestJsonDbQueries)
#include "testjsondbqueries.moc"
diff --git a/tests/auto/tests.xml b/tests/auto/tests.xml
index 56c2a6bf..fc9061e6 100644
--- a/tests/auto/tests.xml
+++ b/tests/auto/tests.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<testdefinition version="0.1">
<suite domain="Functional" name="jsondb-autotests" timeout="2000">
- <set description=" Simple JSON DB auto tests " feature="JSONDB" level="System" name="jsondb-autotests" type="Functional" timeout="2000">
+ <set description=" Simple JSON DB auto tests " feature="JSONDB" level="Auto" name="jsondb-autotests" type="Functional" timeout="2000">
<case name="tst_client" requirement="BAT,CST" component="qt5jsondb" timeout="100">
<description>Client library tests: C++ APIs testcases.</description>
<step>cd /usr/lib/qt5jsondb-tests/auto/client;date &amp;&amp; ./tst_client&amp;&amp; date</step>
</case>
- <case name="tst_daemon" requirement="BAT" component="qt5jsondb" timeout="2000">
- <description> JsonDb daemon tests: This testcase tests server behavior.</description>
- <step>cd /usr/lib/qt5jsondb-tests/auto/daemon;date &amp;&amp; ./tst_daemon &amp;&amp; date</step>
+ <case name="tst_partition" requirement="BAT" component="qt5jsondb" timeout="2000">
+ <description> JsonDb partition tests: This testcase tests server behavior.</description>
+ <step>cd /usr/lib/qt5jsondb-tests/auto/partition;date &amp;&amp; ./tst_partition &amp;&amp; date</step>
</case>
<case name="tst_accesscontrol" requirement="BAT,CST" type="Security" component="qt5jsondb" timeout="600">
<description> JsonDb security tests</description>
@@ -42,6 +42,18 @@
<description>Btree tests</description>
<step>cd /usr/lib/qt5jsondb-tests/auto/qbtree;date &amp;&amp; ./tst_qbtree&amp;&amp; date</step>
</case>
+ <case name="tst_qjsondbrequest" component="qt5jsondb" timeout="600">
+ <description>QJsonDbRequest Class tests</description>
+ <step>cd /usr/lib/qt5jsondb-tests/auto/qjsondbrequest;date &amp;&amp; ./tst_qjsondbrequest &amp;&amp; date</step>
+ </case>
+ <case name="tst_qjsondbflushrequest" component="qt5jsondb" timeout="600">
+ <description>QJsonDbFlushRequest Class tests</description>
+ <step>cd /usr/lib/qt5jsondb-tests/auto/qjsondbflushrequest;date &amp;&amp; ./tst_qjsondbflushrequest &amp;&amp; date</step>
+ </case>
+ <case name="tst_qjsondbwatcher" component="qt5jsondb" timeout="600">
+ <description>QJsonDbWatcher Class tests</description>
+ <step>cd /usr/lib/qt5jsondb-tests/auto/qjsondbwatcher;date &amp;&amp; ./tst_qjsondbwatcher &amp;&amp; date</step>
+ </case>
</set>
</suite>
</testdefinition>