Commit b281f0310b222790bded8e996f3029a56c3dca1a
1 parent
611eaf16
Exists in
master
Caciccomm: QObject agora retornando codestatus;
- Retornando o retorno em "reply" e, se houver erro, em "error"; testecacic: ajustado para os retornos diferentes na comunicação.
Showing
4 changed files
with
36 additions
and
36 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -55,10 +55,10 @@ void CTestCacic::testCommStatus() |
55 | 55 | |
56 | 56 | void CTestCacic::testComm() |
57 | 57 | { |
58 | - | |
59 | - if (OCacicComm.commStatus()) | |
60 | - QVERIFY(OCacic.getValueFromTags(OCacicComm.comm("/ws/get/test"), "Comm_Status", "<>") == QString("OK")); | |
61 | - else | |
58 | + if (OCacicComm.commStatus()){ | |
59 | + QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); | |
60 | + QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); | |
61 | + } else | |
62 | 62 | QSKIP("Teste de comunicação negativo!"); |
63 | 63 | } |
64 | 64 | |
... | ... | @@ -103,8 +103,9 @@ void CTestCacic::testpegarOS(){ |
103 | 103 | |
104 | 104 | void CTestCacic::testLogin(){ |
105 | 105 | QJsonObject sessionjson = OCacicComm.login(); |
106 | - QJsonValue session_str = sessionjson["session"]; | |
107 | - QVERIFY(session_str.isString()); | |
106 | + QJsonValue session_str = sessionjson["codestatus"]; | |
107 | +// qDebug() << session_str.toVariant().toString(); | |
108 | + QVERIFY(!session_str.isNull()); | |
108 | 109 | } |
109 | 110 | |
110 | 111 | void CTestCacic::cleanupTestCase() | ... | ... |
cacic-teste/testcacic.h
src/cacic_comm.h
... | ... | @@ -51,18 +51,24 @@ public: |
51 | 51 | params.addQueryItem("te_versao_gercols",gercolsVersion); |
52 | 52 | } |
53 | 53 | |
54 | - QJsonObject comm(QString route, const QJsonObject &json) | |
54 | + QJsonObject comm(QString route, const QJsonObject &json = QJsonObject()) | |
55 | 55 | { |
56 | - QString retorno = "0"; | |
57 | 56 | QByteArray data; |
58 | 57 | QUrl url = urlGerente + route; |
59 | - | |
60 | - //data.append(params.toString()); | |
61 | - | |
62 | - // Add JSON | |
63 | - QJsonDocument d(json); | |
64 | - data.append(d.toVariant().toString()); | |
65 | - | |
58 | + QNetworkRequest req(url); | |
59 | + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); | |
60 | + if (json.empty()) | |
61 | + { | |
62 | + //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) | |
63 | + req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | |
64 | + data.append(params.toString()); | |
65 | + } else { | |
66 | + // Add JSON | |
67 | + QJsonDocument d(json); | |
68 | + data.append(d.toVariant().toString()); | |
69 | + req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | |
70 | + } | |
71 | +// qDebug() << QString::fromUtf8(d.toJson().trimmed()); | |
66 | 72 | // cria um event-loop temporario |
67 | 73 | QEventLoop eventLoop; |
68 | 74 | // "quit()" o event-loop, when the network request "finished()" |
... | ... | @@ -70,36 +76,30 @@ public: |
70 | 76 | QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); |
71 | 77 | |
72 | 78 | // a requisição HTTP |
73 | - QNetworkRequest req(url); | |
74 | - req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | |
75 | - req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); | |
76 | 79 | |
77 | 80 | QNetworkReply *reply = mgr.post(req, data); |
78 | 81 | eventLoop.exec(); // sai do looping chamando o "finished()". |
79 | 82 | |
80 | - if (reply->error() == QNetworkReply::NoError) { | |
83 | + QVariantMap replyValue; | |
84 | + replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); | |
81 | 85 | |
86 | + if (reply->error() == QNetworkReply::NoError) { | |
82 | 87 | QString strReply = (QString)reply->readAll(); |
83 | - | |
88 | + replyValue["reply"] = strReply; | |
84 | 89 | //parse json |
85 | - qDebug() << "Response:" << strReply; | |
86 | - QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); | |
87 | - | |
88 | - QJsonObject jsonObj = jsonResponse.object(); | |
89 | - | |
90 | - //qDebug() << "Time:" << jsonObj["time"].toString(); | |
91 | - //qDebug() << "Date:" << jsonObj["date"].toString(); | |
90 | +// qDebug() << "Response:" << strReply; | |
92 | 91 | |
93 | 92 | delete reply; |
94 | - | |
95 | - return jsonObj; | |
96 | 93 | } else { |
97 | 94 | //failure |
98 | - qDebug() << "Failure" <<reply->errorString(); | |
95 | +// qDebug() << "Failure" <<reply->errorString(); | |
96 | + replyValue["error"] = reply->errorString(); | |
99 | 97 | delete reply; |
100 | 98 | |
101 | - return QJsonObject (); | |
99 | + | |
102 | 100 | } |
101 | + QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue); | |
102 | + return jsonObj; | |
103 | 103 | } |
104 | 104 | |
105 | 105 | |
... | ... | @@ -122,11 +122,11 @@ public: |
122 | 122 | |
123 | 123 | QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); |
124 | 124 | if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){ |
125 | - qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason; | |
125 | +// qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason; | |
126 | 126 | return true; |
127 | 127 | }else{ |
128 | 128 | reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); |
129 | - // qDebug() << "Error:" << reason; | |
129 | +// qDebug() << "Error:" << reason; | |
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | } |
... | ... | @@ -139,7 +139,7 @@ public: |
139 | 139 | QJsonObject loginJson = QJsonObject::fromVariantMap(loginMap); |
140 | 140 | |
141 | 141 | // Cria conexão e retorna Json da sessão |
142 | - QJsonObject retorno = this->comm("login", loginJson); | |
142 | + QJsonObject retorno = this->comm("/ws/get/test", loginJson); | |
143 | 143 | |
144 | 144 | return retorno; |
145 | 145 | ... | ... |
src/cacic_computer.cpp
... | ... | @@ -52,7 +52,7 @@ std::string CACIC_Computer::pegarOS(){ |
52 | 52 | foreach (text, environment) { |
53 | 53 | if (text.contains("OS=", Qt::CaseInsensitive)){ |
54 | 54 | if ((QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8) && |
55 | - (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8_1)) | |
55 | + (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8_1)); | |
56 | 56 | // qDebug () << "win 8"; |
57 | 57 | else if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8_1) |
58 | 58 | // qDebug() << "win 8.1"; | ... | ... |