Skip to content

Commit ccac132

Browse files
committed
stream: test convert filters seeking
1 parent 76874b3 commit ccac132

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
convert filters (base64, quoted-printable) with seek to start only
3+
--FILE--
4+
<?php
5+
$file = __DIR__ . '/convert_filters_seek.txt';
6+
7+
$text = 'Hello World! This is a test for convert filter seeking functionality.';
8+
9+
echo "Testing convert.base64-encode/decode\n";
10+
$fp = fopen($file, 'w');
11+
stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE);
12+
fwrite($fp, $text);
13+
fclose($fp);
14+
15+
$fp = fopen($file, 'r');
16+
stream_filter_append($fp, 'convert.base64-decode', STREAM_FILTER_READ);
17+
18+
$partial = fread($fp, 20);
19+
echo "First read (20 bytes): $partial\n";
20+
21+
$result = fseek($fp, 0, SEEK_SET);
22+
echo "Seek to start: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n";
23+
24+
$full = fread($fp, strlen($text));
25+
echo "Content matches: " . ($full === $text ? "YES" : "NO") . "\n";
26+
27+
$result = fseek($fp, 50, SEEK_SET);
28+
echo "Seek to middle: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n";
29+
30+
fclose($fp);
31+
32+
echo "\nTesting convert.quoted-printable-encode/decode\n";
33+
$text2 = "Line1\r\nLine2\r\nLine3";
34+
$fp = fopen($file, 'w');
35+
stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_WRITE);
36+
fwrite($fp, $text2);
37+
fclose($fp);
38+
39+
$fp = fopen($file, 'r');
40+
stream_filter_append($fp, 'convert.quoted-printable-decode', STREAM_FILTER_READ);
41+
42+
$partial = fread($fp, 10);
43+
echo "First read (10 bytes): " . bin2hex($partial) . "\n";
44+
45+
$result = fseek($fp, 0, SEEK_SET);
46+
echo "Seek to start: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n";
47+
48+
$full = fread($fp, strlen($text2));
49+
echo "Content matches: " . ($full === $text2 ? "YES" : "NO") . "\n";
50+
51+
$result = fseek($fp, 20, SEEK_SET);
52+
echo "Seek to middle: " . ($result === 0 ? "SUCCESS" : "FAILURE") . "\n";
53+
54+
fclose($fp);
55+
?>
56+
--CLEAN--
57+
<?php
58+
@unlink(__DIR__ . '/convert_filters_seek.txt');
59+
?>
60+
--EXPECTF--
61+
Testing convert.base64-encode/decode
62+
First read (20 bytes): Hello World! This is
63+
Seek to start: SUCCESS
64+
Content matches: YES
65+
66+
Warning: fseek(): Stream filter convert.* is not seekable in %s on line %d
67+
Seek to middle: FAILURE
68+
69+
Testing convert.quoted-printable-encode/decode
70+
First read (10 bytes): 4c696e65310d0a4c696e
71+
Seek to start: SUCCESS
72+
Content matches: YES
73+
74+
Warning: fseek(): Stream filter convert.* is not seekable in %s on line %d
75+
Seek to middle: FAILURE

0 commit comments

Comments
 (0)