1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package tests.util; 19 20 import java.io.FileOutputStream; 21 import java.io.ObjectOutputStream; 22 import java.io.IOException; 23 import tests.support.Support_GetPutFields; 24 import tests.support.Support_GetPutFieldsDeprecated; 25 import tests.support.Support_GetPutFieldsDefaulted; 26 27 /** 28 * Writes three test files that are used as reference in 29 * {@code tests.api.java.io.ObjectInputStreamGetFieldTest} and 30 * {@code tests.api.java.io.ObjectOutputStreamPutFieldTest}. 31 * These files must be moved to 32 * {@code $ANDROID_BUILD_TOP/dalvik/libcore/luni/src/test/resources/tests/api/java/io} 33 * to be included at the correct location in the core tests package. 34 * <p> 35 * <strong>Important:</strong> Before executing this class, the contents of class 36 * {@code tests.support.Support_GetPutFieldsDefaulted} must be commented out. See the 37 * description there for further information. 38 */ 39 public class FieldTestFileGenerator { 40 41 public static void main(String[] args) throws IOException { 42 FileOutputStream fos = null; 43 ObjectOutputStream oos = null; 44 Support_GetPutFields toSerialize = new Support_GetPutFields(); 45 Support_GetPutFieldsDeprecated toSerializeDeprecated = 46 new Support_GetPutFieldsDeprecated(); 47 Support_GetPutFieldsDefaulted toSerializeDefaulted = 48 new Support_GetPutFieldsDefaulted(); 49 boolean success = true; 50 51 toSerialize.initTestValues(); 52 toSerializeDeprecated.initTestValues(); 53 toSerializeDefaulted.initTestValues(); 54 55 System.out.println("Trying to write the test file 'testFields.ser'..."); 56 try { 57 fos = new FileOutputStream("testFields.ser"); 58 oos = new ObjectOutputStream(fos); 59 oos.writeObject(toSerialize); 60 oos.close(); 61 } 62 catch (Exception e) { 63 System.out.println("Exception occured while writing the file: " + e); 64 success = false; 65 } 66 finally { 67 if (fos != null) fos.close(); 68 } 69 70 System.out.println("Trying to write the test file 'testFieldsDeprecated.ser'..."); 71 try { 72 fos = new FileOutputStream("testFieldsDeprecated.ser"); 73 oos = new ObjectOutputStream(fos); 74 oos.writeObject(toSerializeDeprecated); 75 oos.close(); 76 } 77 catch (Exception e) { 78 System.out.println("Exception occured while writing the file: " + e); 79 success = false; 80 } 81 finally { 82 if (fos != null) fos.close(); 83 } 84 85 System.out.println("Trying to write the test file 'testFieldsDefaulted.ser'..."); 86 try { 87 fos = new FileOutputStream("testFieldsDefaulted.ser"); 88 oos = new ObjectOutputStream(fos); 89 oos.writeObject(toSerializeDefaulted); 90 oos.close(); 91 } 92 catch (Exception e) { 93 System.out.println("Exception occured while writing the file: " + e); 94 success = false; 95 } 96 finally { 97 if (fos != null) fos.close(); 98 } 99 100 if (success) { 101 System.out.println("Success!"); 102 } else { 103 System.out.println("Failure!"); 104 } 105 106 } 107 } 108