Commit 3c1f833f authored by Laurent Montel's avatar Laurent Montel 😁

astyle-kdelibs

parent 308e1a2c
......@@ -19,7 +19,6 @@
#include "attributetest.h"
#include <attributefactory.h>
#include <qtest_akonadi.h>
#include <addressattribute.h>
......@@ -39,130 +38,130 @@ 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<AddressAttribute*>( a ) );
}
{
Attribute *a = AttributeFactory::createAttribute( "DispatchModeAttribute" );
QVERIFY( dynamic_cast<DispatchModeAttribute*>( a ) );
}
{
Attribute *a = AttributeFactory::createAttribute( "ErrorAttribute" );
QVERIFY( dynamic_cast<ErrorAttribute*>( a ) );
}
{
Attribute *a = AttributeFactory::createAttribute( "SentActionAttribute" );
QVERIFY( dynamic_cast<SentActionAttribute*>( a ) );
}
{
Attribute *a = AttributeFactory::createAttribute( "SentBehaviourAttribute" );
QVERIFY( dynamic_cast<SentBehaviourAttribute*>( a ) );
}
{
Attribute *a = AttributeFactory::createAttribute( "TransportAttribute" );
QVERIFY( dynamic_cast<TransportAttribute*>( a ) );
}
// The attributes should have been registered without any effort on our part.
{
Attribute *a = AttributeFactory::createAttribute("AddressAttribute");
QVERIFY(dynamic_cast<AddressAttribute *>(a));
}
{
Attribute *a = AttributeFactory::createAttribute("DispatchModeAttribute");
QVERIFY(dynamic_cast<DispatchModeAttribute *>(a));
}
{
Attribute *a = AttributeFactory::createAttribute("ErrorAttribute");
QVERIFY(dynamic_cast<ErrorAttribute *>(a));
}
{
Attribute *a = AttributeFactory::createAttribute("SentActionAttribute");
QVERIFY(dynamic_cast<SentActionAttribute *>(a));
}
{
Attribute *a = AttributeFactory::createAttribute("SentBehaviourAttribute");
QVERIFY(dynamic_cast<SentBehaviourAttribute *>(a));
}
{
Attribute *a = AttributeFactory::createAttribute("TransportAttribute");
QVERIFY(dynamic_cast<TransportAttribute *>(a));
}
}
void AttributeTest::testSerialization()
{
{
QString from( "from@me.org" );
QStringList to( "to1@me.org" );
to << "to2@me.org";
QStringList cc( "cc1@me.org" );
cc << "cc2@me.org";
QStringList bcc( "bcc1@me.org" );
bcc << "bcc2@me.org";
AddressAttribute *a = new AddressAttribute( from, to, cc, bcc );
QByteArray data = a->serialized();
delete a;
a = new AddressAttribute;
a->deserialize( data );
QCOMPARE( from, a->from() );
QCOMPARE( to, a->to() );
QCOMPARE( cc, a->cc() );
QCOMPARE( bcc, a->bcc() );
}
{
DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::Automatic;
QDateTime date = QDateTime::currentDateTime();
// The serializer does not keep track of milliseconds, so forget them.
qDebug() << "ms" << date.toString( "z" );
int ms = date.toString( "z" ).toInt();
date = date.addMSecs( -ms );
DispatchModeAttribute *a = new DispatchModeAttribute( mode );
a->setSendAfter( date );
QByteArray data = a->serialized();
delete a;
a = new DispatchModeAttribute;
a->deserialize( data );
QCOMPARE( mode, a->dispatchMode() );
QCOMPARE( date, a->sendAfter() );
}
{
QString msg( "The #!@$ing thing failed!" );
ErrorAttribute *a = new ErrorAttribute( msg );
QByteArray data = a->serialized();
delete a;
a = new ErrorAttribute;
a->deserialize( data );
QCOMPARE( msg, a->message() );
}
{
SentActionAttribute *a = new SentActionAttribute();
const qlonglong id = 123456789012345ll;
a->addAction( SentActionAttribute::Action::MarkAsReplied, QVariant( id ) );
a->addAction( SentActionAttribute::Action::MarkAsForwarded, QVariant( id ) );
QByteArray data = a->serialized();
delete a;
a = new SentActionAttribute;
a->deserialize( data );
const SentActionAttribute::Action::List actions = a->actions();
QCOMPARE( actions.count(), 2 );
QCOMPARE( SentActionAttribute::Action::MarkAsReplied, actions[0].type() );
QCOMPARE( id, actions[0].value().toLongLong() );
QCOMPARE( SentActionAttribute::Action::MarkAsForwarded, actions[1].type() );
QCOMPARE( id, actions[1].value().toLongLong() );
}
{
SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection;
Collection::Id id = 123456789012345ll;
SentBehaviourAttribute *a = new SentBehaviourAttribute( beh, Collection( id ) );
QByteArray data = a->serialized();
delete a;
a = new SentBehaviourAttribute;
a->deserialize( data );
QCOMPARE( beh, a->sentBehaviour() );
QCOMPARE( id, a->moveToCollection().id() );
}
{
int id = 3219;
TransportAttribute *a = new TransportAttribute( id );
QByteArray data = a->serialized();
delete a;
a = new TransportAttribute;
a->deserialize( data );
QCOMPARE( id, a->transportId() );
}
{
QString from("from@me.org");
QStringList to("to1@me.org");
to << "to2@me.org";
QStringList cc("cc1@me.org");
cc << "cc2@me.org";
QStringList bcc("bcc1@me.org");
bcc << "bcc2@me.org";
AddressAttribute *a = new AddressAttribute(from, to, cc, bcc);
QByteArray data = a->serialized();
delete a;
a = new AddressAttribute;
a->deserialize(data);
QCOMPARE(from, a->from());
QCOMPARE(to, a->to());
QCOMPARE(cc, a->cc());
QCOMPARE(bcc, a->bcc());
}
{
DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::Automatic;
QDateTime date = QDateTime::currentDateTime();
// The serializer does not keep track of milliseconds, so forget them.
qDebug() << "ms" << date.toString("z");
int ms = date.toString("z").toInt();
date = date.addMSecs(-ms);
DispatchModeAttribute *a = new DispatchModeAttribute(mode);
a->setSendAfter(date);
QByteArray data = a->serialized();
delete a;
a = new DispatchModeAttribute;
a->deserialize(data);
QCOMPARE(mode, a->dispatchMode());
QCOMPARE(date, a->sendAfter());
}
{
QString msg("The #!@$ing thing failed!");
ErrorAttribute *a = new ErrorAttribute(msg);
QByteArray data = a->serialized();
delete a;
a = new ErrorAttribute;
a->deserialize(data);
QCOMPARE(msg, a->message());
}
{
SentActionAttribute *a = new SentActionAttribute();
const qlonglong id = 123456789012345ll;
a->addAction(SentActionAttribute::Action::MarkAsReplied, QVariant(id));
a->addAction(SentActionAttribute::Action::MarkAsForwarded, QVariant(id));
QByteArray data = a->serialized();
delete a;
a = new SentActionAttribute;
a->deserialize(data);
const SentActionAttribute::Action::List actions = a->actions();
QCOMPARE(actions.count(), 2);
QCOMPARE(SentActionAttribute::Action::MarkAsReplied, actions[0].type());
QCOMPARE(id, actions[0].value().toLongLong());
QCOMPARE(SentActionAttribute::Action::MarkAsForwarded, actions[1].type());
QCOMPARE(id, actions[1].value().toLongLong());
}
{
SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection;
Collection::Id id = 123456789012345ll;
SentBehaviourAttribute *a = new SentBehaviourAttribute(beh, Collection(id));
QByteArray data = a->serialized();
delete a;
a = new SentBehaviourAttribute;
a->deserialize(data);
QCOMPARE(beh, a->sentBehaviour());
QCOMPARE(id, a->moveToCollection().id());
}
{
int id = 3219;
TransportAttribute *a = new TransportAttribute(id);
QByteArray data = a->serialized();
delete a;
a = new TransportAttribute;
a->deserialize(data);
QCOMPARE(id, a->transportId());
}
}
QTEST_AKONADIMAIN( AttributeTest, NoGUI )
QTEST_AKONADIMAIN(AttributeTest, NoGUI)
......@@ -27,9 +27,9 @@
*/
class AttributeTest : public QObject
{
Q_OBJECT
Q_OBJECT
private Q_SLOTS:
private Q_SLOTS:
void initTestCase();
void testRegistrar();
void testSerialization();
......
......@@ -21,7 +21,6 @@
#include <collectionpathresolver_p.h>
#include <testattribute.h>
#include <attributefactory.h>
#include <collectioncreatejob.h>
#include <itemcreatejob.h>
......@@ -33,7 +32,7 @@
using namespace Akonadi;
QTEST_AKONADIMAIN( FilterActionTest, NoGUI )
QTEST_AKONADIMAIN(FilterActionTest, NoGUI)
static const QByteArray acceptable = "acceptable";
static const QByteArray unacceptable = "unacceptable";
......@@ -44,163 +43,163 @@ class MyFunctor : public FilterAction
{
virtual Akonadi::ItemFetchScope fetchScope() const
{
ItemFetchScope scope;
scope.fetchAttribute<TestAttribute>();
return scope;
ItemFetchScope scope;
scope.fetchAttribute<TestAttribute>();
return scope;
}
virtual bool itemAccepted( const Akonadi::Item &item ) const
virtual bool itemAccepted(const Akonadi::Item &item) const
{
if ( !item.hasAttribute<TestAttribute>() ) {
return false;
}
return ( item.attribute<TestAttribute>()->data == acceptable );
if (!item.hasAttribute<TestAttribute>()) {
return false;
}
return (item.attribute<TestAttribute>()->data == acceptable);
}
virtual Akonadi::Job *itemAction( const Akonadi::Item &item, FilterActionJob *parent ) const
virtual Akonadi::Job *itemAction(const Akonadi::Item &item, FilterActionJob *parent) const
{
Item cp( item );
TestAttribute *newa = new TestAttribute;
newa->data = modified;
cp.addAttribute( newa );
return new ItemModifyJob( cp, parent );
Item cp(item);
TestAttribute *newa = new TestAttribute;
newa->data = modified;
cp.addAttribute(newa);
return new ItemModifyJob(cp, parent);
}
};
void FilterActionTest::initTestCase()
{
AttributeFactory::registerAttribute<TestAttribute>();
AttributeFactory::registerAttribute<TestAttribute>();
CollectionPathResolver *resolver = new CollectionPathResolver( "res1", this );
QVERIFY( resolver->exec() );
res1 = Collection( resolver->collection() );
CollectionPathResolver *resolver = new CollectionPathResolver("res1", this);
QVERIFY(resolver->exec());
res1 = Collection(resolver->collection());
}
void FilterActionTest::testMassModifyItem()
{
Collection col = createCollection( "testMassModifyItem" );
// Test acceptable item.
Item item = createItem( col, true );
FilterActionJob *mjob = new FilterActionJob( item, new MyFunctor, this );
AKVERIFYEXEC( mjob );
ItemFetchJob *fjob = new ItemFetchJob( item, this );
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC( fjob );
QCOMPARE( fjob->items().count(), 1 );
item = fjob->items().first();
QVERIFY( item.hasAttribute<TestAttribute>() );
TestAttribute *attr = item.attribute<TestAttribute>();
QCOMPARE( attr->data, modified );
// Test unacceptable item.
item = createItem( col, false );
mjob = new FilterActionJob( item, new MyFunctor, this );
AKVERIFYEXEC( mjob );
fjob = new ItemFetchJob( item, this );
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC( fjob );
QCOMPARE( fjob->items().count(), 1 );
item = fjob->items().first();
QVERIFY( item.hasAttribute<TestAttribute>() );
attr = item.attribute<TestAttribute>();
QCOMPARE( attr->data, unacceptable );
Collection col = createCollection("testMassModifyItem");
// Test acceptable item.
Item item = createItem(col, true);
FilterActionJob *mjob = new FilterActionJob(item, new MyFunctor, this);
AKVERIFYEXEC(mjob);
ItemFetchJob *fjob = new ItemFetchJob(item, this);
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 1);
item = fjob->items().first();
QVERIFY(item.hasAttribute<TestAttribute>());
TestAttribute *attr = item.attribute<TestAttribute>();
QCOMPARE(attr->data, modified);
// Test unacceptable item.
item = createItem(col, false);
mjob = new FilterActionJob(item, new MyFunctor, this);
AKVERIFYEXEC(mjob);
fjob = new ItemFetchJob(item, this);
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 1);
item = fjob->items().first();
QVERIFY(item.hasAttribute<TestAttribute>());
attr = item.attribute<TestAttribute>();
QCOMPARE(attr->data, unacceptable);
}
void FilterActionTest::testMassModifyItems()
{
Collection col = createCollection( "testMassModifyItems" );
// Test a bunch of acceptable and unacceptable items.
Item::List acc, unacc;
for ( int i = 0; i < 5; i++ ) {
acc.append( createItem( col, true ) );
unacc.append( createItem( col, false ) );
}
Item::List all = acc + unacc;
QCOMPARE( all.count(), 10 );
FilterActionJob *mjob = new FilterActionJob( all, new MyFunctor, this );
AKVERIFYEXEC( mjob );
ItemFetchJob *fjob = new ItemFetchJob( col, this );
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC( fjob );
QCOMPARE( fjob->items().count(), 10 );
foreach ( const Item &item, fjob->items() ) {
QVERIFY( item.hasAttribute<TestAttribute>() );
const QByteArray data = item.attribute<TestAttribute>()->data;
if ( data == unacceptable ) {
QVERIFY( unacc.contains( item ) );
unacc.removeAll( item );
} else if ( data == modified ) {
QVERIFY( acc.contains( item ) );
acc.removeAll( item );
} else {
QVERIFY2( false, QByteArray(QByteArray("Got bad data \"") + data + QByteArray("\"")) );
Collection col = createCollection("testMassModifyItems");
// Test a bunch of acceptable and unacceptable items.
Item::List acc, unacc;
for (int i = 0; i < 5; i++) {
acc.append(createItem(col, true));
unacc.append(createItem(col, false));
}
}
QCOMPARE( acc.count(), 0 );
QCOMPARE( unacc.count(), 0 );
Item::List all = acc + unacc;
QCOMPARE(all.count(), 10);
FilterActionJob *mjob = new FilterActionJob(all, new MyFunctor, this);
AKVERIFYEXEC(mjob);
ItemFetchJob *fjob = new ItemFetchJob(col, this);
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 10);
foreach (const Item &item, fjob->items()) {
QVERIFY(item.hasAttribute<TestAttribute>());
const QByteArray data = item.attribute<TestAttribute>()->data;
if (data == unacceptable) {
QVERIFY(unacc.contains(item));
unacc.removeAll(item);
} else if (data == modified) {
QVERIFY(acc.contains(item));
acc.removeAll(item);
} else {
QVERIFY2(false, QByteArray(QByteArray("Got bad data \"") + data + QByteArray("\"")));
}
}
QCOMPARE(acc.count(), 0);
QCOMPARE(unacc.count(), 0);
}
void FilterActionTest::testMassModifyCollection()
{
Collection col = createCollection( "testMassModifyCollection" );
// Test a bunch of acceptable and unacceptable items.
Item::List acc, unacc;
for ( int i = 0; i < 5; i++ ) {
acc.append( createItem( col, true ) );
unacc.append( createItem( col, false ) );
}
FilterActionJob *mjob = new FilterActionJob( col, new MyFunctor, this );
qDebug() << "Executing FilterActionJob.";
AKVERIFYEXEC( mjob );
ItemFetchJob *fjob = new ItemFetchJob( col, this );
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC( fjob );
QCOMPARE( fjob->items().count(), 10 );
foreach ( const Item &item, fjob->items() ) {
QVERIFY( item.hasAttribute<TestAttribute>() );
const QByteArray data = item.attribute<TestAttribute>()->data;
if ( data == unacceptable ) {
QVERIFY( unacc.contains( item ) );
unacc.removeAll( item );
} else if ( data == modified ) {
QVERIFY( acc.contains( item ) );
acc.removeAll( item );
} else {
QVERIFY2( false, QByteArray(QByteArray("Got bad data \"") + data + QByteArray("\"")) );
Collection col = createCollection("testMassModifyCollection");
// Test a bunch of acceptable and unacceptable items.
Item::List acc, unacc;
for (int i = 0; i < 5; i++) {
acc.append(createItem(col, true));
unacc.append(createItem(col, false));
}
FilterActionJob *mjob = new FilterActionJob(col, new MyFunctor, this);
qDebug() << "Executing FilterActionJob.";
AKVERIFYEXEC(mjob);
ItemFetchJob *fjob = new ItemFetchJob(col, this);
fjob->fetchScope().fetchAllAttributes();
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 10);
foreach (const Item &item, fjob->items()) {
QVERIFY(item.hasAttribute<TestAttribute>());
const QByteArray data = item.attribute<TestAttribute>()->data;
if (data == unacceptable) {
QVERIFY(unacc.contains(item));
unacc.removeAll(item);
} else if (data == modified) {
QVERIFY(acc.contains(item));
acc.removeAll(item);
} else {
QVERIFY2(false, QByteArray(QByteArray("Got bad data \"") + data + QByteArray("\"")));
}
}
}
QCOMPARE( acc.count(), 0 );
QCOMPARE( unacc.count(), 0 );
QCOMPARE(acc.count(), 0);
QCOMPARE(unacc.count(), 0);
}
Collection FilterActionTest::createCollection( const QString &name )
Collection FilterActionTest::createCollection(const QString &name)
{
Collection col;
col.setParentCollection( res1 );
col.setName( name );
CollectionCreateJob *ccjob = new CollectionCreateJob( col, this );
Q_ASSERT( ccjob->exec() );
return ccjob->collection();
Collection col;
col.setParentCollection(res1);
col.setName(name);
CollectionCreateJob *ccjob = new CollectionCreateJob(col, this);
Q_ASSERT(ccjob->exec());
return ccjob->collection();
}
Item FilterActionTest::createItem( const Collection &col, bool accept )
Item FilterActionTest::createItem(const Collection &col, bool accept)
{
Q_ASSERT( col.isValid() );
Item item;
item.setMimeType( "text/directory" );
TestAttribute *attr = new TestAttribute;
if ( accept ) {
attr->data = acceptable;
} else {
attr->data = unacceptable;
}
item.addAttribute( attr );