Started work on json interface. Added unit-tests for json classes.
authorIonutz Borcoman <iborco@gmail.com>
Tue, 1 Feb 2011 13:07:54 +0000 (15:07 +0200)
committerIonutz Borcoman <iborco@gmail.com>
Thu, 10 Mar 2011 08:10:13 +0000 (10:10 +0200)
src/json.cpp [new file with mode: 0644]
src/json.h [new file with mode: 0644]
src/mainwindow.cpp
src/xbmcnetmoviesremote.pro
test-json/main.cpp [new file with mode: 0644]
test-json/test-json.pro [new file with mode: 0644]

diff --git a/src/json.cpp b/src/json.cpp
new file mode 100644 (file)
index 0000000..095c3f1
--- /dev/null
@@ -0,0 +1,20 @@
+#include "json.h"
+
+int JsonEngine::id = 0;
+
+JsonEngine::JsonEngine()
+{
+}
+
+QString JsonEngine::serialize(const QString& method)
+{
+    id++;
+    return QString("{\"jsonrpc\" : \"2.0\", \"method\" : \"%1\", \"id\" : %2}")
+            .arg(method)
+            .arg(id);
+}
+
+QString JsonEngine::playerGetActivePlayers()
+{
+    return serialize("Player.GetActivePlayers");
+}
diff --git a/src/json.h b/src/json.h
new file mode 100644 (file)
index 0000000..38e9177
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef JSON_H
+#define JSON_H
+
+#include <QString>
+
+class JsonEngine
+{
+    QString serialize(const QString& method);
+    static int id;
+public:
+    JsonEngine();
+
+    QString playerGetActivePlayers();
+};
+
+#endif // JSON_H
index b7a7495..7c7115a 100644 (file)
@@ -10,7 +10,8 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
-#include <setupdialog.h>
+#include "setupdialog.h"
+#include "json.h"
 
 #include <QtCore/QCoreApplication>
 
index c95f830..afbc8a2 100644 (file)
@@ -18,11 +18,15 @@ symbian:TARGET.UID3 = 0xED8FBFF1
 # CONFIG += mobility
 # MOBILITY +=
 
+TARGET = xbmcnetmoviesremote
+
 SOURCES += main.cpp mainwindow.cpp \
-    setupdialog.cpp
+    setupdialog.cpp \
+    json.cpp
 HEADERS += mainwindow.h \
     setupdialog.h \
-    constants.h
+    constants.h \
+    json.h
 FORMS += mainwindow.ui \
     setupdialog.ui
 
diff --git a/test-json/main.cpp b/test-json/main.cpp
new file mode 100644 (file)
index 0000000..9e61ad3
--- /dev/null
@@ -0,0 +1,54 @@
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+
+#include "../src/json.h"
+
+class JsonTest : public QObject
+{
+    Q_OBJECT
+
+public:
+    JsonTest();
+
+private Q_SLOTS:
+//    void initTestCase();
+//    void cleanupTestCase();
+//    void testCase1();
+//    void testCase1_data();
+    void testPlayerGetActivePlayers();
+};
+
+JsonTest::JsonTest()
+{
+}
+
+//void JsonTest::initTestCase()
+//{
+//}
+
+//void JsonTest::cleanupTestCase()
+//{
+//}
+
+//void JsonTest::testCase1()
+//{
+//    QFETCH(QString, data);
+//    QVERIFY2(true, "Failure");
+//}
+
+//void JsonTest::testCase1_data()
+//{
+//    QTest::addColumn<QString>("data");
+//    QTest::newRow("0") << QString();
+//}
+
+QTEST_APPLESS_MAIN(JsonTest);
+
+void JsonTest::testPlayerGetActivePlayers()
+{
+    JsonEngine je;
+    QCOMPARE(QString("{\"jsonrpc\" : \"2.0\", \"method\" : \"Player.GetActivePlayers\", \"id\" : 1}"),
+             je.playerGetActivePlayers());
+}
+
+#include "main.moc"
diff --git a/test-json/test-json.pro b/test-json/test-json.pro
new file mode 100644 (file)
index 0000000..c51ddc1
--- /dev/null
@@ -0,0 +1,15 @@
+QT       += testlib
+QT       -= gui
+
+TARGET = test-json
+CONFIG   += console
+CONFIG   -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+    ../src/json.cpp
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+HEADERS += \
+    ../src/json.h