]> granicus.if.org Git - neomutt/commitdiff
test: improve test_mutt_str_substr_cpy()
authorRichard Russon <rich@flatcap.org>
Sun, 26 May 2019 15:02:24 +0000 (16:02 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 26 May 2019 16:19:47 +0000 (17:19 +0100)
mutt/string.c
test/string/mutt_str_substr_cpy.c

index c6d7ad01eaae918c4b825f2c8f04bfc03fbba5af..92a0aa7ec930762403be6e32e20da218154e542f 100644 (file)
@@ -549,7 +549,7 @@ const char *mutt_str_strchrnul(const char *s, char c)
 /**
  * mutt_str_substr_cpy - Copy a sub-string into a buffer
  * @param dest    Buffer for the result
- * @param begin     Start of the string to copy
+ * @param begin   Start of the string to copy
  * @param end     End of the string to copy
  * @param destlen Length of buffer
  * @retval ptr Destination buffer
index c0d68598844d22e95f69c76573d3fc7ff62e106d..aa003122ef384477fe9a56a2cf251802fb21901b 100644 (file)
@@ -29,7 +29,7 @@ void test_mutt_str_substr_cpy(void)
 {
   // char *mutt_str_substr_cpy(char *dest, const char *begin, const char *end, size_t destlen);
 
-  const char *str = "apple banana";
+  const char *str = "apple banana\0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
   {
     TEST_CHECK(mutt_str_substr_cpy(NULL, str + 3, str + 7, 32) == NULL);
@@ -44,4 +44,27 @@ void test_mutt_str_substr_cpy(void)
     char buf[32] = { 0 };
     TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, NULL, sizeof(buf)) == buf);
   }
+
+  {
+    char buf[32] = { 0 };
+    TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 7, 0) == buf);
+  }
+
+  {
+    char buf[32] = { 0 };
+    TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 3, sizeof(buf)) == buf);
+    TEST_CHECK(strcmp(buf, "") == 0);
+  }
+
+  {
+    char buf[32] = { 0 };
+    TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 7, sizeof(buf)) == buf);
+    TEST_CHECK(strcmp(buf, "le b") == 0);
+  }
+
+  {
+    char buf[32] = { 0 };
+    TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 64, sizeof(buf)) == buf);
+    TEST_CHECK(strcmp(buf, "le banana") == 0);
+  }
 }