File: test-mnote.c

package info (click to toggle)
libexif 0.6.25-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,664 kB
  • sloc: ansic: 13,214; cpp: 457; makefile: 395; sh: 206
file content (120 lines) | stat: -rw-r--r-- 2,950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* exif-mnote.c
 *
 * Copyright 2002 Lutz Mueller <lutz@users.sourceforge.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA.
 *
 * SPDX-License-Identifier: LGPL-2.0-or-later
 */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>

#include <libexif/exif-data.h>

static const char *strornull(const char *ptr) {
	if (!ptr)
		return "(none)";
	return ptr;
}

static int
test_exif_data (ExifData *d)
{
	unsigned int i, c;
	char v[1024], *p;
	ExifMnoteData *md;

	printf("Byte order: %s\n",
		exif_byte_order_get_name (exif_data_get_byte_order (d)));

	printf("Parsing maker note...\n");
	md = exif_data_get_mnote_data (d);
	if (!md) {
		fprintf (stderr, "Could not parse maker note!\n");
		exif_data_unref (d);
		return 1;
	}

	printf("Increasing ref-count...\n");
	exif_mnote_data_ref (md);

	printf("Decreasing ref-count...\n");
	exif_mnote_data_unref (md);

	printf("Counting entries...\n");
	c = exif_mnote_data_count (md);
	printf("Found %i entries.\n", c);
	for (i = 0; i < c; i++) {
		printf("Dumping entry number %i...\n", i);
		printf("  Name: '%s'\n",
				strornull(exif_mnote_data_get_name (md, i)));
		printf("  Title: '%s'\n",
				strornull(exif_mnote_data_get_title (md, i)));
		printf("  Description: '%s'\n",
				strornull(exif_mnote_data_get_description (md, i)));
		p = exif_mnote_data_get_value (md, i, v, sizeof (v));
		if (p) { printf("  Value: '%s'\n", v); }
	}

	return 0;
}

int
main (int argc, char **argv)
{
	ExifData *d;
	unsigned int buf_size;
	unsigned char *buf;
	int r;

	if (argc <= 1) {
		fprintf (stderr, "You need to supply a filename!\n");
		return 1;
	}

	printf("Loading '%s'...\n", argv[1]);
	d = exif_data_new_from_file (argv[1]);
	if (!d) {
		fprintf (stderr, "Could not load data from '%s'!\n", argv[1]);
		return 1;
	}
	printf("Loaded '%s'.\n", argv[1]);

	printf("######### Test 1 #########\n");
	r = test_exif_data (d);
	if (r) return r;

	exif_data_save_data (d, &buf, &buf_size);
	exif_data_unref (d);
	d = exif_data_new_from_data (buf, buf_size);
	free (buf);
	if (!d) {
		fprintf (stderr, "Could not load data from buf!\n");
		return 1;
	}

	printf ("######### Test 2 #########\n");
	r = test_exif_data (d);
	exif_data_unref (d);
	if (r) return r;

	printf ("Test successful!\n");

	return 0;
}