diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-01-27 14:37:00 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-01-27 14:37:00 -0900 |
| commit | 7252c8d1e7de7338a30393f8107e07828d45a6de (patch) | |
| tree | 757a02eb067e8a033ddf2bb7c6392b10d8b45af4 /tests/test-array-sorted.c | |
| parent | 2482489e4d8ff94e5727d8434213071580f00e95 (diff) | |
| download | tinyrad-7252c8d1e7de7338a30393f8107e07828d45a6de.tar.gz tinyrad-7252c8d1e7de7338a30393f8107e07828d45a6de.tar.bz2 tinyrad-7252c8d1e7de7338a30393f8107e07828d45a6de.tar.xz tinyrad-7252c8d1e7de7338a30393f8107e07828d45a6de.zip | |
tests: updating our_error() to accept array of error strings
Diffstat (limited to 'tests/test-array-sorted.c')
| -rw-r--r-- | tests/test-array-sorted.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/tests/test-array-sorted.c b/tests/test-array-sorted.c index b8bae20..d410a0e 100644 --- a/tests/test-array-sorted.c +++ b/tests/test-array-sorted.c | |||
| @@ -289,7 +289,7 @@ int main( int argc, char * argv[] ) | |||
| 289 | { | 289 | { |
| 290 | for(; (pos > 0); pos--) | 290 | for(; (pos > 0); pos--) |
| 291 | free(data[pos-1].name); | 291 | free(data[pos-1].name); |
| 292 | return(our_error(opts, "out of virtual memory")); | 292 | return(our_error(opts, NULL, "out of virtual memory")); |
| 293 | }; | 293 | }; |
| 294 | }; | 294 | }; |
| 295 | 295 | ||
| @@ -332,7 +332,7 @@ int main( int argc, char * argv[] ) | |||
| 332 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 332 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 333 | return(1); | 333 | return(1); |
| 334 | if ((list_len)) | 334 | if ((list_len)) |
| 335 | return(our_error(opts, "list still has elements")); | 335 | return(our_error(opts, NULL, "list still has elements")); |
| 336 | free(list); | 336 | free(list); |
| 337 | 337 | ||
| 338 | 338 | ||
| @@ -347,7 +347,7 @@ int main( int argc, char * argv[] ) | |||
| 347 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 347 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 348 | return(1); | 348 | return(1); |
| 349 | if ((list_len)) | 349 | if ((list_len)) |
| 350 | return(our_error(opts, "list still has elements")); | 350 | return(our_error(opts, NULL, "list still has elements")); |
| 351 | free(list); | 351 | free(list); |
| 352 | 352 | ||
| 353 | 353 | ||
| @@ -370,7 +370,7 @@ int main( int argc, char * argv[] ) | |||
| 370 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 370 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 371 | return(1); | 371 | return(1); |
| 372 | if ((list_len)) | 372 | if ((list_len)) |
| 373 | return(our_error(opts, "list still has elements")); | 373 | return(our_error(opts, NULL, "list still has elements")); |
| 374 | free(list); | 374 | free(list); |
| 375 | 375 | ||
| 376 | 376 | ||
| @@ -393,7 +393,7 @@ int main( int argc, char * argv[] ) | |||
| 393 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 393 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 394 | return(1); | 394 | return(1); |
| 395 | if ((list_len)) | 395 | if ((list_len)) |
| 396 | return(our_error(opts, "list still has elements")); | 396 | return(our_error(opts, NULL, "list still has elements")); |
| 397 | free(list); | 397 | free(list); |
| 398 | 398 | ||
| 399 | 399 | ||
| @@ -416,7 +416,7 @@ int main( int argc, char * argv[] ) | |||
| 416 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 416 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 417 | return(1); | 417 | return(1); |
| 418 | if ((list_len)) | 418 | if ((list_len)) |
| 419 | return(our_error(opts, "list still has elements")); | 419 | return(our_error(opts, NULL, "list still has elements")); |
| 420 | free(list); | 420 | free(list); |
| 421 | 421 | ||
| 422 | 422 | ||
| @@ -444,7 +444,7 @@ int main( int argc, char * argv[] ) | |||
| 444 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 444 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 445 | return(1); | 445 | return(1); |
| 446 | if ((list_len)) | 446 | if ((list_len)) |
| 447 | return(our_error(opts, "list still has elements")); | 447 | return(our_error(opts, NULL, "list still has elements")); |
| 448 | free(list); | 448 | free(list); |
| 449 | 449 | ||
| 450 | 450 | ||
| @@ -467,7 +467,7 @@ int main( int argc, char * argv[] ) | |||
| 467 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 467 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 468 | return(1); | 468 | return(1); |
| 469 | if ((list_len)) | 469 | if ((list_len)) |
| 470 | return(our_error(opts, "list still has elements")); | 470 | return(our_error(opts, NULL, "list still has elements")); |
| 471 | free(list); | 471 | free(list); |
| 472 | 472 | ||
| 473 | 473 | ||
| @@ -490,7 +490,7 @@ int main( int argc, char * argv[] ) | |||
| 490 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) | 490 | if ((my_test_remove(opts, list, &list_len, src, test, MY_LIST_LEN, merge))) |
| 491 | return(1); | 491 | return(1); |
| 492 | if ((list_len)) | 492 | if ((list_len)) |
| 493 | return(our_error(opts, "list still has elements")); | 493 | return(our_error(opts, NULL, "list still has elements")); |
| 494 | free(list); | 494 | free(list); |
| 495 | 495 | ||
| 496 | return(0); | 496 | return(0); |
| @@ -613,7 +613,7 @@ my_test_insert( | |||
| 613 | case TINYRAD_ARRAY_REPLACE: action_name = "REPLACE"; break; | 613 | case TINYRAD_ARRAY_REPLACE: action_name = "REPLACE"; break; |
| 614 | case 0: action_name = "DEFAULT"; break; | 614 | case 0: action_name = "DEFAULT"; break; |
| 615 | default: | 615 | default: |
| 616 | return(our_error(opts, "unknown insert action")); | 616 | return(our_error(opts, NULL, "unknown insert action")); |
| 617 | }; | 617 | }; |
| 618 | switch(mergeopt) | 618 | switch(mergeopt) |
| 619 | { | 619 | { |
| @@ -622,19 +622,19 @@ my_test_insert( | |||
| 622 | case TINYRAD_ARRAY_ANYDUP: merge_type = "ANY"; break; | 622 | case TINYRAD_ARRAY_ANYDUP: merge_type = "ANY"; break; |
| 623 | case 0: merge_type = "DEFAULT"; break; | 623 | case 0: merge_type = "DEFAULT"; break; |
| 624 | default: | 624 | default: |
| 625 | return(our_error(opts, "unknown dup action")); | 625 | return(our_error(opts, NULL, "unknown dup action")); |
| 626 | }; | 626 | }; |
| 627 | 627 | ||
| 628 | our_verbose(opts, "testing tinyrad_array_add( %7s, %9s, %s ) [%s] ...", action_name, merge_type, compar_name, (((iteration)) ? "duplicate" : "unique")); | 628 | our_verbose(opts, "testing tinyrad_array_add( %7s, %9s, %s ) [%s] ...", action_name, merge_type, compar_name, (((iteration)) ? "duplicate" : "unique")); |
| 629 | for(x = 0; (x < dat_len); x++) | 629 | for(x = 0; (x < dat_len); x++) |
| 630 | { | 630 | { |
| 631 | if (tinyrad_array_add((void **)listp, list_lenp, sizeof(MyData *), &src[x], arrayopt, compar, NULL, &realloc) == -1) | 631 | if (tinyrad_array_add((void **)listp, list_lenp, sizeof(MyData *), &src[x], arrayopt, compar, NULL, &realloc) == -1) |
| 632 | return(our_error(opts, "tinyrad_array_add(%s): returned error", action_name)); | 632 | return(our_error(opts, NULL, "tinyrad_array_add(%s): returned error", action_name)); |
| 633 | len = (iteration*dat_len) + x + 1; | 633 | len = (iteration*dat_len) + x + 1; |
| 634 | if ( ((iteration)) && (!(arrayopt & TINYRAD_ARRAY_MERGE)) ) | 634 | if ( ((iteration)) && (!(arrayopt & TINYRAD_ARRAY_MERGE)) ) |
| 635 | len = dat_len; | 635 | len = dat_len; |
| 636 | if (*list_lenp != len) | 636 | if (*list_lenp != len) |
| 637 | return(our_error(opts, "tinyrad_array_add(%s): did not increment length", action_name)); | 637 | return(our_error(opts, NULL, "tinyrad_array_add(%s): did not increment length", action_name)); |
| 638 | }; | 638 | }; |
| 639 | 639 | ||
| 640 | list = *listp; | 640 | list = *listp; |
| @@ -648,19 +648,19 @@ my_test_insert( | |||
| 648 | { | 648 | { |
| 649 | pos = x/iteration; | 649 | pos = x/iteration; |
| 650 | if ((strcasecmp(test[pos]->name, list[x]->name))) | 650 | if ((strcasecmp(test[pos]->name, list[x]->name))) |
| 651 | return(our_error(opts, "tinyrad_array_add(%s): misordered the list", action_name)); | 651 | return(our_error(opts, NULL, "tinyrad_array_add(%s): misordered the list", action_name)); |
| 652 | switch(mergeopt) | 652 | switch(mergeopt) |
| 653 | { | 653 | { |
| 654 | case TINYRAD_ARRAY_LASTDUP: | 654 | case TINYRAD_ARRAY_LASTDUP: |
| 655 | if ( (x < ((dat_len*iteration)-1)) && ((x % iteration) == (iteration-1)) ) | 655 | if ( (x < ((dat_len*iteration)-1)) && ((x % iteration) == (iteration-1)) ) |
| 656 | if (!(strcasecmp(list[x]->name, list[x+1]->name))) | 656 | if (!(strcasecmp(list[x]->name, list[x+1]->name))) |
| 657 | return(our_error(opts, "tinyrad_array_add(%s): first match not returned", action_name)); | 657 | return(our_error(opts, NULL, "tinyrad_array_add(%s): first match not returned", action_name)); |
| 658 | break; | 658 | break; |
| 659 | 659 | ||
| 660 | case TINYRAD_ARRAY_FIRSTDUP: | 660 | case TINYRAD_ARRAY_FIRSTDUP: |
| 661 | if ( (x > 0) && (!(x % iteration)) ) | 661 | if ( (x > 0) && (!(x % iteration)) ) |
| 662 | if (!(strcasecmp(list[x]->name, list[x-1]->name))) | 662 | if (!(strcasecmp(list[x]->name, list[x-1]->name))) |
| 663 | return(our_error(opts, "tinyrad_array_add(%s): first match not returned", action_name)); | 663 | return(our_error(opts, NULL, "tinyrad_array_add(%s): first match not returned", action_name)); |
| 664 | break; | 664 | break; |
| 665 | 665 | ||
| 666 | case TINYRAD_ARRAY_ANYDUP: | 666 | case TINYRAD_ARRAY_ANYDUP: |
| @@ -709,7 +709,7 @@ my_test_remove( | |||
| 709 | case TINYRAD_ARRAY_REPLACE: action_name = "REPLACE"; break; | 709 | case TINYRAD_ARRAY_REPLACE: action_name = "REPLACE"; break; |
| 710 | case 0: action_name = "DEFAULT"; break; | 710 | case 0: action_name = "DEFAULT"; break; |
| 711 | default: | 711 | default: |
| 712 | return(our_error(opts, "unknown insert action")); | 712 | return(our_error(opts, NULL, "unknown insert action")); |
| 713 | }; | 713 | }; |
| 714 | switch(mergeopt) | 714 | switch(mergeopt) |
| 715 | { | 715 | { |
| @@ -718,19 +718,19 @@ my_test_remove( | |||
| 718 | case TINYRAD_ARRAY_ANYDUP: merge_type = "ANY"; break; | 718 | case TINYRAD_ARRAY_ANYDUP: merge_type = "ANY"; break; |
| 719 | case 0: merge_type = "DEFAULT"; break; | 719 | case 0: merge_type = "DEFAULT"; break; |
| 720 | default: | 720 | default: |
| 721 | return(our_error(opts, "unknown dup action")); | 721 | return(our_error(opts, NULL, "unknown dup action")); |
| 722 | }; | 722 | }; |
| 723 | 723 | ||
| 724 | our_verbose(opts, "testing tinyrad_array_remove( %7s, %9s, %s ) [%s] ...", action_name, merge_type, compar_name, (((iteration)) ? "duplicate" : "unique")); | 724 | our_verbose(opts, "testing tinyrad_array_remove( %7s, %9s, %s ) [%s] ...", action_name, merge_type, compar_name, (((iteration)) ? "duplicate" : "unique")); |
| 725 | for(x = 0; (x < dat_len); x++) | 725 | for(x = 0; (x < dat_len); x++) |
| 726 | { | 726 | { |
| 727 | if (tinyrad_array_remove(list, list_lenp, sizeof(MyData *), &src[x], arrayopt, compar, NULL) == -1) | 727 | if (tinyrad_array_remove(list, list_lenp, sizeof(MyData *), &src[x], arrayopt, compar, NULL) == -1) |
| 728 | return(our_error(opts, "tinyrad_array_remove(%s): returned error", action_name)); | 728 | return(our_error(opts, NULL, "tinyrad_array_remove(%s): returned error", action_name)); |
| 729 | len = ((iteration+1)*dat_len) - x - 1; | 729 | len = ((iteration+1)*dat_len) - x - 1; |
| 730 | if ( ((iteration)) && (!(arrayopt & TINYRAD_ARRAY_MERGE)) ) | 730 | if ( ((iteration)) && (!(arrayopt & TINYRAD_ARRAY_MERGE)) ) |
| 731 | len = dat_len; | 731 | len = dat_len; |
| 732 | if (*list_lenp != len) | 732 | if (*list_lenp != len) |
| 733 | return(our_error(opts, "tinyrad_array_remove(%s): did not decrement length", action_name)); | 733 | return(our_error(opts, NULL, "tinyrad_array_remove(%s): did not decrement length", action_name)); |
| 734 | }; | 734 | }; |
| 735 | 735 | ||
| 736 | if (!(arrayopt & TINYRAD_ARRAY_MERGE)) | 736 | if (!(arrayopt & TINYRAD_ARRAY_MERGE)) |
| @@ -741,19 +741,19 @@ my_test_remove( | |||
| 741 | { | 741 | { |
| 742 | pos = x/iteration; | 742 | pos = x/iteration; |
| 743 | if ((strcasecmp(test[pos]->name, list[x]->name))) | 743 | if ((strcasecmp(test[pos]->name, list[x]->name))) |
| 744 | return(our_error(opts, "tinyrad_array_remove(%s): misordered the list", action_name)); | 744 | return(our_error(opts, NULL, "tinyrad_array_remove(%s): misordered the list", action_name)); |
| 745 | switch(mergeopt) | 745 | switch(mergeopt) |
| 746 | { | 746 | { |
| 747 | case TINYRAD_ARRAY_LASTDUP: | 747 | case TINYRAD_ARRAY_LASTDUP: |
| 748 | if ( (x < ((dat_len*iteration)-1)) && ((x % iteration) == (iteration-1)) ) | 748 | if ( (x < ((dat_len*iteration)-1)) && ((x % iteration) == (iteration-1)) ) |
| 749 | if (!(strcasecmp(list[x]->name, list[x+1]->name))) | 749 | if (!(strcasecmp(list[x]->name, list[x+1]->name))) |
| 750 | return(our_error(opts, "tinyrad_array_remove(%s): first match not returned", action_name)); | 750 | return(our_error(opts, NULL, "tinyrad_array_remove(%s): first match not returned", action_name)); |
| 751 | break; | 751 | break; |
| 752 | 752 | ||
| 753 | case TINYRAD_ARRAY_FIRSTDUP: | 753 | case TINYRAD_ARRAY_FIRSTDUP: |
| 754 | if ( (x > 0) && (!(x % iteration)) ) | 754 | if ( (x > 0) && (!(x % iteration)) ) |
| 755 | if (!(strcasecmp(list[x]->name, list[x-1]->name))) | 755 | if (!(strcasecmp(list[x]->name, list[x-1]->name))) |
| 756 | return(our_error(opts, "tinyrad_array_remove(%s): first match not returned", action_name)); | 756 | return(our_error(opts, NULL, "tinyrad_array_remove(%s): first match not returned", action_name)); |
| 757 | break; | 757 | break; |
| 758 | 758 | ||
| 759 | case TINYRAD_ARRAY_ANYDUP: | 759 | case TINYRAD_ARRAY_ANYDUP: |
| @@ -796,12 +796,12 @@ my_test_search( | |||
| 796 | case MY_KEY_NAME: ptr = list[y]->name; break; | 796 | case MY_KEY_NAME: ptr = list[y]->name; break; |
| 797 | case MY_KEY_VALUE: ptr = &list[y]->value; break; | 797 | case MY_KEY_VALUE: ptr = &list[y]->value; break; |
| 798 | default: | 798 | default: |
| 799 | return(our_error(opts, "unknown key")); | 799 | return(our_error(opts, NULL, "unknown key")); |
| 800 | }; | 800 | }; |
| 801 | if ((idx = tinyrad_array_search(list, x, sizeof(MyData *), ptr, TINYRAD_ARRAY_FIRSTDUP, NULL, compar)) == -1) | 801 | if ((idx = tinyrad_array_search(list, x, sizeof(MyData *), ptr, TINYRAD_ARRAY_FIRSTDUP, NULL, compar)) == -1) |
| 802 | return(our_error(opts, "tinyrad_array_search(); size: %zu; func: %s; idx: %zu; search error", x, compar_name, y)); | 802 | return(our_error(opts, NULL, "tinyrad_array_search(); size: %zu; func: %s; idx: %zu; search error", x, compar_name, y)); |
| 803 | if ((size_t)idx != y) | 803 | if ((size_t)idx != y) |
| 804 | return(our_error(opts, "tinyrad_array_search(); size: %zu; func: %s; idx: %zu; index mismatch", x, compar_name, y)); | 804 | return(our_error(opts, NULL, "tinyrad_array_search(); size: %zu; func: %s; idx: %zu; index mismatch", x, compar_name, y)); |
| 805 | }; | 805 | }; |
| 806 | }; | 806 | }; |
| 807 | 807 | ||
| @@ -817,14 +817,14 @@ my_test_search( | |||
| 817 | case MY_KEY_NAME: ptr = list[y]->name; break; | 817 | case MY_KEY_NAME: ptr = list[y]->name; break; |
| 818 | case MY_KEY_VALUE: ptr = &list[y]->value; break; | 818 | case MY_KEY_VALUE: ptr = &list[y]->value; break; |
| 819 | default: | 819 | default: |
| 820 | return(our_error(opts, "unknown key")); | 820 | return(our_error(opts, NULL, "unknown key")); |
| 821 | }; | 821 | }; |
| 822 | if ((res = tinyrad_array_get(list, x, sizeof(MyData *), ptr, TINYRAD_ARRAY_FIRSTDUP, compar)) == NULL) | 822 | if ((res = tinyrad_array_get(list, x, sizeof(MyData *), ptr, TINYRAD_ARRAY_FIRSTDUP, compar)) == NULL) |
| 823 | return(our_error(opts, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; search error", x, compar_name, y)); | 823 | return(our_error(opts, NULL, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; search error", x, compar_name, y)); |
| 824 | if ((strcasecmp((*res)->name, list[y]->name))) | 824 | if ((strcasecmp((*res)->name, list[y]->name))) |
| 825 | return(our_error(opts, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; result name does not match", x, compar_name, y)); | 825 | return(our_error(opts, NULL, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; result name does not match", x, compar_name, y)); |
| 826 | if ((*res)->value != list[y]->value) | 826 | if ((*res)->value != list[y]->value) |
| 827 | return(our_error(opts, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; result value does not match", x, compar_name, y)); | 827 | return(our_error(opts, NULL, "tinyrad_array_get(); size: %zu; func: %s; idx: %zu; result value does not match", x, compar_name, y)); |
| 828 | }; | 828 | }; |
| 829 | }; | 829 | }; |
| 830 | 830 | ||
