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        );
71
72        my $zv = Compress::Raw::Zlib::zlibng_version();
73
74        my $compat_ver = $zlibng2zlib{$expected_version};
75
76        is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version";
77        ok ! Compress::Raw::Zlib::is_zlib_native(), "! is_zlib_native";
78        ok   Compress::Raw::Zlib::is_zlibng(), "is_zlibng";
79        ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native";
80        ok   Compress::Raw::Zlib::is_zlibng_compat(), "is_zlibng_compat";
81        is   Compress::Raw::Zlib::zlib_version(), $compat_ver, "zlib_version() should be $compat_ver";
82        is   Compress::Raw::Zlib::ZLIB_VERSION, $compat_ver, "ZLIB_VERSION should be $compat_ver";
83    }
84    else
85    {
86        # zlib native
87        my $zv = Compress::Raw::Zlib::zlib_version();
88        is substr($zv, 0, length($expected_version)), $expected_version, "Expected Version is $expected_version";
89        ok   Compress::Raw::Zlib::is_zlib_native(), "is_zlib_native";
90        ok ! Compress::Raw::Zlib::is_zlibng(), "! is_zlibng";
91        ok ! Compress::Raw::Zlib::is_zlibng_native(), "! is_zlibng_native";
92        ok ! Compress::Raw::Zlib::is_zlibng_compat(), "! is_zlibng_compat";
93        is   Compress::Raw::Zlib::zlibng_version(), '', "zlibng_version() should be empty";
94        is   Compress::Raw::Zlib::ZLIBNG_VERSION, '', "ZLIBNG_VERSION should be empty";    }
95
96}
97