2
Gwenview: an image viewer
3
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "semanticinfobackendtest.moc"
29
#include <ktemporaryfile.h>
30
#include <qtest_kde.h>
33
#include "testutils.h"
34
#include <config-gwenview.h>
36
#ifdef GWENVIEW_SEMANTICINFO_BACKEND_FAKE
37
#include <lib/semanticinfo/fakesemanticinfobackend.h>
39
#elif defined(GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK)
40
#include <nepomuk/resourcemanager.h>
41
#include <lib/semanticinfo/nepomuksemanticinfobackend.h>
45
#error No metadata backend defined
49
QTEST_KDEMAIN( Gwenview::SemanticInfoBackEndTest, GUI )
54
SemanticInfoBackEndClient::SemanticInfoBackEndClient(AbstractSemanticInfoBackEnd* backEnd)
56
connect(backEnd, SIGNAL(semanticInfoRetrieved(const KUrl&, const SemanticInfo&)),
57
SLOT(slotSemanticInfoRetrieved(const KUrl&, const SemanticInfo&)) );
61
void SemanticInfoBackEndClient::slotSemanticInfoRetrieved(const KUrl& url, const SemanticInfo& semanticInfo) {
62
mSemanticInfoForUrl[url] = semanticInfo;
66
void SemanticInfoBackEndTest::initTestCase() {
67
#ifdef GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK
68
if (Nepomuk::ResourceManager::instance()->init() != 0) {
69
QSKIP("This test needs Nepomuk", SkipAll);
72
qRegisterMetaType<KUrl>("KUrl");
73
qRegisterMetaType<QString>("SemanticInfoTag");
77
void SemanticInfoBackEndTest::init() {
78
#ifdef GWENVIEW_SEMANTICINFO_BACKEND_FAKE
79
mBackEnd = new FakeSemanticInfoBackEnd(0, FakeSemanticInfoBackEnd::InitializeEmpty);
80
#elif defined(GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK)
81
mBackEnd = new NepomukSemanticInfoBackEnd(0);
85
void SemanticInfoBackEndTest::cleanup() {
92
* Get and set the rating of a temp file
94
void SemanticInfoBackEndTest::testRating() {
96
temp.setSuffix(".metadatabackendtest");
100
url.setPath(temp.fileName());
102
SemanticInfoBackEndClient client(mBackEnd);
103
QSignalSpy spy(mBackEnd, SIGNAL(semanticInfoRetrieved(const KUrl&, const SemanticInfo&)) );
104
mBackEnd->retrieveSemanticInfo(url);
105
QVERIFY(waitForSignal(spy));
107
SemanticInfo semanticInfo = client.semanticInfoForUrl(url);
108
QCOMPARE(semanticInfo.mRating, 0);
110
semanticInfo.mRating = 5;
111
mBackEnd->storeSemanticInfo(url, semanticInfo);
115
void SemanticInfoBackEndTest::testTagForLabel() {
116
QSignalSpy spy(mBackEnd, SIGNAL(tagAdded(const SemanticInfoTag&, const QString&)) );
118
TagSet oldAllTags = mBackEnd->allTags();
119
QString label = "testTagForLabel-" + KRandom::randomString(5);
120
SemanticInfoTag tag1 = mBackEnd->tagForLabel(label);
121
QVERIFY(!tag1.isEmpty());
122
QVERIFY(!oldAllTags.contains(tag1));
123
QVERIFY(mBackEnd->allTags().contains(tag1));
125
// This is a new tag, we should receive a signal
126
QCOMPARE(spy.count(), 1);
128
SemanticInfoTag tag2 = mBackEnd->tagForLabel(label);
129
QCOMPARE(tag1, tag2);
130
// This is not a new tag, we should not receive a signal
131
QCOMPARE(spy.count(), 1);
133
QString label2 = mBackEnd->labelForTag(tag2);
134
QCOMPARE(label, label2);