1548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen/* test-sorted.c
2548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen *
3548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * This test ensures that the ExifTagTable[] array is stored in sorted
4548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * order. If that were not so, then it a binary search of the array would
5548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * not give correct results.
6548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen *
7548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * Copyright 2009 Dan Fandrich <dan@coneharvesters.com>
8548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen *
9548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * This library is free software; you can redistribute it and/or
10548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * modify it under the terms of the GNU Lesser General Public
11548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * License as published by the Free Software Foundation; either
12548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * version 2 of the License, or (at your option) any later version.
13548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen *
14548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * This library is distributed in the hope that it will be useful,
15548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * but WITHOUT ANY WARRANTY; without even the implied warranty of
16548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * Lesser General Public License for more details.
18548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen *
19548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * You should have received a copy of the GNU Lesser General Public
20548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * License along with this library; if not, write to the
21548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen * Boston, MA  02110-1301  USA
23548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen */
24548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen
25548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen#include <libexif/exif-tag.h>
26548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen#include <stdio.h>
27548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen
28548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissenint
29548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissenmain (void)
30548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen{
31548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	int rc = 0;
32548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	unsigned int i, num;
33548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	ExifTag last = 0, current;
34548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	num = exif_tag_table_count() - 1; /* last entry is a NULL terminator */
35548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	for (i=0; i < num; ++i) {
36548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		current = exif_tag_table_get_tag(i);
37548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		if (current < last) {
38548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen			printf("Tag 0x%04x in ExifTagTable[] is out of order\n",
39548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen				current);
40548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen			rc = 1;
41548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		}
42548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		if (exif_tag_table_get_name(i) == NULL) {
43548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen			printf("Tag 0x%04x has a NULL name\n", current);
44548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen			rc = 1;
45548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		}
46548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen		last = current;
47548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	}
48548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen
49548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen	return rc;
50548dde4863e9a2315e3f327efe63ff55949addb8Marco Nelissen}
51