]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_pathmatch: Extend unit tests
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Mar 2026 15:36:50 +0000 (16:36 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 9 May 2026 10:19:11 +0000 (12:19 +0200)
Add some tests to clarify what happens in these cases. Also, this
increases test coverage.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/test/test_archive_pathmatch.c

index 3b212aca9d94225e909a3f767fe1d133a12758cd..ee3679159727ceccbeddc1971cbbb52dd288be6c 100644 (file)
@@ -56,6 +56,10 @@ DEFINE_TEST(test_archive_pathmatch)
        assertEqualInt(0, archive_pathmatch_w(L"a/b/c", NULL, 0));
 
        /* Empty pattern only matches empty string. */
+       assertEqualInt(1, archive_pathmatch(NULL,NULL, 0));
+       assertEqualInt(1, archive_pathmatch(NULL,"", 0));
+       assertEqualInt(0, archive_pathmatch(NULL,"a", 0));
+       assertEqualInt(1, archive_pathmatch("",NULL, 0));
        assertEqualInt(1, archive_pathmatch("","", 0));
        assertEqualInt(0, archive_pathmatch("","a", 0));
        assertEqualInt(1, archive_pathmatch("*","", 0));
@@ -76,11 +80,15 @@ DEFINE_TEST(test_archive_pathmatch)
        assertEqualInt(0, archive_pathmatch("a", "ab", 0));
        assertEqualInt(0, archive_pathmatch("a", "ab", 0));
        assertEqualInt(1, archive_pathmatch("a?c", "abc", 0));
+       assertEqualInt(1, archive_pathmatch("*a", "/a", 0));
+       assertEqualInt(1, archive_pathmatch("*a", "a", 0));
        /* SUSv2: ? matches / */
        assertEqualInt(1, archive_pathmatch("a?c", "a/c", 0));
        assertEqualInt(1, archive_pathmatch("a?*c*", "a/c", 0));
        assertEqualInt(1, archive_pathmatch("*a*", "a/c", 0));
        assertEqualInt(1, archive_pathmatch("*a*", "/a/c", 0));
+       assertEqualInt(0, archive_pathmatch("*a", "/a/c", 0));
+       assertEqualInt(0, archive_pathmatch("*a", "a/c", 0));
        assertEqualInt(1, archive_pathmatch("*a*", "defaaaaaaa", 0));
        assertEqualInt(0, archive_pathmatch("a*", "defghi", 0));
        assertEqualInt(0, archive_pathmatch("*a*", "defghi", 0));