diff --git a/kcal/tests/CMakeLists.txt b/kcal/tests/CMakeLists.txt index 018ca3e8f..55d9623f6 100644 --- a/kcal/tests/CMakeLists.txt +++ b/kcal/tests/CMakeLists.txt @@ -1,121 +1,122 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) include_directories( ${CMAKE_SOURCE_DIR}/kcal ${LIBICAL_INCLUDE_DIRS} ) MACRO(KCAL_UNIT_TESTS) FOREACH(_testname ${ARGN}) kde4_add_unit_test(${_testname} NOGUI ${_testname}.cpp) target_link_libraries(${_testname} ${KDE4_KDECORE_LIBS} kcal ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${LIBICAL_LIBRARIES}) ENDFOREACH(_testname) ENDMACRO(KCAL_UNIT_TESTS) MACRO(KCAL_EXECUTABLE_TESTS) FOREACH(_testname ${ARGN}) kde4_add_executable(${_testname} NOGUI TEST ${_testname}.cpp) target_link_libraries(${_testname} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} kcal ${QT_QTTEST_LIBRARY} kresources) ENDFOREACH(_testname) ENDMACRO(KCAL_EXECUTABLE_TESTS) KCAL_UNIT_TESTS( testalarm testassignmentvisitor testattachment testattendee testcalendarlocal testcalendarnull # testcalendarresources disable for now because it cause akonadi to start testcalfilter + testcomparisonvisitor testduration testerrorformat testevent testfilestorage testfreebusy testincidencerelation testjournal testkresult testperiod testperson testsortablelist testtodo ) # this test cannot work with msvc because libical should not be altered # and therefore we can't add KCAL_EXPORT there # it should work fine with mingw because of the auto-import feature if(NOT MSVC) KCAL_UNIT_TESTS(testicaltimezones) endif(NOT MSVC) KCAL_EXECUTABLE_TESTS( convertqtopia incidencestest loadcalendar fbrecurring readandwrite testfb testrecurprevious testrecurrence testrecurrencetype testrecurson testresource testtostring testvcalexport ) ########### next target ############### set(testfields_SRCS testfields.cpp) set(srcfile "${CMAKE_SOURCE_DIR}/kcal/tests/data/test_pilot.ics") add_definitions( -D_TESTINPUT="\\"${srcfile}\\"" ) kde4_add_executable(testfields TEST ${testfields_SRCS}) target_link_libraries(testfields ${KDE4_KDECORE_LIBS} kcal ) ########### Tests ####################### FILE( GLOB_RECURSE testFiles data/RecurrenceRule/*.ics ) FILE( GLOB_RECURSE compatFiles data/Compat/*.ics ) FILE( GLOB_RECURSE vCalFilesAsIcal data/vCalendar/*.ics ) FILE( GLOB_RECURSE vCalFiles data/vCalendar/*.vcs ) FOREACH( file ${testFiles} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( RecurNext-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/testrecurrence.shell "next" ${file} ) ENDFOREACH(file) FOREACH( file ${testFiles} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( RecurPrev-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/testrecurprevious.shell "prev" ${file} ) ENDFOREACH(file) FOREACH( file ${testFiles} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( RecursOn-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/testrecurson.shell "recurson" ${file} ) ENDFOREACH(file) FOREACH( file ${compatFiles} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( Compat-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/readandwrite.shell "ical" ${file} ) ENDFOREACH(file) FOREACH( file ${vCalFilesAsIcal} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( VCalOut-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/testvcalexport.shell "vcal" ${file} ) ENDFOREACH(file) FOREACH( file ${vCalFiles} ) GET_FILENAME_COMPONENT( fn ${file} NAME) ADD_TEST( VCalIn-${fn} ${CMAKE_CURRENT_SOURCE_DIR}/runsingletestcase.pl ${EXECUTABLE_OUTPUT_PATH}/readandwrite.shell "ical" ${file} ) ENDFOREACH(file) # ADD_TEST( TestRecurrence runtestcase.pl testrecurrence "next" ${CMAKE_CURRENT_SOURCE_DIR} data/RecurrenceRule/ "*.ics" ) # ADD_TEST( TestRecPrevious runtestcase.pl testrecurprevious "prev" ${CMAKE_CURRENT_SOURCE_DIR} data/RecurrenceRule/ "*.ics" ) # ADD_TEST( TestRecursOn runtestcase.pl testrecurson "recurson" ${CMAKE_CURRENT_SOURCE_DIR} data/RecurrenceRule/ "*.ics" ) # ADD_TEST( TestCompat runtestcase.pl readandwrite "ical" ${CMAKE_CURRENT_SOURCE_DIR} data/Compat/ "*.ics" ) # ADD_TEST( TestVCal runtestcase.pl testvcalexport "vcal" ${CMAKE_CURRENT_SOURCE_DIR} data/vCalendar/ "*.ics" ) # ADD_TEST( TestFromVCal runtestcase.pl readandwrite "ical" ${CMAKE_CURRENT_SOURCE_DIR} data/vCalendar/ "*.vcs" ) diff --git a/kcal/tests/testcomparisonvisitor.cpp b/kcal/tests/testcomparisonvisitor.cpp new file mode 100644 index 000000000..59e28d458 --- /dev/null +++ b/kcal/tests/testcomparisonvisitor.cpp @@ -0,0 +1,169 @@ +/* + This file is part of libkcal. + + Copyright 2009 Ingo Klöcker + + 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 "kcal/comparisonvisitor.h" + +#include "kcal/event.h" +#include "kcal/freebusy.h" +#include "kcal/journal.h" +#include "kcal/todo.h" + +#include + +#include + +using namespace KCal; + +class ComparisonVisitorTest : public QObject +{ + Q_OBJECT + + private: + ComparisonVisitor mComparator; + + private Q_SLOTS: + void testEventComparison(); + void testFreeBusyComparison(); + void testJournalComparison(); + void testTodoComparison(); + void testTypeMismatches(); +}; + +QTEST_KDEMAIN( ComparisonVisitorTest, NoGUI ) + +void ComparisonVisitorTest::testEventComparison() +{ + const QString summary = QLatin1String( "Testing comparison" ); + const QString desc = QLatin1String( "Testing ComparisonVisitor" ); + const KDateTime now = KDateTime::currentUtcDateTime(); + const KDateTime later = now.addSecs( 3600 ); + + Event reference; + reference.setSummary( summary ); + reference.setDescription( desc ); + reference.setDtStart( now ); + reference.setDtEnd( later ); + + // create a copy of the reference incidence + Event event( reference ); + + IncidenceBase *baseReference = &reference; + IncidenceBase *baseIncidence = &event; + + QVERIFY( mComparator.compare( baseIncidence, baseReference ) ); + + // change a property of Event (but not of IncidenceBase) + event.setHasEndDate( !event.hasEndDate() ); + QVERIFY( !mComparator.compare( baseIncidence, baseReference ) ); +} + +void ComparisonVisitorTest::testFreeBusyComparison() +{ + const KDateTime now = KDateTime::currentUtcDateTime(); + const KDateTime later = now.addSecs( 3600 ); + + FreeBusy reference; + reference.setDtStart( now ); + reference.setDtEnd( later ); + + // create a copy of the reference incidence + FreeBusy freebusy( reference ); + + IncidenceBase *baseReference = &reference; + IncidenceBase *baseIncidence = &freebusy; + + QVERIFY( mComparator.compare( baseIncidence, baseReference ) ); + + // change a property of FreeBusy (but not of IncidenceBase) + freebusy.setDtEnd( freebusy.dtEnd().addSecs( 3600 ) ); + QVERIFY( !mComparator.compare( baseIncidence, baseReference ) ); +} + +void ComparisonVisitorTest::testJournalComparison() +{ + const QString summary = QLatin1String( "Testing comparison" ); + const QString desc = QLatin1String( "Testing ComparisonVisitor" ); + const KDateTime now = KDateTime::currentUtcDateTime(); + + Journal reference; + reference.setSummary( summary ); + reference.setDescription( desc ); + reference.setDtStart( now ); + + // create a copy of the reference incidence + Journal journal( reference ); + + IncidenceBase *baseReference = &reference; + IncidenceBase *baseIncidence = &journal; + + QVERIFY( mComparator.compare( baseIncidence, baseReference ) ); + + // change a property of Incidence (Journal has no new properties) (but not of IncidenceBase) + journal.setDescription( summary ); + QVERIFY( !mComparator.compare( baseIncidence, baseReference ) ); +} + +void ComparisonVisitorTest::testTodoComparison() +{ + const QString summary = QLatin1String( "Testing comparison" ); + const QString desc = QLatin1String( "Testing ComparisonVisitor" ); + + Todo reference; + reference.setSummary( summary ); + reference.setDescription( desc ); + reference.setPercentComplete( 50 ); + + // create a copy of the reference incidence + Todo todo( reference ); + + IncidenceBase *baseReference = &reference; + IncidenceBase *baseIncidence = &todo; + + QVERIFY( mComparator.compare( baseIncidence, baseReference ) ); + + // change a property of Todo (but not of IncidenceBase) + todo.setPercentComplete( 100 ); + QVERIFY( !mComparator.compare( baseIncidence, baseReference ) ); +} + +void ComparisonVisitorTest::testTypeMismatches() +{ + Event event; + FreeBusy freeBusy; + Journal journal; + Todo todo; + + QList list; + list << &event << &freeBusy << &journal << &todo << 0; + + for ( int i = 0; i < list.size(); ++i ) { + for ( int j = 0; j < list.size(); ++j ) { + if ( i == j ) + QVERIFY( mComparator.compare( list[ i ], list[ j ] ) ); + else + QVERIFY( !mComparator.compare( list[ i ], list[ j ] ) ); + } + } +} + +#include "kcalcomparisontest.moc" + +// kate: space-indent on; indent-width 2; replace-tabs on;