1 /*
2 * Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "kis_exiv2_test.h"
20
21 #include <QTest>
22 #include <QCoreApplication>
23
24 #include <QBuffer>
25
26 #include "kis_debug.h"
27 #include "kis_meta_data_entry.h"
28 #include "kis_meta_data_io_backend.h"
29 #include "kis_meta_data_schema.h"
30 #include "kis_meta_data_schema_registry.h"
31 #include "kis_meta_data_store.h"
32 #include "kis_meta_data_validator.h"
33 #include <kis_meta_data_value.h>
34 #include "kisexiv2/kis_exiv2.h"
35 #include "filestest.h"
36 #include "sdk/tests/kistest.h"
37
38 #ifndef FILES_DATA_DIR
39 #error "FILES_DATA_DIR not set. A directory with the data used for testing the metadata parser in krita"
40 #endif
41
42 using namespace KisMetaData;
43
testExifLoader()44 void KisExiv2Test::testExifLoader()
45 {
46 KisExiv2::initialize();
47
48 IOBackend* exifIO = IOBackendRegistry::instance()->get("exif");
49 QVERIFY(exifIO);
50 QFile exifFile(QString(FILES_DATA_DIR) + "/metadata/hpim3238.exv");
51 exifFile.open(QIODevice::ReadOnly);
52 exifFile.seek(17);
53 QByteArray exifBytes = exifFile.readAll();
54 QBuffer exifBuffer(&exifBytes);
55
56 Store* store = new Store;
57 bool loadSuccess = exifIO->loadFrom(store, &exifBuffer);
58 QVERIFY(loadSuccess);
59 Validator validator(store);
60
61 for (QMap<QString, Validator::Reason>::const_iterator it = validator.invalidEntries().begin();
62 it != validator.invalidEntries().end(); ++it) {
63 dbgKrita << it.key() << " = " << it.value().type() << " entry = " << store->getEntry(it.key());
64 }
65
66 QCOMPARE(validator.countInvalidEntries(), 0);
67 QCOMPARE(validator.countValidEntries(), 51);
68
69 const KisMetaData::Schema* tiffSchema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::TIFFSchemaUri);
70
71 QCOMPARE(store->getEntry(tiffSchema, "Make").value(), Value("Hewlett-Packard"));
72 QCOMPARE(store->getEntry(tiffSchema, "Model").value(), Value("HP PhotoSmart R707 (V01.00) "));
73 QCOMPARE(store->getEntry(tiffSchema, "Orientation").value(), Value(1));
74 QCOMPARE(store->getEntry(tiffSchema, "XResolution").value(), Value(Rational(72 / 1)));
75 QCOMPARE(store->getEntry(tiffSchema, "YResolution").value(), Value(Rational(72 / 1)));
76 QCOMPARE(store->getEntry(tiffSchema, "ResolutionUnit").value(), Value(2));
77 QCOMPARE(store->getEntry(tiffSchema, "YCbCrPositioning").value(), Value(1));
78
79 const KisMetaData::Schema* exifSchema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::EXIFSchemaUri);
80
81 QCOMPARE(store->getEntry(exifSchema, "ExposureTime").value(), Value(Rational(35355, 100000)));
82 QCOMPARE(store->getEntry(exifSchema, "FNumber").value(), Value(Rational(280, 100)));
83 QCOMPARE(store->getEntry(exifSchema, "ExposureProgram").value(), Value(2));
84 // QCOMPARE(store->getEntry(exifSchema, "ISOSpeedRatings").value(), Value(100)); // TODO it's a list
85 // TODO test OECF
86 QCOMPARE(store->getEntry(exifSchema, "ExifVersion").value(), Value("0220"));
87 QCOMPARE(store->getEntry(exifSchema, "DateTimeOriginal").value(), Value(QDateTime(QDate(2007, 5, 8), QTime(0, 19, 18))));
88 QCOMPARE(store->getEntry(exifSchema, "DateTimeDigitized").value(), Value(QDateTime(QDate(2007, 5, 8), QTime(0, 19, 18))));
89 // TODO ComponentsConfiguration
90 QCOMPARE(store->getEntry(exifSchema, "ShutterSpeedValue").value(), Value(Rational(384, 256)));
91 QCOMPARE(store->getEntry(exifSchema, "ApertureValue").value(), Value(Rational(780, 256)));
92 QCOMPARE(store->getEntry(exifSchema, "BrightnessValue").value(), Value(Rational(-37, 256)));
93 QCOMPARE(store->getEntry(exifSchema, "ExposureBiasValue").value(), Value(Rational(256, 256)));
94 QCOMPARE(store->getEntry(exifSchema, "MaxApertureValue").value(), Value(Rational(280, 100)));
95 QCOMPARE(store->getEntry(exifSchema, "SubjectDistance").value(), Value(Rational(65535, 1000)));
96
97
98 const KisMetaData::Schema* dcSchema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::DublinCoreSchemaUri);
99 Q_UNUSED(dcSchema);
100
101 const KisMetaData::Schema* xmpSchema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::XMPSchemaUri);
102 QCOMPARE(store->getEntry(xmpSchema, "CreatorTool").value(), Value("digiKam-0.9.1"));
103 QCOMPARE(store->getEntry(xmpSchema, "ModifyDate").value(), Value(QDateTime(QDate(2007, 5, 8), QTime(0, 19, 18))));
104
105 const KisMetaData::Schema* mknSchema = KisMetaData::SchemaRegistry::instance()->schemaFromUri(KisMetaData::Schema::MakerNoteSchemaUri);
106 QCOMPARE(store->getEntry(mknSchema, "RawData").value(), Value("SFBNZXQ="));
107 }
108
109 KISTEST_MAIN(KisExiv2Test)
110
111