Path: blob/master/test/jdk/java/io/Serializable/class/NonSerializableTest.java
41154 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 407522126* @library /test/lib27* @build jdk.test.lib.compiler.CompilerUtils28* jdk.test.lib.Utils29* jdk.test.lib.Asserts30* jdk.test.lib.JDKToolFinder31* jdk.test.lib.JDKToolLauncher32* jdk.test.lib.Platform33* jdk.test.lib.process.*34* @run testng/timeout=300 NonSerializableTest35* @summary Enable serialize of nonSerializable Class descriptor.36*/3738import java.nio.file.Paths;39import java.util.Arrays;4041import org.testng.annotations.DataProvider;42import org.testng.annotations.BeforeClass;43import org.testng.annotations.Test;44import static org.testng.Assert.assertTrue;45import static org.testng.Assert.assertEquals;4647import jdk.test.lib.compiler.CompilerUtils;48import jdk.test.lib.process.ProcessTools;495051public class NonSerializableTest {5253@BeforeClass54public void setup() throws Exception {55boolean b = CompilerUtils.compile(56Paths.get(System.getProperty("test.src"), "TestEntry.java"),57Paths.get(System.getProperty("user.dir")));58assertTrue(b, "Compilation failed");59}6061@DataProvider62public Object[][] provider() {63return new String[][][] {64// Write NonSerial1, Read NonSerial165{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},66{{"NonSerialA_1", "-cp", ".", "TestEntry", "-d"}},6768// Write NonSerial1, Read NonSerial269{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},70{{"NonSerialA_2", "-cp", ".", "TestEntry", "-d"}},7172// Write NonSerial1, Read Serial173{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},74{{"SerialA_1", "-cp", ".", "TestEntry", "-d"}},7576// Write Serial1, Read NonSerial177{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},78{{"NonSerialA_1", "-cp", ".", "TestEntry", "-doe"}},7980// Write Serial1, Read Serial281{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},82{{"SerialA_2", "-cp", ".", "TestEntry", "-d"}},8384// Write Serial2, Read Serial185{{"SerialA_2", "-cp", ".", "TestEntry", "-s", "A"}},86{{"SerialA_1", "-cp", ".", "TestEntry", "-d"}},8788// Write Serial1, Read Serial389{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},90{{"SerialA_3", "-cp", ".", "TestEntry", "-de"}},9192// Write Serial3, Read Serial193{{"SerialA_3", "-cp", ".", "TestEntry", "-s", "A"}},94{{"SerialA_1", "-cp", ".", "TestEntry", "-de"}},95};96}9798@Test(dataProvider="provider")99public void test(String[] args) throws Exception {100boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), args[0]),101Paths.get(System.getProperty("user.dir")));102assertTrue(b, "Compilation failed");103String params[] = Arrays.copyOfRange(args, 1, args.length);104ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(params);105Process p = ProcessTools.startProcess("Serializable Test", pb);106int exitValue = p.waitFor();107assertEquals(exitValue, 0, "Test failed");108}109}110111112