Commit 3526feddc7be558fe141507f980c4ebe6af2b32e
1 parent
f9bf9177
Exists in
master
Novo teste de getValuesFromRegistry.
Showing
6 changed files
with
26 additions
and
30 deletions
Show diff stats
cacic-teste/testcacic.cpp
| @@ -105,6 +105,7 @@ void CTestCacic::testConsole() | @@ -105,6 +105,7 @@ void CTestCacic::testConsole() | ||
| 105 | #if defined(Q_OS_LINUX) | 105 | #if defined(Q_OS_LINUX) |
| 106 | QVERIFY(console("echo teste").toStdString() == "teste\n"); | 106 | QVERIFY(console("echo teste").toStdString() == "teste\n"); |
| 107 | #elif defined(Q_OS_WIN) | 107 | #elif defined(Q_OS_WIN) |
| 108 | + qDebug() << console("echo teste"); | ||
| 108 | QVERIFY(console("echo teste").toStdString() == "teste"); | 109 | QVERIFY(console("echo teste").toStdString() == "teste"); |
| 109 | #else | 110 | #else |
| 110 | QVERIFY(false); | 111 | QVERIFY(false); |
| @@ -154,26 +155,6 @@ void CTestCacic::testDeCrypt(){ | @@ -154,26 +155,6 @@ void CTestCacic::testDeCrypt(){ | ||
| 154 | 155 | ||
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | -void CTestCacic::testInstallCacicStart() | ||
| 158 | -{ | ||
| 159 | -// char *argva[] = {"program name", "-host=teste.cacic.cpp", "-user=asda", "-password=qwesd", NULL}; | ||
| 160 | -// int argca = sizeof(argva) / sizeof(char*) - 1; | ||
| 161 | -// QCoreApplication a(argca, argva); | ||
| 162 | - | ||
| 163 | -// InstallCacic *oInstallCacic = new InstallCacic(&a); | ||
| 164 | - | ||
| 165 | -// QStringList args; | ||
| 166 | -// for (int i = 0; i<argca; i++) | ||
| 167 | -// args.append(argva[i]); | ||
| 168 | -// // This will cause the application to exit when | ||
| 169 | -// // the task signals finished. | ||
| 170 | -// QObject::connect(oInstallCacic, SIGNAL(finished()), &a, SLOT(quit())); | ||
| 171 | - | ||
| 172 | -// // This will run the task from the application event loop. | ||
| 173 | -// QMetaObject::invokeMethod(oInstallCacic, "run", Qt::QueuedConnection, Q_ARG(QStringList, args), Q_ARG(int, argca)); | ||
| 174 | - QVERIFY(false); | ||
| 175 | -} | ||
| 176 | - | ||
| 177 | void CTestCacic::testCacicCompToJsonObject() | 158 | void CTestCacic::testCacicCompToJsonObject() |
| 178 | { | 159 | { |
| 179 | // qDebug() << OCacicComp.toJsonObject(); | 160 | // qDebug() << OCacicComp.toJsonObject(); |
| @@ -204,7 +185,7 @@ void CTestCacic::testStartService() | @@ -204,7 +185,7 @@ void CTestCacic::testStartService() | ||
| 204 | #ifdef Q_OS_WIN | 185 | #ifdef Q_OS_WIN |
| 205 | exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic.exe", true, &ok); | 186 | exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic.exe", true, &ok); |
| 206 | #else | 187 | #else |
| 207 | - exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic", &ok); | 188 | + exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic", true, &ok); |
| 208 | #endif | 189 | #endif |
| 209 | QVERIFY(ok); | 190 | QVERIFY(ok); |
| 210 | } | 191 | } |
| @@ -238,6 +219,11 @@ void CTestCacic::testSetRegistry() | @@ -238,6 +219,11 @@ void CTestCacic::testSetRegistry() | ||
| 238 | QVERIFY(confirmaTeste.value("teste1") == QVariant("Teste 1")); | 219 | QVERIFY(confirmaTeste.value("teste1") == QVariant("Teste 1")); |
| 239 | } | 220 | } |
| 240 | 221 | ||
| 222 | +void CTestCacic::testGetValueFromRegistry() | ||
| 223 | +{ | ||
| 224 | + QVERIFY(OCacic.getValueFromRegistry("Lightbase", "Teste", "teste1") == QVariant("Teste 1")); | ||
| 225 | +} | ||
| 226 | + | ||
| 241 | void CTestCacic::testRemoveRegistry() | 227 | void CTestCacic::testRemoveRegistry() |
| 242 | { | 228 | { |
| 243 | OCacic.removeRegistry("Lightbase", "Teste"); | 229 | OCacic.removeRegistry("Lightbase", "Teste"); |
cacic-teste/testcacic.h
| @@ -55,7 +55,6 @@ private slots: | @@ -55,7 +55,6 @@ private slots: | ||
| 55 | void testSslConnection(); | 55 | void testSslConnection(); |
| 56 | void testEnCrypt(); | 56 | void testEnCrypt(); |
| 57 | void testDeCrypt(); | 57 | void testDeCrypt(); |
| 58 | - void testInstallCacicStart(); | ||
| 59 | void testCacicCompToJsonObject(); | 58 | void testCacicCompToJsonObject(); |
| 60 | void testOperatingSystemToJsonObject(); | 59 | void testOperatingSystemToJsonObject(); |
| 61 | void testJsonToFile(); | 60 | void testJsonToFile(); |
| @@ -63,6 +62,7 @@ private slots: | @@ -63,6 +62,7 @@ private slots: | ||
| 63 | void testStartService(); | 62 | void testStartService(); |
| 64 | void testReadConfig(); | 63 | void testReadConfig(); |
| 65 | void testSetRegistry(); | 64 | void testSetRegistry(); |
| 65 | + void testGetValueFromRegistry(); | ||
| 66 | void testRemoveRegistry(); | 66 | void testRemoveRegistry(); |
| 67 | void cleanupTestCase(); | 67 | void cleanupTestCase(); |
| 68 | }; | 68 | }; |
install-cacic/install-cacic.pro.user
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE QtCreatorProject> | 2 | <!DOCTYPE QtCreatorProject> |
| 3 | -<!-- Written by QtCreator 3.1.2, 2014-08-15T20:38:37. --> | 3 | +<!-- Written by QtCreator 3.1.2, 2014-08-18T11:08:49. --> |
| 4 | <qtcreator> | 4 | <qtcreator> |
| 5 | <data> | 5 | <data> |
| 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
| @@ -224,7 +224,7 @@ | @@ -224,7 +224,7 @@ | ||
| 224 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-uninstall</value> | 224 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-uninstall</value> |
| 225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> | 225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> |
| 226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> | 226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
| 227 | - <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> | 227 | + <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value> |
| 228 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> | 228 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> |
| 229 | <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> | 229 | <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> |
| 230 | <value type="bool" key="RunConfiguration.UseCppDebugger">false</value> | 230 | <value type="bool" key="RunConfiguration.UseCppDebugger">false</value> |
install-cacic/installcacic.cpp
| @@ -19,24 +19,27 @@ void InstallCacic::run(QStringList argv, int argc) { | @@ -19,24 +19,27 @@ void InstallCacic::run(QStringList argv, int argc) { | ||
| 19 | if (ok){ | 19 | if (ok){ |
| 20 | //conectado, grava a chave na classe; | 20 | //conectado, grava a chave na classe; |
| 21 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); | 21 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); |
| 22 | +#ifdef Q_OS_WIN | ||
| 22 | oCacic.setCacicMainFolder("c:/cacic"); | 23 | oCacic.setCacicMainFolder("c:/cacic"); |
| 24 | +#elif Q_LINUX | ||
| 25 | + oCacic.setCacicMainFolder("/home/cacic"); | ||
| 26 | +#endif | ||
| 23 | oCacic.createFolder(oCacic.getCacicMainFolder()); | 27 | oCacic.createFolder(oCacic.getCacicMainFolder()); |
| 24 | //grava chave em registro; | 28 | //grava chave em registro; |
| 25 | 29 | ||
| 26 | QVariantMap registro; | 30 | QVariantMap registro; |
| 27 | registro["key"] = oCacic.getChaveCrypt(); | 31 | registro["key"] = oCacic.getChaveCrypt(); |
| 32 | + registro["mainFolder"] = oCacic.getCacicMainFolder(); | ||
| 28 | oCacic.setValueToRegistry("Lightbase", "Cacic", registro); | 33 | oCacic.setValueToRegistry("Lightbase", "Cacic", registro); |
| 29 | //starta o processo do cacic. | 34 | //starta o processo do cacic. |
| 30 | #ifdef Q_OS_WIN | 35 | #ifdef Q_OS_WIN |
| 31 | - QString exitStatus = oCacic.startProcess("cacic.exe", true, &ok); | ||
| 32 | - if (!ok) | ||
| 33 | - std::cout << "Erro ao iniciar o processo: " | ||
| 34 | - << exitStatus.toStdString() << "\n"; | 36 | + QString exitStatus = oCacic.startProcess(oCacic.getCacicMainFolder() + "cacic.exe", true, &ok); |
| 35 | #else | 37 | #else |
| 36 | oCacic.startProcess("cacic.exe", true, &ok); | 38 | oCacic.startProcess("cacic.exe", true, &ok); |
| 37 | - if (!ok) | ||
| 38 | - qDebug() << "Erro ao iniciar o processo."; | ||
| 39 | #endif | 39 | #endif |
| 40 | + if (!ok) | ||
| 41 | + std::cout << "Erro ao iniciar o processo: " | ||
| 42 | + << exitStatus.toStdString() << "\n"; | ||
| 40 | } else | 43 | } else |
| 41 | std::cout << "Nao foi possivel realizar o login.\n " | 44 | std::cout << "Nao foi possivel realizar o login.\n " |
| 42 | << jsonLogin["error"].toString().toStdString(); | 45 | << jsonLogin["error"].toString().toStdString(); |
src/ccacic.cpp
| @@ -216,6 +216,12 @@ void CCacic::setValueToRegistry(QString organization, QString application, QVari | @@ -216,6 +216,12 @@ void CCacic::setValueToRegistry(QString organization, QString application, QVari | ||
| 216 | registry.sync(); | 216 | registry.sync(); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | +QVariant CCacic::getValueFromRegistry(QString organization, QString application, QString key) | ||
| 220 | +{ | ||
| 221 | + QSettings registry(organization, application); | ||
| 222 | + return registry.value(key); | ||
| 223 | +} | ||
| 224 | + | ||
| 219 | void CCacic::removeRegistry(QString organization, QString application) | 225 | void CCacic::removeRegistry(QString organization, QString application) |
| 220 | { | 226 | { |
| 221 | QSettings registry(organization, application); | 227 | QSettings registry(organization, application); |
src/ccacic.h
| @@ -37,6 +37,7 @@ public: | @@ -37,6 +37,7 @@ public: | ||
| 37 | QJsonObject getJsonFromFile(QString filepath); | 37 | QJsonObject getJsonFromFile(QString filepath); |
| 38 | QString startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments = QStringList()); | 38 | QString startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments = QStringList()); |
| 39 | void setValueToRegistry(QString organization, QString application, QVariantMap values); | 39 | void setValueToRegistry(QString organization, QString application, QVariantMap values); |
| 40 | + QVariant getValueFromRegistry(QString organization, QString application, QString key); | ||
| 40 | void removeRegistry(QString organization, QString application); | 41 | void removeRegistry(QString organization, QString application); |
| 41 | 42 | ||
| 42 | 43 |