Avoid non-ANSI pointer comparison. (#54344, Morten Welinder)
[platform/upstream/glib.git] / tests / strfunc-test.c
index 1f13831..eeb7c97 100644 (file)
@@ -92,6 +92,20 @@ str_check (gchar *str,
   return ok;
 }
 
+static gboolean
+strchomp_check (gchar *str,
+               gchar *expected)
+{
+  gchar *tmp = strdup (str);
+  gboolean ok;
+
+  g_strchomp (tmp);
+  ok = (strcmp (tmp, expected) == 0);
+  g_free (tmp);
+
+  return ok;
+}
+
 #define FOR_ALL_CTYPE(macro)   \
        macro(isalnum)          \
        macro(isalpha)          \
@@ -331,6 +345,15 @@ main (int   argc,
 
   #undef TEST_DIGIT
 
+  /* Tests for strchomp () */
+  TEST (NULL, strchomp_check ("", ""));
+  TEST (NULL, strchomp_check (" ", ""));
+  TEST (NULL, strchomp_check (" \t\r\n", ""));
+  TEST (NULL, strchomp_check ("a ", "a"));
+  TEST (NULL, strchomp_check ("a  ", "a"));
+  TEST (NULL, strchomp_check ("a a", "a a"));
+  TEST (NULL, strchomp_check ("a a ", "a a"));
+
   /* Tests for g_build_path, g_build_filename */
 
   TEST (NULL, str_check (g_build_path ("", NULL), ""));