xref: /PHP-7.2/ext/snmp/tests/snmp2_set.phpt (revision 17ccbeec)
1--TEST--
2Function snmp2_set
3--CREDITS--
4Boris Lytochkin
5--SKIPIF--
6<?php
7require_once(dirname(__FILE__).'/skipif.inc');
8?>
9--FILE--
10<?php
11require_once(dirname(__FILE__).'/snmp_include.inc');
12
13//EXPECTF format is quickprint OFF
14snmp_set_quick_print(false);
15snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
16
17echo "Check error handing\n";
18echo "4args (5 needed)\n";
19$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0');
20var_dump($z);
21
22echo "No type & no value (timeout & retries instead)\n";
23$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
24var_dump($z);
25
26echo "No value (timeout instead), retries instead of timeout\n";
27$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', 'q', $timeout, $retries);
28var_dump($z);
29
30echo "Bogus OID\n";
31$z = snmp2_set($hostname, $communityWrite, '.1.3.6.777.888.999.444.0', 's', 'bbb', $timeout, $retries);
32var_dump($z);
33
34echo "Checking working\n";
35$oid1 = 'SNMPv2-MIB::sysContact.0';
36$oldvalue1 = snmpget($hostname, $communityWrite, $oid1, $timeout, $retries);
37$newvalue1 = $oldvalue1 . '0';
38$oid2 = 'SNMPv2-MIB::sysLocation.0';
39$oldvalue2 = snmpget($hostname, $communityWrite, $oid1, $timeout, $retries);
40$newvalue2 = $oldvalue2 . '0';
41
42echo "Single OID\n";
43$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $newvalue1, $timeout, $retries);
44var_dump($z);
45var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
46$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $oldvalue1, $timeout, $retries);
47var_dump($z);
48var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
49
50echo "Multiple OID\n";
51$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($newvalue1, $newvalue2), $timeout, $retries);
52var_dump($z);
53var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
54var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
55$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
56var_dump($z);
57var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
58var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
59
60echo "Multiple OID, single type & value\n";
61$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', $newvalue1, $timeout, $retries);
62var_dump($z);
63var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
64var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue1));
65$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
66var_dump($z);
67var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
68var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
69
70echo "Multiple OID, single type, multiple value\n";
71$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries);
72var_dump($z);
73var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
74var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
75$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
76var_dump($z);
77var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
78var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
79
80
81echo "More error handing\n";
82echo "Single OID, single type in array, single value\n";
83$z = snmp2_set($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
84var_dump($z);
85var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
86var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
87
88echo "Single OID, single type, single value in array\n";
89$z = snmp2_set($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
90var_dump($z);
91var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
92var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
93
94echo "Multiple OID, 1st wrong type\n";
95$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
96var_dump($z);
97var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
98var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
99
100echo "Multiple OID, 2nd wrong type\n";
101$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
102var_dump($z);
103var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
104var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
105
106echo "Multiple OID, single type in array, multiple value\n";
107$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s'), array($newvalue1, $newvalue2), $timeout, $retries);
108var_dump($z);
109var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
110var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
111
112echo "Multiple OID & type, singe value in array\n";
113$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s', 's'), array($newvalue1), $timeout, $retries);
114var_dump($z);
115var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
116var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
117
118echo "Multiple OID, 1st bogus, single type, multiple value\n";
119$z = snmp2_set($hostname, $communityWrite, array($oid1 . '44.55.66.77', $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries);
120var_dump($z);
121var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
122var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
123
124echo "Multiple OID, 2nd bogus, single type, multiple value\n";
125$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2 . '44.55.66.77'), 's', array($newvalue1, $newvalue2), $timeout, $retries);
126var_dump($z);
127var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
128var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
129
130echo "Multiple OID, single multiple type (1st bogus), multiple value\n";
131$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('q', 's'), array($newvalue1, $newvalue2), $timeout, $retries);
132var_dump($z);
133var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
134var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
135
136echo "Multiple OID, single multiple type (2nd bogus), multiple value\n";
137$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s', 'w'), array($newvalue1, $newvalue2), $timeout, $retries);
138var_dump($z);
139var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
140var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
141
142?>
143--EXPECTF--
144Check error handing
1454args (5 needed)
146
147Warning: snmp2_set() expects at least 5 parameters, 3 given in %s on line %d
148bool(false)
149No type & no value (timeout & retries instead)
150
151Warning: snmp2_set(): Bogus type '-1', should be single char, got 2 in %s on line %d
152bool(false)
153No value (timeout instead), retries instead of timeout
154
155Warning: snmp2_set(): Could not add variable: OID='%s' type='q' value='%i': Bad variable type ("q") in %s on line %d
156bool(false)
157Bogus OID
158
159Warning: snmp2_set(): Error in packet at '%s': notWritable (That object does not support modification) in %s on line %d
160bool(false)
161Checking working
162Single OID
163bool(true)
164bool(true)
165bool(true)
166bool(true)
167Multiple OID
168bool(true)
169bool(true)
170bool(true)
171bool(true)
172bool(true)
173bool(true)
174Multiple OID, single type & value
175bool(true)
176bool(true)
177bool(true)
178bool(true)
179bool(true)
180bool(true)
181Multiple OID, single type, multiple value
182bool(true)
183bool(true)
184bool(true)
185bool(true)
186bool(true)
187bool(true)
188More error handing
189Single OID, single type in array, single value
190
191Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %s
192bool(false)
193bool(true)
194bool(true)
195Single OID, single type, single value in array
196
197Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %s
198bool(false)
199bool(true)
200bool(true)
201Multiple OID, 1st wrong type
202
203Warning: snmp2_set(): '%s': bogus type 'sw', should be single char, got 2 in %s on line %s
204bool(false)
205bool(true)
206bool(true)
207Multiple OID, 2nd wrong type
208
209Warning: snmp2_set(): '%s': bogus type 'sb', should be single char, got 2 in %s on line %s
210bool(false)
211bool(true)
212bool(true)
213Multiple OID, single type in array, multiple value
214
215Warning: snmp2_set(): '%s': no type set in %s on line %d
216bool(false)
217bool(true)
218bool(true)
219Multiple OID & type, singe value in array
220
221Warning: snmp2_set(): '%s': no value set in %s on line %d
222bool(false)
223bool(true)
224bool(true)
225Multiple OID, 1st bogus, single type, multiple value
226
227Warning: snmp2_set(): Error in packet at '%s': %rnoCreation|notWritable%r (%s) in %s on line %d
228bool(false)
229bool(true)
230bool(true)
231Multiple OID, 2nd bogus, single type, multiple value
232
233Warning: snmp2_set(): Error in packet at '%s': %rnoCreation|notWritable%r (%s) in %s on line %d
234bool(false)
235bool(true)
236bool(true)
237Multiple OID, single multiple type (1st bogus), multiple value
238
239Warning: snmp2_set(): Could not add variable: OID='%s' type='q' value='%s': Bad variable type ("q") in %s on line %d
240bool(false)
241bool(true)
242bool(true)
243Multiple OID, single multiple type (2nd bogus), multiple value
244
245Warning: snmp2_set(): Could not add variable: OID='%s' type='w' value='%s': Bad variable type ("w") in %s on line %d
246bool(false)
247bool(true)
248bool(true)
249