Commit 94f925e5 authored by pvuorela's avatar pvuorela

[qtcontacts-sqlite] Cleanups. Contributes to JB#38781

Fix style, remove dead code etc.
parent 80fa7829
......@@ -36,6 +36,10 @@
#include <QScopedPointer>
#include <QSqlDatabase>
#include <QObject>
#include <QList>
#include <QMap>
#include <QString>
#include "contactsdatabase.h"
#include "contactnotifier.h"
......
......@@ -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"));
......@@ -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
......@@ -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)
......
......@@ -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>
......
......@@ -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");
......
......@@ -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".
}
......
......@@ -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
......@@ -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);
......
......@@ -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; \
......@@ -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>)
......@@ -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);
......
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