ProcessBuilderTest.java revision bfd74c5fa8b6b91dfc28986da159a9179916d0e6
1/* 2 * Copyright (C) 2009 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 17package java.lang; 18 19import static tests.support.Support_Exec.execAndCheckOutput; 20 21import junit.framework.Test; 22import junit.framework.TestSuite; 23 24import java.io.InputStream; 25import java.util.Arrays; 26 27public class ProcessBuilderTest extends junit.framework.TestCase { 28 private static String shell() { 29 return "Dalvik".equals(System.getProperty("java.vm.name")) ? "/system/bin/sh" : "/bin/sh"; 30 } 31 32 public void testRedirectErrorStream(boolean doRedirect, 33 String expectedOut, String expectedErr) throws Exception { 34 ProcessBuilder pb = new ProcessBuilder(shell(), "-c", "echo out; echo err 1>&2"); 35 pb.redirectErrorStream(doRedirect); 36 execAndCheckOutput(pb, expectedOut, expectedErr); 37 } 38 39 public void test_redirectErrorStream_true() throws Exception { 40 testRedirectErrorStream(true, "out\nerr\n", ""); 41 } 42 43 public void test_redirectErrorStream_false() throws Exception { 44 testRedirectErrorStream(false, "out\n", "err\n"); 45 } 46} 47