Re: MFH for 2 zlib patches?
| From: | Stefan Roehrich | Date: | Thu, 14 Mar 2002 14:34:55 +0000 |
| Subject: | Re: MFH for 2 zlib patches? | ||
| References: | 1 2 3 | Groups: | php.qa |
| Request: | Send a blank email to php-qa+get-4511@lists.php.net to get a copy of this message | ||
On 2002-03-13 21:30:13, Stefan Roehrich wrote:
> For gzencode() I think the best testing method would be, if you take
> arbitray strings, gzencode() them and feed it to gzip -t or compare
> the string to the output of gzip -c . But I don't know if that's
> allowed in your testing environment (gzip normally isn't avalaible on
> windows ...).
I just wrote a little test script for gzencode(), it uses gzip -t to
test the output (if you want to use gzip -cd, you would need
bidirectional pipes working ...). The script is attached.
Stefan
--
Stefan Röhrich stefan@roehri.ch, sr@linux.de
http://www.roehri.ch/~sr/
--TEST-- gzencode() --SKIPIF-- <?php if (!extension_loaded("zlib") || !system("gzip -h")) print "skip"; ?> --POST-- --GET-- --FILE-- <?php function gen_string($length) { $str = ''; for($i = 0; $i < $length; $i++) $str .= chr(rand(0,255)); return $str; } for($i = 1; $i <= 128*1024; $i*=2) { $original = gen_string($i); $level = rand(1,9); $packed=gzencode($original, $level); # if($i == 64) # $packed = "trallala"; printf("Length: %7d", strlen($original)); # gzip test $fp = popen("gzip -t", "w") or die(-1); if(fwrite($fp, $packed) != strlen($packed)) { echo " error in writing to pipe!\n"; break; } if(pclose($fp) == 0) echo " - tested.\n"; else { echo " failed test with level $level!\n"; echo base64_encode($original); break; } } ?> --EXPECT-- Length: 1 - tested. Length: 2 - tested. Length: 4 - tested. Length: 8 - tested. Length: 16 - tested. Length: 32 - tested. Length: 64 - tested. Length: 128 - tested. Length: 256 - tested. Length: 512 - tested. Length: 1024 - tested. Length: 2048 - tested. Length: 4096 - tested. Length: 8192 - tested. Length: 16384 - tested. Length: 32768 - tested. Length: 65536 - tested. Length: 131072 - tested.
--TEST-- gzencode() --SKIPIF-- <?php if (!extension_loaded("zlib") || !system("gzip -h")) print "skip"; ?> --POST-- --GET-- --FILE-- <?php function gen_string($length) { $str = ''; for($i = 0; $i < $length; $i++) $str .= chr(rand(0,255)); return $str; } for($i = 1; $i <= 128*1024; $i*=2) { $original = gen_string($i); $level = rand(1,9); $packed=gzencode($original, $level); # if($i == 64) # $packed = "trallala"; printf("Length: %7d", strlen($original)); # gzip test $fp = popen("gzip -t", "w") or die(-1); if(fwrite($fp, $packed) != strlen($packed)) { echo " error in writing to pipe!\n"; break; } if(pclose($fp) == 0) echo " - tested.\n"; else { echo " failed test with level $level!\n"; echo base64_encode($original); break; } } ?> --EXPECT-- Length: 1 - tested. Length: 2 - tested. Length: 4 - tested. Length: 8 - tested. Length: 16 - tested. Length: 32 - tested. Length: 64 - tested. Length: 128 - tested. Length: 256 - tested. Length: 512 - tested. Length: 1024 - tested. Length: 2048 - tested. Length: 4096 - tested. Length: 8192 - tested. Length: 16384 - tested. Length: 32768 - tested. Length: 65536 - tested. Length: 131072 - tested.