1 /* Test program for the Gedcom library.
2 Copyright (C) 2001, 2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
6 The Gedcom parser library is free software; you can redistribute it
7 and/or modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The Gedcom parser library is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the Gedcom parser library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include "portability.h"
30 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
33 output(1, "MESSAGE: ");
34 else if (type == WARNING)
35 output(1, "WARNING: ");
36 else if (type == ERROR)
38 output(1, "%s\n", msg);
43 printf("gedcom-parse test program for libgedcom\n\n");
44 printf("Usage: updatetest [options] file\n");
46 printf(" -h Show this help text\n");
47 printf(" -q No output to standard output\n");
48 printf(" -o <outfile> File to generate output to (def. testgedcom.out)\n");
51 int test_xref_functions()
53 struct xref_value* xr;
57 xr = gedcom_get_by_xref("@NOTHING_THERE@");
61 xr = gedcom_add_xref(XREF_FAM, "NOT_AN_XREF", (Gedcom_ctxt)1);
65 xr = gedcom_add_xref(XREF_FAM, "@XREF@ BUT EXTRA", (Gedcom_ctxt)1);
69 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)1);
73 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)2);
77 xr = gedcom_get_by_xref("@NEWFAM@");
81 if (xr->type != XREF_FAM) {
82 output(1, "Not the correct cross-reference type\n");
86 tmp = void_ptr_to_int(xr->object);
88 output(1, "Not the correct cross-reference object\n");
92 xr = gedcom_link_xref(XREF_INDI, "@NEWFAM@");
96 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
100 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM");
104 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
108 xr = gedcom_link_xref(XREF_INDI, "@OLDINDI@");
112 result = gedcom_delete_xref("@NEWFAM@");
116 xr = gedcom_unlink_xref(XREF_INDI, "@NEWFAM@");
120 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
124 result = gedcom_delete_xref("@NEWFAM@");
128 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
132 result = gedcom_delete_xref("@NEWFAM@");
139 int main(int argc, char* argv[])
142 char* outfilename = NULL;
146 for (i=1; i<argc; i++) {
147 if (!strncmp(argv[i], "-h", 3)) {
151 else if (!strncmp(argv[i], "-q", 3)) {
154 else if (!strncmp(argv[i], "-o", 3)) {
157 outfilename = argv[i];
160 printf ("Missing output file name\n");
166 printf ("Unrecognized option: %s\n", argv[i]);
174 setlocale(LC_ALL, "");
175 gedcom_set_message_handler(gedcom_message_handler);
177 output_open(outfilename);
179 result = gedcom_new_model();
181 result |= test_xref_functions();
183 output(1, "Test succeeded\n");
186 output(1, "Test failed: %d\n", result);