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");
47 printf(" -o <outfile> File to generate output to (def. testgedcom.out)\n");
50 int test_xref_functions()
52 struct xref_value* xr;
55 xr = gedcom_get_by_xref("@NOTHING_THERE@");
59 xr = gedcom_add_xref(XREF_FAM, "NOT_AN_XREF", (Gedcom_ctxt)1);
63 xr = gedcom_add_xref(XREF_FAM, "@XREF@ BUT EXTRA", (Gedcom_ctxt)1);
67 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)1);
71 xr = gedcom_add_xref(XREF_FAM, "@NEWFAM@", (Gedcom_ctxt)2);
75 xr = gedcom_get_by_xref("@NEWFAM@");
79 if (xr->type != XREF_FAM) {
80 output(1, "Not the correct cross-reference type\n");
84 if ((int)xr->object != 1) {
85 output(1, "Not the correct cross-reference object\n");
89 xr = gedcom_link_xref(XREF_INDI, "@NEWFAM@");
93 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
97 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM");
101 xr = gedcom_link_xref(XREF_FAM, "@NEWFAM@");
105 xr = gedcom_link_xref(XREF_INDI, "@OLDINDI@");
109 result = gedcom_delete_xref("@NEWFAM@");
113 xr = gedcom_unlink_xref(XREF_INDI, "@NEWFAM@");
117 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
121 result = gedcom_delete_xref("@NEWFAM@");
125 xr = gedcom_unlink_xref(XREF_FAM, "@NEWFAM@");
129 result = gedcom_delete_xref("@NEWFAM@");
136 int main(int argc, char* argv[])
139 char* outfilename = NULL;
143 for (i=1; i<argc; i++) {
144 if (!strncmp(argv[i], "-h", 3)) {
148 else if (!strncmp(argv[i], "-q", 3)) {
151 else if (!strncmp(argv[i], "-o", 3)) {
154 outfilename = argv[i];
157 printf ("Missing output file name\n");
163 printf ("Unrecognized option: %s\n", argv[i]);
171 setlocale(LC_ALL, "");
172 gedcom_set_message_handler(gedcom_message_handler);
174 output_open(outfilename);
176 result = gedcom_new_model();
178 result |= test_xref_functions();
180 output(1, "Test succeeded\n");
183 output(1, "Test failed: %d\n", result);