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"
33 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
36 output(1, "MESSAGE: ");
37 else if (type == WARNING)
38 output(1, "WARNING: ");
39 else if (type == ERROR)
41 output(1, "%s\n", msg);
46 printf("gedcom-parse test program for libgedcom\n\n");
47 printf("Usage: updategomtest [options]\n");
49 printf(" -h Show this help text\n");
50 printf(" -q No output to standard output\n");
51 printf(" -o <outfile> File to generate output to (def. testgedcom.out)\n");
54 int test_string_functions()
57 struct submitter* subm;
58 struct xref_value* xref;
61 const char* orig_source_id = "GEDCOM_PARSE";
62 const char* new_source_id = "TEST_UPDATE";
63 const char* new_submitter_name_utf8 = "Belgi\xC3\xAB";
64 const char* new_submitter_name_ansi = "Belgi\xEB";
66 head = gom_get_header();
70 value = gom_get_string(head->source.id);
73 if (strcmp(value, orig_source_id))
76 value = gom_set_string(&head->source.id, new_source_id);
79 if (strcmp(value, new_source_id))
82 value = gom_get_string(head->source.id);
85 if (strcmp(value, new_source_id))
88 xref = head->submitter;
92 subm = gom_get_submitter_by_xref(xref->string);
96 value = gom_set_string(&subm->name, new_submitter_name_utf8);
99 if (strcmp(value, new_submitter_name_utf8))
102 value = gom_get_string_for_locale(subm->name, &conv_fails);
105 if (!strcmp(value, new_submitter_name_utf8))
110 value = gom_set_string(&subm->name, new_submitter_name_ansi);
114 value = gom_set_string_for_locale(&subm->name, new_submitter_name_ansi);
121 char* print_date(const char* message, struct date_value* dv)
124 output(0, "\n%s:", message);
126 date_str = gedcom_date_to_string(dv);
127 output(0, "String: '%s'\n", str_val(date_str));
131 int test_date_functions()
134 struct date_value* dv;
138 head = gom_get_header();
146 dv = gedcom_new_date_value(NULL);
151 date_str = print_date("Initial date value", dv);
155 dv->date1.cal = CAL_GREGORIAN;
156 strcpy(dv->date1.year_str, "1990");
157 normalized = gedcom_normalize_date(DI_FROM_STRINGS, dv);
160 date_str = print_date("Setting only year string", dv);
164 dv->date1.year = 1989;
165 normalized = gedcom_normalize_date(DI_FROM_NUMBERS, dv);
168 date_str = print_date("Setting only year number", dv);
172 dv->date1.type = DATE_EXACT;
173 dv->date1.sdn1 = 2500000;
175 normalized = gedcom_normalize_date(DI_FROM_SDN, dv);
178 date_str = print_date("Setting only SDN 1", dv);
182 dv->date1.cal = CAL_HEBREW;
183 normalized = gedcom_normalize_date(DI_FROM_SDN, dv);
186 date_str = print_date("Same date in Hebrew calendar", dv);
190 dv->date1.cal = CAL_FRENCH_REV;
191 normalized = gedcom_normalize_date(DI_FROM_SDN, dv);
194 date_str = print_date("Same date in French revolution calendar", dv);
198 dv->date1.cal = CAL_GREGORIAN;
201 dv->date1.year = 1799;
202 normalized = gedcom_normalize_date(DI_FROM_NUMBERS, dv);
205 dv->date1.cal = CAL_FRENCH_REV;
206 normalized = gedcom_normalize_date(DI_FROM_SDN, dv);
209 date_str = print_date("Valid French revolution date", dv);
216 int test_record_add_delete_functions()
219 struct individual *ind1, *ind2, *ind3, *ind4;
220 struct multimedia* mm1;
222 struct repository* repo1;
223 struct source* sour1;
224 struct submitter* subm2;
225 struct submission* subn1;
226 struct user_rec* user1;
227 struct xref_value* xr;
228 struct xref_list* xrl;
231 const char* new_nr_of_children = "3";
232 const char* note_text = "This is some text";
234 fam1 = gom_new_family("@FAM1@");
235 if (!fam1) return 101;
237 value = gom_set_string(&fam1->nr_of_children, new_nr_of_children);
240 if (strcmp(value, new_nr_of_children))
243 ind1 = gom_new_individual("@FAM1@");
244 if (ind1) return 104;
246 ind1 = gom_new_individual("@IND1@");
247 if (!ind1) return 105;
249 mm1 = gom_new_multimedia("@OBJ1@");
250 if (!mm1) return 106;
252 note1 = gom_new_note("@NOTE1@");
253 if (!note1) return 107;
255 value = gom_set_string(¬e1->text, note_text);
258 if (strcmp(value, note_text))
261 repo1 = gom_new_repository("@REPO1@");
262 if (!repo1) return 110;
264 sour1 = gom_new_source("@SOUR1@");
265 if (!sour1) return 111;
267 subm2 = gom_new_submitter("@SUBMITTER@");
268 if (subm2) return 112;
270 subm2 = gom_new_submitter("@SUBM2@");
271 if (!subm2) return 113;
273 subn1 = gom_new_submission("@SUBMISSION@");
274 if (!subn1) return 114;
276 user1 = gom_new_user_rec("@USER1@", "WRTAG");
277 if (user1) return 115;
279 user1 = gom_new_user_rec("@USER1@", "_TAG");
280 if (!user1) return 116;
282 xr = gom_set_xref(&(fam1->husband), ind1->xrefstr);
285 ind2 = gom_new_individual("@IND2@");
286 if (!ind2) return 119;
288 ind3 = gom_new_individual("@IND3@");
289 if (!ind3) return 120;
291 ind4 = gom_new_individual("@IND4@");
292 if (!ind4) return 121;
294 xrl = gom_add_xref(&(fam1->children), ind2->xrefstr);
295 if (!xrl) return 122;
297 xrl = gom_add_xref(&(fam1->children), ind3->xrefstr);
298 if (!xrl) return 123;
300 xrl = gom_add_xref(&(fam1->children), ind4->xrefstr);
301 if (!xrl) return 124;
303 result = gom_move_xref(MOVE_UP, &(fam1->children), ind4->xrefstr);
304 if (result != 0) return 127;
306 result = gom_move_xref(MOVE_UP, &(fam1->children), ind4->xrefstr);
307 if (result != 0) return 128;
309 result = gom_move_xref(MOVE_UP, &(fam1->children), ind4->xrefstr);
310 if (result != 0) return 129;
312 result = gom_move_xref(MOVE_DOWN, &(fam1->children), ind4->xrefstr);
313 if (result != 0) return 130;
315 result = gom_remove_xref(&(fam1->children), ind3->xrefstr);
316 if (result != 0) return 125;
318 result = gom_remove_xref(&(fam1->children), ind4->xrefstr);
319 if (result != 0) return 126;
321 output(1, "Intermediate output:\n");
324 result = gom_delete_individual(ind1);
325 if (result == 0) return 150;
327 xr = gom_set_xref(&(fam1->husband), NULL);
330 result = gom_delete_individual(ind1);
331 if (result != 0) return 152;
333 result = gom_delete_family(fam1);
334 if (result != 0) return 153;
336 result = gom_delete_individual(ind2);
337 if (result != 0) return 154;
339 result = gom_delete_multimedia(mm1);
340 if (result != 0) return 155;
342 result = gom_delete_note(note1);
343 if (result != 0) return 156;
345 result = gom_delete_repository(repo1);
346 if (result != 0) return 157;
348 result = gom_delete_source(sour1);
349 if (result != 0) return 158;
351 result = gom_delete_submitter(subm2);
352 if (result != 0) return 159;
354 result = gom_delete_submission(subn1);
355 if (result != 0) return 160;
357 result = gom_delete_user_rec(user1);
358 if (result != 0) return 161;
363 int main(int argc, char* argv[])
366 char* outfilename = NULL;
370 for (i=1; i<argc; i++) {
371 if (!strncmp(argv[i], "-h", 3)) {
375 else if (!strncmp(argv[i], "-q", 3)) {
378 else if (!strncmp(argv[i], "-o", 3)) {
381 outfilename = argv[i];
384 printf ("Missing output file name\n");
390 printf ("Unrecognized option: %s\n", argv[i]);
398 setlocale(LC_ALL, "");
399 gedcom_set_message_handler(gedcom_message_handler);
401 output_open(outfilename);
403 result = gom_new_model();
405 result |= test_string_functions();
407 result |= test_date_functions();
409 result |= test_record_add_delete_functions();
411 output(1, "Test succeeded\n");
414 output(1, "Test failed: %d\n", result);