EXIF library (libexif) Internals  0.6.24
test-null.c
Go to the documentation of this file.
1 
23 #include "libexif/exif-data.h"
24 #include "libexif/exif-entry.h"
25 #include "libexif/exif-loader.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 static void loader_null_test(void)
32 {
33  ExifLoader *l;
34  ExifData *d;
35  unsigned char ret;
36  const unsigned char *ccp;
37  unsigned int i;
38 
39  l = exif_loader_new_mem(NULL);
40  if (l) {
41  fprintf(stderr, "Unexpected success in %s\n", "exif_loader_new_mem");
42  exit(13);
43  }
44 
45  exif_loader_ref(NULL);
46 
47  exif_loader_unref(NULL);
48 
49  exif_loader_write_file(NULL, "test");
50 
51  exif_loader_write_file(NULL, NULL);
52 
53  ret = exif_loader_write(NULL, (unsigned char *)"x", 1);
54  if (ret) {
55  fprintf(stderr, "Unexpected success in %s\n", "exif_loader_write");
56  exit(13);
57  }
58 
59  exif_loader_write(NULL, NULL, 123);
60 
61  exif_loader_reset(NULL);
62 
63  d = exif_loader_get_data(NULL);
64  if (d) {
65  fprintf(stderr, "Unexpected success in %s\n", "exif_loader_get_data");
66  exit(13);
67  }
68 
69  exif_loader_get_buf(NULL, NULL, NULL);
70 
71  exif_loader_log(NULL, NULL);
72 
73  l = exif_loader_new();
74  if (!l) {
75  fprintf(stderr, "Out of memory\n");
76  exit(13);
77  }
78 
79  exif_loader_write_file(l, NULL);
80 
81  exif_loader_write(l, NULL, 0);
82  exif_loader_write(l, NULL, 1);
83 
84  exif_loader_get_buf(l, NULL, NULL);
85  exif_loader_get_buf(l, &ccp, NULL);
86  exif_loader_get_buf(l, NULL, &i);
87 
88  exif_loader_log(l, NULL);
89 
91 }
92 
93 static void data_null_test(void)
94 {
95  /* exif_data_new_from_file() is untested since it doesn't check path */
96 
97  ExifData *d;
98  ExifByteOrder bo;
99  ExifMnoteData *m;
100  ExifDataType dt;
101  unsigned char *buf;
102  unsigned int len;
103 
104  d = exif_data_new_mem(NULL);
105  if (d) {
106  fprintf(stderr, "Unexpected success in %s\n", "exif_data_new_mem");
107  exit(13);
108  }
109 
110  d = exif_data_new_from_data(NULL, 123);
111  if (d) {
112  exif_data_unref(d);
113  }
114 
115  bo = exif_data_get_byte_order(NULL);
116  (void) bo;
117 
119 
120  m = exif_data_get_mnote_data(NULL);
121  if (m) {
122  fprintf(stderr, "Unexpected success in %s\n", "exif_data_get_mnote_data");
123  exit(13);
124  }
125 
126  exif_data_fix(NULL);
127 
128  exif_data_foreach_content(NULL, NULL, NULL);
129 
131 
133 
135 
136  dt = exif_data_get_data_type(NULL);
137  (void) dt;
138 
139  exif_data_load_data(NULL, NULL, 123);
140 
141  exif_data_save_data(NULL, NULL, NULL);
142 
143  exif_data_log(NULL, NULL);
144 
145  exif_data_dump(NULL);
146 
147  exif_data_ref(NULL);
148 
149  exif_data_unref(NULL);
150 
151  d = exif_data_new();
152  if (!d) {
153  fprintf(stderr, "Out of memory\n");
154  exit(13);
155  }
156 
157  exif_data_load_data(d, NULL, 123);
158 
159  exif_data_save_data(d, NULL, &len);
160  exif_data_save_data(d, &buf, NULL);
161  exif_data_save_data(d, NULL, NULL);
162 
163  exif_data_foreach_content(d, NULL, NULL);
164 
165  exif_data_log(d, NULL);
166 
167  exif_data_unref(d);
168 }
169 
170 static void content_null_test(void)
171 {
172  ExifContent *c;
173  ExifIfd i;
174 
175  c = exif_content_new_mem(NULL);
176  if (c) {
177  fprintf(stderr, "Unexpected success in %s\n", "exif_content_new_mem");
178  exit(13);
179  }
180 
181  exif_content_ref(NULL);
182 
183  exif_content_unref(NULL);
184 
185  exif_content_free(NULL);
186 
188 
189  exif_content_fix(NULL);
190 
191  exif_content_foreach_entry(NULL, NULL, NULL);
192 
193  i = exif_content_get_ifd(NULL);
194  (void) i;
195 
196  exif_content_dump(NULL, 0);
197 
198  exif_content_add_entry(NULL, NULL);
199 
200  exif_content_remove_entry(NULL, NULL);
201 
202  exif_content_log(NULL, NULL);
203 
204  c = exif_content_new();
205  if (!c) {
206  fprintf(stderr, "Out of memory\n");
207  exit(13);
208  }
209 
210  exif_content_add_entry(c, NULL);
211 
212  exif_content_remove_entry(c, NULL);
213 
214  exif_content_log(c, NULL);
215 
216  exif_content_foreach_entry(c, NULL, NULL);
217 
219 }
220 
221 static void entry_null_test(void)
222 {
223  ExifEntry *e;
224  const char *v = NULL;
225  char buf[] = {0};
226  ExifData *d;
227 
228  e = exif_entry_new_mem(NULL);
229  if (e) {
230  fprintf(stderr, "Unexpected success in %s\n", "exif_entry_new_mem");
231  exit(13);
232  }
233 
234  exif_entry_ref(NULL);
235 
236  exif_entry_unref(NULL);
237 
238  exif_entry_free(NULL);
239 
241 
242  exif_entry_fix(NULL);
243 
244  v = exif_entry_get_value(NULL, NULL, 123);
245  if (v) {
246  fprintf(stderr, "Unexpected success in %s\n", "exif_entry_get_value");
247  exit(13);
248  }
249 
250  v = exif_entry_get_value(NULL, buf, 1);
251  if (v != buf) {
252  fprintf(stderr, "Unexpected value in %s\n", "exif_entry_get_value");
253  exit(13);
254  }
255 
256  exif_entry_dump(NULL, 0);
257 
258  /* Creating a plain ExifEntry isn't enough, since some functions require
259  * that it exists in an IFD.
260  */
261  d = exif_data_new();
262  if (!d) {
263  fprintf(stderr, "Out of memory\n");
264  exit(13);
265  }
266  /* Create the mandatory EXIF fields so we have something to work with */
267  exif_data_fix(d);
269 
270  (void) exif_entry_get_value(e, NULL, 0);
271  (void) exif_entry_get_value(e, NULL, 123);
272 
273  exif_data_unref(d);
274 }
275 
276 static void mnote_null_test(void)
277 {
278  /* Note that these APIs aren't tested with a real ExifMnoteData pointer
279  * because it's impossible to create one without real data.
280  */
281  exif_mnote_data_ref(NULL);
282 
283  exif_mnote_data_unref(NULL);
284 
285  exif_mnote_data_load(NULL, NULL, 123);
286 
287  exif_mnote_data_load(NULL, (const unsigned char *)"x", 1);
288 
289  exif_mnote_data_save(NULL, NULL, NULL);
290 
291  exif_mnote_data_count(NULL);
292 
293  exif_mnote_data_get_id(NULL, 0);
294 
295  exif_mnote_data_get_name(NULL, 0);
296 
297  exif_mnote_data_get_title(NULL, 0);
298 
300 
301  exif_mnote_data_get_value(NULL, 0, NULL, 123);
302 
303  exif_mnote_data_log(NULL, NULL);
304 }
305 
306 static void log_null_test(void)
307 {
308  ExifLog *l;
309  static va_list va;
310 
311  l = exif_log_new_mem(NULL);
312  if (l) {
313  fprintf(stderr, "Unexpected success in %s\n", "exif_log_new_mem");
314  exit(13);
315  }
316 
317  exif_log_ref(NULL);
318 
319  exif_log_unref(NULL);
320 
321  exif_log_free(NULL);
322 
323  exif_log_set_func(NULL, NULL, NULL);
324 
325  exif_log(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY");
326 
327  exif_logv(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY", va);
328 
329  l = exif_log_new();
330  if (!l) {
331  fprintf(stderr, "Out of memory\n");
332  exit(13);
333  }
334 
335  exif_log_set_func(l, NULL, NULL);
336 
337  exif_log_unref(l);
338 }
339 
340 int main(void)
341 {
343  data_null_test();
345  entry_null_test();
346  mnote_null_test();
347  log_null_test();
348 
349  /* If it gets here, we didn't get a SIGSEGV, so success! */
350  return 0;
351 }
ExifByteOrder
Which byte order to use.
@ EXIF_BYTE_ORDER_MOTOROLA
Big-endian byte order.
void exif_content_remove_entry(ExifContent *c, ExifEntry *e)
Remove an EXIF tag from an IFD.
Definition: exif-content.c:163
ExifIfd exif_content_get_ifd(ExifContent *c)
Return the IFD number in which the given ExifContent is found.
Definition: exif-content.c:240
void exif_content_fix(ExifContent *c)
Fix the IFD to bring it into specification.
Definition: exif-content.c:284
void exif_content_ref(ExifContent *content)
Increase reference counter for ExifContent.
Definition: exif-content.c:79
void exif_content_unref(ExifContent *content)
Decrease reference counter for ExifContent.
Definition: exif-content.c:88
void exif_content_add_entry(ExifContent *c, ExifEntry *entry)
Add an EXIF tag to an IFD.
Definition: exif-content.c:139
ExifContent * exif_content_new_mem(ExifMem *mem)
Reserve memory for and initialize new ExifContent using the specified memory allocator.
Definition: exif-content.c:54
void exif_content_dump(ExifContent *content, unsigned int indent)
Dump contents of the IFD to stdout.
Definition: exif-content.c:120
ExifEntry * exif_content_get_entry(ExifContent *content, ExifTag tag)
Return the ExifEntry in this IFD corresponding to the given tag.
Definition: exif-content.c:202
void exif_content_log(ExifContent *content, ExifLog *log)
Set the log message object for this IFD.
Definition: exif-content.c:229
ExifContent * exif_content_new(void)
Reserve memory for and initialize a new ExifContent.
Definition: exif-content.c:43
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
Definition: exif-content.c:216
void exif_content_free(ExifContent *content)
Actually free the ExifContent.
Definition: exif-content.c:99
ExifDataType
Represents the type of image data to which the EXIF data applies.
@ EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition: exif-data.c:1217
ExifData * exif_data_new(void)
Allocate a new ExifData.
Definition: exif-data.c:96
void exif_data_unref(ExifData *data)
Definition: exif-data.c:1098
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition: exif-data.c:1173
void exif_data_ref(ExifData *data)
Definition: exif-data.c:1089
void exif_data_load_data(ExifData *data, const unsigned char *d_orig, unsigned int ds)
Load the ExifData structure from the raw JPEG or EXIF data in the given memory buffer.
Definition: exif-data.c:844
ExifDataType exif_data_get_data_type(ExifData *d)
Return the data type for the given ExifData.
Definition: exif-data.c:1357
ExifData * exif_data_new_from_data(const unsigned char *data, unsigned int size)
Allocate a new ExifData and load EXIF data from a memory buffer.
Definition: exif-data.c:154
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition: exif-data.c:90
void exif_data_fix(ExifData *d)
Fix the EXIF data to bring it into specification.
Definition: exif-data.c:1342
void exif_data_dump(ExifData *data)
Dump all EXIF data to stdout.
Definition: exif-data.c:1146
ExifData * exif_data_new_mem(ExifMem *mem)
Allocate a new ExifData using the given memory allocator.
Definition: exif-data.c:107
void exif_data_unset_option(ExifData *d, ExifDataOption o)
Clear the given option on the given ExifData.
Definition: exif-data.c:1305
void exif_data_set_data_type(ExifData *d, ExifDataType dt)
Set the data type for the given ExifData.
Definition: exif-data.c:1348
void exif_data_save_data(ExifData *data, unsigned char **d, unsigned int *ds)
Store raw EXIF data representing the ExifData structure into a memory buffer.
Definition: exif-data.c:1030
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition: exif-data.c:1182
void exif_data_log(ExifData *data, ExifLog *log)
Set the log message object for all IFDs.
Definition: exif-data.c:1233
void exif_data_set_option(ExifData *d, ExifDataOption o)
Set the given option on the given ExifData.
Definition: exif-data.c:1296
Defines the ExifData type and the associated functions.
@ EXIF_DATA_OPTION_FOLLOW_SPECIFICATION
Fix the EXIF tags to follow the spec.
Definition: exif-data.h:179
void exif_entry_free(ExifEntry *e)
Actually free the ExifEntry.
Definition: exif-entry.c:157
ExifEntry * exif_entry_new_mem(ExifMem *mem)
Reserve memory for and initialize new ExifEntry using the specified memory allocator.
Definition: exif-entry.c:122
void exif_entry_unref(ExifEntry *e)
Decrease reference counter for ExifEntry.
Definition: exif-entry.c:147
void exif_entry_fix(ExifEntry *e)
Fix the type or format of the given EXIF entry to bring it into spec.
Definition: exif-entry.c:205
void exif_entry_initialize(ExifEntry *e, ExifTag tag)
Initialize an empty ExifEntry with default data in the correct format for the given tag.
Definition: exif-entry.c:1459
void exif_entry_dump(ExifEntry *e, unsigned int indent)
Dump text representation of ExifEntry to stdout.
Definition: exif-entry.c:598
void exif_entry_ref(ExifEntry *e)
Increase reference counter for ExifEntry.
Definition: exif-entry.c:139
const char * exif_entry_get_value(ExifEntry *e, char *val, unsigned int maxlen)
Return a localized textual representation of the value of the EXIF entry.
Definition: exif-entry.c:846
Handling EXIF entries.
ExifIfd
Possible EXIF Image File Directories.
Definition: exif-ifd.h:29
@ EXIF_IFD_0
Definition: exif-ifd.h:30
void exif_loader_log(ExifLoader *loader, ExifLog *log)
Set the log message object used by this ExifLoader.
Definition: exif-loader.c:465
void exif_loader_reset(ExifLoader *loader)
Free any data previously loaded and reset the ExifLoader to its newly-initialized state.
Definition: exif-loader.c:413
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
Definition: exif-loader.c:352
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
Definition: exif-loader.c:404
ExifLoader * exif_loader_new_mem(ExifMem *mem)
Allocate a new ExifLoader using the specified memory allocator.
Definition: exif-loader.c:363
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
Definition: exif-loader.c:426
unsigned char exif_loader_write(ExifLoader *eld, unsigned char *buf, unsigned int len)
Load a buffer into the ExifLoader from a memory buffer.
Definition: exif-loader.c:163
void exif_loader_ref(ExifLoader *loader)
Increase the refcount of the ExifLoader.
Definition: exif-loader.c:382
void exif_loader_get_buf(ExifLoader *loader, const unsigned char **buf, unsigned int *buf_size)
Return the raw data read by the loader.
Definition: exif-loader.c:442
void exif_loader_write_file(ExifLoader *l, const char *path)
Load a file into the given ExifLoader from the filesystem.
Definition: exif-loader.c:117
Defines the ExifLoader type.
void exif_log(ExifLog *log, ExifLogCode code, const char *domain, const char *format,...)
Definition: exif-log.c:135
void exif_log_set_func(ExifLog *log, ExifLogFunc func, void *data)
Register log callback function.
Definition: exif-log.c:123
void exif_log_unref(ExifLog *log)
Definition: exif-log.c:104
ExifLog * exif_log_new(void)
Create a new logging instance.
Definition: exif-log.c:86
void exif_logv(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args)
Definition: exif-log.c:146
void exif_log_ref(ExifLog *log)
Definition: exif-log.c:97
ExifLog * exif_log_new_mem(ExifMem *mem)
Definition: exif-log.c:71
void exif_log_free(ExifLog *log)
Delete instance of ExifLog.
Definition: exif-log.c:112
@ EXIF_LOG_CODE_CORRUPT_DATA
Definition: exif-log.h:58
void exif_mnote_data_load(ExifMnoteData *d, const unsigned char *buf, unsigned int buf_size)
Load the MakerNote data from a memory buffer.
void exif_mnote_data_ref(ExifMnoteData *d)
char * exif_mnote_data_get_value(ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen)
Return a textual representation of the value of the MakerNote entry.
void exif_mnote_data_save(ExifMnoteData *d, unsigned char **buf, unsigned int *buf_size)
Save the raw MakerNote data into a memory buffer.
const char * exif_mnote_data_get_name(ExifMnoteData *d, unsigned int n)
Returns textual name of the given MakerNote tag.
unsigned int exif_mnote_data_get_id(ExifMnoteData *d, unsigned int n)
Return the MakerNote tag number for the tag at the specified index within the MakerNote.
const char * exif_mnote_data_get_description(ExifMnoteData *d, unsigned int n)
Returns verbose textual description of the given MakerNote tag.
const char * exif_mnote_data_get_title(ExifMnoteData *d, unsigned int n)
Returns textual title of the given MakerNote tag.
void exif_mnote_data_log(ExifMnoteData *d, ExifLog *log)
unsigned int exif_mnote_data_count(ExifMnoteData *d)
Return the number of tags in the MakerNote.
void exif_mnote_data_unref(ExifMnoteData *d)
Handling EXIF MakerNote tags.
@ EXIF_TAG_COMPRESSION
Definition: exif-tag.h:41
@ EXIF_TAG_X_RESOLUTION
Definition: exif-tag.h:53
Represents the entire EXIF data found in an image.
Definition: exif-data.h:47
ExifContent * ifd[EXIF_IFD_COUNT]
Data for each IFD.
Definition: exif-data.h:49
Data found in one EXIF tag.
Definition: exif-entry.h:43
static void log_null_test(void)
Definition: test-null.c:306
static void mnote_null_test(void)
Definition: test-null.c:276
static void data_null_test(void)
Definition: test-null.c:93
int main(void)
Definition: test-null.c:340
static void content_null_test(void)
Definition: test-null.c:170
static void loader_null_test(void)
Definition: test-null.c:31
static void entry_null_test(void)
Definition: test-null.c:221

libexif Generated by doxygen