Fix an unused variable warning.
[platform/upstream/libexif.git] / test / test-fuzzer.c
1 /**file test-fuzzer.c
2  * from test-parse.c and test-mnote.c
3  *
4  * \brief Completely parse all files given on the command line.
5  *
6  * Copyright (C) 2007 Hans Ulrich Niedermann <gp@n-dimensional.de>
7  * Copyright 2002 Lutz Mueller <lutz@users.sourceforge.net>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, 
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details. 
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA  02110-1301  USA.
23  *
24  */
25
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "libexif/exif-data.h"
31 #include "libexif/exif-system.h"
32
33 /** Callback function handling an ExifEntry. */
34 void content_foreach_func(ExifEntry *entry, void *callback_data);
35 void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
36 {
37         char buf[2001];
38
39         /* ensure \0 */
40         buf[sizeof(buf)-1] = 0;
41         buf[sizeof(buf)-2] = 0;
42         exif_tag_get_name(entry->tag);
43         exif_format_get_name(entry->format);
44         exif_entry_get_value(entry, buf, sizeof(buf)-1);
45         if (buf[sizeof(buf)-2] != 0) abort();
46 }
47
48
49 /** Callback function handling an ExifContent (corresponds 1:1 to an IFD). */
50 void data_foreach_func(ExifContent *content, void *callback_data);
51 void data_foreach_func(ExifContent *content, void *callback_data)
52 {
53         printf("  Content %p: ifd=%d\n", content, exif_content_get_ifd(content));
54         exif_content_foreach_entry(content, content_foreach_func, callback_data);
55 }
56 static int
57 test_exif_data (ExifData *d)
58 {
59         unsigned int i, c;
60         char v[1024];
61         ExifMnoteData *md;
62
63         fprintf (stdout, "Byte order: %s\n",
64                 exif_byte_order_get_name (exif_data_get_byte_order (d)));
65
66         md = exif_data_get_mnote_data (d);
67         if (!md) {
68                 fprintf (stderr, "Could not parse maker note!\n");
69                 return 1;
70         }
71
72         exif_mnote_data_ref (md);
73         exif_mnote_data_unref (md);
74
75         c = exif_mnote_data_count (md);
76         for (i = 0; i < c; i++) {
77                 const char *name = exif_mnote_data_get_name (md, i);
78                 if (!name) break;
79                 exif_mnote_data_get_name (md, i);
80                 exif_mnote_data_get_title (md, i);
81                 exif_mnote_data_get_description (md, i);
82                 exif_mnote_data_get_value (md, i, v, sizeof (v));
83         }
84
85         return 0;
86 }
87
88
89
90 /** Run EXIF parsing test on the given file. */
91 static void test_parse(const char *filename, void *callback_data)
92 {
93         ExifData *d;
94         unsigned int buf_size;
95         unsigned char *buf;
96
97         d = exif_data_new_from_file(filename);
98         exif_data_foreach_content(d, data_foreach_func, callback_data);
99         test_exif_data (d);
100
101         buf = NULL;
102         exif_data_save_data (d, &buf, &buf_size);
103         free (buf);
104
105         exif_data_set_byte_order(d, EXIF_BYTE_ORDER_INTEL);
106
107         buf = NULL;
108         exif_data_save_data (d, &buf, &buf_size);
109         free (buf);
110
111
112         exif_data_unref(d);
113 }
114
115
116 /** Main program. */
117 int main(const int argc, const char *argv[])
118 {
119         int i;
120         void *callback_data = NULL;
121
122         for (i=1; i<argc; i++) {
123                 test_parse(argv[i], callback_data);
124         }
125         return 0;
126 }