void tst_QServiceFilter::testCapabilities() { QServiceFilter filter; QCOMPARE(filter.capabilities(), QStringList()); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchMinimum); filter.setCapabilities(QServiceFilter::MatchMinimum, QStringList() << "execute"); QCOMPARE(filter.capabilities(), (QStringList() << "execute")); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchMinimum); filter.setCapabilities(QServiceFilter::MatchMinimum, QStringList() << "execute" << "read"); QCOMPARE(filter.capabilities(), (QStringList() << "execute" << "read")); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchMinimum); filter.setCapabilities(QServiceFilter::MatchMinimum); QCOMPARE(filter.capabilities(), QStringList()); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchMinimum); filter.setCapabilities(QServiceFilter::MatchLoadable, QStringList() << "execute" << "read"); QCOMPARE(filter.capabilities(), (QStringList() << "execute" << "read")); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchLoadable); filter.setCapabilities(QServiceFilter::MatchLoadable); QCOMPARE(filter.capabilities(), QStringList()); QCOMPARE(filter.capabilityMatchRule(), QServiceFilter::MatchLoadable); }
void tst_QServiceFilter::streamTest() { QByteArray byteArray; QBuffer buffer(&byteArray); buffer.open(QIODevice::ReadWrite); QDataStream stream(&buffer); QServiceFilter emptyFilter; QCOMPARE(emptyFilter.majorVersion(), -1); QCOMPARE(emptyFilter.minorVersion(), -1); QCOMPARE(emptyFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(emptyFilter.serviceName(), QString("")); QCOMPARE(emptyFilter.interfaceName(), QString("")); QCOMPARE(emptyFilter.customAttribute("key1"), QString()); QCOMPARE(emptyFilter.capabilities(), QStringList()); QCOMPARE(emptyFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); buffer.seek(0); stream << emptyFilter; QServiceFilter tempFilter; QCOMPARE(tempFilter.majorVersion(), -1); QCOMPARE(tempFilter.minorVersion(), -1); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("")); QCOMPARE(tempFilter.interfaceName(), QString("")); QCOMPARE(tempFilter.customAttribute("key1"), QString()); QCOMPARE(tempFilter.capabilities(), QStringList()); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); buffer.seek(0); stream >> tempFilter; QCOMPARE(tempFilter.majorVersion(), -1); QCOMPARE(tempFilter.minorVersion(), -1); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("")); QCOMPARE(tempFilter.interfaceName(), QString("")); QCOMPARE(tempFilter.customAttribute("key1"), QString()); QCOMPARE(tempFilter.capabilities(), QStringList()); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); //assign filter to new filter via constructor tempFilter.setInterface("com.nokia.qt.valid", "4.77", QServiceFilter::ExactVersionMatch); tempFilter.setServiceName("ServiceName"); tempFilter.setCustomAttribute("key1", "value1"); tempFilter.setCapabilities(QServiceFilter::MatchLoadable, QStringList() << "execute" << "delete"); QCOMPARE(tempFilter.majorVersion(), 4); QCOMPARE(tempFilter.minorVersion(), 77); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("ServiceName")); QCOMPARE(tempFilter.interfaceName(), QString("com.nokia.qt.valid")); QCOMPARE(tempFilter.customAttribute("key1"), QString("value1")); QCOMPARE(tempFilter.capabilities(), (QStringList()<<"execute" << "delete")); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable); buffer.seek(0); stream << tempFilter; QServiceFilter constructFilter; buffer.seek(0); stream >> constructFilter; QCOMPARE(constructFilter.majorVersion(), 4); QCOMPARE(constructFilter.minorVersion(), 77); QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch); QCOMPARE(constructFilter.serviceName(), QString("ServiceName")); QCOMPARE(constructFilter.interfaceName(), QString("com.nokia.qt.valid")); QCOMPARE(constructFilter.customAttribute("key1"), QString("value1")); QCOMPARE(constructFilter.capabilities(), (QStringList()<<"execute" << "delete")); QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable); //assign empty filter to filter with values buffer.seek(0); stream << emptyFilter; buffer.seek(0); stream >> constructFilter; QCOMPARE(constructFilter.majorVersion(), -1); QCOMPARE(constructFilter.minorVersion(), -1); QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(constructFilter.serviceName(), QString("")); QCOMPARE(constructFilter.interfaceName(), QString("")); QCOMPARE(constructFilter.customAttribute("key1"), QString()); QCOMPARE(constructFilter.capabilities(), QStringList()); QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); }
void tst_QServiceFilter::testAssignmentOperator() { QServiceFilter emptyFilter; QServiceFilter tempFilter(emptyFilter); //assign empty filter to empty filter QCOMPARE(emptyFilter.majorVersion(), -1); QCOMPARE(emptyFilter.minorVersion(), -1); QCOMPARE(emptyFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(emptyFilter.serviceName(), QString("")); QCOMPARE(emptyFilter.interfaceName(), QString("")); QCOMPARE(emptyFilter.customAttribute("key1"), QString()); QCOMPARE(emptyFilter.capabilities(), QStringList()); QCOMPARE(emptyFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); QCOMPARE(tempFilter.majorVersion(), -1); QCOMPARE(tempFilter.minorVersion(), -1); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("")); QCOMPARE(tempFilter.interfaceName(), QString("")); QCOMPARE(tempFilter.customAttribute("key1"), QString()); QCOMPARE(tempFilter.capabilities(), QStringList()); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); tempFilter = emptyFilter; QCOMPARE(tempFilter.majorVersion(), -1); QCOMPARE(tempFilter.minorVersion(), -1); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("")); QCOMPARE(tempFilter.interfaceName(), QString("")); QCOMPARE(tempFilter.customAttribute("key1"), QString()); QCOMPARE(tempFilter.capabilities(), QStringList()); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); //assign filter to new filter via constructor tempFilter.setInterface("com.nokia.qt.valid", "4.77", QServiceFilter::ExactVersionMatch); tempFilter.setServiceName("ServiceName"); tempFilter.setCustomAttribute("key1", "value1"); tempFilter.setCapabilities(QServiceFilter::MatchLoadable, QStringList() << "read" << "write"); QCOMPARE(tempFilter.majorVersion(), 4); QCOMPARE(tempFilter.minorVersion(), 77); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("ServiceName")); QCOMPARE(tempFilter.interfaceName(), QString("com.nokia.qt.valid")); QCOMPARE(tempFilter.customAttribute("key1"), QString("value1")); QCOMPARE(tempFilter.capabilities(), (QStringList() << "read" << "write")); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable); QServiceFilter constructFilter(tempFilter); QCOMPARE(constructFilter.majorVersion(), 4); QCOMPARE(constructFilter.minorVersion(), 77); QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch); QCOMPARE(constructFilter.serviceName(), QString("ServiceName")); QCOMPARE(constructFilter.interfaceName(), QString("com.nokia.qt.valid")); QCOMPARE(constructFilter.customAttribute("key1"), QString("value1")); QCOMPARE(constructFilter.capabilities(), (QStringList() << "read" << "write")); QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable); //ensure that we don't have any potential references between tempFilter and //constructedFilter tempFilter.setServiceName("NewServiceName"); tempFilter.setInterface("com.nokia.qt.valid2", "5.88", QServiceFilter::MinimumVersionMatch); tempFilter.setCustomAttribute("key2", "value2"); tempFilter.setCapabilities(QServiceFilter::MatchMinimum,QStringList() << "execute"); QCOMPARE(tempFilter.majorVersion(), 5); QCOMPARE(tempFilter.minorVersion(), 88); QCOMPARE(tempFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(tempFilter.serviceName(), QString("NewServiceName")); QCOMPARE(tempFilter.interfaceName(), QString("com.nokia.qt.valid2")); QCOMPARE(tempFilter.customAttribute("key1"), QString("value1")); QCOMPARE(tempFilter.customAttribute("key2"), QString("value2")); QCOMPARE(tempFilter.capabilities(), (QStringList() << "execute")); QCOMPARE(tempFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); QCOMPARE(constructFilter.majorVersion(), 4); QCOMPARE(constructFilter.minorVersion(), 77); QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::ExactVersionMatch); QCOMPARE(constructFilter.serviceName(), QString("ServiceName")); QCOMPARE(constructFilter.interfaceName(), QString("com.nokia.qt.valid")); QCOMPARE(constructFilter.customAttribute("key1"), QString("value1")); QCOMPARE(constructFilter.customAttribute("key2"), QString()); QCOMPARE(constructFilter.capabilities(), (QStringList() << "read" << "write")); QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchLoadable); //assign empty filter to filter with values constructFilter = emptyFilter; QCOMPARE(constructFilter.majorVersion(), -1); QCOMPARE(constructFilter.minorVersion(), -1); QCOMPARE(constructFilter.versionMatchRule(), QServiceFilter::MinimumVersionMatch); QCOMPARE(constructFilter.serviceName(), QString("")); QCOMPARE(constructFilter.interfaceName(), QString("")); QCOMPARE(constructFilter.customAttribute("key1"), QString()); QCOMPARE(constructFilter.customAttribute("key2"), QString()); QCOMPARE(constructFilter.capabilities(), QStringList()); QCOMPARE(constructFilter.capabilityMatchRule(), QServiceFilter::MatchMinimum); }