Skip to content

Commit 4d3d0ae

Browse files
committed
Add test for mandatory zlib locks
Windows has mandatory locks, so we can test the exclusive lock reliably.
1 parent acb17fb commit 4d3d0ae

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

ext/zlib/tests/005.txt.gz

150 Bytes
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
Test mandatory locking on Windows
3+
--EXTENSIONS--
4+
zlib
5+
--SKIPIF--
6+
<?php
7+
if (PHP_OS_FAMILY !== "Windows") die("skip Only for Windows because it has mandatory locking");
8+
?>
9+
--FILE--
10+
<?php
11+
12+
echo "without wrapper\n";
13+
$f = __DIR__."/005.txt.gz";
14+
$h = gzopen($f,'r');
15+
$h2 = gzopen($f, 'r');
16+
stream_set_chunk_size($h2,1);
17+
18+
var_dump(flock($h, LOCK_EX));
19+
var_dump(fread($h2, 1));
20+
var_dump(fread($h, 1));
21+
22+
gzclose($h);
23+
gzclose($h2);
24+
25+
echo "\nwith wrapper\n";
26+
$f = "compress.zlib://".__DIR__."/005.txt.gz";
27+
$h = fopen($f,'r');
28+
$h2 = fopen($f, 'r');
29+
stream_set_chunk_size($h2, 1);
30+
31+
var_dump(flock($h, LOCK_EX));
32+
var_dump(fread($h2, 1));
33+
var_dump(fread($h, 1));
34+
35+
gzclose($h);
36+
gzclose($h2);
37+
38+
?>
39+
--EXPECTF--
40+
without wrapper
41+
bool(true)
42+
43+
Notice: fread(): Read of 1 bytes failed with errno=13 Permission denied in %s on line %d
44+
bool(false)
45+
string(1) "W"
46+
47+
with wrapper
48+
bool(true)
49+
50+
Notice: fread(): Read of 1 bytes failed with errno=13 Permission denied in %s on line %d
51+
bool(false)
52+
string(1) "W"

0 commit comments

Comments
 (0)