/*******************************************************************************
* 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.image;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.tools.diagnostics.image.CorruptDataException;
import javax.tools.diagnostics.image.DataUnavailable;
import javax.tools.diagnostics.image.ImageAddressSpace;
import javax.tools.diagnostics.image.ImageProcess;
import javax.tools.diagnostics.runtime.java.JavaRuntime;
public class TestImageProcess extends AbstractHProfTestCase {
public void testGetCommandLine() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getCommandLine();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetEnvironment() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getEnvironment();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetExecutable() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getExecutable();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetLibraries() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getLibraries();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetSignalNumber() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getSignalNumber();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetSignalName() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getSignalName();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetID() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
try {
process.getID();
fail("expected DataUnavailable exception");
} catch(DataUnavailable du) {
}
}
public void testGetPointerSize() throws IOException, CorruptDataException {
ImageProcess process=getCurrentProcess();
int size=process.getPointerSize();
assertTrue("pointer size ("+size+") is less than 1",size>0);
}
public void testGetThreadsNotNull() throws Exception {
ImageProcess process = getCurrentProcess();
List threads = process.getThreads();
assertNotNull(threads);
}
public void testGetThreadsEmpty() throws Exception {
ImageProcess process = getCurrentProcess();
Iterator threads = process.getThreads().iterator();
assertFalse(threads.hasNext());
}
public void testGetCurrentThread() throws Exception {
ImageProcess process = getCurrentProcess();
assertNull(process.getCurrentThread());
}
public void testGetRuntimes() throws Exception {
ImageProcess process = getCurrentProcess();
Iterator runtimes = process.getRuntimes().iterator();
int count = 0;
while (runtimes.hasNext()) {
Object obj = runtimes.next();
count++;
assertTrue(obj instanceof JavaRuntime);
}
assertEquals(1, count);
}
public void testEqualsSelf() throws Exception {
ImageProcess process = getCurrentProcess();
assertTrue(process.equals(process));
}
public void testEqualsNull() throws Exception {
ImageProcess process = getCurrentProcess();
assertFalse(process.equals(null));
}
public void testEqualsString() throws Exception {
ImageProcess process = getCurrentProcess();
assertFalse(process.equals("This is not a Process"));
}
public void testEqualsOther() throws Exception {
ImageProcess populatedProcess = ((ImageAddressSpace)(getPopulatedImage().getAddressSpaces().get(0))).getCurrentProcess();
ImageProcess process = getCurrentProcess();
assertFalse(process.equals(populatedProcess));
}
}