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 | 24 | void cacicD::start() { |
25 | 25 | try{ |
26 | 26 | this->app = application(); |
27 | + QLogger::QLoggerManager::get | |
27 | 28 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); |
28 | 29 | QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); |
29 | 30 | if(!result.contains("error") && !result.isEmpty()){ | ... | ... |
cacic-teste/cacic-teste.pro
... | ... | @@ -30,6 +30,7 @@ SOURCES += \ |
30 | 30 | ../src/vregistry.cpp \ |
31 | 31 | ../src/ccoleta.cpp \ |
32 | 32 | ../src/wmi.cpp \ |
33 | + ../src/QLogger.cpp | |
33 | 34 | # ../src/qtservice/src/qtservice.cpp \ |
34 | 35 | # ../src/qtservice/src/qtservice_unix.cpp \ |
35 | 36 | # ../src/qtservice/src/qtservice_win.cpp \ |
... | ... | @@ -50,6 +51,7 @@ HEADERS += \ |
50 | 51 | ../src/vregistry.h \ |
51 | 52 | ../src/ccoleta.h \ |
52 | 53 | ../src/wmi.h \ |
54 | + ../src/QLogger.h | |
53 | 55 | # ../src/qtservice/src/qtservice.h \ |
54 | 56 | # ../src/qtservice/src/qtservice_p.h \ |
55 | 57 | # ../src/qtservice/src/qtunixserversocket.h \ | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -263,8 +263,28 @@ void CTestCacic::testColeta() |
263 | 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 | 285 | void CTestCacic::cleanupTestCase() |
267 | 286 | { |
287 | + OCacic.deleteFile("log.txt"); | |
268 | 288 | OCacic.deleteFile("configRequest.json"); |
269 | 289 | OCacic.deleteFile("teste.json"); |
270 | 290 | OCacic.deleteFile("configReq.json"); | ... | ... |
cacic-teste/testcacic.h
... | ... | @@ -17,6 +17,7 @@ |
17 | 17 | #include <QtNetwork/QtNetwork> |
18 | 18 | #include <QJsonObject> |
19 | 19 | #include <ccoleta.h> |
20 | +#include <QLogger.h> | |
20 | 21 | |
21 | 22 | class CTestCacic : public QObject |
22 | 23 | { |
... | ... | @@ -73,6 +74,7 @@ private slots: |
73 | 74 | void testConvertDouble(); |
74 | 75 | void testGetTest(); |
75 | 76 | void testColeta(); |
77 | + void testLogger(); | |
76 | 78 | void cleanupTestCase(); |
77 | 79 | }; |
78 | 80 | ... | ... |
src/QLogger.h
... | ... | @@ -162,6 +162,7 @@ namespace QLogger |
162 | 162 | * @param level The maximum level allowed. |
163 | 163 | * @return Returns true if any error have been done. |
164 | 164 | */ |
165 | + bool addDestination(const QString &fileDest, const QString &modules, LogLevel level); | |
165 | 166 | bool addDestination(const QString &fileDest, const QStringList &modules, LogLevel level); |
166 | 167 | /** |
167 | 168 | * @brief Gets the QLoggerWriter instance corresponding to the module <em>module</em>. | ... | ... |