Java Code Examples for inet.ipaddr.IPAddressString#getAddress()

The following examples show how to use inet.ipaddr.IPAddressString#getAddress() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: IPAddress   File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
boolean confirmAddrStrings(IPAddress ipAddr, String ...strs) {
	for(String str : strs) {
		if(str == null) {
			continue;
		}
		IPAddressString addrString = createAddress(str, DEFAULT_BASIC_VALIDATION_OPTIONS);
		IPAddress addr = addrString.getAddress();
		if(!ipAddr.equals(addr)) {
			addFailure(new Failure("failed produced string: " + str, ipAddr));
			addrString = createAddress(str, DEFAULT_BASIC_VALIDATION_OPTIONS);
			addrString.getAddress();
			return false;
		}
	}
	incrementTestCount();
	return true;
}
 
Example 2
Source Project: IPAddress   File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
void testHostAddress(String addressStr) {
	IPAddressString str = createAddress(addressStr);
	IPAddress address = str.getAddress();
	if(address != null) {
		IPAddress hostAddress = str.getHostAddress();
		int prefixIndex = addressStr.indexOf(IPAddress.PREFIX_LEN_SEPARATOR);
		if(prefixIndex < 0) {
			if(!address.equals(hostAddress) || !address.contains(hostAddress)) {
				addFailure(new Failure("failed host address with no prefix: " + hostAddress + " expected: " + address, str));
			}
		} else {
			String substr = addressStr.substring(0, prefixIndex);
			IPAddressString str2 = createAddress(substr);
			IPAddress address2 = str2.getAddress();
			if(!address2.equals(hostAddress)) {
				addFailure(new Failure("failed host address: " + hostAddress + " expected: " + address2, str));
			}
		}
	}
}
 
Example 3
Source Project: IPAddress   File: SpecialTypesTest.java    License: Apache License 2.0 6 votes vote down vote up
void testAllValues(IPVersion version, BigInteger count) {
	HostName hostAll = createHost("*", HOST_OPTIONS);
	IPAddressString addressAllStr = createAddress("*", ADDRESS_OPTIONS);
	IPAddress addressAll = addressAllStr.getAddress(version);
	String address2Str = version.isIPv4() ? "*.*.*.*" : "*:*:*:*:*:*:*:*";
	IPAddress address = createAddress(address2Str, ADDRESS_OPTIONS).getAddress();
	if(!addressAll.equals(address)) {
		addFailure(new Failure("no match " + address, addressAll));
	} else if(addressAll.compareTo(address) != 0) {
		addFailure(new Failure("no match " + address, addressAll));
	} else if(!addressAll.getCount().equals(count)) {
		addFailure(new Failure("no count match ", addressAll));
	} else {
		addressAll = hostAll.asAddress(version);
		if(!addressAll.equals(address)) {
			addFailure(new Failure("no match " + address, addressAll));
		} else if(addressAll.compareTo(address) != 0) {
			addFailure(new Failure("no match " + address, addressAll));
		} else if(!addressAll.getCount().equals(count)) {
			addFailure(new Failure("no count match ", addressAll));
		}
	}
	incrementTestCount();
}
 
Example 4
Source Project: IPAddress   File: TestBase.java    License: Apache License 2.0 5 votes vote down vote up
boolean confirmAddrStrings(IPAddress ipAddr, IPAddressString ...strs) {
	for(IPAddressString str : strs) {
		IPAddress addr = str.getAddress();
		if(!ipAddr.equals(addr)) {
			addFailure(new Failure("failed produced string: " + str, ipAddr));
			return false;
		}
	}
	incrementTestCount();
	return true;
}
 
Example 5
Source Project: IPAddress   File: SpecialTypesTest.java    License: Apache License 2.0 5 votes vote down vote up
void testIPv4Strings(String addr, boolean explicit, String normalizedString, String normalizedWildcardString, String sqlString, String fullString, String reverseDNSString, String singleHex, String singleOctal) {
	IPAddressString w = createAddress(addr, ADDRESS_OPTIONS);
	IPAddress ipAddr;
	if(explicit) {
		ipAddr = w.getAddress(IPVersion.IPV4);
	} else {
		ipAddr = w.getAddress();
	}
	testStrings(w, ipAddr, normalizedString, normalizedWildcardString, normalizedWildcardString, sqlString, fullString, 
			normalizedString, normalizedString, normalizedWildcardString, normalizedString, normalizedWildcardString, reverseDNSString, normalizedString,
			singleHex, singleOctal);
}
 
Example 6
Source Project: IPAddress   File: SpecialTypesTest.java    License: Apache License 2.0 5 votes vote down vote up
void testAllValues() {
	HostName hostAll = createHost("*", HOST_OPTIONS);
	IPAddressString addressAll = createAddress("*", ADDRESS_OPTIONS);
	MACAddressString macAll = createMACAddress("*", MAC_OPTIONS);
	if(addressAll.getAddress() != null) {
		addFailure(new Failure("non null", addressAll));
	} else if(hostAll.asAddress() != null) {
		addFailure(new Failure("non null", hostAll));
	} else if(hostAll.getAddress() != null) {
		addFailure(new Failure("non null", hostAll));
	} else if(macAll.getAddress() == null) {
		addFailure(new Failure("null", macAll));
	}
	incrementTestCount();
}
 
Example 7
Source Project: IPAddress   File: SpecialTypesTest.java    License: Apache License 2.0 4 votes vote down vote up
void testIPv6Strings(String addr,
		boolean explicit,
		String normalizedString,
		String normalizedWildcardString, 
		String canonicalWildcardString, 
		String sqlString, 
		String fullString,
		String compressedString,
		String canonicalString,
		String subnetString,
		String compressedWildcardString,
		String mixedStringNoCompressMixed,
		String mixedStringNoCompressHost,
		String mixedStringCompressCoveredHost,
		String mixedString,
		String reverseDNSString,
		String uncHostString,
		String base85String,
		String singleHex,
		String singleOctal) {
	IPAddressString w = createAddress(addr, ADDRESS_OPTIONS);
	IPAddress ipAddr;
	if(explicit) {
		ipAddr = w.getAddress(IPVersion.IPV6);
	} else {
		ipAddr = w.getAddress();
	}
	testIPv6Strings(w,
			ipAddr,
			normalizedString,
			normalizedWildcardString,
			canonicalWildcardString,
			sqlString, 
			fullString,
			compressedString,
			canonicalString,
			subnetString,
			compressedWildcardString,
			mixedStringNoCompressMixed,
			mixedStringNoCompressHost,
			mixedStringCompressCoveredHost,
			mixedString,
			reverseDNSString,
			uncHostString,
			base85String,
			singleHex,
			singleOctal);
}