From: Peter Verthez Date: Sun, 22 Sep 2002 13:02:12 +0000 (+0000) Subject: Moved from parent directory to here. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=40b99549ec69cb65fc3b979c6383bed5b88af7f4;p=gedcom-parse.git Moved from parent directory to here. --- diff --git a/t/src/Makefile.am b/t/src/Makefile.am new file mode 100644 index 0000000..53029b3 --- /dev/null +++ b/t/src/Makefile.am @@ -0,0 +1,31 @@ +## Process this file with automake to produce Makefile.in +# $Id$ +# $Name$ + +INCLUDES = -DPKGDATADIR=\"$(pkgdatadir)\" -I $(srcdir)/../../include \ + -I $(srcdir)/../../utf8 +CFLAGS = -g -O2 + +noinst_PROGRAMS = testgedcom pathtest gomtest updatetest @EXTRA_PROGS@ +EXTRA_PROGRAMS = gomtest_static + +testgedcom_SOURCES = standalone.c +testgedcom_LDFLAGS = -L ../../gedcom/.libs -lgedcom +testgedcom_LDADD = @INTLLIBS@ ../../utf8/libutf8.la + +pathtest_SOURCES = pathtest.c +pathtest_LDFLAGS = -L ../../gedcom/.libs -lgedcom + +gomtest_SOURCES = gomtest.c +gomtest_LDFLAGS = -L ../../gedcom/.libs -L ../../gom/.libs -lgedcom_gom -lgedcom + +gomtest_static_SOURCES = gomtest.c +gomtest_static_LDADD = ../../gedcom/.libs/libgedcom.a \ + ../../gom/.libs/libgedcom_gom.a + +updatetest_SOURCES = update.c +updatetest_LDFLAGS = -L ../../gedcom/.libs -lgedcom + +TEST_SCRIPT=test_script test_gom test_update + +EXTRA_DIST=$(TEST_SCRIPT) diff --git a/t/src/gomtest.c b/t/src/gomtest.c new file mode 100644 index 0000000..9076173 --- /dev/null +++ b/t/src/gomtest.c @@ -0,0 +1,926 @@ +/* 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 "gom.h" +#include +#include +#include +#include "gedcom.h" + +#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 show_help () +{ + printf("gedcom-parse test program for libgedcom and libgom\n\n"); + printf("Usage: gom_test [options] file\n"); + printf("Options:\n"); + printf(" -h Show this help text\n"); + printf(" -nc Disable compatibility mode\n"); + printf(" -fi Fail immediately on errors\n"); + printf(" -fd Deferred fail on errors, but parse completely\n"); + printf(" -fn No fail on errors\n"); + printf(" -dg Debug setting: only libgedcom debug messages\n"); + printf(" -da Debug setting: libgedcom + yacc debug messages\n"); + printf(" -q No output to standard output\n"); +} + +void gedcom_message_handler(Gedcom_msg_type type, char *msg) +{ + output(1, "%s\n", msg); +} + +char* make_prefix(int depth) +{ + char* prefix = (char*)calloc(depth+1, sizeof(char)); + memset(prefix, ' ', depth); + return prefix; +} + +void dump_xref(int st, int prefix_depth, struct xref_value* xr); + +void dump_user_data(int st, int prefix_depth, struct user_data* data) +{ + char* prefix = make_prefix(prefix_depth); + if (data) { + output(st, "\n"); + for (data; data; data = data->next) { + output(st, "%sData: \n", prefix); + output(st, "%s %d, %s, %s\n", prefix, data->level, data->tag, data->str_value); + output(st, "%s reference: ", prefix); + dump_xref(st, prefix_depth + 4, data->xref_value); + } + } + else { + output(st, "%p\n", data); + } + free(prefix); +} + +void dump_address(int st, int prefix_depth, struct address* addr) +{ + char* prefix = make_prefix(prefix_depth); + if (addr) { + output(st, "\n"); + output(st, "%sFull label: %s\n", prefix, addr->full_label); + output(st, "%sLine 1: %s\n", prefix, addr->line1); + output(st, "%sLine 2: %s\n", prefix, addr->line2); + output(st, "%sCity: %s\n", prefix, addr->city); + output(st, "%sState: %s\n", prefix, addr->state); + output(st, "%sPostal: %s\n", prefix, addr->postal); + output(st, "%sCountry: %s\n", prefix, addr->country); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, addr->extra); + } + else { + output(st, "%p\n", addr); + } + free(prefix); +} + +void dump_date(int st, int prefix_depth, struct date_value* dv) +{ + char* prefix = make_prefix(prefix_depth); + if (dv) { + output(st, "\n"); + output(st, "%stype: %d\n", prefix, dv->type); + output(st, "%sdate1:\n", prefix); + output(st, "%s calendar type: %d\n", prefix, dv->date1.cal); + output(st, "%s day: %s\n", prefix, dv->date1.day_str); + output(st, "%s month: %s\n", prefix, dv->date1.month_str); + output(st, "%s year: %s\n", prefix, dv->date1.year_str); + output(st, "%s date type: %d\n", prefix, dv->date1.type); + output(st, "%s sdn1: %ld\n", prefix, dv->date1.sdn1); + output(st, "%s sdn2: %ld\n", prefix, dv->date1.sdn2); + output(st, "%sdate2:\n", prefix); + output(st, "%s calendar type: %d\n", prefix, dv->date2.cal); + output(st, "%s day: %s\n", prefix, dv->date2.day_str); + output(st, "%s month: %s\n", prefix, dv->date2.month_str); + output(st, "%s year: %s\n", prefix, dv->date2.year_str); + output(st, "%s date type: %d\n", prefix, dv->date2.type); + output(st, "%s sdn1: %ld\n", prefix, dv->date2.sdn1); + output(st, "%s sdn2: %ld\n", prefix, dv->date2.sdn2); + output(st, "%sphrase: %s\n", prefix, dv->phrase); + } + else { + output(st, "%p\n", dv); + } + free(prefix); +} + +void dump_age(int st, int prefix_depth, struct age_value* age) +{ + char* prefix = make_prefix(prefix_depth); + if (age) { + output(st, "\n"); + output(st, "%stype: %d\n", prefix, age->type); + output(st, "%smodifier: %d\n", prefix, age->mod); + output(st, "%syears: %d\n", prefix, age->years); + output(st, "%smonths: %d\n", prefix, age->months); + output(st, "%sdays: %d\n", prefix, age->days); + output(st, "%sphrase: %s\n", prefix, age->phrase); + } + else { + output(st, "%p\n", age); + } + free(prefix); +} + +void dump_xref(int st, int prefix_depth, struct xref_value* xr) +{ + char* prefix = make_prefix(prefix_depth); + if (xr) { + output(st, "\n"); + output(st, "%stype: %d\n", prefix, xr->type); + output(st, "%sxref: %s\n", prefix, xr->string); + output(st, "%sobject: %p\n", prefix, xr->object); + } + else { + output(st, "%p\n", xr); + } + free(prefix); +} + +void dump_xref_list(int st, int prefix_depth, struct xref_list* xr) +{ + char* prefix = make_prefix(prefix_depth); + if (xr) { + output(st, "\n"); + for (xr; xr; xr = xr->next) { + output(st, "%sreference: ", prefix); + dump_xref(st, prefix_depth + 2, xr->xref); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, xr->extra); + } + } + else { + output(st, "%p\n", xr); + } + free(prefix); +} + +void dump_texts(int st, int prefix_depth, struct text* t) +{ + char* prefix = make_prefix(prefix_depth); + if (t) { + output(st, "\n"); + for (t; t; t = t->next) { + output(st, "%sText: %s\n", prefix, t->text); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, t->extra); + } + } + else { + output(st, "%p\n", t); + } + free(prefix); +} + +void dump_user_ref(int st, int prefix_depth, struct user_ref_number* ref) +{ + char* prefix = make_prefix(prefix_depth); + if (ref) { + output(st, "\n"); + for (ref; ref; ref = ref->next) { + output(st, "%sValue: %s\n", prefix, ref->value); + output(st, "%sType: %s\n", prefix, ref->type); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, ref->extra); + } + } + else { + output(st, "%p\n", ref); + } + free(prefix); +} + +void dump_citations(int st, int prefix_depth, struct source_citation* cit); + +void dump_note_sub(int st, int prefix_depth, struct note_sub* note) +{ + char* prefix = make_prefix(prefix_depth); + if (note) { + output(st, "\n"); + for (note; note; note = note->next) { + output(st, "%sNote: \n", prefix); + output(st, "%s text: %s\n", prefix, note->text); + output(st, "%s reference: ", prefix); + dump_xref(st, prefix_depth + 4, note->reference); + output(st, "%s citations: ", prefix); + dump_citations(st, prefix_depth + 4, note->citation); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, note->extra); + } + } + else { + output(st, "%p\n", note); + } + free(prefix); +} + +void dump_mm_links(int st, int prefix_depth, struct multimedia_link* link) +{ + char* prefix = make_prefix(prefix_depth); + if (link) { + output(st, "\n"); + for (link; link; link = link->next) { + output(st, "%slink: \n", prefix); + output(st, "%s reference: ", prefix); + dump_xref(st, prefix_depth + 4, link->reference); + output(st, "%s Form: %s\n", prefix, link->form); + output(st, "%s Title: %s\n", prefix, link->title); + output(st, "%s File: %s\n", prefix, link->file); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, link->note); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, link->extra); + } + } + else { + output(st, "%p\n", link); + } + free(prefix); +} + +void dump_citations(int st, int prefix_depth, struct source_citation* cit) +{ + char* prefix = make_prefix(prefix_depth); + if (cit) { + output(st, "\n"); + for (cit; cit; cit = cit->next) { + output(st, "%sCitation: \n", prefix); + output(st, "%s description: %s\n", prefix, cit->description); + output(st, "%s reference: ", prefix); + dump_xref(st, prefix_depth + 4, cit->reference); + output(st, "%s page: %s\n", prefix, cit->page); + output(st, "%s event: %s\n", prefix, cit->event); + output(st, "%s role: %s\n", prefix, cit->role); + output(st, "%s Date: ", prefix); + dump_date(st, prefix_depth + 4, cit->date); + output(st, "%s texts: ", prefix, prefix); + dump_texts(st, prefix_depth + 4, cit->text); + output(st, "%s quality: %s\n", prefix, cit->quality); + output(st, "%s multimedia links: ", prefix); + dump_mm_links(st, prefix_depth + 4, cit->mm_link); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, cit->note); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, cit->extra); + } + } + else { + output(st, "%p\n", cit); + } + free(prefix); +} + +void dump_lds(int st, int prefix_depth, struct lds_event* lds) +{ + char* prefix = make_prefix(prefix_depth); + if (lds) { + output(st, "\n"); + for (lds; lds; lds = lds->next) { + output(st, "%sDate status: %s\n", prefix, lds->date); + output(st, "%sDate: ", prefix); + dump_date(st, prefix_depth + 2, lds->date); + output(st, "%sTemple code: %s\n", prefix, lds->temple_code); + output(st, "%sPlace living ordinance: %s\n", prefix, + lds->place_living_ordinance); + output(st, "%scitations: ", prefix); + dump_citations(st, prefix_depth + 2, lds->citation); + output(st, "%snotes: ", prefix); + dump_note_sub(st, prefix_depth + 2, lds->note); + output(st, "%sfamily: ", prefix); + dump_xref(st, prefix_depth + 2, lds->family); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, lds->extra); + } + } + else { + output(st, "%p\n", lds); + } + free(prefix); +} + +void dump_change_date(int st, int prefix_depth, struct change_date* chan) +{ + char* prefix = make_prefix(prefix_depth); + if (chan) { + output(st, "\n"); + output(st, "%sDate: ", prefix); + dump_date(st, prefix_depth + 2, chan->date); + output(st, "%sTime: %s\n", prefix, chan->time); + output(st, "%snotes: ", prefix); + dump_note_sub(st, prefix_depth + 2, chan->note); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, chan->extra); + } + else { + output(st, "%p\n", chan); + } + free(prefix); +} + +void dump_personal_name(int st, int prefix_depth, struct personal_name* name) +{ + char* prefix = make_prefix(prefix_depth); + if (name) { + output(st, "\n"); + for (name; name; name = name->next) { + output(st, "%sName: \n", prefix); + output(st, "%s Name: %s\n", prefix, name->name); + output(st, "%s Prefix: %s\n", prefix, name->prefix); + output(st, "%s Given: %s\n", prefix, name->given); + output(st, "%s Nickname: %s\n", prefix, name->nickname); + output(st, "%s Surname prefix: %s\n", prefix, name->surname_prefix); + output(st, "%s Surname: %s\n", prefix, name->surname); + output(st, "%s Suffix: %s\n", prefix, name->suffix); + output(st, "%s citations: ", prefix); + dump_citations(st, prefix_depth + 4, name->citation); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, name->note); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, name->extra); + } + } + else { + output(st, "%p\n", name); + } + free(prefix); +} + +void dump_pedigree(int st, int prefix_depth, struct pedigree* p) +{ + char* prefix = make_prefix(prefix_depth); + if (p) { + output(st, "\n"); + for (p; p; p = p->next) { + output(st, "%sPedigree: %s\n", prefix, p->pedigree); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, p->extra); + } + } + else { + output(st, "%p\n", p); + } + free(prefix); +} + +void dump_family_link(int st, int prefix_depth, struct family_link *link) +{ + char* prefix = make_prefix(prefix_depth); + if (link) { + output(st, "\n"); + for (link; link; link = link->next) { + output(st, "%sFamily:\n", prefix); + output(st, "%s Family: ", prefix); + dump_xref(st, prefix_depth + 4, link->family); + output(st, "%s pedigrees: ", prefix); + dump_pedigree(st, prefix_depth + 4, link->pedigree); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, link->note); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, link->extra); + } + } + else { + output(st, "%p\n", link); + } + free(prefix); +} + +void dump_association(int st, int prefix_depth, struct association *assoc) +{ + char* prefix = make_prefix(prefix_depth); + if (assoc) { + output(st, "\n"); + for (assoc; assoc; assoc = assoc->next) { + output(st, "%sAssociation:\n", prefix); + output(st, "%s To:\n", prefix); + dump_xref(st, prefix_depth + 4, assoc->to); + output(st, "%s Type: %s\n", prefix, assoc->type); + output(st, "%s Relation: %s\n", assoc->relation); + output(st, "%s citations: ", prefix); + dump_citations(st, prefix_depth + 4, assoc->citation); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, assoc->note); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, assoc->extra); + } + } + else { + output(st, "%p\n", assoc); + } + free(prefix); +} + +void dump_place(int st, int prefix_depth, struct place* place) +{ + char* prefix = make_prefix(prefix_depth); + if (place) { + output(st, "\n"); + output(st, "%svalue: %s\n", prefix, place->value); + output(st, "%splace_hierarchy: %s\n", prefix, place->place_hierarchy); + output(st, "%scitations: ", prefix); + dump_citations(st, prefix_depth + 2, place->citation); + output(st, "%snotes: ", prefix); + dump_note_sub(st, prefix_depth + 2, place->note); + output(st, "%sUser data:", prefix); + dump_user_data(st, prefix_depth + 2, place->extra); + } + else { + output(st, "%p\n", place); + } + free(prefix); +} + +void dump_source_events(int st, int prefix_depth, struct source_event* evt) +{ + char* prefix = make_prefix(prefix_depth); + if (evt) { + output(st, "\n"); + for (evt; evt; evt = evt->next) { + output(st, "%sEvent:\n", prefix); + output(st, "%s Recorded events: %s\n", prefix, evt->recorded_events); + output(st, "%s Date period: ", prefix); + dump_date(st, prefix_depth + 4, evt->date_period); + output(st, "%s Jurisdiction: %s\n", prefix, evt->jurisdiction); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, evt->extra); + } + } + else { + output(st, "%p\n", evt); + } + free(prefix); +} + +void dump_source_descriptions(int st, int prefix_depth, + struct source_description* desc) +{ + char* prefix = make_prefix(prefix_depth); + if (desc) { + output(st, "\n"); + for (desc; desc; desc = desc->next) { + output(st, "%sSource description:\n", prefix); + output(st, "%s Call number: %s\n", prefix, desc->call_number); + output(st, "%s Media: %s\n", prefix, desc->media); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, desc->extra); + } + } + else { + output(st, "%p\n", desc); + } + free(prefix); +} + +void dump_events(int st, int prefix_depth, struct event *evt) +{ + char* prefix = make_prefix(prefix_depth); + if (evt) { + output(st, "\n"); + for (evt; evt; evt = evt->next) { + output(st, "%sEvent: %d (%s)\n", prefix, evt->event, evt->event_name); + output(st, "%s Value: %s\n", prefix, evt->val); + output(st, "%s Type: %s\n", prefix, evt->type); + output(st, "%s Date: ", prefix); + dump_date(st, prefix_depth + 4, evt->date); + output(st, "%s Place: ", prefix); + dump_place(st, prefix_depth + 4, evt->place); + output(st, "%s Address: ", prefix); + dump_address(st, prefix_depth + 4, evt->address); + output(st, "%s Phone 1: %s\n", prefix, evt->phone[0]); + output(st, "%s Phone 2: %s\n", prefix, evt->phone[1]); + output(st, "%s Phone 3: %s\n", prefix, evt->phone[2]); + output(st, "%s Age: ", prefix); + dump_age(st, prefix_depth + 4, evt->age); + output(st, "%s Agency: %s\n", prefix, evt->agency); + output(st, "%s Cause: %s\n", prefix, evt->cause); + output(st, "%s citations: ", prefix); + dump_citations(st, prefix_depth + 4, evt->citation); + output(st, "%s multimedia links: ", prefix); + dump_mm_links(st, prefix_depth + 4, evt->mm_link); + output(st, "%s notes: ", prefix); + dump_note_sub(st, prefix_depth + 4, evt->note); + output(st, "%s Age of husband: ", prefix); + dump_age(st, prefix_depth + 4, evt->husband_age); + output(st, "%s Age of wife: ", prefix); + dump_age(st, prefix_depth + 4, evt->wife_age); + output(st, "%s Family: ", prefix); + dump_xref(st, prefix_depth + 4, evt->family); + output(st, "%s Adoption parent: %s\n", prefix, evt->adoption_parent); + output(st, "%s User data:", prefix); + dump_user_data(st, prefix_depth + 4, evt->extra); + } + } + else { + output(st, "%p\n", evt); + } + free(prefix); +} + +void dump_header() +{ + struct header* header = gom_get_header(); + output(1, "=== HEADER ===\n"); + output(0, "Source:\n"); + output(0, " ID: %s\n", header->source.id); + output(0, " Name: %s\n", header->source.name); + output(0, " Version: %s\n", header->source.version); + output(0, " Corporation:\n"); + output(0, " Name: %s\n", header->source.corporation.name); + output(0, " Address: "); + dump_address(0, 6, header->source.corporation.address); + output(0, " Phone 1: %s\n", header->source.corporation.phone[0]); + output(0, " Phone 2: %s\n", header->source.corporation.phone[1]); + output(0, " Phone 3: %s\n", header->source.corporation.phone[2]); + output(0, " Data:\n"); + output(0, " Name: %s\n", header->source.data.name); + output(0, " Date: "); + dump_date(0, 6, header->source.data.date); + output(0, " Copyright: %s\n", header->source.data.copyright); + output(0, "Destination: %s\n", header->destination); + output(0, "Date: "); + dump_date(0, 2, header->date); + output(0, "Time: %s\n", header->time); + output(0, "Submitter: "); + dump_xref(0, 2, header->submitter); + output(0, "Submission: "); + dump_xref(0, 2, header->submission); + output(0, "File name: %s\n", header->filename); + output(0, "Copyright: %s\n", header->copyright); + output(0, "Gedcom:\n"); + output(0, " Version: %s\n", header->gedcom.version); + output(0, " Form: %s\n", header->gedcom.form); + output(0, "Character set:\n"); + output(0, " Name: %s\n", header->charset.name); + output(0, " Version: %s\n", header->charset.version); + output(0, "Language: %s\n", header->language); + output(0, "Place hierarchy: %s\n", header->place_hierarchy); + output(0, "Note:\n"); + output(0, "====\n"); + output(0, "%s\n", header->note); + output(0, "====\n"); + output(0, "User data:"); + dump_user_data(0, 2, header->extra); +} + +void dump_submission() +{ + struct submission* subn = gom_get_submission(); + if (subn) { + output(1, "=== SUBMISSION (%s) ===\n", subn->xrefstr); + output(0, "Submitter: "); + dump_xref(0, 2, subn->submitter); + output(0, "Family file: %s\n", subn->family_file); + output(0, "Temple code: %s\n", subn->temple_code); + output(0, "Nr of ancestor generations: %s\n", subn->nr_of_ancestor_gens); + output(0, "Nr of descendant generations: %s\n", + subn->nr_of_descendant_gens); + output(0, "Ordinance process flag: %s\n", subn->ordinance_process_flag); + output(0, "Record id: %s\n", subn->record_id); + output(0, "User data:"); + dump_user_data(0, 2, subn->extra); + } +} + +void dump_families() +{ + struct family* fam = gom_get_first_family(); + for (fam; fam; fam = fam->next) { + output(1, "=== FAMILY (%s) ===\n", fam->xrefstr); + output(0, "Family events: "); + dump_events(0, 2, fam->event); + output(0, "Husband: "); + dump_xref(0, 2, fam->husband); + output(0, "Wife: "); + dump_xref(0, 2, fam->wife); + output(0, "Children: "); + dump_xref_list(0, 2, fam->children); + output(0, "Number of children: %s\n", fam->nr_of_children); + output(0, "Submitters: "); + dump_xref_list(0, 2, fam->submitters); + output(0, "LDS spouse sealings: "); + dump_lds(0, 2, fam->lds_spouse_sealing); + output(0, "citations: "); + dump_citations(0, 2, fam->citation); + output(0, "multimedia links: "); + dump_mm_links(0, 2, fam->mm_link); + output(0, "notes: "); + dump_note_sub(0, 2, fam->note); + output(0, "user refs: "); + dump_user_ref(0, 2, fam->ref); + output(0, "Record ID: %s\n", fam->record_id); + output(0, "change date: "); + dump_change_date(0, 2, fam->change_date); + output(0, "User data:"); + dump_user_data(0, 2, fam->extra); + } +} + +void dump_individuals() +{ + struct individual* indiv = gom_get_first_individual(); + for (indiv; indiv; indiv = indiv->next) { + output(1, "=== INDIVIDUAL (%s) ===\n", indiv->xrefstr); + output(0, "Restriction notice: %s\n", indiv->restriction_notice); + output(0, "names: "); + dump_personal_name(0, 2, indiv->name); + output(0, "Sex: %s\n", indiv->sex); + output(0, "Individual events: "); + dump_events(0, 2, indiv->event); + output(0, "Individual attributes: "); + dump_events(0, 2, indiv->attribute); + output(0, "LDS individual ordinance: "); + dump_lds(0, 2, indiv->lds_individual_ordinance); + output(0, "Child to family links: "); + dump_family_link(0, 2, indiv->child_to_family); + output(0, "Spouse to family links: "); + dump_family_link(0, 2, indiv->spouse_to_family); + output(0, "Submitters: "); + dump_xref_list(0, 2, indiv->submitters); + output(0, "Associations: "); + dump_association(0, 2, indiv->association); + output(0, "Aliases: "); + dump_xref_list(0, 2, indiv->alias); + output(0, "Ancestor interest: "); + dump_xref_list(0, 2, indiv->ancestor_interest); + output(0, "Descendant interest: "); + dump_xref_list(0, 2, indiv->descendant_interest); + output(0, "citations: "); + dump_citations(0, 2, indiv->citation); + output(0, "multimedia links: "); + dump_mm_links(0, 2, indiv->mm_link); + output(0, "notes: "); + dump_note_sub(0, 2, indiv->note); + output(0, "Record file nr: %s\n", indiv->record_file_nr); + output(0, "Ancestral file nr: %s\n", indiv->ancestral_file_nr); + output(0, "user refs: "); + dump_user_ref(0, 2, indiv->ref); + output(0, "Record ID: %s\n", indiv->record_id); + output(0, "change date: "); + dump_change_date(0, 2, indiv->change_date); + output(0, "User data:"); + dump_user_data(0, 2, indiv->extra); + } +} + +void dump_multimedia() +{ + struct multimedia* obj = gom_get_first_multimedia(); + for (obj; obj; obj = obj->next) { + output(1, "=== MULTIMEDIA (%s) ===\n", obj->xrefstr); + output(0, "Form: %s\n", obj->form); + output(0, "Title: %s\n", obj->title); + output(0, "notes: "); + dump_note_sub(0, 2, obj->note); + output(0, "Data: %s\n", obj->data); + output(0, "Continued: "); + dump_xref(0, 2, obj->continued); + output(0, "user refs: "); + dump_user_ref(0, 2, obj->ref); + output(0, "Record ID: %s\n", obj->record_id); + output(0, "change date: "); + dump_change_date(0, 2, obj->change_date); + output(0, "User data:"); + dump_user_data(0, 2, obj->extra); + } +} + +void dump_notes() +{ + struct note* note = gom_get_first_note(); + for (note; note; note = note->next) { + output(1, "=== NOTE (%s) ===\n", note->xrefstr); + output(0, "Text: %s\n", note->text); + output(0, "citations: "); + dump_citations(0, 2, note->citation); + output(0, "user refs: "); + dump_user_ref(0, 2, note->ref); + output(0, "Record ID: %s\n", note->record_id); + output(0, "change date: "); + dump_change_date(0, 2, note->change_date); + output(0, "User data:"); + dump_user_data(0, 2, note->extra); + } +} + +void dump_repositories() +{ + struct repository* repo = gom_get_first_repository(); + for (repo; repo; repo = repo->next) { + output(1, "=== REPOSITORY (%s) ===\n", repo->xrefstr); + output(0, "Name: %s\n", repo->name); + output(0, "Address: "); + dump_address(0, 2, repo->address); + output(0, "Phone 1: %s\n", repo->phone[0]); + output(0, "Phone 2: %s\n", repo->phone[1]); + output(0, "Phone 3: %s\n", repo->phone[2]); + output(0, "notes: "); + dump_note_sub(0, 2, repo->note); + output(0, "user refs: "); + dump_user_ref(0, 2, repo->ref); + output(0, "Record ID: %s\n", repo->record_id); + output(0, "change date: "); + dump_change_date(0, 2, repo->change_date); + output(0, "User data:"); + dump_user_data(0, 2, repo->extra); + } +} + +void dump_sources() +{ + struct source* sour = gom_get_first_source(); + for (sour; sour; sour = sour->next) { + output(1, "=== SOURCE (%s) ===\n", sour->xrefstr); + output(0, "Data: \n"); + output(0, " events: "); + dump_source_events(0, 4, sour->data.event); + output(0, " Agency: %s\n", sour->data.agency); + output(0, " notes: "); + dump_note_sub(0, 4, sour->data.note); + output(0, "Author: %s\n", sour->author); + output(0, "Title: %s\n", sour->title); + output(0, "Abbreviation: %s\n", sour->abbreviation); + output(0, "Publication: %s\n", sour->publication); + output(0, "Text: %s\n", sour->text); + output(0, "Repository:\n"); + output(0, " Link: "); + dump_xref(0, 4, sour->repository.link); + output(0, " notes: "); + dump_note_sub(0, 4, sour->repository.note); + output(0, " source descriptions: "); + dump_source_descriptions(0, 4, sour->repository.description); + output(0, "multimedia links: "); + dump_mm_links(0, 2, sour->mm_link); + output(0, "notes: "); + dump_note_sub(0, 2, sour->note); + output(0, "user refs: "); + dump_user_ref(0, 2, sour->ref); + output(0, "Record ID: %s\n", sour->record_id); + output(0, "change date: "); + dump_change_date(0, 2, sour->change_date); + output(0, "User data:"); + dump_user_data(0, 2, sour->extra); + } +} + +void dump_submitters() +{ + struct submitter* subm = gom_get_first_submitter(); + for (subm; subm; subm = subm->next) { + output(1, "=== SUBMITTER (%s) ===\n", subm->xrefstr); + output(0, "Name: %s\n", subm->name); + output(0, "Address: "); + dump_address(0, 2, subm->address); + output(0, "Phone 1: %s\n", subm->phone[0]); + output(0, "Phone 2: %s\n", subm->phone[1]); + output(0, "Phone 3: %s\n", subm->phone[2]); + output(0, "multimedia links: "); + dump_mm_links(0, 2, subm->mm_link); + output(0, "Language 1: %s\n", subm->language[0]); + output(0, "Language 2: %s\n", subm->language[1]); + output(0, "Language 3: %s\n", subm->language[2]); + output(0, "Record file nr: %s\n", subm->record_file_nr); + output(0, "Record ID: %s\n", subm->record_id); + output(0, "change date: "); + dump_change_date(0, 2, subm->change_date); + output(0, "User data:"); + dump_user_data(0, 2, subm->extra); + } +} + +void dump_user_records() +{ + struct user_rec* rec = gom_get_first_user_rec(); + for (rec; rec; rec = rec->next) { + output(1, "=== USER RECORD (%s) ===\n", rec->xrefstr); + output(0, "Tag: %s\n", rec->tag); + output(0, "String value: %s\n", rec->str_value); + output(0, "Xref value: "); + dump_xref(0, 2, rec->xref_value); + output(0, "User data:"); + dump_user_data(0, 2, rec->extra); + } +} + +void show_data() +{ + dump_header(); + dump_submission(); + dump_families(); + dump_individuals(); + dump_multimedia(); + dump_notes(); + dump_repositories(); + dump_sources(); + dump_submitters(); + dump_user_records(); +} + +int main(int argc, char* argv[]) +{ + Gedcom_err_mech mech = IMMED_FAIL; + int compat_enabled = 1; + int debug_level = 0; + int result = 0; + char* file_name = NULL; + + if (argc > 1) { + int i; + for (i=1; i, 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 +#include +#include "gedcom.h" + +int check_gconv_path() +{ + char* path = getenv("GCONV_PATH"); + if (path == NULL || strstr(path, PKGDATADIR) == NULL) + return 1; + else + return 0; +} + +int main(int argc, char* argv[]) +{ + char* path; + /* This checks whether the constructor in encoding.c is doing its work + properly */ + gedcom_init(); + exit(check_gconv_path()); +} diff --git a/t/src/standalone.c b/t/src/standalone.c new file mode 100644 index 0000000..5efb081 --- /dev/null +++ b/t/src/standalone.c @@ -0,0 +1,324 @@ +/* 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 +#include +#include +#include +#include +#include +#include "utf8-locale.h" + +#define OUTFILE "testgedcom.out" +#define BOGUS_FILE_NAME "Makefile.am" +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 show_help () +{ + printf("gedcom-parse test program for libgedcom\n\n"); + printf("Usage: testgedcom [options] file\n"); + printf("Options:\n"); + printf(" -h Show this help text\n"); + printf(" -nc Disable compatibility mode\n"); + printf(" -fi Fail immediately on errors\n"); + printf(" -fd Deferred fail on errors, but parse completely\n"); + printf(" -fn No fail on errors\n"); + printf(" -dg Debug setting: only libgedcom debug messages\n"); + printf(" -da Debug setting: libgedcom + yacc debug messages\n"); + printf(" -2 Run the test parse 2 times instead of once\n"); + printf(" -3 Run the test parse 3 times instead of once\n"); + printf(" -b Parse a bogus file before parsing the main file\n"); + printf(" -q No output to standard output\n"); +} + +Gedcom_ctxt header_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, + char *raw_value, int tag_value, + Gedcom_val parsed_value) +{ + output(1, "Header start\n"); + return (Gedcom_ctxt)1; +} + +void header_end(Gedcom_rec rec, Gedcom_ctxt self) +{ + output(1, "Header end, context is %d\n", (int)self); +} + +char family_xreftags[100][255]; +int family_nr = 1; + +Gedcom_ctxt family_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, + char *raw_value, int tag_value, + Gedcom_val parsed_value) +{ + struct xref_value *xr = GEDCOM_XREF_PTR(xref); + output(1, "Family start, xref is %s\n", xr->string); + strcpy(family_xreftags[family_nr], xr->string); + xr->object = (Gedcom_ctxt)family_nr; + return (Gedcom_ctxt)(family_nr++); +} + +Gedcom_ctxt rec_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, + char *raw_value, int tag_value, + Gedcom_val parsed_value) +{ + char* xref_str = NULL; + if (! GEDCOM_IS_NULL(xref)) + xref_str = GEDCOM_XREF_PTR(xref)->string; + output(1, "Rec %s start, xref is %s\n", tag, xref_str); + return (Gedcom_ctxt)tag_value; +} + +Gedcom_ctxt note_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, + char *raw_value, int tag_value, + Gedcom_val parsed_value) +{ + output(1, "== %d %s (%d) %s (xref is %s)\n", + level, tag, tag_value, GEDCOM_STRING(parsed_value), + GEDCOM_XREF_PTR(xref)->string); + return (Gedcom_ctxt)tag_value; +} + +void family_end(Gedcom_rec rec, Gedcom_ctxt self) +{ + output(1, "Family end, xref is %s\n", family_xreftags[(int)self]); +} + +Gedcom_ctxt submit_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, + char *raw_value, int tag_value, + Gedcom_val parsed_value) +{ + output(1, "Submitter, xref is %s\n", GEDCOM_XREF_PTR(xref)->string); + return (Gedcom_ctxt)10000; +} + +Gedcom_ctxt source_start(Gedcom_elt elt, Gedcom_ctxt parent, int level, + char *tag, char* raw_value, + int tag_value, Gedcom_val parsed_value) +{ + Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000); + output(1, "Source is %s (ctxt is %d, parent is %d)\n", + GEDCOM_STRING(parsed_value), (int) self, (int) parent); + return self; +} + +void source_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self, + Gedcom_val parsed_value) +{ + output(1, "Source context %d in parent %d\n", (int)self, (int)parent); +} + +Gedcom_ctxt date_start(Gedcom_elt elt, Gedcom_ctxt parent, int level, + char *tag, char* raw_value, + int tag_value, Gedcom_val parsed_value) +{ + struct date_value dv; + Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000); + dv = GEDCOM_DATE(parsed_value); + output(1, "Contents of the date_value:\n"); + output(1, " raw value: %s\n", raw_value); + output(1, " type: %d\n", dv.type); + output(1, " date1:\n"); + output(1, " calendar type: %d\n", dv.date1.cal); + output(1, " day: %s\n", dv.date1.day_str); + output(1, " month: %s\n", dv.date1.month_str); + output(1, " year: %s\n", dv.date1.year_str); + output(1, " date type: %d\n", dv.date1.type); + output(1, " sdn1: %ld\n", dv.date1.sdn1); + output(1, " sdn2: %ld\n", dv.date1.sdn2); + output(1, " date2:\n"); + output(1, " calendar type: %d\n", dv.date2.cal); + output(1, " day: %s\n", dv.date2.day_str); + output(1, " month: %s\n", dv.date2.month_str); + output(1, " year: %s\n", dv.date2.year_str); + output(1, " date type: %d\n", dv.date2.type); + output(1, " sdn1: %ld\n", dv.date2.sdn1); + output(1, " sdn2: %ld\n", dv.date2.sdn2); + output(1, " phrase: %s\n", dv.phrase); + return self; +} + +Gedcom_ctxt age_start(Gedcom_elt elt, Gedcom_ctxt parent, int level, + char *tag, char *raw_value, + int tag_value, Gedcom_val parsed_value) +{ + struct age_value age; + Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000); + age = GEDCOM_AGE(parsed_value); + output(1, "Contents of the age_value:\n"); + output(1, " raw value: %s\n", raw_value); + output(1, " type: %d\n", age.type); + output(1, " modifier: %d\n", age.mod); + output(1, " years: %d\n", age.years); + output(1, " months: %d\n", age.months); + output(1, " days: %d\n", age.days); + output(1, " phrase: %s\n", age.phrase); + return self; +} + +void default_cb(Gedcom_elt elt, Gedcom_ctxt ctxt, int level, char *tag, + char *raw_value, int tag_value) +{ + char *converted = NULL; + int conv_fails = 0; + if (raw_value) + converted = convert_utf8_to_locale(raw_value, &conv_fails); + output(0, "== %d %s (%d) %s (ctxt is %d, conversion failures: %d)\n", + level, tag, tag_value, converted, (int)ctxt, conv_fails); +} + +void subscribe_callbacks() +{ + gedcom_subscribe_to_record(REC_HEAD, header_start, header_end); + gedcom_subscribe_to_record(REC_FAM, family_start, family_end); + gedcom_subscribe_to_record(REC_INDI, rec_start, NULL); + gedcom_subscribe_to_record(REC_OBJE, rec_start, NULL); + gedcom_subscribe_to_record(REC_NOTE, note_start, NULL); + gedcom_subscribe_to_record(REC_REPO, rec_start, NULL); + gedcom_subscribe_to_record(REC_SOUR, rec_start, NULL); + gedcom_subscribe_to_record(REC_SUBN, rec_start, NULL); + gedcom_subscribe_to_record(REC_SUBM, submit_start, NULL); + gedcom_subscribe_to_record(REC_USER, rec_start, NULL); + gedcom_subscribe_to_element(ELT_HEAD_SOUR, source_start, source_end); + gedcom_subscribe_to_element(ELT_SOUR_DATA_EVEN_DATE, + date_start, NULL); + gedcom_subscribe_to_element(ELT_SUB_EVT_DATE, date_start, NULL); + gedcom_subscribe_to_element(ELT_SUB_FAM_EVT_AGE, age_start, NULL); +} + +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); +} + +int main(int argc, char* argv[]) +{ + Gedcom_err_mech mech = IMMED_FAIL; + int compat_enabled = 1; + int debug_level = 0; + int run_times = 1; + int bogus = 0; + int result = 0; + char* file_name = NULL; + + if (argc > 1) { + int i; + for (i=1; i 0) { + output(0, "\n=== Parsing file %s\n", file_name); + result |= gedcom_parse_file(file_name); + } + if (result == 0) { + output(1, "Parse succeeded\n"); + } + else { + output(1, "Parse failed\n"); + } + fclose(outfile); + return result; +} diff --git a/t/src/test_gom b/t/src/test_gom new file mode 100755 index 0000000..fdb849f --- /dev/null +++ b/t/src/test_gom @@ -0,0 +1,62 @@ +#!/bin/sh +# $Id$ +# $Name$ + +options="-q" +extra_options= +dmalloc=`which dmalloc` +dmalloc_tmp=dmalloc.env + +while [ $# -gt 0 ] +do + case "$1" in + -*) extra_options="$extra_options $1";; + *) break;; + esac + shift +done + +file=$1 +expected_result=$2 +if [ -z "$expected_result" ] +then + expected_result=0 +fi + +# For use outside Makefile +if [ -z "$srcdir" ] +then + testfile=$file + srcdir=. + options=$extra_options +else + testfile=$srcdir/input/$file + options="$options $extra_options" +fi + +builddir=`pwd` +export GCONV_PATH=.:$GCONV_PATH +export LD_LIBRARY_PATH=$builddir/../gedcom/.libs:$builddir/../gom/.libs:$LD_LIBRARY_PATH +ln -s $srcdir/../data/gedcom.enc . +ln -s $builddir/../ansel/.libs/ANSI_Z39.47.so . +ln -s $srcdir/../ansel/gconv-modules . +rm -f core +if [ "$GOM_DMALLOC_TEST" = "" ] +then + $GEDCOM_TESTENV $builddir/src/gomtest $options $testfile +else + $dmalloc -b -l $GOM_DMALLOC_TEST -i 100 low > $dmalloc_tmp + . $dmalloc_tmp + rm $dmalloc_tmp + $GEDCOM_TESTENV $builddir/src/gomtest_static $options $testfile +fi +result=$? +rm gedcom.enc +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/test_script b/t/src/test_script new file mode 100755 index 0000000..eebe7e6 --- /dev/null +++ b/t/src/test_script @@ -0,0 +1,52 @@ +#!/bin/sh +# $Id$ +# $Name$ + +options="-q" +extra_options= + +while [ $# -gt 0 ] +do + case "$1" in + -*) extra_options="$extra_options $1";; + *) break;; + esac + shift +done + +file=$1 +expected_result=$2 +if [ -z "$expected_result" ] +then + expected_result=0 +fi + +# For use outside Makefile +if [ -z "$srcdir" ] +then + testfile=$file + srcdir=. + options=$extra_options +else + testfile=$srcdir/input/$file + 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 $builddir/../ansel/.libs/ANSI_Z39.47.so . +ln -s $srcdir/../ansel/gconv-modules . +rm -f core +$GEDCOM_TESTENV $builddir/src/testgedcom $options $testfile +result=$? +rm gedcom.enc +rm ANSI_Z39.47.so +rm gconv-modules +if [ "$result" -eq "$expected_result" -a ! -r core ] +then + exit 0 +else + exit 1 +fi