Skip to content

Commit e06204f

Browse files
committed
updating test cases.
TODO: fix mem leaks on encryption methods.
1 parent 21f8bb6 commit e06204f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

ext/zip/tests/oo_addglob2.phpt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,26 @@ if (!$zip->addGlob($dirname . 'foo.*', GLOB_BRACE, $options)) {
3333
$options = [
3434
'remove_all_path' => true,
3535
'comp_method' => ZipArchive::CM_STORE,
36-
'comp_flags' => 5,
36+
'comp_flags' => PHP_INT_MIN,
3737
'enc_method' => ZipArchive::EM_AES_256,
3838
'enc_password' => 'secret',
3939
];
40+
41+
try {
42+
$zip->addGlob($dirname. 'bar.*', GLOB_BRACE, $options);
43+
} catch (\ValueError $e) {
44+
echo $e->getMessage(), PHP_EOL;
45+
}
46+
47+
$options['comp_flags'] = 65536;
48+
49+
try {
50+
$zip->addGlob($dirname. 'bar.*', GLOB_BRACE, $options);
51+
} catch (\ValueError $e) {
52+
echo $e->getMessage(), PHP_EOL;
53+
}
54+
55+
$options['comp_flags'] = 5;
4056
if (!$zip->addGlob($dirname . 'bar.*', GLOB_BRACE, $options)) {
4157
echo "failed 2\n";
4258
}
@@ -61,6 +77,9 @@ $dirname = __DIR__ . '/';
6177
include $dirname . 'utils.inc';
6278
rmdir_rf(__DIR__ . '/__tmp_oo_addglob2/');
6379
?>
64-
--EXPECT--
80+
--EXPECTF--
81+
Warning: ZipArchive::addGlob(): Option "comp_flags" must be between 0 and 65535 in %s on line %d
82+
83+
Warning: ZipArchive::addGlob(): Option "comp_flags" must be between 0 and 65535 in %s on line %d
6584
0: foo.txt, comp=8, enc=0
6685
1: bar.txt, comp=0, enc=259

ext/zip/tests/oo_setcompression.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ var_dump($zip->setCompressionName('entry2.txt', ZipArchive::CM_DEFAULT));
2828
var_dump($zip->setCompressionName('dir/entry3.txt', ZipArchive::CM_STORE));
2929
var_dump($zip->setCompressionName('entry4.txt', ZipArchive::CM_DEFLATE));
3030

31+
try {
32+
$zip->setCompressionName('entry5.txt', -1);
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage(), PHP_EOL;
35+
}
36+
37+
try {
38+
$zip->setCompressionName('entry5.txt', PHP_INT_MAX);
39+
} catch (\ValueError $e) {
40+
echo $e->getMessage(), PHP_EOL;
41+
}
42+
43+
try {
44+
$zip->setCompressionIndex(4, -1);
45+
} catch (\ValueError $e) {
46+
echo $e->getMessage(), PHP_EOL;
47+
}
48+
49+
try {
50+
$zip->setCompressionIndex(4, PHP_INT_MAX);
51+
} catch (\ValueError $e) {
52+
echo $e->getMessage(), PHP_EOL;
53+
}
54+
3155
var_dump($zip->setCompressionIndex(4, ZipArchive::CM_STORE));
3256
var_dump($zip->setCompressionIndex(5, ZipArchive::CM_DEFLATE));
3357
var_dump($zip->setCompressionIndex(6, ZipArchive::CM_DEFAULT));

0 commit comments

Comments
 (0)