1/*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "collectiontest.h"
21#include "test.h"
22
23#include <akonadi/collectioncreatejob.h>
24#include <akonadi/collectionmodifyjob.h>
25#include <akonadi/collectiondeletejob.h>
26#include <akonadi/private/collectionpathresolver_p.h>
27
28#include <QStringList>
29
30using namespace Akonadi;
31
32CollectionTest::CollectionTest(QObject* parent) :
33 QObject( parent )
34{
35}
36
37void CollectionTest::setParent(const Akonadi::Collection& parent)
38{
39 mParent = parent;
40}
41
42void CollectionTest::setCollection(const Akonadi::Collection& collection)
43{
44 mCollection = collection;
45}
46
47void CollectionTest::setParent(const QString& parentPath)
48{
49 CollectionPathResolver* resolver = new CollectionPathResolver( parentPath, this );
50 if ( !resolver->exec() )
51 Test::instance()->fail( resolver->errorString() );
52 setParent( Collection( resolver->collection() ) );
53}
54
55void CollectionTest::setCollection(const QString& path)
56{
57 CollectionPathResolver* resolver = new CollectionPathResolver( path, this );
58 if ( !resolver->exec() )
59 Test::instance()->fail( resolver->errorString() );
60 setCollection( Collection( resolver->collection() ) );
61}
62
63void CollectionTest::setName(const QString& name)
64{
65 mCollection.setName( name );
66}
67
68void CollectionTest::addContentType(const QString& type)
69{
70 mCollection.setContentMimeTypes( mCollection.contentMimeTypes() << type );
71}
72
73void CollectionTest::create()
74{
75 mCollection.setParentCollection( mParent );
76 CollectionCreateJob* job = new CollectionCreateJob( mCollection, this );
77 if ( !job->exec() )
78 Test::instance()->fail( job->errorString() );
79}
80
81void CollectionTest::update()
82{
83 CollectionModifyJob* job = new CollectionModifyJob( mCollection, this );
84 if ( !job->exec() )
85 Test::instance()->fail( job->errorString() );
86}
87
88void CollectionTest::remove()
89{
90 CollectionDeleteJob* job = new CollectionDeleteJob( mCollection, this );
91 if ( !job->exec() )
92 Test::instance()->fail( job->errorString() );
93}
94
95QObject* CollectionTest::newInstance()
96{
97 return createNewInstance<CollectionTest>( this );
98}
99
100