1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.harmony.tests.java.lang; 19 20 import java.io.IOException; 21 import java.io.InputStream; 22 import java.util.ArrayList; 23 import java.util.List; 24 import java.util.Vector; 25 26 public class RuntimeTest extends junit.framework.TestCase { 27 28 Runtime r = Runtime.getRuntime(); 29 30 InputStream is; 31 32 String s; 33 34 static boolean flag = false; 35 36 static boolean ranFinalize = false; 37 38 class HasFinalizer { 39 String internalString; 40 41 HasFinalizer(String s) { 42 internalString = s; 43 } 44 45 @Override 46 protected void finalize() { 47 internalString = "hit"; 48 } 49 } 50 51 @Override 52 protected void finalize() { 53 if (flag) 54 ranFinalize = true; 55 } 56 57 protected RuntimeTest createInstance() { 58 return new RuntimeTest("FT"); 59 } 60 61 /** 62 * java.lang.Runtime#exit(int) 63 */ 64 public void test_exitI() { 65 // Test for method void java.lang.Runtime.exit(int) 66 assertTrue("Can't really test this", true); 67 } 68 69 /** 70 * java.lang.Runtime#exec(java.lang.String) 71 */ 72 public void test_exec() { 73 boolean success = false; 74 75 /* successful exec's are tested by java.lang.Process */ 76 try { 77 Runtime.getRuntime().exec("AnInexistentProgram"); 78 } catch (IOException e) { 79 success = true; 80 } 81 assertTrue( 82 "failed to throw IOException when exec'ed inexistent program", 83 success); 84 } 85 86 /** 87 * java.lang.Runtime#getRuntime() 88 */ 89 public void test_getRuntime() { 90 // Test for method java.lang.Runtime java.lang.Runtime.getRuntime() 91 assertTrue("Used to test", true); 92 } 93 94 /** 95 * java.lang.Runtime#runFinalization() 96 */ 97 public void test_runFinalization() { 98 // Test for method void java.lang.Runtime.runFinalization() 99 100 flag = true; 101 createInstance(); 102 int count = 10; 103 // the gc below likely bogosifies the test, but will have to do for 104 // the moment 105 while (!ranFinalize && count-- > 0) { 106 r.gc(); 107 r.runFinalization(); 108 } 109 assertTrue("Failed to run finalization", ranFinalize); 110 } 111 112 /** 113 * java.lang.Runtime#freeMemory() / java.lang.Runtime#totalMemory() / 114 * java.lang.Runtime#maxMemory() 115 */ 116 public void test_memory() { 117 assertTrue("freeMemory < 0", r.freeMemory() >= 0); 118 assertTrue("totalMemory() < freeMemory()", r.totalMemory() >= r.freeMemory()); 119 assertTrue("maxMemory() < totalMemory()", r.maxMemory() >= r.totalMemory()); 120 } 121 122 public RuntimeTest() { 123 } 124 125 public RuntimeTest(String name) { 126 super(name); 127 } 128 } 129