From 678c03f5cfecc6448af6474c52c116644f9f54f9 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 19 Nov 2009 14:37:15 +1000 Subject: Remove useless, untested methods from QmlGraphicsTextEdit I don't think we'll need to expose QTextCursor for QML. --- .../graphicsitems/qmlgraphicstextedit.cpp | 52 ---------------------- .../graphicsitems/qmlgraphicstextedit_p.h | 7 --- 2 files changed, 59 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index b691304..a6b5ae0 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -686,29 +686,6 @@ Qt::TextInteractionFlags QmlGraphicsTextEdit::textInteractionFlags() const } /*! - Returns the cursor for the point at the given \a pos on the - text edit. -*/ -QTextCursor QmlGraphicsTextEdit::cursorForPosition(const QPoint &pos) const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->cursorForPosition(pos); -} - -/*! - Returns the rectangle where the given text \a cursor is rendered - within the text edit. -*/ -QRect QmlGraphicsTextEdit::cursorRect(const QTextCursor &cursor) const -{ - Q_D(const QmlGraphicsTextEdit); - if (cursor.isNull()) - return QRect(); - - return d->control->cursorRect(cursor).toRect(); -} - -/*! Returns the rectangle where the text cursor is rendered within the text edit. */ @@ -720,35 +697,6 @@ QRect QmlGraphicsTextEdit::cursorRect() const /*! - Sets the text cursor for the text edit to the given \a cursor. -*/ -void QmlGraphicsTextEdit::setTextCursor(const QTextCursor &cursor) -{ - Q_D(QmlGraphicsTextEdit); - d->control->setTextCursor(cursor); -} - -/*! - Returns the text cursor for the text edit. -*/ -QTextCursor QmlGraphicsTextEdit::textCursor() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor(); -} - -/*! -Moves the cursor by performing the given \a operation. - -If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys. -*/ -void QmlGraphicsTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) -{ - Q_D(QmlGraphicsTextEdit); - d->control->moveCursor(operation, mode); -} - -/*! \overload Handles the given \a event. */ diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit_p.h b/src/declarative/graphicsitems/qmlgraphicstextedit_p.h index fa95373..1ddfa6b 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit_p.h +++ b/src/declarative/graphicsitems/qmlgraphicstextedit_p.h @@ -169,15 +169,8 @@ public: void setTextInteractionFlags(Qt::TextInteractionFlags flags); Qt::TextInteractionFlags textInteractionFlags() const; - QTextCursor cursorForPosition(const QPoint &pos) const; - QRect cursorRect(const QTextCursor &cursor) const; QRect cursorRect() const; - void setTextCursor(const QTextCursor &cursor); - QTextCursor textCursor() const; - - void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); - QVariant inputMethodQuery(Qt::InputMethodQuery property) const; Q_SIGNALS: -- cgit v0.12 From 3e52973f552391a5159b27d6252a81f6a1d52d8c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 19 Nov 2009 15:28:48 +1000 Subject: Extend tests for TextInput --- .../qmlgraphicstextinput/data/masks.qml | 7 ++++ .../qmlgraphicstextinput/data/maxLength.qml | 7 ++++ .../tst_qmlgraphicstextinput.cpp | 44 +++++++++++++++++----- 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicstextinput/data/masks.qml create mode 100644 tests/auto/declarative/qmlgraphicstextinput/data/maxLength.qml diff --git a/tests/auto/declarative/qmlgraphicstextinput/data/masks.qml b/tests/auto/declarative/qmlgraphicstextinput/data/masks.qml new file mode 100644 index 0000000..08a857c --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstextinput/data/masks.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +TextInput{ + focus: true + objectName: "myInput" + inputMask: "HHHHhhhh; " +} diff --git a/tests/auto/declarative/qmlgraphicstextinput/data/maxLength.qml b/tests/auto/declarative/qmlgraphicstextinput/data/maxLength.qml new file mode 100644 index 0000000..7cbeadd --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstextinput/data/maxLength.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +TextInput{ + focus: true + objectName: "myInput" + maximumLength: 10 +} diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index d84623f..0eba11b 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -328,27 +328,53 @@ void tst_qmlgraphicstextinput::selection() void tst_qmlgraphicstextinput::maxLength() { - QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; - QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); + //QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; + QmlView *canvas = createView(SRCDIR "/data/maxLength.qml"); + canvas->execute(); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->root() != 0); + QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->root()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->text().isEmpty()); + QVERIFY(textinputObject->maxLength() == 10); foreach(const QString &str, standard){ QVERIFY(textinputObject->text().length() <= 10); textinputObject->setText(str); QVERIFY(textinputObject->text().length() <= 10); } - //TODO: Simulated keypress input adding 11 chars at a time + + textinputObject->setText(""); + QTRY_VERIFY(textinputObject->hasFocus() == true); + for(int i=0; i<20; i++){ + QCOMPARE(textinputObject->text().length(), qMin(i,10)); + //simulateKey(canvas, Qt::Key_A); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + } } void tst_qmlgraphicstextinput::masks() { - QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; - QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); + //Not a comprehensive test of the possible masks, that's done elsewhere (QLineEdit) + //QString componentStr = "import Qt 4.6\nTextInput { inputMask: 'HHHHhhhh'; }"; + QmlView *canvas = createView(SRCDIR "/data/masks.qml"); + canvas->execute(); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->root() != 0); + QmlGraphicsTextInput *textinputObject = qobject_cast(canvas->root()); QVERIFY(textinputObject != 0); - - //TODO: Me + QTRY_VERIFY(textinputObject->hasFocus() == true); + QVERIFY(textinputObject->text().length() == 0); + QCOMPARE(textinputObject->inputMask(), QString("HHHHhhhh; ")); + for(int i=0; i<10; i++){ + QCOMPARE(qMin(i,8), textinputObject->text().length()); + QCOMPARE(i>=4, textinputObject->hasAcceptableInput()); + //simulateKey(canvas, Qt::Key_A); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + } } void tst_qmlgraphicstextinput::validators() -- cgit v0.12 From 8f6453c94a9fb146b3f44f66677a3d4579b2583b Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 19 Nov 2009 15:34:04 +1000 Subject: Fix for empty query results. --- src/declarative/qml/qmlsqldatabase.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index 9e4c198..21ca145 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -107,8 +107,11 @@ public: int s = query.size(); if (s<0) { // Inefficient. - query.last(); - return query.at()+1; + if (query.last()) { + return query.at()+1; + } else { + return 0; + } } else { return s; } -- cgit v0.12 From 2b383690c17e1f0f58ad0061fda9d51ff4fe469a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 19 Nov 2009 15:34:42 +1000 Subject: Test new creation APIs. --- tests/auto/declarative/sql/data/1a-creation.js | 25 +++++++++++++++++++++++++ tests/auto/declarative/sql/data/1b-creation.js | 22 ++++++++++++++++++++++ tests/auto/declarative/sql/tst_sql.cpp | 14 ++++++++------ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/auto/declarative/sql/data/1a-creation.js create mode 100644 tests/auto/declarative/sql/data/1b-creation.js diff --git a/tests/auto/declarative/sql/data/1a-creation.js b/tests/auto/declarative/sql/data/1a-creation.js new file mode 100644 index 0000000..5ff2c73 --- /dev/null +++ b/tests/auto/declarative/sql/data/1a-creation.js @@ -0,0 +1,25 @@ +function test() { + var r=0; + + var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000, + function(db) { + r = "FAILED: should have already been created"; + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + }) + }); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (r==0) { + if (rs.rows.length==1) // created in 1-creation + r = "passed"; + else + r = "FAILED"; + } + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/1b-creation.js b/tests/auto/declarative/sql/data/1b-creation.js new file mode 100644 index 0000000..e02c7f0 --- /dev/null +++ b/tests/auto/declarative/sql/data/1b-creation.js @@ -0,0 +1,22 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-b", "", "Test B database from Qt autotests", 1000000, + function(db) { + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + }) + }); + var r; + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.length == 0) + r = "passed"; + else + r = "FAILED: got results:" + rs.rows.length + } + ); + + return r; +} + diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index cbd14ab..ceab74b 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -138,13 +138,15 @@ void tst_sql::testQml_data() QTest::addColumn("qmlextension"); // Things WebKit can't do QTest::newRow("creation") << "data/1-creation.js" << "passed" << 1 << false; + QTest::newRow("creation-a") << "data/1a-creation.js" << "passed" << 1 << false; QTest::newRow("selection") << "data/2-selection.js" << "passed" << 1 << false; - QTest::newRow("selection-bindnames") << "data/2-selection-bindnames.js" << "passed" << 1 << true; // WebKit somehow breaks named parameters - QTest::newRow("iteration-item-function") << "data/3-iteration-item-function.js" << "passed" << 1 << false; - QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 1 << true; // Some HTML5 documents say to use rows by index, others by item() function - QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 1 << true; // As with previous, WebKit doesn't give an array - QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 1 << true; // It's very inefficient to find the total number of results, here is a solution - QTest::newRow("error-a") << "data/7a-error.js" << "passed" << 1 << false; + QTest::newRow("creation-b") << "data/1b-creation.js" << "passed" << 2 << false; + QTest::newRow("selection-bindnames") << "data/2-selection-bindnames.js" << "passed" << 2 << true; // WebKit somehow breaks named parameters + QTest::newRow("iteration-item-function") << "data/3-iteration-item-function.js" << "passed" << 2 << false; + QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 2 << true; // Some HTML5 documents say to use rows by index, others by item() function + QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 2 << true; // As with previous, WebKit doesn't give an array + QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 2 << true; // It's very inefficient to find the total number of results, here is a solution + QTest::newRow("error-a") << "data/7a-error.js" << "passed" << 2 << false; } void tst_sql::validateAgainstWebkit_data() -- cgit v0.12 From 337eff4a30844d85c6344091e75acb493771237f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 19 Nov 2009 16:56:24 +1000 Subject: Remove unused constructor. --- src/declarative/graphicsitems/qmlgraphicsimagebase.cpp | 6 ------ src/declarative/graphicsitems/qmlgraphicsimagebase_p.h | 1 - 2 files changed, 7 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp index 3e86a7c..6cd1c05 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp @@ -49,12 +49,6 @@ QT_BEGIN_NAMESPACE -QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsImageBasePrivate), parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); -} - QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent) : QmlGraphicsItem(dd, parent) { diff --git a/src/declarative/graphicsitems/qmlgraphicsimagebase_p.h b/src/declarative/graphicsitems/qmlgraphicsimagebase_p.h index 8144ce0..bab93b7 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimagebase_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsimagebase_p.h @@ -59,7 +59,6 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsImageBase : public QmlGraphicsItem Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) public: - QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); ~QmlGraphicsImageBase(); enum Status { Null, Ready, Loading, Error }; Status status() const; -- cgit v0.12 From 244c5fbcf4556f4cfbf82500c4712abda3e77e9b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 19 Nov 2009 15:39:54 +1000 Subject: TextEdit ignores unused key navigation Task-number: QT-2236 --- .../graphicsitems/qmlgraphicstextedit.cpp | 24 ++-------------------- .../tst_qmlgraphicstextedit.cpp | 1 - 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index a6b5ae0..2588f7d 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -717,28 +717,7 @@ Handles the given key \a event. void QmlGraphicsTextEdit::keyPressEvent(QKeyEvent *event) { Q_D(QmlGraphicsTextEdit); - //### this causes non-standard cursor behavior in some cases. - // is it still needed? - /*QTextCursor c = textCursor(); - QTextCursor::MoveOperation op = QTextCursor::NoMove; - if (event == QKeySequence::MoveToNextChar) { - op = QTextCursor::Right; - } else if (event == QKeySequence::MoveToPreviousChar) { - op = QTextCursor::Left; - } else if (event == QKeySequence::MoveToNextWord) { - op = QTextCursor::WordRight; - } else if (event == QKeySequence::MoveToPreviousWord) { - op = QTextCursor::WordLeft; - } else if (event == QKeySequence::MoveToNextLine) { - op = QTextCursor::Down; - } else if (event == QKeySequence::MoveToPreviousLine) { - op = QTextCursor::Up; - } - - if (op != QTextCursor::NoMove && !c.movePosition(op)) - event->ignore(); - else*/ - d->control->processEvent(event, QPointF(0, 0)); + d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) QmlGraphicsPaintedItem::keyPressEvent(event); @@ -890,6 +869,7 @@ void QmlGraphicsTextEditPrivate::init() q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); control = new QTextControl(q); + control->setIgnoreUnusedNavigationEvents(true); QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateImgCache(QRectF))); diff --git a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp index 543c650..96df0a5 100644 --- a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp +++ b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp @@ -656,7 +656,6 @@ void tst_qmlgraphicstextedit::navigation() QVERIFY(input != 0); QTRY_VERIFY(input->hasFocus() == true); - QEXPECT_FAIL("", "Depends on QT-2236", Abort); simulateKey(canvas, Qt::Key_Left); QVERIFY(input->hasFocus() == false); simulateKey(canvas, Qt::Key_Right); -- cgit v0.12 From 27b0c833c18f6b98687937f427887da291184eec Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 19 Nov 2009 17:45:10 +1000 Subject: Clean-up SQL tests to not be order-dependent Add tests for new SQL APIs Remove some non-useful SQL API extensions. --- src/declarative/qml/qmlsqldatabase.cpp | 18 ++++++-- tests/auto/declarative/sql/data/1-creation.js | 15 ------ tests/auto/declarative/sql/data/1a-creation.js | 25 ---------- tests/auto/declarative/sql/data/1b-creation.js | 22 --------- .../declarative/sql/data/2-selection-bindnames.js | 16 ------- tests/auto/declarative/sql/data/2-selection.js | 19 -------- .../sql/data/3-iteration-item-function.js | 19 -------- .../auto/declarative/sql/data/4-iteration-index.js | 19 -------- .../declarative/sql/data/5-iteration-iterator.js | 19 -------- .../declarative/sql/data/6-iteration-efficient.js | 29 ------------ tests/auto/declarative/sql/data/7a-error.js | 20 -------- tests/auto/declarative/sql/data/changeversion.js | 53 ++++++++++++++++++++++ tests/auto/declarative/sql/data/creation-a.js | 18 ++++++++ tests/auto/declarative/sql/data/creation.js | 14 ++++++ tests/auto/declarative/sql/data/error-a.js | 20 ++++++++ tests/auto/declarative/sql/data/iteration.js | 28 ++++++++++++ .../declarative/sql/data/selection-bindnames.js | 26 +++++++++++ tests/auto/declarative/sql/data/selection.js | 26 +++++++++++ tests/auto/declarative/sql/tst_sql.cpp | 21 ++++----- 19 files changed, 209 insertions(+), 218 deletions(-) delete mode 100644 tests/auto/declarative/sql/data/1-creation.js delete mode 100644 tests/auto/declarative/sql/data/1a-creation.js delete mode 100644 tests/auto/declarative/sql/data/1b-creation.js delete mode 100644 tests/auto/declarative/sql/data/2-selection-bindnames.js delete mode 100644 tests/auto/declarative/sql/data/2-selection.js delete mode 100644 tests/auto/declarative/sql/data/3-iteration-item-function.js delete mode 100644 tests/auto/declarative/sql/data/4-iteration-index.js delete mode 100644 tests/auto/declarative/sql/data/5-iteration-iterator.js delete mode 100644 tests/auto/declarative/sql/data/6-iteration-efficient.js delete mode 100644 tests/auto/declarative/sql/data/7a-error.js create mode 100644 tests/auto/declarative/sql/data/changeversion.js create mode 100644 tests/auto/declarative/sql/data/creation-a.js create mode 100644 tests/auto/declarative/sql/data/creation.js create mode 100644 tests/auto/declarative/sql/data/error-a.js create mode 100644 tests/auto/declarative/sql/data/iteration.js create mode 100644 tests/auto/declarative/sql/data/selection-bindnames.js create mode 100644 tests/auto/declarative/sql/data/selection.js diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index 21ca145..dfe3982 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -148,13 +148,14 @@ public: return QScriptValue::Undeletable; } - QScriptClassPropertyIterator *newIterator(const QScriptValue &object); + //QScriptClassPropertyIterator *newIterator(const QScriptValue &object); private: QScriptString str_length; QScriptString str_forwardOnly; }; +/* class QmlSqlQueryScriptClassPropertyIterator : public QScriptClassPropertyIterator { public: @@ -223,6 +224,7 @@ QScriptClassPropertyIterator *QmlSqlQueryScriptClass::newIterator(const QScriptV { return new QmlSqlQueryScriptClassPropertyIterator(object); } +*/ enum SqlException { UNKNOWN_ERR, @@ -352,7 +354,9 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri return engine->undefinedValue(); } + bool ok = true; if (callback.isFunction()) { + ok = false; db.transaction(); callback.call(QScriptValue(), QScriptValueList() << tx); if (engine->hasUncaughtException()) { @@ -362,13 +366,17 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri db.rollback(); THROW_SQL(0,QmlEngine::tr("SQL transaction failed")); } else { - context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly); - QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat); - ini.setValue(QLatin1String("Version"), to_version); + ok = true; } } } + if (ok) { + context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly); + QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat); + ini.setValue(QLatin1String("Version"), to_version); + } + return engine->undefinedValue(); } @@ -442,6 +450,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng if (QSqlDatabase::connectionNames().contains(dbid)) { database = QSqlDatabase::database(dbid); + version = ini.value(QLatin1String("Version")).toString(); } else { created = !QFile::exists(basename+QLatin1String(".sqlite")); database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); @@ -459,6 +468,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng // Incompatible THROW_SQL(VERSION_ERR,QmlEngine::tr("SQL: database version mismatch")); } + version = ini.value("Version").toString(); } database.setDatabaseName(basename+QLatin1String(".sqlite")); } diff --git a/tests/auto/declarative/sql/data/1-creation.js b/tests/auto/declarative/sql/data/1-creation.js deleted file mode 100644 index aab9b5d..0000000 --- a/tests/auto/declarative/sql/data/1-creation.js +++ /dev/null @@ -1,15 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - // Asynchronous in WebKit, so must wait before calling test() - 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/sql/data/1a-creation.js b/tests/auto/declarative/sql/data/1a-creation.js deleted file mode 100644 index 5ff2c73..0000000 --- a/tests/auto/declarative/sql/data/1a-creation.js +++ /dev/null @@ -1,25 +0,0 @@ -function test() { - var r=0; - - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000, - function(db) { - r = "FAILED: should have already been created"; - db.transaction(function(tx){ - tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); - }) - }); - - db.transaction( - function(tx) { - var rs = tx.executeSql('SELECT * FROM Greeting'); - if (r==0) { - if (rs.rows.length==1) // created in 1-creation - r = "passed"; - else - r = "FAILED"; - } - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/1b-creation.js b/tests/auto/declarative/sql/data/1b-creation.js deleted file mode 100644 index e02c7f0..0000000 --- a/tests/auto/declarative/sql/data/1b-creation.js +++ /dev/null @@ -1,22 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB-b", "", "Test B database from Qt autotests", 1000000, - function(db) { - db.transaction(function(tx){ - tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); - }) - }); - var r; - - db.transaction( - function(tx) { - var rs = tx.executeSql('SELECT * FROM Greeting'); - if (rs.rows.length == 0) - r = "passed"; - else - r = "FAILED: got results:" + rs.rows.length - } - ); - - return r; -} - diff --git a/tests/auto/declarative/sql/data/2-selection-bindnames.js b/tests/auto/declarative/sql/data/2-selection-bindnames.js deleted file mode 100644 index 21f34db..0000000 --- a/tests/auto/declarative/sql/data/2-selection-bindnames.js +++ /dev/null @@ -1,16 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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 != 4 ) - 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/sql/data/2-selection.js b/tests/auto/declarative/sql/data/2-selection.js deleted file mode 100644 index f141d2c..0000000 --- a/tests/auto/declarative/sql/data/2-selection.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - db.transaction( - function(tx) { - tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); - 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 ) // 1 from test1, 3 from this test. - r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1] - else - r = "passed"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/3-iteration-item-function.js b/tests/auto/declarative/sql/data/3-iteration-item-function.js deleted file mode 100644 index 57c8a17..0000000 --- a/tests/auto/declarative/sql/data/3-iteration-item-function.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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;") - r = "SELECTED DATA WRONG: "+r1; - else - r = "passed"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/4-iteration-index.js b/tests/auto/declarative/sql/data/4-iteration-index.js deleted file mode 100644 index 512cf8d..0000000 --- a/tests/auto/declarative/sql/data/4-iteration-index.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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[i].salutation + ", " + rs.rows[i].salutee + ";" - if (r1 != "hello, world;hello, world;hello, world;hello, world;") - r = "SELECTED DATA WRONG: "+r1; - else - r = "passed"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/5-iteration-iterator.js b/tests/auto/declarative/sql/data/5-iteration-iterator.js deleted file mode 100644 index ae4fd34..0000000 --- a/tests/auto/declarative/sql/data/5-iteration-iterator.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - db.transaction( - function(tx) { - var rs = tx.executeSql('SELECT * FROM Greeting') - var r1="" - for(var i in rs.rows) - r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";" - if (r1 != "hello, world;hello, world;hello, world;hello, world;") - r = "SELECTED DATA WRONG: "+r1; - else - r = "passed"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/6-iteration-efficient.js b/tests/auto/declarative/sql/data/6-iteration-efficient.js deleted file mode 100644 index fe0acfc..0000000 --- a/tests/auto/declarative/sql/data/6-iteration-efficient.js +++ /dev/null @@ -1,29 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - db.transaction( - function(tx) { - var rs = tx.executeSql('SELECT * FROM Greeting'); - var r1="" - var fbefiore = rs.rows.forwardOnly; - rs.rows.forwardOnly = true; - var fafter = rs.rows.forwardOnly; - if (fbefore) - r = "forward wrong before"; - else if (!fafter) - r = "forward wrong after"; - else { - for(var i=0; rs.rows[i]; ++i) { - r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";" - } - if (r1 != "hello, world;hello, world;hello, world;hello, world;") - r = "SELECTED DATA WRONG: "+r1; - else - r = "passed"; - } - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/7a-error.js b/tests/auto/declarative/sql/data/7a-error.js deleted file mode 100644 index 65d0c03..0000000 --- a/tests/auto/declarative/sql/data/7a-error.js +++ /dev/null @@ -1,20 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "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/sql/data/changeversion.js b/tests/auto/declarative/sql/data/changeversion.js new file mode 100644 index 0000000..680d7a6 --- /dev/null +++ b/tests/auto/declarative/sql/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("databases"); // The number of databases that should have been created QTest::addColumn("qmlextension"); // Things WebKit can't do - QTest::newRow("creation") << "data/1-creation.js" << "passed" << 1 << false; - QTest::newRow("creation-a") << "data/1a-creation.js" << "passed" << 1 << false; - QTest::newRow("selection") << "data/2-selection.js" << "passed" << 1 << false; - QTest::newRow("creation-b") << "data/1b-creation.js" << "passed" << 2 << false; - QTest::newRow("selection-bindnames") << "data/2-selection-bindnames.js" << "passed" << 2 << true; // WebKit somehow breaks named parameters - QTest::newRow("iteration-item-function") << "data/3-iteration-item-function.js" << "passed" << 2 << false; - QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 2 << true; // Some HTML5 documents say to use rows by index, others by item() function - QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 2 << true; // As with previous, WebKit doesn't give an array - QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 2 << true; // It's very inefficient to find the total number of results, here is a solution - QTest::newRow("error-a") << "data/7a-error.js" << "passed" << 2 << false; + // Each test should use a newly named DB to avoid inter-test dependencies + QTest::newRow("creation") << "data/creation.js" << "passed" << 1 << false; + QTest::newRow("creation-a") << "data/creation-a.js" << "passed" << 2 << false; + QTest::newRow("changeversion") << "data/changeversion.js" << "passed" << 3 << false; + QTest::newRow("selection") << "data/selection.js" << "passed" << 4 << false; + QTest::newRow("selection-bindnames") << "data/selection-bindnames.js" << "passed" << 5 << true; + QTest::newRow("iteration") << "data/iteration.js" << "passed" << 6 << false; + QTest::newRow("error-a") << "data/error-a.js" << "passed" << 7 << false; } void tst_sql::validateAgainstWebkit_data() @@ -155,7 +154,7 @@ void tst_sql::validateAgainstWebkit_data() QTest::addColumn("result"); // The required output from the js test() function QTest::addColumn("databases"); // The number of databases that should have been created QTest::addColumn("qmlextension"); // Things WebKit can't do - QTest::newRow("creation") << "data/1-creation.js" << "passed" << 1 << false; + QTest::newRow("creation") << "data/creation.js" << "passed" << 1 << false; } void tst_sql::validateAgainstWebkit() -- cgit v0.12