[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bkdepimlibs=5D_kcalcore=3A_Add_unit_test_for_the_Tod?=
From:       Sergio Martins <iamsergio () gmail ! com>
Date:       2011-02-06 2:10:13
Message-ID: 20110206021013.9DD9AA609B () git ! kde ! org
[Download RAW message or body]

Git commit c9db13a84b708409fd1f3c224a02a9b3e46c4573 by Sergio Martins.
Committed on 06/02/11 at 03:09.
Pushed by smartins into branch 'master'.

Add unit test for the Todo::recurTodo() method.

M  +1    -0    kcalcore/tests/CMakeLists.txt     
A  +80   -0    kcalcore/tests/testrecurtodo.cpp         [License: LGPL (v2+)]
A  +35   -0    kcalcore/tests/testrecurtodo.h         [License: LGPL (v2+)]

http://commits.kde.org/kdepimlibs/c9db13a84b708409fd1f3c224a02a9b3e46c4573

diff --git a/kcalcore/tests/CMakeLists.txt b/kcalcore/tests/CMakeLists.txt
index 1448f68..b33de6f 100644
--- a/kcalcore/tests/CMakeLists.txt
+++ b/kcalcore/tests/CMakeLists.txt
@@ -38,6 +38,7 @@ KCALCORE_UNIT_TESTS(
   testperiod
   testfreebusyperiod
   testperson
+  testrecurtodo
   testsortablelist
   testtodo
   testtimesininterval
diff --git a/kcalcore/tests/testrecurtodo.cpp b/kcalcore/tests/testrecurtodo.cpp
new file mode 100644
index 0000000..45e0761
--- /dev/null
+++ b/kcalcore/tests/testrecurtodo.cpp
@@ -0,0 +1,80 @@
+/*
+  This file is part of the kcalcore library.
+
+  Copyright (c) 2011 Sérgio Martins <iamsergio@gmail.com>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Library General Public
+  License as published by the Free Software Foundation; either
+  version 2 of the License, or (at your option) any later version.
+
+  This library 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
+  Library General Public License for more details.
+
+  You should have received a copy of the GNU Library General Public License
+  along with this library; see the file COPYING.LIB.  If not, write to
+  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
+*/
+#include "testrecurtodo.h"
+#include "testrecurtodo.moc"
+#include "../todo.h"
+//#include <kdebug.h>
+#include <qtest_kde.h>
+QTEST_KDEMAIN( RecurTodoTest, NoGUI )
+
+using namespace KCalCore;
+
+void RecurTodoTest::testAllDay()
+{
+  const QDate dueDate( QDate::currentDate().addDays( -3 ) );
+  Todo *todo = new Todo();
+  todo->setDtStart( KDateTime( dueDate.addDays( -1 ) ) );
+  todo->setDtDue( KDateTime( dueDate ) );
+  todo->setSummary( QLatin1String( "All day event" ) );
+  todo->setAllDay( true );
+
+  Recurrence *recurrence = todo->recurrence();
+  recurrence->unsetRecurs();
+  recurrence->setDaily( 1 );
+  QVERIFY( todo->dtDue() == KDateTime( dueDate ) );
+  todo->setCompleted( KDateTime::currentUtcDateTime() );
+  QVERIFY( todo->recurs() );
+  QVERIFY( todo->percentComplete() == 0 );
+  QVERIFY( todo->dtDue().date() == QDate::currentDate() );
+
+  todo->setCompleted( KDateTime::currentUtcDateTime() );
+  QVERIFY( todo->dtDue().date() == QDate::currentDate().addDays( 1 ) );
+  QVERIFY( todo->dtDue( true /*first ocurrence*/ ).date() == dueDate );
+}
+
+void RecurTodoTest::testNonAllDay()
+{
+  const QDate twoDaysAgo( QDate::currentDate().addDays( -2 ) );
+  const QDate treeDaysAgo( QDate::currentDate().addDays( -3 ) );
+  const QTime currentTimeWithMS = QTime::currentTime();
+  const QTime currentTime( currentTimeWithMS.hour(), currentTimeWithMS.minute(), \
currentTimeWithMS.second() ); +  const QDate currentDate = QDate::currentDate();
+
+  Todo *todo = new Todo();
+  todo->setDtStart( KDateTime( twoDaysAgo ) );
+  todo->setDtDue( KDateTime( treeDaysAgo, currentTime ) );
+  todo->setSummary( QLatin1String( "Not an all day event" ) );
+  todo->setAllDay( false );
+
+  Recurrence *recurrence = todo->recurrence();
+  recurrence->unsetRecurs();
+  recurrence->setDaily( 1 );
+  QVERIFY( todo->dtDue() == KDateTime( treeDaysAgo, currentTime ) );
+  todo->setCompleted( KDateTime::currentUtcDateTime() );
+  QVERIFY( todo->recurs() );
+  QVERIFY( todo->percentComplete() == 0 );
+  //kDebug() << todo->dtDue() << KDateTime( currentDate, currentTime, \
todo->dtDue().timeSpec() ).addDays( 1 ); +  QVERIFY( todo->dtDue() == KDateTime( \
currentDate, currentTime, todo->dtDue().timeSpec() ).addDays( 1 ) ); +
+  todo->setCompleted( KDateTime::currentUtcDateTime() );
+  QVERIFY( todo->dtDue() == KDateTime( currentDate, currentTime, \
todo->dtDue().timeSpec() ).addDays( 2 ) ); +  QVERIFY( todo->dtDue( true /*first \
ocurrence*/ ) == KDateTime( treeDaysAgo, currentTime ) ); +}
diff --git a/kcalcore/tests/testrecurtodo.h b/kcalcore/tests/testrecurtodo.h
new file mode 100644
index 0000000..78aa077
--- /dev/null
+++ b/kcalcore/tests/testrecurtodo.h
@@ -0,0 +1,35 @@
+/*
+  This file is part of the kcalcore library.
+
+  Copyright (c) 2011 Sérgio Martins <iamsergio@gmail.com>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Library General Public
+  License as published by the Free Software Foundation; either
+  version 2 of the License, or (at your option) any later version.
+
+  This library 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
+  Library General Public License for more details.
+
+  You should have received a copy of the GNU Library General Public License
+  along with this library; see the file COPYING.LIB.  If not, write to
+  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
+*/
+
+#ifndef TESTRECURTODO_H
+#define TESTRECURTODO_H
+
+#include <QtCore/QObject>
+
+class RecurTodoTest : public QObject
+{
+  Q_OBJECT
+  private Q_SLOTS:
+    void testAllDay();
+    void testNonAllDay();
+};
+
+#endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic