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
29 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
32 output(1, "MESSAGE: ");
33 else if (type == WARNING)
34 output(1, "WARNING: ");
35 else if (type == ERROR)
37 output(1, "%s\n", msg);
42 printf("gedcom-parse test program for libgedcom\n\n");
43 printf("Usage: updatetest [options] file\n");
45 printf(" -h Show this help text\n");
46 printf(" -q No output to standard output\n");
49 int test_xref_functions()
51 struct xref_value* xr;
54 xr = gedcom_get_by_xref("@NOTHING_THERE@");
58 xr = gedcom_add_xref(XREF_FAM, "NOT_AN_XREF", (Gedcom_ctxt)1);
62 xr = gedcom_add_xref(XREF_FAM, "@XREF@ BUT EXTRA", (Gedcom_ctxt)1);
66 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)1);
70 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)2);
74 xr = gedcom_get_by_xref("@NEWFAM@");
78 if (xr->type != XREF_FAM) {
79 output(1, "Not the correct cross-reference type\n");
83 if ((int)xr->object != 1) {
84 output(1, "Not the correct cross-reference object\n");
88 xr = gedcom_link_xref(XREF_INDI, "@NEWFAM@");
92 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
96 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM");
100 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
104 xr = gedcom_link_xref(XREF_INDI, "@OLDINDI@");
108 result = gedcom_delete_xref("@NEWFAM@");
112 xr = gedcom_unlink_xref(XREF_INDI, "@NEWFAM@");
116 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
120 result = gedcom_delete_xref("@NEWFAM@");
124 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
128 result = gedcom_delete_xref("@NEWFAM@");
135 int main(int argc, char* argv[])
141 for (i=1; i<argc; i++) {
142 if (!strncmp(argv[i], "-h", 3)) {
146 else if (!strncmp(argv[i], "-q", 3)) {
150 printf ("Unrecognized option: %s\n", argv[i]);
158 setlocale(LC_ALL, "");
159 gedcom_set_message_handler(gedcom_message_handler);
163 result = gedcom_new_model();
164 result |= test_xref_functions();
166 output(1, "Test succeeded\n");
169 output(1, "Test failed: %d\n", result);