diff --git a/akonadi/itemdeletejob.cpp b/akonadi/itemdeletejob.cpp index 60503705a..51026dc34 100644 --- a/akonadi/itemdeletejob.cpp +++ b/akonadi/itemdeletejob.cpp @@ -1,92 +1,88 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 "itemdeletejob.h" #include "itemmodifyjob.h" #include "job_p.h" -#include "transactionjobs.h" +#include "transactionsequence.h" #include "expungejob.h" using namespace Akonadi; class Akonadi::ItemDeleteJobPrivate : public JobPrivate { public: enum State { Begin, Store, Expunge, Commit }; ItemDeleteJobPrivate( ItemDeleteJob *parent ) : JobPrivate( parent ) { } void jobDone( KJob* ); Q_DECLARE_PUBLIC( ItemDeleteJob ) Item mItem; State mState; }; void ItemDeleteJobPrivate::jobDone( KJob * job ) { Q_Q( ItemDeleteJob ); if ( !job->error() ) // error is already handled by KCompositeJob q->emitResult(); } ItemDeleteJob::ItemDeleteJob( const Item & item, QObject * parent ) : Job( new ItemDeleteJobPrivate( this ), parent ) { Q_D( ItemDeleteJob ); d->mItem = item; d->mState = ItemDeleteJobPrivate::Begin; } ItemDeleteJob::~ItemDeleteJob() { } void ItemDeleteJob::doStart() { Q_D( ItemDeleteJob ); - TransactionBeginJob *begin = new TransactionBeginJob( this ); - addSubjob( begin ); + TransactionSequence *transaction = new TransactionSequence( this ); + connect( transaction, SIGNAL(result(KJob*)), SLOT(jobDone(KJob*)) ); + addSubjob( transaction ); d->mItem.setFlag( "\\Deleted" ); - ItemModifyJob* store = new ItemModifyJob( d->mItem, this ); + ItemModifyJob* store = new ItemModifyJob( d->mItem, transaction ); store->disableRevisionCheck(); - addSubjob( store ); - ExpungeJob *expunge = new ExpungeJob( this ); - addSubjob( expunge ); - - TransactionCommitJob *commit = new TransactionCommitJob( this ); - connect( commit, SIGNAL(result(KJob*)), SLOT(jobDone(KJob*)) ); - addSubjob( commit ); + new ExpungeJob( transaction ); + transaction->commit(); } #include "itemdeletejob.moc" diff --git a/akonadi/tests/CMakeLists.txt b/akonadi/tests/CMakeLists.txt index 50bd983e9..7a14d8715 100644 --- a/akonadi/tests/CMakeLists.txt +++ b/akonadi/tests/CMakeLists.txt @@ -1,110 +1,111 @@ if(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH} ) else(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH . ) endif(${EXECUTABLE_OUTPUT_PATH}) set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) include_directories( ${CMAKE_SOURCE_DIR}/akonadi ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ${Boost_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ) # add testrunner (application for managing a self-contained test # environment) add_subdirectory(testrunner) # add benchmarker add_subdirectory(benchmarker) # convenience macro to add akonadi demo application macro(add_akonadi_demo _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS}) endmacro(add_akonadi_demo) # convenience macro to add akonadi qtestlib unit-tests macro(add_akonadi_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_unit_test(${_name} TESTNAME libakonadi-${_name} ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) endmacro(add_akonadi_test) # convenience macro to add akonadi testrunner unit-tests macro(add_akonadi_isolated_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) # based on kde4_add_unit_test if (WIN32) get_target_property( _loc ${_name} LOCATION ) set(_executable ${_loc}.bat) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest.bat) else (WIN32) set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_name}) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest) endif (WIN32) if (UNIX) set(_executable ${_executable}.shell) set(_testrunner ${_testrunner}.shell) endif (UNIX) add_test( libakonadi-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) endmacro(add_akonadi_isolated_test) # demo applications add_akonadi_demo(itemdumper.cpp) add_akonadi_demo(subscriber.cpp) add_akonadi_demo(headfetcher.cpp) add_akonadi_demo(agentinstancewidgettest.cpp) add_akonadi_demo(agenttypewidgettest.cpp) add_akonadi_demo(pluginloadertest.cpp) add_akonadi_demo(selftester.cpp) kde4_add_executable( akonadi-firstrun TEST ../firstrun.cpp firstrunner.cpp ) target_link_libraries( akonadi-firstrun akonadi-kde ${KDE4_KDEUI_LIBS} ) # qtestlib unit tests add_akonadi_test(imapparsertest.cpp) add_akonadi_test(imapsettest.cpp) add_akonadi_test(itemhydratest.cpp) add_akonadi_test(itemtest.cpp) add_akonadi_test(itemserializertest.cpp) add_akonadi_test(mimetypecheckertest.cpp) add_akonadi_test(notificationmessagetest.cpp) # testrunner tests add_akonadi_isolated_test(testenvironmenttest.cpp) add_akonadi_isolated_test(collectionjobtest.cpp) add_akonadi_isolated_test(collectionpathresolvertest.cpp) add_akonadi_isolated_test(collectionattributetest.cpp) add_akonadi_isolated_test(itemfetchtest.cpp) add_akonadi_isolated_test(itemappendtest.cpp) add_akonadi_isolated_test(itemstoretest.cpp) +add_akonadi_isolated_test(itemdeletetest.cpp) add_akonadi_isolated_test(monitortest.cpp) add_akonadi_isolated_test(searchjobtest.cpp) add_akonadi_isolated_test(changerecordertest.cpp) add_akonadi_isolated_test(resourcetest.cpp) add_akonadi_isolated_test(subscriptiontest.cpp) add_akonadi_isolated_test(transactiontest.cpp) add_akonadi_isolated_test(itemcopytest.cpp) add_akonadi_isolated_test(itemmovetest.cpp) add_akonadi_isolated_test(collectioncopytest.cpp) add_akonadi_isolated_test(collectionmovetest.cpp) add_akonadi_isolated_test(itemsynctest.cpp) add_akonadi_isolated_test(linktest.cpp) add_akonadi_isolated_test(servermanagertest.cpp) add_akonadi_isolated_test(collectioncreator.cpp) diff --git a/akonadi/tests/itemdeletetest.cpp b/akonadi/tests/itemdeletetest.cpp new file mode 100644 index 000000000..21d09321b --- /dev/null +++ b/akonadi/tests/itemdeletetest.cpp @@ -0,0 +1,65 @@ +/* + Copyright (c) 20089 Volker Krause + + 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 +#include +#include +#include +#include +#include + +#include + +#include + +using namespace Akonadi; + +class LinkTest : public QObject +{ + Q_OBJECT + private slots: + void initTestCase() + { + Control::start(); + } + + void testIleagalDelete() + { + ItemDeleteJob *djob = new ItemDeleteJob( Item( INT_MAX ), this ); + QVERIFY( !djob->exec() ); + + // make sure a failed delete doesn't leave a transaction open (the kpilot bug) + TransactionRollbackJob *tjob = new TransactionRollbackJob( this ); + QVERIFY( !tjob->exec() ); + } + + void testDelete() + { + ItemDeleteJob *djob = new ItemDeleteJob( Item( 1 ), this ); + QVERIFY( djob->exec() ); + + ItemFetchJob *fjob = new ItemFetchJob( Item( 1 ), this ); + fjob->exec(); + QCOMPARE( fjob->items().count(), 0 ); + } +}; + +QTEST_AKONADIMAIN( LinkTest, NoGUI ) + +#include "itemdeletetest.moc"