From: Hans U. N. <hu...@us...> - 2007-06-29 11:37:42
|
Update of /cvsroot/libexif/libexif/test In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10878 Modified Files: Makefile.am test-integers.c Added Files: test-parse.c Log Message: new test/example: parse file and dump contents Index: Makefile.am =================================================================== RCS file: /cvsroot/libexif/libexif/test/Makefile.am,v retrieving revision 1.20 retrieving revision 1.21 diff -u -p -d -r1.20 -r1.21 --- Makefile.am 12 Jun 2007 13:51:59 -0000 1.20 +++ Makefile.am 29 Jun 2007 11:37:36 -0000 1.21 @@ -10,12 +10,17 @@ SUBDIRS = nls # And this is just the lib - we don't have the program available # here yet. -TESTS = test-mem test-value test-integers +TESTS = test-mem test-value test-integers test-parse -check_PROGRAMS = test-mem test-mnote test-value test-integers +TEST_IMAGES = $(top_srcdir)/daniel-andrews-sample.jpg +export TEST_IMAGES + +check_PROGRAMS = test-mem test-mnote test-value test-integers test-parse test_mem_LDADD = $(top_builddir)/libexif/libexif.la $(LTLIBINTL) test_mnote_LDADD = $(top_builddir)/libexif/libexif.la $(LTLIBINTL) test_value_LDADD = $(top_builddir)/libexif/libexif.la $(LTLIBINTL) + +test_parse_LDADD = $(top_builddir)/libexif/libexif.la $(LTLIBINTL) Index: test-integers.c =================================================================== RCS file: /cvsroot/libexif/libexif/test/test-integers.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -d -r1.1 -r1.2 --- test-integers.c 12 Jun 2007 13:51:58 -0000 1.1 +++ test-integers.c 29 Jun 2007 11:37:36 -0000 1.2 @@ -1,10 +1,64 @@ +/** \file test-integers.c + * \brief Check assumptions about integer types (sizes, ranges). + * + * Copyright (C) 2007 Hans Ulrich Niedermann <gp...@n-...> + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + #include "libexif/_stdint.h" +#include <stdlib.h> +#include <stdio.h> + + +typedef enum { + EN_A, + EN_B, + EN_C, + EN_D, + EN_E, + EN_F +} enum_t; + + +#if defined(__GNUC__) && (__GNUC__ >= 4) +# define CHECK(condition) \ + if (!(condition)) { \ + fprintf(stderr, "%s:%d: check failed: %s\n", \ + __FILE__, __LINE__, #condition); \ + errors++; \ + } +#else +# define CHECK(condition) \ + if (!(condition)) { \ + abort(); \ + } +#endif + int main() { - /* libexif assumes that in very many places */ - if (sizeof(unsigned int) < sizeof(uint32_t)) { - return 1; - } - return 0; + unsigned int errors = 0; + + /* libexif assumes unsigned ints are not smaller than 32bit in many places */ + CHECK(sizeof(unsigned int) >= sizeof(uint32_t)); + + /* libexif assumes that enums fit into ints */ + CHECK(sizeof(enum_t) <= sizeof(int)); + + return (errors>0)?1:0; } --- NEW FILE: test-parse.c --- /** \file test-parse.c * \brief Completely parse all files given on the command line. * * Copyright (C) 2007 Hans Ulrich Niedermann <gp...@n-...> * * 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., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "libexif/exif-data.h" #include "libexif/exif-system.h" #include <string.h> #include <stdio.h> #include <stdlib.h> void content_foreach_func(ExifEntry *entry, void *user_data); void content_foreach_func(ExifEntry *entry, void *UNUSED(user_data)) { char buf[2000]; exif_entry_get_value(entry, buf, sizeof(buf)); printf(" Entry %p: %s (%s)\n" " Size, Comps: %d, %d\n" " Value: %s\n", entry, exif_tag_get_name(entry->tag), exif_format_get_name(entry->format), entry->size, (int)(entry->components), exif_entry_get_value(entry, buf, sizeof(buf))); } void data_foreach_func(ExifContent *content, void *user_data); void data_foreach_func(ExifContent *content, void *user_data) { printf(" Content %p: ifd=%d\n", content, exif_content_get_ifd(content)); exif_content_foreach_entry(content, content_foreach_func, user_data); } void test_parse(const char *filename, void *data); void test_parse(const char *filename, void *data) { ExifData *d; printf("File %s\n", filename); d = exif_data_new_from_file(filename); exif_data_foreach_content(d, data_foreach_func, data); exif_data_unref(d); } typedef void (*test_parse_func) (const char *filename, void *data); /** Split string at whitespace and call callback with each substring */ void split_ws_string(const char *string, test_parse_func func, void *data); void split_ws_string(const char *string, test_parse_func func, void *data) { const char *start = string; const char *p = start; for (;;) { if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\0' ) { size_t len = p-start; if (len > 0) { /* emulate strndup */ char *str = malloc(1+len); if (str) { memcpy(str, start, len); str[len] = '\0'; func(str, data); free(str); start = p+1; } } else { start = p+1; } } if (*p == '\0') { break; } p++; } } int main(const int argc, const char *argv[]) { int i; void *data = NULL; const char *envar = getenv("TEST_IMAGES"); if (envar) { split_ws_string(envar, test_parse, data); } for (i=1; i<argc; i++) { test_parse(argv[i], data); } return 0; } |