From 63b6a314939f40a868b3589dcf47ae30cfac0395 Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sun, 22 Sep 2002 18:54:48 +0000 Subject: [PATCH] Test program for cross-reference updates. --- t/src/test_update | 51 ++++++++++++ t/src/update.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100755 t/src/test_update create mode 100644 t/src/update.c diff --git a/t/src/test_update b/t/src/test_update new file mode 100755 index 0000000..7393494 --- /dev/null +++ b/t/src/test_update @@ -0,0 +1,51 @@ +#!/bin/sh +# $Id$ +# $Name$ + +options="-q" +extra_options= + +while [ $# -gt 0 ] +do + case "$1" in + -*) extra_options="$extra_options $1";; + *) break;; + esac + shift +done + +expected_result=$1 +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 + +builddir=`pwd` +export GCONV_PATH=.:$GCONV_PATH +export LD_LIBRARY_PATH=$builddir/../gedcom/.libs:$LD_LIBRARY_PATH +ln -s $srcdir/../data/gedcom.enc . +ln -s $srcdir/../data/new.ged . +ln -s $builddir/../ansel/.libs/ANSI_Z39.47.so . +ln -s $srcdir/../ansel/gconv-modules . +rm -f core +$GEDCOM_TESTENV $builddir/src/updatetest $options +result=$? +rm gedcom.enc +rm new.ged +rm ANSI_Z39.47.so +rm gconv-modules +if [ "$result" -eq "$expected_result" -a ! -r core ] +then + exit 0 +else + exit 1 +fi diff --git a/t/src/update.c b/t/src/update.c new file mode 100644 index 0000000..bc2e0f6 --- /dev/null +++ b/t/src/update.c @@ -0,0 +1,193 @@ +/* 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 , 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 +#include + +#define OUTFILE "testgedcom.out" +FILE* outfile = NULL; +int quiet = 0; + +void output(int to_stdout_too, char* format, ...) +{ + va_list ap; + va_start(ap, format); + if (outfile) { + vfprintf(outfile, format, ap); + } + if (to_stdout_too && !quiet) { + vprintf(format, ap); + } + va_end(ap); +} + +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: updatetest [options] file\n"); + printf("Options:\n"); + printf(" -h Show this help text\n"); + printf(" -q No output to standard output\n"); +} + +int test_xref_functions() +{ + struct xref_value* xr; + int result; + + xr = gedcom_get_by_xref("@NOTHING_THERE@"); + if (xr != NULL) + return 10; + + xr = gedcom_add_xref(XREF_FAM, "NOT_AN_XREF", (Gedcom_ctxt)1); + if (xr != NULL) + return 11; + + xr = gedcom_add_xref(XREF_FAM, "@XREF@ BUT EXTRA", (Gedcom_ctxt)1); + if (xr != NULL) + return 12; + + xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)1); + if (xr == NULL) + return 13; + + xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)2); + if (xr != NULL) + return 14; + + xr = gedcom_get_by_xref("@NEWFAM@"); + if (xr == NULL) + return 15; + + if (xr->type != XREF_FAM) { + output(1, "Not the correct cross-reference type\n"); + return 16; + } + + if ((int)xr->object != 1) { + output(1, "Not the correct cross-reference object\n"); + return 17; + } + + xr = gedcom_link_xref(XREF_INDI, "@NEWFAM@"); + if (xr != NULL) + return 18; + + xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@"); + if (xr == NULL) + return 19; + + xr = gedcom_link_xref(XREF_FAM, "@NEWFAM"); + if (xr != NULL) + return 20; + + xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@"); + if (xr == NULL) + return 21; + + xr = gedcom_link_xref(XREF_INDI, "@OLDINDI@"); + if (xr != NULL) + return 22; + + result = gedcom_delete_xref("@NEWFAM@"); + if (result == 0) + return 23; + + xr = gedcom_unlink_xref(XREF_INDI, "@NEWFAM@"); + if (xr != NULL) + return 24; + + xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@"); + if (xr == NULL) + return 25; + + result = gedcom_delete_xref("@NEWFAM@"); + if (result == 0) + return 26; + + xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@"); + if (xr == NULL) + return 27; + + result = gedcom_delete_xref("@NEWFAM@"); + if (result != 0) + return 28; + + return 0; +} + +int main(int argc, char* argv[]) +{ + int result; + + if (argc > 1) { + int i; + for (i=1; i