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 org.apache.harmony.luni.tests.java.io;
18
19import java.io.File;
20import java.io.FileOutputStream;
21import java.io.IOException;
22import java.io.RandomAccessFile;
23
24import junit.framework.TestCase;
25
26public class OpenRandomFileTest extends TestCase {
27
28    public static void main(String[] args) throws IOException {
29        new OpenRandomFileTest().testOpenEmptyFile();
30    }
31
32    public OpenRandomFileTest() {
33        super();
34    }
35
36    public void testOpenNonEmptyFile() throws IOException {
37        File file = File.createTempFile("test", "tmp");
38        assertTrue(file.exists());
39        file.deleteOnExit();
40        FileOutputStream fos = new FileOutputStream(file);
41        fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
42        fos.close();
43
44        String fileName = file.getCanonicalPath();
45        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
46        raf.close();
47    }
48
49    public void testOpenEmptyFile() throws IOException {
50        File file = File.createTempFile("test", "tmp");
51        assertTrue(file.exists());
52        file.deleteOnExit();
53
54        String fileName = file.getCanonicalPath();
55        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
56        raf.close();
57    }
58}
59