mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
[gnc-glib-utils] Define and export gnc_list_length_cmp
This commit is contained in:
parent
b5f5129f7d
commit
3dfdf60608
@ -351,3 +351,13 @@ gnc_g_list_stringjoin (GList *list_of_strings, const gchar *sep)
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gint
|
||||
gnc_list_length_cmp (const GList *list, size_t len)
|
||||
{
|
||||
for (GList *lst = (GList*) list;; lst = g_list_next (lst), len--)
|
||||
{
|
||||
if (!lst) return (len ? -1 : 0);
|
||||
if (!len) return 1;
|
||||
}
|
||||
}
|
||||
|
@ -199,6 +199,20 @@ void gnc_scm_log_debug(const gchar *msg);
|
||||
**/
|
||||
gchar * gnc_g_list_stringjoin (GList *list_of_strings, const gchar *sep);
|
||||
|
||||
/**
|
||||
* @brief Scans the GList elements the minimum number of iterations
|
||||
* required to test it against a specified size. Returns -1, 0 or 1
|
||||
* depending on whether the GList length has less, same, or more
|
||||
* elements than the size specified.
|
||||
*
|
||||
* @param lst A GList
|
||||
*
|
||||
* @param len the comparator length to compare the GList length with
|
||||
*
|
||||
* @return A signed int comparing GList length with specified size.
|
||||
**/
|
||||
gint gnc_list_length_cmp (const GList *list, size_t len);
|
||||
|
||||
/** Kill a process. On UNIX send a SIGKILL, on Windows call TerminateProcess.
|
||||
*
|
||||
* @param pid The process ID. */
|
||||
|
@ -110,6 +110,28 @@ test_g_list_stringjoin (gconstpointer data)
|
||||
g_list_free (test);
|
||||
}
|
||||
|
||||
static void
|
||||
test_gnc_list_length (gconstpointer data)
|
||||
{
|
||||
GList *lst = NULL;
|
||||
|
||||
g_assert (gnc_list_length_cmp (lst, 0) == 0);
|
||||
g_assert (gnc_list_length_cmp (lst, 1) == -1);
|
||||
|
||||
lst = g_list_prepend (lst, (gpointer)1);
|
||||
g_assert (gnc_list_length_cmp (lst, 0) == 1);
|
||||
g_assert (gnc_list_length_cmp (lst, 1) == 0);
|
||||
g_assert (gnc_list_length_cmp (lst, 2) == -1);
|
||||
|
||||
lst = g_list_prepend (lst, (gpointer)2);
|
||||
g_assert (gnc_list_length_cmp (lst, 1) == 1);
|
||||
g_assert (gnc_list_length_cmp (lst, 2) == 0);
|
||||
g_assert (gnc_list_length_cmp (lst, 3) == -1);
|
||||
|
||||
g_list_free (lst);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -119,6 +141,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_data_func ("/core-utils/gnc_utf8_strip_invalid_and_controls invalid utf8", (gconstpointer)invalid_utf8, test_gnc_utf8_strip_invalid_and_controls);
|
||||
g_test_add_data_func ("/core-utils/gnc_utf8_strip_invalid_and_controls control chars", (gconstpointer)controls, test_gnc_utf8_strip_invalid_and_controls);
|
||||
g_test_add_data_func ("/core-utils/gnc_g_list_stringjoin", NULL, test_g_list_stringjoin);
|
||||
g_test_add_data_func ("/core-utils/gnc_list_length", NULL, test_gnc_list_length);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user