#include "../shared/testhttpserver.h"
#include "../../../shared/util.h"
+#include "../shared/util.h"
#define SERVER_ADDR "http://127.0.0.1:14450"
#define SERVER_PORT 14450
QVERIFY(!component.isError()); \
QVERIFY(component.errors().isEmpty()); \
} else { \
- QString verify_errors_file_name = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + QLatin1String(errorfile); \
+ QString verify_errors_file_name = TESTDATA(errorfile); \
QFile file(verify_errors_file_name); \
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \
QByteArray data = file.readAll(); \
qWarning() << "Expected:" << expected << "Actual:" << actual; \
} \
if (qgetenv("QDECLARATIVELANGUAGE_UPDATEERRORS") != "" && expected != actual) {\
- QFile file(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + QLatin1String(errorfile)); \
+ QFile file(TESTDATA(errorfile)); \
QVERIFY(file.open(QIODevice::WriteOnly)); \
for (int ii = 0; ii < actual.count(); ++ii) { \
file.write(actual.at(ii)); file.write("\n"); \
inline QUrl TEST_FILE(const QString &filename)
{
- QFileInfo fileInfo(__FILE__);
- return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename));
+ return QUrl::fromLocalFile(TESTDATA(filename));
+}
+
+QString IMPORTSDIR()
+{
+ // Try to find it relative to the binary.
+ QDir appDir(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("imports"));
+ if (appDir.exists()) {
+ return appDir.absolutePath();
+ }
+
+ // Else try to find it in the source tree
+ QDir sourceDir(QFileInfo(__FILE__).absoluteDir().filePath(QLatin1String("imports")));
+ if (sourceDir.exists()) {
+ return sourceDir.absolutePath();
+ }
+
+ qWarning("requested importsPath could not be found (looked at: %s, %s)",
+ qPrintable(appDir.path()),
+ qPrintable(sourceDir.path())
+ );
+
+ return QString();
}
void tst_qdeclarativemoduleplugin::importsPlugin()
{
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
QTest::ignoreMessage(QtWarningMsg, "plugin created");
QTest::ignoreMessage(QtWarningMsg, "import worked");
- QDeclarativeComponent component(&engine, TEST_FILE("data/works.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("works.qml"));
foreach (QDeclarativeError err, component.errors())
qWarning() << err;
VERIFY_ERRORS(0);
void tst_qdeclarativemoduleplugin::importsPlugin2()
{
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
QTest::ignoreMessage(QtWarningMsg, "plugin2 created");
QTest::ignoreMessage(QtWarningMsg, "import2 worked");
- QDeclarativeComponent component(&engine, TEST_FILE("data/works2.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("works2.qml"));
foreach (QDeclarativeError err, component.errors())
qWarning() << err;
VERIFY_ERRORS(0);
void tst_qdeclarativemoduleplugin::importsPlugin21()
{
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
QTest::ignoreMessage(QtWarningMsg, "plugin2.1 created");
QTest::ignoreMessage(QtWarningMsg, "import2.1 worked");
- QDeclarativeComponent component(&engine, TEST_FILE("data/works21.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("works21.qml"));
foreach (QDeclarativeError err, component.errors())
qWarning() << err;
VERIFY_ERRORS(0);
void tst_qdeclarativemoduleplugin::incorrectPluginCase()
{
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
- QDeclarativeComponent component(&engine, TEST_FILE("data/incorrectCase.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("incorrectCase.qml"));
QList<QDeclarativeError> errors = component.errors();
QCOMPARE(errors.count(), 1);
#elif defined(Q_OS_WIN32)
QString libname = "PluGin.dll";
#endif
- QString expectedError = QLatin1String("plugin cannot be loaded for module \"com.nokia.WrongCase\": File name case mismatch for \"") + QFileInfo(__FILE__).absoluteDir().filePath("imports/com/nokia/WrongCase/" + libname) + QLatin1String("\"");
+ QString expectedError = QLatin1String("plugin cannot be loaded for module \"com.nokia.WrongCase\": File name case mismatch for \"") + QDir(IMPORTSDIR()).filePath("com/nokia/WrongCase/" + libname) + QLatin1String("\"");
#else
QString expectedError = QLatin1String("module \"com.nokia.WrongCase\" plugin \"PluGin\" not found");
#endif
void tst_qdeclarativemoduleplugin::importPluginWithQmlFile()
{
- QString path = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports");
+ QString path = IMPORTSDIR();
// QTBUG-16885: adding an import path with a lower-case "c:" causes assert failure
// (this only happens if the plugin includes pure QML files)
QDeclarativeEngine engine;
engine.addImportPath(path);
- QDeclarativeComponent component(&engine, TEST_FILE("data/pluginWithQmlFile.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("pluginWithQmlFile.qml"));
foreach (QDeclarativeError err, component.errors())
qWarning() << err;
VERIFY_ERRORS(0);
{
TestHTTPServer server(SERVER_PORT);
QVERIFY(server.isValid());
- server.serveDirectory(SRCDIR "/imports");
+ server.serveDirectory(IMPORTSDIR());
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine);
{
TestHTTPServer server(SERVER_PORT);
QVERIFY(server.isValid());
- server.serveDirectory(SRCDIR "/imports");
+ server.serveDirectory(IMPORTSDIR());
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
QDeclarativeComponent component(&engine);
component.setData("import com.nokia.PureQmlModule 1.0 \nComponentA { width: 300; ComponentB{} }", QUrl());
void tst_qdeclarativemoduleplugin::importsMixedQmlCppPlugin()
{
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
{
- QDeclarativeComponent component(&engine, TEST_FILE("data/importsMixedQmlCppPlugin.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("importsMixedQmlCppPlugin.qml"));
QObject *o = component.create();
QVERIFY(o != 0);
}
{
- QDeclarativeComponent component(&engine, TEST_FILE("data/importsMixedQmlCppPlugin.2.qml"));
+ QDeclarativeComponent component(&engine, TEST_FILE("importsMixedQmlCppPlugin.2.qml"));
QObject *o = component.create();
QVERIFY(o != 0);
QTest::addColumn<QString>("file");
QTest::addColumn<QString>("errorFile");
- QTest::newRow("versionNotInstalled") << "data/versionNotInstalled.qml" << "versionNotInstalled.errors.txt";
- QTest::newRow("versionNotInstalled") << "data/versionNotInstalled.2.qml" << "versionNotInstalled.2.errors.txt";
+ QTest::newRow("versionNotInstalled") << "versionNotInstalled.qml" << "versionNotInstalled.errors.txt";
+ QTest::newRow("versionNotInstalled") << "versionNotInstalled.2.qml" << "versionNotInstalled.2.errors.txt";
}
void tst_qdeclarativemoduleplugin::versionNotInstalled()
QFETCH(QString, errorFile);
QDeclarativeEngine engine;
- engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"));
+ engine.addImportPath(IMPORTSDIR());
QDeclarativeComponent component(&engine, TEST_FILE(file));
VERIFY_ERRORS(errorFile.toLatin1().constData());
QFETCH(QString, file);
QFETCH(QString, errorFile);
- QString importPath = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + directory;
- QString fileName = QLatin1String("data") + QDir::separator() + directory + QDir::separator() + file;
+ QString importPath = TESTDATA(directory);
+ QString fileName = directory + QDir::separator() + file;
QString errorFileName = directory + QDir::separator() + errorFile;
QUrl testFileUrl = TEST_FILE(fileName);
#include <QtSql/qsqldatabase.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
+#include "../shared/util.h"
class tst_qdeclarativesqldatabase : public QObject
{
QTest::addColumn<QString>("jsfile"); // The input file
// Each test should use a newly named DB to avoid inter-test dependencies
- QTest::newRow("creation") << "data/creation.js";
- QTest::newRow("creation-a") << "data/creation-a.js";
- QTest::newRow("creation") << "data/creation.js";
- QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses above DB
- QTest::newRow("changeversion") << "data/changeversion.js";
- QTest::newRow("readonly") << "data/readonly.js";
- QTest::newRow("readonly-error") << "data/readonly-error.js";
- QTest::newRow("selection") << "data/selection.js";
- QTest::newRow("selection-bindnames") << "data/selection-bindnames.js";
- QTest::newRow("iteration") << "data/iteration.js";
- QTest::newRow("iteration-forwardonly") << "data/iteration-forwardonly.js";
- QTest::newRow("error-a") << "data/error-a.js";
- QTest::newRow("error-notransaction") << "data/error-notransaction.js";
- QTest::newRow("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above
- QTest::newRow("reopen1") << "data/reopen1.js";
- QTest::newRow("reopen2") << "data/reopen2.js"; // re-uses above DB
+ 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
// 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.
engine->setOfflineStoragePath(dbDir());
QDeclarativeComponent component(engine);
- component.setData(qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports
+ component.setData(qml.toUtf8(), QUrl::fromLocalFile(TESTDATA("empty.qml"))); // just a file for relative local imports
QVERIFY(!component.isError());
QSGText *text = qobject_cast<QSGText*>(component.create());
QVERIFY(text != 0);
void tst_qdeclarativesqldatabase::testQml_cleanopen_data()
{
QTest::addColumn<QString>("jsfile"); // The input file
- QTest::newRow("reopen1") << "data/reopen1.js";
- QTest::newRow("reopen2") << "data/reopen2.js";
- QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses creation DB
+ QTest::newRow("reopen1") << "reopen1.js";
+ QTest::newRow("reopen2") << "reopen2.js";
+ QTest::newRow("error-creation") << "error-creation.js"; // re-uses creation DB
}
void tst_qdeclarativesqldatabase::testQml_cleanopen()