Commit 838ed1baeb8de3db1acb6b2634e8bd95453bb5d1

Authored by Eric Menezes Noronha
1 parent 845fdf99
Exists in master

Criacao do metodo para iniciar processo. Correcao do Json do computador. Pequenos refinamentos

cacic-teste/testcacic.cpp
... ... @@ -96,6 +96,8 @@ void CTestCacic::testConsole()
96 96 ConsoleObject console;
97 97 #if defined(Q_OS_LINUX)
98 98 QVERIFY(console("echo teste").toStdString() == "teste\n");
  99 +#elif defined(Q_OS_WIN)
  100 + QVERIFY(console("echo teste").toStdString() == "teste");
99 101 #else
100 102 QVERIFY(false);
101 103 #endif
... ... @@ -163,6 +165,7 @@ void CTestCacic::testInstallCacicStart()
163 165  
164 166 void CTestCacic::testCacicCompToJsonObject()
165 167 {
  168 +// qDebug() << OCacicComp.toJsonObject();
166 169 QVERIFY(!OCacicComp.toJsonObject().empty());
167 170 }
168 171  
... ... @@ -183,6 +186,18 @@ void CTestCacic::testJsonFromFile()
183 186 QVERIFY(OCacic.getJsonFromFile("teste.json")["teste"].toString() == "teste");
184 187 }
185 188  
  189 +void CTestCacic::testStartService()
  190 +{
  191 + bool ok;
  192 + QString exitStatus;
  193 +#ifdef Q_OS_WIN
  194 + exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic.exe", true, &ok);
  195 +#else
  196 + exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic", &ok);
  197 +#endif
  198 + QVERIFY(ok);
  199 +}
  200 +
186 201 void CTestCacic::cleanupTestCase()
187 202 {
188 203 OCacic.deleteFile("teste.json");
... ...
cacic-teste/testcacic.h
... ... @@ -57,6 +57,7 @@ private slots:
57 57 void testOperatingSystemToJsonObject();
58 58 void testJsonToFile();
59 59 void testJsonFromFile();
  60 + void testStartService();
60 61 void cleanupTestCase();
61 62 };
62 63  
... ...
install-cacic/install-cacic.pro.user
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <!DOCTYPE QtCreatorProject>
3   -<!-- Written by QtCreator 3.1.2, 2014-08-14T17:39:38. -->
  3 +<!-- Written by QtCreator 3.1.2, 2014-08-15T13:57:58. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
... ...
install-cacic/installcacic.cpp
... ... @@ -7,7 +7,6 @@ InstallCacic::InstallCacic(QObject *parent) :
7 7 }
8 8  
9 9 void InstallCacic::run(QStringList argv, int argc) {
10   - QMap<QString, QString> args;
11 10 bool ok;
12 11 //valida os parametros repassados
13 12 validaParametros(argv, argc, &ok);
... ... @@ -28,6 +27,18 @@ void InstallCacic::run(QStringList argv, int argc) {
28 27 configToSave["chaveCrypt"] = QJsonValue::fromVariant(oCacic.getChaveCrypt());
29 28 configJson["configs"] = configToSave;
30 29 oCacic.setJsonToFile(configJson, oCacic.getCacicMainFolder() + "/cacicTeste.json");
  30 +
  31 + //starta o processo do cacic.
  32 +#ifdef Q_OS_WIN
  33 + QString exitStatus = oCacic.startProcess("cacic.exe", true, &ok);
  34 + if (!ok)
  35 + std::cout << "Erro ao iniciar o processo: "
  36 + << exitStatus.toStdString() << "\n";
  37 +#else
  38 + oCacic.startProcess("cacic.exe", true, &ok);
  39 + if (!ok)
  40 + qDebug() << "Erro ao iniciar o processo.";
  41 +#endif
31 42 }
32 43 else
33 44 std::cout << "Nao foi possivel realizar o login.\n "
... ...
install-cacic/installcacic.h
... ... @@ -17,6 +17,7 @@ public:
17 17 QMap<QString, QString> getArgumentos();
18 18 void setArgumentos(QMap<QString, QString> value);
19 19 QMap<QString, QString> validaParametros(QStringList argv, int argc, bool *ok);
  20 + bool startProcess(QString pathprogram, bool wait, QStringList arguments);
20 21  
21 22 private:
22 23 QMap<QString, QString> argumentos;
... ...
src/cacic_computer.cpp
... ... @@ -52,12 +52,12 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){
52 52 QJsonObject CACIC_Computer::toJsonObject()
53 53 {
54 54 QJsonObject json;
55   - QJsonObject network;
  55 + QJsonArray network;
56 56 int count = 1;
57 57 json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario));
58 58 json["operatingSystem"] = this->oOperatingSystem.toJsonObject();
59 59 foreach(QVariantMap auxMap, this->getNetworkInterface()){
60   - network["network" + QVariant::fromValue(count).toString()] = QJsonObject::fromVariantMap(auxMap);
  60 + network.append(QJsonObject::fromVariantMap(auxMap));
61 61 count++;
62 62 }
63 63 json["networkDevices"] = network;
... ...
src/ccacic.cpp
... ... @@ -196,6 +196,13 @@ QString CCacic::deCrypt(std::string str_in, std::string iv) {
196 196 return QString::fromStdString(str_out);
197 197 }
198 198  
  199 +QString CCacic::startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments)
  200 +{
  201 + QProcess process;
  202 + arguments.empty() ? process.start(pathprogram) : process.start(pathprogram, arguments);
  203 + *ok = wait ? process.waitForFinished() : process.waitForStarted();
  204 + return process.errorString();
  205 +}
199 206  
200 207 /*Getters/Setters
201 208 * Begin:
... ...
src/ccacic.h
... ... @@ -2,6 +2,7 @@
2 2 #define CCACIC_H
3 3  
4 4 #include <QCoreApplication>
  5 +#include <QProcess>
5 6 #include <QObject>
6 7 #include <QFile>
7 8 #include <QSettings>
... ... @@ -34,6 +35,7 @@ public:
34 35 QJsonValue jsonValueFromJsonString(QString json, QString key);
35 36 bool setJsonToFile(QJsonObject json, QString filepath);
36 37 QJsonObject getJsonFromFile(QString filepath);
  38 + QString startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments = QStringList());
37 39  
38 40 //Geters/seters:
39 41  
... ...
src/console.h
... ... @@ -21,7 +21,7 @@ public:
21 21 options << "-c" << QString::fromStdString(input);
22 22 process->start("/bin/sh", options);
23 23 #elif defined(Q_OS_WIN)
24   - process->start(input);
  24 + process->start(QString::fromStdString(input));
25 25 #endif
26 26 process->waitForFinished();
27 27 QString output = process->readAll();
... ...
src/operatingsystem.cpp
... ... @@ -38,7 +38,7 @@ int OperatingSystem::coletaIdOs(){
38 38 }
39 39  
40 40 #else
41   - return 0;
  41 + return -1;
42 42 #endif
43 43 }
44 44  
... ...