/*******************************************************************************
* Licensed 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 test.apache.kato.common;
import java.io.IOException;
import java.util.List;
import junit.framework.TestCase;
import org.apache.kato.common.IDataProvider;
import org.apache.kato.common.SubsetDataProvider;
public class TestSubsetDataProvider extends TestCase {
public void testCreationNullProvider() throws IOException {
try {
new SubsetDataProvider(null,0);
fail("Expected illegal arguement exception");
}
catch (IllegalArgumentException e) {
; // ok
}
}
public void testCreationNegativeRange() throws IOException {
try {
new SubsetDataProvider(new MockDataProvider(),-1);
fail("Expected illegal arguement exception");
}
catch (IllegalArgumentException e) {
; // ok
}
}
public void testGetDataAt00() throws IOException {
SubsetDataProvider provider=new SubsetDataProvider(new MockDataProvider(),10);
short b=provider.readByte();
assertEquals(0,b);
}
public void testGetDataAt01() throws IOException {
MockDataProvider p=new MockDataProvider();
p.moveTo(1);
SubsetDataProvider provider=new SubsetDataProvider(p,10);
short b=provider.readByte();
assertEquals(1,b);
}
class MockDataProvider implements IDataProvider {
private long location=0;
private long length=100;
public MockDataProvider() {
}
public MockDataProvider(int length) {
this.length=length;
}
@Override
public void addState(List state) {
// TODO Auto-generated method stub
}
@Override
public void close() throws IOException {
// TODO Auto-generated method stub
}
@Override
public long getCurrentLocation() throws IOException {
return location;
}
@Override
public long getDataLength() throws IOException {
return length;
}
@Override
public void moveBy(int left) throws IOException {
// TODO Auto-generated method stub
}
@Override
public void moveTo(long l) throws IOException {
this.location=l;
}
@Override
public void open() throws IOException {
// TODO Auto-generated method stub
}
@Override
public short readByte() throws IOException {
return (short) location;
}
@Override
public byte[] readBytes(int left) throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public String readCString() throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public short readU2() throws IOException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int readU4() throws IOException {
// TODO Auto-generated method stub
return 0;
}
@Override
public long readU8() throws IOException {
// TODO Auto-generated method stub
return 0;
}
@Override
public long dataRemaining() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean moved() {
// TODO Auto-generated method stub
return false;
}
}
}