1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ahat; 18 19 import com.android.ahat.heapdump.AhatInstance; 20 import com.android.ahat.heapdump.AhatSnapshot; 21 import java.io.IOException; 22 import org.junit.Test; 23 24 import static org.junit.Assert.assertNotNull; 25 26 public class ObjectHandlerTest { 27 @Test noCrashClassInstance()28 public void noCrashClassInstance() throws IOException { 29 TestDump dump = TestDump.getTestDump(); 30 31 AhatInstance object = dump.getDumpedAhatInstance("aPhantomReference"); 32 assertNotNull(object); 33 34 AhatHandler handler = new ObjectHandler(dump.getAhatSnapshot()); 35 TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); 36 } 37 38 @Test noCrashClassObj()39 public void noCrashClassObj() throws IOException { 40 TestDump dump = TestDump.getTestDump(); 41 42 AhatSnapshot snapshot = dump.getAhatSnapshot(); 43 AhatHandler handler = new ObjectHandler(snapshot); 44 45 AhatInstance object = dump.findClass("Main"); 46 assertNotNull(object); 47 48 TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); 49 } 50 51 @Test noCrashSystemClassObj()52 public void noCrashSystemClassObj() throws IOException { 53 TestDump dump = TestDump.getTestDump(); 54 55 AhatSnapshot snapshot = dump.getAhatSnapshot(); 56 AhatHandler handler = new ObjectHandler(snapshot); 57 58 AhatInstance object = dump.findClass("java.lang.String"); 59 assertNotNull(object); 60 61 TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); 62 } 63 64 @Test noCrashArrayInstance()65 public void noCrashArrayInstance() throws IOException { 66 TestDump dump = TestDump.getTestDump(); 67 68 AhatInstance object = dump.getDumpedAhatInstance("gcPathArray"); 69 assertNotNull(object); 70 71 AhatHandler handler = new ObjectHandler(dump.getAhatSnapshot()); 72 TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); 73 } 74 } 75