New test (for textdomain corruption).
[gedcom-parse.git] / t / src / testintl.c
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.
5
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.
10
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.
15
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
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #include "gedcom.h"
25 #include <locale.h>
26 #include <stdio.h>
27
28 #define MYTEXTDOMAIN "TESTINTL"
29
30 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
31 {
32   if (type == MESSAGE)
33     output(1, "MESSAGE: ");
34   else if (type == WARNING)
35     output(1, "WARNING: ");
36   else if (type == ERROR)
37     output(1, "ERROR: ");
38   output(1, "%s\n", msg);
39 }
40
41 void show_help ()
42 {
43   printf("gedcom-parse test program for libgedcom\n\n");
44   printf("Usage:  testintl [options]\n");
45   printf("Options:\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");
49 }
50
51 int main(int argc, char* argv[])
52 {
53   int result;
54   char* outfilename = NULL;
55   
56   if (argc > 1) {
57     int i;
58     for (i=1; i<argc; i++) {
59       if (!strncmp(argv[i], "-h", 3)) {
60         show_help();
61         exit(1);
62       }
63       else if (!strncmp(argv[i], "-q", 3)) {
64         output_set_quiet(1);
65       }
66       else if (!strncmp(argv[i], "-o", 3)) {
67         i++;
68         if (i < argc) {
69           outfilename = argv[i];
70         }
71         else {
72           printf ("Missing output file name\n");
73           show_help();
74           exit(1);
75         }
76       }
77       else {
78         printf ("Unrecognized option: %s\n", argv[i]);
79         show_help();
80         exit(1);
81       }
82     }
83   }
84   
85   gedcom_init();
86   setlocale(LC_ALL, "");
87   textdomain(MYTEXTDOMAIN);
88   gedcom_set_message_handler(gedcom_message_handler);
89
90   output_open(outfilename);
91   
92   result = gedcom_new_model();
93   if (result == 0) {
94     char* textdom = textdomain(NULL);
95     if (strcmp(textdom, MYTEXTDOMAIN)) {
96       output(1, "Text domain is %s, should be %s\n", textdom, MYTEXTDOMAIN);
97       result = 1;
98     }
99   }
100     
101   if (result == 0) {
102     output(1, "Test succeeded\n");
103   }
104   else {
105     output(1, "Test failed: %d\n", result);
106   }
107
108   output_close();
109   return result;
110 }