add test structure

pull/135/head
Simon Stürz 2016-03-31 18:07:57 +02:00 committed by Michael Zanetti
parent 541bbbdc6b
commit a4d6f58f3c
8 changed files with 99 additions and 11 deletions

Binary file not shown.

View File

@ -4,16 +4,16 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> #
# Copyright (C) 2015-2016 Simon Stuerz <simon.stuerz@guh.guru> #
# Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> #
# #
# This file is part of guh-cli. #
# This file is part of guh. #
# #
# guh-cli is free software: you can redistribute it and/or modify #
# guh is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, version 2 of the License. #
# #
# guh-cli is distributed in the hope that it will be useful, #
# guh is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #

View File

@ -198,7 +198,6 @@ bool CalendarItem::evaluateWeekly(const QDateTime &dateTime) const
// and end of this calendar item from the previouse week
return true;
} else if (dateTime >= startDateTime && dateTime < endDateTime) {
// Return true if the current time is between start
// and end of this calendar item

View File

@ -24,7 +24,6 @@
\ingroup rules
\inmodule core
*/
/*! \fn void guhserver::TimeManager::tick()
@ -70,12 +69,12 @@ QByteArray TimeManager::timeZone() const
return m_timeZone.id();
}
/*! Sets the \a timeZone of this \l{TimeManager}. */
/*! Sets the \a timeZone of this \l{TimeManager}. Allowed values according to the \l{http://www.iana.org/time-zones}{IANA database}. */
void TimeManager::setTimeZone(const QByteArray &timeZone)
{
if (!QTimeZone(timeZone).isValid()) {
qCWarning(dcTimeManager()) << "Invalid time zone" << timeZone;
qCWarning(dcTimeManager()) << "Using default system timezone" << QTimeZone::systemTimeZoneId();
qCWarning(dcTimeManager()) << "Using system time zone" << QTimeZone::systemTimeZoneId();
m_timeZone = QTimeZone(QTimeZone::systemTimeZoneId());
} else {
qCDebug(dcTimeManager()) << "Set time zone" << timeZone;
@ -107,7 +106,6 @@ void TimeManager::guhTimeout()
emit tick();
QDateTime currentDateTime = QDateTime::currentDateTimeUtc();
//qCDebug(dcTimeManager) << "Time changed" << currentDateTime.toTimeZone(m_timeZone).time().toString("hh:mm:ss");
// Minute based guh time
if (m_dateTime.time().minute() != currentDateTime.toTimeZone(m_timeZone).time().minute()) {

View File

@ -51,7 +51,6 @@ signals:
void dateChanged(const QDate &currentDate);
void timeChanged(const QTime &currentTime);
private slots:
void guhTimeout();

View File

@ -17,5 +17,5 @@ SUBDIRS = versioning \
websocketserver \
logging \
restlogging \
coap \
timemanager \

View File

@ -0,0 +1,86 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "guhtestbase.h"
#include "guhcore.h"
#include "time/timemanager.h"
#include "devicemanager.h"
#include "mocktcpserver.h"
#include <QTimeZone>
#include <QDateTime>
#include <QtTest/QtTest>
#include <QCoreApplication>
using namespace guhserver;
class TestTimeManager: public GuhTestBase
{
Q_OBJECT
private slots:
void changeTimeZone_data();
void changeTimeZone();
};
void TestTimeManager::changeTimeZone_data()
{
QTest::addColumn<QByteArray>("timeZoneId");
QTest::addColumn<bool>("valid");
QTest::newRow("valid timezone: Asia/Tokyo") << QByteArray("Asia/Tokyo") << true;
QTest::newRow("valid timezone: America/Lima") << QByteArray("America/Lima") << true;
QTest::newRow("valid timezone: Africa/Harare") << QByteArray("Africa/Harare") << true;
QTest::newRow("invalid timezone: Mars/Diacria") << QByteArray("Mars/Diacria") << false;
QTest::newRow("invalid timezone: Moon/Kepler") << QByteArray("Moon/Kepler") << false;
}
void TestTimeManager::changeTimeZone()
{
QFETCH(QByteArray, timeZoneId);
QFETCH(bool, valid);
QTimeZone currentTimeZone(GuhCore::instance()->timeManager()->timeZone());
QTimeZone newTimeZone(timeZoneId);
QDateTime currentDateTime = GuhCore::instance()->timeManager()->currentDateTime();
qDebug() << currentDateTime.toString();
GuhCore::instance()->timeManager()->setTimeZone(timeZoneId);
QDateTime newDateTime = GuhCore::instance()->timeManager()->currentDateTime();
qDebug() << newDateTime.toString();
int offsetOriginal = currentTimeZone.offsetFromUtc(currentDateTime);
int offsetNew = newTimeZone.offsetFromUtc(newDateTime);
if (valid)
QVERIFY(offsetOriginal != offsetNew);
}
#include "testtimemanager.moc"
QTEST_MAIN(TestTimeManager)

View File

@ -0,0 +1,6 @@
TARGET = testtimemanager
include(../../../guh.pri)
include(../autotests.pri)
SOURCES += testtimemanager.cpp