mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 18:26:19 +01:00
Fixing glib/tests/strfuncs.c to conform to new test coding standards
This commit is contained in:
parent
95a5f63775
commit
b3eab1deaf
@ -199,50 +199,53 @@ test_is_to_digit (void)
|
|||||||
#undef TEST_DIGIT
|
#undef TEST_DIGIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strdup() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strdup (void)
|
test_strdup (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strdup (NULL);
|
g_assert_null (g_strdup (NULL));
|
||||||
g_assert (str == NULL);
|
|
||||||
|
|
||||||
str = g_strdup (GLIB_TEST_STRING);
|
str = g_strdup (GLIB_TEST_STRING);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strndup() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strndup (void)
|
test_strndup (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strndup (NULL, 3);
|
str = g_strndup (NULL, 3);
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
|
|
||||||
str = g_strndup ("aaaa", 5);
|
str = g_strndup ("aaaa", 5);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "aaaa");
|
g_assert_cmpstr (str, ==, "aaaa");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strndup ("aaaa", 2);
|
str = g_strndup ("aaaa", 2);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "aa");
|
g_assert_cmpstr (str, ==, "aa");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strdup_printf() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strdup_printf (void)
|
test_strdup_printf (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strdup_printf ("%05d %-5s", 21, "test");
|
str = g_strdup_printf ("%05d %-5s", 21, "test");
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "00021 test ");
|
g_assert_cmpstr (str, ==, "00021 test ");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strdupv() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strdupv (void)
|
test_strdupv (void)
|
||||||
{
|
{
|
||||||
@ -250,92 +253,96 @@ test_strdupv (void)
|
|||||||
gchar **copy;
|
gchar **copy;
|
||||||
|
|
||||||
copy = g_strdupv (NULL);
|
copy = g_strdupv (NULL);
|
||||||
g_assert (copy == NULL);
|
g_assert_null (copy);
|
||||||
|
|
||||||
copy = g_strdupv (vec);
|
copy = g_strdupv (vec);
|
||||||
g_assert (copy != NULL);
|
g_assert_nonnull (copy);
|
||||||
g_assert_cmpstr (copy[0], ==, "Foo");
|
g_assert_cmpstr (copy[0], ==, "Foo");
|
||||||
g_assert_cmpstr (copy[1], ==, "Bar");
|
g_assert_cmpstr (copy[1], ==, "Bar");
|
||||||
g_assert (copy[2] == NULL);
|
g_assert_null (copy[2]);
|
||||||
g_strfreev (copy);
|
g_strfreev (copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strfill() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strnfill (void)
|
test_strnfill (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strnfill (0, 'a');
|
str = g_strnfill (0, 'a');
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (*str == '\0');
|
g_assert_true (*str == '\0');
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strnfill (5, 'a');
|
str = g_strnfill (5, 'a');
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "aaaaa");
|
g_assert_cmpstr (str, ==, "aaaaa");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strconcat() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strconcat (void)
|
test_strconcat (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strconcat (GLIB_TEST_STRING, NULL);
|
str = g_strconcat (GLIB_TEST_STRING, NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strconcat (GLIB_TEST_STRING,
|
str = g_strconcat (GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
g_assert (g_strconcat (NULL, "bla", NULL) == NULL);
|
g_assert_null (g_strconcat (NULL, "bla", NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strjoin() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strjoin (void)
|
test_strjoin (void)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strjoin (NULL, NULL);
|
str = g_strjoin (NULL, NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (*str == '\0');
|
g_assert_true (*str == '\0');
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strjoin (":", NULL);
|
str = g_strjoin (":", NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (*str == '\0');
|
g_assert_true (*str == '\0');
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
|
str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strjoin (NULL,
|
str = g_strjoin (NULL,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strjoin (":",
|
str = g_strjoin (":",
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
GLIB_TEST_STRING,
|
GLIB_TEST_STRING,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
|
g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strcanon() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strcanon (void)
|
test_strcanon (void)
|
||||||
{
|
{
|
||||||
@ -349,24 +356,25 @@ test_strcanon (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
str = g_strcanon (NULL, "ab", 'y');
|
str = g_strcanon (NULL, "ab", 'y');
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
|
|
||||||
str = g_strdup ("abxabxab");
|
str = g_strdup ("abxabxab");
|
||||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
ret = g_strcanon (str, NULL, 'y');
|
ret = g_strcanon (str, NULL, 'y');
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (ret == NULL);
|
g_assert_null (ret);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
str = g_strdup ("abxabxab");
|
str = g_strdup ("abxabxab");
|
||||||
str = g_strcanon (str, "ab", 'y');
|
str = g_strcanon (str, "ab", 'y');
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "abyabyab");
|
g_assert_cmpstr (str, ==, "abyabyab");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strcompress() and g_strescape() functions with various cases */
|
||||||
static void
|
static void
|
||||||
test_strcompress_strescape (void)
|
test_strcompress_strescape (void)
|
||||||
{
|
{
|
||||||
@ -380,7 +388,7 @@ test_strcompress_strescape (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
str = g_strcompress (NULL);
|
str = g_strcompress (NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
|
|
||||||
/* trailing slashes are not allowed */
|
/* trailing slashes are not allowed */
|
||||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||||
@ -392,7 +400,7 @@ test_strcompress_strescape (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313\\12345z");
|
str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313\\12345z");
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313\12345z");
|
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313\12345z");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
@ -403,29 +411,30 @@ test_strcompress_strescape (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
str = g_strescape (NULL, NULL);
|
str = g_strescape (NULL, NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
|
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313");
|
g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313",
|
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313",
|
||||||
"\b\f\001\002\003\004");
|
"\b\f\001\002\003\004");
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\\v\003\\177\\234\\313");
|
g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\\v\003\\177\\234\\313");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
/* round trip */
|
/* round trip */
|
||||||
tmp = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
|
tmp = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
|
||||||
str = g_strcompress (tmp);
|
str = g_strcompress (tmp);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313");
|
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_ascii_strcasecmp() and g_ascii_strncasecmp() */
|
||||||
static void
|
static void
|
||||||
test_ascii_strcasecmp (void)
|
test_ascii_strcasecmp (void)
|
||||||
{
|
{
|
||||||
@ -437,13 +446,13 @@ test_ascii_strcasecmp (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_ascii_strcasecmp ("foo", NULL);
|
res = g_ascii_strcasecmp ("foo", NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_ascii_strcasecmp (NULL, "foo");
|
res = g_ascii_strcasecmp (NULL, "foo");
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
|
res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
|
||||||
@ -504,6 +513,7 @@ do_test_strchug (const gchar *str, const gchar *expected)
|
|||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_cmpint (res, ==, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strchug() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strchug (void)
|
test_strchug (void)
|
||||||
{
|
{
|
||||||
@ -539,6 +549,7 @@ do_test_strchomp (const gchar *str, const gchar *expected)
|
|||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_cmpint (res, ==, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strchomp() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strchomp (void)
|
test_strchomp (void)
|
||||||
{
|
{
|
||||||
@ -559,6 +570,7 @@ test_strchomp (void)
|
|||||||
do_test_strchomp ("a a ", "a a");
|
do_test_strchomp ("a a ", "a a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strreverse() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strreverse (void)
|
test_strreverse (void)
|
||||||
{
|
{
|
||||||
@ -571,22 +583,23 @@ test_strreverse (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
str = g_strreverse (NULL);
|
str = g_strreverse (NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
str = p = g_strdup ("abcde");
|
str = p = g_strdup ("abcde");
|
||||||
str = g_strreverse (str);
|
str = g_strreverse (str);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (p == str);
|
g_assert_true (p == str);
|
||||||
g_assert_cmpstr (str, ==, "edcba");
|
g_assert_cmpstr (str, ==, "edcba");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strncasecmp() functions */
|
||||||
static void
|
static void
|
||||||
test_strncasecmp (void)
|
test_strncasecmp (void)
|
||||||
{
|
{
|
||||||
g_assert (g_strncasecmp ("abc1", "ABC2", 3) == 0);
|
g_assert_cmpint (g_strncasecmp ("abc1", "ABC2", 3), ==, 0);
|
||||||
g_assert (g_strncasecmp ("abc1", "ABC2", 4) != 0);
|
g_assert_cmpint (g_strncasecmp ("abc1", "ABC2", 4), !=, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -599,71 +612,72 @@ test_strstr (void)
|
|||||||
|
|
||||||
/* strstr_len */
|
/* strstr_len */
|
||||||
res = g_strstr_len (haystack, 6, "xxx");
|
res = g_strstr_len (haystack, 6, "xxx");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
|
res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strstr_len (haystack, 3, "Bar");
|
res = g_strstr_len (haystack, 3, "Bar");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strstr_len (haystack, 6, "");
|
res = g_strstr_len (haystack, 6, "");
|
||||||
g_assert (res == haystack);
|
g_assert_true (res == haystack);
|
||||||
g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
|
g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
|
||||||
|
|
||||||
res = g_strstr_len (haystack, 6, "Bar");
|
res = g_strstr_len (haystack, 6, "Bar");
|
||||||
g_assert (res == haystack + 3);
|
g_assert_true (res == haystack + 3);
|
||||||
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
||||||
|
|
||||||
res = g_strstr_len (haystack, -1, "Bar");
|
res = g_strstr_len (haystack, -1, "Bar");
|
||||||
g_assert (res == haystack + 3);
|
g_assert_true (res == haystack + 3);
|
||||||
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
||||||
|
|
||||||
/* strrstr */
|
/* strrstr */
|
||||||
res = g_strrstr (haystack, "xxx");
|
res = g_strrstr (haystack, "xxx");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strrstr (haystack, "FooBarFooBarFooBar");
|
res = g_strrstr (haystack, "FooBarFooBarFooBar");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strrstr (haystack, "");
|
res = g_strrstr (haystack, "");
|
||||||
g_assert (res == haystack);
|
g_assert_true (res == haystack);
|
||||||
g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
|
g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
|
||||||
|
|
||||||
res = g_strrstr (haystack, "Bar");
|
res = g_strrstr (haystack, "Bar");
|
||||||
g_assert (res == haystack + 9);
|
g_assert_true (res == haystack + 9);
|
||||||
g_assert_cmpstr (res, ==, "BarFoo");
|
g_assert_cmpstr (res, ==, "BarFoo");
|
||||||
|
|
||||||
/* strrstr_len */
|
/* strrstr_len */
|
||||||
res = g_strrstr_len (haystack, 14, "xxx");
|
res = g_strrstr_len (haystack, 14, "xxx");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
|
res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strrstr_len (haystack, 3, "Bar");
|
res = g_strrstr_len (haystack, 3, "Bar");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
res = g_strrstr_len (haystack, 14, "BarFoo");
|
res = g_strrstr_len (haystack, 14, "BarFoo");
|
||||||
g_assert (res == haystack + 3);
|
g_assert_true (res == haystack + 3);
|
||||||
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
g_assert_cmpstr (res, ==, "BarFooBarFoo");
|
||||||
|
|
||||||
res = g_strrstr_len (haystack, 15, "BarFoo");
|
res = g_strrstr_len (haystack, 15, "BarFoo");
|
||||||
g_assert (res == haystack + 9);
|
g_assert_true (res == haystack + 9);
|
||||||
g_assert_cmpstr (res, ==, "BarFoo");
|
g_assert_cmpstr (res, ==, "BarFoo");
|
||||||
|
|
||||||
res = g_strrstr_len (haystack, -1, "BarFoo");
|
res = g_strrstr_len (haystack, -1, "BarFoo");
|
||||||
g_assert (res == haystack + 9);
|
g_assert_true (res == haystack + 9);
|
||||||
g_assert_cmpstr (res, ==, "BarFoo");
|
g_assert_cmpstr (res, ==, "BarFoo");
|
||||||
|
|
||||||
/* test case for strings with \0 in the middle */
|
/* test case for strings with \0 in the middle */
|
||||||
*(haystack + 7) = '\0';
|
*(haystack + 7) = '\0';
|
||||||
res = g_strstr_len (haystack, 15, "BarFoo");
|
res = g_strstr_len (haystack, 15, "BarFoo");
|
||||||
g_assert (res == NULL);
|
g_assert_null (res);
|
||||||
|
|
||||||
g_free (haystack);
|
g_free (haystack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_str_has_prefix() */
|
||||||
static void
|
static void
|
||||||
test_has_prefix (void)
|
test_has_prefix (void)
|
||||||
{
|
{
|
||||||
@ -675,13 +689,13 @@ test_has_prefix (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_str_has_prefix ("foo", NULL);
|
res = g_str_has_prefix ("foo", NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_str_has_prefix (NULL, "foo");
|
res = g_str_has_prefix (NULL, "foo");
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = g_str_has_prefix ("foo", "bar");
|
res = g_str_has_prefix ("foo", "bar");
|
||||||
@ -717,35 +731,35 @@ test_has_suffix (void)
|
|||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_str_has_suffix ("foo", NULL);
|
res = g_str_has_suffix ("foo", NULL);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
"*assertion*!= NULL*");
|
"*assertion*!= NULL*");
|
||||||
res = g_str_has_suffix (NULL, "foo");
|
res = g_str_has_suffix (NULL, "foo");
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert (res == FALSE);
|
g_assert_false (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = g_str_has_suffix ("foo", "bar");
|
res = g_str_has_suffix ("foo", "bar");
|
||||||
g_assert_cmpint (res, ==, FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("bar", "foobar");
|
res = g_str_has_suffix ("bar", "foobar");
|
||||||
g_assert_cmpint (res, ==, FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("foobar", "foo");
|
res = g_str_has_suffix ("foobar", "foo");
|
||||||
g_assert_cmpint (res, ==, FALSE);
|
g_assert_false (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("foobar", "bar");
|
res = g_str_has_suffix ("foobar", "bar");
|
||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("foo", "");
|
res = g_str_has_suffix ("foo", "");
|
||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("foo", "foo");
|
res = g_str_has_suffix ("foo", "foo");
|
||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_true (res);
|
||||||
|
|
||||||
res = g_str_has_suffix ("", "");
|
res = g_str_has_suffix ("", "");
|
||||||
g_assert_cmpint (res, ==, TRUE);
|
g_assert_true (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -761,7 +775,7 @@ strv_check (gchar **strv, ...)
|
|||||||
const gchar *str = va_arg (list, const char *);
|
const gchar *str = va_arg (list, const char *);
|
||||||
if (strv[i] == NULL)
|
if (strv[i] == NULL)
|
||||||
{
|
{
|
||||||
g_assert (str == NULL);
|
g_assert_null (str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
@ -779,6 +793,7 @@ strv_check (gchar **strv, ...)
|
|||||||
g_strfreev (strv);
|
g_strfreev (strv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strsplit() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strsplit (void)
|
test_strsplit (void)
|
||||||
{
|
{
|
||||||
@ -822,6 +837,7 @@ test_strsplit (void)
|
|||||||
strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL);
|
strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing function g_strsplit_set() */
|
||||||
static void
|
static void
|
||||||
test_strsplit_set (void)
|
test_strsplit_set (void)
|
||||||
{
|
{
|
||||||
@ -846,7 +862,7 @@ test_strsplit_set (void)
|
|||||||
strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL);
|
strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL);
|
||||||
strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL);
|
strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL);
|
||||||
strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL);
|
strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL);
|
||||||
|
|
||||||
strv_check (g_strsplit_set ("", ",", 0), NULL);
|
strv_check (g_strsplit_set ("", ",", 0), NULL);
|
||||||
strv_check (g_strsplit_set ("x", ",", 0), "x", NULL);
|
strv_check (g_strsplit_set ("x", ",", 0), "x", NULL);
|
||||||
strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL);
|
strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL);
|
||||||
@ -883,10 +899,11 @@ test_strsplit_set (void)
|
|||||||
strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL);
|
strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL);
|
||||||
strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
|
strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
|
||||||
strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
|
strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
|
||||||
|
|
||||||
strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
|
strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strv_length() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strv_length (void)
|
test_strv_length (void)
|
||||||
{
|
{
|
||||||
@ -914,13 +931,13 @@ static void
|
|||||||
check_strtod_string (gchar *number,
|
check_strtod_string (gchar *number,
|
||||||
double res,
|
double res,
|
||||||
gboolean check_end,
|
gboolean check_end,
|
||||||
gint correct_len)
|
gsize correct_len)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
gint l;
|
gsize l;
|
||||||
gchar *dummy;
|
gchar *dummy;
|
||||||
|
|
||||||
/* we try a copy of number, with some free space for malloc before that.
|
/* we try a copy of number, with some free space for malloc before that.
|
||||||
* This is supposed to smash the some wrong pointer calculations. */
|
* This is supposed to smash the some wrong pointer calculations. */
|
||||||
|
|
||||||
dummy = g_malloc (100000);
|
dummy = g_malloc (100000);
|
||||||
@ -933,8 +950,9 @@ check_strtod_string (gchar *number,
|
|||||||
|
|
||||||
setlocale (LC_NUMERIC, locales[l]);
|
setlocale (LC_NUMERIC, locales[l]);
|
||||||
d = g_ascii_strtod (number, &end);
|
d = g_ascii_strtod (number, &end);
|
||||||
g_assert (isnan (res) ? isnan (d) : (d == res));
|
g_assert_true (isnan (res) ? isnan (d) : (d == res));
|
||||||
g_assert ((end - number) == (check_end ? correct_len : strlen (number)));
|
g_assert_true ((gsize) (end - number) ==
|
||||||
|
(check_end ? correct_len : strlen (number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (number);
|
g_free (number);
|
||||||
@ -943,7 +961,7 @@ check_strtod_string (gchar *number,
|
|||||||
static void
|
static void
|
||||||
check_strtod_number (gdouble num, gchar *fmt, gchar *str)
|
check_strtod_number (gdouble num, gchar *fmt, gchar *str)
|
||||||
{
|
{
|
||||||
int l;
|
gsize l;
|
||||||
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||||
|
|
||||||
for (l = 0; l < G_N_ELEMENTS (locales); l++)
|
for (l = 0; l < G_N_ELEMENTS (locales); l++)
|
||||||
@ -954,8 +972,9 @@ check_strtod_number (gdouble num, gchar *fmt, gchar *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_ascii_strtod() function with various positive and negative cases */
|
||||||
static void
|
static void
|
||||||
test_strtod (void)
|
test_ascii_strtod (void)
|
||||||
{
|
{
|
||||||
gdouble d, our_nan, our_inf;
|
gdouble d, our_nan, our_inf;
|
||||||
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
|
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
|
||||||
@ -966,15 +985,25 @@ test_strtod (void)
|
|||||||
/* Do this before any call to setlocale. */
|
/* Do this before any call to setlocale. */
|
||||||
our_nan = atof ("NaN");
|
our_nan = atof ("NaN");
|
||||||
#endif
|
#endif
|
||||||
g_assert (isnan (our_nan));
|
g_assert_true (isnan (our_nan));
|
||||||
|
|
||||||
#ifdef INFINITY
|
#ifdef INFINITY
|
||||||
our_inf = INFINITY;
|
our_inf = INFINITY;
|
||||||
#else
|
#else
|
||||||
our_inf = atof ("Infinity");
|
our_inf = atof ("Infinity");
|
||||||
#endif
|
#endif
|
||||||
g_assert (our_inf > 1 && our_inf == our_inf / 2);
|
g_assert_true (our_inf > 1 && our_inf == our_inf / 2);
|
||||||
|
|
||||||
|
/* Testing degenerated cases */
|
||||||
|
if (g_test_undefined ())
|
||||||
|
{
|
||||||
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
|
"*assertion*!= NULL*");
|
||||||
|
d = g_ascii_strtod (NULL, NULL);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Testing normal cases */
|
||||||
check_strtod_string ("123.123", 123.123, FALSE, 0);
|
check_strtod_string ("123.123", 123.123, FALSE, 0);
|
||||||
check_strtod_string ("123.123e2", 123.123e2, FALSE, 0);
|
check_strtod_string ("123.123e2", 123.123e2, FALSE, 0);
|
||||||
check_strtod_string ("123.123e-2", 123.123e-2, FALSE, 0);
|
check_strtod_string ("123.123e-2", 123.123e-2, FALSE, 0);
|
||||||
@ -1006,17 +1035,17 @@ test_strtod (void)
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
/* the values of d in the following 2 tests generate a C1064 compiler limit error */
|
/* the values of d in the following 2 tests generate a C1064 compiler limit error */
|
||||||
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
||||||
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
||||||
|
|
||||||
d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
||||||
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
d = pow (2.0, -1024.1);
|
d = pow (2.0, -1024.1);
|
||||||
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
||||||
|
|
||||||
d = -pow (2.0, -1024.1);
|
d = -pow (2.0, -1024.1);
|
||||||
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
|
||||||
|
|
||||||
/* for #343899 */
|
/* for #343899 */
|
||||||
check_strtod_string (" 0.75", 0.75, FALSE, 0);
|
check_strtod_string (" 0.75", 0.75, FALSE, 0);
|
||||||
@ -1055,9 +1084,9 @@ check_uint64 (const gchar *str,
|
|||||||
actual = g_ascii_strtoull (str, &endptr, base);
|
actual = g_ascii_strtoull (str, &endptr, base);
|
||||||
err = errno;
|
err = errno;
|
||||||
|
|
||||||
g_assert (actual == result);
|
g_assert_true (actual == result);
|
||||||
g_assert_cmpstr (end, ==, endptr);
|
g_assert_cmpstr (end, ==, endptr);
|
||||||
g_assert (err == error);
|
g_assert_true (err == error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1075,9 +1104,9 @@ check_int64 (const gchar *str,
|
|||||||
actual = g_ascii_strtoll (str, &endptr, base);
|
actual = g_ascii_strtoll (str, &endptr, base);
|
||||||
err = errno;
|
err = errno;
|
||||||
|
|
||||||
g_assert (actual == result);
|
g_assert_true (actual == result);
|
||||||
g_assert_cmpstr (end, ==, endptr);
|
g_assert_cmpstr (end, ==, endptr);
|
||||||
g_assert (err == error);
|
g_assert_true (err == error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1103,6 +1132,7 @@ test_strtoll (void)
|
|||||||
check_int64 ("-001", "", 10, -1, 0);
|
check_int64 ("-001", "", 10, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing functions bounds */
|
||||||
static void
|
static void
|
||||||
test_bounds (void)
|
test_bounds (void)
|
||||||
{
|
{
|
||||||
@ -1129,12 +1159,12 @@ test_bounds (void)
|
|||||||
g_mapped_file_unref (before);
|
g_mapped_file_unref (before);
|
||||||
g_mapped_file_unref (after);
|
g_mapped_file_unref (after);
|
||||||
|
|
||||||
g_assert (file != NULL);
|
g_assert_nonnull (file);
|
||||||
g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
|
g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
|
||||||
string = g_mapped_file_get_contents (file);
|
string = g_mapped_file_get_contents (file);
|
||||||
|
|
||||||
/* ensure they're all non-nul */
|
/* ensure they're all non-nul */
|
||||||
g_assert (memchr (string, '\0', 4096) == NULL);
|
g_assert_null (memchr (string, '\0', 4096));
|
||||||
|
|
||||||
/* test set 1: ensure that nothing goes past its maximum length, even in
|
/* test set 1: ensure that nothing goes past its maximum length, even in
|
||||||
* light of a missing nul terminator.
|
* light of a missing nul terminator.
|
||||||
@ -1146,7 +1176,7 @@ test_bounds (void)
|
|||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
|
||||||
/* found no bugs in gnome, i hope :) */
|
/* found no bugs in gnome, i hope :) */
|
||||||
g_assert (g_strstr_len (string, 4096, "BUGS") == NULL);
|
g_assert_null (g_strstr_len (string, 4096, "BUGS"));
|
||||||
g_strstr_len (string, 4096, "B");
|
g_strstr_len (string, 4096, "B");
|
||||||
g_strstr_len (string, 4096, ".");
|
g_strstr_len (string, 4096, ".");
|
||||||
g_strstr_len (string, 4096, "");
|
g_strstr_len (string, 4096, "");
|
||||||
@ -1225,8 +1255,8 @@ test_bounds (void)
|
|||||||
|
|
||||||
tmp = g_ascii_strdown (string, -1);
|
tmp = g_ascii_strdown (string, -1);
|
||||||
tmp2 = g_ascii_strdown (tmp, -1);
|
tmp2 = g_ascii_strdown (tmp, -1);
|
||||||
g_assert_cmpint (strlen(tmp), ==, strlen(tmp2));
|
g_assert_cmpint (strlen (tmp), ==, strlen (tmp2));
|
||||||
g_assert_cmpint (strlen(string), ==, strlen(tmp));
|
g_assert_cmpint (strlen (string), ==, strlen (tmp));
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
|
||||||
@ -1235,8 +1265,8 @@ test_bounds (void)
|
|||||||
|
|
||||||
tmp = g_ascii_strup (string, -1);
|
tmp = g_ascii_strup (string, -1);
|
||||||
tmp2 = g_ascii_strup (string, -1);
|
tmp2 = g_ascii_strup (string, -1);
|
||||||
g_assert_cmpint (strlen(tmp), ==, strlen(tmp2));
|
g_assert_cmpint (strlen (tmp), ==, strlen (tmp2));
|
||||||
g_assert_cmpint (strlen(string), ==, strlen(tmp));
|
g_assert_cmpint (strlen (string), ==, strlen (tmp));
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
|
||||||
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
|
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
|
||||||
@ -1295,6 +1325,7 @@ test_bounds (void)
|
|||||||
g_mapped_file_unref (file);
|
g_mapped_file_unref (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strip_context() function with various cases */
|
||||||
static void
|
static void
|
||||||
test_strip_context (void)
|
test_strip_context (void)
|
||||||
{
|
{
|
||||||
@ -1302,23 +1333,22 @@ test_strip_context (void)
|
|||||||
const gchar *msgval;
|
const gchar *msgval;
|
||||||
const gchar *s;
|
const gchar *s;
|
||||||
|
|
||||||
|
|
||||||
msgid = "blabla";
|
msgid = "blabla";
|
||||||
msgval = "bla";
|
msgval = "bla";
|
||||||
s = g_strip_context (msgid, msgval);
|
s = g_strip_context (msgid, msgval);
|
||||||
g_assert (s == msgval);
|
g_assert_true (s == msgval);
|
||||||
|
|
||||||
msgid = msgval = "blabla";
|
msgid = msgval = "blabla";
|
||||||
s = g_strip_context (msgid, msgval);
|
s = g_strip_context (msgid, msgval);
|
||||||
g_assert (s == msgval);
|
g_assert_true (s == msgval);
|
||||||
|
|
||||||
msgid = msgval = "blabla|foo";
|
msgid = msgval = "blabla|foo";
|
||||||
s = g_strip_context (msgid, msgval);
|
s = g_strip_context (msgid, msgval);
|
||||||
g_assert (s == msgval + 7);
|
g_assert_true (s == msgval + 7);
|
||||||
|
|
||||||
msgid = msgval = "blabla||bar";
|
msgid = msgval = "blabla||bar";
|
||||||
s = g_strip_context (msgid, msgval);
|
s = g_strip_context (msgid, msgval);
|
||||||
g_assert (s == msgval + 7);
|
g_assert_true (s == msgval + 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the strings returned by g_strerror() are valid and unique. On Windows,
|
/* Test the strings returned by g_strerror() are valid and unique. On Windows,
|
||||||
@ -1340,8 +1370,8 @@ test_strerror (void)
|
|||||||
gboolean is_unknown;
|
gboolean is_unknown;
|
||||||
str = g_strerror (i);
|
str = g_strerror (i);
|
||||||
is_unknown = (strcmp (str, unknown_str) == 0);
|
is_unknown = (strcmp (str, unknown_str) == 0);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (g_utf8_validate (str, -1, NULL));
|
g_assert_true (g_utf8_validate (str, -1, NULL));
|
||||||
g_assert_true (!g_hash_table_contains (strs, str) || is_unknown);
|
g_assert_true (!g_hash_table_contains (strs, str) || is_unknown);
|
||||||
g_hash_table_add (strs, (char *)str);
|
g_hash_table_add (strs, (char *)str);
|
||||||
}
|
}
|
||||||
@ -1349,6 +1379,7 @@ test_strerror (void)
|
|||||||
g_hash_table_unref (strs);
|
g_hash_table_unref (strs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strsignal() function with various cases */
|
||||||
static void
|
static void
|
||||||
test_strsignal (void)
|
test_strsignal (void)
|
||||||
{
|
{
|
||||||
@ -1358,11 +1389,12 @@ test_strsignal (void)
|
|||||||
for (i = 1; i < 20; i++)
|
for (i = 1; i < 20; i++)
|
||||||
{
|
{
|
||||||
str = g_strsignal (i);
|
str = g_strsignal (i);
|
||||||
g_assert (str != NULL);
|
g_assert_nonnull (str);
|
||||||
g_assert (g_utf8_validate (str, -1, NULL));
|
g_assert_true (g_utf8_validate (str, -1, NULL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strup(), g_strdown() and g_strcasecmp() */
|
||||||
static void
|
static void
|
||||||
test_strup (void)
|
test_strup (void)
|
||||||
{
|
{
|
||||||
@ -1371,10 +1403,11 @@ test_strup (void)
|
|||||||
s = g_strdup ("lower");
|
s = g_strdup ("lower");
|
||||||
g_assert_cmpstr (g_strup (s), ==, "LOWER");
|
g_assert_cmpstr (g_strup (s), ==, "LOWER");
|
||||||
g_assert_cmpstr (g_strdown (s), ==, "lower");
|
g_assert_cmpstr (g_strdown (s), ==, "lower");
|
||||||
g_assert (g_strcasecmp ("lower", "LOWER") == 0);
|
g_assert_cmpint (g_strcasecmp ("lower", "LOWER"), ==, 0);
|
||||||
g_free (s);
|
g_free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_str_to_ascii() function with various cases */
|
||||||
static void
|
static void
|
||||||
test_transliteration (void)
|
test_transliteration (void)
|
||||||
{
|
{
|
||||||
@ -1481,12 +1514,13 @@ test_transliteration (void)
|
|||||||
g_free (out);
|
g_free (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing g_strv_contains() function with various cases */
|
||||||
static void
|
static void
|
||||||
test_strv_contains (void)
|
test_strv_contains (void)
|
||||||
{
|
{
|
||||||
static const gchar *strv_simple[] = { "hello", "there", NULL };
|
const gchar *strv_simple[] = { "hello", "there", NULL };
|
||||||
static const gchar *strv_dupe[] = { "dupe", "dupe", NULL };
|
const gchar *strv_dupe[] = { "dupe", "dupe", NULL };
|
||||||
static const gchar *strv_empty[] = { NULL };
|
const gchar *strv_empty[] = { NULL };
|
||||||
|
|
||||||
g_assert_true (g_strv_contains (strv_simple, "hello"));
|
g_assert_true (g_strv_contains (strv_simple, "hello"));
|
||||||
g_assert_true (g_strv_contains (strv_simple, "there"));
|
g_assert_true (g_strv_contains (strv_simple, "there"));
|
||||||
@ -1609,11 +1643,13 @@ const TestData test_data[] = {
|
|||||||
{ "+ 0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
|
{ "+ 0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Testing g_ascii_string_to_signed() and g_ascii_string_to_unsigned() functions */
|
||||||
static void
|
static void
|
||||||
test_ascii_string_to_number_usual (void)
|
test_ascii_string_to_number_usual (void)
|
||||||
{
|
{
|
||||||
gsize idx;
|
gsize idx;
|
||||||
|
|
||||||
|
/* Testing usual cases */
|
||||||
for (idx = 0; idx < G_N_ELEMENTS (test_data); ++idx)
|
for (idx = 0; idx < G_N_ELEMENTS (test_data); ++idx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -1658,7 +1694,7 @@ test_ascii_string_to_number_usual (void)
|
|||||||
if (data->should_fail)
|
if (data->should_fail)
|
||||||
{
|
{
|
||||||
g_assert_false (result);
|
g_assert_false (result);
|
||||||
g_assert_error (error, G_NUMBER_PARSER_ERROR, data->error_code);
|
g_assert_error (error, G_NUMBER_PARSER_ERROR, (gint) data->error_code);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1670,6 +1706,7 @@ test_ascii_string_to_number_usual (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Testing pathological cases for g_ascii_string_to_(un)signed() */
|
||||||
static void
|
static void
|
||||||
test_ascii_string_to_number_pathological (void)
|
test_ascii_string_to_number_pathological (void)
|
||||||
{
|
{
|
||||||
@ -1751,39 +1788,39 @@ main (int argc,
|
|||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
|
|
||||||
g_test_add_func ("/strfuncs/strdup", test_strdup);
|
|
||||||
g_test_add_func ("/strfuncs/strndup", test_strndup);
|
|
||||||
g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
|
|
||||||
g_test_add_func ("/strfuncs/strdupv", test_strdupv);
|
|
||||||
g_test_add_func ("/strfuncs/strnfill", test_strnfill);
|
|
||||||
g_test_add_func ("/strfuncs/strconcat", test_strconcat);
|
|
||||||
g_test_add_func ("/strfuncs/strjoin", test_strjoin);
|
|
||||||
g_test_add_func ("/strfuncs/strcanon", test_strcanon);
|
|
||||||
g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
|
|
||||||
g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
|
g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
|
||||||
g_test_add_func ("/strfuncs/strchug", test_strchug);
|
g_test_add_func ("/strfuncs/ascii-string-to-num/pathological", test_ascii_string_to_number_pathological);
|
||||||
g_test_add_func ("/strfuncs/strchomp", test_strchomp);
|
g_test_add_func ("/strfuncs/ascii-string-to-num/usual", test_ascii_string_to_number_usual);
|
||||||
g_test_add_func ("/strfuncs/strreverse", test_strreverse);
|
g_test_add_func ("/strfuncs/ascii_strtod", test_ascii_strtod);
|
||||||
g_test_add_func ("/strfuncs/strncasecmp", test_strncasecmp);
|
g_test_add_func ("/strfuncs/bounds-check", test_bounds);
|
||||||
g_test_add_func ("/strfuncs/strstr", test_strstr);
|
|
||||||
g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
|
g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
|
||||||
g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
|
g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
|
||||||
|
g_test_add_func ("/strfuncs/strcanon", test_strcanon);
|
||||||
|
g_test_add_func ("/strfuncs/strchomp", test_strchomp);
|
||||||
|
g_test_add_func ("/strfuncs/strchug", test_strchug);
|
||||||
|
g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
|
||||||
|
g_test_add_func ("/strfuncs/strconcat", test_strconcat);
|
||||||
|
g_test_add_func ("/strfuncs/strdup", test_strdup);
|
||||||
|
g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
|
||||||
|
g_test_add_func ("/strfuncs/strdupv", test_strdupv);
|
||||||
|
g_test_add_func ("/strfuncs/strerror", test_strerror);
|
||||||
|
g_test_add_func ("/strfuncs/strip-context", test_strip_context);
|
||||||
|
g_test_add_func ("/strfuncs/strjoin", test_strjoin);
|
||||||
|
g_test_add_func ("/strfuncs/strncasecmp", test_strncasecmp);
|
||||||
|
g_test_add_func ("/strfuncs/strndup", test_strndup);
|
||||||
|
g_test_add_func ("/strfuncs/strnfill", test_strnfill);
|
||||||
|
g_test_add_func ("/strfuncs/strreverse", test_strreverse);
|
||||||
|
g_test_add_func ("/strfuncs/strsignal", test_strsignal);
|
||||||
g_test_add_func ("/strfuncs/strsplit", test_strsplit);
|
g_test_add_func ("/strfuncs/strsplit", test_strsplit);
|
||||||
g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
|
g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
|
||||||
g_test_add_func ("/strfuncs/strv-length", test_strv_length);
|
g_test_add_func ("/strfuncs/strstr", test_strstr);
|
||||||
g_test_add_func ("/strfuncs/strtod", test_strtod);
|
|
||||||
g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
|
g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
|
||||||
g_test_add_func ("/strfuncs/bounds-check", test_bounds);
|
|
||||||
g_test_add_func ("/strfuncs/strip-context", test_strip_context);
|
|
||||||
g_test_add_func ("/strfuncs/strerror", test_strerror);
|
|
||||||
g_test_add_func ("/strfuncs/strsignal", test_strsignal);
|
|
||||||
g_test_add_func ("/strfuncs/strup", test_strup);
|
g_test_add_func ("/strfuncs/strup", test_strup);
|
||||||
g_test_add_func ("/strfuncs/transliteration", test_transliteration);
|
|
||||||
g_test_add_func ("/strfuncs/strv-contains", test_strv_contains);
|
g_test_add_func ("/strfuncs/strv-contains", test_strv_contains);
|
||||||
g_test_add_func ("/strfuncs/strv-equal", test_strv_equal);
|
g_test_add_func ("/strfuncs/strv-equal", test_strv_equal);
|
||||||
g_test_add_func ("/strfuncs/ascii-string-to-num/usual", test_ascii_string_to_number_usual);
|
g_test_add_func ("/strfuncs/strv-length", test_strv_length);
|
||||||
g_test_add_func ("/strfuncs/ascii-string-to-num/pathological", test_ascii_string_to_number_pathological);
|
g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
|
||||||
|
g_test_add_func ("/strfuncs/transliteration", test_transliteration);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user