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 | 94 | void CTestCacic::testConsole() |
95 | 95 | { |
96 | 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 | 100 | QVERIFY(false); |
101 | +#endif | |
100 | 102 | } |
101 | 103 | |
102 | 104 | void CTestCacic::testPegarUsu(){ | ... | ... |
src/console.h
... | ... | @@ -11,14 +11,18 @@ class ConsoleObject:public std::unary_function<std::string,QString> |
11 | 11 | |
12 | 12 | public: |
13 | 13 | |
14 | -#if defined(Q_OS_LINUX) | |
14 | + | |
15 | 15 | QString operator() (std::string input) |
16 | 16 | { |
17 | 17 | QProcess* process = new QProcess(); |
18 | 18 | |
19 | +#if defined(Q_OS_LINUX) | |
19 | 20 | QStringList options; |
20 | 21 | options << "-c" << QString::fromStdString(input); |
21 | 22 | process->start("/bin/sh", options); |
23 | +#elif defined(Q_OS_WIN) | |
24 | + process->start(input); | |
25 | +#endif | |
22 | 26 | process->waitForFinished(); |
23 | 27 | QString output = process->readAll(); |
24 | 28 | // qDebug() << output; |
... | ... | @@ -26,7 +30,6 @@ public: |
26 | 30 | delete process; |
27 | 31 | return output; |
28 | 32 | } |
29 | -#endif | |
30 | 33 | }; |
31 | 34 | |
32 | 35 | #endif // CONSOLE_H | ... | ... |
src/operatingsystem.cpp
... | ... | @@ -6,6 +6,7 @@ OperatingSystem::OperatingSystem() |
6 | 6 | this->nomeOs = this->coletaNomeOs(); |
7 | 7 | } |
8 | 8 | |
9 | + | |
9 | 10 | /*pegarOS |
10 | 11 | * @return: int; |
11 | 12 | * retorna um id referente a versão do SO. |
... | ... | @@ -14,13 +15,28 @@ OperatingSystem::OperatingSystem() |
14 | 15 | * 144 = Windows 7 |
15 | 16 | * 160 = Windows 8 |
16 | 17 | * 176 = Windows 8.1 |
17 | - * 200 = Linux | |
18 | + * [enum] = Linux | |
18 | 19 | */ |
19 | 20 | int OperatingSystem::coletaIdOs(){ |
20 | 21 | #if defined (Q_OS_WIN) |
21 | 22 | return QSysInfo::WindowsVersion; |
22 | 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 | 40 | #else |
25 | 41 | return 0; |
26 | 42 | #endif | ... | ... |
src/operatingsystem.h