Changes: Added unut tests for Logger

RevBy: Alexey Shilov
pull/1/head
Dmitry Rozenshtein 14 years ago
parent 8592b4a554
commit fa069ba7ca

@ -16,3 +16,5 @@ usr/share/applauncherd-tests/libutwithcreate.so
usr/share/applauncherd-tests/libutwithcreatetype.so
usr/share/applauncherd-tests/libutwithcreatetypesocketname.so
usr/share/applauncherd-tests/libutplugin.so
usr/share/applauncherd-tests/ut_logger

1
debian/changelog vendored

@ -6,6 +6,7 @@ applauncherd (0.30.6) unstable; urgency=low
* Changes: Added unittests for mbooster, qtbooster, ebooster, dbooster
* Changes: Added unittests for SingleInstance
* Changes: Added unittests for BoosterPluginRegistry
* Changes: Added unittests for Logger
-- Alexey Shilov <alexey.shilov@nokia.com> Tue, 28 Jun 2011 13:55:48 +0300

@ -93,6 +93,10 @@ private:
//! Echo everything including debug messages to stdout if true
static bool m_debugMode;
#ifdef UNIT_TEST
friend class Ut_Logger;
#endif
};
#endif // LOGGER_H

@ -10,6 +10,7 @@ add_subdirectory(ut_socketmanager)
add_subdirectory(ut_singleinstance)
add_subdirectory(ut_boosterpluginregistry)
add_subdirectory(ut_appdata)
add_subdirectory(ut_logger)
install(FILES tests.xml DESTINATION /usr/share/applauncherd-tests)

@ -93,6 +93,22 @@
</get-->
</set>
<set name="logger-test" description="Logger unit tests" feature="AF Logger for Launcher daemon" requirement="1131430" >
<case name="Logger" type="Functional" description="Unit tests for Logger class" level="Component" timeout="20">
<step expected_result="0">su - user -c 'source /tmp/session_bus_address.user &amp;&amp; DISPLAY=:0 /usr/share/applauncherd-tests/ut_logger'</step>
</case>
<environments>
<scratchbox>true</scratchbox>
<hardware>true</hardware>
</environments>
<!--get>
</get-->
</set>
</suite>
</testdefinition>

@ -0,0 +1,29 @@
set(LAUNCHER ${CMAKE_HOME_DIRECTORY}/src/launcherlib)
set(COMMON ${CMAKE_HOME_DIRECTORY}/src/common)
set(DESTINATION "/usr/share/applauncherd-tests/")
# Set sources
set(SRC ut_logger.cpp ${LAUNCHER}/logger.cpp)
# Set moc headers
set(MOC_HDRS ut_logger.h)
# Run moc
qt4_wrap_cpp(MOC_SRC ${MOC_HDRS})
# Enable test library
set(QT_USE_QTTEST TRUE)
# Set include paths
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${LAUNCHER} ${COMMON})
link_libraries(${QT_QTTEST_LIBRARY})
# Enable Qt (may not be needed, because already defined on higher level)
include(${QT_USE_FILE})
add_executable(ut_logger ${SRC} ${MOC_SRC})
# Install
install(PROGRAMS ut_logger DESTINATION ${DESTINATION})

@ -0,0 +1,116 @@
/***************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include <QString>
#include <QProcess>
#include <QDateTime>
#include <QtGlobal>
#include <sys/syslog.h>
#include "ut_logger.h"
#include "logger.h"
static const QString syslogFile = "/var/log/syslog";
static const char * progName = "Ut_Logger";
static const int delay = 1000;
Ut_Logger::Ut_Logger() :
m_subject(new Logger)
{}
Ut_Logger::~Ut_Logger()
{}
void Ut_Logger::initTestCase()
{
qsrand(QDateTime::currentMSecsSinceEpoch());
}
void Ut_Logger::cleanupTestCase()
{}
void Ut_Logger::testOpenLog() {
QVERIFY(m_subject->m_isOpened == false);
Logger::openLog(progName);
QVERIFY(m_subject->m_isOpened == true);
}
void Ut_Logger::testSetDebugMode() {
QVERIFY(m_subject->m_debugMode == false);
Logger::setDebugMode(true);
QVERIFY(m_subject->m_debugMode == true);
}
void Ut_Logger::testLogDebug() {
//case with debug mode on
Logger::setDebugMode(true);
_setTestPhrase(Q_FUNC_INFO);
Logger::logDebug(m_testPhrase);
QTest::qSleep(delay);
QVERIFY(_findPhraseInSyslog() == true);
//case with debug mode off
Logger::setDebugMode(false);
_setTestPhrase(Q_FUNC_INFO);
Logger::logDebug(m_testPhrase);
QTest::qSleep(delay);
QVERIFY(_findPhraseInSyslog() == false);
}
void Ut_Logger::testLogError() {
_setTestPhrase(Q_FUNC_INFO);
Logger::logError(m_testPhrase);
QTest::qSleep(delay);
QVERIFY(_findPhraseInSyslog() == true);
}
void Ut_Logger::testLogInfo() {
_setTestPhrase(Q_FUNC_INFO);
Logger::logInfo(m_testPhrase);
QTest::qSleep(delay);
QVERIFY(_findPhraseInSyslog() == true);
}
void Ut_Logger::testLogWarning() {
_setTestPhrase(Q_FUNC_INFO);
Logger::logWarning(m_testPhrase);
QTest::qSleep(delay);
QVERIFY(_findPhraseInSyslog() == true);
}
void Ut_Logger::testCloseLog() {
QVERIFY(m_subject->m_isOpened == true);
Logger::closeLog();
QVERIFY(m_subject->m_isOpened == false);
}
bool Ut_Logger::_findPhraseInSyslog()
{
int exitCode = QProcess::execute("grep", QStringList() << QString(m_testPhrase) << syslogFile);
return exitCode == 0;
}
void Ut_Logger::_setTestPhrase(const char * base)
{
sprintf(m_testPhrase, "%s: %d", base, qrand());
}
QTEST_APPLESS_MAIN(Ut_Logger)

@ -0,0 +1,58 @@
/***************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#ifndef UT_LOGGER_H
#define UT_LOGGER_H
#include <QtTest/QtTest>
#include <QObject>
#include <tr1/memory>
#define UNIT_TEST
class Logger;
class Ut_Logger : public QObject
{
Q_OBJECT
public:
Ut_Logger();
virtual ~Ut_Logger();
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testOpenLog();
void testSetDebugMode();
void testLogDebug();
void testLogError();
void testLogInfo();
void testLogWarning();
void testCloseLog();
private:
char m_testPhrase[255];
bool _findPhraseInSyslog();
void _setTestPhrase(const char * base);
std::tr1::shared_ptr<Logger> m_subject;
};
#endif // UT_LOGGER_H
Loading…
Cancel
Save