mirror of https://github.com/cutefishos/appmotor
parent
8592b4a554
commit
fa069ba7ca
@ -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…
Reference in New Issue