Commit a0da9800ef3bc5f22b8368103be0db8ee37958e1

Authored by Eric Menezes Noronha
2 parents ba240cf2 624c6f9e
Exists in master

Merge branch 'master' of https://github.com/lightbase/cacic-agente

cacic-teste/testcacic.cpp
... ... @@ -86,11 +86,19 @@ void CTestCacic::testInterfaceDeRede(){
86 86 }
87 87  
88 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 100 void CTestCacic::testPegarUsu(){
93   - QVERIFY(OCacicComp.getUsuario() != "");
  101 + QVERIFY(OCacicComp.getUser() != "");
94 102 }
95 103  
96 104 void CTestCacic::testJsonValueFromJsonString()
... ... @@ -110,6 +118,7 @@ void CTestCacic::testSslConnection()
110 118 {
111 119 QJsonObject json = OCacicComm.comm("", QJsonObject(), true);
112 120 QJsonValue jsonvalue = json["codestatus"];
  121 +// qDebug() << jsonvalue.toDouble();
113 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 70 // json.insert("network", network);
71 71 }
72 72  
  73 +
73 74 /*pegarOS
74 75 * @return: int;
75 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 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 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 97 #else
90   - return 0;
  98 + return -1;
91 99 #endif
92 100 }
93 101  
... ... @@ -117,7 +125,7 @@ int CACIC_Computer::getOs() const
117 125 return os;
118 126 }
119 127  
120   -std::string CACIC_Computer::getUsuario() const {
  128 +std::string CACIC_Computer::getUser() const {
121 129 return usuario;
122 130 }
123 131  
... ...
src/cacic_computer.h
... ... @@ -8,20 +8,38 @@
8 8 #include <QtNetwork/QtNetwork>
9 9 #include <QSysInfo>
10 10  
  11 +#include <stdio.h>
  12 +#include <unistd.h>
  13 +#include <sys/types.h>
  14 +
11 15 class CACIC_Computer
12 16 {
13 17 public:
14 18 CACIC_Computer();
15 19  
16   - int pegarOS();
17   - std::string pegarUsu();
18 20 int getOs() const;
19   - std::string getUsuario() const;
  21 + std::string getUser() const;
20 22 QList<QVariantMap> getNetworkInterface() const;
21 23 QList<QVariantMap> networkInterfacesRunning();
22 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 39 private:
  40 + int pegarOS();
  41 + std::string pegarUsu();
  42 +
25 43 QList<QVariantMap> networkInterface;
26 44 int os;
27 45 std::string usuario;
... ...