8180927: refactor ./java/io/Serializable/class/run.sh to java test
Reviewed-by: psandoz
This commit is contained in:
parent
4af3f644b2
commit
2af3b0cc19
105
jdk/test/java/io/Serializable/class/NonSerializableTest.java
Normal file
105
jdk/test/java/io/Serializable/class/NonSerializableTest.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4075221
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.compiler.*
|
||||
* @build jdk.test.lib.process.*
|
||||
* @run testng/timeout=300 NonSerializableTest
|
||||
* @summary Enable serialize of nonSerializable Class descriptor.
|
||||
*/
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import jdk.test.lib.compiler.CompilerUtils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
|
||||
public class NonSerializableTest {
|
||||
|
||||
@BeforeClass
|
||||
public void setup() throws Exception {
|
||||
boolean b = CompilerUtils.compile(
|
||||
Paths.get(System.getProperty("test.src"), "TestEntry.java"),
|
||||
Paths.get(System.getProperty("user.dir")));
|
||||
assertTrue(b, "Compilation failed");
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new String[][][] {
|
||||
// Write NonSerial1, Read NonSerial1
|
||||
{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"NonSerialA_1", "-cp", ".", "TestEntry", "-d"}},
|
||||
|
||||
// Write NonSerial1, Read NonSerial2
|
||||
{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"NonSerialA_2", "-cp", ".", "TestEntry", "-d"}},
|
||||
|
||||
// Write NonSerial1, Read Serial1
|
||||
{{"NonSerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-d"}},
|
||||
|
||||
// Write Serial1, Read NonSerial1
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"NonSerialA_1", "-cp", ".", "TestEntry", "-doe"}},
|
||||
|
||||
// Write Serial1, Read Serial2
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"SerialA_2", "-cp", ".", "TestEntry", "-d"}},
|
||||
|
||||
// Write Serial2, Read Serial1
|
||||
{{"SerialA_2", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-d"}},
|
||||
|
||||
// Write Serial1, Read Serial3
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"SerialA_3", "-cp", ".", "TestEntry", "-de"}},
|
||||
|
||||
// Write Serial3, Read Serial1
|
||||
{{"SerialA_3", "-cp", ".", "TestEntry", "-s", "A"}},
|
||||
{{"SerialA_1", "-cp", ".", "TestEntry", "-de"}},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="provider")
|
||||
public void test(String[] args) throws Exception {
|
||||
boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), args[0]),
|
||||
Paths.get(System.getProperty("user.dir")));
|
||||
assertTrue(b, "Compilation failed");
|
||||
String params[] = Arrays.copyOfRange(args, 1, args.length);
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(params);
|
||||
Process p = ProcessTools.startProcess("Serializable Test", pb);
|
||||
int exitValue = p.waitFor();
|
||||
assertEquals(exitValue, 0, "Test failed");
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class A implements Serializable {
|
||||
int field1;
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,9 +26,16 @@
|
||||
* @summary Enable serialize of nonSerializable Class descriptor.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InvalidClassException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
|
||||
class Test {
|
||||
class TestEntry {
|
||||
public static void main(String args[]) throws Exception {
|
||||
File f = new File("tmp.ser");
|
||||
if (args[0].compareTo("-s") == 0) {
|
||||
@ -73,6 +80,8 @@ class Test {
|
||||
}
|
||||
ois.close();
|
||||
System.out.println("DeSerialized Class " + cl.getName());
|
||||
} else {
|
||||
throw new RuntimeException("Unrecognized argument");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# @test
|
||||
# @bug 4075221
|
||||
# @run shell/timeout=300 run.sh
|
||||
# @summary Enable serialize of nonSerializable Class descriptor.
|
||||
|
||||
set -ex
|
||||
|
||||
if [ "${TESTJAVA}" = "" ]
|
||||
then
|
||||
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${COMPILEJAVA}" = "" ] ; then
|
||||
COMPILEJAVA="${TESTJAVA}"
|
||||
fi
|
||||
|
||||
if [ "${TESTSRC}" = "" ]
|
||||
then
|
||||
TESTSRC="."
|
||||
fi
|
||||
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Test.java
|
||||
|
||||
echo Write NonSerial1, Read NonSerial1
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/NonSerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -d
|
||||
echo
|
||||
|
||||
echo Write NonSerial1, Read NonSerial2
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/NonSerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/NonSerialA_2.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -d
|
||||
echo
|
||||
|
||||
echo Write NonSerial1, Read Serial1
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/NonSerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -d
|
||||
echo
|
||||
|
||||
echo Write Serial1, Read NonSerial1
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/NonSerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -doe
|
||||
echo
|
||||
|
||||
echo Write Serial1, Read Serial2
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_2.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -d
|
||||
echo
|
||||
|
||||
echo Write Serial2, Read Serial1
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_2.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -d
|
||||
echo
|
||||
|
||||
echo Write Serial1, Read Serial3
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_3.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -de
|
||||
echo
|
||||
|
||||
echo Write Serial3, Read Serial1
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_3.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -s A
|
||||
rm -f A.java
|
||||
cp ${TESTSRC}/SerialA_1.java A.java
|
||||
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} A.java
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} Test -de
|
||||
echo
|
||||
|
||||
echo Passed
|
Loading…
Reference in New Issue
Block a user