Commit 48718298 authored by Sandro Knauß's avatar Sandro Knauß

Make ImapAclAttribute the same in kdepim and kdepim-runtime

ImapAclAttribute main location is kdepim-runtime and every other
location should be a simple copy without any motification. So make sure
that all changes, that were done at kdepim are merged back.

REVIEW: 123661
parent c276bf4c
...@@ -33,6 +33,91 @@ class ImapAclAttributeTest : public QObject ...@@ -33,6 +33,91 @@ class ImapAclAttributeTest : public QObject
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void shouldHaveDefaultValue()
{
ImapAclAttribute attr;
QVERIFY(attr.oldRights().isEmpty());
QVERIFY(attr.rights().isEmpty());
QVERIFY(!attr.myRights());
}
void shouldBuildAttribute()
{
QMap<QByteArray, KIMAP::Acl::Rights> right;
right.insert("test", KIMAP::Acl::Admin);
right.insert("foo", KIMAP::Acl::Admin);
QMap<QByteArray, KIMAP::Acl::Rights> oldright;
right.insert("test", KIMAP::Acl::Delete);
right.insert("foo", KIMAP::Acl::Delete);
ImapAclAttribute attr(right, oldright);
QCOMPARE(attr.oldRights(), oldright);
QCOMPARE(attr.rights(), right);
}
void shouldAssignValue()
{
ImapAclAttribute attr;
QMap<QByteArray, KIMAP::Acl::Rights> right;
right.insert("test", KIMAP::Acl::Admin);
right.insert("foo", KIMAP::Acl::Admin);
attr.setRights(right);
QCOMPARE(attr.rights(), right);
}
void shouldCloneAttr()
{
ImapAclAttribute attr;
QMap<QByteArray, KIMAP::Acl::Rights> right;
right.insert("test", KIMAP::Acl::Admin);
right.insert("foo", KIMAP::Acl::Admin);
attr.setRights(right);
ImapAclAttribute *clone = attr.clone();
QVERIFY(attr == *clone);
delete clone;
}
void shouldSerializedAttribute()
{
QMap<QByteArray, KIMAP::Acl::Rights> right;
right.insert("test", KIMAP::Acl::Admin);
right.insert("foo", KIMAP::Acl::Admin);
QMap<QByteArray, KIMAP::Acl::Rights> oldright;
right.insert("test", KIMAP::Acl::Delete);
right.insert("foo", KIMAP::Acl::Delete);
ImapAclAttribute attr(right, oldright);
const QByteArray ba = attr.serialized();
ImapAclAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
}
void shouldHaveType()
{
ImapAclAttribute attr;
QCOMPARE(attr.type(), QByteArray("imapacl"));
}
void testMyRights()
{
ImapAclAttribute attr;
KIMAP::Acl::Rights myRight = KIMAP::Acl::Admin;
attr.setMyRights(myRight);
QCOMPARE(attr.myRights(), myRight);
ImapAclAttribute *clone = attr.clone();
QCOMPARE(clone->myRights(), myRight);
QVERIFY(*clone == attr);
clone->setMyRights(KIMAP::Acl::Custom0);
QVERIFY(!(*clone == attr));
delete clone;
}
void testDeserialize_data() void testDeserialize_data()
{ {
QTest::addColumn<ImapAcl>("rights"); QTest::addColumn<ImapAcl>("rights");
...@@ -91,34 +176,40 @@ private Q_SLOTS: ...@@ -91,34 +176,40 @@ private Q_SLOTS:
void testSerializeDeserialize_data() void testSerializeDeserialize_data()
{ {
QTest::addColumn<ImapAcl>("rights"); QTest::addColumn<ImapAcl>("rights");
QTest::addColumn<KIMAP::Acl::Rights>("myRights");
QTest::addColumn<QByteArray>("serialized"); QTest::addColumn<QByteArray>("serialized");
QTest::addColumn<QByteArray>("oldSerialized"); QTest::addColumn<QByteArray>("oldSerialized");
ImapAcl acl; ImapAcl acl;
QTest::newRow("empty") << acl << QByteArray(" %% ") << QByteArray("testme@host l %% "); QTest::newRow("empty") << acl << KIMAP::Acl::Rights(KIMAP::Acl::None) << QByteArray(" %% ") << QByteArray("testme@host l %% ");
acl.insert("user@host", KIMAP::Acl::None); acl.insert("user@host", KIMAP::Acl::None);
QTest::newRow("none") << acl << QByteArray("user@host %% ") << QByteArray("testme@host l %% user@host "); QTest::newRow("none") << acl << KIMAP::Acl::Rights(KIMAP::Acl::None) << QByteArray("user@host %% ") << QByteArray("testme@host l %% user@host ");
acl.insert("user@host", KIMAP::Acl::Lookup); acl.insert("user@host", KIMAP::Acl::Lookup);
QTest::newRow("lookup") << acl << QByteArray("user@host l %% ") << QByteArray("testme@host l %% user@host l"); QTest::newRow("lookup") << acl << KIMAP::Acl::Rights(KIMAP::Acl::None) << QByteArray("user@host l %% ") << QByteArray("testme@host l %% user@host l");
acl.insert("user@host", KIMAP::Acl::Lookup | KIMAP::Acl::Read); acl.insert("user@host", KIMAP::Acl::Lookup | KIMAP::Acl::Read);
QTest::newRow("lookup/read") << acl << QByteArray("user@host lr %% ") << QByteArray("testme@host l %% user@host lr"); QTest::newRow("lookup/read") << acl << KIMAP::Acl::Rights(KIMAP::Acl::None) << QByteArray("user@host lr %% ") << QByteArray("testme@host l %% user@host lr");
acl.insert("otheruser@host", KIMAP::Acl::Lookup | KIMAP::Acl::Read); acl.insert("otheruser@host", KIMAP::Acl::Lookup | KIMAP::Acl::Read);
QTest::newRow("lookup/read") << acl << QByteArray("otheruser@host lr % user@host lr %% ") QTest::newRow("lookup/read") << acl << KIMAP::Acl::Rights(KIMAP::Acl::None) << QByteArray("otheruser@host lr % user@host lr %% ")
<< QByteArray("testme@host l %% otheruser@host lr % user@host lr"); << QByteArray("testme@host l %% otheruser@host lr % user@host lr");
QTest::newRow("myrights") << acl << KIMAP::Acl::rightsFromString("lrswipckxtdaen") << QByteArray("otheruser@host lr % user@host lr %% %% lrswipckxtdaen")
<< QByteArray("testme@host l %% otheruser@host lr % user@host lr %% lrswipckxtdaen");
} }
void testSerializeDeserialize() void testSerializeDeserialize()
{ {
QFETCH(ImapAcl, rights); QFETCH(ImapAcl, rights);
QFETCH(KIMAP::Acl::Rights, myRights);
QFETCH(QByteArray, serialized); QFETCH(QByteArray, serialized);
QFETCH(QByteArray, oldSerialized); QFETCH(QByteArray, oldSerialized);
ImapAclAttribute *attr = new ImapAclAttribute(); ImapAclAttribute *attr = new ImapAclAttribute();
attr->setRights(rights); attr->setRights(rights);
attr->setMyRights(myRights);
QCOMPARE(attr->serialized(), serialized); QCOMPARE(attr->serialized(), serialized);
ImapAcl acl; ImapAcl acl;
...@@ -132,6 +223,7 @@ private Q_SLOTS: ...@@ -132,6 +223,7 @@ private Q_SLOTS:
ImapAclAttribute deserializeAttr; ImapAclAttribute deserializeAttr;
deserializeAttr.deserialize(serialized); deserializeAttr.deserialize(serialized);
QCOMPARE(deserializeAttr.rights(), rights); QCOMPARE(deserializeAttr.rights(), rights);
QCOMPARE(deserializeAttr.myRights(), myRights);
} }
void testOldRights() void testOldRights()
......
...@@ -65,7 +65,7 @@ QByteArray ImapAclAttribute::type() const ...@@ -65,7 +65,7 @@ QByteArray ImapAclAttribute::type() const
return sType; return sType;
} }
Akonadi::Attribute *ImapAclAttribute::clone() const ImapAclAttribute *ImapAclAttribute::clone() const
{ {
ImapAclAttribute *attr = new ImapAclAttribute(mRights, mOldRights); ImapAclAttribute *attr = new ImapAclAttribute(mRights, mOldRights);
attr->setMyRights(mMyRights); attr->setMyRights(mMyRights);
...@@ -104,8 +104,10 @@ QByteArray ImapAclAttribute::serialized() const ...@@ -104,8 +104,10 @@ QByteArray ImapAclAttribute::serialized() const
result.chop(3); result.chop(3);
} }
result += " %% "; if (mMyRights) {
result += KIMAP::Acl::rightsToString(mMyRights); result += " %% ";
result += KIMAP::Acl::rightsToString(mMyRights);
}
return result; return result;
} }
......
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
void setMyRights(KIMAP::Acl::Rights rights); void setMyRights(KIMAP::Acl::Rights rights);
KIMAP::Acl::Rights myRights() const; KIMAP::Acl::Rights myRights() const;
QByteArray type() const Q_DECL_OVERRIDE; QByteArray type() const Q_DECL_OVERRIDE;
Attribute *clone() const Q_DECL_OVERRIDE; ImapAclAttribute *clone() const Q_DECL_OVERRIDE;
QByteArray serialized() const Q_DECL_OVERRIDE; QByteArray serialized() const Q_DECL_OVERRIDE;
void deserialize(const QByteArray &data) Q_DECL_OVERRIDE; void deserialize(const QByteArray &data) Q_DECL_OVERRIDE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment