File indexing completed on 2025-01-05 03:58:09
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-06-28 0007 * Description : Test loading and saving of data in GPSItemContainer. 0008 * 0009 * SPDX-FileCopyrightText: 2010 by Michael G. Hansen <mike at mghansen dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "gpsimageitem_utest.h" 0016 0017 // Qt includes 0018 0019 #include <QDateTime> 0020 #include <QScopedPointer> 0021 #include <QUrl> 0022 0023 // local includes 0024 0025 #include "digikam_debug.h" 0026 #include "dmetadata.h" 0027 #include "gpsdatacontainer.h" 0028 #include "gpsitemcontainer.h" 0029 #include "dtestdatadir.h" 0030 0031 using namespace Digikam; 0032 0033 void TestGPSItemContainer::initTestCase() 0034 { 0035 // initialize Exiv2 before doing any multitasking 0036 0037 MetaEngine::initializeExiv2(); 0038 } 0039 0040 void TestGPSItemContainer::cleanupTestCase() 0041 { 0042 } 0043 0044 /** 0045 * @brief Return the path of the directory containing the test data 0046 */ 0047 QString GetTestDataDirectory() 0048 { 0049 QString filesPath = DTestDataDir::TestData(QString::fromUtf8("core/tests/geolocation/editor")) 0050 .root().path() + QLatin1Char('/'); 0051 qCDebug(DIGIKAM_TESTS_LOG) << "Test Data Dir:" << filesPath; 0052 0053 return filesPath; 0054 } 0055 0056 GPSItemContainer* ItemFromFile(const QUrl& url) 0057 { 0058 QScopedPointer<GPSItemContainer> imageItem(new GPSItemContainer(url)); 0059 0060 if (imageItem->loadImageData()) 0061 { 0062 return imageItem.take(); 0063 } 0064 0065 return nullptr; 0066 } 0067 0068 /** 0069 * @brief Dummy test that does nothing 0070 */ 0071 void TestGPSItemContainer::testNoOp() 0072 { 0073 } 0074 0075 void TestGPSItemContainer::testBasicLoading() 0076 { 0077 { 0078 // test failure on not-existing file 0079 QUrl testDataDir = QUrl::fromLocalFile(GetTestDataDirectory() + QLatin1String("not-existing")); 0080 QScopedPointer<GPSItemContainer> imageItem(ItemFromFile(testDataDir)); 0081 QVERIFY(!imageItem); 0082 } 0083 0084 { 0085 // load a file without GPS info 0086 QUrl testDataDir = QUrl::fromLocalFile(GetTestDataDirectory() + QLatin1String("exiftest-nogps.png")); 0087 QScopedPointer<GPSItemContainer> imageItem(ItemFromFile(testDataDir)); 0088 QVERIFY(imageItem); 0089 0090 const GPSDataContainer container = imageItem->gpsData(); 0091 QVERIFY(!container.hasCoordinates()); 0092 QVERIFY(!container.hasAltitude()); 0093 QVERIFY(!container.hasNSatellites()); 0094 QVERIFY(!container.hasDop()); 0095 QVERIFY(!container.hasFixType()); 0096 } 0097 0098 { 0099 // load a file with geo:5,15,25 0100 QUrl testDataDir = QUrl::fromLocalFile(GetTestDataDirectory() + QLatin1String("exiftest-5_15_25.jpg")); 0101 QScopedPointer<GPSItemContainer> imageItem(ItemFromFile(testDataDir)); 0102 QVERIFY(imageItem); 0103 0104 const GPSDataContainer container = imageItem->gpsData(); 0105 QVERIFY(container.hasCoordinates()); 0106 QVERIFY(container.hasAltitude()); 0107 QVERIFY(container.getCoordinates().lat() == 5.0); 0108 QVERIFY(container.getCoordinates().lon() == 15.0); 0109 QVERIFY(container.getCoordinates().alt() == 25.0); 0110 QVERIFY(!container.hasNSatellites()); 0111 QVERIFY(!container.hasDop()); 0112 QVERIFY(!container.hasFixType()); 0113 } 0114 } 0115 0116 QTEST_GUILESS_MAIN(TestGPSItemContainer) 0117 0118 #include "moc_gpsimageitem_utest.cpp"