Skip to content

Commit

Permalink
Merge branch 'cleanups' into 'master'
Browse files Browse the repository at this point in the history
[qtcontacts-sqlite] Cleanups. Contributes to JB#38781

See merge request mer-core/qtcontacts-sqlite!16
  • Loading branch information
pvuorela committed Apr 16, 2019
2 parents 80fa782 + 94f925e commit 7b785aa
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 166 deletions.
6 changes: 3 additions & 3 deletions src/engine/contactsdatabase.cpp
Expand Up @@ -2882,9 +2882,9 @@ ContactsDatabase::ProcessMutex *ContactsDatabase::processMutex() const
// QDir::isReadable() doesn't support group permissions, only user permissions.
bool directoryIsRW(const QString &dirPath)
{
QFileInfo databaseDirInfo(dirPath);
return (databaseDirInfo.permission(QFile::ReadGroup | QFile::WriteGroup)
|| databaseDirInfo.permission(QFile::ReadUser | QFile::WriteUser));
QFileInfo databaseDirInfo(dirPath);
return (databaseDirInfo.permission(QFile::ReadGroup | QFile::WriteGroup)
|| databaseDirInfo.permission(QFile::ReadUser | QFile::WriteUser));
}

bool ContactsDatabase::open(const QString &connectionName, bool nonprivileged, bool autoTest, bool secondaryConnection)
Expand Down
4 changes: 4 additions & 0 deletions src/engine/contactsengine.h
Expand Up @@ -36,6 +36,10 @@

#include <QScopedPointer>
#include <QSqlDatabase>
#include <QObject>
#include <QList>
#include <QMap>
#include <QString>

#include "contactsdatabase.h"
#include "contactnotifier.h"
Expand Down
32 changes: 0 additions & 32 deletions src/engine/contactwriter.cpp
Expand Up @@ -117,11 +117,6 @@ namespace {

return entropy / 8;
}

double entropy(const QByteArray &data)
{
return entropy(data.constBegin(), data.constEnd(), data.size());
}
}

static const QString aggregateSyncTarget(QString::fromLatin1("aggregate"));
Expand Down Expand Up @@ -1148,25 +1143,6 @@ static bool detailValuesEqual(const QContactDetail &lhs, const QContactDetail &r
return true;
}

static bool detailValuesSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True if all values in rhs are present in lhs
const DetailMap lhsValues(detailValues(lhs, false));
const DetailMap rhsValues(detailValues(rhs, false));

if (lhsValues.count() < rhsValues.count()) {
return false;
}

foreach (const DetailMap::key_type &key, rhsValues.keys()) {
if (!variantEqual(lhsValues[key], rhsValues[key])) {
return false;
}
}

return true;
}

static bool detailsEquivalent(const QContactDetail &lhs, const QContactDetail &rhs)
{
// Same as operator== except ignores differences in accessConstraints values
Expand All @@ -1175,14 +1151,6 @@ static bool detailsEquivalent(const QContactDetail &lhs, const QContactDetail &r
return detailValuesEqual(lhs, rhs);
}

static bool detailsSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True is lhs is a superset of rhs
if (detailType(lhs) != detailType(rhs))
return false;
return detailValuesSuperset(lhs, rhs);
}

QContactManager::Error ContactWriter::fetchSyncContacts(const QString &syncTarget, const QDateTime &lastSync, const QList<QContactId> &exportedIds,
QList<QContact> *syncContacts, QList<QContact> *addedContacts, QList<QContactId> *deletedContactIds,
QDateTime *maxTimestamp)
Expand Down
4 changes: 2 additions & 2 deletions src/engine/memorytable_p.h
Expand Up @@ -30,8 +30,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef __MEMORYTABLE_H__
#define __MEMORYTABLE_H__
#ifndef MEMORYTABLE_H
#define MEMORYTABLE_H

#include <QByteArray>

Expand Down
1 change: 0 additions & 1 deletion tests/auto/aggregation/tst_aggregation.cpp
Expand Up @@ -2652,7 +2652,6 @@ void tst_Aggregation::wasLocalCreation()
QSignalSpy addSpy(m_cm, contactsAddedSignal);
QSignalSpy remSpy(m_cm, contactsRemovedSignal);
int addSpyCount = 0;
int remSpyCount = 0;

