1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. 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 tests.api.java.io; 18 19import java.io.File; 20import java.io.FileOutputStream; 21import java.io.IOException; 22import java.io.RandomAccessFile; 23 24import junit.framework.TestCase; 25import dalvik.annotation.TestLevel; 26import dalvik.annotation.TestTargetClass; 27import dalvik.annotation.TestTargetNew; 28 29/** 30 * TODO Type description 31 */ 32@TestTargetClass(RandomAccessFile.class) 33public class OpenRandomFileTest extends TestCase { 34 35 public static void main(String[] args) { 36 new OpenRandomFileTest().testOpenEmptyFile(); 37 } 38 39 public OpenRandomFileTest() { 40 super(); 41 } 42 @TestTargetNew( 43 level = TestLevel.PARTIAL_COMPLETE, 44 notes = "", 45 method = "RandomAccessFile", 46 args = {java.lang.String.class, java.lang.String.class} 47 ) 48 public void testOpenNonEmptyFile() { 49 try { 50 File file = File.createTempFile("test", "tmp"); 51 assertTrue(file.exists()); 52 file.deleteOnExit(); 53 FileOutputStream fos = new FileOutputStream(file); 54 fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); 55 fos.close(); 56 57 String fileName = file.getCanonicalPath(); 58 RandomAccessFile raf = new RandomAccessFile(fileName, "rw"); 59 raf.close(); 60 } catch (IOException ex) { 61 fail(ex.getLocalizedMessage()); 62 } 63 } 64 @TestTargetNew( 65 level = TestLevel.PARTIAL_COMPLETE, 66 notes = "", 67 method = "RandomAccessFile", 68 args = {java.lang.String.class, java.lang.String.class} 69 ) 70 public void testOpenEmptyFile() { 71 try { 72 File file = File.createTempFile("test", "tmp"); 73 assertTrue(file.exists()); 74 file.deleteOnExit(); 75 76 String fileName = file.getCanonicalPath(); 77 RandomAccessFile raf = new RandomAccessFile(fileName, "rw"); 78 raf.close(); 79 } catch (IOException ex) { 80 fail(ex.getLocalizedMessage()); 81 } 82 } 83} 84