1BEGIN { 2 if ($ENV{PERL_CORE}) { 3 chdir 't' if -d 't'; 4 @INC = ("../lib", "lib/compress"); 5 } 6} 7 8use lib qw(t t/compress); 9use strict ; 10use warnings ; 11 12use Test::More ; 13 14BEGIN 15{ 16 # use Test::NoWarnings, if available 17 my $extra = 0 ; 18 $extra = 1 19 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; 20 21 plan tests => 9 + $extra ; 22 23 use_ok('Compress::Raw::Zlib', 2) ; 24} 25 26use CompTestUtils; 27 28 29# Check zlib_version and ZLIB_VERSION are the same. 30test_zlib_header_matches_library(); 31 32SKIP: 33{ 34 # If running a github workflow that tests upstream zlib/zlib-ng, check we have the version requested 35 36 # Not github or not asking for explicit verson, so skip 37 skip "Not github", 7 38 if ! (defined $ENV{GITHUB_ACTION} && defined $ENV{ZLIB_VERSION}) ; 39 40 my $expected_version = $ENV{ZLIB_VERSION} ; 41 # zlib prefixes tags with a "v", so remove 42 $expected_version =~ s/^v//i; 43 44 skip "Skipping version tests for 'develop' branch", 7 45 if ($expected_version eq 'develop') ; 46 47 if ($ENV{USE_ZLIB_NG}) 48 { 49 # zlib-ng native 50 my $zv = Compress::Raw::Zlib::zlibng_version(); 51 is substr($zv, 0, length($expected_version)), $expected_version, "Expected version is $expected_version"; 52 ok ! Compress::Raw::Zlib::is_zlib_native(), "! is_zlib_native"; 53 ok Compress::Raw::Zlib::is_zlibng(), "is_zlibng"; 54 ok Compress::Raw::Zlib::is_zlibng_native(), "is_zlibng_native"; 55 ok ! Compress::Raw::Zlib::is_zlibng_compat(), "! is_zlibng_compat"; 56 is Compress::Raw::Zlib::zlib_version(), '', "zlib_version() should be empty"; 57 is Compress::Raw::Zlib::ZLIB_VERSION, '', "ZLIB_VERSION should be empty"; 58 } 59 elsif ($ENV{ZLIB_NG_PRESENT}) 60 { 61 # zlib-ng compat 62 my %zlibng2zlib = ( 63 '2.0.0' => '1.2.11.zlib-ng', 64 '2.0.1' => '1.2.11.zlib-ng', 65 '2.0.2' => '1.2.11.zlib-ng', 66 '2.0.3' => '1.2.11.zlib-ng', 67 '2.0.4' => '1.2.11.zlib-ng', 68 '2.0.5' => '1.2.11.zlib-ng', 69 '2.0.6' => '1.2.11.zlib-ng', 70 '2.0.7' => '1.2.11.zlib-ng', 71 '2.1.2' => '1.2.13.zlib-ng', 72 '2.1.3' => '1.2.13.zlib-ng', 73 '2.1.4' => '1.3.0.zlib-ng', 74 '2.1.5' => '1.3.0.zlib-ng', 75 '2.1.6' => '1.3.0.zlib-ng', 76 ); 77 78 my $zv = Compress::Raw::Zlib::zlibng_version(); 79 80 my $compat_ver = $zlibng2zlib{$expected_version}; 81 82 is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version"; 83 ok ! Compress::Raw::Zlib::is_zlib_native(), "! is_zlib_native"; 84 ok Compress::Raw::Zlib::is_zlibng(), "is_zlibng"; 85 ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native"; 86 ok Compress::Raw::Zlib::is_zlibng_compat(), "is_zlibng_compat"; 87 is Compress::Raw::Zlib::zlib_version(), $compat_ver, "zlib_version() should be $compat_ver"; 88 is Compress::Raw::Zlib::ZLIB_VERSION, $compat_ver, "ZLIB_VERSION should be $compat_ver"; 89 } 90 else 91 { 92 # zlib native 93 my $zv = Compress::Raw::Zlib::zlib_version(); 94 is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version"; 95 ok Compress::Raw::Zlib::is_zlib_native(), "is_zlib_native"; 96 ok ! Compress::Raw::Zlib::is_zlibng(), "! is_zlibng"; 97 ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native"; 98 ok ! Compress::Raw::Zlib::is_zlibng_compat(), "! is_zlibng_compat"; 99 is Compress::Raw::Zlib::zlibng_version(), '', "zlibng_version() should be empty"; 100 is Compress::Raw::Zlib::ZLIBNG_VERSION, '', "ZLIBNG_VERSION should be empty"; } 101 102} 103