New test (for textdomain corruption).
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 3 Nov 2002 13:18:56 +0000 (13:18 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 3 Nov 2002 13:18:56 +0000 (13:18 +0000)
t/intl.test [new file with mode: 0755]
t/output/intl.ref [new file with mode: 0644]
t/src/test_intl [new file with mode: 0755]
t/src/testintl.c [new file with mode: 0644]

diff --git a/t/intl.test b/t/intl.test
new file mode 100755 (executable)
index 0000000..1f6ce7d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+$srcdir/src/test_intl intl 0
diff --git a/t/output/intl.ref b/t/output/intl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -0,0 +1 @@
+Test succeeded
diff --git a/t/src/test_intl b/t/src/test_intl
new file mode 100755 (executable)
index 0000000..6706ad9
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/sh
+# $Id$
+# $Name$
+
+options="-q"
+extra_options=
+
+while [ $# -gt 0 ]
+do
+  case "$1" in
+    -*) extra_options="$extra_options $1";;
+    *)  break;;
+  esac
+  shift
+done
+
+test_name=$1
+expected_result=$2
+if [ -z "$test_name" ]
+then
+  test_name=check
+fi
+if [ -z "$expected_result" ]
+then
+  expected_result=0
+fi
+
+# For use outside Makefile
+if [ -z "$srcdir" ]
+then
+  srcdir=.
+  options=$extra_options
+else
+  options="$options $extra_options"
+fi
+
+outfile=$test_name.out
+logfile=check.out
+reffile=$srcdir/output/$test_name.ref
+options="$options -o $outfile"
+
+builddir=`pwd`
+ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la"
+GCONV_PATH=.:$GCONV_PATH
+export GCONV_PATH
+ln -s $srcdir/../data/gedcom.enc .
+ln -s $builddir/../data/new.ged .
+ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so .
+ln -s $srcdir/../iconv/glibc/gconv-modules .
+rm -f core
+echo "======================================================">> $logfile
+echo "Performing test '$test_name'" >> $logfile
+$ltcmd $GEDCOM_TESTENV $builddir/src/testintl $options
+result=$?
+rm gedcom.enc
+rm new.ged
+rm ANSI_Z39.47.so
+rm gconv-modules
+
+echo "Result is $result (expected: $expected_result)" >> $logfile
+if [ "$result" -ne "$expected_result" ]
+then
+  echo "Not the expected return value!" >> $logfile
+  exit 1
+else
+  if [ -r core ]
+  then
+    echo "Core file generated!" >> $logfile
+    exit 1
+  else
+    if diff $outfile $reffile >/dev/null 2>>$logfile
+    then
+      echo "Output agrees with reference output" >> $logfile
+      rm $outfile
+      exit 0
+    else
+      echo "Differences with reference output detected!" >> $logfile
+      exit 1
+    fi
+  fi
+fi
diff --git a/t/src/testintl.c b/t/src/testintl.c
new file mode 100644 (file)
index 0000000..95a324c
--- /dev/null
@@ -0,0 +1,110 @@
+/* Test program for the Gedcom library.
+   Copyright (C) 2001, 2002 The Genes Development Team
+   This file is part of the Gedcom parser library.
+   Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
+
+   The Gedcom parser 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.1 of the License, or (at your option) any later version.
+
+   The Gedcom parser 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 the Gedcom parser library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* $Id$ */
+/* $Name$ */
+
+#include "gedcom.h"
+#include <locale.h>
+#include <stdio.h>
+
+#define MYTEXTDOMAIN "TESTINTL"
+
+void gedcom_message_handler(Gedcom_msg_type type, char *msg)
+{
+  if (type == MESSAGE)
+    output(1, "MESSAGE: ");
+  else if (type == WARNING)
+    output(1, "WARNING: ");
+  else if (type == ERROR)
+    output(1, "ERROR: ");
+  output(1, "%s\n", msg);
+}
+
+void show_help ()
+{
+  printf("gedcom-parse test program for libgedcom\n\n");
+  printf("Usage:  testintl [options]\n");
+  printf("Options:\n");
+  printf("  -h    Show this help text\n");
+  printf("  -q    No output to standard output\n");
+  printf("  -o <outfile>  File to generate output to (def. testgedcom.out)\n");
+}
+
+int main(int argc, char* argv[])
+{
+  int result;
+  char* outfilename = NULL;
+  
+  if (argc > 1) {
+    int i;
+    for (i=1; i<argc; i++) {
+      if (!strncmp(argv[i], "-h", 3)) {
+       show_help();
+       exit(1);
+      }
+      else if (!strncmp(argv[i], "-q", 3)) {
+       output_set_quiet(1);
+      }
+      else if (!strncmp(argv[i], "-o", 3)) {
+       i++;
+       if (i < argc) {
+         outfilename = argv[i];
+       }
+       else {
+         printf ("Missing output file name\n");
+         show_help();
+         exit(1);
+       }
+      }
+      else {
+       printf ("Unrecognized option: %s\n", argv[i]);
+       show_help();
+       exit(1);
+      }
+    }
+  }
+  
+  gedcom_init();
+  setlocale(LC_ALL, "");
+  textdomain(MYTEXTDOMAIN);
+  gedcom_set_message_handler(gedcom_message_handler);
+
+  output_open(outfilename);
+  
+  result = gedcom_new_model();
+  if (result == 0) {
+    char* textdom = textdomain(NULL);
+    if (strcmp(textdom, MYTEXTDOMAIN)) {
+      output(1, "Text domain is %s, should be %s\n", textdom, MYTEXTDOMAIN);
+      result = 1;
+    }
+  }
+    
+  if (result == 0) {
+    output(1, "Test succeeded\n");
+  }
+  else {
+    output(1, "Test failed: %d\n", result);
+  }
+
+  output_close();
+  return result;
+}