/*******************************************************************************
* 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.File;
import java.io.RandomAccessFile;
import org.apache.kato.hprof.datalayer.CachedRandomAccesDataProvider;
import junit.framework.TestCase;
public class TestCachedRandomAccessDataProvider extends TestCase {
static File testFile = new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"testFile");
public void setUp() throws Exception {
if(!testFile.exists()) {
RandomAccessFile raf = new RandomAccessFile(testFile,"rw");
for(int i=0; i < 1048576; i++) {
raf.writeInt(i);
}
raf.close();
}
}
public void testRead() throws Exception {
CachedRandomAccesDataProvider provider = new CachedRandomAccesDataProvider(testFile);
provider.open();
for(int i=0; i < 1048576; i++) {
int val = provider.readU4();
assertEquals(i,val);
}
provider.close();
}
public void testReadBackwards() throws Exception {
CachedRandomAccesDataProvider provider = new CachedRandomAccesDataProvider(testFile);
provider.open();
for(int i=1048572; i >0 ; i-=1) {
provider.moveTo(i*4);
int val = provider.readU4();
assertEquals(i,val);
}
provider.close();
}
}