summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-05-12 06:52:13 +0200
committerMontel Laurent <[email protected]>2015-05-12 06:55:13 +0200
commitab8ab2e7a78227d68dc43472bf0af40d904a3360 (patch)
tree58f2d09a9dda0a4d5064e3b9cac2460ff1c6aa31
parent538fc83be87d42ea88757276e6cb95d1ddbf20b4 (diff)
Return hash value
-rw-r--r--pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp9
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.cpp11
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.h3
3 files changed, 19 insertions, 4 deletions
diff --git a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
index 317e4d9..b4e4bbf 100644
--- a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
+++ b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
@@ -55,19 +55,22 @@ void GravatarResolvUrlJobTest::shouldNotStart()
void GravatarResolvUrlJobTest::shouldGenerateGravatarUrl_data()
{
QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("calculedhash");
QTest::addColumn<KUrl>("output");
- QTest::newRow("empty") << QString() << KUrl();
- QTest::newRow("no domain") << QString(QLatin1String("foo")) << KUrl();
- QTest::newRow("validemail") << QString(QLatin1String("[email protected]")) << KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404");
+ QTest::newRow("empty") << QString() << QString() << KUrl();
+ QTest::newRow("no domain") << QString(QLatin1String("foo")) << QString() << KUrl();
+ QTest::newRow("validemail") << QString(QLatin1String("[email protected]")) << QString(QLatin1String("89b4e14cf2fc6d426275c019c6dc9de6")) << KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404");
}
void GravatarResolvUrlJobTest::shouldGenerateGravatarUrl()
{
QFETCH( QString, input );
+ QFETCH( QString, calculedhash);
QFETCH( KUrl, output );
PimCommon::GravatarResolvUrlJob job;
job.setEmail(input);
KUrl url = job.generateGravatarUrl();
+ QCOMPARE(calculedhash, job.calculatedHash());
QCOMPARE(url, output);
}
diff --git a/pimcommon/gravatar/gravatarresolvurljob.cpp b/pimcommon/gravatar/gravatarresolvurljob.cpp
index a74959d..7e3b169 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.cpp
+++ b/pimcommon/gravatar/gravatarresolvurljob.cpp
@@ -55,6 +55,7 @@ bool GravatarResolvUrlJob::hasGravatar() const
void GravatarResolvUrlJob::start()
{
if (canStart()) {
+ mCalculatedHash.clear();
const KUrl url = createUrl();
} else {
//TODO return message Error.
@@ -80,8 +81,15 @@ QString GravatarResolvUrlJob::calculateHash()
return QString::fromUtf8(hash.result().toHex());
}
+QString GravatarResolvUrlJob::calculatedHash() const
+{
+ return mCalculatedHash;
+}
+
+
KUrl GravatarResolvUrlJob::createUrl()
{
+ mCalculatedHash.clear();
if (!canStart()) {
return KUrl();
}
@@ -89,7 +97,8 @@ KUrl GravatarResolvUrlJob::createUrl()
url.setScheme(QLatin1String("http"));
url.setHost(QLatin1String("www.gravatar.com"));
url.setPort(80);
- url.setPath(QLatin1String("/avatar/") + calculateHash());
+ mCalculatedHash = calculateHash();
+ url.setPath(QLatin1String("/avatar/") + mCalculatedHash);
//Add ?d=404
url.addQueryItem(QLatin1String("d"), QLatin1String("404"));
return url;
diff --git a/pimcommon/gravatar/gravatarresolvurljob.h b/pimcommon/gravatar/gravatarresolvurljob.h
index f87c8b0..d0be12d 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.h
+++ b/pimcommon/gravatar/gravatarresolvurljob.h
@@ -41,6 +41,8 @@ public:
bool hasGravatar() const;
+ QString calculatedHash() const;
+
Q_SIGNALS:
void urlResolved(const KUrl &url);
@@ -48,6 +50,7 @@ private:
KUrl createUrl();
QString calculateHash();
QString mEmail;
+ QString mCalculatedHash;
};
}