⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subnetipv4test.java

📁 mina是以Java实现的一个开源的网络程序框架
💻 JAVA
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one *  or more contributor license agreements.  See the NOTICE file *  distributed with this work for additional information *  regarding copyright ownership.  The ASF licenses this file *  to you under the Apache License, Version 2.0 (the *  "License"); you may not use this file except in compliance *  with the License.  You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, *  software distributed under the License is distributed on an *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *  KIND, either express or implied.  See the License for the *  specific language governing permissions and limitations *  under the License. * */package org.apache.mina.filter.firewall;import java.net.InetAddress;import java.net.UnknownHostException;import junit.framework.TestCase;/** * TODO Add documentation *  * @author The Apache MINA Project (dev@mina.apache.org) * @version $Rev$, $Date$ */public class SubnetIPv4Test extends TestCase {	public void test24() throws UnknownHostException {		InetAddress a = InetAddress.getByName("127.2.3.0");		InetAddress b = InetAddress.getByName("127.2.3.4");		InetAddress c = InetAddress.getByName("127.2.3.255");		InetAddress d = InetAddress.getByName("127.2.4.4");				Subnet mask = new Subnet(a, 24);				assertTrue(mask.inSubnet(a));		assertTrue(mask.inSubnet(b));		assertTrue(mask.inSubnet(c));		assertFalse(mask.inSubnet(d));	}	public void test16() throws UnknownHostException {		InetAddress a = InetAddress.getByName("127.2.0.0");		InetAddress b = InetAddress.getByName("127.2.3.4");		InetAddress c = InetAddress.getByName("127.2.129.255");		InetAddress d = InetAddress.getByName("127.3.4.4");				Subnet mask = new Subnet(a, 16);				assertTrue(mask.inSubnet(a));		assertTrue(mask.inSubnet(b));		assertTrue(mask.inSubnet(c));		assertFalse(mask.inSubnet(d));	}		public void testSingleIp() throws UnknownHostException {		InetAddress a = InetAddress.getByName("127.2.3.4");		InetAddress b = InetAddress.getByName("127.2.3.3");		InetAddress c = InetAddress.getByName("127.2.3.255");		InetAddress d = InetAddress.getByName("127.2.3.0");				Subnet mask = new Subnet(a, 32);				assertTrue(mask.inSubnet(a));		assertFalse(mask.inSubnet(b));		assertFalse(mask.inSubnet(c));		assertFalse(mask.inSubnet(d));	}		public void testToString() throws UnknownHostException {		InetAddress a = InetAddress.getByName("127.2.3.0");		Subnet mask = new Subnet(a, 24);				assertEquals("127.2.3.0/24", mask.toString());	}	public void testToStringLiteral() throws UnknownHostException {		InetAddress a = InetAddress.getByName("localhost");		Subnet mask = new Subnet(a, 32);				assertEquals("127.0.0.1/32", mask.toString());	}			public void testEquals() throws UnknownHostException {		Subnet a = new Subnet(InetAddress.getByName("127.2.3.4"), 32);		Subnet b = new Subnet(InetAddress.getByName("127.2.3.4"), 32);		Subnet c = new Subnet(InetAddress.getByName("127.2.3.5"), 32);		Subnet d = new Subnet(InetAddress.getByName("127.2.3.5"), 24);				assertTrue(a.equals(b));		assertFalse(a.equals(c));		assertFalse(a.equals(d));		assertFalse(a.equals(null));	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -