1561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/*
2561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  Licensed to the Apache Software Foundation (ASF) under one or more
3561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  contributor license agreements.  See the NOTICE file distributed with
4561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  this work for additional information regarding copyright ownership.
5561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  The ASF licenses this file to You under the Apache License, Version 2.0
6561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  (the "License"); you may not use this file except in compliance with
7561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  the License.  You may obtain a copy of the License at
8561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
9561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *     http://www.apache.org/licenses/LICENSE-2.0
10561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
11561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  Unless required by applicable law or agreed to in writing, software
12561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  distributed under the License is distributed on an "AS IS" BASIS,
13561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  See the License for the specific language governing permissions and
15561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  limitations under the License.
16561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */
17561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
18561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespackage org.apache.harmony.luni.tests.internal.process;
19561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
20561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.OutputStream;
21561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
22561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport junit.framework.TestCase;
23561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport tests.support.Support_Exec;
24561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
25561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespublic class SystemProcessTest extends TestCase {
26561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
27561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_interrupt() throws Exception {
28561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Object[] execArgs = null;
29561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Process process = null;
30561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
31561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            Thread.currentThread().interrupt();
32561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            execArgs = Support_Exec.execJava2(
33561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    new String[] { "tests.support.Support_AvailTest" }, null,
34561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    true);
35561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            process = (Process) execArgs[0];
36561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            OutputStream os = process.getOutputStream();
37561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            os.write("10 5 abcde".getBytes());
38561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            os.close();
39561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            process.waitFor();
40561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw InterruptedException");
41561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (InterruptedException e) {
42561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Expected
43561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
44561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
45561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
46561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            Thread.sleep(1000);
47561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (InterruptedException e) {
48561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Ignored
49561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
50561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        process.waitFor();
51561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Support_Exec.checkStderr(execArgs);
52561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        process.destroy();
53561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
54561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes}
55