2 Gwenview: an image viewer
3 Copyright 2008 Aurélien Gâteau <aurelien.gateau@free.fr>
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 <lib/semanticinfo/nepomuksemanticinfobackend.h>
44 #error No metadata backend defined
48 QTEST_KDEMAIN( Gwenview::SemanticInfoBackEndTest
, GUI
)
53 SemanticInfoBackEndClient::SemanticInfoBackEndClient(AbstractSemanticInfoBackEnd
* backEnd
)
55 connect(backEnd
, SIGNAL(semanticInfoRetrieved(const KUrl
&, const SemanticInfo
&)),
56 SLOT(slotSemanticInfoRetrieved(const KUrl
&, const SemanticInfo
&)) );
60 void SemanticInfoBackEndClient::slotSemanticInfoRetrieved(const KUrl
& url
, const SemanticInfo
& semanticInfo
) {
61 mSemanticInfoForUrl
[url
] = semanticInfo
;
65 void SemanticInfoBackEndTest::initTestCase() {
66 qRegisterMetaType
<KUrl
>("KUrl");
67 qRegisterMetaType
<QString
>("SemanticInfoTag");
71 void SemanticInfoBackEndTest::init() {
72 #ifdef GWENVIEW_SEMANTICINFO_BACKEND_FAKE
73 mBackEnd
.reset(new FakeSemanticInfoBackEnd(0, FakeSemanticInfoBackEnd::InitializeEmpty
));
74 #elif defined(GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK)
75 mBackEnd
.reset(new NepomukSemanticInfoBackEnd(0));
81 * Get and set the rating of a temp file
83 void SemanticInfoBackEndTest::testRating() {
85 temp
.setSuffix(".metadatabackendtest");
89 url
.setPath(temp
.fileName());
91 SemanticInfoBackEndClient
client(mBackEnd
.get());
92 QSignalSpy
spy(mBackEnd
.get(), SIGNAL(semanticInfoRetrieved(const KUrl
&, const SemanticInfo
&)) );
93 mBackEnd
->retrieveSemanticInfo(url
);
94 QVERIFY(waitForSignal(spy
));
96 SemanticInfo semanticInfo
= client
.semanticInfoForUrl(url
);
97 QCOMPARE(semanticInfo
.mRating
, 0);
99 semanticInfo
.mRating
= 5;
100 mBackEnd
->storeSemanticInfo(url
, semanticInfo
);
104 void SemanticInfoBackEndTest::testTagForLabel() {
105 QSignalSpy
spy(mBackEnd
.get(), SIGNAL(tagAdded(const SemanticInfoTag
&, const QString
&)) );
107 TagSet oldAllTags
= mBackEnd
->allTags();
108 QString label
= "testTagForLabel-" + KRandom::randomString(5);
109 SemanticInfoTag tag1
= mBackEnd
->tagForLabel(label
);
110 QVERIFY(!tag1
.isEmpty());
111 QVERIFY(!oldAllTags
.contains(tag1
));
112 QVERIFY(mBackEnd
->allTags().contains(tag1
));
114 // This is a new tag, we should receive a signal
115 QCOMPARE(spy
.count(), 1);
117 SemanticInfoTag tag2
= mBackEnd
->tagForLabel(label
);
118 QCOMPARE(tag1
, tag2
);
119 // This is not a new tag, we should not receive a signal
120 QCOMPARE(spy
.count(), 1);
122 QString label2
= mBackEnd
->labelForTag(tag2
);
123 QCOMPARE(label
, label2
);