/* * Copyright 2009-2014 Jagornet Technologies, LLC. All Rights Reserved. * * This software is the proprietary information of Jagornet Technologies, LLC. * Use is subject to license terms. * */ /* * This file TestDhcpPreferenceOption.java is part of Jagornet DHCP. * * Jagornet DHCP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Jagornet DHCP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jagornet DHCP. If not, see <http://www.gnu.org/licenses/>. * */ package com.jagornet.dhcp.option; import java.nio.ByteBuffer; import junit.framework.TestCase; import com.jagornet.dhcp.option.v6.DhcpV6PreferenceOption; import com.jagornet.dhcp.util.DhcpConstants; // TODO: Auto-generated Javadoc /** * The Class TestDhcpPreferenceOption. */ public class TestDhcpPreferenceOption extends TestCase { /** * Test encode. * * @throws Exception the exception */ public void testEncode() throws Exception { DhcpV6PreferenceOption dpo = new DhcpV6PreferenceOption(); dpo.setUnsignedByte((byte)2); ByteBuffer bb = dpo.encode(); assertNotNull(bb); assertEquals(5, bb.capacity()); assertEquals(5, bb.limit()); assertEquals(0, bb.position()); assertEquals(DhcpConstants.V6OPTION_PREFERENCE, bb.getShort()); assertEquals((short)1, bb.getShort()); // length assertEquals((byte)2, bb.get()); } /** * Test decode. * * @throws Exception the exception */ public void testDecode() throws Exception { // just three bytes, because we start decoding // _after_ the option code itself ByteBuffer bb = ByteBuffer.allocate(3); bb.putShort((short)1); // length bb.put((byte)2); bb.flip(); DhcpV6PreferenceOption dpo = new DhcpV6PreferenceOption(); dpo.decode(bb); assertEquals(1, dpo.getLength()); assertEquals(2, dpo.getUnsignedByte()); } /** * Test to string. */ public void testToString() { DhcpV6PreferenceOption dpo = new DhcpV6PreferenceOption(); dpo.setUnsignedByte((byte)2); System.out.println(dpo); } }