Changeset View
Changeset View
Standalone View
Standalone View
autotests/gravatarcachetest.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "gravatarcachetest.h" | 20 | #include "gravatarcachetest.h" | ||
21 | #include "../src/misc/gravatarcache.h" | 21 | #include "../src/misc/gravatarcache.h" | ||
22 | 22 | | |||
23 | #include <QPixmap> | ||||
24 | #include <QStandardPaths> | ||||
23 | #include <qtest.h> | 25 | #include <qtest.h> | ||
24 | 26 | | |||
27 | using namespace Gravatar; | ||||
28 | | ||||
25 | GravatarCacheTest::GravatarCacheTest(QObject *parent) | 29 | GravatarCacheTest::GravatarCacheTest(QObject *parent) | ||
26 | : QObject(parent) | 30 | : QObject(parent) | ||
27 | { | 31 | { | ||
28 | } | 32 | } | ||
29 | 33 | | |||
30 | GravatarCacheTest::~GravatarCacheTest() | 34 | GravatarCacheTest::~GravatarCacheTest() | ||
31 | { | 35 | { | ||
32 | } | 36 | } | ||
33 | 37 | | |||
38 | void GravatarCacheTest::initTestCase() | ||||
39 | { | ||||
40 | QStandardPaths::setTestModeEnabled(true); | ||||
41 | } | ||||
42 | | ||||
34 | void GravatarCacheTest::shouldHaveDefaultValue() | 43 | void GravatarCacheTest::shouldHaveDefaultValue() | ||
35 | { | 44 | { | ||
36 | Gravatar::GravatarCache gravatarCache; | 45 | Gravatar::GravatarCache gravatarCache; | ||
37 | QCOMPARE(gravatarCache.maximumSize(), 20); | 46 | QCOMPARE(gravatarCache.maximumSize(), 20); | ||
38 | } | 47 | } | ||
39 | 48 | | |||
40 | void GravatarCacheTest::shouldChangeCacheValue() | 49 | void GravatarCacheTest::shouldChangeCacheValue() | ||
41 | { | 50 | { | ||
42 | Gravatar::GravatarCache gravatarCache; | 51 | Gravatar::GravatarCache gravatarCache; | ||
43 | int val = 30; | 52 | int val = 30; | ||
44 | gravatarCache.setMaximumSize(val); | 53 | gravatarCache.setMaximumSize(val); | ||
45 | 54 | | |||
46 | QCOMPARE(gravatarCache.maximumSize(), val); | 55 | QCOMPARE(gravatarCache.maximumSize(), val); | ||
47 | val = 50; | 56 | val = 50; | ||
48 | gravatarCache.setMaximumSize(val); | 57 | gravatarCache.setMaximumSize(val); | ||
49 | 58 | | |||
50 | QCOMPARE(gravatarCache.maximumSize(), val); | 59 | QCOMPARE(gravatarCache.maximumSize(), val); | ||
51 | } | 60 | } | ||
52 | 61 | | |||
62 | void GravatarCacheTest::testLookup() | ||||
63 | { | ||||
64 | { | ||||
65 | GravatarCache cache; | ||||
66 | cache.clearAllCache(); | ||||
67 | bool found = false; | ||||
68 | const auto result = cache.loadGravatarPixmap(QStringLiteral("fa1afe1"), found); | ||||
69 | QVERIFY(!found); | ||||
70 | QVERIFY(result.isNull()); | ||||
71 | } | ||||
72 | | ||||
73 | QPixmap px(42, 42); | ||||
74 | px.fill(Qt::blue); | ||||
75 | | ||||
76 | { | ||||
77 | GravatarCache cache; | ||||
78 | cache.saveGravatarPixmap(QStringLiteral("fa1afe1"), px); | ||||
79 | | ||||
80 | // in-memory cache lookup | ||||
81 | bool found = false; | ||||
82 | const auto result = cache.loadGravatarPixmap(QStringLiteral("fa1afe1"), found); | ||||
83 | QVERIFY(found); | ||||
84 | QVERIFY(!result.isNull()); | ||||
85 | QCOMPARE(result.size(), QSize(42, 42)); | ||||
86 | } | ||||
87 | | ||||
88 | { | ||||
89 | // disk lookup | ||||
90 | GravatarCache cache; | ||||
91 | bool found = false; | ||||
92 | const auto result = cache.loadGravatarPixmap(QStringLiteral("fa1afe1"), found); | ||||
93 | QVERIFY(found); | ||||
94 | QVERIFY(!result.isNull()); | ||||
95 | QCOMPARE(result.size(), QSize(42, 42)); | ||||
96 | } | ||||
97 | } | ||||
98 | | ||||
53 | QTEST_MAIN(GravatarCacheTest) | 99 | QTEST_MAIN(GravatarCacheTest) |