~ubuntu-branches/ubuntu/utopic/kde4libs/utopic

« back to all changes in this revision

Viewing changes to kdecore/tests/kshareddatacachetest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Kolberg
  • Date: 2012-03-03 00:25:28 UTC
  • mfrom: (1.14.15)
  • Revision ID: package-import@ubuntu.com-20120303002528-chhwyfluldkicy5k
Tags: 4:4.8.1-0ubuntu1
* New upstream release
  - Update symbol files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE libraries
 
2
 *  Copyright (c) 2012 David Faure <faure@kde.org>
 
3
 *
 
4
 *  This library is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU Lesser General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License or ( at
 
7
 *  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
 
8
 *  act as a proxy as in section 14 of the GPLv3 ), any later version.
 
9
 *
 
10
 *  This library 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 GNU
 
13
 *  Library General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU Lesser General Public License
 
16
 *  along with this library; see the file COPYING.LIB.  If not, write to
 
17
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 *  Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include <kshareddatacache.h>
 
22
 
 
23
#include <qtest_kde.h>
 
24
 
 
25
#include <QtCore/QObject>
 
26
#include <QtCore/QString>
 
27
#include <QtCore/QStringList>
 
28
#include <QtCore/QDir>
 
29
#include <kstandarddirs.h>
 
30
#include <string.h> // strcpy
 
31
 
 
32
class KSharedDataCacheTest : public QObject
 
33
{
 
34
    Q_OBJECT
 
35
 
 
36
private Q_SLOTS:
 
37
    void initTestCase();
 
38
    void simpleInsert();
 
39
};
 
40
 
 
41
void KSharedDataCacheTest::initTestCase()
 
42
{
 
43
}
 
44
 
 
45
void KSharedDataCacheTest::simpleInsert()
 
46
{
 
47
    const QLatin1String cacheName("myTestCache");
 
48
    const QLatin1String key("mypic");
 
49
    // clear the cache
 
50
    QString cacheFile = KGlobal::dirs()->locateLocal("cache", cacheName + QLatin1String(".kcache"));
 
51
    QFile file(cacheFile);
 
52
    if (file.exists())
 
53
        QVERIFY(file.remove());
 
54
    // insert something into it
 
55
    KSharedDataCache cache(cacheName, 5*1024*1024);
 
56
    QVERIFY(file.exists()); // make sure we got the cache filename right
 
57
    QByteArray data;
 
58
    data.resize(9228);
 
59
    strcpy(data.data(), "Hello world");
 
60
    QVERIFY(cache.insert(key, data));
 
61
    // read it out again
 
62
    QByteArray result;
 
63
    QVERIFY(cache.find(key, &result));
 
64
    QCOMPARE(result, data);
 
65
    // another insert
 
66
    strcpy(data.data(), "Hello KDE");
 
67
    QVERIFY(cache.insert(key, data));
 
68
    // and another read
 
69
    QVERIFY(cache.find(key, &result));
 
70
    QEXPECT_FAIL("", "Bug in findNamedEntry!", Continue);
 
71
    QCOMPARE(result, data);
 
72
}
 
73
 
 
74
QTEST_KDEMAIN_CORE(KSharedDataCacheTest)
 
75
 
 
76
#include "kshareddatacachetest.moc"