File: key-test.cpp

package info (click to toggle)
exiv2 0.20-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,080 kB
  • ctags: 6,382
  • sloc: cpp: 56,011; sh: 10,092; ansic: 1,622; makefile: 594; awk: 92; python: 36; sed: 16
file content (198 lines) | stat: -rw-r--r-- 4,904 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// ***************************************************************** -*- C++ -*-
/*
  Abstract : Key unit tests

  File     : key-test.cpp
  Version  : $Rev: 1512 $
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
  History  : 24-Aug-04, ahu: created

 */
// *****************************************************************************
// included header files
#include <exiv2/exif.hpp>
#include <exiv2/iptc.hpp>
#include <iostream>
#include <string>

using namespace Exiv2;

int main()
{
    int tc = 0;
    int rc = 0;

    std::string key("Exif.Iop.InteroperabilityVersion");
    ExifKey ek(key);

    // operator<<
    tc += 1;
    std::ostringstream os;
    os << ek;
    if (os.str() != key) {
        std::cout << "Testcase failed (operator<<)" << std::endl;
        rc += 1;
    }
    // familyName
    tc += 1;
    if (std::string(ek.familyName()) != "Exif") {
        std::cout << "Testcase failed (familyName)" << std::endl;
        rc += 1;
    }
    // groupName
    tc += 1;
    if (ek.groupName() != "Iop") {
        std::cout << "Testcase failed (groupName)" << std::endl;
        rc += 1;
    }
    // tagName
    tc += 1;
    if (ek.tagName() != "InteroperabilityVersion") {
        std::cout << "Testcase failed (tagName)" << std::endl;
        rc += 1;
    }
    // tagName
    tc += 1;
    if (ek.tag() != 0x0002) {
        std::cout << "Testcase failed (tag)" << std::endl;
        rc += 1;
    }
    // ifdName
    tc += 1;
    if (std::string(ek.ifdName()) != "Iop") {
        std::cout << "Testcase failed (ifdName: " << std::endl;
        rc += 1;
    }
    // sectionName
    tc += 1;
    if (ek.sectionName() != "Interoperability") {
        std::cout << "Testcase failed (sectionName)" << std::endl;
        rc += 1;
    }

    // -----

    // Copy constructor
    ExifKey ek2(ek);

    // operator<<
    tc += 1;
    std::ostringstream os2;
    os2 << ek2;
    if (os2.str() != key) {
        std::cout << "Testcase failed (operator<<)" << std::endl;
        rc += 1;
    }
    // familyName
    tc += 1;
    if (std::string(ek2.familyName()) != "Exif") {
        std::cout << "Testcase failed (familyName)" << std::endl;
        rc += 1;
    }
    // groupName
    tc += 1;
    if (ek2.groupName() != "Iop") {
        std::cout << "Testcase failed (groupName)" << std::endl;
        rc += 1;
    }
    // tagName
    tc += 1;
    if (ek2.tagName() != "InteroperabilityVersion") {
        std::cout << "Testcase failed (tagName)" << std::endl;
        rc += 1;
    }
    // tagName
    tc += 1;
    if (ek2.tag() != 0x0002) {
        std::cout << "Testcase failed (tag)" << std::endl;
        rc += 1;
    }
    // ifdName
    tc += 1;
    if (std::string(ek2.ifdName()) != "Iop") {
        std::cout << "Testcase failed (ifdName: " << std::endl;
        rc += 1;
    }
    // sectionName
    tc += 1;
    if (ek2.sectionName() != "Interoperability") {
        std::cout << "Testcase failed (sectionName)" << std::endl;
        rc += 1;
    }

    // -----

    ExifKey ek4("Exif.Image.0x0110");
    tc += 1;
    if (ek4.key() != "Exif.Image.Model") {
        std::cout << "Testcase failed (converted key)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ek4.tagName() != "Model") {
        std::cout << "Testcase failed (converted tagName)" << std::endl;
        rc += 1;
    }

    // -----

    ExifKey ek5("Exif.Nikon3.0x0007");
    tc += 1;
    if (ek5.key() != "Exif.Nikon3.Focus") {
        std::cout << "Testcase failed (converted key)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ek5.tagName() != "Focus") {
        std::cout << "Testcase failed (converted tagName)" << std::endl;
        rc += 1;
    }

    // -----

    IptcKey ik1("Iptc.Envelope.0x0005");
    tc += 1;
    if (ik1.key() != "Iptc.Envelope.Destination") {
        std::cout << "Testcase failed (converted Iptc key)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ik1.tagName() != "Destination") {
        std::cout << "Testcase failed (converted tagName)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ik1.recordName() != "Envelope") {
        std::cout << "Testcase failed (converted recordName)" << std::endl;
        rc += 1;
    }

    // -----

    IptcKey ik2(0xabcd, 0x1234);
    tc += 1;
    if (ik2.key() != "Iptc.0x1234.0xabcd") {
        std::cout << "Testcase failed (unknown Iptc key)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ik2.tagName() != "0xabcd") {
        std::cout << "Testcase failed (converted tagName)" << std::endl;
        rc += 1;
    }
    tc += 1;
    if (ik2.recordName() != "0x1234") {
        std::cout << "Testcase failed (converted recordName)" << std::endl;
        rc += 1;
    }

    // -----

    if (rc == 0) {
        std::cout << "All " << tc << " testcases passed." << std::endl;
    }
    else {
        std::cout << rc << " of " << tc << " testcases failed." << std::endl;
    }
}