]> granicus.if.org Git - file/commitdiff
Add the beginnings of a test suite, based on test.c.
authorReuben Thomas <rrt@sc3d.org>
Sun, 24 Feb 2008 00:55:49 +0000 (00:55 +0000)
committerReuben Thomas <rrt@sc3d.org>
Sun, 24 Feb 2008 00:55:49 +0000 (00:55 +0000)
Makefile.am
configure.ac
tests/.cvsignore [new file with mode: 0644]
tests/Makefile.am [new file with mode: 0644]
tests/gedcom.magic [new file with mode: 0644]
tests/gedcom.result [new file with mode: 0644]
tests/gedcom.testfile [new file with mode: 0644]
tests/test.c [moved from src/test.c with 69% similarity]

index f003f4b5ce5adc2c22df54f4b257b776e9cb79d6..0300b9f47f4b69cb6bc06d77a1761cd997c19332 100644 (file)
@@ -1,3 +1,3 @@
 EXTRA_DIST = MAINT
 
-SUBDIRS = src magic doc python
+SUBDIRS = src magic tests doc python
index 8ad8dc3e08e6c7cd84e79a8f3259c94ab235d342..84d998b658afb22c8ff15b86e0c17ccb7c4d6923 100644 (file)
@@ -118,5 +118,5 @@ AC_CHECK_LIB(z,gzopen)
 dnl See if we are cross-compiling\r
 AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes)\r
 \r
-AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile doc/Makefile python/Makefile])\r
+AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile])\r
 AC_OUTPUT\r
diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644 (file)
index 0000000..0c9ae99
--- /dev/null
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile.in
+Makefile
+test
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..3880de8
--- /dev/null
@@ -0,0 +1,12 @@
+# FIXME: Actually run a test on a magic file
+check_PROGRAMS = test
+test_LDADD = $(top_builddir)/src/libmagic.la
+
+check-local:
+       MAGIC=$(top_builddir)/magic/magic ./test
+       for i in $(TEST_BASES); do MAGIC=./$$i.magic ./test ./$$i.testfile ./$$i.result; done
+
+TEST_BASES = gedcom
+
+EXTRA_DIST = \
+       gedcom.magic gedcom.testfile gedcom.result
diff --git a/tests/gedcom.magic b/tests/gedcom.magic
new file mode 100644 (file)
index 0000000..4cfcde9
--- /dev/null
@@ -0,0 +1,6 @@
+# GEDCOM Geneaolgy file
+
+0       string/c        0\ HEAD         GEDCOM genealogy data
+>&0     search          1\ GEDC
+>>&0    search          2\ VERS         version
+>>>&1   string          >\0             %s
diff --git a/tests/gedcom.result b/tests/gedcom.result
new file mode 100644 (file)
index 0000000..e121a4e
--- /dev/null
@@ -0,0 +1 @@
+GEDCOM genealogy data version  5.5
\ No newline at end of file
diff --git a/tests/gedcom.testfile b/tests/gedcom.testfile
new file mode 100644 (file)
index 0000000..3d9607e
--- /dev/null
@@ -0,0 +1,8 @@
+0 HEAD
+1 SOUR GENJ
+2 VERS 2.x
+1 GEDC
+2 VERS 5.5
+2 FORM Lineage-Linked
+1 CHAR UNICODE
+1 LANG Italian
similarity index 69%
rename from src/test.c
rename to tests/test.c
index 94e483bfc22a97ccaed209bee059128ff78ca053..1786bbc0d9ae5c9b8ec499e485eb2c3ce70c3b73 100644 (file)
 int
 main(int argc, char **argv)
 {
-    struct magic_set *ms;
-    const char *m;
-    int i;
+       struct magic_set *ms;
+       const char *m;
+       int i;
 
-    ms = magic_open(MAGIC_NONE);
-    if (ms == NULL) {
-       (void) printf("ERROR opening MAGIC_NONE: out of memory\n");
-       return 1;
-    }
-    if (magic_load(ms, NULL) == -1) {
-       (void) printf("ERROR loading with NULL file: %s\n", magic_error(ms));
-       return 2;
-    }
+       ms = magic_open(MAGIC_NONE);
+       if (ms == NULL) {
+               fprintf(stderr, "ERROR opening MAGIC_NONE: out of memory\n");
+               return 1;
+       }
+       if (magic_load(ms, NULL) == -1) {
+               fprintf(stderr, "ERROR loading with NULL file: %s\n", magic_error(ms));
+               return 2;
+       }
 
-    for (i = 1; i < argc; i++) {
-        if ((m = magic_file(ms, argv[i])) == NULL) {
-            (void) printf("ERROR loading file %s: %s\n", argv[i], magic_error(ms));
-            return 3;
-        }      else
-            (void) printf("%s: %s\n", argv[i], m);
-    }
+       if (argc > 1) {
+               if (argc != 3) {
+                       fprintf(stderr, "Usage: test TEST-FILE RESULT\n");
+               } else {
+                       if ((m = magic_file(ms, argv[1])) == NULL) {
+                               fprintf(stderr, "ERROR loading file %s: %s\n", argv[1], magic_error(ms));
+                               return 3;
+                       } else {
+                               printf("%s: %s\n", argv[1], m);
+                                       /* Compare m with contents of argv[3] */
+                       }
+               }
+       }
 
-    magic_close(ms);
-    return 0;
+       magic_close(ms);
+       return 0;
 }