Commit 3fbccd5972fcfa0d42eb173a6943abd5e0c1b3a8

Authored by Thiago Rocha
1 parent 8a891b95
Exists in master

Modificação em teste de getOs, e no metodo pegarOs.

cacic-teste/testcacic.cpp
@@ -86,11 +86,19 @@ void CTestCacic::testInterfaceDeRede(){ @@ -86,11 +86,19 @@ void CTestCacic::testInterfaceDeRede(){
86 } 86 }
87 87
88 void CTestCacic::testpegarOS(){ 88 void CTestCacic::testpegarOS(){
89 - QVERIFY(OCacicComp.getOs() != 0); 89 + QVERIFY(OCacicComp.getOs() == CACIC_Computer::WIN_XP ||
  90 + OCacicComp.getOs() == CACIC_Computer::WIN_VISTA ||
  91 + OCacicComp.getOs() == CACIC_Computer::WIN_7 ||
  92 + OCacicComp.getOs() == CACIC_Computer::WIN_8 ||
  93 + OCacicComp.getOs() == CACIC_Computer::WIN_8_1 ||
  94 + OCacicComp.getOs() == CACIC_Computer::MAC ||
  95 + OCacicComp.getOs() == CACIC_Computer::LINUX_DEBIAN ||
  96 + OCacicComp.getOs() == CACIC_Computer::LINUX_UBUNTU ||
  97 + OCacicComp.getOs() == CACIC_Computer::LINUX_ARCH );
90 } 98 }
91 99
92 void CTestCacic::testPegarUsu(){ 100 void CTestCacic::testPegarUsu(){
93 - QVERIFY(OCacicComp.getUsuario() != ""); 101 + QVERIFY(OCacicComp.getUser() != "");
94 } 102 }
95 103
96 void CTestCacic::testJsonValueFromJsonString() 104 void CTestCacic::testJsonValueFromJsonString()
@@ -110,6 +118,7 @@ void CTestCacic::testSslConnection() @@ -110,6 +118,7 @@ void CTestCacic::testSslConnection()
110 { 118 {
111 QJsonObject json = OCacicComm.comm("", QJsonObject(), true); 119 QJsonObject json = OCacicComm.comm("", QJsonObject(), true);
112 QJsonValue jsonvalue = json["codestatus"]; 120 QJsonValue jsonvalue = json["codestatus"];
  121 +// qDebug() << jsonvalue.toDouble();
113 QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); 122 QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302);
114 } 123 }
115 124
src/cacic_computer.cpp
@@ -70,24 +70,32 @@ QJsonObject CACIC_Computer::toJsonObject() @@ -70,24 +70,32 @@ QJsonObject CACIC_Computer::toJsonObject()
70 // json.insert("network", network); 70 // json.insert("network", network);
71 } 71 }
72 72
  73 +
73 /*pegarOS 74 /*pegarOS
74 * @return: int; 75 * @return: int;
75 * retorna um id referente a versão do SO. 76 * retorna um id referente a versão do SO.
76 - * 48 = Windows XP  
77 - * 128 = Windows Vista  
78 - * 144 = Windows 7  
79 - * 160 = Windows 8  
80 - * 176 = Windows 8.1  
81 - * 200 = Linux  
82 - * 0 = unkown  
83 */ 77 */
84 int CACIC_Computer::pegarOS(){ 78 int CACIC_Computer::pegarOS(){
85 -#if defined (Q_OS_WIN)  
86 - return QSysInfo::WindowsVersion; 79 +
  80 +#if defined (Q_OS_WIN) || defined(Q_OS_CYGWIN)
  81 + if(QSysInfo::WindowsVersion == QSysInfo::QSysInfo.WinVersion.WV_XP)
  82 + return WIN_XP;
  83 + else if(QSysInfo::WindowsVersion == QSysInfo::QSysInfo.WinVersion.WV_VISTA)
  84 + return WIN_VISTA;
  85 + else if(QSysInfo::WindowsVersion == QSysInfo::QSysInfo.WinVersion.WV_WINDOWS7)
  86 + return WIN_7;
  87 + else if(QSysInfo::WindowsVersion == QSysInfo::QSysInfo.WinVersion.WV_WINDOWS8)
  88 + return WIN_8;
  89 + else if(QSysInfo::WindowsVersion == QSysInfo::QSysInfo.WinVersion.WV_WINDOWS8_1)
  90 + return WIN_8_1;
  91 +#elif defined(Q_OS_MAC)
  92 + return MAC;
87 #elif defined (Q_OS_LINUX) 93 #elif defined (Q_OS_LINUX)
88 - return 200; 94 +
  95 + //TODO: extrair info de distro do "cat /etc/*release"
  96 + return LINUX_ARCH;
89 #else 97 #else
90 - return 0; 98 + return -1;
91 #endif 99 #endif
92 } 100 }
93 101
@@ -117,7 +125,7 @@ int CACIC_Computer::getOs() const @@ -117,7 +125,7 @@ int CACIC_Computer::getOs() const
117 return os; 125 return os;
118 } 126 }
119 127
120 -std::string CACIC_Computer::getUsuario() const { 128 +std::string CACIC_Computer::getUser() const {
121 return usuario; 129 return usuario;
122 } 130 }
123 131
src/cacic_computer.h
@@ -8,20 +8,38 @@ @@ -8,20 +8,38 @@
8 #include <QtNetwork/QtNetwork> 8 #include <QtNetwork/QtNetwork>
9 #include <QSysInfo> 9 #include <QSysInfo>
10 10
  11 +#include <stdio.h>
  12 +#include <unistd.h>
  13 +#include <sys/types.h>
  14 +
11 class CACIC_Computer 15 class CACIC_Computer
12 { 16 {
13 public: 17 public:
14 CACIC_Computer(); 18 CACIC_Computer();
15 19
16 - int pegarOS();  
17 - std::string pegarUsu();  
18 int getOs() const; 20 int getOs() const;
19 - std::string getUsuario() const; 21 + std::string getUser() const;
20 QList<QVariantMap> getNetworkInterface() const; 22 QList<QVariantMap> getNetworkInterface() const;
21 QList<QVariantMap> networkInterfacesRunning(); 23 QList<QVariantMap> networkInterfacesRunning();
22 QJsonObject toJsonObject(); 24 QJsonObject toJsonObject();
23 25
  26 + enum OsList {
  27 + WIN_XP,
  28 + WIN_VISTA,
  29 + WIN_7,
  30 + WIN_8,
  31 + WIN_8_1,
  32 + MAC,
  33 + LINUX_DEBIAN,
  34 + LINUX_UBUNTU,
  35 + LINUX_ARCH
  36 + };
  37 + static const enum OsList OsList;
  38 +
24 private: 39 private:
  40 + int pegarOS();
  41 + std::string pegarUsu();
  42 +
25 QList<QVariantMap> networkInterface; 43 QList<QVariantMap> networkInterface;
26 int os; 44 int os;
27 std::string usuario; 45 std::string usuario;