From 67e42ba2eb8ab2115e929791cb67a8e9ba413e80 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 12 Nov 2009 18:02:05 +1000 Subject: Qt.md5() method --- doc/src/declarative/globalobject.qdoc | 4 ++++ src/declarative/qml/qmlengine.cpp | 14 ++++++++++++++ src/declarative/qml/qmlengine_p.h | 1 + tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 15 +++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 06f6bdc..3cf1ca3 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -122,6 +122,10 @@ This function plays the audio file located at \c soundLocation. Only .wav files \section3 Qt.openUrlExternally(url target) This function attempts to open the specified \c target url in an external application, based on the user's desktop preferences. It will return true if it succeeds, and false otherwise. + +\section3 Qt.md5(data) +This function returns a hex string of the md5 hash of \c data. + \endlist \section1 Dynamic Object Creation diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 177818f..53febf5 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -88,6 +88,7 @@ #include #include #include +#include #ifdef Q_OS_WIN // for %APPDATA% #include "qt_windows.h" @@ -150,6 +151,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); + qtObject.setProperty(QLatin1String("md5"),scriptEngine.newFunction(md5, 1)); scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"), scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1)); @@ -816,6 +818,18 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } +QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e) +{ + QByteArray data; + + if (ctxt->argumentCount() >= 1) + data = ctxt->argument(0).toString().toUtf8(); + + QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5); + + return QScriptValue(QLatin1String(result.toHex())); +} + QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) { if(ctxt->argumentCount() < 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 3c60b5c..5b4e884 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -272,6 +272,7 @@ public: static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); + static QScriptValue md5(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEngine *getEngine(QScriptEngine *e) { return static_cast(e)->p->q_func(); } diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp index e9c9052..13f4904 100644 --- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -46,6 +46,7 @@ #include #include #include +#include class tst_qmlqt : public QObject { @@ -67,6 +68,7 @@ private slots: void closestAngle(); void playSound(); void openUrlExternally(); + void md5(); private: QmlEngine engine; @@ -279,6 +281,19 @@ void tst_qmlqt::openUrlExternally() QVERIFY(false); } +void tst_qmlqt::md5() +{ + QmlComponent component(&engine, TEST_FILE("md5.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").toString(), QLatin1String(QCryptographicHash::hash(QByteArray(), QCryptographicHash::Md5).toHex())); + QCOMPARE(object->property("test2").toString(), QLatin1String(QCryptographicHash::hash("Hello World", QCryptographicHash::Md5).toHex())); + + delete object; +} + + QTEST_MAIN(tst_qmlqt) #include "tst_qmlqt.moc" -- cgit v0.12 From 588c7e44bcd724765b620e3b0c64af59d83c8ac5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 12 Nov 2009 18:22:35 +1000 Subject: Compile --- tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index ece6030..fe2658c 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v0.12 From 652e43ddbc4bf32b8c5f634a47a883f7029fd890 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 13 Nov 2009 10:44:15 +1000 Subject: XMLHttpRequest tests --- src/declarative/qml/qmlxmlhttprequest.cpp | 11 ++--- .../auto/declarative/xmlhttprequest/data/text.qml | 56 ++++++++++++++++++++++ .../auto/declarative/xmlhttprequest/data/text.xml | 1 + .../xmlhttprequest/tst_xmlhttprequest.cpp | 14 ++++++ 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 tests/auto/declarative/xmlhttprequest/data/text.qml create mode 100644 tests/auto/declarative/xmlhttprequest/data/text.xml diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index a6cdfb1..1e9ad50 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -465,12 +465,11 @@ QScriptValue Node::create(QScriptEngine *engine, NodeImpl *data) case NodeImpl::Entity: case NodeImpl::EntityReference: case NodeImpl::Notation: + case NodeImpl::ProcessingInstruction: + return QScriptValue(); case NodeImpl::CDATA: instance.setPrototype(CDATA::prototype(engine)); break; - case NodeImpl::ProcessingInstruction: - instance.setPrototype(Node::prototype(engine)); - break; case NodeImpl::Text: instance.setPrototype(Text::prototype(engine)); break; @@ -556,8 +555,7 @@ QScriptValue Text::isElementContentWhitespace(QScriptContext *context, QScriptEn Node node = qscriptvalue_cast(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(false); + return node.d->data.trimmed().isEmpty(); } QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) @@ -565,8 +563,7 @@ QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) Node node = qscriptvalue_cast(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(QString()); + return node.d->data; } QScriptValue Text::prototype(QScriptEngine *engine) diff --git a/tests/auto/declarative/xmlhttprequest/data/text.qml b/tests/auto/declarative/xmlhttprequest/data/text.qml new file mode 100644 index 0000000..b64f80b --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/text.qml @@ -0,0 +1,56 @@ +import Qt 4.6 + +Object { + property bool xmlTest: false + property bool dataOK: false + + Script { + function checkText(text, whitespacetext) + { + if (text.wholeText != "Hello world!") + return; + + if (text.isElementContentWhitespace != false) + return; + + if (whitespacetext.wholeText != " ") + return; + + if (whitespacetext.isElementContentWhitespace != true) + return; + + xmlTest = true; + } + + function checkXML(document) + { + checkText(document.documentElement.childNodes[0].childNodes[0], + document.documentElement.childNodes[1].childNodes[0]); + + } + } + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "text.xml"); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + + dataOK = true; + + if (x.responseXML != null) + checkXML(x.responseXML); + + } + } + + x.send() + } +} + + + + diff --git a/tests/auto/declarative/xmlhttprequest/data/text.xml b/tests/auto/declarative/xmlhttprequest/data/text.xml new file mode 100644 index 0000000..e741688 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/text.xml @@ -0,0 +1 @@ +Hello world! diff --git a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp index 0af7b18..cf1ffd3 100644 --- a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp +++ b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp @@ -88,6 +88,7 @@ private slots: void document(); void element(); void attr(); + void text(); // Crashes // void outstanding_request_at_shutdown(); @@ -1017,6 +1018,19 @@ void tst_xmlhttprequest::attr() delete object; } +void tst_xmlhttprequest::text() +{ + QmlComponent component(&engine, TEST_FILE("text.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + QCOMPARE(object->property("xmlTest").toBool(), true); + + delete object; +} + QTEST_MAIN(tst_xmlhttprequest) #include "tst_xmlhttprequest.moc" -- cgit v0.12 From 17b6a9fbfc9de4dae58653b18c26d1ce509e4c21 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 13 Nov 2009 14:31:52 +1000 Subject: test elementAreaAt --- .../qmlgraphicswebview/tst_qmlgraphicswebview.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp index 9032300..308cdd6 100644 --- a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp +++ b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp @@ -59,6 +59,7 @@ private slots: void basicProperties(); void historyNav(); void multipleWindows(); + void elementAreaAt(); void loadError(); void setHtml(); void javaScript(); @@ -258,6 +259,21 @@ void tst_qmlgraphicswebview::setHtml() QCOMPARE(wv->html(),QString("

