1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* 2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements. See the NOTICE file distributed with 4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership. 5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with 7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. You may obtain a copy of the License at 8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software 12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * See the License for the specific language governing permissions and 15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * limitations under the License. 16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 18ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.io; 19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.ByteArrayInputStream; 21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.ObjectInputStream; 22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.StreamCorruptedException; 23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class StreamCorruptedExceptionTest extends junit.framework.TestCase { 25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 26cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 27cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.StreamCorruptedException#StreamCorruptedException() 28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_Constructor() throws Exception { 30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method java.io.StreamCorruptedException() 31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath ObjectInputStream ois = new ObjectInputStream( 34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath new ByteArrayInputStream( 35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "kLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLl" 36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .getBytes())); 37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath ois.readObject(); 38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (StreamCorruptedException e) { 39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Correct 40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath return; 41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Failed to throw StreamCorruptedException for non serialized stream"); 44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.StreamCorruptedException#StreamCorruptedException(java.lang.String) 48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_lang_String() throws Exception { 50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method java.io.StreamCorruptedException(java.lang.String) 51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath ObjectInputStream ois = new ObjectInputStream( 53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath new ByteArrayInputStream( 54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "kLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLl" 55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .getBytes())); 56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath ois.readObject(); 57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (StreamCorruptedException e) { 58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Correct 59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath return; 60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Failed to throw StreamCorruptedException for non serialized stream"); 63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Sets up the fixture, for example, open a network connection. This method 67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * is called before a test is executed. 68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 69cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath protected void setUp() { 70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Tears down the fixture, for example, close a network connection. This 74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * method is called after a test is executed. 75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath protected void tearDown() { 77cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 78cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath} 79