test-mnote.c

Go to the documentation of this file.
00001 /* exif-mnote.c
00002  *
00003  * Copyright 2002 Lutz M\uffffller <lutz@users.sourceforge.net>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA  02110-1301  USA.
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 
00026 #include <libexif/exif-data.h>
00027 
00028 static int
00029 test_exif_data (ExifData *d)
00030 {
00031         unsigned int i, c;
00032         char v[1024], *p;
00033         ExifMnoteData *md;
00034 
00035         fprintf (stdout, "Byte order: %s\n",
00036                 exif_byte_order_get_name (exif_data_get_byte_order (d)));
00037 
00038         fprintf (stdout, "Parsing maker note...\n");
00039         md = exif_data_get_mnote_data (d);
00040         if (!md) {
00041                 fprintf (stderr, "Could not parse maker note!\n");
00042                 exif_data_unref (d);
00043                 return 1;
00044         }
00045 
00046         fprintf (stdout, "Increasing ref-count...\n");
00047         exif_mnote_data_ref (md);
00048 
00049         fprintf (stdout, "Decreasing ref-count...\n");
00050         exif_mnote_data_unref (md);
00051 
00052         fprintf (stdout, "Counting entries...\n");
00053         c = exif_mnote_data_count (md);
00054         fprintf (stdout, "Found %i entries.\n", c);
00055         for (i = 0; i < c; i++) {
00056                 fprintf (stdout, "Dumping entry number %i...\n", i);
00057                 fprintf (stdout, "  Name: '%s'\n",
00058                                 exif_mnote_data_get_name (md, i));
00059                 fprintf (stdout, "  Title: '%s'\n",
00060                                 exif_mnote_data_get_title (md, i));
00061                 fprintf (stdout, "  Description: '%s'\n",
00062                                 exif_mnote_data_get_description (md, i));
00063                 p = exif_mnote_data_get_value (md, i, v, sizeof (v));
00064                 if (p) { fprintf (stdout, "  Value: '%s'\n", v); }
00065         }
00066 
00067         return 0;
00068 }
00069 
00070 int
00071 main (int argc, char **argv)
00072 {
00073         ExifData *d;
00074         unsigned int buf_size;
00075         unsigned char *buf;
00076         int r;
00077 
00078         if (argc <= 1) {
00079                 fprintf (stderr, "You need to supply a filename!\n");
00080                 return 1;
00081         }
00082 
00083         fprintf (stdout, "Loading '%s'...\n", argv[1]);
00084         d = exif_data_new_from_file (argv[1]);
00085         if (!d) {
00086                 fprintf (stderr, "Could not load data from '%s'!\n", argv[1]);
00087                 return 1;
00088         }
00089         fprintf (stdout, "Loaded '%s'.\n", argv[1]);
00090 
00091         fprintf (stdout, "######### Test 1 #########\n");
00092         r = test_exif_data (d);
00093         if (r) return r;
00094 
00095         exif_data_save_data (d, &buf, &buf_size);
00096         exif_data_unref (d);
00097         d = exif_data_new_from_data (buf, buf_size);
00098         free (buf);
00099 
00100         fprintf (stdout, "######### Test 2 #########\n");
00101         r = test_exif_data (d);
00102         if (r) return r;
00103 
00104         fprintf (stdout, "Test successful!\n");
00105 
00106         return 1;
00107 }

SourceForge.net Logo Generated by doxygen