Magick++ 7.1.1
Loading...
Searching...
No Matches
coderInfo.cpp
1// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 2001, 2002, 2003
4//
5// Test Magick::CoderInfo class and Magick::coderInfoList
6//
7
8#include <Magick++.h>
9#include <string>
10#include <iostream>
11#include <list>
12
13using namespace std;
14
15using namespace Magick;
16
17int test( CoderInfo::MatchType isReadable_,
18 CoderInfo::MatchType isWritable_,
19 CoderInfo::MatchType isMultiFrame_ )
20{
21 int result = 0;
22 list<CoderInfo> coderList;
23 coderInfoList( &coderList, isReadable_, isWritable_, isMultiFrame_ );
24 list<CoderInfo>::iterator entry = coderList.begin();
25 while( entry != coderList.end() )
26 {
27 // Readable
28 if ( isReadable_ != CoderInfo::AnyMatch &&
29 (( entry->isReadable() && isReadable_ != CoderInfo::TrueMatch ) ||
30 ( !entry->isReadable() && isReadable_ != CoderInfo::FalseMatch )) )
31 {
32 cout << "Entry \""
33 << entry->name()
34 << "\" has unexpected readability state ("
35 << static_cast<int>(entry->isReadable())
36 << ")"
37 << endl;
38 ++result;
39 }
40
41 // Writable
42 if ( isWritable_ != CoderInfo::AnyMatch &&
43 (( entry->isWritable() && isWritable_ != CoderInfo::TrueMatch ) ||
44 ( !entry->isWritable() && isWritable_ != CoderInfo::FalseMatch )) )
45 {
46 cout << "Entry \""
47 << entry->name()
48 << "\" has unexpected writability state ("
49 << static_cast<int>(entry->isWritable())
50 << ")"
51 << endl;
52 ++result;
53 }
54
55 // MultiFrame
56 if ( isMultiFrame_ != CoderInfo::AnyMatch &&
57 (( entry->isMultiFrame() && isMultiFrame_ != CoderInfo::TrueMatch ) ||
58 ( !entry->isMultiFrame() && isMultiFrame_ != CoderInfo::FalseMatch )) )
59 {
60 cout << "Entry \""
61 << entry->name()
62 << "\" has unexpected multiframe state ("
63 << static_cast<int>(entry->isMultiFrame())
64 << ")"
65 << endl;
66 ++result;
67 }
68
69 entry++;
70 }
71
72 return result;
73}
74
75int main( int /*argc*/, char **argv)
76{
77
78 // Initialize ImageMagick install location for Windows
79 InitializeMagick(*argv);
80
81 int failures=0;
82
83 try {
84
85 CoderInfo coderInfo("GIF");
86 if ( coderInfo.name() != string("GIF") )
87 {
88 cout << "Unexpected coder name \""
89 << coderInfo.name()
90 << "\""
91 << endl;
92 ++failures;
93 }
94
95 if( coderInfo.description() != string("CompuServe graphics interchange format") )
96 {
97 cout << "Unexpected coder description \""
98 << coderInfo.description()
99 << "\""
100 << endl;
101 ++failures;
102 }
103
104 failures += test(CoderInfo::AnyMatch,CoderInfo::AnyMatch,CoderInfo::AnyMatch);
105 failures += test(CoderInfo::FalseMatch,CoderInfo::FalseMatch,CoderInfo::FalseMatch);
106
107 failures += test(CoderInfo::TrueMatch,CoderInfo::AnyMatch,CoderInfo::AnyMatch);
108 failures += test(CoderInfo::FalseMatch,CoderInfo::AnyMatch,CoderInfo::AnyMatch);
109
110 failures += test(CoderInfo::AnyMatch,CoderInfo::TrueMatch,CoderInfo::AnyMatch);
111 failures += test(CoderInfo::AnyMatch,CoderInfo::FalseMatch,CoderInfo::AnyMatch);
112
113 failures += test(CoderInfo::AnyMatch,CoderInfo::AnyMatch,CoderInfo::TrueMatch);
114 failures += test(CoderInfo::AnyMatch,CoderInfo::AnyMatch,CoderInfo::FalseMatch);
115 }
116 catch( Exception &error_ )
117 {
118 cout << "Caught exception: " << error_.what() << endl;
119 return 1;
120 }
121 catch( exception &error_ )
122 {
123 cout << "Caught exception: " << error_.what() << endl;
124 return 1;
125 }
126
127 if ( failures )
128 {
129 cout << failures << " failures" << endl;
130 return 1;
131 }
132
133 return 0;
134}