X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;ds=sidebyside;f=t%2Fsrc%2Fupdate_gom.c;h=87a65a1fd1a7f1dd987b55f171d36cc147ef8bd5;hb=6e84ed5bc58dab589250c5cae425223d43895d32;hp=e7190d0f8a80c87ef5eba1a33aa992a88466e970;hpb=2ccfaedef455b54f53d9da0936f1a0539d22bfd4;p=gedcom-parse.git diff --git a/t/src/update_gom.c b/t/src/update_gom.c index e7190d0..87a65a1 100644 --- a/t/src/update_gom.c +++ b/t/src/update_gom.c @@ -26,6 +26,7 @@ #include "output.h" #include "dump_gom.h" #include "portability.h" +#include "string.h" #include #include @@ -117,6 +118,236 @@ int test_string_functions() return 0; } +char* print_date(const char* message, struct date_value* dv) +{ + char* date_str; + output(0, "\n%s:", message); + show_date(dv); + date_str = gedcom_date_to_string(dv); + output(0, "String: '%s'\n", str_val(date_str)); + return date_str; +} + +int test_date_functions() +{ + struct header* head; + struct date_value* dv; + char* date_str; + int normalized; + + head = gom_get_header(); + if (head == NULL) + return 50; + + dv = head->date; + if (dv != NULL) + return 51; + + dv = gedcom_new_date_value(NULL); + if (dv == NULL) + return 52; + + head->date = dv; + date_str = print_date("Initial date value", dv); + if (date_str[0]) + return 53; + + dv->date1.cal = CAL_GREGORIAN; + strcpy(dv->date1.year_str, "1990"); + normalized = gedcom_normalize_date(DI_FROM_STRINGS, dv); + if (normalized != 0) + return 54; + date_str = print_date("Setting only year string", dv); + if (! date_str[0]) + return 55; + + dv->date1.year = 1989; + normalized = gedcom_normalize_date(DI_FROM_NUMBERS, dv); + if (normalized != 0) + return 56; + date_str = print_date("Setting only year number", dv); + if (! date_str[0]) + return 57; + + dv->date1.type = DATE_EXACT; + dv->date1.sdn1 = 2500000; + dv->date1.sdn2 = -1; + normalized = gedcom_normalize_date(DI_FROM_SDN, dv); + if (normalized != 0) + return 58; + date_str = print_date("Setting only SDN 1", dv); + if (! date_str[0]) + return 59; + + dv->date1.cal = CAL_HEBREW; + normalized = gedcom_normalize_date(DI_FROM_SDN, dv); + if (normalized != 0) + return 60; + date_str = print_date("Same date in Hebrew calendar", dv); + if (! date_str[0]) + return 61; + + dv->date1.cal = CAL_FRENCH_REV; + normalized = gedcom_normalize_date(DI_FROM_SDN, dv); + if (normalized == 0) + return 62; + date_str = print_date("Same date in French revolution calendar", dv); + if (date_str[0]) + return 63; + + dv->date1.cal = CAL_GREGORIAN; + dv->date1.day = 4; + dv->date1.month = 2; + dv->date1.year = 1799; + normalized = gedcom_normalize_date(DI_FROM_NUMBERS, dv); + if (normalized != 0) + return 64; + dv->date1.cal = CAL_FRENCH_REV; + normalized = gedcom_normalize_date(DI_FROM_SDN, dv); + if (normalized != 0) + return 65; + date_str = print_date("Valid French revolution date", dv); + if (! date_str[0]) + return 66; + + return 0; +} + +int test_record_add_delete_functions() +{ + struct family* fam1; + struct individual *ind1, *ind2, *ind3, *ind4; + struct multimedia* mm1; + struct note* note1; + struct repository* repo1; + struct source* sour1; + struct submitter* subm2; + struct submission* subn1; + struct user_rec* user1; + struct xref_value* xr; + struct xref_list* xrl; + int result; + char* value; + const char* new_nr_of_children = "3"; + const char* note_text = "This is some text"; + + fam1 = gom_new_family("@FAM1@"); + if (!fam1) return 101; + + value = gom_set_string(&fam1->nr_of_children, new_nr_of_children); + if (value == NULL) + return 102; + if (strcmp(value, new_nr_of_children)) + return 103; + + ind1 = gom_new_individual("@FAM1@"); + if (ind1) return 104; + + ind1 = gom_new_individual("@IND1@"); + if (!ind1) return 105; + + mm1 = gom_new_multimedia("@OBJ1@"); + if (!mm1) return 106; + + note1 = gom_new_note("@NOTE1@"); + if (!note1) return 107; + + value = gom_set_string(¬e1->text, note_text); + if (value == NULL) + return 108; + if (strcmp(value, note_text)) + return 109; + + repo1 = gom_new_repository("@REPO1@"); + if (!repo1) return 110; + + sour1 = gom_new_source("@SOUR1@"); + if (!sour1) return 111; + + subm2 = gom_new_submitter("@SUBMITTER@"); + if (subm2) return 112; + + subm2 = gom_new_submitter("@SUBM2@"); + if (!subm2) return 113; + + subn1 = gom_new_submission("@SUBMISSION@"); + if (!subn1) return 114; + + user1 = gom_new_user_rec("@USER1@", "WRTAG"); + if (user1) return 115; + + user1 = gom_new_user_rec("@USER1@", "_TAG"); + if (!user1) return 116; + + xr = gom_set_xref(&(fam1->husband), ind1->xrefstr); + if (!xr) return 118; + + ind2 = gom_new_individual("@IND2@"); + if (!ind2) return 119; + + ind3 = gom_new_individual("@IND3@"); + if (!ind3) return 120; + + ind4 = gom_new_individual("@IND4@"); + if (!ind4) return 121; + + xrl = gom_add_xref(&(fam1->children), ind2->xrefstr); + if (!xrl) return 122; + + xrl = gom_add_xref(&(fam1->children), ind3->xrefstr); + if (!xrl) return 123; + + xrl = gom_add_xref(&(fam1->children), ind4->xrefstr); + if (!xrl) return 124; + + result = gom_remove_xref(&(fam1->children), ind3->xrefstr); + if (result != 0) return 125; + + result = gom_remove_xref(&(fam1->children), ind4->xrefstr); + if (result != 0) return 126; + + output(1, "Intermediate output:\n"); + show_data(); + + result = gom_delete_individual(ind1); + if (result == 0) return 150; + + xr = gom_set_xref(&(fam1->husband), NULL); + if (xr) return 151; + + result = gom_delete_individual(ind1); + if (result != 0) return 152; + + result = gom_delete_family(fam1); + if (result != 0) return 153; + + result = gom_delete_individual(ind2); + if (result != 0) return 154; + + result = gom_delete_multimedia(mm1); + if (result != 0) return 155; + + result = gom_delete_note(note1); + if (result != 0) return 156; + + result = gom_delete_repository(repo1); + if (result != 0) return 157; + + result = gom_delete_source(sour1); + if (result != 0) return 158; + + result = gom_delete_submitter(subm2); + if (result != 0) return 159; + + result = gom_delete_submission(subn1); + if (result != 0) return 160; + + result = gom_delete_user_rec(user1); + if (result != 0) return 161; + + return 0; +} + int main(int argc, char* argv[]) { int result; @@ -160,6 +391,10 @@ int main(int argc, char* argv[]) result = gom_new_model(); if (result == 0) result |= test_string_functions(); + if (result == 0) + result |= test_date_functions(); + if (result == 0) + result |= test_record_add_delete_functions(); if (result == 0) { output(1, "Test succeeded\n"); }