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 "itemtest.h"
21
22#include "global.h"
23#include "test.h"
24
25#include <akonadi/private/collectionpathresolver_p.h>
26#include <akonadi/itemcreatejob.h>
27
28#include <KDebug>
29#include <QFile>
30
31using namespace Akonadi;
32
33ItemTest::ItemTest( QObject *parent ) :
34 QObject( parent )
35{
36 setObjectName( "global" );
37}
38
39void ItemTest::setParentCollection(const Akonadi::Collection& parent)
40{
41 mParent = parent;
42}
43
44void ItemTest::setParentCollection(const QString& path)
45{
46 CollectionPathResolver* resolver = new CollectionPathResolver( path, this );
47 if ( !resolver->exec() )
48 Test::instance()->fail( resolver->errorString() );
49 setParentCollection( Collection( resolver->collection() ) );
50}
51
52QString ItemTest::mimeType() const
53{
54 return mItem.mimeType();
55}
56
57void ItemTest::setMimeType(const QString& mimeType)
58{
59 mItem.setMimeType( mimeType );
60}
61
62void ItemTest::setPayloadFromFile(const QString& fileName)
63{
64 QFile file( Global::basePath() + fileName );
65 if ( !file.open( QFile::ReadOnly ) )
66 Test::instance()->fail( file.errorString() );
67 mItem.setPayloadFromData( file.readAll() );
68}
69
70void ItemTest::create()
71{
72 ItemCreateJob* job = new ItemCreateJob( mItem, mParent, this );
73 if ( !job->exec() )
74 Test::instance()->fail( job->errorString() );
75 mItem = job->item();
76}
77
78QObject* ItemTest::newInstance()
79{
80 return createNewInstance<ItemTest>( this );
81}
82
83