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); }