Ejemplo n.º 1
0
void DataSpecTest::test_isCompatible()
{
    // Use Case:
    // DataSpec matches the data hash
    // expect true
    {
        DataSpec req;
        req.addServiceData("wibble1");
        QHash<QString, DataBlob*> hashData;
        hashData.insert("wibble1", NULL);
        CPPUNIT_ASSERT_EQUAL(true, req.isCompatible(hashData));

        DataSpec reqdata;
        reqdata.addServiceData("wibble1");
        CPPUNIT_ASSERT_EQUAL(true, req.isCompatible(reqdata));
    }

    // Use Case:
    // DataSpec contains a subset of the data hash
    // expect true
    {
        DataSpec req;
        req.addServiceData("wibble1");
        QHash<QString, DataBlob*> hashData;
        hashData.insert("wibble1", NULL);
        hashData.insert("wibble2", NULL);
        CPPUNIT_ASSERT_EQUAL(true, req.isCompatible(hashData));

        DataSpec reqdata;
        reqdata.addServiceData("wibble1");
        reqdata.addServiceData("wibble2");
        CPPUNIT_ASSERT_EQUAL(true, req.isCompatible(reqdata));
    }

    // Use Case:
    // DataSpec contains some elements of the data, but is not compatible with it.
    // The data requirements have an additional data type which is not in the hash.
    // expect false
    {
        DataSpec req;
        QSet<QString> dataTypes;
        dataTypes << "wibble1" << "other";
        req.addServiceData(dataTypes);
        QHash<QString, DataBlob*> hashData;
        hashData.insert("wibble1", NULL);
        hashData.insert("wibble2", NULL);
        CPPUNIT_ASSERT_EQUAL(false, req.isCompatible(hashData));

        DataSpec reqdata;
        reqdata.addServiceData("wibble1");
        reqdata.addServiceData("wibble2");
        CPPUNIT_ASSERT_EQUAL(false, req.isCompatible(reqdata));
    }

}