Commit 47feef3a03457e5c6b05b15b3a3decd26e9bb798
1 parent
9522da34
Exists in
master
Criado teste do QLogger, que servirá também como exemplo de como usa-lo.
Showing
5 changed files
with
26 additions
and
0 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
@@ -24,6 +24,7 @@ cacicD::~cacicD() | @@ -24,6 +24,7 @@ cacicD::~cacicD() | ||
24 | void cacicD::start() { | 24 | void cacicD::start() { |
25 | try{ | 25 | try{ |
26 | this->app = application(); | 26 | this->app = application(); |
27 | + QLogger::QLoggerManager::get | ||
27 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); | 28 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); |
28 | QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); | 29 | QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); |
29 | if(!result.contains("error") && !result.isEmpty()){ | 30 | if(!result.contains("error") && !result.isEmpty()){ |
cacic-teste/cacic-teste.pro
@@ -30,6 +30,7 @@ SOURCES += \ | @@ -30,6 +30,7 @@ SOURCES += \ | ||
30 | ../src/vregistry.cpp \ | 30 | ../src/vregistry.cpp \ |
31 | ../src/ccoleta.cpp \ | 31 | ../src/ccoleta.cpp \ |
32 | ../src/wmi.cpp \ | 32 | ../src/wmi.cpp \ |
33 | + ../src/QLogger.cpp | ||
33 | # ../src/qtservice/src/qtservice.cpp \ | 34 | # ../src/qtservice/src/qtservice.cpp \ |
34 | # ../src/qtservice/src/qtservice_unix.cpp \ | 35 | # ../src/qtservice/src/qtservice_unix.cpp \ |
35 | # ../src/qtservice/src/qtservice_win.cpp \ | 36 | # ../src/qtservice/src/qtservice_win.cpp \ |
@@ -50,6 +51,7 @@ HEADERS += \ | @@ -50,6 +51,7 @@ HEADERS += \ | ||
50 | ../src/vregistry.h \ | 51 | ../src/vregistry.h \ |
51 | ../src/ccoleta.h \ | 52 | ../src/ccoleta.h \ |
52 | ../src/wmi.h \ | 53 | ../src/wmi.h \ |
54 | + ../src/QLogger.h | ||
53 | # ../src/qtservice/src/qtservice.h \ | 55 | # ../src/qtservice/src/qtservice.h \ |
54 | # ../src/qtservice/src/qtservice_p.h \ | 56 | # ../src/qtservice/src/qtservice_p.h \ |
55 | # ../src/qtservice/src/qtunixserversocket.h \ | 57 | # ../src/qtservice/src/qtunixserversocket.h \ |
cacic-teste/testcacic.cpp
@@ -263,8 +263,28 @@ void CTestCacic::testColeta() | @@ -263,8 +263,28 @@ void CTestCacic::testColeta() | ||
263 | !oColeta.toJsonObject()["hardware"].toObject().isEmpty()); | 263 | !oColeta.toJsonObject()["hardware"].toObject().isEmpty()); |
264 | } | 264 | } |
265 | 265 | ||
266 | +void CTestCacic::testLogger() | ||
267 | +{ | ||
268 | + QLogger::QLoggerManager *logManager = QLogger::QLoggerManager::getInstance(); | ||
269 | + logManager->addDestination("./log.txt","teste",QLogger::DebugLevel); | ||
270 | + | ||
271 | + QLogger::QLog_Debug("teste", "Teste do módulo logger."); | ||
272 | + | ||
273 | + QFile logFile("./log.txt"); | ||
274 | + if(logFile.exists()) logFile.open(QIODevice::ReadOnly); | ||
275 | + | ||
276 | + QVERIFY(logManager && | ||
277 | + logFile.exists() && | ||
278 | + logFile.readLine().contains("Teste do módulo logger.") | ||
279 | + ); | ||
280 | + | ||
281 | + logManager->closeLogger(); | ||
282 | + logFile.close(); | ||
283 | +} | ||
284 | + | ||
266 | void CTestCacic::cleanupTestCase() | 285 | void CTestCacic::cleanupTestCase() |
267 | { | 286 | { |
287 | + OCacic.deleteFile("log.txt"); | ||
268 | OCacic.deleteFile("configRequest.json"); | 288 | OCacic.deleteFile("configRequest.json"); |
269 | OCacic.deleteFile("teste.json"); | 289 | OCacic.deleteFile("teste.json"); |
270 | OCacic.deleteFile("configReq.json"); | 290 | OCacic.deleteFile("configReq.json"); |
cacic-teste/testcacic.h
@@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
17 | #include <QtNetwork/QtNetwork> | 17 | #include <QtNetwork/QtNetwork> |
18 | #include <QJsonObject> | 18 | #include <QJsonObject> |
19 | #include <ccoleta.h> | 19 | #include <ccoleta.h> |
20 | +#include <QLogger.h> | ||
20 | 21 | ||
21 | class CTestCacic : public QObject | 22 | class CTestCacic : public QObject |
22 | { | 23 | { |
@@ -73,6 +74,7 @@ private slots: | @@ -73,6 +74,7 @@ private slots: | ||
73 | void testConvertDouble(); | 74 | void testConvertDouble(); |
74 | void testGetTest(); | 75 | void testGetTest(); |
75 | void testColeta(); | 76 | void testColeta(); |
77 | + void testLogger(); | ||
76 | void cleanupTestCase(); | 78 | void cleanupTestCase(); |
77 | }; | 79 | }; |
78 | 80 |
src/QLogger.h
@@ -162,6 +162,7 @@ namespace QLogger | @@ -162,6 +162,7 @@ namespace QLogger | ||
162 | * @param level The maximum level allowed. | 162 | * @param level The maximum level allowed. |
163 | * @return Returns true if any error have been done. | 163 | * @return Returns true if any error have been done. |
164 | */ | 164 | */ |
165 | + bool addDestination(const QString &fileDest, const QString &modules, LogLevel level); | ||
165 | bool addDestination(const QString &fileDest, const QStringList &modules, LogLevel level); | 166 | bool addDestination(const QString &fileDest, const QStringList &modules, LogLevel level); |
166 | /** | 167 | /** |
167 | * @brief Gets the QLoggerWriter instance corresponding to the module <em>module</em>. | 168 | * @brief Gets the QLoggerWriter instance corresponding to the module <em>module</em>. |