X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=t%2Fsrc%2Fupdate.c;h=22e852c76278ed5d323deda0278062a3e01cbd1d;hb=ea81accae13a4617cc46f5256dad50e2732cc206;hp=bc2e0f6f614c65cbe12b202a418a98fd54a02ded;hpb=63b6a314939f40a868b3589dcf47ae30cfac0395;p=gedcom-parse.git diff --git a/t/src/update.c b/t/src/update.c index bc2e0f6..22e852c 100644 --- a/t/src/update.c +++ b/t/src/update.c @@ -22,26 +22,11 @@ /* $Name$ */ #include "gedcom.h" +#include "output.h" +#include "portability.h" #include #include -#define OUTFILE "testgedcom.out" -FILE* outfile = NULL; -int quiet = 0; - -void output(int to_stdout_too, char* format, ...) -{ - va_list ap; - va_start(ap, format); - if (outfile) { - vfprintf(outfile, format, ap); - } - if (to_stdout_too && !quiet) { - vprintf(format, ap); - } - va_end(ap); -} - void gedcom_message_handler(Gedcom_msg_type type, char *msg) { if (type == MESSAGE) @@ -56,16 +41,18 @@ void gedcom_message_handler(Gedcom_msg_type type, char *msg) void show_help () { printf("gedcom-parse test program for libgedcom\n\n"); - printf("Usage: updatetest [options] file\n"); + printf("Usage: updatetest [options]\n"); printf("Options:\n"); printf(" -h Show this help text\n"); printf(" -q No output to standard output\n"); + printf(" -o File to generate output to (def. testgedcom.out)\n"); } int test_xref_functions() { struct xref_value* xr; int result; + long int tmp; xr = gedcom_get_by_xref("@NOTHING_THERE@"); if (xr != NULL) @@ -96,7 +83,8 @@ int test_xref_functions() return 16; } - if ((int)xr->object != 1) { + tmp = void_ptr_to_int(xr->object); + if (tmp != 1) { output(1, "Not the correct cross-reference object\n"); return 17; } @@ -151,6 +139,7 @@ int test_xref_functions() int main(int argc, char* argv[]) { int result; + char* outfilename = NULL; if (argc > 1) { int i; @@ -160,7 +149,18 @@ int main(int argc, char* argv[]) exit(1); } else if (!strncmp(argv[i], "-q", 3)) { - quiet = 1; + output_set_quiet(1); + } + else if (!strncmp(argv[i], "-o", 3)) { + i++; + if (i < argc) { + outfilename = argv[i]; + } + else { + printf ("Missing output file name\n"); + show_help(); + exit(1); + } } else { printf ("Unrecognized option: %s\n", argv[i]); @@ -173,21 +173,19 @@ int main(int argc, char* argv[]) gedcom_init(); setlocale(LC_ALL, ""); gedcom_set_message_handler(gedcom_message_handler); - - outfile = fopen(OUTFILE, "a"); - if (!outfile) { - printf("Could not open %s for appending\n", OUTFILE); - } + + output_open(outfilename); result = gedcom_new_model(); - result |= test_xref_functions(); + if (result == 0) + result |= test_xref_functions(); if (result == 0) { output(1, "Test succeeded\n"); } else { output(1, "Test failed: %d\n", result); } - - fclose(outfile); + + output_close(); return result; }