1 /*
2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8224184
27  * @summary Control Char <UNDEF> check for pty
28  * @modules jdk.internal.le/jdk.internal.org.jline.terminal
29  *          jdk.internal.le/jdk.internal.org.jline.terminal.impl
30  * @requires (os.family == "linux") | (os.family == "aix")
31  */
32 
33 import java.util.List;
34 import jdk.internal.org.jline.terminal.Attributes;
35 import jdk.internal.org.jline.terminal.Attributes.ControlChar;
36 import jdk.internal.org.jline.terminal.Attributes.LocalFlag;
37 import jdk.internal.org.jline.terminal.impl.ExecPty;
38 
39 public class ExecPtyGetFlagsToSetTest extends ExecPty {
ExecPtyGetFlagsToSetTest(String name, boolean system)40     public ExecPtyGetFlagsToSetTest(String name, boolean system) {
41         super(name, system);
42     }
43 
44     @Override
getFlagsToSet(Attributes attr, Attributes current)45     protected List<String> getFlagsToSet(Attributes attr, Attributes current) {
46         return super.getFlagsToSet(attr, current);
47     }
48 
main(String[] args)49     public static void main(String[] args) {
50         ExecPtyGetFlagsToSetTest testPty =
51             new ExecPtyGetFlagsToSetTest("stty", true);
52 
53         Attributes attr = new Attributes();
54         Attributes current = new Attributes();
55 
56         current.setLocalFlag(LocalFlag.ICANON, false);
57         current.setControlChar(ControlChar.VMIN, 1);
58         current.setControlChar(ControlChar.VTIME, 0);
59 
60         attr.setLocalFlag(LocalFlag.ICANON, true);
61         attr.setControlChar(ControlChar.VMIN, -1);
62         attr.setControlChar(ControlChar.VTIME, -1);
63 
64         List<String> commands = testPty.getFlagsToSet(attr, current);
65         String result = String.join(" ", commands);
66         if (!result.equals("icanon")) {
67             throw new RuntimeException("stty options contains invalid value.");
68         }
69     }
70 }
71