summaryrefslogtreecommitdiffstats
path: root/harmony-tests
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-06-11 19:26:26 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-11 19:26:26 +0000
commit886a55157f2feda49098fe5b118280268a306830 (patch)
treec1b5d625a8a8667462fb9dc76ce530585b72901d /harmony-tests
parentd9814db6c843b8b0d0d118e568d00bc6f4f36f44 (diff)
parent3dc2e67e393d89902fac3deee351ee20cde3d2e3 (diff)
downloadlibcore-886a55157f2feda49098fe5b118280268a306830.zip
libcore-886a55157f2feda49098fe5b118280268a306830.tar.gz
libcore-886a55157f2feda49098fe5b118280268a306830.tar.bz2
am 3dc2e67e: am 995dc174: Merge "Tests for Runtime.*Memory()"
* commit '3dc2e67e393d89902fac3deee351ee20cde3d2e3': Tests for Runtime.*Memory()
Diffstat (limited to 'harmony-tests')
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/RuntimeTest.java36
1 files changed, 23 insertions, 13 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/RuntimeTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/RuntimeTest.java
index 08a4fa9..17f822d 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/RuntimeTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/RuntimeTest.java
@@ -19,6 +19,8 @@ package org.apache.harmony.tests.java.lang;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
public class RuntimeTest extends junit.framework.TestCase {
@@ -82,14 +84,6 @@ public class RuntimeTest extends junit.framework.TestCase {
}
/**
- * java.lang.Runtime#freeMemory()
- */
- public void test_freeMemory() {
- // Test for method long java.lang.Runtime.freeMemory()
- assertTrue("freeMemory returned nonsense value", r.freeMemory() > 0);
- }
-
- /**
* java.lang.Runtime#gc()
*/
public void test_gc() {
@@ -142,12 +136,28 @@ public class RuntimeTest extends junit.framework.TestCase {
}
/**
- * java.lang.Runtime#totalMemory()
+ * java.lang.Runtime#freeMemory() / java.lang.Runtime#totalMemory() /
+ * java.lang.Runtime#maxMemory()
*/
- public void test_totalMemory() {
- // Test for method long java.lang.Runtime.totalMemory()
- assertTrue("totalMemory returned nonsense value", r.totalMemory() >= r
- .freeMemory());
+ public void test_memory() {
+ assertTrue("freeMemory <= 0", r.freeMemory() > 0);
+ assertTrue("totalMemory() < freeMemory()", r.totalMemory() >= r.freeMemory());
+ assertTrue("maxMemory() < totalMemory()", r.maxMemory() >= r.totalMemory());
+ }
+
+ public void test_freeMemory() {
+ // Heap might grow or do GC at any time, so we can't really test a lot. Hence we are just
+ // doing some basic sanity checks here.
+ long freeBefore = r.freeMemory();
+ List<byte[]> arrays = new ArrayList<byte[]>();
+ for (int i = 1; i < 10; i++) {
+ arrays.add(new byte[10000]);
+ }
+ long freeAfter = r.freeMemory();
+
+ // If totalMemory() has grown/shrunk freeMemory() might have gone down or up, but the
+ // freeMemory is unlikely to stay the same.
+ assertTrue("free memory must change with allocations", freeAfter != freeBefore);
}
public RuntimeTest() {