File: Geolocation.t

package info (click to toggle)
libimage-exiftool-perl 13.25%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,600 kB
  • sloc: perl: 297,808; xml: 123; makefile: 22; sh: 15
file content (132 lines) | stat: -rw-r--r-- 4,114 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/Geolocation.t".

BEGIN {
    $| = 1; print "1..8\n"; $Image::ExifTool::configFile = '';
    require './t/TestLib.pm'; t::TestLib->import();
}
END {print "not ok 1\n" unless $loaded;}

# test 1: Load the module(s)
use Image::ExifTool 'ImageInfo';
use Image::ExifTool::Geolocation;
$loaded = 1;
print "ok 1\n";

my $testname = 'Geolocation';
my $testnum = 1;

# test 2: Test Geolocation option
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(Geolocation => 1);
    $exifTool->Options(GeolocMinPop => 5000);
    my $info = $exifTool->ImageInfo('t/images/GPS.jpg', 'Geolocation*');
    notOK() unless check($exifTool, $info, $testname, $testnum);
    print "ok $testnum\n";
}

# test 3: Test writing Geolocate with GPS
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(GeolocMinPop => 1000000);
    $exifTool->SetNewValue(Geolocate => '44,-72');
    $exifTool->SetNewValue('IPTC:Geolocate' => '48.338, 2.074');
    $testfile = "t/${testname}_${testnum}_failed.jpg";
    unlink $testfile;
    writeInfo($exifTool, 't/images/Writer.jpg', $testfile);
    my $info = $exifTool->ImageInfo($testfile, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 4: Test writing Geolocate with city name
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->SetNewValue(Geolocate => 'Kingston,Ontario');
    $exifTool->Options(Composite => 0);
    $testfile = "t/${testname}_${testnum}_failed.jpg";
    unlink $testfile;
    writeInfo($exifTool, 't/images/Writer.jpg', $testfile);
    my $info = $exifTool->ImageInfo($testfile, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 5: Geotag with Geolocation
{
    my @testTags = ('Error', 'Warning', 'GPS:*', 'XMP:*', 'IPTC:*');
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $testfile = "t/${testname}_${testnum}_failed.jpg";
    unlink $testfile;
    $exifTool->SetNewValue('IPTC:XMP:Geolocate' => 'Geotag');
    $exifTool->SetNewValue(Geotag => 't/images/Geotag.gpx');
    $exifTool->SetNewValue(Geotime => '2003:05:24 17:09:31Z');
    $exifTool->WriteInfo('t/images/Writer.jpg', $testfile);
    my $info = $exifTool->ImageInfo($testfile, @testTags);
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 6: Generate geolocation information from dummy file in memory,
#         returning the two nearest cities, avoiding PPLX features
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(Geolocation => '48.1375,11.5755,num=2');
    $exifTool->Options(GeolocFeature => '-PPLX');
    my $dat = '';
    my $info = $exifTool->ImageInfo(\$dat, 'geolocation*');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# tests 7-8: Test regular expression with combined search with user-defined
#            database entry
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    Image::ExifTool::Geolocation::AddEntry('Sinemorets','burgas','Obshtina Tsarevo',
        'BG','','Europe/Sofia','',400,42.06115,27.97833,'abcde,fghij,klmno');
    $exifTool->Options(Geolocation => '1,2,co/Canada/');
    my $dat = '';
    my $info = $exifTool->ImageInfo(\$dat, 'geolocation*');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";

    ++$testnum;
    $exifTool->Options(Geolocation => 'fghij');
    $info = $exifTool->ImageInfo(\$dat, 'geolocation*');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

done(); # end