assertEquals("DHO_DHCP_LEASE_TIME(51)=<null>", buf.toString());
}
@Test
public void testAppend() throws Exception {
StringBuilder buf;
DHCPOption opt;
buf = new StringBuilder();
opt = new DHCPOption((byte) -2, HexUtils.hexToBytes("00010000FC0AE003FFFF"));
opt.append(buf);
assertEquals("(254)=0x00010000FC0AE003FFFF", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsByte(DHO_DHCP_MESSAGE_TYPE, DHCPOFFER);
opt.append(buf);
assertEquals("DHO_DHCP_MESSAGE_TYPE(53)=DHCPOFFER", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsByte(DHO_DHCP_MESSAGE_TYPE, (byte) -1);
opt.append(buf);
assertEquals("DHO_DHCP_MESSAGE_TYPE(53)=-1", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsByte(DHO_IP_FORWARDING, (byte) -10);
opt.append(buf);
assertEquals("DHO_IP_FORWARDING(19)=-10", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsShort(DHO_INTERFACE_MTU, (short) 1500);
opt.append(buf);
assertEquals("DHO_INTERFACE_MTU(26)=1500", buf.toString());
buf = new StringBuilder();
opt = new DHCPOption(DHO_PATH_MTU_PLATEAU_TABLE, HexUtils.hexToBytes("00010000FC0A"));
opt.append(buf);
assertEquals("DHO_PATH_MTU_PLATEAU_TABLE(25)=1 0 -1014 ", buf.toString());
buf = new StringBuilder();
opt = new DHCPOption(DHO_PATH_MTU_PLATEAU_TABLE, new byte[0]);
opt.append(buf);
assertEquals("DHO_PATH_MTU_PLATEAU_TABLE(25)=", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsInt(DHO_DHCP_LEASE_TIME, 0x01234567);
opt.append(buf);
assertEquals("DHO_DHCP_LEASE_TIME(51)=19088743", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsInetAddress(DHO_SUBNET_MASK,
InetAddress.getByName("252.10.224.3"));
opt.append(buf);
assertEquals("DHO_SUBNET_MASK(1)=252.10.224.3", buf.toString());
buf = new StringBuilder();
InetAddress[] iadrs = new InetAddress[3];
iadrs[0] = InetAddress.getByName("0.0.0.0");
iadrs[1] = InetAddress.getByName("252.10.224.3");
iadrs[2] = InetAddress.getByName("255.255.255.255");
opt = DHCPOption.newOptionAsInetAddresses(DHO_WWW_SERVER, iadrs);
opt.append(buf);
assertEquals("DHO_WWW_SERVER(72)=0.0.0.0 252.10.224.3 255.255.255.255 ", buf.toString());
buf = new StringBuilder();
opt = DHCPOption.newOptionAsString(DHO_TFTP_SERVER, "foobar");
opt.append(buf);
assertEquals("DHO_TFTP_SERVER(66)=\"foobar\"", buf.toString());
buf = new StringBuilder();
opt = new DHCPOption(DHO_DHCP_PARAMETER_REQUEST_LIST, HexUtils.hexToBytes("0001FC0AE003FF"));
opt.append(buf);
assertEquals("DHO_DHCP_PARAMETER_REQUEST_LIST(55)=0 1 252 10 224 3 255 ", buf.toString());
buf = new StringBuilder();
opt = new DHCPOption(DHO_USER_CLASS, "\03foo\06foobar".getBytes());
opt.append(buf);
assertEquals("DHO_USER_CLASS(77)=\"foo\",\"foobar\"", buf.toString());
buf = new StringBuilder();
opt = new DHCPOption(DHO_DHCP_AGENT_OPTIONS, "\01\03foo\02\06barbaz\377\00".getBytes());
opt.append(buf);
assertEquals("DHO_DHCP_AGENT_OPTIONS(82)={1}\"foo\",{2}\"barbaz\",{255}\"\"", buf.toString());
}