/*******************************************************************************
* 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.hprof;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import junit.framework.TestCase;
import org.apache.kato.hprof.datalayer.HProfFile;
import org.apache.kato.hprof.datalayer.HProfFactory;
import org.apache.kato.hprof.datalayer.IHProfRecord;
public class TestHProf extends TestCase {
private static final String DUMP = "/data/java.hprof";
public void testHeader() throws IOException,java.net.URISyntaxException {
URL datafile=getClass().getResource(DUMP);
URI i=datafile.toURI();
File dump=new File(i);
HProfFile h=HProfFactory.createReader(dump);
h.open();
String header=h.getHeader();
int idSize=h.getIdentifierSize();
long timeStamp=h.getTimeStamp();
IHProfRecord record=h.getRecord(0);
assertNotNull(record);
System.out.println("tag="+Integer.toHexString(record.getTag()));
h.close();
}
public void testRead() throws IOException,java.net.URISyntaxException {
URL datafile=getClass().getResource(DUMP);
URI i=datafile.toURI();
File dump=new File(i);
HProfFile h=HProfFactory.createReader(dump);
h.open();
int records=h.getRecordCount();
h.close();
assertEquals(1526,records);
}
public void testReadTwice() throws IOException,java.net.URISyntaxException {
URL datafile=getClass().getResource(DUMP);
URI uri=datafile.toURI();
File dump=new File(uri);
HProfFile h=HProfFactory.createReader(dump);
h.open();
int records=h.getRecordCount();
for(int i=0;i<records;i++) {
Object o=h.getRecord(i);
assertNotNull("element "+i+" is null",o);
}
h.close();
}
}