Commit 8a891b95dd1543acaf749699334b602a5fc64229

Authored by Eric Menezes Noronha
1 parent 4b0fdcf6
Exists in master

Pequenas modificações de refinamento

cacic-teste/testcacic.cpp
@@ -29,9 +29,9 @@ void CTestCacic::initTestCase() @@ -29,9 +29,9 @@ void CTestCacic::initTestCase()
29 OCacicComm.setPassword("cacic123"); 29 OCacicComm.setPassword("cacic123");
30 this->testPath = QDir::currentPath() + "/teste"; 30 this->testPath = QDir::currentPath() + "/teste";
31 this->testIniPath = testPath + "/teste.ini"; 31 this->testIniPath = testPath + "/teste.ini";
32 - QVariantMap json;  
33 - json["session"] = "lakdhfalkfhsaklfhasfhsl";  
34 - this->session = QJsonObject::fromVariantMap(json); 32 + QVariantMap jsonMap;
  33 + jsonMap["session"] = "lakdhfalkfhsaklfhasfhsl";
  34 + this->session = QJsonObject::fromVariantMap(jsonMap);
35 } 35 }
36 36
37 void CTestCacic::testCreateFolder() 37 void CTestCacic::testCreateFolder()
@@ -60,6 +60,7 @@ void CTestCacic::testComm() @@ -60,6 +60,7 @@ void CTestCacic::testComm()
60 { 60 {
61 if (OCacicComm.commStatus()){ 61 if (OCacicComm.commStatus()){
62 QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); 62 QJsonObject jsonreply = OCacicComm.comm("/ws/get/test");
  63 +// qDebug() << jsonreply["codestatus"].toString();
63 QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); 64 QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK"));
64 } else 65 } else
65 QSKIP("Teste de comunicação negativo!"); 66 QSKIP("Teste de comunicação negativo!");
@@ -89,7 +90,7 @@ void CTestCacic::testpegarOS(){ @@ -89,7 +90,7 @@ void CTestCacic::testpegarOS(){
89 } 90 }
90 91
91 void CTestCacic::testPegarUsu(){ 92 void CTestCacic::testPegarUsu(){
92 - QVERIFY(OCacicComp.getUser() != "0"); 93 + QVERIFY(OCacicComp.getUsuario() != "");
93 } 94 }
94 95
95 void CTestCacic::testJsonValueFromJsonString() 96 void CTestCacic::testJsonValueFromJsonString()
@@ -98,9 +99,10 @@ void CTestCacic::testJsonValueFromJsonString() @@ -98,9 +99,10 @@ void CTestCacic::testJsonValueFromJsonString()
98 } 99 }
99 100
100 void CTestCacic::testLogin(){ 101 void CTestCacic::testLogin(){
101 - QJsonObject json = OCacicComm.login();  
102 - QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session");  
103 - qDebug() << sessionvalue.toString(); 102 + QJsonObject jsonReply = OCacicComm.login();
  103 +// QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session");
  104 + QJsonValue sessionvalue = jsonReply["reply"];
  105 +// qDebug() << sessionvalue.toString();
104 QVERIFY(!sessionvalue.isNull()); 106 QVERIFY(!sessionvalue.isNull());
105 } 107 }
106 108
@@ -108,8 +110,7 @@ void CTestCacic::testSslConnection() @@ -108,8 +110,7 @@ void CTestCacic::testSslConnection()
108 { 110 {
109 QJsonObject json = OCacicComm.comm("", QJsonObject(), true); 111 QJsonObject json = OCacicComm.comm("", QJsonObject(), true);
110 QJsonValue jsonvalue = json["codestatus"]; 112 QJsonValue jsonvalue = json["codestatus"];
111 -// qDebug() << jsonvalue.toString();  
112 - QVERIFY(jsonvalue.toString() == "200" || jsonvalue.toString() == "302"); 113 + QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302);
113 } 114 }
114 115
115 void CTestCacic::testEnCrypt(){ 116 void CTestCacic::testEnCrypt(){
src/cacic_comm.h
@@ -58,6 +58,8 @@ public: @@ -58,6 +58,8 @@ public:
58 QByteArray data; 58 QByteArray data;
59 QNetworkRequest req; 59 QNetworkRequest req;
60 QUrl url; 60 QUrl url;
  61 + QString strReply;
  62 + QJsonObject jsonObj;
61 if (isSsl){ 63 if (isSsl){
62 url = urlSsl + route; 64 url = urlSsl + route;
63 req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); 65 req.setSslConfiguration(QSslConfiguration::defaultConfiguration());
@@ -91,28 +93,27 @@ public: @@ -91,28 +93,27 @@ public:
91 reply->ignoreSslErrors(); 93 reply->ignoreSslErrors();
92 } 94 }
93 eventLoop.exec(); // sai do looping chamando o "finished()". 95 eventLoop.exec(); // sai do looping chamando o "finished()".
94 - QVariantMap replyValue;  
95 - //grava o código de retorno  
96 - replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); 96 + //grava codigo de retorno
  97 + jsonObj.insert("codestatus", QJsonValue::fromVariant(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute)));
