diff --git a/outboxinterface/CMakeLists.txt b/outboxinterface/CMakeLists.txt index 65a7e77b3..8a4578a8f 100644 --- a/outboxinterface/CMakeLists.txt +++ b/outboxinterface/CMakeLists.txt @@ -1,39 +1,40 @@ add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) add_subdirectory( tests ) set( outboxinterface_lib_srcs dispatcherinterface.cpp messagequeuejob.cpp outboxactions.cpp addressattribute.cpp dispatchmodeattribute.cpp errorattribute.cpp sentbehaviourattribute.cpp transportattribute.cpp + attributeregistrar.cpp ) kde4_add_library( outboxinterface SHARED ${outboxinterface_lib_srcs} ) target_link_libraries( outboxinterface ${KDE4_KIO_LIBS} akonadi-kde akonadi-kmime kmime mailtransport ) set_target_properties( outboxinterface PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install( TARGETS outboxinterface ${INSTALL_TARGETS_DEFAULT_ARGS} ) install( FILES outboxinterface_export.h dispatcherinterface.h messagequeuejob.h outboxactions.h addressattribute.h dispatchmodeattribute.h errorattribute.h sentbehaviourattribute.h transportattribute.h DESTINATION ${INCLUDE_INSTALL_DIR}/outboxinterface COMPONENT Devel ) diff --git a/outboxinterface/TODO b/outboxinterface/TODO index 0b53d3218..b6902daf1 100644 --- a/outboxinterface/TODO +++ b/outboxinterface/TODO @@ -1,9 +1,11 @@ Design: * Use d-pointers for the attributes? Or rely on having SomeAttrV2 in case something needs to be added? -* Currently apps have to call DispatcherInterface::self() for the attributes to - get registered. Find a way to do this automatically. + +Future: +* Support volatile outbox (not stored on disk). +* Support optional default folders (e.g. no sent-mail for IMAP users). Build: * Get our own debug area. diff --git a/outboxinterface/attributeregistrar.cpp b/outboxinterface/attributeregistrar.cpp new file mode 100644 index 000000000..ff424643e --- /dev/null +++ b/outboxinterface/attributeregistrar.cpp @@ -0,0 +1,46 @@ +/* + Copyright (c) 2009 Constantin Berzan + + 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 "addressattribute.h" +#include "dispatchmodeattribute.h" +#include "errorattribute.h" +#include "sentbehaviourattribute.h" +#include "transportattribute.h" + +#include + +namespace { + +// Anonymous namespace; function is invisible outside this file. +bool dummy() +{ + using namespace Akonadi; + using namespace OutboxInterface; + AttributeFactory::registerAttribute(); + AttributeFactory::registerAttribute(); + AttributeFactory::registerAttribute(); + AttributeFactory::registerAttribute(); + AttributeFactory::registerAttribute(); + return true; +} + +// Called when this library is loaded. +const bool registered = dummy(); + +} // namespace diff --git a/outboxinterface/dispatcherinterface.cpp b/outboxinterface/dispatcherinterface.cpp index cb02e0969..d85ddeb47 100644 --- a/outboxinterface/dispatcherinterface.cpp +++ b/outboxinterface/dispatcherinterface.cpp @@ -1,130 +1,118 @@ /* Copyright (c) 2009 Constantin Berzan 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 "dispatcherinterface.h" -#include "addressattribute.h" -#include "dispatchmodeattribute.h" -#include "errorattribute.h" #include "outboxactions.h" -#include "sentbehaviourattribute.h" -#include "transportattribute.h" #include #include #include #include -#include #include #include #include using namespace Akonadi; using namespace OutboxInterface; /** @internal */ class OutboxInterface::DispatcherInterfacePrivate { public: DispatcherInterfacePrivate(); ~DispatcherInterfacePrivate(); DispatcherInterface *instance; // slots void massModifyResult( KJob *job ); }; K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) DispatcherInterfacePrivate::DispatcherInterfacePrivate() : instance( new DispatcherInterface( this ) ) { } DispatcherInterfacePrivate::~DispatcherInterfacePrivate() { delete instance; } void DispatcherInterfacePrivate::massModifyResult( KJob *job ) { // Nothing to do here, really. If the job fails, the user can retry it. if( job->error() ) { kDebug() << "failed" << job->errorString(); } else { kDebug() << "succeeded."; } } DispatcherInterface::DispatcherInterface( DispatcherInterfacePrivate *dd ) : QObject() , d( dd ) { - // register attributes - AttributeFactory::registerAttribute(); - AttributeFactory::registerAttribute(); - AttributeFactory::registerAttribute(); - AttributeFactory::registerAttribute(); - AttributeFactory::registerAttribute(); } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } AgentInstance DispatcherInterface::dispatcherInstance() const { AgentInstance a = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); if( !a.isValid() ) { kWarning() << "Could not get MDA instance."; } return a; } void DispatcherInterface::dispatchManually() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new SendQueuedAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } void DispatcherInterface::retryDispatching() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new ClearErrorAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } #include "dispatcherinterface.moc" diff --git a/outboxinterface/dispatchmodeattribute.cpp b/outboxinterface/dispatchmodeattribute.cpp index 3cbc5de41..cbf401788 100644 --- a/outboxinterface/dispatchmodeattribute.cpp +++ b/outboxinterface/dispatchmodeattribute.cpp @@ -1,95 +1,97 @@ /* Copyright 2009 Constantin Berzan 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 "dispatchmodeattribute.h" #include +#include "akonadi/attributefactory.h" + using namespace Akonadi; using namespace OutboxInterface; DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode, const QDateTime &date ) : mMode( mode ) , mDueDate( date ) { } DispatchModeAttribute::~DispatchModeAttribute() { } DispatchModeAttribute* DispatchModeAttribute::clone() const { return new DispatchModeAttribute( mMode, mDueDate ); } QByteArray DispatchModeAttribute::type() const { static const QByteArray sType( "DispatchModeAttribute" ); return sType; } QByteArray DispatchModeAttribute::serialized() const { switch( mMode ) { case Immediately: return "immediately"; case AfterDueDate: return "after" + mDueDate.toString(Qt::ISODate).toLatin1(); case Never: return "never"; } Q_ASSERT( false ); return QByteArray(); // suppress control-reaches-end-of-non-void-function warning } void DispatchModeAttribute::deserialize( const QByteArray &data ) { mDueDate = QDateTime(); if ( data == "immediately" ) { mMode = Immediately; } else if ( data == "never" ) { mMode = Never; } else if ( data.startsWith( QByteArray( "after" ) ) ) { mMode = AfterDueDate; mDueDate = QDateTime::fromString( data.mid(5), Qt::ISODate ); // NOTE: 5 is the strlen of "after". } else { kWarning() << "Failed to deserialize data [" << data << "]"; } } DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const { return mMode; } void DispatchModeAttribute::setDispatchMode( DispatchMode mode ) { mMode = mode; } QDateTime DispatchModeAttribute::dueDate() const { return mDueDate; } void DispatchModeAttribute::setDueDate( const QDateTime &date ) { mDueDate = date; } diff --git a/outboxinterface/tests/CMakeLists.txt b/outboxinterface/tests/CMakeLists.txt index 13deeb25d..963f43a60 100644 --- a/outboxinterface/tests/CMakeLists.txt +++ b/outboxinterface/tests/CMakeLists.txt @@ -1,61 +1,62 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set(queuer_srcs queuer.cpp) kde4_add_executable(queuer TEST ${queuer_srcs}) target_link_libraries(queuer ${KDE4_KDEUI_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} outboxinterface) set( sendqueued_srcs sendqueued.cpp ) kde4_add_executable( sendqueued TEST ${sendqueued_srcs} ) target_link_libraries( sendqueued outboxinterface ) set( clearerror_srcs clearerror.cpp ) kde4_add_executable( clearerror TEST ${clearerror_srcs} ) target_link_libraries( clearerror outboxinterface ) set( abort_srcs abort.cpp ) kde4_add_executable( abort TEST ${abort_srcs} ) target_link_libraries( abort outboxinterface ) # Stolen from kdepimlibs/akonadi/tests macro(add_akonadi_isolated_test _source) get_filename_component(_targetName ${_source} NAME_WE) set(_srcList ${_source} ) kde4_add_executable(${_targetName} TEST ${_srcList}) target_link_libraries(${_targetName} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_AKONADI_LIBS} ${KDE4_KDECORE_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} outboxinterface ) # based on kde4_add_unit_test if (WIN32) get_target_property( _loc ${_targetName} LOCATION ) set(_executable ${_loc}.bat) else (WIN32) set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_targetName}) endif (WIN32) if (UNIX) set(_executable ${_executable}.shell) endif (UNIX) find_program(_testrunner akonaditest) add_test( outboxinterface-${_targetName} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) endmacro(add_akonadi_isolated_test) +add_akonadi_isolated_test( attributetest.cpp ) add_akonadi_isolated_test( messagequeuejobtest.cpp ) diff --git a/outboxinterface/tests/attributetest.cpp b/outboxinterface/tests/attributetest.cpp new file mode 100644 index 000000000..03c1ede14 --- /dev/null +++ b/outboxinterface/tests/attributetest.cpp @@ -0,0 +1,69 @@ +/* + Copyright 2009 Constantin Berzan + + 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 "attributetest.h" + +#include +#include + +#include +#include +#include +#include +#include + +using namespace Akonadi; +using namespace OutboxInterface; + +void AttributeTest::initTestCase() +{ +} + +void AttributeTest::testRegistrar() +{ + // The attributes should have been registered without any effort on our part. + { + Attribute *a = AttributeFactory::createAttribute( "AddressAttribute" ); + QVERIFY( dynamic_cast( a ) ); + } + + { + Attribute *a = AttributeFactory::createAttribute( "DispatchModeAttribute" ); + QVERIFY( dynamic_cast( a ) ); + } + + { + Attribute *a = AttributeFactory::createAttribute( "ErrorAttribute" ); + QVERIFY( dynamic_cast( a ) ); + } + + { + Attribute *a = AttributeFactory::createAttribute( "SentBehaviourAttribute" ); + QVERIFY( dynamic_cast( a ) ); + } + + { + Attribute *a = AttributeFactory::createAttribute( "TransportAttribute" ); + QVERIFY( dynamic_cast( a ) ); + } +} + +QTEST_AKONADIMAIN( AttributeTest, NoGUI ) + +#include "attributetest.moc" diff --git a/outboxinterface/tests/messagequeuejobtest.h b/outboxinterface/tests/attributetest.h similarity index 69% copy from outboxinterface/tests/messagequeuejobtest.h copy to outboxinterface/tests/attributetest.h index 23ca4cf35..4e345f7d2 100644 --- a/outboxinterface/tests/messagequeuejobtest.h +++ b/outboxinterface/tests/attributetest.h @@ -1,47 +1,40 @@ /* Copyright 2009 Constantin Berzan 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 MESSAGEQUEUEJOBTEST_H -#define MESSAGEQUEUEJOBTEST_H +#ifndef ATTRIBUTETEST_H +#define ATTRIBUTETEST_H #include - /** - This tests the ability to queue messages (MessageQueueJob class). - Note that the actual sending of messages is the MDA's job, and is not tested - here. - */ -class MessageQueueJobTest : public QObject + This is a test of the various attributes. +*/ +class AttributeTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); - void testAddressesFromMime(); - void testValidMessages(); - void testInvalidMessages(); + void testRegistrar(); - private: - void verifyOutboxContents( qlonglong count ); + // TODO test serialization / deserialization }; - #endif diff --git a/outboxinterface/tests/clearerror.cpp b/outboxinterface/tests/clearerror.cpp index 501a1d89a..7f81a57f1 100644 --- a/outboxinterface/tests/clearerror.cpp +++ b/outboxinterface/tests/clearerror.cpp @@ -1,86 +1,82 @@ /* Copyright (c) 2009 Constantin Berzan 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 "clearerror.h" #include #include #include #include #include #include #include #include -#include #include using namespace Akonadi; using namespace OutboxInterface; Runner::Runner() { Control::start(); connect( LocalFolders::self(), SIGNAL( foldersReady() ), this, SLOT( checkFolders() ) ); LocalFolders::self()->fetch(); - - // HACK: Register attributes. - DispatcherInterface::self(); } void Runner::checkFolders() { Collection outbox = LocalFolders::self()->outbox(); kDebug() << "Got outbox" << outbox.id(); if( !outbox.isValid() ) { KApplication::exit( 1 ); } FilterActionJob *fjob = new FilterActionJob( outbox, new ClearErrorAction, this ); connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); } void Runner::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "Job error:" << job->errorString(); KApplication::exit( 2 ); } else { kDebug() << "Job success."; KApplication::exit( 0 ); } } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "clearerror", 0, ki18n( "clearerror" ), "0", ki18n( "An app that re-queues failed items from the outbox" ) ); KApplication app; new Runner(); return app.exec(); } #include "clearerror.moc" diff --git a/outboxinterface/tests/messagequeuejobtest.cpp b/outboxinterface/tests/messagequeuejobtest.cpp index 6be922df8..e49c06180 100644 --- a/outboxinterface/tests/messagequeuejobtest.cpp +++ b/outboxinterface/tests/messagequeuejobtest.cpp @@ -1,202 +1,193 @@ /* Copyright 2009 Constantin Berzan 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 "messagequeuejobtest.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #define SPAM_ADDRESS ( QStringList() << "idanoka@gmail.com" ) using namespace Akonadi; using namespace KMime; using namespace MailTransport; using namespace OutboxInterface; void MessageQueueJobTest::initTestCase() { Control::start(); // HACK: Otherwise the MDA is not switched offline soon enough apparently... QTest::qWait( 1000 ); - // HACK: Register attributes. - DispatcherInterface::self(); - // Switch MDA offline to avoid spam. AgentInstance mda = AgentManager::self()->instance( "akonadi_maildispatcher_agent" ); QVERIFY( mda.isValid() ); mda.setIsOnline( false ); // check that outbox is empty LocalFolders::self()->fetch(); QTest::kWaitForSignal( LocalFolders::self(), SIGNAL( foldersReady() ) ); verifyOutboxContents( 0 ); } -void MessageQueueJobTest::testAddressesFromMime() -{ - // TODO -} - void MessageQueueJobTest::testValidMessages() { // check transport int tid = TransportManager::self()->defaultTransportId(); QVERIFY2( tid >= 0, "I need a default transport, but there is none." ); // send a valid message using the default transport MessageQueueJob *qjob = new MessageQueueJob; qjob->setTransportId( tid ); Message::Ptr msg = Message::Ptr( new Message ); msg->setContent( "\nThis is message #1 from the MessageQueueJobTest unit test.\n" ); qjob->setMessage( msg ); qjob->setTo( SPAM_ADDRESS ); verifyOutboxContents( 0 ); AKVERIFYEXEC( qjob ); // fetch the message and verify it QTest::qWait( 1000 ); verifyOutboxContents( 1 ); ItemFetchJob *fjob = new ItemFetchJob( LocalFolders::self()->outbox() ); fjob->fetchScope().fetchFullPayload(); fjob->fetchScope().fetchAllAttributes(); AKVERIFYEXEC( fjob ); QCOMPARE( fjob->items().count(), 1 ); Item item = fjob->items().first(); QVERIFY( !item.remoteId().isEmpty() ); // stored by the resource QVERIFY( item.hasPayload() ); AddressAttribute *addrA = item.attribute(); QVERIFY( addrA ); QVERIFY( addrA->from().isEmpty() ); QCOMPARE( addrA->to().count(), 1 ); QCOMPARE( addrA->to(), SPAM_ADDRESS ); QCOMPARE( addrA->cc().count(), 0 ); QCOMPARE( addrA->bcc().count(), 0 ); DispatchModeAttribute *dA = item.attribute(); QVERIFY( dA ); QCOMPARE( dA->dispatchMode(), DispatchModeAttribute::Immediately ); // default mode SentBehaviourAttribute *sA = item.attribute(); QVERIFY( sA ); QCOMPARE( sA->sentBehaviour(), SentBehaviourAttribute::MoveToDefaultSentCollection ); // default sent collection TransportAttribute *tA = item.attribute(); QVERIFY( tA ); QCOMPARE( tA->transportId(), tid ); ErrorAttribute *eA = item.attribute(); QVERIFY( !eA ); // no error QCOMPARE( item.flags().count(), 1 ); QVERIFY( item.flags().contains( "queued" ) ); // delete message, for further tests ItemDeleteJob *djob = new ItemDeleteJob( item ); AKVERIFYEXEC( djob ); verifyOutboxContents( 0 ); // TODO test with no To: but only BCC: // TODO test due-date sending // TODO test sending with custom sent-mail collections } void MessageQueueJobTest::testInvalidMessages() { MessageQueueJob *job = 0; Message::Ptr msg; // without message job = new MessageQueueJob; job->setTransportId( TransportManager::self()->defaultTransportId() ); job->setTo( SPAM_ADDRESS ); QVERIFY( !job->exec() ); // without recipients job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTransportId( TransportManager::self()->defaultTransportId() ); QVERIFY( !job->exec() ); // without transport job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); QVERIFY( !job->exec() ); // with AfterDueDate and no due date job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); job->setDispatchMode( DispatchModeAttribute::AfterDueDate ); QVERIFY( !job->exec() ); // with MoveToCollection and no sent-mail folder job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); job->setSentBehaviour( SentBehaviourAttribute::MoveToCollection ); QVERIFY( !job->exec() ); } void MessageQueueJobTest::verifyOutboxContents( qlonglong count ) { QVERIFY( LocalFolders::self()->isReady() ); Collection outbox = LocalFolders::self()->outbox(); QVERIFY( outbox.isValid() ); CollectionStatisticsJob *job = new CollectionStatisticsJob( outbox ); AKVERIFYEXEC( job ); QCOMPARE( job->statistics().count(), count ); } QTEST_AKONADIMAIN( MessageQueueJobTest, NoGUI ) #include "messagequeuejobtest.moc" diff --git a/outboxinterface/tests/messagequeuejobtest.h b/outboxinterface/tests/messagequeuejobtest.h index 23ca4cf35..767e6539c 100644 --- a/outboxinterface/tests/messagequeuejobtest.h +++ b/outboxinterface/tests/messagequeuejobtest.h @@ -1,47 +1,46 @@ /* Copyright 2009 Constantin Berzan 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 MESSAGEQUEUEJOBTEST_H #define MESSAGEQUEUEJOBTEST_H #include /** This tests the ability to queue messages (MessageQueueJob class). Note that the actual sending of messages is the MDA's job, and is not tested here. */ class MessageQueueJobTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); - void testAddressesFromMime(); void testValidMessages(); void testInvalidMessages(); private: void verifyOutboxContents( qlonglong count ); }; #endif diff --git a/outboxinterface/tests/sendqueued.cpp b/outboxinterface/tests/sendqueued.cpp index 1d8f621d7..4396a6f2e 100644 --- a/outboxinterface/tests/sendqueued.cpp +++ b/outboxinterface/tests/sendqueued.cpp @@ -1,86 +1,82 @@ /* Copyright (c) 2009 Constantin Berzan 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 "sendqueued.h" #include #include #include #include #include #include #include #include -#include #include using namespace Akonadi; using namespace OutboxInterface; Runner::Runner() { Control::start(); connect( LocalFolders::self(), SIGNAL( foldersReady() ), this, SLOT( checkFolders() ) ); LocalFolders::self()->fetch(); - - // HACK: Register attributes. - DispatcherInterface::self(); } void Runner::checkFolders() { Collection outbox = LocalFolders::self()->outbox(); kDebug() << "Got outbox" << outbox.id(); if( !outbox.isValid() ) { KApplication::exit( 1 ); } FilterActionJob *fjob = new FilterActionJob( outbox, new SendQueuedAction, this ); connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); } void Runner::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "Job error:" << job->errorString(); KApplication::exit( 2 ); } else { kDebug() << "Job success."; KApplication::exit( 0 ); } } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "sendqueued", 0, ki18n( "sendqueued" ), "0", ki18n( "An app that sends all queued messages" ) ); KApplication app; new Runner(); return app.exec(); } #include "sendqueued.moc"