void ut_metadata::testEditCity()
{
    QTemporaryFile file;
    file.open();
    sourceImage.save(file.fileName(), "jpg");
    QuillMetadata empty;
    empty.setEntry(QuillMetadata::Tag_City, QString("Tapiola"));
    empty.write(file.fileName());

    QuillMetadata writtenMetadata(file.fileName());
    QVERIFY(writtenMetadata.isValid());
    QCOMPARE(writtenMetadata.entry(QuillMetadata::Tag_City).toString(),
             QString("Tapiola"));
}
void ut_metadata::testEditOrientation()
{
    QTemporaryFile file;
    file.open();
    sourceImage.save(file.fileName(), "jpg");
    QuillMetadata empty;
    empty.setEntry(QuillMetadata::Tag_Orientation, QVariant(7));
    QVERIFY(empty.write(file.fileName()));

    QuillMetadata writtenMetadata(file.fileName());
    QVERIFY(writtenMetadata.isValid());
    QCOMPARE(writtenMetadata.entry(QuillMetadata::Tag_Orientation).toString(),
             QString("7"));
}
void ut_metadata::testEditTitle()
{
    QTemporaryFile file;
    file.open();
    sourceImage.save(file.fileName(), "jpg");
    QuillMetadata empty;
    empty.setEntry(QuillMetadata::Tag_Title,
                   QString("The Big Fish"));
    QVERIFY(empty.write(file.fileName()));

    QuillMetadata writtenMetadata(file.fileName());
    QVERIFY(writtenMetadata.isValid());

    QCOMPARE(writtenMetadata.entry(QuillMetadata::Tag_Title).toString(),
             QString("The Big Fish"));
}
void ut_metadata::testEditKeywords()
{
    QTemporaryFile file;
    file.open();
    sourceImage.save(file.fileName(), "jpg");
    QuillMetadata empty;
    QStringList list;
    list << "aquarium" << "Neon Tetra" << "Paracheirodon innesi";

    empty.setEntry(QuillMetadata::Tag_Subject, list);
    empty.write(file.fileName());

    QuillMetadata writtenMetadata(file.fileName());
    QVERIFY(writtenMetadata.isValid());

    QStringList resultList =
        writtenMetadata.entry(QuillMetadata::Tag_Subject).toStringList();
    QCOMPARE(resultList, list);
}
void ut_load::testExifRotationSizePeek()
{
    QTemporaryFile testFile;
    testFile.open();

    QImage image("/usr/share/quillimagefilter-tests/images/16_color_palette.png");
    image.save(testFile.fileName(), "jpeg");

    QuillMetadata metadata;
    metadata.setEntry(QuillMetadata::Tag_Orientation, QVariant(6));
    metadata.write(testFile.fileName());

    QuillImageFilter *filter =
        QuillImageFilterFactory::createImageFilter("org.maemo.load");

    filter->setOption(QuillImageFilter::FileName, QString(testFile.fileName()));
    QCOMPARE(filter->newFullImageSize(QSize()), QSize(2, 8));

    delete filter;
}
void ut_metadata::testEditGps_direction()
{
    QuillMetadata editMetadata;

    QVERIFY(editMetadata.isValid());

    // Setting image direction between 0.00 and 359.99
    editMetadata.setEntry(QuillMetadata::Tag_GPSImgDirection, QVariant(double(25.25)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSImgDirection).toString(), QString("25.25"));

    // Setting image under 0.00
    editMetadata.setEntry(QuillMetadata::Tag_GPSImgDirection, QVariant(double(-15)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSImgDirection).toString(), QString("345"));

    // Setting image over 359.99
    editMetadata.setEntry(QuillMetadata::Tag_GPSImgDirection, QVariant(double(400)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSImgDirection).toString(), QString("40"));

    // Manually setting the direction reference
    editMetadata.setEntry(QuillMetadata::Tag_GPSImgDirectionRef, QVariant(QString("T")));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSImgDirectionRef).toString(), QString("T"));
}
void ut_metadata::testOrientationTagSpeedup()
{
    QString str("/usr/share/quillimagefilter-tests/images/16_color_palette.png");

    for (int i = 0; i<=8; i++){
        QTemporaryFile file;
        file.open();
        sourceImage.save(file.fileName(), "jpg");

        QuillMetadata empty;
        empty.setEntry(QuillMetadata::Tag_Orientation, QVariant(i));
        QVERIFY(empty.write(file.fileName()));

        int orientation1, orientation2;
        {
            QuillMetadata *metadata = new QuillMetadata(file.fileName(),
                                                        QuillMetadata::ExifFormat);
            QVERIFY(metadata->isValid());
            QCOMPARE(metadata->entry(QuillMetadata::Tag_Orientation).toInt(), i);

            orientation1 = metadata->entry(QuillMetadata::Tag_Orientation).toInt();

            delete metadata;
        }
        {
            QuillMetadata *metadata = new QuillMetadata(file.fileName(),
                                                        QuillMetadata::ExifFormat,
                                                        QuillMetadata::Tag_Orientation);
            QVERIFY(metadata->isValid());
            QCOMPARE(metadata->entry(QuillMetadata::Tag_Orientation).toInt(), i);
            orientation2 = metadata->entry(QuillMetadata::Tag_Orientation).toInt();

            delete metadata;
        }
        QCOMPARE(orientation1, orientation2);
    }
}
void ut_metadata::testEditGps_altitude()
{
    QuillMetadata editMetadata;
    double expected = 60.1639;
    double actual;

    QVERIFY(editMetadata.isValid());

    // Setting a latitude
    editMetadata.setEntry(QuillMetadata::Tag_GPSAltitude, QVariant(expected));
    actual = editMetadata.entry(QuillMetadata::Tag_GPSAltitude).toDouble();
    QCOMPARE(round(actual * PRECISION), round(expected * PRECISION));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSAltitudeRef).toString(), QString("0"));

    // Setting a negative altitude (that is: the altitude reference should be now "1" (below sea level)
    editMetadata.setEntry(QuillMetadata::Tag_GPSAltitude, QVariant(-expected));
    actual = editMetadata.entry(QuillMetadata::Tag_GPSAltitude).toDouble();
    QCOMPARE(round(actual * PRECISION), round(expected * PRECISION));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSAltitudeRef).toString(), QString("1"));

    // 0 meters altitude is over sea level
    editMetadata.setEntry(QuillMetadata::Tag_GPSAltitude, QVariant(double(0)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSAltitude).toString(), QString("0"));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSAltitudeRef).toString(), QString("0"));

    // Manually setting the altitude reference
    editMetadata.setEntry(QuillMetadata::Tag_GPSAltitudeRef, QVariant(int(1)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSAltitudeRef).toString(), QString("1"));
}
void ut_metadata::testEditGps_longitude()
{
    QuillMetadata editMetadata;
    double expected = 60.1639;
    double actual;

    QVERIFY(editMetadata.isValid());

    // Setting a setEntry
    editMetadata.setEntry(QuillMetadata::Tag_GPSLongitude, QVariant(expected));
    actual = editMetadata.entry(QuillMetadata::Tag_GPSLongitude).toDouble();
    QCOMPARE(round(actual * PRECISION), round(expected * PRECISION));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSLongitudeRef).toString(), QString("E"));

    // Setting a negative longitude (that is: the longitude reference should be now "W"est)
    editMetadata.setEntry(QuillMetadata::Tag_GPSLongitude, QVariant(-expected));
    actual = editMetadata.entry(QuillMetadata::Tag_GPSLongitude).toDouble();
    QCOMPARE(round(actual * PRECISION), round(expected * PRECISION));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSLongitudeRef).toString(), QString("W"));

    // 0 degrees longitude is "E"ast
    editMetadata.setEntry(QuillMetadata::Tag_GPSLongitude, QVariant(double(0)));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSLongitude).toString(), QString("0"));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSLongitudeRef).toString(), QString("E"));

    // Manually setting the longitude reference
    editMetadata.setEntry(QuillMetadata::Tag_GPSLongitudeRef, QVariant(QString("W")));
    QCOMPARE(editMetadata.entry(QuillMetadata::Tag_GPSLongitudeRef).toString(), QString("W"));
}