1/* 2 * Copyright (c) 2016, 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 8160128 8159935 8168615 27 * @summary Tests for Aux channel, custom remote agents, custom JDI implementations. 28 * @build KullaTesting ExecutionControlTestBase MyExecutionControl MyRemoteExecutionControl MyExecutionControlProvider 29 * @run testng UserJdiUserRemoteTest 30 */ 31import java.io.ByteArrayOutputStream; 32import org.testng.annotations.Test; 33import org.testng.annotations.BeforeMethod; 34import jdk.jshell.Snippet; 35import static jdk.jshell.Snippet.Status.OVERWRITTEN; 36import static jdk.jshell.Snippet.Status.VALID; 37import jdk.jshell.VarSnippet; 38import jdk.jshell.spi.ExecutionControl; 39import jdk.jshell.spi.ExecutionControl.ExecutionControlException; 40import static org.testng.Assert.assertEquals; 41 42@Test 43public class UserJdiUserRemoteTest extends ExecutionControlTestBase { 44 45 ExecutionControl currentEC; 46 ByteArrayOutputStream auxStream; 47 48 @BeforeMethod 49 @Override 50 public void setUp() { 51 auxStream = new ByteArrayOutputStream(); 52 setUp(builder -> builder.executionEngine(new MyExecutionControlProvider(this), null)); 53 } 54 55 public void testVarValue() { 56 VarSnippet dv = varKey(assertEval("double aDouble = 1.5;")); 57 String vd = getState().varValue(dv); 58 assertEquals(vd, "1.5"); 59 assertEquals(auxStream.toString(), "aDouble"); 60 } 61 62 public void testExtension() throws ExecutionControlException { 63 assertEval("42;"); 64 Object res = currentEC.extensionCommand("FROG", "test"); 65 assertEquals(res, "ribbit"); 66 } 67 68 public void testRedefine() { 69 Snippet vx = varKey(assertEval("int x;")); 70 Snippet mu = methodKey(assertEval("int mu() { return x * 4; }")); 71 Snippet c = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }")); 72 assertEval("C c0 = new C();"); 73 assertEval("c0.v();", "\"#0\""); 74 assertEval("int x = 10;", "10", 75 ste(MAIN_SNIPPET, VALID, VALID, false, null), 76 ste(vx, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); 77 assertEval("c0.v();", "\"#40\""); 78 assertEval("C c = new C();"); 79 assertEval("c.v();", "\"#40\""); 80 assertEval("int mu() { return x * 3; }", 81 ste(MAIN_SNIPPET, VALID, VALID, false, null), 82 ste(mu, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); 83 assertEval("c.v();", "\"#30\""); 84 assertEval("class C { String v() { return \"@\" + mu(); } }", 85 ste(MAIN_SNIPPET, VALID, VALID, false, null), 86 ste(c, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); 87 assertEval("c0.v();", "\"@30\""); 88 assertEval("c = new C();"); 89 assertEval("c.v();", "\"@30\""); 90 assertActiveKeys(); 91 } 92} 93