aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-01-18 17:12:25 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-24 23:18:34 +0100
commit149f6afe321ce59aebe4ce2f9dddd1881d0ac22b (patch)
tree45233b8c808ed553051799b38a6b1e73898db2e1 /tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
parent49212ef6d8934a023e6d0a7b778ec25605a8be7a (diff)
Allow JS API in modules
Allow modules to export verisoned javascript code into specified namespaces. Task-number: QTBUG-20857 Change-Id: Ic968c697ba36cbc4535870ed5eed2fe7f01af11d Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp109
1 files changed, 100 insertions, 9 deletions
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index 422b34c15b..ff956ec182 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -159,6 +159,8 @@ private slots:
void importsOrder_data();
void importsOrder();
void importIncorrectCase();
+ void importJs_data();
+ void importJs();
void qmlAttachedPropertiesObjectMethod();
void customOnProperty();
@@ -179,21 +181,17 @@ private:
void testType(const QString& qml, const QString& type, const QString& error);
};
-#define VERIFY_ERRORS(errorfile) \
- if (!errorfile) { \
- if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) \
- qWarning() << "Unexpected Errors:" << component.errors(); \
- QVERIFY(!component.isError()); \
- QVERIFY(component.errors().isEmpty()); \
- } else { \
+#define DETERMINE_ERRORS(errorfile,expected,actual)\
+ QList<QByteArray> expected; \
+ QList<QByteArray> actual; \
+ do { \
QFile file(testdata(QLatin1String(errorfile))); \
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \
QByteArray data = file.readAll(); \
file.close(); \
- QList<QByteArray> expected = data.split('\n'); \
+ expected = data.split('\n'); \
expected.removeAll(QByteArray("")); \
QList<QDeclarativeError> errors = component.errors(); \
- QList<QByteArray> actual; \
for (int ii = 0; ii < errors.count(); ++ii) { \
const QDeclarativeError &error = errors.at(ii); \
QByteArray errorStr = QByteArray::number(error.line()) + ":" + \
@@ -201,6 +199,16 @@ private:
error.description().toUtf8(); \
actual << errorStr; \
} \
+ } while (false);
+
+#define VERIFY_ERRORS(errorfile) \
+ if (!errorfile) { \
+ if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) \
+ qWarning() << "Unexpected Errors:" << component.errors(); \
+ QVERIFY(!component.isError()); \
+ QVERIFY(component.errors().isEmpty()); \
+ } else { \
+ DETERMINE_ERRORS(errorfile,actual,expected);\
if (qgetenv("DEBUG") != "" && expected != actual) \
qWarning() << "Expected:" << expected << "Actual:" << actual; \
if (qgetenv("QDECLARATIVELANGUAGE_UPDATEERRORS") != "" && expected != actual) {\
@@ -1923,6 +1931,89 @@ void tst_qdeclarativelanguage::importIncorrectCase()
QCOMPARE(errors.at(0).description(), expectedError);
}
+void tst_qdeclarativelanguage::importJs_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("errorFile");
+ QTest::addColumn<bool>("performTest");
+
+ QTest::newRow("defaultVersion")
+ << "importJs.1.qml"
+ << "importJs.1.errors.txt"
+ << true;
+
+ QTest::newRow("specifiedVersion")
+ << "importJs.2.qml"
+ << "importJs.2.errors.txt"
+ << true;
+
+ QTest::newRow("excludeExcessiveVersion")
+ << "importJs.3.qml"
+ << "importJs.3.errors.txt"
+ << false;
+
+ QTest::newRow("includeAppropriateVersion")
+ << "importJs.4.qml"
+ << "importJs.4.errors.txt"
+ << true;
+
+ QTest::newRow("noDefaultVersion")
+ << "importJs.5.qml"
+ << "importJs.5.errors.txt"
+ << false;
+
+ QTest::newRow("repeatImportFails")
+ << "importJs.6.qml"
+ << "importJs.6.errors.txt"
+ << false;
+
+ QTest::newRow("multipleVersionImportFails")
+ << "importJs.7.qml"
+ << "importJs.7.errors.txt"
+ << false;
+
+ QTest::newRow("namespacedImport")
+ << "importJs.8.qml"
+ << "importJs.8.errors.txt"
+ << true;
+
+ QTest::newRow("namespacedVersionedImport")
+ << "importJs.9.qml"
+ << "importJs.9.errors.txt"
+ << true;
+
+ QTest::newRow("namespacedRepeatImport")
+ << "importJs.10.qml"
+ << "importJs.10.errors.txt"
+ << true;
+}
+
+void tst_qdeclarativelanguage::importJs()
+{
+ QFETCH(QString, file);
+ QFETCH(QString, errorFile);
+ QFETCH(bool, performTest);
+
+ QDeclarativeComponent component(&engine, TEST_FILE(file));
+
+ {
+ DETERMINE_ERRORS(errorFile.toLatin1().constData(),expected,actual);
+ QCOMPARE(expected.size(), actual.size());
+ for (int i = 0; i < expected.size(); ++i)
+ {
+ size_t compareLen = std::min(expected.at(i).length(), actual.at(i).length());
+ QCOMPARE(expected.at(i).left(compareLen), actual.at(i).left(compareLen));
+ }
+ }
+
+ if (performTest) {
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("test").toBool(),true);
+ delete object;
+ }
+}
+
void tst_qdeclarativelanguage::qmlAttachedPropertiesObjectMethod()
{
QObject object;