xref: /PHP-8.2/ext/bz2/tests/004.phpt (revision 56f90492)
1--TEST--
2bzread() tests with invalid files
3--EXTENSIONS--
4bz2
5--FILE--
6<?php
7
8$fd = bzopen(__DIR__."/004_1.txt.bz2","r");
9var_dump(bzerror($fd));
10var_dump(bzerrstr($fd));
11var_dump(bzerrno($fd));
12
13$fd2 = bzopen(__DIR__."/004_2.txt.bz2","r");
14var_dump(bzerror($fd2));
15var_dump(bzerrstr($fd2));
16var_dump(bzerrno($fd2));
17
18var_dump(bzread($fd, 10));
19var_dump(bzerror($fd));
20var_dump(bzerrstr($fd));
21var_dump(bzerrno($fd));
22
23var_dump(bzread($fd2, 10));
24var_dump(bzerror($fd2));
25var_dump(bzerrstr($fd2));
26var_dump(bzerrno($fd2));
27
28var_dump(bzread($fd));
29var_dump(bzerror($fd));
30var_dump(bzerrstr($fd));
31var_dump(bzerrno($fd));
32
33var_dump(bzread($fd2));
34var_dump(bzerror($fd2));
35var_dump(bzerrstr($fd2));
36var_dump(bzerrno($fd2));
37
38bzclose($fd2);
39try {
40    var_dump(bzread($fd2));
41} catch (TypeError $e) {
42    echo $e->getMessage(), "\n";
43}
44try {
45    var_dump(bzerror($fd2));
46} catch (TypeError $e) {
47    echo $e->getMessage(), "\n";
48}
49try {
50    var_dump(bzerrstr($fd2));
51} catch (TypeError $e) {
52    echo $e->getMessage(), "\n";
53}
54try {
55    var_dump(bzerrno($fd2));
56} catch (TypeError $e) {
57    echo $e->getMessage(), "\n";
58}
59
60echo "Done\n";
61?>
62--EXPECT--
63array(2) {
64  ["errno"]=>
65  int(0)
66  ["errstr"]=>
67  string(2) "OK"
68}
69string(2) "OK"
70int(0)
71array(2) {
72  ["errno"]=>
73  int(0)
74  ["errstr"]=>
75  string(2) "OK"
76}
77string(2) "OK"
78int(0)
79bool(false)
80array(2) {
81  ["errno"]=>
82  int(-5)
83  ["errstr"]=>
84  string(16) "DATA_ERROR_MAGIC"
85}
86string(16) "DATA_ERROR_MAGIC"
87int(-5)
88bool(false)
89array(2) {
90  ["errno"]=>
91  int(-4)
92  ["errstr"]=>
93  string(10) "DATA_ERROR"
94}
95string(10) "DATA_ERROR"
96int(-4)
97bool(false)
98array(2) {
99  ["errno"]=>
100  int(-5)
101  ["errstr"]=>
102  string(16) "DATA_ERROR_MAGIC"
103}
104string(16) "DATA_ERROR_MAGIC"
105int(-5)
106bool(false)
107array(2) {
108  ["errno"]=>
109  int(-4)
110  ["errstr"]=>
111  string(10) "DATA_ERROR"
112}
113string(10) "DATA_ERROR"
114int(-4)
115bzread(): supplied resource is not a valid stream resource
116bzerror(): supplied resource is not a valid stream resource
117bzerrstr(): supplied resource is not a valid stream resource
118bzerrno(): supplied resource is not a valid stream resource
119Done
120