Commit 1e98760087f0aae198423918644bf3333175d34a

Authored by Eric Menezes Noronha
1 parent 6533f577
Exists in master

Refaturando.

cacic-teste/testcacic.cpp
... ... @@ -97,13 +97,13 @@ void CTestCacic::testInterfaceDeRede(){
97 97 }
98 98  
99 99 void CTestCacic::testpegarOS(){
100   - QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux"));
  100 + QVERIFY(OCacicComp.getOs() != "0");
101 101 }
102 102  
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.getUser() != "0");
107 107 }
108 108  
109 109 void CTestCacic::testLogin(){
... ...
cacic-teste/testcacic.h
... ... @@ -46,6 +46,7 @@ private slots:
46 46 void testPegarUsu();
47 47 void testpegarOS();
48 48 void testLogin();
  49 + void testSslConnection();
49 50 void cleanupTestCase();
50 51 };
51 52  
... ...
src/cacic_computer.cpp
... ... @@ -48,19 +48,19 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){
48 48 *
49 49 */
50 50 std::string CACIC_Computer::pegarOS(){
51   - QString text;
52   - QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
53   - foreach (text, environment) {
54   - if (text.contains("OS=Win", Qt::CaseInsensitive)){
  51 + QString text;
  52 + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
  53 + foreach (text, environment) {
  54 + if (text.contains("OS=Win", Qt::CaseInsensitive)){
55 55 //qDebug() << "Windows_NT";
56   - return "Windows_NT";
57   - }else{
58   - if (text.contains("SESSION=", Qt::CaseInsensitive)){
59   - //qDebug() << "linux";
60   - return "linux";
61   - }
62   - }
  56 + return "Windows_NT";
  57 + } else if (text.contains("SESSION=", Qt::CaseInsensitive)){
  58 + //qDebug() << "linux";
  59 + return "linux";
  60 + } else
  61 + return "0"; //SO desconhecido.
63 62 }
  63 + return "0";
64 64 }
65 65  
66 66  
... ... @@ -70,38 +70,25 @@ std::string CACIC_Computer::pegarOS(){
70 70 * retorna uma string o qual dirá qual é o usuario logado no sistema.
71 71 */
72 72 std::string CACIC_Computer::pegarUsu(){
73   - QString text;
74   - QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
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   - }
100   - }
  73 + QString text, key;
  74 + std::string retorno;
  75 + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
  76 + foreach (text, environment) {
  77 + if (text.contains("USER=", Qt::CaseInsensitive))
  78 + key = "USER=";
  79 + else if (text.contains("USERNAME=", Qt::CaseInsensitive))
  80 + key = "USERNAME=";
  81 + else
  82 + continue;
  83 +
  84 + int keySize = key.size();
  85 +// qDebug() << text.mid(text.indexOf(key) + keySize);
  86 + retorno = text.mid(text.indexOf(key) + keySize).toStdString();
  87 + if (retorno != "")
  88 + return retorno;
101 89 }
102   - return false;
  90 + return "0";
103 91 }
104   -
105 92 /*
106 93 * getters/setters
107 94 */
... ...