Commit 06b83eafe22e4df3d038ebd2be3160d925af1a83
1 parent
f3d2ba1e
Exists in
master
Refactor no metodo de pegarUsu.
Showing
2 changed files
with
5 additions
and
25 deletions
Show diff stats
cacic-teste/testcacic.cpp
| @@ -103,7 +103,7 @@ void CTestCacic::testpegarOS(){ | @@ -103,7 +103,7 @@ void CTestCacic::testpegarOS(){ | ||
| 103 | void CTestCacic::testPegarUsu(){ | 103 | void CTestCacic::testPegarUsu(){ |
| 104 | //lightbase = user do linux. | 104 | //lightbase = user do linux. |
| 105 | //Usuario = user da vm winxp. | 105 | //Usuario = user da vm winxp. |
| 106 | - QVERIFY(OCacicComp.getUser() == "lightbase" || OCacicComp.getUser() == "Usuario"); | 106 | + QVERIFY(OCacicComp.pegarUsu() == "thiroc80" || OCacicComp.pegarUsu() == "Usuario"); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void CTestCacic::testLogin(){ | 109 | void CTestCacic::testLogin(){ |
src/cacic_computer.cpp
| @@ -73,30 +73,10 @@ std::string CACIC_Computer::pegarUsu(){ | @@ -73,30 +73,10 @@ std::string CACIC_Computer::pegarUsu(){ | ||
| 73 | QString text; | 73 | QString text; |
| 74 | QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | 74 | QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); |
| 75 | foreach (text, environment) { | 75 | foreach (text, environment) { |
| 76 | - if (text.contains("USER=", Qt::CaseInsensitive)){ | ||
| 77 | - QString x = text; | ||
| 78 | - QString s = "USER="; | ||
| 79 | - QString e = "\""; | ||
| 80 | - int start = x.indexOf(s, 0, Qt::CaseInsensitive); | ||
| 81 | - int end = x.indexOf(e, Qt::CaseInsensitive); | ||
| 82 | - if(start != -1){ | ||
| 83 | - QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); | ||
| 84 | - //qDebug() << y; | ||
| 85 | - return y.toStdString(); | ||
| 86 | - } | ||
| 87 | - }else{ | ||
| 88 | - if (text.contains("USERNAME=", Qt::CaseInsensitive)){ | ||
| 89 | - QString x = text; | ||
| 90 | - QString s = "USERNAME="; | ||
| 91 | - QString e = "\""; | ||
| 92 | - int start = x.indexOf(s, 0, Qt::CaseInsensitive); | ||
| 93 | - int end = x.indexOf(e, Qt::CaseInsensitive); | ||
| 94 | - if(start != -1){ | ||
| 95 | - QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); | ||
| 96 | - // qDebug() << y; | ||
| 97 | - return y.toStdString(); | ||
| 98 | - } | ||
| 99 | - } | 76 | + if (text.contains("USER=", Qt::CaseInsensitive) |
| 77 | + || text.contains("USERNAME=", Qt::CaseInsensitive) ){ | ||
| 78 | + QStringList split = text.split("="); | ||
| 79 | + return split[1].toStdString(); | ||
| 100 | } | 80 | } |
| 101 | } | 81 | } |
| 102 | return false; | 82 | return false; |