Commit 845fdf994f8ba164511025d312ca859166c33de5
1 parent
bf68278d
Exists in
master
Alteração no testConsole para passar somente no Linux e no coletaIdOs para retornar distribuição.
Showing
4 changed files
with
31 additions
and
6 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -94,9 +94,11 @@ void CTestCacic::testpegarOS(){ | @@ -94,9 +94,11 @@ void CTestCacic::testpegarOS(){ | ||
94 | void CTestCacic::testConsole() | 94 | void CTestCacic::testConsole() |
95 | { | 95 | { |
96 | ConsoleObject console; | 96 | ConsoleObject console; |
97 | - | ||
98 | -// QVERIFY(console("echo teste").toStdString() == "teste\n"); | 97 | +#if defined(Q_OS_LINUX) |
98 | + QVERIFY(console("echo teste").toStdString() == "teste\n"); | ||
99 | +#else | ||
99 | QVERIFY(false); | 100 | QVERIFY(false); |
101 | +#endif | ||
100 | } | 102 | } |
101 | 103 | ||
102 | void CTestCacic::testPegarUsu(){ | 104 | void CTestCacic::testPegarUsu(){ |
src/console.h
@@ -11,14 +11,18 @@ class ConsoleObject:public std::unary_function<std::string,QString> | @@ -11,14 +11,18 @@ class ConsoleObject:public std::unary_function<std::string,QString> | ||
11 | 11 | ||
12 | public: | 12 | public: |
13 | 13 | ||
14 | -#if defined(Q_OS_LINUX) | 14 | + |
15 | QString operator() (std::string input) | 15 | QString operator() (std::string input) |
16 | { | 16 | { |
17 | QProcess* process = new QProcess(); | 17 | QProcess* process = new QProcess(); |
18 | 18 | ||
19 | +#if defined(Q_OS_LINUX) | ||
19 | QStringList options; | 20 | QStringList options; |
20 | options << "-c" << QString::fromStdString(input); | 21 | options << "-c" << QString::fromStdString(input); |
21 | process->start("/bin/sh", options); | 22 | process->start("/bin/sh", options); |
23 | +#elif defined(Q_OS_WIN) | ||
24 | + process->start(input); | ||
25 | +#endif | ||
22 | process->waitForFinished(); | 26 | process->waitForFinished(); |
23 | QString output = process->readAll(); | 27 | QString output = process->readAll(); |
24 | // qDebug() << output; | 28 | // qDebug() << output; |
@@ -26,7 +30,6 @@ public: | @@ -26,7 +30,6 @@ public: | ||
26 | delete process; | 30 | delete process; |
27 | return output; | 31 | return output; |
28 | } | 32 | } |
29 | -#endif | ||
30 | }; | 33 | }; |
31 | 34 | ||
32 | #endif // CONSOLE_H | 35 | #endif // CONSOLE_H |
src/operatingsystem.cpp
@@ -6,6 +6,7 @@ OperatingSystem::OperatingSystem() | @@ -6,6 +6,7 @@ OperatingSystem::OperatingSystem() | ||
6 | this->nomeOs = this->coletaNomeOs(); | 6 | this->nomeOs = this->coletaNomeOs(); |
7 | } | 7 | } |
8 | 8 | ||
9 | + | ||
9 | /*pegarOS | 10 | /*pegarOS |
10 | * @return: int; | 11 | * @return: int; |
11 | * retorna um id referente a versão do SO. | 12 | * retorna um id referente a versão do SO. |
@@ -14,13 +15,28 @@ OperatingSystem::OperatingSystem() | @@ -14,13 +15,28 @@ OperatingSystem::OperatingSystem() | ||
14 | * 144 = Windows 7 | 15 | * 144 = Windows 7 |
15 | * 160 = Windows 8 | 16 | * 160 = Windows 8 |
16 | * 176 = Windows 8.1 | 17 | * 176 = Windows 8.1 |
17 | - * 200 = Linux | 18 | + * [enum] = Linux |
18 | */ | 19 | */ |
19 | int OperatingSystem::coletaIdOs(){ | 20 | int OperatingSystem::coletaIdOs(){ |
20 | #if defined (Q_OS_WIN) | 21 | #if defined (Q_OS_WIN) |
21 | return QSysInfo::WindowsVersion; | 22 | return QSysInfo::WindowsVersion; |
22 | #elif defined (Q_OS_LINUX) | 23 | #elif defined (Q_OS_LINUX) |
23 | - return LINUX_ARCH; | 24 | + |
25 | + ConsoleObject console; | ||
26 | + QStringList catOutput = console("cat /etc/*release").split("\n"); | ||
27 | + | ||
28 | + QString line; | ||
29 | + foreach(line, catOutput) { | ||
30 | + if(line.contains("PRETTY_NAME")) { | ||
31 | + if( line.contains("Arch")) | ||
32 | + return LINUX_ARCH; | ||
33 | + else if( line.contains("Debian")) | ||
34 | + return LINUX_DEBIAN; | ||
35 | + else if( line.contains("Ubuntu")) | ||
36 | + return LINUX_UBUNTU; | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
24 | #else | 40 | #else |
25 | return 0; | 41 | return 0; |
26 | #endif | 42 | #endif |
src/operatingsystem.h
@@ -2,8 +2,12 @@ | @@ -2,8 +2,12 @@ | ||
2 | #define OPERATINGSYSTEM_H | 2 | #define OPERATINGSYSTEM_H |
3 | 3 | ||
4 | #include <QtCore> | 4 | #include <QtCore> |
5 | +#include <QString> | ||
6 | +#include <QStringList> | ||
5 | #include <QSysInfo> | 7 | #include <QSysInfo> |
8 | + | ||
6 | #include <ccacic.h> | 9 | #include <ccacic.h> |
10 | +#include <console.h> | ||
7 | 11 | ||
8 | class OperatingSystem | 12 | class OperatingSystem |
9 | { | 13 | { |