diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 94ac276..373ca66 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -97,13 +97,13 @@ void CTestCacic::testInterfaceDeRede(){ } void CTestCacic::testpegarOS(){ - QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); + QVERIFY(OCacicComp.getOs() != "0"); } void CTestCacic::testPegarUsu(){ //lightbase = user do linux. //Usuario = user da vm winxp. - QVERIFY(OCacicComp.getUser() == "lightbase" || OCacicComp.getUser() == "Usuario"); + QVERIFY(OCacicComp.getUser() != "0"); } void CTestCacic::testLogin(){ diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index dd9958f..a4b3691 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -46,6 +46,7 @@ private slots: void testPegarUsu(); void testpegarOS(); void testLogin(); + void testSslConnection(); void cleanupTestCase(); }; diff --git a/src/cacic_computer.cpp b/src/cacic_computer.cpp index 0f73aa9..465dd80 100644 --- a/src/cacic_computer.cpp +++ b/src/cacic_computer.cpp @@ -48,19 +48,19 @@ QList> CACIC_Computer::networkInterfacesRunning(){ * */ std::string CACIC_Computer::pegarOS(){ - QString text; - QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); - foreach (text, environment) { - if (text.contains("OS=Win", Qt::CaseInsensitive)){ + QString text; + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); + foreach (text, environment) { + if (text.contains("OS=Win", Qt::CaseInsensitive)){ //qDebug() << "Windows_NT"; - return "Windows_NT"; - }else{ - if (text.contains("SESSION=", Qt::CaseInsensitive)){ - //qDebug() << "linux"; - return "linux"; - } - } + return "Windows_NT"; + } else if (text.contains("SESSION=", Qt::CaseInsensitive)){ + //qDebug() << "linux"; + return "linux"; + } else + return "0"; //SO desconhecido. } + return "0"; } @@ -70,38 +70,25 @@ std::string CACIC_Computer::pegarOS(){ * retorna uma string o qual dirá qual é o usuario logado no sistema. */ std::string CACIC_Computer::pegarUsu(){ - QString text; - QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); - foreach (text, environment) { - if (text.contains("USER=", Qt::CaseInsensitive)){ - QString x = text; - QString s = "USER="; - QString e = "\""; - int start = x.indexOf(s, 0, Qt::CaseInsensitive); - int end = x.indexOf(e, Qt::CaseInsensitive); - if(start != -1){ - QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); - //qDebug() << y; - return y.toStdString(); - } - }else{ - if (text.contains("USERNAME=", Qt::CaseInsensitive)){ - QString x = text; - QString s = "USERNAME="; - QString e = "\""; - int start = x.indexOf(s, 0, Qt::CaseInsensitive); - int end = x.indexOf(e, Qt::CaseInsensitive); - if(start != -1){ - QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); - // qDebug() << y; - return y.toStdString(); - } - } - } + QString text, key; + std::string retorno; + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); + foreach (text, environment) { + if (text.contains("USER=", Qt::CaseInsensitive)) + key = "USER="; + else if (text.contains("USERNAME=", Qt::CaseInsensitive)) + key = "USERNAME="; + else + continue; + + int keySize = key.size(); +// qDebug() << text.mid(text.indexOf(key) + keySize); + retorno = text.mid(text.indexOf(key) + keySize).toStdString(); + if (retorno != "") + return retorno; } - return false; + return "0"; } - /* * getters/setters */ -- libgit2 0.21.2