QContactName an;
an.setFirstName("Alice");
Expand Down
Expand Up @@ -65,6 +65,7 @@ int TestDlgg::priority() const

bool TestDlgg::validForLocale(const QLocale &locale) const
{
Q_UNUSED(locale)
return true; // this test plugin is always "valid".
}

Expand Down
74 changes: 73 additions & 1 deletion tests/auto/qcontactmanager/tst_qcontactmanager.cpp
Expand Up @@ -70,6 +70,77 @@ Q_DECLARE_METATYPE(QContact)
Q_DECLARE_METATYPE(QContactManager::Error)
Q_DECLARE_METATYPE(Qt::CaseSensitivity)

static bool variantEqual(const QVariant &lhs, const QVariant &rhs)
{
// Work around incorrect result from QVariant::operator== when variants contain QList<int>
static const int QListIntType = QMetaType::type("QList<int>");

const int lhsType = lhs.userType();
if (lhsType != rhs.userType()) {
return false;
}

if (lhsType == QListIntType) {
return (lhs.value<QList<int> >() == rhs.value<QList<int> >());
}
return (lhs == rhs);
}

static bool detailValuesEqual(const QContactDetail &lhs, const QContactDetail &rhs)
{
const DetailMap lhsValues(detailValues(lhs, false));
const DetailMap rhsValues(detailValues(rhs, false));

if (lhsValues.count() != rhsValues.count()) {
return false;
}

DetailMap::const_iterator lit = lhsValues.constBegin(), lend = lhsValues.constEnd();
DetailMap::const_iterator rit = rhsValues.constBegin();
for ( ; lit != lend; ++lit, ++rit) {
if (!variantEqual(*lit, *rit)) {
return false;
}
}

return true;
}

static bool detailsEquivalent(const QContactDetail &lhs, const QContactDetail &rhs)
{
// Same as operator== except ignores differences in accessConstraints values
if (detailType(lhs) != detailType(rhs))
return false;
return detailValuesEqual(lhs, rhs);
}

static bool detailValuesSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True if all values in rhs are present in lhs
const DetailMap lhsValues(detailValues(lhs, false));
const DetailMap rhsValues(detailValues(rhs, false));

if (lhsValues.count() < rhsValues.count()) {
return false;
}

foreach (const DetailMap::key_type &key, rhsValues.keys()) {
if (!variantEqual(lhsValues[key], rhsValues[key])) {
return false;
}
}

return true;
}

static bool detailsSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True is lhs is a superset of rhs
if (detailType(lhs) != detailType(rhs))
return false;
return detailValuesSuperset(lhs, rhs);
}

class tst_QContactManager : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -2515,7 +2586,8 @@ void tst_QContactManager::signalEmission()
/* We basically loop, processing events, until we've seen an Add signal for each contact */
sigids.clear();

QTRY_WAIT( while(spyCA.size() > 0) {sigids += spyCA.takeFirst().at(0).value<QList<QContactId> >(); }, sigids.contains(ContactId::apiId(c)) && sigids.contains(ContactId::apiId(c2)) && sigids.contains(ContactId::apiId(c3)));
QTRY_WAIT( while(spyCA.size() > 0) {sigids += spyCA.takeFirst().at(0).value<QList<QContactId> >(); },
sigids.contains(ContactId::apiId(c)) && sigids.contains(ContactId::apiId(c2)) && sigids.contains(ContactId::apiId(c3)));
// if we perform aggregation, aggregates might get updated; this cannot be verified:
//QTRY_COMPARE(spyCM.count(), 0);

Expand Down
127 changes: 0 additions & 127 deletions tests/util.h
Expand Up @@ -74,39 +74,6 @@
// qtpim doesn't support the displayLabelGroup field natively, but qtcontacts-sqlite provides it
#define DISPLAY_LABEL_GROUP_STORAGE_SUPPORTED

// Eventually these will make it into qtestcase.h
// but we might need to tweak the timeout values here.
#ifndef QTRY_COMPARE
#define QTRY_COMPARE(__expr, __expected) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if ((__expr) != (__expected)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
QTest::qWait(__step); \
} \
QCOMPARE(__expr, __expected); \
} while(0)
#endif

