git repos / SagoImageBrowser

blame: test/test_exifreader.cpp

normal view · raw

14cf904f Poul Sander 2026-06-22 18:18 1
/*
14cf904f Poul Sander 2026-06-22 18:18 2
MIT License
14cf904f Poul Sander 2026-06-22 18:18 3
14cf904f Poul Sander 2026-06-22 18:18 4
Copyright (c) 2026 Poul Sander
14cf904f Poul Sander 2026-06-22 18:18 5
14cf904f Poul Sander 2026-06-22 18:18 6
Permission is hereby granted, free of charge, to any person obtaining a copy
14cf904f Poul Sander 2026-06-22 18:18 7
of this software and associated documentation files (the "Software"), to deal
14cf904f Poul Sander 2026-06-22 18:18 8
in the Software without restriction, including without limitation the rights
14cf904f Poul Sander 2026-06-22 18:18 9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14cf904f Poul Sander 2026-06-22 18:18 10
copies of the Software, and to permit persons to whom the Software is
14cf904f Poul Sander 2026-06-22 18:18 11
furnished to do so, subject to the following conditions:
14cf904f Poul Sander 2026-06-22 18:18 12
14cf904f Poul Sander 2026-06-22 18:18 13
The above copyright notice and this permission notice shall be included in all
14cf904f Poul Sander 2026-06-22 18:18 14
copies or substantial portions of the Software.
14cf904f Poul Sander 2026-06-22 18:18 15
14cf904f Poul Sander 2026-06-22 18:18 16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14cf904f Poul Sander 2026-06-22 18:18 17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14cf904f Poul Sander 2026-06-22 18:18 18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14cf904f Poul Sander 2026-06-22 18:18 19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14cf904f Poul Sander 2026-06-22 18:18 20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14cf904f Poul Sander 2026-06-22 18:18 21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
14cf904f Poul Sander 2026-06-22 18:18 22
SOFTWARE.
14cf904f Poul Sander 2026-06-22 18:18 23
14cf904f Poul Sander 2026-06-22 18:18 24
*/
14cf904f Poul Sander 2026-06-22 18:18 25
35c3554c Poul Sander 2026-06-07 13:09 26
#include <QCoreApplication>
35c3554c Poul Sander 2026-06-07 13:09 27
#include <QDebug>
35c3554c Poul Sander 2026-06-07 13:09 28
#include <cassert>
35c3554c Poul Sander 2026-06-07 13:09 29
#include "exifreader.h"
35c3554c Poul Sander 2026-06-07 13:09 30
35c3554c Poul Sander 2026-06-07 13:09 31
int main(int argc, char *argv[]) {
35c3554c Poul Sander 2026-06-07 13:09 32
    QCoreApplication app(argc, argv);
35c3554c Poul Sander 2026-06-07 13:09 33
35c3554c Poul Sander 2026-06-07 13:09 34
    qDebug() << "Running ExifReader test...";
35c3554c Poul Sander 2026-06-07 13:09 35
35c3554c Poul Sander 2026-06-07 13:09 36
    // Test ExifData::isEmpty()
35c3554c Poul Sander 2026-06-07 13:09 37
    ExifData data;
35c3554c Poul Sander 2026-06-07 13:09 38
    assert(data.isEmpty());
35c3554c Poul Sander 2026-06-07 13:09 39
    qDebug() << "ExifData::isEmpty() passed for empty data.";
35c3554c Poul Sander 2026-06-07 13:09 40
35c3554c Poul Sander 2026-06-07 13:09 41
    data.filename = "test.jpg";
35c3554c Poul Sander 2026-06-07 13:09 42
    assert(!data.isEmpty());
35c3554c Poul Sander 2026-06-07 13:09 43
    qDebug() << "ExifData::isEmpty() passed for non-empty data.";
35c3554c Poul Sander 2026-06-07 13:09 44
35c3554c Poul Sander 2026-06-07 13:09 45
    // Test ExifData::toList()
35c3554c Poul Sander 2026-06-07 13:09 46
    data.fileSize = "1.2 MiB";
091a4f7d Poul Sander 2026-06-09 19:54 47
    data.orientation = "1 (top, left)";
091a4f7d Poul Sander 2026-06-09 19:54 48
    data.latitude = "55deg 40' 32.12\" N";
091a4f7d Poul Sander 2026-06-09 19:54 49
    data.longitude = "12deg 34' 11.23\" E";
091a4f7d Poul Sander 2026-06-09 19:54 50
    data.osmLink = "https://www.openstreetmap.org/?mlat=55.675589&mlon=12.569786#map=16/55.675589/12.569786";
35c3554c Poul Sander 2026-06-07 13:09 51
    auto list = data.toList();
35c3554c Poul Sander 2026-06-07 13:09 52
    bool foundFilename = false;
35c3554c Poul Sander 2026-06-07 13:09 53
    bool foundSize = false;
091a4f7d Poul Sander 2026-06-09 19:54 54
    bool foundOrientation = false;
091a4f7d Poul Sander 2026-06-09 19:54 55
    bool foundLat = false;
091a4f7d Poul Sander 2026-06-09 19:54 56
    bool foundLon = false;
091a4f7d Poul Sander 2026-06-09 19:54 57
    bool foundOsm = false;
35c3554c Poul Sander 2026-06-07 13:09 58
    for (const auto &pair : list) {
35c3554c Poul Sander 2026-06-07 13:09 59
        if (pair.first == "Filename" && pair.second == "test.jpg") foundFilename = true;
35c3554c Poul Sander 2026-06-07 13:09 60
        if (pair.first == "File Size" && pair.second == "1.2 MiB") foundSize = true;
091a4f7d Poul Sander 2026-06-09 19:54 61
        if (pair.first == "Orientation" && pair.second == "1 (top, left)") foundOrientation = true;
091a4f7d Poul Sander 2026-06-09 19:54 62
        if (pair.first == "Latitude" && pair.second == "55deg 40' 32.12\" N") foundLat = true;
091a4f7d Poul Sander 2026-06-09 19:54 63
        if (pair.first == "Longitude" && pair.second == "12deg 34' 11.23\" E") foundLon = true;
091a4f7d Poul Sander 2026-06-09 19:54 64
        if (pair.first == "OpenStreetMap" && pair.second == "https://www.openstreetmap.org/?mlat=55.675589&mlon=12.569786#map=16/55.675589/12.569786") foundOsm = true;
35c3554c Poul Sander 2026-06-07 13:09 65
    }
35c3554c Poul Sander 2026-06-07 13:09 66
    assert(foundFilename);
35c3554c Poul Sander 2026-06-07 13:09 67
    assert(foundSize);
091a4f7d Poul Sander 2026-06-09 19:54 68
    assert(foundOrientation);
091a4f7d Poul Sander 2026-06-09 19:54 69
    assert(foundLat);
091a4f7d Poul Sander 2026-06-09 19:54 70
    assert(foundLon);
091a4f7d Poul Sander 2026-06-09 19:54 71
    assert(foundOsm);
35c3554c Poul Sander 2026-06-07 13:09 72
    qDebug() << "ExifData::toList() passed.";
35c3554c Poul Sander 2026-06-07 13:09 73
35c3554c Poul Sander 2026-06-07 13:09 74
    qDebug() << "All ExifReader tests passed!";
35c3554c Poul Sander 2026-06-07 13:09 75
    return 0;
35c3554c Poul Sander 2026-06-07 13:09 76
}
1970-01-01 00:00 77