2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qtest.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqmlengine.h>
|
|
|
|
#include <QtQml/qqmlcomponent.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/private/qquicktext_p.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <private/qqmlengine_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qcryptographichash.h>
|
|
|
|
#include <QtSql/qsqldatabase.h>
|
|
|
|
#include <QtCore/qdir.h>
|
|
|
|
#include <QtCore/qfile.h>
|
2021-08-06 10:27:35 +00:00
|
|
|
#include <QtQuickTestUtils/private/qmlutils_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class tst_qqmlsqldatabase : public QQmlDataTest
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-02-16 04:43:03 +00:00
|
|
|
tst_qqmlsqldatabase()
|
2021-08-06 10:27:35 +00:00
|
|
|
: QQmlDataTest(QT_QMLTEST_DATADIR)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
qApp->setApplicationName("tst_qqmlsqldatabase");
|
2013-07-15 12:59:07 +00:00
|
|
|
qApp->setOrganizationName("QtProject");
|
|
|
|
qApp->setOrganizationDomain("www.qt-project.org");
|
2012-02-16 04:43:03 +00:00
|
|
|
engine = new QQmlEngine;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
~tst_qqmlsqldatabase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
delete engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
2021-02-23 08:46:23 +00:00
|
|
|
void initTestCase() override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void checkDatabasePath();
|
|
|
|
|
|
|
|
void testQml_data();
|
|
|
|
void testQml();
|
|
|
|
void testQml_cleanopen_data();
|
|
|
|
void testQml_cleanopen();
|
|
|
|
void totalDatabases();
|
2018-11-20 15:51:57 +00:00
|
|
|
void upgradeDatabase();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString dbDir() const;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine *engine;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void removeRecursive(const QString& dirname)
|
|
|
|
{
|
|
|
|
QDir dir(dirname);
|
|
|
|
QFileInfoList entries(dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot));
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that on() was replaced with a matcher that doesn't ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-08 17:56:03 +00:00
|
|
|
for (int i = 0; i < entries.size(); ++i)
|
2011-04-27 10:05:43 +00:00
|
|
|
if (entries[i].isDir())
|
|
|
|
removeRecursive(entries[i].filePath());
|
|
|
|
else
|
|
|
|
dir.remove(entries[i].fileName());
|
|
|
|
QDir().rmdir(dirname);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::initTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDataTest::initTestCase();
|
2011-04-27 10:05:43 +00:00
|
|
|
removeRecursive(dbDir());
|
|
|
|
QDir().mkpath(dbDir());
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::cleanupTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
2011-04-27 10:05:43 +00:00
|
|
|
removeRecursive(dbDir());
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QString tst_qqmlsqldatabase::dbDir() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
static QString tmpd = QDir::tempPath()+"/tst_qqmlsqldatabase_output-"
|
2011-04-27 10:05:43 +00:00
|
|
|
+ QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss"));
|
|
|
|
return tmpd;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::checkDatabasePath()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// Check default storage path (we can't use it since we don't want to mess with user's data)
|
2012-02-16 04:43:03 +00:00
|
|
|
QVERIFY(engine->offlineStoragePath().contains("tst_qqmlsqldatabase"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(engine->offlineStoragePath().contains("OfflineStorage"));
|
|
|
|
}
|
|
|
|
|
2016-06-03 14:14:21 +00:00
|
|
|
static const int total_databases_created_by_tests = 13;
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::testQml_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("jsfile"); // The input file
|
|
|
|
|
|
|
|
// Each test should use a newly named DB to avoid inter-test dependencies
|
2011-10-14 02:02:43 +00:00
|
|
|
QTest::newRow("creation") << "creation.js";
|
|
|
|
QTest::newRow("creation-a") << "creation-a.js";
|
|
|
|
QTest::newRow("creation") << "creation.js";
|
|
|
|
QTest::newRow("error-creation") << "error-creation.js"; // re-uses above DB
|
|
|
|
QTest::newRow("changeversion") << "changeversion.js";
|
|
|
|
QTest::newRow("readonly") << "readonly.js";
|
|
|
|
QTest::newRow("readonly-error") << "readonly-error.js";
|
|
|
|
QTest::newRow("selection") << "selection.js";
|
|
|
|
QTest::newRow("selection-bindnames") << "selection-bindnames.js";
|
|
|
|
QTest::newRow("iteration") << "iteration.js";
|
|
|
|
QTest::newRow("iteration-forwardonly") << "iteration-forwardonly.js";
|
|
|
|
QTest::newRow("error-a") << "error-a.js";
|
|
|
|
QTest::newRow("error-notransaction") << "error-notransaction.js";
|
|
|
|
QTest::newRow("error-outsidetransaction") << "error-outsidetransaction.js"; // reuse above
|
|
|
|
QTest::newRow("reopen1") << "reopen1.js";
|
|
|
|
QTest::newRow("reopen2") << "reopen2.js"; // re-uses above DB
|
2016-06-03 14:14:21 +00:00
|
|
|
QTest::newRow("null-values") << "nullvalues.js";
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// If you add a test, you should usually use a new database in the
|
|
|
|
// test - in which case increment total_databases_created_by_tests above.
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::testQml()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// Tests QML SQL Database support with tests
|
|
|
|
// that have been validated against Webkit.
|
|
|
|
//
|
|
|
|
QFETCH(QString, jsfile);
|
|
|
|
|
|
|
|
QString qml=
|
2011-07-11 03:47:51 +00:00
|
|
|
"import QtQuick 2.0\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"import \""+jsfile+"\" as JS\n"
|
|
|
|
"Text { text: JS.test() }";
|
|
|
|
|
|
|
|
engine->setOfflineStoragePath(dbDir());
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(engine);
|
2011-12-21 08:06:26 +00:00
|
|
|
component.setData(qml.toUtf8(), testFileUrl("empty.qml")); // just a file for relative local imports
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!component.isError());
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *text = qobject_cast<QQuickText*>(component.create());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(text != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(text->text(),QString("passed"));
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::testQml_cleanopen_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("jsfile"); // The input file
|
2011-10-14 02:02:43 +00:00
|
|
|
QTest::newRow("reopen1") << "reopen1.js";
|
|
|
|
QTest::newRow("reopen2") << "reopen2.js";
|
|
|
|
QTest::newRow("error-creation") << "error-creation.js"; // re-uses creation DB
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::testQml_cleanopen()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// Same as testQml, but clean connections between tests,
|
|
|
|
// making it more like the tests are running in new processes.
|
|
|
|
testQml();
|
|
|
|
|
2011-05-11 07:20:40 +00:00
|
|
|
engine->collectGarbage();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
foreach (QString dbname, QSqlDatabase::connectionNames()) {
|
|
|
|
QSqlDatabase::removeDatabase(dbname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_qqmlsqldatabase::totalDatabases()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-19 03:50:39 +00:00
|
|
|
if (engine->offlineStoragePath().isEmpty())
|
|
|
|
QSKIP("offlineStoragePath is empty, skip this test.");
|
|
|
|
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that on() was replaced with a matcher that doesn't ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-08 17:56:03 +00:00
|
|
|
QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).size(), total_databases_created_by_tests*2);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 15:51:57 +00:00
|
|
|
void tst_qqmlsqldatabase::upgradeDatabase()
|
|
|
|
{
|
|
|
|
QQmlComponent component(engine, testFile("changeVersion.qml"));
|
|
|
|
QVERIFY(component.isReady());
|
|
|
|
|
|
|
|
QObject *object = component.create();
|
|
|
|
QVERIFY(object);
|
|
|
|
QVERIFY(object->property("version").toString().isEmpty());
|
|
|
|
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(object, "create"));
|
|
|
|
QCOMPARE(object->property("version").toString(), QLatin1String("2"));
|
|
|
|
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(object, "upgrade"));
|
|
|
|
QCOMPARE(object->property("version").toString(), QLatin1String("22"));
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QTEST_MAIN(tst_qqmlsqldatabase)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "tst_qqmlsqldatabase.moc"
|