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