diff --git a/kcal/tests/CMakeLists.txt b/kcal/tests/CMakeLists.txt index 55d9623f6..5a8a0bab1 100644 --- a/kcal/tests/CMakeLists.txt +++ b/kcal/tests/CMakeLists.txt @@ -1,122 +1,123 @@ 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 + testcustomproperties 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/testcustomproperties.cpp b/kcal/tests/testcustomproperties.cpp new file mode 100644 index 000000000..24ea42aa6 --- /dev/null +++ b/kcal/tests/testcustomproperties.cpp @@ -0,0 +1,110 @@ +/* + This file is part of the kcal library. + Copyright (c) 2009 Allen Winter + + 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 "testcustomproperties.h" +#include "testcustomproperties.moc" +#include + +QTEST_KDEMAIN( CustomPropertiesTest, NoGUI ) + +#include "kcal/customproperties.h" +using namespace KCal; + +void CustomPropertiesTest::testValidity() +{ + CustomProperties cp; + + QByteArray app( "KORG" ); + QByteArray key( "TEXT" ); + + cp.setCustomProperty( app, key, "rich" ); + QCOMPARE( cp.customProperty( app, key ), QString( "rich" ) ); + + cp.removeCustomProperty( app, key ); + cp.setCustomProperty( app, key, "foo" ); + cp.setCustomProperty( app, key, "rich" ); + QCOMPARE( cp.customProperty( app, key ), QString( "rich" ) ); + + key = "X-TEXT"; + cp.setNonKDECustomProperty( key, "rich" ); + QCOMPARE( cp.nonKDECustomProperty( key ), QString( "rich" ) ); + + cp.removeNonKDECustomProperty( key ); + cp.setNonKDECustomProperty( key, "foo" ); + cp.setNonKDECustomProperty( key, "rich" ); + QCOMPARE( cp.nonKDECustomProperty( key ), QString( "rich" ) ); +} + +void CustomPropertiesTest::testCompare() +{ + CustomProperties cp1, cp2; + + QByteArray app( "KORG" ); + QByteArray key( "TEXT" ); + + cp1.setCustomProperty( app, key, "rich" ); + cp2 = cp1; + QVERIFY( cp1 == cp2 ); + + CustomProperties cp3; + cp3.setCustomProperty( app, key, cp1.customProperty( app, key ) ); + QVERIFY( cp1 == cp3 ); + + key = "X-TEXT"; + cp1.setNonKDECustomProperty( key, "rich" ); + cp2 = cp1; + QVERIFY( cp1 == cp2 ); + + cp3.setNonKDECustomProperty( key, cp1.nonKDECustomProperty( key ) ); + QVERIFY( cp1 == cp3 ); +} + +void CustomPropertiesTest::testMapValidity() +{ + QMap cpmap; + cpmap.insert( "X-key1", QString( "val1" ) ); + cpmap.insert( "X-key2", QString( "val2" ) ); + cpmap.insert( "X-key3", QString( "val3" ) ); + cpmap.insert( "X-key4", QString( "val4" ) ); + cpmap.insert( "X-key5", QString( "val5" ) ); + + CustomProperties cp; + cp.setCustomProperties( cpmap ); + + QVERIFY( cp.customProperties().value( "X-key3" ) == QString( "val3" ) ); +} + +void CustomPropertiesTest::testMapCompare() +{ + QMap cpmap; + cpmap.insert( "X-key1", QString( "val1" ) ); + cpmap.insert( "X-key2", QString( "val2" ) ); + cpmap.insert( "X-key3", QString( "val3" ) ); + cpmap.insert( "X-key4", QString( "val4" ) ); + cpmap.insert( "X-key5", QString( "val5" ) ); + + CustomProperties cp1, cp2; + cp1.setCustomProperties( cpmap ); + cp1 = cp2; + QVERIFY( cp1 == cp2 ); + + CustomProperties cp3; + cp3.setCustomProperties( cp1.customProperties() ); + QVERIFY( cp1 == cp3 ); +} diff --git a/kcal/tests/testcustomproperties.h b/kcal/tests/testcustomproperties.h new file mode 100644 index 000000000..2c6f6a2b0 --- /dev/null +++ b/kcal/tests/testcustomproperties.h @@ -0,0 +1,36 @@ +/* + This file is part of the kcal library. + Copyright (c) 2009 Allen Winter + + 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 TESTCUSTOMPROPERTIES_H +#define TESTCUSTOMPROPERTIES_H + +#include + +class CustomPropertiesTest : public QObject +{ + Q_OBJECT + private Q_SLOTS: + void testValidity(); + void testCompare(); + void testMapValidity(); + void testMapCompare(); +}; + +#endif