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
28 #include "portability.h"
32 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
35 output(1, "MESSAGE: ");
36 else if (type == WARNING)
37 output(1, "WARNING: ");
38 else if (type == ERROR)
40 output(1, "%s\n", msg);
45 printf("gedcom-parse test program for libgedcom\n\n");
46 printf("Usage: updategomtest [options]\n");
48 printf(" -h Show this help text\n");
49 printf(" -q No output to standard output\n");
50 printf(" -o <outfile> File to generate output to (def. testgedcom.out)\n");
53 int test_string_functions()
56 struct submitter* subm;
57 struct xref_value* xref;
60 const char* orig_source_id = "GEDCOM_PARSE";
61 const char* new_source_id = "TEST_UPDATE";
62 const char* new_submitter_name_utf8 = "Belgi\xC3\xAB";
63 const char* new_submitter_name_ansi = "Belgi\xEB";
65 head = gom_get_header();
69 value = gom_get_string(head->source.id);
72 if (strcmp(value, orig_source_id))
75 value = gom_set_string(&head->source.id, new_source_id);
78 if (strcmp(value, new_source_id))
81 value = gom_get_string(head->source.id);
84 if (strcmp(value, new_source_id))
87 xref = head->submitter;
91 subm = gom_get_submitter_by_xref(xref->string);
95 value = gom_set_string(&subm->name, new_submitter_name_utf8);
98 if (strcmp(value, new_submitter_name_utf8))
101 value = gom_get_string_for_locale(subm->name, &conv_fails);
104 if (!strcmp(value, new_submitter_name_utf8))
109 value = gom_set_string(&subm->name, new_submitter_name_ansi);
113 value = gom_set_string_for_locale(&subm->name, new_submitter_name_ansi);
120 int main(int argc, char* argv[])
123 char* outfilename = NULL;
127 for (i=1; i<argc; i++) {
128 if (!strncmp(argv[i], "-h", 3)) {
132 else if (!strncmp(argv[i], "-q", 3)) {
135 else if (!strncmp(argv[i], "-o", 3)) {
138 outfilename = argv[i];
141 printf ("Missing output file name\n");
147 printf ("Unrecognized option: %s\n", argv[i]);
155 setlocale(LC_ALL, "");
156 gedcom_set_message_handler(gedcom_message_handler);
158 output_open(outfilename);
160 result = gom_new_model();
162 result |= test_string_functions();
164 output(1, "Test succeeded\n");
167 output(1, "Test failed: %d\n", result);