97 // qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); 98 // qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
98 99
99 if (reply->error() == QNetworkReply::NoError) { 100 if (reply->error() == QNetworkReply::NoError) {
100 //se não houver erro, grava o retorno; 101 //se não houver erro, grava o retorno;
101 - QString strReply = (QString)reply->readAll();  
102 - replyValue["reply"] = strReply; 102 + strReply = (QString)reply->readAll();
  103 + jsonObj["reply"] = strReply;
103 // qDebug() << "Response:" << strReply; 104 // qDebug() << "Response:" << strReply;
104 105
105 delete reply; 106 delete reply;
106 } else { 107 } else {
107 //failure 108 //failure
108 // qDebug() << "Failure" <<reply->errorString(); 109 // qDebug() << "Failure" <<reply->errorString();
109 - replyValue["error"] = reply->errorString(); 110 + strReply = reply->errorString();
  111 + jsonObj.insert("error", QJsonValue::fromVariant(strReply));
110 delete reply; 112 delete reply;
111 113
112 114
113 } 115 }
114 //retorna o json; 116 //retorna o json;
115 - QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue);  
116 return jsonObj; 117 return jsonObj;
117 } 118 }
118 119
@@ -158,7 +159,8 @@ public: @@ -158,7 +159,8 @@ public:
158 login["password"] = this->password; 159 login["password"] = this->password;
159 // QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); 160 // QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session");
160 // Cria conexão e retorna Json da sessão 161 // Cria conexão e retorna Json da sessão
161 - return this->comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true); 162 + QJsonObject retorno = this->comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true);
  163 + return retorno;
162 } 164 }
163 165
164 QString getUrlSsl (){ 166 QString getUrlSsl (){
src/cacic_computer.cpp
@@ -4,7 +4,7 @@ CACIC_Computer::CACIC_Computer() @@ -4,7 +4,7 @@ CACIC_Computer::CACIC_Computer()
4 { 4 {
5 os = pegarOS(); 5 os = pegarOS();
6 networkInterface = networkInterfacesRunning(); 6 networkInterface = networkInterfacesRunning();
7 - usu = pegarUsu(); 7 + usuario = pegarUsu();
8 } 8 }
9 9
10 /*NetworkInterfacesRunning 10 /*NetworkInterfacesRunning
@@ -50,6 +50,26 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){ @@ -50,6 +50,26 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){
50 return listaMap; 50 return listaMap;
51 } 51 }
52 52
  53 +QJsonObject CACIC_Computer::toJsonObject()
  54 +{
  55 +// QJsonObject json;
  56 +// QJsonValue valor;
  57 +// QVariant aux;
  58 +// QJsonArray jsonArray;
  59 +// aux = this->os;
  60 +// valor.fromVariant(aux);
  61 +// json.insert("so", valor);
  62 +// aux = this->usuario;
  63 +// valor.fromVariant(aux);
  64 +// json.insert("usuario", this->usuario);
  65 +// aux.clear();
  66 +// foreach(QVariantMap auxMap, this->getNetworkInterface()){
  67 +// json.insert()
  68 +// }
  69 +
  70 +// json.insert("network", network);
  71 +}
  72 +
53 /*pegarOS 73 /*pegarOS
54 * @return: int; 74 * @return: int;
55 * retorna um id referente a versão do SO. 75 * retorna um id referente a versão do SO.
@@ -97,8 +117,8 @@ int CACIC_Computer::getOs() const @@ -97,8 +117,8 @@ int CACIC_Computer::getOs() const
97 return os; 117 return os;
98 } 118 }
99 119
100 -std::string CACIC_Computer::getUser() const {  
101 - return usu; 120 +std::string CACIC_Computer::getUsuario() const {
  121 + return usuario;
102 } 122 }
103 123
104 QList<QVariantMap> CACIC_Computer::getNetworkInterface() const 124 QList<QVariantMap> CACIC_Computer::getNetworkInterface() const
src/cacic_computer.h
@@ -16,14 +16,15 @@ public: @@ -16,14 +16,15 @@ public:
16 int pegarOS(); 16 int pegarOS();
17 std::string pegarUsu(); 17 std::string pegarUsu();
18 int getOs() const; 18 int getOs() const;
19 - std::string getUser() const; 19 + std::string getUsuario() const;
20 QList<QVariantMap> getNetworkInterface() const; 20 QList<QVariantMap> getNetworkInterface() const;
21 QList<QVariantMap> networkInterfacesRunning(); 21 QList<QVariantMap> networkInterfacesRunning();
  22 + QJsonObject toJsonObject();
22 23
23 private: 24 private:
24 QList<QVariantMap> networkInterface; 25 QList<QVariantMap> networkInterface;
25 int os; 26 int os;
26 - std::string usu; 27 + std::string usuario;
27 28
28 }; 29 };
29 30