1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.core; 18 19import junit.framework.TestCase; 20 21import java.io.ByteArrayInputStream; 22import java.io.ByteArrayOutputStream; 23import java.io.IOException; 24import java.io.ObjectInputStream; 25import java.io.ObjectOutputStream; 26import java.io.Serializable; 27import android.test.suitebuilder.annotation.SmallTest; 28 29/** 30 * Tests serialization of user-level classes. 31 */ 32public class SerializationTest extends TestCase { 33 34 static class MySerializable implements Serializable {} 35 36 @SmallTest 37 public void testSerialization() throws IOException, ClassNotFoundException { 38 ByteArrayOutputStream bout = new ByteArrayOutputStream(); 39 ObjectOutputStream oout = new ObjectOutputStream(bout); 40 oout.writeObject(new MySerializable()); 41 oout.close(); 42 43 ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); 44 Object o = new ObjectInputStream(bin).readObject(); 45 assertTrue(o instanceof MySerializable); 46 } 47} 48