Commit 54c86695 authored by Laurent Montel's avatar Laurent Montel 😁

Astyle kdelibs

parent 24042caf
......@@ -23,7 +23,8 @@
#include <QtCore/QObject>
namespace Akonadi {
namespace Akonadi
{
class CollectionCreateJob;
class ItemCreateJob;
}
......
......@@ -65,8 +65,8 @@ private Q_SLOTS:
QTest::newRow("multipleItems") << (QStringList() << QStringLiteral("c1") << QStringLiteral("c2") << QStringLiteral("c3") << QStringLiteral("r1") << QStringLiteral("c4") << QStringLiteral("r2") << QStringLiteral("r3") << QStringLiteral("r4") << QStringLiteral("rn"));
QTest::newRow("reload") << (QStringList() << QStringLiteral("c1") << QStringLiteral("c1") << QStringLiteral("c3") << QStringLiteral("reload") << QStringLiteral("r1") << QStringLiteral("r1") << QStringLiteral("r3") << QStringLiteral("rn"));
QTest::newRow("more") << (QStringList() << QStringLiteral("c1") << QStringLiteral("c2") << QStringLiteral("c3") << QStringLiteral("reload") << QStringLiteral("r1") << QStringLiteral("reload") << QStringLiteral("c4") << QStringLiteral("reload") << QStringLiteral("r2") << QStringLiteral("reload") << QStringLiteral("r3") << QStringLiteral("r4") << QStringLiteral("rn"));
//FIXME: Due to the event compression in the server we simply expect a removal signal
// QTest::newRow("modifyThenDelete") << (QStringList() << "c1" << "d1" << "r1" << "rn");
//FIXME: Due to the event compression in the server we simply expect a removal signal
// QTest::newRow("modifyThenDelete") << (QStringList() << "c1" << "d1" << "r1" << "rn");
}
void testChangeRecorder()
......
......@@ -59,8 +59,7 @@ public:
{
return mData;
}
void deserialize(const QByteArray &data) Q_DECL_OVERRIDE
{
void deserialize(const QByteArray &data) Q_DECL_OVERRIDE {
mData = data;
}
private:
......
......@@ -26,7 +26,6 @@
#include "qtest_akonadi.h"
#include "test_utils.h"
using namespace Akonadi;
class CollectionCreator : public QObject
......@@ -64,18 +63,20 @@ private Q_SLOTS:
static int index = 0;
Job *lastJob = 0;
QBENCHMARK
{
if (useTransaction) {
QBENCHMARK {
if (useTransaction)
{
lastJob = new TransactionBeginJob(this);
}
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i)
{
Collection col;
col.setParentCollection(parent);
col.setName(QLatin1String("col") + QString::number(++index));
lastJob = new CollectionCreateJob(col, this);
}
if (useTransaction) {
if (useTransaction)
{
lastJob = new TransactionCommitJob(this);
}
AkonadiTest::akWaitForSignal(lastJob, SIGNAL(result(KJob*)), 15000);
......
This diff is collapsed.
......@@ -24,8 +24,8 @@
class CollectionJobTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testTopLevelList();
void testFolderList();
......
......@@ -8,15 +8,15 @@
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#include "test_utils.h"
......@@ -77,4 +77,5 @@ private Q_SLOTS:
QTEST_AKONADIMAIN(CollectionModifyTest)
#include "collectionmodifytest.moc"
\ No newline at end of file
#include "collectionmodifytest.moc"
......@@ -110,10 +110,10 @@ private:
collections << shared;
for (int i = 0; i < 10000; ++i) {
const Collection col = createCollection(QString::fromLatin1("Shared Col %1").arg(i), QString::fromLatin1("/shared%1").arg(i), shared);
collections << col;
for (int j = 0; j < 6; ++j) {
collections << createCollection(QString::fromLatin1("Shared Subcol %1-%2").arg(i).arg(j), QString::fromLatin1("/shared%1-%2").arg(i).arg(j), col);
}
collections << col;
for (int j = 0; j < 6; ++j) {
collections << createCollection(QString::fromLatin1("Shared Subcol %1-%2").arg(i).arg(j), QString::fromLatin1("/shared%1-%2").arg(i).arg(j), col);
}
}
return collections;
}
......@@ -130,7 +130,7 @@ private:
void cleanupBenchmark(const Collection::List &collections)
{
Collection::List baseCols;
Q_FOREACH(const Collection &col, collections) {
Q_FOREACH (const Collection &col, collections) {
if (col.remoteId().startsWith(QLatin1String("/baseCol")) || col.remoteId() == QLatin1String("/shared")) {
baseCols << col;
}
......@@ -141,15 +141,14 @@ private:
}
}
public Q_SLOTS:
public Q_SLOTS:
void syncBenchmarkProgress(KJob *job, ulong percent)
{
Q_UNUSED(job);
qDebug() << "CollectionSync progress:" << percent << "%";
}
private Q_SLOTS:
private Q_SLOTS:
void initTestCase()
{
AkonadiTest::checkTestIsIsolated();
......@@ -288,7 +287,6 @@ private:
syncer->setRemoteCollections(resultCols, delCols);
AKVERIFYEXEC(syncer);
Collection::List resultCols2 = fetchCollections(resource);
QCOMPARE(resultCols2.count(), resultCols.count());
}
......@@ -368,41 +366,41 @@ private:
void testAttributeChanges()
{
QFETCH(bool, keepLocalChanges);
const QString resource(QStringLiteral("akonadi_knut_resource_0"));
Collection col = fetchCollections( resource ).first();
col.attribute<EntityDisplayAttribute>(Akonadi::Entity::AddIfMissing)->setDisplayName(QStringLiteral("foo"));
col.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << QStringLiteral("foo"));
{
CollectionModifyJob *job = new CollectionModifyJob(col);
AKVERIFYEXEC(job);
}
col.attribute<EntityDisplayAttribute>()->setDisplayName(QStringLiteral("default"));
col.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << QStringLiteral("default"));
CollectionSync* syncer = new CollectionSync( resource, this );
if (keepLocalChanges) {
syncer->setKeepLocalChanges(QSet<QByteArray>() << "ENTITYDISPLAY" << "CONTENTMIMETYPES");
} else {
syncer->setKeepLocalChanges(QSet<QByteArray>());
}
syncer->setRemoteCollections( Collection::List() << col, Collection::List() );
AKVERIFYEXEC( syncer );
{
CollectionFetchJob *job = new CollectionFetchJob(col, Akonadi::CollectionFetchJob::Base);
AKVERIFYEXEC(job);
Collection resultCol = job->collections().first();
QFETCH(bool, keepLocalChanges);
const QString resource(QStringLiteral("akonadi_knut_resource_0"));
Collection col = fetchCollections(resource).first();
col.attribute<EntityDisplayAttribute>(Akonadi::Entity::AddIfMissing)->setDisplayName(QStringLiteral("foo"));
col.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << QStringLiteral("foo"));
{
CollectionModifyJob *job = new CollectionModifyJob(col);
AKVERIFYEXEC(job);
}
col.attribute<EntityDisplayAttribute>()->setDisplayName(QStringLiteral("default"));
col.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << QStringLiteral("default"));
CollectionSync *syncer = new CollectionSync(resource, this);
if (keepLocalChanges) {
QCOMPARE( resultCol.displayName(), QString::fromLatin1("foo") );
QVERIFY(resultCol.contentMimeTypes().contains(QStringLiteral("foo")));
syncer->setKeepLocalChanges(QSet<QByteArray>() << "ENTITYDISPLAY" << "CONTENTMIMETYPES");
} else {
QCOMPARE( resultCol.displayName(), QString::fromLatin1("default") );
QVERIFY(resultCol.contentMimeTypes().contains(QStringLiteral("default")));
syncer->setKeepLocalChanges(QSet<QByteArray>());
}
syncer->setRemoteCollections(Collection::List() << col, Collection::List());
AKVERIFYEXEC(syncer);
{
CollectionFetchJob *job = new CollectionFetchJob(col, Akonadi::CollectionFetchJob::Base);
AKVERIFYEXEC(job);
Collection resultCol = job->collections().first();
if (keepLocalChanges) {
QCOMPARE(resultCol.displayName(), QString::fromLatin1("foo"));
QVERIFY(resultCol.contentMimeTypes().contains(QStringLiteral("foo")));
} else {
QCOMPARE(resultCol.displayName(), QString::fromLatin1("default"));
QVERIFY(resultCol.contentMimeTypes().contains(QStringLiteral("default")));
}
}
}
}
// Disabled by default, because they take ~15 minutes to complete
......
......@@ -25,55 +25,55 @@ using namespace Akonadi;
class CollectionUtilsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
Q_OBJECT
private Q_SLOTS:
void testHasValidHierarchicalRID_data()
{
QTest::addColumn<Collection>( "collection" );
QTest::addColumn<bool>( "isHRID" );
QTest::addColumn<Collection>("collection");
QTest::addColumn<bool>("isHRID");
QTest::newRow( "empty" ) << Collection() << false;
QTest::newRow( "root" ) << Collection::root() << true;
Collection c;
c.setParentCollection( Collection::root() );
QTest::newRow( "one level not ok" ) << c << false;
c.setRemoteId( QLatin1String("r1") );
QTest::newRow( "one level ok" ) << c << true;
Collection c2;
c2.setParentCollection( c );
QTest::newRow( "two level not ok" ) << c2 << false;
c2.setRemoteId( QLatin1String("r2") );
QTest::newRow( "two level ok" ) << c2 << true;
c2.parentCollection().setRemoteId( QString() );
QTest::newRow( "mid RID missing" ) << c2 << false;
QTest::newRow("empty") << Collection() << false;
QTest::newRow("root") << Collection::root() << true;
Collection c;
c.setParentCollection(Collection::root());
QTest::newRow("one level not ok") << c << false;
c.setRemoteId(QLatin1String("r1"));
QTest::newRow("one level ok") << c << true;
Collection c2;
c2.setParentCollection(c);
QTest::newRow("two level not ok") << c2 << false;
c2.setRemoteId(QLatin1String("r2"));
QTest::newRow("two level ok") << c2 << true;
c2.parentCollection().setRemoteId(QString());
QTest::newRow("mid RID missing") << c2 << false;
}
void testHasValidHierarchicalRID()
{
QFETCH( Collection, collection );
QFETCH( bool, isHRID );
QCOMPARE( CollectionUtils::hasValidHierarchicalRID( collection ), isHRID );
QFETCH(Collection, collection);
QFETCH(bool, isHRID);
QCOMPARE(CollectionUtils::hasValidHierarchicalRID(collection), isHRID);
}
void testPersistentParentCollection()
{
Collection col1(1);
Collection col2(2);
Collection col3(3);
Collection col1(1);
Collection col2(2);
Collection col3(3);
col2.setParentCollection(col3);
col1.setParentCollection(col2);
col2.setParentCollection(col3);
col1.setParentCollection(col2);
Collection assigned = col1;
QCOMPARE(assigned.parentCollection(), col2);
QCOMPARE(assigned.parentCollection().parentCollection(), col3);
Collection assigned = col1;
QCOMPARE(assigned.parentCollection(), col2);
QCOMPARE(assigned.parentCollection().parentCollection(), col3);
Collection copied(col1);
QCOMPARE(copied.parentCollection(), col2);
QCOMPARE(copied.parentCollection().parentCollection(), col3);
Collection copied(col1);
QCOMPARE(copied.parentCollection(), col2);
QCOMPARE(copied.parentCollection().parentCollection(), col3);
}
};
QTEST_AKONADIMAIN( CollectionUtilsTest )
QTEST_AKONADIMAIN(CollectionUtilsTest)
#include "collectionutilstest.moc"
......@@ -22,150 +22,150 @@
#include <QSignalSpy>
#include <qtest_akonadi.h>
using namespace Akonadi;
class EntityCacheTest : public QObject
{
Q_OBJECT
private:
Q_OBJECT
private:
template <typename T, typename FetchJob, typename FetchScope>
void testCache()
{
EntityCache<T, FetchJob, FetchScope> cache( 2 );
QSignalSpy spy( &cache, SIGNAL(dataAvailable()) );
QVERIFY( spy.isValid() );
QVERIFY( !cache.isCached( 1 ) );
QVERIFY( !cache.isRequested( 1 ) );
QVERIFY( !cache.retrieve( 1 ).isValid() );
FetchScope scope;
scope.setAncestorRetrieval( FetchScope::All );
cache.request( 1, scope );
QVERIFY( !cache.isCached( 1 ) );
QVERIFY( cache.isRequested( 1 ) );
QVERIFY( !cache.retrieve( 1 ).isValid() );
QTRY_COMPARE( spy.count(), 1 );
QVERIFY( cache.isCached( 1 ) );
QVERIFY( cache.isRequested( 1 ) );
const T e1 = cache.retrieve( 1 );
QCOMPARE( e1.id(), 1ll );
QVERIFY( e1.parentCollection().isValid() );
QVERIFY( !e1.parentCollection().remoteId().isEmpty() || e1.parentCollection() == Collection::root() );
spy.clear();
cache.request( 2, FetchScope() );
cache.request( 3, FetchScope() );
QVERIFY( !cache.isCached( 1 ) );
QVERIFY( !cache.isRequested( 1 ) );
QVERIFY( cache.isRequested( 2 ) );
QVERIFY( cache.isRequested( 3 ) );
cache.invalidate( 2 );
QTRY_COMPARE( spy.count(), 2 );
QVERIFY( cache.isCached( 2 ) );
QVERIFY( cache.isCached( 3 ) );
const T e2 = cache.retrieve( 2 );
const T e3a = cache.retrieve( 3 );
QCOMPARE( e3a.id(), 3ll );
QVERIFY( !e2.isValid() );
cache.invalidate( 3 );
const T e3b = cache.retrieve( 3 );
QVERIFY( !e3b.isValid() );
spy.clear();
// updating a cached entry removes it
cache.update( 3, FetchScope() );
cache.update( 3, FetchScope() );
QVERIFY( !cache.isCached( 3 ) );
QVERIFY( !cache.isRequested( 3 ) );
QVERIFY( !cache.retrieve( 3 ).isValid() );
// updating a pending entry re-fetches
cache.request( 3, FetchScope() );
cache.update( 3, FetchScope() );
QVERIFY( !cache.isCached( 3 ) );
QVERIFY( cache.isRequested( 3 ) );
cache.update( 3, FetchScope() );
QVERIFY( !cache.isCached( 3 ) );
QVERIFY( cache.isRequested( 3 ) );
QTRY_COMPARE( spy.count(), 3 );
QVERIFY( cache.isCached( 3 ) );
QVERIFY( cache.retrieve( 3 ).isValid() );
EntityCache<T, FetchJob, FetchScope> cache(2);
QSignalSpy spy(&cache, SIGNAL(dataAvailable()));
QVERIFY(spy.isValid());
QVERIFY(!cache.isCached(1));
QVERIFY(!cache.isRequested(1));
QVERIFY(!cache.retrieve(1).isValid());
FetchScope scope;
scope.setAncestorRetrieval(FetchScope::All);
cache.request(1, scope);
QVERIFY(!cache.isCached(1));
QVERIFY(cache.isRequested(1));
QVERIFY(!cache.retrieve(1).isValid());
QTRY_COMPARE(spy.count(), 1);
QVERIFY(cache.isCached(1));
QVERIFY(cache.isRequested(1));
const T e1 = cache.retrieve(1);
QCOMPARE(e1.id(), 1ll);
QVERIFY(e1.parentCollection().isValid());
QVERIFY(!e1.parentCollection().remoteId().isEmpty() || e1.parentCollection() == Collection::root());