]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
[Windows] Fix test compilation warnings with Visual Studio (#2178)
authorTobias Stoeckmann <stoeckmann@users.noreply.github.com>
Sun, 12 May 2024 19:26:19 +0000 (21:26 +0200)
committerGitHub <noreply@github.com>
Sun, 12 May 2024 19:26:19 +0000 (12:26 -0700)
Fixes all test-related compiler warnings with Visual Studio 2022 on
Windows 11.

Contains some changes from
https://github.com/libarchive/libarchive/pull/2095.

CC: @dunhor
---------

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
cpio/test/test_option_c.c
libarchive/test/test_archive_match_time.c
libarchive/test/test_read_format_rar5.c
test_utils/test_main.c

index 0b6bed2fac933c9d9577386f18a4327c3bf22894..de25ed1ab52d45233b08a98206d9fff935072665 100644 (file)
@@ -119,9 +119,9 @@ DEFINE_TEST(test_option_c)
        assert(is_octal(e, 76)); /* Entire header is octal digits. */
        assertEqualMem(e + 0, "070707", 6); /* Magic */
        assert(is_octal(e + 6, 6)); /* dev */
-       dev = from_octal(e + 6, 6);
+       dev = (int)from_octal(e + 6, 6);
        assert(is_octal(e + 12, 6)); /* ino */
-       ino = from_octal(e + 12, 6);
+       ino = (int)from_octal(e + 12, 6);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        /* Group members bits and others bits do not work. */
        assertEqualMem(e + 18, "100666", 6); /* Mode */
@@ -129,10 +129,10 @@ DEFINE_TEST(test_option_c)
        assertEqualMem(e + 18, "100644", 6); /* Mode */
 #endif
        if (uid < 0)
-               uid = from_octal(e + 24, 6);
+               uid = (int)from_octal(e + 24, 6);
        assertEqualInt(from_octal(e + 24, 6), uid); /* uid */
        assert(is_octal(e + 30, 6)); /* gid */
-       gid = from_octal(e + 30, 6);
+       gid = (int)from_octal(e + 30, 6);
        assertEqualMem(e + 36, "000001", 6); /* nlink */
        failure("file entries should not have rdev set (dev field was 0%o)",
            dev);
index 25a0623a7e5a7e10f44fd20947103ee5a98f6323..27ad1da2f1394cc35eb9c1809d1de57b1e72946e 100644 (file)
@@ -316,15 +316,14 @@ test_newer_mtime_than_file_mbs(void)
 static void
 test_newer_ctime_than_file_mbs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -373,6 +372,7 @@ test_newer_ctime_than_file_mbs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
@@ -435,15 +435,14 @@ test_newer_mtime_than_file_wcs(void)
 static void
 test_newer_ctime_than_file_wcs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -493,6 +492,7 @@ test_newer_ctime_than_file_wcs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
@@ -787,15 +787,14 @@ test_older_mtime_than_file_mbs(void)
 static void
 test_older_ctime_than_file_mbs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -845,6 +844,7 @@ test_older_ctime_than_file_mbs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
@@ -907,15 +907,14 @@ test_older_mtime_than_file_wcs(void)
 static void
 test_older_ctime_than_file_wcs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -965,6 +964,7 @@ test_older_ctime_than_file_wcs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
@@ -1088,15 +1088,14 @@ test_mtime_between_files_wcs(void)
 static void
 test_ctime_between_files_mbs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -1147,20 +1146,20 @@ test_ctime_between_files_mbs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
 test_ctime_between_files_wcs(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       skipping("Can't set ctime on Windows");
+       return;
+#else
        struct archive *a;
        struct archive_entry *ae;
        struct archive *m;
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        skipping("Can't set ctime on Windows");
-        return;
-#endif
-
        if (!assert((m = archive_match_new()) != NULL))
                return;
        if (!assert((ae = archive_entry_new()) != NULL)) {
@@ -1211,6 +1210,7 @@ test_ctime_between_files_wcs(void)
        archive_read_free(a);
        archive_entry_free(ae);
        archive_match_free(m);
+#endif
 }
 
 static void
index 705913b04cc23c174ec9892dd12494d3f50c70b4..f278b0719e76683015cf431c73a62ea888ed4536 100644 (file)
@@ -932,19 +932,22 @@ DEFINE_TEST(test_read_format_rar5_symlink)
        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
        assertEqualString("file.txt", archive_entry_symlink(ae));
        assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae));
-       assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+       assertEqualInt(0, archive_entry_size(ae));
+       assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
 
        assertA(0 == archive_read_next_header(a, &ae));
        assertEqualString("dirlink", archive_entry_pathname(ae));
        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
        assertEqualString("dir", archive_entry_symlink(ae));
        assertEqualInt(AE_SYMLINK_TYPE_DIRECTORY, archive_entry_symlink_type(ae));
-       assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+       assertEqualInt(0, archive_entry_size(ae));
+       assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
 
        assertA(0 == archive_read_next_header(a, &ae));
        assertEqualString("dir", archive_entry_pathname(ae));
        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
-       assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+       assertEqualInt(0, archive_entry_size(ae));
+       assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
 
        assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
 
@@ -969,7 +972,8 @@ DEFINE_TEST(test_read_format_rar5_hardlink)
        assertEqualString("hardlink.txt", archive_entry_pathname(ae));
        assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
        assertEqualString("file.txt", archive_entry_hardlink(ae));
-       assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+       assertEqualInt(0, archive_entry_size(ae));
+       assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
 
        assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
 
index 6617732a335b030dd2bdd64126608bab2ea9c03e..496db6d9122c2bd08bd2d0fcbee60331127d3f86 100644 (file)
 #define access _access
 #undef chdir
 #define chdir _chdir
+#undef chmod
+#define chmod _chmod
 #endif
 #ifndef fileno
 #define fileno _fileno