Added a thumbnail to test-mem.c to ensure it's properly freed.
[platform/upstream/libexif.git] / test / test-mem.c
1 /* test-mem.c
2  *
3  * Copyright (c) 2002 Lutz Mueller <lutz@users.sourceforge.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, 
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details. 
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA.
19  */
20
21 #include <config.h>
22
23 #include <libexif/exif-data.h>
24 #include <libexif/exif-ifd.h>
25 #include <libexif/exif-loader.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 int
31 main ()
32 {
33         ExifData *ed;
34         /* ExifEntry *e; */
35         unsigned char *eb, size[2];
36         unsigned int ebs;
37         ExifLoader *loader;
38         unsigned int i;
39
40         printf ("Creating EXIF data...\n");
41         ed = exif_data_new ();
42         exif_data_set_data_type (ed, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY);
43
44         printf ("Fill EXIF data with all necessary entries to follow specs...\n");
45         exif_data_fix (ed);
46
47         /* Add a dummy thumbnail */
48         ed->size = 4;
49         ed->data = calloc(1, ed->size);
50
51         exif_data_dump (ed);
52
53         printf ("Saving EXIF data to memory...\n");
54         exif_data_save_data (ed, &eb, &ebs);
55         exif_data_unref (ed);
56
57         printf ("Writing %i byte(s) EXIF data to loader...\n", ebs);
58         loader = exif_loader_new ();
59         size[0] = (unsigned char) ebs;
60         size[1] = (unsigned char) (ebs >> 8);
61         exif_loader_write (loader, size, 2);
62         for (i = 0; i < ebs && exif_loader_write (loader, eb + i, 1); i++);
63         printf ("Wrote %i byte(s).\n", i);
64         free (eb);
65         ed = exif_loader_get_data (loader);
66         exif_loader_unref (loader);
67         exif_data_dump (ed);
68         exif_data_unref (ed);
69
70         return 0;
71 }