From f0204d8762bc29ca11f0eb8e188db5247d4ffa9d Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Fri, 26 Jan 2024 13:10:57 +0100 Subject: [PATCH] Remove unused stringlist c code --- lib/include/ert/util/stringlist.hpp | 51 --- lib/util/stringlist.cpp | 355 -------------------- lib/util/tests/ert_util_stringlist_test.cpp | 269 --------------- 3 files changed, 675 deletions(-) diff --git a/lib/include/ert/util/stringlist.hpp b/lib/include/ert/util/stringlist.hpp index d4e31a79a..dd16dea88 100644 --- a/lib/include/ert/util/stringlist.hpp +++ b/lib/include/ert/util/stringlist.hpp @@ -21,76 +21,31 @@ int stringlist_select_files(stringlist_type *names, const char *path, const char *stringlist_get_last(const stringlist_type *stringlist); char *stringlist_pop(stringlist_type *stringlist); -void stringlist_deep_copy(stringlist_type *target, const stringlist_type *src); -stringlist_type * -stringlist_alloc_deep_copy_with_limits(const stringlist_type *src, int offset, - int num_strings); -stringlist_type * -stringlist_alloc_deep_copy_with_offset(const stringlist_type *src, int offset); -stringlist_type *stringlist_alloc_deep_copy(const stringlist_type *src); stringlist_type *stringlist_alloc_new(void); -void stringlist_free__(void *); void stringlist_free(stringlist_type *); void stringlist_clear(stringlist_type *); void stringlist_append_copy(stringlist_type *, const char *); -const char *stringlist_safe_iget(const stringlist_type *stringlist, int index); -bool stringlist_unique(const stringlist_type *stringlist); -bool stringlist_iequal(const stringlist_type *stringlist, int index, - const char *s); const char *stringlist_iget(const stringlist_type *, int); -int stringlist_iget_as_int(const stringlist_type *stringlist, int index, - bool *valid); double stringlist_iget_as_double(const stringlist_type *stringlist, int index, bool *valid); -bool stringlist_iget_as_bool(const stringlist_type *stringlist, int index, - bool *valid); char *stringlist_iget_copy(const stringlist_type *stringlist, int); -char *stringlist_alloc_joined_string(const stringlist_type *, const char *); -char *stringlist_alloc_joined_substring(const stringlist_type *s, - int start_index, int end_index, - const char *sep); const char *stringlist_front(const stringlist_type *stringlist); const char *stringlist_back(const stringlist_type *stringlist); void stringlist_iset_copy(stringlist_type *, int index, const char *); -void stringlist_iset_ref(stringlist_type *, int index, const char *); void stringlist_iset_owned_ref(stringlist_type *, int index, const char *); -void stringlist_insert_copy(stringlist_type *, int index, const char *); -void stringlist_insert_ref(stringlist_type *, int index, const char *); -void stringlist_insert_owned_ref(stringlist_type *, int index, const char *); - -void stringlist_idel(stringlist_type *stringlist, int index); - int stringlist_get_size(const stringlist_type *); -void stringlist_fprintf(const stringlist_type *, const char *, FILE *); -void stringlist_fprintf_fmt(const stringlist_type *stringlist, - const stringlist_type *fmt_list, FILE *stream); stringlist_type *stringlist_alloc_argv_copy(const char **, int); -stringlist_type *stringlist_alloc_argv_ref(const char **, int); -stringlist_type *stringlist_alloc_argv_owned_ref(const char **argv, int argc); -stringlist_type *stringlist_alloc_from_split(const char *input_string, - const char *sep); -stringlist_type *stringlist_fread_alloc(FILE *); - -void stringlist_append_stringlist_copy(stringlist_type *, - const stringlist_type *); -void stringlist_insert_stringlist_copy(stringlist_type *, - const stringlist_type *, int); bool stringlist_equal(const stringlist_type *, const stringlist_type *); bool stringlist_contains(const stringlist_type *, const char *); int_vector_type *stringlist_find(const stringlist_type *, const char *); int stringlist_find_first(const stringlist_type *, const char *); -int stringlist_get_argc(const stringlist_type *); -char **stringlist_alloc_char_copy(const stringlist_type *); -char **stringlist_alloc_char_ref(const stringlist_type *stringlist); -void stringlist_fread(stringlist_type *, FILE *); -void stringlist_fwrite(const stringlist_type *, FILE *); void stringlist_sort(stringlist_type *, string_cmp_ftype *string_cmp); void stringlist_reverse(stringlist_type *s); void stringlist_python_sort(stringlist_type *s, int cmp_flag); @@ -100,12 +55,6 @@ int stringlist_select_matching(stringlist_type *names, const char *pattern); #endif int stringlist_select_matching_files(stringlist_type *names, const char *path, const char *file_pattern); -int stringlist_select_matching_elements(stringlist_type *target, - const stringlist_type *src, - const char *pattern); -int stringlist_append_matching_elements(stringlist_type *target, - const stringlist_type *src, - const char *pattern); UTIL_IS_INSTANCE_HEADER(stringlist); #ifdef __cplusplus diff --git a/lib/util/stringlist.cpp b/lib/util/stringlist.cpp index 37aeb9cce..3ac317ba5 100644 --- a/lib/util/stringlist.cpp +++ b/lib/util/stringlist.cpp @@ -38,39 +38,6 @@ struct stringlist_struct { vector_type *strings; }; -static void stringlist_fprintf__(const stringlist_type *stringlist, - const char *sep, FILE *stream) { - int length = vector_get_size(stringlist->strings); - if (length > 0) { - int i; - for (i = 0; i < length - 1; i++) { - const char *s = stringlist_iget(stringlist, i); - fprintf(stream, "%s%s", s, sep); - } - - fprintf(stream, "%s", stringlist_iget(stringlist, length - 1)); - } -} - -void stringlist_fprintf(const stringlist_type *stringlist, const char *sep, - FILE *stream) { - stringlist_fprintf__(stringlist, sep, stream); -} - -void stringlist_fprintf_fmt(const stringlist_type *stringlist, - const stringlist_type *fmt_list, FILE *stream) { - if (stringlist_get_size(stringlist) == stringlist_get_size(fmt_list)) { - int i; - for (i = 0; i < stringlist_get_size(stringlist); i++) - fprintf(stream, stringlist_iget(fmt_list, i), - stringlist_iget(stringlist, i)); - } - util_abort("%s: length of stringlist:%d length of fmt_list:%d - must be " - "equal \n", - __func__, stringlist_get_size(stringlist), - stringlist_get_size(fmt_list)); -} - /** This function appends a copy of s into the stringlist. */ @@ -86,31 +53,11 @@ void stringlist_iset_copy(stringlist_type *stringlist, int index, vector_iset_buffer(stringlist->strings, index, s, strlen(s) + 1); } -void stringlist_iset_ref(stringlist_type *stringlist, int index, - const char *s) { - vector_iset_ref(stringlist->strings, index, s); -} - void stringlist_iset_owned_ref(stringlist_type *stringlist, int index, const char *s) { vector_iset_owned_ref(stringlist->strings, index, s, free); } -void stringlist_insert_copy(stringlist_type *stringlist, int index, - const char *s) { - vector_insert_buffer(stringlist->strings, index, s, strlen(s) + 1); -} - -void stringlist_insert_ref(stringlist_type *stringlist, int index, - const char *s) { - vector_insert_ref(stringlist->strings, index, s); -} - -void stringlist_insert_owned_ref(stringlist_type *stringlist, int index, - const char *s) { - vector_insert_owned_ref(stringlist->strings, index, s, free); -} - static stringlist_type *stringlist_alloc_empty(bool alloc_vector) { stringlist_type *stringlist = (stringlist_type *)util_malloc(sizeof *stringlist); @@ -135,32 +82,6 @@ stringlist_type *stringlist_alloc_argv_copy(const char **argv, int argc) { return stringlist; } -/* - Can not use vector_deep copy - because we might not have the - constructor registered, in the node_data instance; but in this case - we know the copy constructor. -*/ - -stringlist_type * -stringlist_alloc_deep_copy_with_limits(const stringlist_type *src, int offset, - int num_strings) { - stringlist_type *copy = stringlist_alloc_empty(true); - int i; - for (i = 0; i < num_strings; i++) - stringlist_append_copy(copy, stringlist_iget(src, i + offset)); - return copy; -} - -stringlist_type * -stringlist_alloc_deep_copy_with_offset(const stringlist_type *src, int offset) { - return stringlist_alloc_deep_copy_with_limits( - src, offset, stringlist_get_size(src) - offset); -} - -stringlist_type *stringlist_alloc_deep_copy(const stringlist_type *src) { - return stringlist_alloc_deep_copy_with_offset(src, 0); -} - void stringlist_append_stringlist_copy(stringlist_type *stringlist, const stringlist_type *src) { int i; @@ -168,54 +89,6 @@ void stringlist_append_stringlist_copy(stringlist_type *stringlist, stringlist_append_copy(stringlist, stringlist_iget(src, i)); } -/** - Insert a copy of a stringlist in some position. - - Can probably be made more efficient. -*/ - -void stringlist_insert_stringlist_copy(stringlist_type *stringlist, - const stringlist_type *src, int pos) { - int size_old = stringlist_get_size(stringlist); - - /** Cannot use assert_index here. */ - if (pos < 0 || pos > size_old) - util_abort("%s: Position %d is out of bounds. Min: 0 Max: %d\n", pos, - size_old); - { - stringlist_type *start = stringlist_alloc_new(); - stringlist_type *end = stringlist_alloc_new(); - stringlist_type *newList = stringlist_alloc_new(); - int i; - - for (i = 0; i < pos; i++) - stringlist_append_copy(start, stringlist_iget(stringlist, i)); - - for (i = pos; i < size_old; i++) - stringlist_append_copy(end, stringlist_iget(stringlist, i)); - - stringlist_append_stringlist_copy(newList, start); - stringlist_append_stringlist_copy(newList, src); - stringlist_append_stringlist_copy(newList, end); - - stringlist_clear(stringlist); - stringlist_append_stringlist_copy(stringlist, newList); - - stringlist_free(newList); - stringlist_free(start); - stringlist_free(end); - } -} - -void stringlist_deep_copy(stringlist_type *target, const stringlist_type *src) { - stringlist_clear(target); - { - int i; - for (i = 0; i < stringlist_get_size(src); i++) - stringlist_append_copy(target, stringlist_iget(src, i)); - } -} - /** Frees all the memory contained by the stringlist. */ @@ -232,15 +105,6 @@ void stringlist_free(stringlist_type *stringlist) { static UTIL_SAFE_CAST_FUNCTION(stringlist, STRINGLIST_TYPE_ID); UTIL_IS_INSTANCE_FUNCTION(stringlist, STRINGLIST_TYPE_ID) -void stringlist_free__(void *__stringlist) { - stringlist_type *stringlist = stringlist_safe_cast(__stringlist); - stringlist_free(stringlist); -} - -void stringlist_idel(stringlist_type *stringlist, int index) { - vector_idel(stringlist->strings, index); -} - char *stringlist_pop(stringlist_type *stringlist) { return (char *)vector_pop_back(stringlist->strings); } @@ -258,21 +122,6 @@ const char *stringlist_back(const stringlist_type *stringlist) { vector_get_size(stringlist->strings) - 1); } -int stringlist_iget_as_int(const stringlist_type *stringlist, int index, - bool *valid) { - const char *string_value = stringlist_iget(stringlist, index); - int value = -1; - - if (valid != NULL) - *valid = false; - - if (util_sscanf_int(string_value, &value)) - if (valid != NULL) - *valid = true; - - return value; -} - double stringlist_iget_as_double(const stringlist_type *stringlist, int index, bool *valid) { const char *string_value = stringlist_iget(stringlist, index); @@ -288,44 +137,10 @@ double stringlist_iget_as_double(const stringlist_type *stringlist, int index, return value; } -bool stringlist_iget_as_bool(const stringlist_type *stringlist, int index, - bool *valid) { - const char *string_value = stringlist_iget(stringlist, index); - bool value = false; - - if (valid != NULL) - *valid = false; - - if (util_sscanf_bool(string_value, &value)) - if (valid != NULL) - *valid = true; - - return value; -} - const char *stringlist_get_last(const stringlist_type *stringlist) { return (const char *)vector_get_last(stringlist->strings); } -bool stringlist_iequal(const stringlist_type *stringlist, int index, - const char *s) { - return util_string_equal(stringlist_iget(stringlist, index), s); -} - -/** - Will return NULL if you ask for something beyond the limits of the - stringlist (will die on negative index - that is NEVER OK). -*/ -const char *stringlist_safe_iget(const stringlist_type *stringlist, int index) { - if (index < 0) - util_abort("%s: negative index:%d is NOT allowed \n", __func__, index); - - if (index < stringlist_get_size(stringlist)) - return stringlist_iget(stringlist, index); - else - return NULL; -} - char *stringlist_iget_copy(const stringlist_type *stringlist, int index) { return util_alloc_string_copy(stringlist_iget(stringlist, index)); } @@ -334,34 +149,6 @@ int stringlist_get_size(const stringlist_type *stringlist) { return vector_get_size(stringlist->strings); } -/* - Return NULL if the list has zero entries. -*/ -static char **stringlist_alloc_char__(const stringlist_type *stringlist, - bool deep_copy) { - char **strings = NULL; - int size = stringlist_get_size(stringlist); - if (size > 0) { - int i; - strings = (char **)util_calloc(size, sizeof *strings); - for (i = 0; i < size; i++) { - if (deep_copy) - strings[i] = stringlist_iget_copy(stringlist, i); - else - strings[i] = (char *)stringlist_iget(stringlist, i); - } - } - return strings; -} - -char **stringlist_alloc_char_copy(const stringlist_type *stringlist) { - return stringlist_alloc_char__(stringlist, true); -} - -char **stringlist_alloc_char_ref(const stringlist_type *stringlist) { - return stringlist_alloc_char__(stringlist, false); -} - /** Scans the stringlist (linear scan) to see if it contains (at least) one occurence of 's'. Will never return true if the input @@ -446,105 +233,6 @@ bool stringlist_equal(const stringlist_type *s1, const stringlist_type *s2) { return false; } -/** - The interval is halfopen: [start_index , end_index). -*/ - -/* Based on buffer?? */ - -char *stringlist_alloc_joined_substring(const stringlist_type *s, - int start_index, int end_index, - const char *sep) { - if (start_index >= stringlist_get_size(s)) - return util_alloc_string_copy(""); - { - char *string = NULL; - int i; - - /* Start with allocating a string long enough to hold all the substrings. */ - { - int sep_length = strlen(sep); - int total_length = 0; - for (i = start_index; i < end_index; i++) - total_length += (strlen(stringlist_iget(s, i)) + sep_length); - - total_length += (1 - sep_length); - string = (char *)util_malloc(total_length * sizeof *string); - string[0] = '\0'; - } - - for (i = start_index; i < end_index; i++) { - strcat(string, stringlist_iget(s, i)); - if (i < (end_index - 1)) - strcat(string, sep); - } - - return string; - } -} - -char *stringlist_alloc_joined_string(const stringlist_type *s, - const char *sep) { - return stringlist_alloc_joined_substring(s, 0, stringlist_get_size(s), sep); -} - -/** - This function will allocate a stringlist instance based on - splitting the input string. If the input string is NULL the - function will return a stringlist instance with zero elements. - - Observe that the splitting is based on __ANY__ character in @sep; - NOT the full exact string @sep. - - The newly allocated stringlist will take ownership of the strings - in the list. The actual functionality is in the util_split_string() - function. -*/ - -stringlist_type *stringlist_alloc_from_split(const char *input_string, - const char *sep) { - stringlist_type *slist = stringlist_alloc_new(); - if (input_string != NULL) { - char **items; - int num_items, i; - util_split_string(input_string, sep, &num_items, &items); - for (i = 0; i < num_items; i++) - stringlist_append_copy(slist, items[i]); - util_free_stringlist(items, num_items); - } - return slist; -} - -void stringlist_fwrite(const stringlist_type *s, FILE *stream) { - int i; - int size = stringlist_get_size(s); - util_fwrite_int(size, stream); - for (i = 0; i < size; i++) - util_fwrite_string(stringlist_iget(s, i), stream); -} - -/* - When a stringlist is loaded from file the current content of the - stringlist is discarded; and the stringlist becomes the owner of - all the data read in. -*/ -void stringlist_fread(stringlist_type *s, FILE *stream) { - int size = util_fread_int(stream); - int i; - stringlist_clear(s); - for (i = 0; i < size; i++) { - char *tmp = util_fread_alloc_string(stream); - stringlist_append_copy(s, tmp); - free(tmp); - } -} - -stringlist_type *stringlist_fread_alloc(FILE *stream) { - stringlist_type *s = stringlist_alloc_empty(true); - stringlist_fread(s, stream); - return s; -} - static int strcmp__(const void *__s1, const void *__s2) { const char *s1 = (const char *)__s1; const char *s2 = (const char *)__s2; @@ -711,49 +399,6 @@ int stringlist_select_files(stringlist_type *names, const char *path, return stringlist_get_size(names); } -int stringlist_append_matching_elements(stringlist_type *target, - const stringlist_type *src, - const char *pattern) { - int ielm; - int match_count = 0; - for (ielm = 0; ielm < stringlist_get_size(src); ielm++) { - const char *item = stringlist_iget(src, ielm); - if (util_fnmatch(pattern, item) == 0) { - stringlist_append_copy(target, item); - match_count++; - } - } - return match_count; -} - -int stringlist_select_matching_elements(stringlist_type *target, - const stringlist_type *src, - const char *pattern) { - stringlist_clear(target); - return stringlist_append_matching_elements(target, src, pattern); -} - -static int void_strcmp(const void *s1, const void *s2) { - return strcmp((char *)s1, (char *)s2); -} - -bool stringlist_unique(const stringlist_type *stringlist) { - bool unique = true; - stringlist_type *cpy = stringlist_alloc_deep_copy(stringlist); - - stringlist_sort(cpy, void_strcmp); - for (int i = 0; i < stringlist_get_size(cpy) - 1; i++) { - const char *s1 = stringlist_iget(cpy, i); - const char *s2 = stringlist_iget(cpy, i + 1); - if (strcmp(s1, s2) == 0) { - unique = false; - break; - } - } - stringlist_free(cpy); - return unique; -} - #ifdef __cplusplus } #endif diff --git a/lib/util/tests/ert_util_stringlist_test.cpp b/lib/util/tests/ert_util_stringlist_test.cpp index 4440e0bcf..160396991 100644 --- a/lib/util/tests/ert_util_stringlist_test.cpp +++ b/lib/util/tests/ert_util_stringlist_test.cpp @@ -16,79 +16,6 @@ void test_char() { stringlist_append_copy(s, S2); stringlist_append_copy(s, S3); - { - char **copy = stringlist_alloc_char_copy(s); - int i; - bool equal = true; - - for (i = 0; i < stringlist_get_size(s); i++) { - if (strcmp(stringlist_iget(s, i), copy[i]) != 0) - equal = false; - free(copy[i]); - } - free(copy); - if (!equal) - test_assert_false("Bug in test_char() function\n"); - } - stringlist_free(s); -} - -void test_alloc_join(const stringlist_type *s, const char *sep, - const char *expected) { - char *j = stringlist_alloc_joined_string(s, sep); - test_assert_string_equal(j, expected); - free(j); -} - -void test_join() { - const char *elt0 = "AAA"; - const char *elt1 = "BBB"; - const char *elt2 = "CCC"; - const char *elt3 = "DDD"; - const char *elt4 = "EEE"; - const char *elt5 = "FFF"; - - stringlist_type *s = stringlist_alloc_new(); - test_alloc_join(s, "!!!", ""); - - stringlist_append_copy(s, elt0); - stringlist_append_copy(s, elt1); - stringlist_append_copy(s, elt2); - - const char *sep0 = ""; - const char *sep1 = "!!!"; - const char *sep2 = " abc "; - - test_alloc_join(s, sep0, "AAABBBCCC"); - test_alloc_join(s, sep1, "AAA!!!BBB!!!CCC"); - test_alloc_join(s, sep2, "AAA abc BBB abc CCC"); - - { - stringlist_type *s1 = stringlist_alloc_new(); - - stringlist_append_copy(s1, elt0); - test_alloc_join(s1, sep0, "AAA"); - test_alloc_join(s1, sep1, "AAA"); - test_alloc_join(s1, sep2, "AAA"); - - stringlist_free(s1); - } - { - stringlist_type *sub = stringlist_alloc_new(); - stringlist_append_copy(sub, elt0); - stringlist_append_copy(sub, elt1); - stringlist_append_copy(sub, elt2); - stringlist_append_copy(sub, elt3); - stringlist_append_copy(sub, elt4); - stringlist_append_copy(sub, elt5); - { - char *j = stringlist_alloc_joined_substring(sub, 2, 5, ":"); - test_assert_string_equal("CCC:DDD:EEE", j); - free(j); - } - - stringlist_free(sub); - } stringlist_free(s); } @@ -111,30 +38,6 @@ void test_reverse() { stringlist_free(s); } -void test_iget_as_int() { - stringlist_type *s = stringlist_alloc_new(); - stringlist_append_copy(s, "1000"); - stringlist_append_copy(s, "1000X"); - stringlist_append_copy(s, "XXXX"); - - { - int value; - bool valid; - - value = stringlist_iget_as_int(s, 0, &valid); - test_assert_int_equal(value, 1000); - test_assert_true(valid); - - value = stringlist_iget_as_int(s, 1, &valid); - test_assert_int_equal(value, -1); - test_assert_false(valid); - - value = stringlist_iget_as_int(s, 2, NULL); - test_assert_int_equal(value, -1); - } - stringlist_free(s); -} - void test_iget_as_double() { stringlist_type *s = stringlist_alloc_new(); stringlist_append_copy(s, "1000.90"); @@ -160,81 +63,8 @@ void test_iget_as_double() { stringlist_free(s); } -void test_iget_as_bool() { - stringlist_type *s = stringlist_alloc_new(); - stringlist_append_copy(s, "TRUE"); - stringlist_append_copy(s, "True"); - stringlist_append_copy(s, "true"); - stringlist_append_copy(s, "T"); - stringlist_append_copy(s, "1"); - - stringlist_append_copy(s, "FALSE"); - stringlist_append_copy(s, "False"); - stringlist_append_copy(s, "false"); - stringlist_append_copy(s, "F"); - stringlist_append_copy(s, "0"); - - stringlist_append_copy(s, "not_so_bool"); - stringlist_append_copy(s, "8"); - - { - bool value = false; - bool valid = false; - - value = stringlist_iget_as_bool(s, 0, &valid); - test_assert_true(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 1, &valid); - test_assert_true(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 2, &valid); - test_assert_true(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 3, &valid); - test_assert_true(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 4, &valid); - test_assert_true(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 5, &valid); - test_assert_false(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 6, &valid); - test_assert_false(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 7, &valid); - test_assert_false(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 8, &valid); - test_assert_false(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 9, &valid); - test_assert_false(value); - test_assert_true(valid); - - value = stringlist_iget_as_bool(s, 10, &valid); - test_assert_false(value); - test_assert_false(valid); - - value = stringlist_iget_as_bool(s, 11, &valid); - test_assert_false(value); - test_assert_false(valid); - } - stringlist_free(s); -} - void test_empty() { stringlist_type *s = stringlist_alloc_new(); - stringlist_fprintf(s, "\n", stdout); stringlist_free(s); } @@ -251,83 +81,6 @@ void test_front_back() { stringlist_free(s); } -void test_split() { - stringlist_type *s1 = - stringlist_alloc_from_split("My Name is Joakim Hove", " "); - test_assert_int_equal(5, stringlist_get_size(s1)); - test_assert_string_equal("My", stringlist_iget(s1, 0)); - test_assert_string_equal("Name", stringlist_iget(s1, 1)); - test_assert_string_equal("is", stringlist_iget(s1, 2)); - test_assert_string_equal("Joakim", stringlist_iget(s1, 3)); - test_assert_string_equal("Hove", stringlist_iget(s1, 4)); - stringlist_free(s1); - - s1 = stringlist_alloc_from_split("StringWithNoSPlit", " "); - test_assert_int_equal(1, stringlist_get_size(s1)); - test_assert_string_equal("StringWithNoSPlit", stringlist_iget(s1, 0)); - stringlist_free(s1); - - s1 = stringlist_alloc_from_split("A:B::C:D:", ":"); - test_assert_int_equal(4, stringlist_get_size(s1)); - test_assert_string_equal("A", stringlist_iget(s1, 0)); - test_assert_string_equal("B", stringlist_iget(s1, 1)); - test_assert_string_equal("C", stringlist_iget(s1, 2)); - test_assert_string_equal("D", stringlist_iget(s1, 3)); - stringlist_free(s1); - - s1 = stringlist_alloc_from_split("A:B::C:D:", "::"); - test_assert_int_equal(4, stringlist_get_size(s1)); - test_assert_string_equal("A", stringlist_iget(s1, 0)); - test_assert_string_equal("B", stringlist_iget(s1, 1)); - test_assert_string_equal("C", stringlist_iget(s1, 2)); - test_assert_string_equal("D", stringlist_iget(s1, 3)); - stringlist_free(s1); -} - -void test_matching() { - stringlist_type *s1 = stringlist_alloc_new(); - stringlist_type *s2 = stringlist_alloc_new(); - - stringlist_append_copy(s1, "AAA"); - stringlist_append_copy(s1, "ABC"); - stringlist_append_copy(s1, "123"); - stringlist_append_copy(s1, "ABC:123"); - - stringlist_select_matching_elements(s2, s1, "*"); - test_assert_int_equal(4, stringlist_get_size(s2)); - test_assert_string_equal("AAA", stringlist_iget(s2, 0)); - test_assert_string_equal("ABC", stringlist_iget(s2, 1)); - test_assert_string_equal("123", stringlist_iget(s2, 2)); - test_assert_string_equal("ABC:123", stringlist_iget(s2, 3)); - - stringlist_select_matching_elements(s2, s1, "*"); - test_assert_int_equal(4, stringlist_get_size(s2)); - test_assert_string_equal("AAA", stringlist_iget(s2, 0)); - test_assert_string_equal("ABC", stringlist_iget(s2, 1)); - test_assert_string_equal("123", stringlist_iget(s2, 2)); - test_assert_string_equal("ABC:123", stringlist_iget(s2, 3)); - - stringlist_append_matching_elements(s2, s1, "*"); - test_assert_int_equal(8, stringlist_get_size(s2)); - test_assert_string_equal("AAA", stringlist_iget(s2, 0)); - test_assert_string_equal("ABC", stringlist_iget(s2, 1)); - test_assert_string_equal("123", stringlist_iget(s2, 2)); - test_assert_string_equal("ABC:123", stringlist_iget(s2, 3)); - - test_assert_string_equal("AAA", stringlist_iget(s2, 4)); - test_assert_string_equal("ABC", stringlist_iget(s2, 5)); - test_assert_string_equal("123", stringlist_iget(s2, 6)); - test_assert_string_equal("ABC:123", stringlist_iget(s2, 7)); - - stringlist_select_matching_elements(s2, s1, "*B*"); - test_assert_int_equal(2, stringlist_get_size(s2)); - test_assert_string_equal("ABC", stringlist_iget(s2, 0)); - test_assert_string_equal("ABC:123", stringlist_iget(s2, 1)); - - stringlist_free(s2); - stringlist_free(s1); -} - bool FILE_predicate(const char *name, const void *arg) { return util_string_equal("FILE.txt", name); } @@ -373,33 +126,11 @@ void test_predicate_matching() { stringlist_free(s); } -void test_unique() { - stringlist_type *s = stringlist_alloc_new(); - - test_assert_true(stringlist_unique(s)); - - stringlist_append_copy(s, "S1"); - test_assert_true(stringlist_unique(s)); - - stringlist_append_copy(s, "S2"); - test_assert_true(stringlist_unique(s)); - - stringlist_append_copy(s, "S2"); - test_assert_false(stringlist_unique(s)); - stringlist_free(s); -} - int main(int argc, char **argv) { test_empty(); test_char(); - test_join(); test_reverse(); - test_iget_as_int(); - test_iget_as_bool(); test_iget_as_double(); - test_split(); - test_matching(); - test_unique(); test_predicate_matching(); exit(0); }