From 4b90b2fb8b5c2d9ec1d8a060360e58956dfadf6b Mon Sep 17 00:00:00 2001
From: "evgenii.tagiltsev" <tagiltsev.evgenii@gmail.com>
Date: Tue, 8 Oct 2019 19:08:26 +0200
Subject: [PATCH] [*] added test for checking QByteArray

---
 .../DapCommandController.cpp                  | 17 ++++++++++++++
 CellFrameDashboardGUI/DapCommandController.h  |  4 ++++
 .../DapChainDashboardService.cpp              | 14 ++++++++++++
 .../DapChainDashboardService.h                |  2 ++
 DapRPCProtocol/DapRpcLocalServer.cpp          |  2 +-
 DapRPCProtocol/DapRpcMessage.cpp              | 12 ++++++++++
 DapRPCProtocol/DapRpcMessage.h                | 11 +++++-----
 DapRPCProtocol/DapRpcService.cpp              | 22 ++++++++-----------
 8 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp
index 2942f0c90..d3673baf4 100755
--- a/CellFrameDashboardGUI/DapCommandController.cpp
+++ b/CellFrameDashboardGUI/DapCommandController.cpp
@@ -51,6 +51,7 @@ void DapCommandController::getHistory()
 {
     DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getHistory");
     connect(reply, SIGNAL(finished()), this, SLOT(processGetHistory()));
+
 }
 
 void DapCommandController::setNewHistory(const QVariant& aData)
@@ -70,6 +71,12 @@ void DapCommandController::getCmdHistory()
     connect(reply, SIGNAL(finished()), this, SLOT(processGetCmdHistory()));
 }
 
+void DapCommandController::getTest()
+{
+    DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getTest");
+    connect(reply, SIGNAL(finished()), this, SLOT(processGetTest()));
+}
+
 void DapCommandController::processChangedLog()
 {
 //    QStringList tempLogModel;
@@ -213,6 +220,14 @@ void DapCommandController::processGetCmdHistory()
     emit sigCmdHistory(result);
 }
 
+void DapCommandController::processGetTest()
+{
+    qDebug() << "!!!!!!!!processGetTest!!!!!!!!!!";
+    DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender());
+    QByteArray result = reply->response().result().toVariant().toByteArray();
+    qDebug() << result;
+}
+
 /// Show or hide GUI client by clicking on the tray icon.
 /// @param aIsActivated Accepts true - when requesting to 
 /// display a client, falso - when requesting to hide a client.
@@ -251,6 +266,8 @@ void DapCommandController::getWallets()
 {
     DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getWallets");
     connect(reply, SIGNAL(finished()), this, SLOT(processGetWallets()));
+    getTest();
+
 }
 
 void DapCommandController::getWalletInfo(const QString& asWalletName)
diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h
index 845f95cc6..2f6e3f0c5 100755
--- a/CellFrameDashboardGUI/DapCommandController.h
+++ b/CellFrameDashboardGUI/DapCommandController.h
@@ -84,6 +84,8 @@ private slots:
 
     void processGetCmdHistory();
 
+    void processGetTest();
+
 public slots:
     /// Show or hide GUI client by clicking on the tray icon.
     /// @param aIsActivated Accepts true - when requesting to 
@@ -119,6 +121,8 @@ public slots:
     void requestConsole(const QString& aQueue);
     /// Get command history
     void getCmdHistory();
+
+    void getTest();
 };
 
 #endif // COMMANDCONTROLLER_H
diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp
index fa588c86d..c98290f3e 100755
--- a/CellFrameDashboardService/DapChainDashboardService.cpp
+++ b/CellFrameDashboardService/DapChainDashboardService.cpp
@@ -100,6 +100,20 @@ QString DapChainDashboardService::getCmdHistory() const
     return m_pDapChainConsoleHandler->getHistory();
 }
 
