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

libdpkg: Improve version strict check unit test

The current test was using a single version with lots of invalid
characters, but only the first invalid character would get checked
against. Create a version per each invalid character to be tested
instead.
Guillem Jover лет назад: 15
Родитель
Сommit
be7a2c7829
1 измененных файлов с 19 добавлено и 3 удалено
  1. 19 3
      lib/dpkg/test/t-version.c

+ 19 - 3
lib/dpkg/test/t-version.c

@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * t-version.c - test version handling
  *
- * Copyright © 2009 Guillem Jover <guillem@debian.org>
+ * Copyright © 2009-2010 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,10 @@
 #include <config.h>
 #include <compat.h>
 
+#include <stdlib.h>
+
 #include <dpkg/test.h>
+#include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 
 #define version(epoch, version, revision) \
@@ -64,6 +67,8 @@ static void
 test_version_parse(void)
 {
 	struct versionrevision a, b;
+	const char *p;
+	char *verstr;
 
 	/* Test 0 versions. */
 	blankversion(&a);
@@ -137,11 +142,22 @@ test_version_parse(void)
 	test_fail(parseversion(&a, "A:0-0") == NULL);
 
 	/* Test invalid characters in upstream version. */
-	test_fail(parseversion(&a, "0:!#@$%&/|\\<>()[]{};,=*^'-0") == NULL);
+	verstr = m_strdup("0:0-0");
+	for (p = "!#@$%&/|\\<>()[]{};,_=*^'"; *p; p++) {
+		verstr[2] = *p;
+		test_fail(parseversion(&a, verstr) == NULL);
+	}
+	free(verstr);
 
 	/* Test invalid characters in revision. */
 	test_fail(parseversion(&a, "0:0-0:0") == NULL);
-	test_fail(parseversion(&a, "0:0-!#@$%&/|\\<>()[]{}:;,=*^'") == NULL);
+
+	verstr = m_strdup("0:0-0");
+	for (p = "!#@$%&/|\\<>()[]{}:;,_=*^'"; *p; p++) {
+		verstr[4] = *p;
+		test_fail(parseversion(&a, verstr) == NULL);
+	}
+	free(verstr);
 
 	/* FIXME: Complete. */
 }