getMessage(); } catch (Throwable $e) { return get_class($e); } } foreach (array('a list' => array('1'), 'text' => 'abc', 'an empty value' => '') as $name => $rate) { check("rate as $name is refused", run($switch, array('command' => '15', 'rate' => $rate)), 'Invalid rate for VARPLAY'); } // MSG_CMD (4 bytes, host order), the command byte, then rate + 32768 as a big-endian uint16. $header = bin2hex(pack('lc', 1, 15)); check('rate 100', run($switch, array('command' => '15', 'rate' => '100')), $header.'8064'); check('rate -100', run($switch, array('command' => '15', 'rate' => '-100')), $header.'7f9c'); check('rate 0', run($switch, array('command' => '15', 'rate' => '0')), $header.'8000'); check('rate as an int', run($switch, array('command' => '15', 'rate' => 100)), $header.'8064'); check('a missing rate is rate 0', run($switch, array('command' => '15')), $header.'8000'); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0);