1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4######################### We start with some black magic to print on failure.
5
6# Change 1..1 below to 1..last_test_to_print .
7# (It may become useful if the test is moved to ./t subdirectory.)
8
9BEGIN { $| = 1; print "1..6\n"; }
10END {print "package load...        not ok 1\n" unless $loaded;}
11use Image::IPTCInfo;
12$loaded = 1;
13print "package load....        ok 1\n";
14
15######################### End of black magic.
16
17#
18# Make sure debug mode is turned off for release
19#
20
21if ($Image::IPTCInfo::debugMode == 0)
22{
23    print "debug mode off....      ok 2\n";
24}
25else
26{
27    print "debug mode off....      not ok 2\n";
28}
29
30
31#
32# Test loading IPTC info
33#
34
35my $info = new Image::IPTCInfo('demo_images/burger_van.jpg');
36
37if (defined($info) && $info->Attribute('caption/abstract') eq
38    'A van full of burgers awaits mysterious buyers in a dark parking lot.')
39{
40    print "get caption....         ok 3\n";
41}
42else
43{
44    print "get caption....         not ok 3\n";
45    print "error: " . Image::IPTCInfo::Error() . "\n";
46}
47
48#
49# Test saving IPTC info
50#
51
52$info->SetAttribute('caption/abstract', 'modified caption');
53$info->SaveAs('demo_images/burger_van_save1.jpg') ||
54    print "error: " . Image::IPTCInfo::Error() . "\n";
55
56undef $info;
57
58$info = new Image::IPTCInfo('demo_images/burger_van_save1.jpg');
59
60if (defined($info) && $info->Attribute('caption/abstract') eq 'modified caption')
61{
62    print "save and load....       ok 4\n";
63}
64else
65{
66    print "save and load....       not ok 4\n";
67    print "error: " . Image::IPTCInfo::Error() . "\n";
68}
69
70#
71# Re-load modified image and use Save() to save, then check it
72#
73undef $info;
74
75$info = new Image::IPTCInfo('demo_images/burger_van_save1.jpg');
76
77if (!defined($info))
78{
79    print "re-save and re-load.... not ok 5\n";
80    print "error: " . Image::IPTCInfo::Error() . "\n";
81    exit;
82}
83
84$info->SetAttribute('caption/abstract', 'modified caption 2');
85$info->Save();
86
87undef $info;
88
89$info = new Image::IPTCInfo('demo_images/burger_van_save1.jpg');
90
91if (defined($info) && $info->Attribute('caption/abstract')
92    eq 'modified caption 2')
93{
94    print "re-save and re-load.... ok 5\n";
95}
96else
97{
98    print "re-save and re-load.... not ok 5\n";
99    print "error: " . Image::IPTCInfo::Error() . "\n";
100}
101
102use IO::File;
103my $handle = IO::File->new('demo_images/burger_van_save1.jpg');
104$info = Image::IPTCInfo->new($handle);
105if (defined($info) && $info->Attribute('caption/abstract')
106    eq 'modified caption 2')
107{
108    print "re-load with handle.... ok 6\n";
109}
110else
111{
112    print "re-load with handle.... not ok 6\n";
113    print "error: " . Image::IPTCInfo::Error() . "\n";
114}
115