+QByteArray DapChainDashboardService::getTest() const
+{
+    QByteArray data;
+    QDataStream out(&data, QIODevice::WriteOnly);
+
+    DapNodeData nodeData;
+    nodeData.Cell = 1;
+    nodeData.Ipv4 = "mua";
+
+    out << nodeData;
+
+    return data;
+}
+
 void DapChainDashboardService::doRequestWallets()
 {
     m_pDapChainHistoryHandler->onRequestNewHistory(m_pDapChainWalletHandler->getWallets());
diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h
index 6f1fe70bd..6844f6073 100755
--- a/CellFrameDashboardService/DapChainDashboardService.h
+++ b/CellFrameDashboardService/DapChainDashboardService.h
@@ -111,6 +111,8 @@ public slots:
     /// @return history of last 50 commands
     QString getCmdHistory() const;
 
+    QByteArray getTest() const;
+
 private slots:
     void doRequestWallets();
     void doSendNewHistory(const QVariant& aData);
diff --git a/DapRPCProtocol/DapRpcLocalServer.cpp b/DapRPCProtocol/DapRpcLocalServer.cpp
index 11a2e8423..bb1b65b3a 100644
--- a/DapRPCProtocol/DapRpcLocalServer.cpp
+++ b/DapRPCProtocol/DapRpcLocalServer.cpp
@@ -21,7 +21,7 @@ DapRpcLocalServer::~DapRpcLocalServer()
 
 bool DapRpcLocalServer::listen(const QString &asAddress, quint16 aPort)
 {
-    Q_UNUSED(aPort);
+    Q_UNUSED(aPort)
 
     return QLocalServer::listen(asAddress);
 }
diff --git a/DapRPCProtocol/DapRpcMessage.cpp b/DapRPCProtocol/DapRpcMessage.cpp
index d07901ba3..43aba8e7b 100644
--- a/DapRPCProtocol/DapRpcMessage.cpp
+++ b/DapRPCProtocol/DapRpcMessage.cpp
@@ -204,6 +204,12 @@ DapRpcMessage DapRpcMessage::createRequest(const QString &asMethod,
     return request;
 }
 
+DapRpcMessage DapRpcMessage::createRequest(const QString& asMethod, const QByteArray& aStream)
+{
+    DapRpcMessage request = createRequest(asMethod, QJsonValue::fromVariant(aStream));
+    return request;
+}
+
 DapRpcMessage DapRpcMessage::createNotification(const QString &asMethod, const QJsonArray &aParams)
 {
     DapRpcMessage notification = DapRpcMessagePrivate::createBasicRequest(asMethod, aParams);
@@ -227,6 +233,12 @@ DapRpcMessage DapRpcMessage::createNotification(const QString &asMethod,
     return notification;
 }
 
+DapRpcMessage DapRpcMessage::createNotification(const QString& asMethod, const QByteArray& aStream)
+{
+    DapRpcMessage notification = createNotification(asMethod, QJsonValue::fromVariant(aStream));
+    return notification;
+}
+
 DapRpcMessage DapRpcMessage::createResponse(const QJsonValue &aResult) const
 {
     DapRpcMessage response;
diff --git a/DapRPCProtocol/DapRpcMessage.h b/DapRPCProtocol/DapRpcMessage.h
index 92b47aaa6..dc3164b40 100644
--- a/DapRPCProtocol/DapRpcMessage.h
+++ b/DapRPCProtocol/DapRpcMessage.h
@@ -47,16 +47,15 @@ public:
         Error
     };
 
-    static DapRpcMessage createRequest(const QString &asMethod,
-                                         const QJsonArray &aParams = QJsonArray());
+    static DapRpcMessage createRequest(const QString &asMethod, const QJsonArray &aParams = QJsonArray());
     static DapRpcMessage createRequest(const QString &asMethod, const QJsonValue &aParam);
     static DapRpcMessage createRequest(const QString &asMethod, const QJsonObject &aNamedParameters);
+    static DapRpcMessage createRequest(const QString &asMethod, const QByteArray& aStream);
 
-    static DapRpcMessage createNotification(const QString &asMethod,
-                                              const QJsonArray &aParams = QJsonArray());
+    static DapRpcMessage createNotification(const QString &asMethod, const QJsonArray &aParams = QJsonArray());
     static DapRpcMessage createNotification(const QString &asMethod, const QJsonValue &aParam);
-    static DapRpcMessage createNotification(const QString &asMethod,
-                                              const QJsonObject &aNamedParameters);
+    static DapRpcMessage createNotification(const QString &asMethod, const QJsonObject &aNamedParameters);
+    static DapRpcMessage createNotification(const QString &asMethod, const QByteArray& aStream);
 
     DapRpcMessage createResponse(const QJsonValue &aResult) const;
     DapRpcMessage createErrorResponse(DapErrorCode aCode,
diff --git a/DapRPCProtocol/DapRpcService.cpp b/DapRPCProtocol/DapRpcService.cpp
index 7159d4acc..34aad0f9c 100644
--- a/DapRPCProtocol/DapRpcService.cpp
+++ b/DapRPCProtocol/DapRpcService.cpp
@@ -93,19 +93,14 @@ int DapRpcService::convertVariantTypeToJSType(int aType)
     case QMetaType::ULongLong:
     case QMetaType::UShort:
     case QMetaType::UChar:
-    case QMetaType::Float:
-        return QJsonValue::Double;    // all numeric types in js are doubles
+        case QMetaType::QByteArray:
+    case QMetaType::Float: return QJsonValue::Double;    // all numeric types in js are doubles
     case QMetaType::QVariantList:
-    case QMetaType::QStringList:
-        return QJsonValue::Array;
-    case QMetaType::QVariantMap:
-        return QJsonValue::Object;
-    case QMetaType::QString:
-        return QJsonValue::String;
-    case QMetaType::Bool:
-        return QJsonValue::Bool;
-    default:
-        break;
+    case QMetaType::QStringList: return QJsonValue::Array;
+    case QMetaType::QVariantMap: return QJsonValue::Object;
+    case QMetaType::QString: return QJsonValue::String;
+    case QMetaType::Bool: return QJsonValue::Bool;
+    default: break;
     }
 
     return QJsonValue::Undefined;
@@ -217,7 +212,7 @@ QJsonValue DapRpcService::convertReturnValue(QVariant &aReturnValue)
     else if (static_cast<int>(aReturnValue.type()) == qMetaTypeId<QJsonArray>())
         return QJsonValue(aReturnValue.toJsonArray());
 
-    switch (aReturnValue.type()) {
+    switch (static_cast<QMetaType::Type>(aReturnValue.type())) {
     case QMetaType::Bool:
     case QMetaType::Int:
     case QMetaType::Double:
@@ -228,6 +223,7 @@ QJsonValue DapRpcService::convertReturnValue(QVariant &aReturnValue)
     case QMetaType::QStringList:
     case QMetaType::QVariantList:
     case QMetaType::QVariantMap:
+    case QMetaType::QByteArray:
         return QJsonValue::fromVariant(aReturnValue);
     default:
         // if a conversion operator was registered it will be used
-- 
GitLab