• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* test-sorted.c
2  *
3  * This test ensures that the ExifTagTable[] array is stored in sorted
4  * order. If that were not so, then it a binary search of the array would
5  * not give correct results.
6  *
7  * Copyright 2009-2022 Dan Fandrich <dan@coneharvesters.com>
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  * SPDX-License-Identifier: LGPL-2.0-or-later
25  */
26 
27 #include <libexif/exif-tag.h>
28 #include <stdio.h>
29 #include <string.h>
30 
31 int
main(void)32 main (void)
33 {
34 	int rc = 0;
35 	unsigned int i, num;
36 	ExifTag last = 0, current;
37 	const char *name;
38 	num = exif_tag_table_count() - 1; /* last entry is a NULL terminator */
39 	for (i=0; i < num; ++i) {
40 		current = exif_tag_table_get_tag(i);
41 		if (current < last) {
42 			printf("Tag 0x%04x in ExifTagTable[] is out of order\n",
43 				current);
44 			rc = 1;
45 		}
46 		name = exif_tag_table_get_name(i);
47 		/* Ensure each tag has a name */
48 		if (name == NULL) {
49 			printf("Tag 0x%04x has a NULL name\n", current);
50 			rc = 1;
51 		}
52 		/* Ensure each tag's name contains only valid characters */
53 		if (strspn(name, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/") != strlen(name)) {
54 			printf("Tag 0x%04x has an invalid name: %s\n", current, name);
55 			rc = 1;
56 		}
57 		last = current;
58 	}
59 
60 	return rc;
61 }
62