Package org.dhcp4java

Examples of org.dhcp4java.InetCidr


    assertEquals(cidr1, cidr2);
  }
 
  @Test
  public void testToString() throws Exception {
    InetCidr cidr = new InetCidr(InetAddress.getByName("16.17.18.19"), 20);
    assertEquals("16.17.16.0/20", cidr.toString());
  }
View Full Code Here


    assertEquals("16.17.16.0/20", cidr.toString());
  }
 
  @Test
  public void testHashCode() throws Exception {
    int hash1 = (new InetCidr(InetAddress.getByName("224.17.252.127"), 24)).hashCode();
    int hash2 = (new InetCidr(InetAddress.getByName("224.17.252.127"), 20)).hashCode();
    assertTrue(hash1 != 0);
    assertTrue(hash2 != 0);
    assertTrue(hash1 != hash2);
  }
View Full Code Here

    assertTrue(hash1 != hash2);
  }
 
  @Test
  public void testEquals() throws Exception {
    InetCidr cidr1 = new InetCidr(InetAddress.getByName("224.17.252.127"), 24);
    InetCidr cidr2 = new InetCidr(InetAddress.getByName("224.17.252.0"), 24);
   
    assertTrue(cidr1.equals(cidr1));
    assertTrue(cidr1.equals(cidr2));
    assertTrue(cidr2.equals(cidr1));
    assertFalse(cidr1.equals(null));
    assertFalse(cidr1.equals(new Integer(1)));
    assertFalse(cidr1.equals(new InetCidr(InetAddress.getByName("224.17.252.0"), 25)));
    assertFalse(cidr1.equals(new InetCidr(InetAddress.getByName("225.17.252.0"), 24)));
  }
View Full Code Here

    assertFalse(cidr1.equals(new InetCidr(InetAddress.getByName("225.17.252.0"), 24)));
  }
 
  @Test (expected=NullPointerException.class)
  public void testAddrmask2CidrAddrNull() {
    new InetCidr(null, Util.int2InetAddress(0x12345678));
  }
View Full Code Here

  public void testAddrmask2CidrAddrNull() {
    new InetCidr(null, Util.int2InetAddress(0x12345678));
  }
  @Test (expected=NullPointerException.class)
  public void testAddrmask2CidrAddrMask() {
    new InetCidr(Util.int2InetAddress(0x12345678), null);
  }
View Full Code Here

    new InetCidr(Util.int2InetAddress(0x12345678), null);
  }
  @Test (expected=IllegalArgumentException.class)
  public void testAddrmask2CidrBadMask() {
    InetAddress ip = Util.int2InetAddress(0x12345678);
    new InetCidr(ip, ip);    // exception should be raised here
  }
View Full Code Here

    int mask = 32;
    InetCidr[] addrs = InetCidr.addr2Cidr(Util.int2InetAddress(ip));
   
    assertEquals(32, addrs.length);
    for (int i=0; i<32; i++) {
      InetCidr refValue =  new InetCidr(Util.int2InetAddress(ip), mask);
      assertEquals(addrs[i], refValue);
      assertEquals(addrs[i].getAddr(), Util.int2InetAddress(ip));
      assertEquals(addrs[i].getMask(), mask);
      ip = ip << 1;
      mask--;
View Full Code Here

    InetCidr.addr2Cidr(InetAddress.getByName("1080:0:0:0:8:800:200C:417A"));
  }
 
  @Test
  public void testToLong() throws UnknownHostException {
    InetCidr cidr = new InetCidr(InetAddress.getByName("10.11.12.0"), 24);
    assertEquals(0x180A0B0C00L, cidr.toLong());
  }
View Full Code Here

    assertEquals(0x180A0B0C00L, cidr.toLong());
  }
 
  @Test
  public void testFromLong() throws UnknownHostException {
    InetCidr cidr = new InetCidr(InetAddress.getByName("10.11.12.0"), 24);
    assertEquals(cidr, InetCidr.fromLong(0x180A0B0C00L));
    assertEquals(cidr, InetCidr.fromLong(0x180A0B0CFFL));
  }
View Full Code Here

    InetCidr.fromLong(-1);
  }
 
  @Test
  public void testCompareTo() throws UnknownHostException {
    InetCidr cidr0 = new InetCidr(InetAddress.getByName("10.11.12.0"), 24);
    InetCidr cidr1 = new InetCidr(InetAddress.getByName("10.11.12.0"), 24);
    InetCidr cidr2 = new InetCidr(InetAddress.getByName("10.11.12.0"), 23);
    InetCidr cidr3 = new InetCidr(InetAddress.getByName("10.11.12.0"), 25);
    InetCidr cidr4 = new InetCidr(InetAddress.getByName("10.11.11.0"), 24);
    InetCidr cidr5 = new InetCidr(InetAddress.getByName("10.11.13.0"), 24);
    InetCidr cidr6 = new InetCidr(InetAddress.getByName("11.11.12.0"), 24);
    InetCidr cidr7 = new InetCidr(InetAddress.getByName("129.11.12.0"), 24);

    assertEquals(0, cidr0.compareTo(cidr0));
    assertEquals(0, cidr0.compareTo(cidr1));
    assertEquals(1, cidr1.compareTo(cidr2));
    assertEquals(-1, cidr1.compareTo(cidr3));
View Full Code Here

TOP

Related Classes of org.dhcp4java.InetCidr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.