void ImageCollectionTest::testImages() { ImageCollection c; QCOMPARE( c.getIds( QStringList() ).count(), 0 ); QImage image( "test.png" ); c.addImage( image, QStringList() ); // Verify that we have one image and get the id for it QList<int> ids = c.getIds( QStringList() ); QCOMPARE( ids.count(), 1 ); int id = ids[0]; QImage fromDb = c.getImage( id ); QVERIFY( pixelCompareImages( image, fromDb ) ); // Will call qFatal and end the application // QTest::ignoreMessage( QtFatalMsg, "Failed to get image id" ); // fromDb = c.getImage( id+1 ); // QVERIFY( fromDb.isNull() ); QSqlDatabase::removeDatabase( QLatin1String( QSqlDatabase::defaultConnection ) ); }
void ImageCollectionTest::testTags() { ImageCollection c; // Make sure that the collection is empty QCOMPARE( c.getTags().count(), 0 ); // At least one image is needed to be able to add tags c.addImage( QImage( "test.png" ), QStringList() ); // Verify that we have one image and get the id for it QList<int> ids = c.getIds( QStringList() ); QCOMPARE( ids.count(), 1 ); int id = ids[0]; // Add one tag, total one c.addTag( id, "Foo" ); QCOMPARE( c.getTags().count(), 1 ); // Add one tag, total two c.addTag( id, "Bar" ); QCOMPARE( c.getTags().count(), 2 ); // Add one tag, total three c.addTag( id, "Baz" ); QCOMPARE( c.getTags().count(), 3 ); // Add a duplicate tag, total three c.addTag( id, "Foo" ); QCOMPARE( c.getTags().count(), 3 ); // Try to add a tag to a nonexisting id QEXPECT_FAIL("", "The tag will be added to the non-existing image.", Continue); c.addTag( id+1, "Foz" ); QCOMPARE( c.getTags().count(), 3 ); QSqlDatabase::removeDatabase( QLatin1String( QSqlDatabase::defaultConnection ) ); }
void ImageCollectionTest::testImagesFromTags() { ImageCollection c; QCOMPARE( c.getIds( QStringList() ).count(), 0 ); QImage image( "test.png" ); QStringList tags; tags << "Foo" << "Bar"; c.addImage( image, tags ); QCOMPARE( c.getTags().count(), 2 ); QCOMPARE( c.getIds( QStringList() ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Foo" ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Bar" ).count(), 1 ); QCOMPARE( c.getIds( tags ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Baz" ).count(), 0 ); tags.clear(); tags << "Baz"; c.addImage( image, tags ); QCOMPARE( c.getTags().count(), 3 ); QCOMPARE( c.getIds( QStringList() ).count(), 2 ); QCOMPARE( c.getIds( QStringList() << "Foo" ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Bar" ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Baz" ).count(), 1 ); tags.clear(); tags << "Bar" << "Baz"; c.addImage( image, tags ); QCOMPARE( c.getTags().count(), 3 ); QCOMPARE( c.getIds( QStringList() ).count(), 3 ); QCOMPARE( c.getIds( QStringList() << "Foo" ).count(), 1 ); QCOMPARE( c.getIds( QStringList() << "Bar" ).count(), 2 ); QCOMPARE( c.getIds( tags ).count(), 3 ); QCOMPARE( c.getIds( QStringList() << "Baz" ).count(), 2 ); QSqlDatabase::removeDatabase( QLatin1String( QSqlDatabase::defaultConnection ) ); }