X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=t%2Fsrc%2Fgom_write.c;h=30a45a64c777b4332638b8b340cfa20d3393fe75;hb=681b182b6f003e91a47a098b7e8ac632315f61a6;hp=cb28844aa81f08b5d96dda6f885c992a27015f6d;hpb=8a73dd117ad3bf06a89595f7cd8fdef45c231a6e;p=gedcom-parse.git diff --git a/t/src/gom_write.c b/t/src/gom_write.c index cb28844..30a45a6 100644 --- a/t/src/gom_write.c +++ b/t/src/gom_write.c @@ -31,6 +31,7 @@ #define WRITE_GEDCOM "gom_write.ged" #define PROG_NAME "writegomtest" #define PROG_VERSION "3.14" +#define TIMESTAMP 1000000000L void gedcom_message_handler(Gedcom_msg_type type, char *msg) { @@ -72,13 +73,12 @@ int update_header(char* encoding) if (head == NULL) return 1; else { - /* - value = gom_set_string(&head->charset.name, encoding); - if (value == NULL || strcmp(value, encoding)) - return 1; - else - return 0; - */ + /* force warning for anything except UNICODE */ + if (!strcmp(encoding, "UNICODE")) { + value = gom_set_string(&head->charset.name, encoding); + if (value == NULL || strcmp(value, encoding)) + return 1; + } value = gom_set_string(&head->note, long_note); if (value == NULL || strcmp(value, long_note)) return 1; @@ -87,6 +87,31 @@ int update_header(char* encoding) } } +int test_timestamps() +{ + int result = 0; + struct tm* tm_ptr; + time_t tval; + /* Make sure we get a reproduceable output, in different timezones */ + tval = TIMESTAMP; + tm_ptr = gmtime(&tval); + tm_ptr->tm_isdst = 0; + tval = mktime(tm_ptr); + result = gom_header_update_timestamp(tval); + + /* Also change timestamp of submitter */ + if (result == 0) { + struct submitter* subm = gom_get_first_submitter(); + if (!subm) + result = 100; + else { + result = gom_update_timestamp(&(subm->change_date), tval); + } + } + + return result; +} + int main(int argc, char* argv[]) { int result; @@ -210,8 +235,6 @@ int main(int argc, char* argv[]) gedcom_init(); setlocale(LC_ALL, ""); gedcom_set_message_handler(gedcom_message_handler); - gedcom_write_set_encoding(encoding, enc, bom); - gedcom_write_set_line_terminator(end); output_open(outfilename); @@ -219,13 +242,24 @@ int main(int argc, char* argv[]) result = gom_parse_file(infilename); } else { + gedcom_write_set_encoding(ENC_MANUAL, encoding, enc, bom); + gedcom_write_set_line_terminator(ENC_MANUAL, end); result = gom_new_model(); if (result == 0) result |= update_header(encoding); } if (result == 0) + result |= test_timestamps(); + if (result == 0) { + output(1, "Writing file...\n"); result |= gom_write_file(gedfilename, &total_conv_fails); + } if (result == 0 && total_conv_fails == 0) { + output(1, "Re-parsing file...\n"); + gedcom_set_compat_handling(0); + result |= gom_parse_file(gedfilename); + } + if (result == 0) { output(1, "Test succeeded\n"); } else {