#ifndef QTRY_VERIFY
#define QTRY_VERIFY(__expr) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if (!(__expr)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
QTest::qWait(__step); \
} \
QVERIFY(__expr); \
} while(0)
#endif


#define QTRY_WAIT(code, __expr) \
do { \
const int __step = 50; \
Expand All @@ -123,29 +90,6 @@
#define QCONTACTMANAGER_REMOVE_VERSIONS_FROM_URI(params) params.remove(QString::fromLatin1(QTCONTACTS_VERSION_NAME)); \
params.remove(QString::fromLatin1(QTCONTACTS_IMPLEMENTATION_VERSION_NAME))

#define QTRY_COMPARE_SIGNALS_LOCALID_COUNT(__signalSpy, __expectedCount) \
do { \
int __spiedSigCount = 0; \
const int __step = 50; \
const int __timeout = 5000; \
for (int __i = 0; __i < __timeout; __i+=__step) { \
/* accumulate added from signals */ \
__spiedSigCount = 0; \
const QList<QList<QVariant> > __spiedSignals = __signalSpy; \
foreach (const QList<QVariant> &__arguments, __spiedSignals) { \
foreach (QContactId __apiId, __arguments.first().value<QList<QContactId> >()) { \
QVERIFY(ContactId::isValid(__apiId)); \
__spiedSigCount++; \
} \
} \
if(__spiedSigCount == __expectedCount) { \
break; \
} \
QTest::qWait(__step); \
} \
QCOMPARE(__spiedSigCount, __expectedCount); \
} while(0)

QTCONTACTS_USE_NAMESPACE

Q_DECLARE_METATYPE(QList<QContactId>)
Expand Down Expand Up @@ -219,77 +163,6 @@ DetailMap detailValues(const QContactDetail &detail, bool includeProvenance = tr
return rv;
}

static bool variantEqual(const QVariant &lhs, const QVariant &rhs)
{
// Work around incorrect result from QVariant::operator== when variants contain QList<int>
static const int QListIntType = QMetaType::type("QList<int>");

const int lhsType = lhs.userType();
if (lhsType != rhs.userType()) {
return false;
}

if (lhsType == QListIntType) {
return (lhs.value<QList<int> >() == rhs.value<QList<int> >());
}
return (lhs == rhs);
}

static bool detailValuesEqual(const QContactDetail &lhs, const QContactDetail &rhs)
{
const DetailMap lhsValues(detailValues(lhs, false));
const DetailMap rhsValues(detailValues(rhs, false));

if (lhsValues.count() != rhsValues.count()) {
return false;
}

DetailMap::const_iterator lit = lhsValues.constBegin(), lend = lhsValues.constEnd();
DetailMap::const_iterator rit = rhsValues.constBegin();
for ( ; lit != lend; ++lit, ++rit) {
if (!variantEqual(*lit, *rit)) {
return false;
}
}

return true;
}

static bool detailValuesSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True if all values in rhs are present in lhs
const DetailMap lhsValues(detailValues(lhs, false));
const DetailMap rhsValues(detailValues(rhs, false));

if (lhsValues.count() < rhsValues.count()) {
return false;
}

foreach (const DetailMap::key_type &key, rhsValues.keys()) {
if (!variantEqual(lhsValues[key], rhsValues[key])) {
return false;
}
}

return true;
}

static bool detailsEquivalent(const QContactDetail &lhs, const QContactDetail &rhs)
{
// Same as operator== except ignores differences in accessConstraints values
if (detailType(lhs) != detailType(rhs))
return false;
return detailValuesEqual(lhs, rhs);
}

static bool detailsSuperset(const QContactDetail &lhs, const QContactDetail &rhs)
{
// True is lhs is a superset of rhs
if (detailType(lhs) != detailType(rhs))
return false;
return detailValuesSuperset(lhs, rhs);
}

bool validContactType(const QContact &contact)
{
return (contact.type() == QContactType::TypeContact);
Expand Down

0 comments on commit 7b785aa

Please sign in to comment.