This is a string set on the WebView

")); } +void tst_qmlgraphicswebview::elementAreaAt() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/elements.qml")); + checkNoErrors(component); + QmlGraphicsWebView *wv = qobject_cast(component.create()); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QCOMPARE(wv->elementAreaAt(40,30,100,100),QRect(1,1,75,54)); // Area A in data/elements.html + QCOMPARE(wv->elementAreaAt(130,30,200,100),QRect(78,3,110,50)); // Area B + QCOMPARE(wv->elementAreaAt(40,30,400,400),QRect(0,0,310,100)); // Whole view + QCOMPARE(wv->elementAreaAt(130,30,280,280),QRect(76,1,223,54)); // Area BC + QCOMPARE(wv->elementAreaAt(130,30,400,400),QRect(0,0,310,100)); // Whole view +} + void tst_qmlgraphicswebview::javaScript() { QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/javaScript.qml")); -- cgit v0.12 From 08405d50115aaf787f09c7c8151bd10f8b4d02ce Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 13 Nov 2009 14:32:14 +1000 Subject: Make 'public' (testable) --- src/declarative/graphicsitems/qmlgraphicswebview_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 7c9faf4..1d55830 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -128,6 +128,7 @@ public: qreal zoomFactor() const; void setZoomFactor(qreal); Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; int preferredWidth() const; void setPreferredWidth(int); @@ -223,7 +224,6 @@ protected: virtual void focusChanged(bool); virtual bool sceneEvent(QEvent *event); QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; private: void init(); -- cgit v0.12 From 2e1ad8b5d2b1927e80a3bd08209a75199e241b3c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 13 Nov 2009 14:47:54 +1000 Subject: XMLHttpRequest tests --- src/declarative/qml/qmlxmlhttprequest.cpp | 153 +++++---------------- .../auto/declarative/xmlhttprequest/data/cdata.qml | 135 ++++++++++++++++++ .../auto/declarative/xmlhttprequest/data/cdata.xml | 2 + .../declarative/xmlhttprequest/data/document.qml | 6 + .../declarative/xmlhttprequest/data/document.xml | 2 +- .../declarative/xmlhttprequest/data/element.qml | 28 +++- .../auto/declarative/xmlhttprequest/data/text.qml | 75 ++++++++++ .../xmlhttprequest/tst_xmlhttprequest.cpp | 22 +++ 8 files changed, 303 insertions(+), 120 deletions(-) create mode 100644 tests/auto/declarative/xmlhttprequest/data/cdata.qml create mode 100644 tests/auto/declarative/xmlhttprequest/data/cdata.xml diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 0a774e6..848533c 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -131,10 +131,10 @@ public: QList attributes; }; -class DocumentImpl : public QmlRefCount +class DocumentImpl : public NodeImpl { public: - DocumentImpl() : root(0) { } + DocumentImpl() : root(0) { type = Document; } virtual ~DocumentImpl() { if (root) D(root); } @@ -158,12 +158,13 @@ public: NamedNodeMap(); NamedNodeMap(const NamedNodeMap &); - NamedNodeMap &operator=(const NamedNodeMap &); ~NamedNodeMap(); bool isNull(); NodeImpl *d; QList *list; +private: + NamedNodeMap &operator=(const NamedNodeMap &); }; class NamedNodeMapClass : public QScriptClass @@ -180,7 +181,6 @@ class NodeList public: // JS API static QScriptValue length(QScriptContext *context, QScriptEngine *engine); - static QScriptValue item(QScriptContext *context, QScriptEngine *engine); // C++ API static QScriptValue prototype(QScriptEngine *); @@ -188,11 +188,12 @@ public: NodeList(); NodeList(const NodeList &); - NodeList &operator=(const NodeList &); ~NodeList(); bool isNull(); NodeImpl *d; +private: + NodeList &operator=(const NodeList &); }; class NodeListClass : public QScriptClass @@ -232,11 +233,13 @@ public: Node(); Node(const Node &o); - Node &operator=(const Node &); ~Node(); bool isNull() const; NodeImpl *d; + +private: + Node &operator=(const Node &); }; class Element : public Node @@ -301,31 +304,29 @@ public: // C++ API static QScriptValue prototype(QScriptEngine *); static QScriptValue load(QScriptEngine *engine, const QString &data); - - Document(); - Document(const Document &); - Document &operator=(const Document &); - ~Document(); - bool isNull() const; - - DocumentImpl *d; -private: - Document(DocumentImpl *); }; -}; +}; // namespace Q_DECLARE_METATYPE(Node); Q_DECLARE_METATYPE(NodeList); Q_DECLARE_METATYPE(NamedNodeMap); -Q_DECLARE_METATYPE(Document); QScriptValue Node::nodeName(QScriptContext *context, QScriptEngine *engine) { Node node = qscriptvalue_cast(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - return QScriptValue(node.d->name); + switch (node.d->type) { + case NodeImpl::Document: + return QScriptValue(QLatin1String("#document")); + case NodeImpl::CDATA: + return QScriptValue(QLatin1String("#cdata-section")); + case NodeImpl::Text: + return QScriptValue(QLatin1String("#text")); + default: + return QScriptValue(node.d->name); + } } QScriptValue Node::nodeValue(QScriptContext *context, QScriptEngine *engine) @@ -643,6 +644,7 @@ QScriptValue Document::load(QScriptEngine *engine, const QString &data) attr->name = a.name().toString(); attr->data = a.value().toString(); attr->parent = node; + A(attr->parent); node->attributes.append(attr); } } @@ -678,7 +680,9 @@ QScriptValue Document::load(QScriptEngine *engine, const QString &data) QScriptValue instance = engine->newObject(); instance.setPrototype(Document::prototype(engine)); - return engine->newVariant(instance, qVariantFromValue(Document(document))); + Node documentNode; + documentNode.d = document; + return engine->newVariant(instance, qVariantFromValue(documentNode)); } Node::Node() @@ -692,14 +696,6 @@ Node::Node(const Node &o) if (d) A(d); } -Node &Node::operator=(const Node &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - Node::~Node() { if (d) D(d); @@ -758,15 +754,6 @@ NamedNodeMap::NamedNodeMap(const NamedNodeMap &o) if (d) A(d); } -NamedNodeMap &NamedNodeMap::operator=(const NamedNodeMap &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - list = o.list; - return *this; -} - NamedNodeMap::~NamedNodeMap() { if (d) D(d); @@ -777,20 +764,6 @@ bool NamedNodeMap::isNull() return d == 0; } -QScriptValue NodeList::item(QScriptContext *context, QScriptEngine *engine) -{ - NodeList list = qscriptvalue_cast(context->thisObject().data()); - if (list.isNull() || context->argumentCount() != 1) - return engine->undefinedValue(); - - qint32 index = context->argument(0).toInt32(); - - if (index >= list.d->children.count()) - return engine->undefinedValue(); // ### Exception - else - return Node::create(engine, list.d->children.at(index)); -} - QScriptValue NodeList::length(QScriptContext *context, QScriptEngine *engine) { NodeList list = qscriptvalue_cast(context->thisObject().data()); @@ -804,7 +777,6 @@ QScriptValue NodeList::prototype(QScriptEngine *engine) QScriptValue proto = engine->newObject(); proto.setProperty(QLatin1String("length"), engine->newFunction(length), QScriptValue::ReadOnly | QScriptValue::PropertyGetter); - proto.setProperty(QLatin1String("item"), engine->newFunction(item, 1), QScriptValue::ReadOnly); return proto; } @@ -839,14 +811,6 @@ NodeList::NodeList(const NodeList &o) if (d) A(d); } -NodeList &NodeList::operator=(const NodeList &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - NodeList::~NodeList() { if (d) D(d); @@ -917,81 +881,36 @@ QScriptValue NodeListClass::property(const QScriptValue &object, const QScriptSt return Node::create(engine(), list.d->children.at(id)); } -Document::Document() -: d(0) -{ -} - -Document::Document(DocumentImpl *data) -: d(data) -{ -} - -Document::Document(const Document &o) -: Node(o), d(o.d) -{ - if (d) A(d); -} - -Document &Document::operator=(const Document &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - -Document::~Document() -{ - if (d) D(d); -} - -bool Document::isNull() const -{ - return d == 0; -} - QScriptValue Document::documentElement(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (!document.d->root) return engine->nullValue(); + Node document = qscriptvalue_cast(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return Node::create(engine, document.d->root); + return Node::create(engine, static_cast(document.d)->root); } QScriptValue Document::xmlStandalone(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (context->argumentCount()) - document.d->isStandalone = context->argument(0).toBool(); + Node document = qscriptvalue_cast(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return QScriptValue(document.d->isStandalone); + return QScriptValue(static_cast(document.d)->isStandalone); } QScriptValue Document::xmlVersion(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); + Node document = qscriptvalue_cast(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - if (context->argumentCount()) - document.d->version = context->argument(0).toString(); - - return QScriptValue(document.d->version); + return QScriptValue(static_cast(document.d)->version); } QScriptValue Document::xmlEncoding(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (context->argumentCount()) - document.d->encoding = context->argument(0).toString(); + Node document = qscriptvalue_cast(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return QScriptValue(document.d->encoding); + return QScriptValue(static_cast(document.d)->encoding); } class QmlXMLHttpRequest : public QObject diff --git a/tests/auto/declarative/xmlhttprequest/data/cdata.qml b/tests/auto/declarative/xmlhttprequest/data/cdata.qml new file mode 100644 index 0000000..5faa359 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/cdata.qml @@ -0,0 +1,135 @@ +import Qt 4.6 + +Object { + property bool xmlTest: false + property bool dataOK: false + + Script { + function checkCData(text, whitespacetext) + { + // This is essentially a copy of text.qml/checkText() + + if (text == null) + return; + + if (text.nodeName != "#cdata-section") + return; + + if (text.nodeValue != "Hello world!") + return; + + if (text.nodeType != 4) + return; + + if (text.parentNode.nodeName != "item") + return; + + if (text.childNodes.length != 0) + return; + + if (text.firstChild != null) + return; + + if (text.lastChild != null) + return; + + if (text.previousSibling != null) + return; + + if (text.nextSibling != null) + return; + + if (text.attributes != null) + return; + + if (text.wholeText != "Hello world!") + return; + + if (text.data != "Hello world!") + return; + + if (text.length != 12) + return; + + if (text.isElementContentWhitespace != false) + return; + + if (whitespacetext.nodeName != "#cdata-section") + return; + + if (whitespacetext.nodeValue != " ") + return; + + if (whitespacetext.nodeType != 4) + return; + + if (whitespacetext.parentNode.nodeName != "item") + return; + + if (whitespacetext.childNodes.length != 0) + return; + + if (whitespacetext.firstChild != null) + return; + + if (whitespacetext.lastChild != null) + return; + + if (whitespacetext.previousSibling != null) + return; + + if (whitespacetext.nextSibling != null) + return; + + if (whitespacetext.attributes != null) + return; + + if (whitespacetext.wholeText != " ") + return; + + if (whitespacetext.data != " ") + return; + + if (whitespacetext.length != 3) + return; + + if (whitespacetext.isElementContentWhitespace != true) + return; + + + xmlTest = true; + } + + function checkXML(document) + { + checkCData(document.documentElement.childNodes[0].childNodes[0], + document.documentElement.childNodes[1].childNodes[0]); + + } + } + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "cdata.xml"); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + + dataOK = true; + + if (x.responseXML != null) + checkXML(x.responseXML); + + } + } + + x.send() + } +} + + + + + diff --git a/tests/auto/declarative/xmlhttprequest/data/cdata.xml b/tests/auto/declarative/xmlhttprequest/data/cdata.xml new file mode 100644 index 0000000..061d37c --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/cdata.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/auto/declarative/xmlhttprequest/data/document.qml b/tests/auto/declarative/xmlhttprequest/data/document.qml index fe78e31..7601a10 100644 --- a/tests/auto/declarative/xmlhttprequest/data/document.qml +++ b/tests/auto/declarative/xmlhttprequest/data/document.qml @@ -10,12 +10,18 @@ Object { if (document.xmlVersion != "1.0") return; + if (document.xmlEncoding != "UTF-8") + return; + if (document.xmlStandalone != true) return; if (document.documentElement == null) return; + if (document.nodeName != "#document") + return; + if (document.nodeValue != null) return; diff --git a/tests/auto/declarative/xmlhttprequest/data/document.xml b/tests/auto/declarative/xmlhttprequest/data/document.xml index b5fbe31..fb693ea 100644 --- a/tests/auto/declarative/xmlhttprequest/data/document.xml +++ b/tests/auto/declarative/xmlhttprequest/data/document.xml @@ -1,3 +1,3 @@ - + diff --git a/tests/auto/declarative/xmlhttprequest/data/element.qml b/tests/auto/declarative/xmlhttprequest/data/element.qml index a1ae2ab..79620bf 100644 --- a/tests/auto/declarative/xmlhttprequest/data/element.qml +++ b/tests/auto/declarative/xmlhttprequest/data/element.qml @@ -5,7 +5,7 @@ Object { property bool dataOK: false Script { - function checkElement(e) + function checkElement(e, person, fruit) { if (e.tagName != "root") return; @@ -47,6 +47,9 @@ Object { if (e.attributes == null) return; + if (e.attributes.length != 2) + return; + var attr1 = e.attributes["attr"]; if (attr1.nodeValue != "value") return; @@ -67,12 +70,33 @@ Object { if (attrIdx2 != null) return; + // Check person and fruit sub elements + if (person.parentNode.nodeName != "root") + return; + + if (person.previousSibling != null) + return; + + if (person.nextSibling.nodeName != "fruit") + return; + + if (fruit.parentNode.nodeName != "root") + return; + + if (fruit.previousSibling.nodeName != "person") + return; + + if (fruit.nextSibling != null) + return; + xmlTest = true; } function checkXML(document) { - checkElement(document.documentElement); + checkElement(document.documentElement, + document.documentElement.childNodes[0], + document.documentElement.childNodes[1]); } } diff --git a/tests/auto/declarative/xmlhttprequest/data/text.qml b/tests/auto/declarative/xmlhttprequest/data/text.qml index b64f80b..8c97504 100644 --- a/tests/auto/declarative/xmlhttprequest/data/text.qml +++ b/tests/auto/declarative/xmlhttprequest/data/text.qml @@ -7,15 +7,90 @@ Object { Script { function checkText(text, whitespacetext) { + if (text == null) + return; + + if (text.nodeName != "#text") + return; + + if (text.nodeValue != "Hello world!") + return; + + if (text.nodeType != 3) + return; + + if (text.parentNode.nodeName != "item") + return; + + if (text.childNodes.length != 0) + return; + + if (text.firstChild != null) + return; + + if (text.lastChild != null) + return; + + if (text.previousSibling != null) + return; + + if (text.nextSibling != null) + return; + + if (text.attributes != null) + return; + if (text.wholeText != "Hello world!") return; + if (text.data != "Hello world!") + return; + + if (text.length != 12) + return; + if (text.isElementContentWhitespace != false) return; + if (whitespacetext.nodeName != "#text") + return; + + if (whitespacetext.nodeValue != " ") + return; + + if (whitespacetext.nodeType != 3) + return; + + if (whitespacetext.parentNode.nodeName != "item") + return; + + if (whitespacetext.childNodes.length != 0) + return; + + if (whitespacetext.firstChild != null) + return; + + if (whitespacetext.lastChild != null) + return; + + if (whitespacetext.previousSibling != null) + return; + + if (whitespacetext.nextSibling != null) + return; + + if (whitespacetext.attributes != null) + return; + if (whitespacetext.wholeText != " ") return; + if (whitespacetext.data != " ") + return; + + if (whitespacetext.length != 3) + return; + if (whitespacetext.isElementContentWhitespace != true) return; diff --git a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp index cf1ffd3..100a11b 100644 --- a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp +++ b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp @@ -84,11 +84,14 @@ private slots: void statusText(); void responseText(); void responseXML_invalid(); + void invalidMethodUsage(); + // Attributes void document(); void element(); void attr(); void text(); + void cdata(); // Crashes // void outstanding_request_at_shutdown(); @@ -963,6 +966,10 @@ void tst_xmlhttprequest::responseText() } } +void tst_xmlhttprequest::invalidMethodUsage() +{ +} + void tst_xmlhttprequest::responseXML_invalid() { QmlComponent component(&engine, TEST_FILE("responseXML_invalid.qml")); @@ -1018,6 +1025,7 @@ void tst_xmlhttprequest::attr() delete object; } +// Test the Text DOM element void tst_xmlhttprequest::text() { QmlComponent component(&engine, TEST_FILE("text.qml")); @@ -1031,6 +1039,20 @@ void tst_xmlhttprequest::text() delete object; } +// Test the CDataSection DOM element +void tst_xmlhttprequest::cdata() +{ + QmlComponent component(&engine, TEST_FILE("cdata.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + QCOMPARE(object->property("xmlTest").toBool(), true); + + delete object; +} + QTEST_MAIN(tst_xmlhttprequest) #include "tst_xmlhttprequest.moc" -- cgit v0.12 From f2d9bdb36061b4b419e777075027f609bf9890b2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 13 Nov 2009 14:48:33 +1000 Subject: Better gcov compile flags --- src/declarative/declarative.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index e4901bf..da8434f 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -9,7 +9,7 @@ solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors # LIBS += -lgcov INCLUDEPATH += ../../include/QtDeclarative -- cgit v0.12 From b143576a735b6ec67058d5c6b6cf369b1002756d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 13 Nov 2009 14:53:49 +1000 Subject: Missing files --- tests/auto/declarative/qmllanguage/data/cppnamespace.2.qml | 5 +++++ tests/auto/declarative/qmlqt/data/md5.qml | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/auto/declarative/qmllanguage/data/cppnamespace.2.qml create mode 100644 tests/auto/declarative/qmlqt/data/md5.qml diff --git a/tests/auto/declarative/qmllanguage/data/cppnamespace.2.qml b/tests/auto/declarative/qmllanguage/data/cppnamespace.2.qml new file mode 100644 index 0000000..e3b32ca --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/cppnamespace.2.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MySecondNamespacedType { + list: [ MyNamespacedType {} ] +} diff --git a/tests/auto/declarative/qmlqt/data/md5.qml b/tests/auto/declarative/qmlqt/data/md5.qml new file mode 100644 index 0000000..3c96a6b --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/md5.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + property string test1: Qt.md5() + property string test2: Qt.md5("Hello World") +} -- cgit v0.12