Commit 06b83eafe22e4df3d038ebd2be3160d925af1a83

Authored by Thiago Rocha
1 parent f3d2ba1e
Exists in master

Refactor no metodo de pegarUsu.

cacic-teste/testcacic.cpp
... ... @@ -103,7 +103,7 @@ void CTestCacic::testpegarOS(){
103 103 void CTestCacic::testPegarUsu(){
104 104 //lightbase = user do linux.
105 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 109 void CTestCacic::testLogin(){
... ...
src/cacic_computer.cpp
... ... @@ -73,30 +73,10 @@ std::string CACIC_Computer::pegarUsu(){
73 73 QString text;
74 74 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
75 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 82 return false;
... ...