diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-15 06:41:15 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-15 06:41:15 (GMT) |
commit | d8a49ccfb8308aec11cd24e823c297ef157cc4c6 (patch) | |
tree | 18fc19e36264839be851553a892480ce575da11e /tests/auto/declarative/qdeclarativesqldatabase/data | |
parent | 30a3e78a12b72ab6f67992ec2f06cd4f21a01a6c (diff) | |
parent | 62e52a19f1c7ac81a36f394e43f916c3c8933e8f (diff) | |
download | Qt-d8a49ccfb8308aec11cd24e823c297ef157cc4c6.zip Qt-d8a49ccfb8308aec11cd24e823c297ef157cc4c6.tar.gz Qt-d8a49ccfb8308aec11cd24e823c297ef157cc4c6.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tests/auto/declarative/qdeclarativesqldatabase/data')
17 files changed, 357 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/README b/tests/auto/declarative/qdeclarativesqldatabase/data/README new file mode 100644 index 0000000..7efca3a --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/README @@ -0,0 +1,3 @@ +These tests are executed in sequence - the database persist until the end of the +testing. This is done to better exercise the persistence of the database, since +that is how it is used. diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/changeversion.js b/tests/auto/declarative/qdeclarativesqldatabase/data/changeversion.js new file mode 100644 index 0000000..680d7a6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/changeversion.js @@ -0,0 +1,53 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000, + function(db) { + db.changeVersion("","1.0") + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + }) + }); + + db.transaction(function(tx){ + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + }); + + + db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000); + + if (db.version == "1.0") + db.changeVersion("1.0","2.0",function(tx) + { + tx.executeSql('CREATE TABLE Utterance(type TEXT, phrase TEXT)') + var rs = tx.executeSql('SELECT * FROM Greeting'); + for (var i=0; i<rs.rows.length; ++i) { + var type = "Greeting"; + var phrase = rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee; + if (rs.rows.item(i).salutation == "Goodbye" + || rs.rows.item(i).salutation == "Farewell" + || rs.rows.item(i).salutation == "Good-bye") type = "Valediction"; + var ins = tx.executeSql('INSERT INTO Utterance VALUES(?,?)',[type,phrase]); + } + tx.executeSql('DROP TABLE Greeting'); + }); + else + return "db.version should be 1.0, but is " + db.version; + + var db = openDatabaseSync("QmlTestDB-changeversion", "2.0", "Test database from Qt autotests", 1000000); + + db.transaction(function(tx){ + var rs = tx.executeSql('SELECT * FROM Utterance'); + r = "" + for (var i=0; i<rs.rows.length; ++i) { + r += "(" + rs.rows.item(i).type + ": " + rs.rows.item(i).phrase + ")"; + } + if (r == "(Greeting: Hello, world)(Valediction: Goodbye, cruel world)") + r = "passed" + else + r = "WRONG DATA: " + r; + }) + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/creation-a.js b/tests/auto/declarative/qdeclarativesqldatabase/data/creation-a.js new file mode 100644 index 0000000..bd7d5c5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/creation-a.js @@ -0,0 +1,18 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + r = "passed"; + }) + }); + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + r = "FAILED: should have already been created"; + }); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/creation.js b/tests/auto/declarative/qdeclarativesqldatabase/data/creation.js new file mode 100644 index 0000000..317b4c1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/creation.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-creation", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/error-a.js b/tests/auto/declarative/qdeclarativesqldatabase/data/error-a.js new file mode 100644 index 0000000..10a23f6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/error-a.js @@ -0,0 +1,20 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-error-a", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + try { + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM NotExists'); + r = "SHOULD NOT SUCCEED"; + } + ); + } catch (err) { + if (err.message == "no such table: NotExists Unable to execute statement") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/error-b.js b/tests/auto/declarative/qdeclarativesqldatabase/data/error-b.js new file mode 100644 index 0000000..4dd0ecf --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/error-b.js @@ -0,0 +1,13 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-error-b", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES("junk","junk")'); + notexist[123] = "oops" + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/error-creation.js b/tests/auto/declarative/qdeclarativesqldatabase/data/error-creation.js new file mode 100644 index 0000000..0ab2a35 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/error-creation.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + try { + var db = openDatabaseSync("QmlTestDB-creation", "2.0", "Test database from Qt autotests", 1000000); + } catch (err) { + if (err.code != SQLException.VERSION_ERR) + r = "WRONG ERROR CODE="+err.code; + else if (err.message != "SQL: database version mismatch") + r = "WRONG ERROR="+err.message; + else + r = "passed"; + } + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/error-notransaction.js b/tests/auto/declarative/qdeclarativesqldatabase/data/error-notransaction.js new file mode 100644 index 0000000..b9cc647 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/error-notransaction.js @@ -0,0 +1,15 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + try { + db.transaction(); + } catch (err) { + if (err.message == "transaction: missing callback") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/error-outsidetransaction.js b/tests/auto/declarative/qdeclarativesqldatabase/data/error-outsidetransaction.js new file mode 100644 index 0000000..a7af3bd --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/error-outsidetransaction.js @@ -0,0 +1,17 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + var v; + + try { + db.transaction(function(tx) { v = tx }); + v.executeSql("SELECT 'bad'") + } catch (err) { + if (err.message == "executeSql called outside transaction()") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/iteration-forwardonly.js b/tests/auto/declarative/qdeclarativesqldatabase/data/iteration-forwardonly.js new file mode 100644 index 0000000..45947c0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/iteration-forwardonly.js @@ -0,0 +1,29 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-iteration-forwardonly", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + rs.forwardOnly = !rs.forwardOnly + var r1="" + for(var i = 0; i < rs.rows.length; i++) + r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";" + if (r1 != "hello, world;hello, world;hello, world;hello, world;") + if (r1 != "Hello, world;Goodbye, cruel world;") + r = "SELECTED DATA WRONG: "+r1; + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/iteration.js b/tests/auto/declarative/qdeclarativesqldatabase/data/iteration.js new file mode 100644 index 0000000..c34cbbb --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/iteration.js @@ -0,0 +1,28 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-iteration", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + var r1="" + for(var i = 0; i < rs.rows.length; i++) + r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";" + if (r1 != "hello, world;hello, world;hello, world;hello, world;") + if (r1 != "Hello, world;Goodbye, cruel world;") + r = "SELECTED DATA WRONG: "+r1; + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/readonly-error.js b/tests/auto/declarative/qdeclarativesqldatabase/data/readonly-error.js new file mode 100644 index 0000000..69ec67f --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/readonly-error.js @@ -0,0 +1,27 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly-error", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + } + ); + + try { + db.readTransaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "FAILED"; + } + ); + } catch (err) { + if (err.message == "Read-only Transaction") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/readonly.js b/tests/auto/declarative/qdeclarativesqldatabase/data/readonly.js new file mode 100644 index 0000000..5ee862c --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/readonly.js @@ -0,0 +1,24 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + db.readTransaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/reopen1.js b/tests/auto/declarative/qdeclarativesqldatabase/data/reopen1.js new file mode 100644 index 0000000..c1a8157 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/reopen1.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/reopen2.js b/tests/auto/declarative/qdeclarativesqldatabase/data/reopen2.js new file mode 100644 index 0000000..4f7248f --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/reopen2.js @@ -0,0 +1,16 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/selection-bindnames.js b/tests/auto/declarative/qdeclarativesqldatabase/data/selection-bindnames.js new file mode 100644 index 0000000..9786821 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/selection-bindnames.js @@ -0,0 +1,26 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-bindnames", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'goodbye', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'there' ]); + } + ); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting WHERE salutation=:p2 AND salutee=:p1', {':p1':'world', ':p2':'hello'}); + if ( rs.rows.length != 2 ) + r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1) + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js b/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js new file mode 100644 index 0000000..f116eff --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/data/selection.js @@ -0,0 +1,26 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-selection", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + } + ); + + db.transaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + var rs = tx.executeSql('SELECT * FROM Greeting'); + if ( rs.rows.length != 4 ) + r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1] + else + r = "passed"; + } + ); + + return r; +} |