Просмотр исходного кода

libdpkg: Improve branch coverage for string module

Guillem Jover лет назад: 12
Родитель
Сommit
d8f78de9b0
2 измененных файлов с 18 добавлено и 7 удалено
  1. 2 0
      debian/changelog
  2. 16 7
      lib/dpkg/test/t-string.c

+ 2 - 0
debian/changelog

@@ -8,6 +8,8 @@ dpkg (1.17.10) UNRELEASED; urgency=low
   * Fix possible out of bounds buffer read access in the error output on
     bogus ar member sizes.
   * Fix memory leaks in buffer_copy() on error conditions.
+  * Test suite:
+    - Improve C code coverage.
 
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).

+ 16 - 7
lib/dpkg/test/t-string.c

@@ -47,6 +47,7 @@ test_str_match_end(void)
 	test_pass(str_match_end("foo bar quux", "quux"));
 	test_pass(str_match_end("foo bar quux", "bar quux"));
 	test_pass(str_match_end("foo bar quux", "foo bar quux"));
+	test_fail(str_match_end("foo bar quux", "foo bar quux zorg"));
 	test_fail(str_match_end("foo bar quux", "foo bar"));
 	test_fail(str_match_end("foo bar quux", "foo"));
 }
@@ -77,6 +78,14 @@ test_str_escape_fmt(void)
 	test_str(buf, ==, "%%b%%b%%c%%c%%%% end");
 
 	/* Test delimited buffer. */
+	memset(buf, 'a', sizeof(buf));
+	q = str_escape_fmt(buf, NULL, 0);
+	test_mem(buf, ==, "aaaa", 4);
+
+	memset(buf, 'a', sizeof(buf));
+	q = str_escape_fmt(buf, "b", 1);
+	test_str(q, ==, "");
+
 	memset(buf, 'a', sizeof(buf));
 	q = str_escape_fmt(buf, "%%%", 5);
 	strcpy(q, " end");
@@ -93,16 +102,16 @@ test_str_quote_meta(void)
 {
 	char *str;
 
-	str = str_quote_meta("foo bar");
-	test_str(str, ==, "foo\\ bar");
+	str = str_quote_meta("foo1 2bar");
+	test_str(str, ==, "foo1\\ 2bar");
 	free(str);
 
-	str = str_quote_meta("foo?bar");
-	test_str(str, ==, "foo\\?bar");
+	str = str_quote_meta("foo1?2bar");
+	test_str(str, ==, "foo1\\?2bar");
 	free(str);
 
-	str = str_quote_meta("foo*bar");
-	test_str(str, ==, "foo\\*bar");
+	str = str_quote_meta("foo1*2bar");
+	test_str(str, ==, "foo1\\*2bar");
 	free(str);
 }
 
@@ -151,7 +160,7 @@ test_str_strip_quotes(void)
 static void
 test(void)
 {
-	test_plan(29);
+	test_plan(32);
 
 	test_str_is_set();
 	test_str_match_end();