diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-11-06 16:47:48 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2013-11-14 16:41:27 +0100 |
commit | bc06e88886ca33ce68c3ae3a72cf011257d1fadd (patch) | |
tree | 64716a51c4da5f73425f965475e5057a1c2345bc /src | |
parent | 86eacb18b6868173b63b8f67feb481d6e291ad7a (diff) | |
download | qtwebchannel-bc06e88886ca33ce68c3ae3a72cf011257d1fadd.tar.gz |
Add unit test harness for QWebChannel and two initial tests.
This uncovered a bug in webchannel.js, which stringified strings leading
to duplicated quoting. This is also fixed now.
Furthermore, some QMake changes are required to make it possible to run
the tests without first installing QWebChannel.
Change-Id: If7e8f73a748f86f2d5c7d39000e90612367038af
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/src.pro | 29 | ||||
-rw-r--r-- | src/webchannel.js | 5 |
2 files changed, 22 insertions, 12 deletions
diff --git a/src/src.pro b/src/src.pro index ee77e4b..5690897 100644 --- a/src/src.pro +++ b/src/src.pro @@ -12,6 +12,9 @@ TARGET = $$qtLibraryTarget($$TARGET) SOURCES += qwebchannel_plugin.cpp HEADERS += qwebchannel_plugin.h +RESOURCES += \ + resources.qrc + OTHER_FILES = qmldir \ qtc_packaging/debian_harmattan/rules \ qtc_packaging/debian_harmattan/README \ @@ -24,20 +27,24 @@ OTHER_FILES = qmldir \ MetaObjectPublisher.qml \ WebChannel.qml -!equals(_PRO_FILE_PWD_, $$OUT_PWD) { - copy_qmldir.target = $$OUT_PWD/qmldir - copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir - copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" - QMAKE_EXTRA_TARGETS += copy_qmldir - PRE_TARGETDEPS += $$copy_qmldir.target -} - target.path = $$[QT_INSTALL_QML]/$$TARGETPATH -qmldir.files += $$PWD/qmldir $$PWD/MetaObjectPublisher.qml $$PWD/WebChannel.qml +# extra files that need to be deployed to $$TARGETPATH +DEPLOY_FILES = \ + qmldir \ + MetaObjectPublisher.qml \ + WebChannel.qml + +for(FILE, DEPLOY_FILES): qmldir.files += $$PWD/$$FILE qmldir.path += $$[QT_INSTALL_QML]/$$TARGETPATH INSTALLS += target qmldir -RESOURCES += \ - resources.qrc +# ensure that plugin is put into the correct folder structure +DESTDIR = $$TARGETPATH + +# copy files in order to run tests without calling make install first +for(FILE, DEPLOY_FILES) { + PRE_TARGETDEPS += $$PWD/$$FILE + QMAKE_POST_LINK += $$quote($$QMAKE_COPY \"$$PWD/$$FILE\" $$OUT_PWD/$$TARGETPATH$$escape_expand(\n\t)) +} diff --git a/src/webchannel.js b/src/webchannel.js index 0cb3d8a..15ae127 100644 --- a/src/webchannel.js +++ b/src/webchannel.js @@ -57,7 +57,10 @@ var QWebChannel = function(baseUrl, initCallback) this.socket = new WebSocket(socketUrl, "QWebChannel"); this.send = function(data) { - channel.socket.send(JSON.stringify(data)); + if (typeof(data) !== "string") { + data = JSON.stringify(data); + } + channel.socket.send(data); }; this.socket.onopen = function() |