forked from square/leakcanary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes square#162
- Loading branch information
Showing
6 changed files
with
175 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/com/squareup/leakcanary/RetainedSizeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.squareup.leakcanary; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK; | ||
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_MPREVIEW2; | ||
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_M_POSTPREVIEW2; | ||
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.SERVICE_BINDER; | ||
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.SERVICE_BINDER_IGNORED; | ||
import static com.squareup.leakcanary.TestUtil.analyze; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* This test makes sure there is no regression on the retained size calculation. | ||
*/ | ||
@RunWith(Parameterized.class) // | ||
public class RetainedSizeTest { | ||
|
||
@Parameterized.Parameters public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][] { | ||
{ ASYNC_TASK, 207_407 }, // | ||
{ ASYNC_TASK_MPREVIEW2, 1_604 }, // | ||
{ ASYNC_TASK_M_POSTPREVIEW2, 1_870 }, // | ||
{ SERVICE_BINDER, 378 }, // | ||
{ SERVICE_BINDER_IGNORED, 378 }, // | ||
}); | ||
} | ||
|
||
private final TestUtil.HeapDumpFile heapDumpFile; | ||
private final long expectedRetainedHeapSize; | ||
ExcludedRefs.Builder excludedRefs; | ||
|
||
public RetainedSizeTest(TestUtil.HeapDumpFile heapDumpFile, long expectedRetainedHeapSize) { | ||
this.heapDumpFile = heapDumpFile; | ||
this.expectedRetainedHeapSize = expectedRetainedHeapSize; | ||
} | ||
|
||
@Before public void setUp() { | ||
excludedRefs = new ExcludedRefs.Builder().clazz(WeakReference.class.getName(), true) | ||
.clazz("java.lang.ref.FinalizerReference", true); | ||
} | ||
|
||
@Test public void leakFound() { | ||
AnalysisResult result = analyze(heapDumpFile, excludedRefs); | ||
assertEquals(expectedRetainedHeapSize, result.retainedHeapSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters