/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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.jboss.netty.buffer;
import static org.jboss.netty.buffer.ChannelBuffers.*;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Random;
import java.util.Set;
import org.jboss.netty.util.CharsetUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* An abstract test class for channel buffers
*/
public abstract class AbstractChannelBufferTest {
private static final int CAPACITY = 4096; // Must be even
private static final int BLOCK_SIZE = 128;
private long seed;
private Random random;
private ChannelBuffer buffer;
protected abstract ChannelBuffer newBuffer(int capacity);
protected abstract ChannelBuffer[] components();
protected boolean discardReadBytesDoesNotMoveWritableBytes() {
return true;
}
@Before
public void init() {
buffer = newBuffer(CAPACITY);
seed = System.currentTimeMillis();
random = new Random(seed);
}
@After
public void dispose() {
buffer = null;
}
@Test
public void initialState() {
assertEquals(CAPACITY, buffer.capacity());
assertEquals(0, buffer.readerIndex());
}
@Test(expected = IndexOutOfBoundsException.class)
public void readerIndexBoundaryCheck1() {
try {
buffer.writerIndex(0);
} catch (IndexOutOfBoundsException e) {
fail();
}
buffer.readerIndex(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void readerIndexBoundaryCheck2() {
try {
buffer.writerIndex(buffer.capacity());
} catch (IndexOutOfBoundsException e) {
fail();
}
buffer.readerIndex(buffer.capacity() + 1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void readerIndexBoundaryCheck3() {
try {
buffer.writerIndex(CAPACITY / 2);
} catch (IndexOutOfBoundsException e) {
fail();
}
buffer.readerIndex(CAPACITY * 3 / 2);
}
@Test
public void readerIndexBoundaryCheck4() {
buffer.writerIndex(0);
buffer.readerIndex(0);
buffer.writerIndex(buffer.capacity());
buffer.readerIndex(buffer.capacity());
}
@Test(expected = IndexOutOfBoundsException.class)
public void writerIndexBoundaryCheck1() {
buffer.writerIndex(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void writerIndexBoundaryCheck2() {
try {
buffer.writerIndex(CAPACITY);
buffer.readerIndex(CAPACITY);
} catch (IndexOutOfBoundsException e) {
fail();
}
buffer.writerIndex(buffer.capacity() + 1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void writerIndexBoundaryCheck3() {
try {
buffer.writerIndex(CAPACITY);
buffer.readerIndex(CAPACITY / 2);
} catch (IndexOutOfBoundsException e) {
fail();
}
buffer.writerIndex(CAPACITY / 4);
}
@Test
public void writerIndexBoundaryCheck4() {
buffer.writerIndex(0);
buffer.readerIndex(0);
buffer.writerIndex(CAPACITY);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getByteBoundaryCheck1() {
buffer.getByte(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getByteBoundaryCheck2() {
buffer.getByte(buffer.capacity());
}
@Test(expected = IndexOutOfBoundsException.class)
public void getShortBoundaryCheck1() {
buffer.getShort(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getShortBoundaryCheck2() {
buffer.getShort(buffer.capacity() - 1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getMediumBoundaryCheck1() {
buffer.getMedium(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getMediumBoundaryCheck2() {
buffer.getMedium(buffer.capacity() - 2);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getIntBoundaryCheck1() {
buffer.getInt(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getIntBoundaryCheck2() {
buffer.getInt(buffer.capacity() - 3);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getLongBoundaryCheck1() {
buffer.getLong(-1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getLongBoundaryCheck2() {
buffer.getLong(buffer.capacity() - 7);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getByteArrayBoundaryCheck1() {
buffer.getBytes(-1, new byte[0]);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getByteArrayBoundaryCheck2() {
buffer.getBytes(-1, new byte[0], 0, 0);
}
@Test
public void getByteArrayBoundaryCheck3() {
byte[] dst = new byte[4];
buffer.setInt(0, 0x01020304);
try {
buffer.getBytes(0, dst, -1, 4);
fail();
} catch (IndexOutOfBoundsException e) {
// Success
}
// No partial copy is expected.
assertEquals(0, dst[0]);
assertEquals(0, dst[1]);
assertEquals(0, dst[2]);
assertEquals(0, dst[3]);
}
@Test
public void getByteArrayBoundaryCheck4() {
byte[] dst = new byte[4];
buffer.setInt(0, 0x01020304);
try {
buffer.getBytes(0, dst, 1, 4);
fail();
} catch (IndexOutOfBoundsException e) {
// Success
}
// No partial copy is expected.
assertEquals(0, dst[0]);
assertEquals(0, dst[1]);
assertEquals(0, dst[2]);
assertEquals(0, dst[3]);
}
@Test(expected = IndexOutOfBoundsException.class)
public void getByteBufferBoundaryCheck() {
buffer.getBytes(-1, ByteBuffer.allocate(0));
}
@Test(expected = IndexOutOfBoundsException.class)
public void copyBoundaryCheck1() {
buffer.copy(-1, 0);
}
@Test(expected = IndexOutOfBoundsException.class)
public void copyBoundaryCheck2() {
buffer.copy(0, buffer.capacity() + 1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void copyBoundaryCheck3() {
buffer.copy(buffer.capacity() + 1, 0);
}
@Test(expected = IndexOutOfBoundsException.class)
public void copyBoundaryCheck4() {
buffer.copy(buffer.capacity(), 1);
}
@Test(expected = IndexOutOfBoundsException.class)
public void setIndexBoundaryCheck1() {
buffer.setIndex(-1, CAPACITY);
}
@Test(expected = IndexOutOfBoundsException.class)
public void setIndexBoundaryCheck2() {
buffer.setIndex(CAPACITY / 2, CAPACITY / 4);
}
@Test(expected = IndexOutOfBoundsException.class)
public void setIndexBoundaryCheck3() {
buffer.setIndex(0, CAPACITY + 1);
}
@Test
public void getByteBufferState() {
ByteBuffer dst = ByteBuffer.allocate(4);
dst.position(1);
ds
没有合适的资源?快使用搜索试试~ 我知道了~
基于java的开发源码-网络应用框架 Netty.zip
共2000个文件
html:1693个
java:299个
xml:4个
0 下载量 10 浏览量
2024-04-01
19:53:53
上传
评论
收藏 12.46MB ZIP 举报
温馨提示
基于java的开发源码-网络应用框架 Netty.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于java的开发源码-网络应用框架 Netty.zip (2000个子文件)
stylesheet.css 11KB
stylesheet.css 2KB
index-all.html 1.85MB
LocalTimeProtocol.html 334KB
HttpPostRequestDecoder.html 282KB
ChannelBuffer.html 261KB
ChannelHandlerContext.html 251KB
ChannelBuffer.html 235KB
ChannelBuffer.html 207KB
Deflate.html 206KB
SslHandler.html 184KB
AbstractChannelBuffer.html 183KB
ConcurrentIdentityWeakKeyHashMap.html 181KB
ConcurrentWeakKeyHashMap.html 180KB
Channel.html 179KB
package-use.html 175KB
ConcurrentIdentityHashMap.html 171KB
ConcurrentHashMap.html 170KB
HttpUploadClient.html 162KB
ChannelBuffers.html 157KB
ChannelHandler.html 152KB
overview-tree.html 149KB
ChannelFuture.html 136KB
HttpHeaders.html 134KB
Channels.html 131KB
HttpPostRequestEncoder.html 130KB
constant-values.html 126KB
Channels.html 116KB
SpdySessionHandler.html 114KB
AbstractNioWorker.html 108KB
DefaultChannelPipeline.html 103KB
ChannelBuffers.html 97KB
HttpMessageDecoder.html 95KB
allclasses-frame.html 94KB
SpdyFrameDecoder.html 94KB
SpdyHeaders.html 93KB
ChannelEvent.html 92KB
CompositeChannelBuffer.html 92KB
ReplayingDecoderBuffer.html 90KB
ReadOnlyChannelBuffer.html 89KB
DynamicChannelBuffer.html 88KB
TruncatedChannelBuffer.html 86KB
SlicedChannelBuffer.html 86KB
DuplicatedChannelBuffer.html 86KB
MemoryAwareThreadPoolExecutor.html 84KB
StaticChannelPipeline.html 79KB
SslHandler.html 79KB
InfCodes.html 78KB
AbstractChannelBuffer.html 77KB
InfBlocks.html 77KB
HttpHeaders.Names.html 77KB
Inflate.html 75KB
CompositeChannelBuffer.html 75KB
ChannelUpstreamHandler.html 75KB
FrameDecoder.html 75KB
DefaultChannelPipeline.html 74KB
ChannelPipeline.html 74KB
ReplayingDecoder.html 74KB
HttpResponseStatus.html 73KB
FrameDecoder.html 73KB
HttpTunnelingSocketChannelConfig.html 72KB
allclasses-frame.html 71KB
HashedWheelTimer.html 70KB
StaticChannelPipeline.html 69KB
NioClientSocketPipelineSink.html 68KB
HttpResponseStatus.html 68KB
ReplayingDecoder.html 68KB
ChannelPipeline.html 67KB
SpdyHeaders.html 66KB
AbstractTrafficShapingHandler.html 66KB
HttpUploadServerHandler.html 65KB
IdleStateHandler.html 65KB
MemoryAwareThreadPoolExecutor.html 65KB
HttpResponseStatus.html 64KB
DefaultChannelGroup.html 64KB
AbstractChannel.html 64KB
ByteBufferBackedChannelBuffer.html 64KB
ChannelDownstreamHandler.html 64KB
Bootstrap.html 63KB
allclasses-noframe.html 63KB
LengthFieldBasedFrameDecoder.html 62KB
SimpleChannelHandler.html 61KB
MixedFileUpload.html 61KB
InfTree.html 60KB
WebSocket08FrameDecoder.html 60KB
DefaultDatagramChannelConfig.html 59KB
DefaultChannelFuture.html 56KB
RtspHeaders.html 56KB
ObjectDecoderInputStream.html 55KB
BufferedWriteHandler.html 55KB
Channel.html 55KB
HttpMessage.html 54KB
ZlibEncoder.html 54KB
MixedAttribute.html 54KB
RtspHeaders.Names.html 54KB
HeapChannelBuffer.html 54KB
ChannelStateEvent.html 54KB
NioProviderMetadata.html 54KB
SpdyCodecUtil.html 54KB
QueryStringDecoder.html 54KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
毕业_设计
- 粉丝: 1944
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功