OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [FileTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* File.java -- Tests File class
3
/*
4
/* Copyright (c) 1998 Free Software Foundation, Inc.
5
/* Written by Aaron M. Renn (arenn@urbanophile.com)
6
/*
7
/* This program is free software; you can redistribute it and/or modify
8
/* it under the terms of the GNU General Public License as published
9
/* by the Free Software Foundation, version 2. (see COPYING)
10
/*
11
/* This program is distributed in the hope that it will be useful, but
12
/* WITHOUT ANY WARRANTY; without even the implied warranty of
13
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
/* GNU General Public License for more details.
15
/*
16
/* You should have received a copy of the GNU General Public License
17
/* along with this program; if not, write to the Free Software Foundation
18
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
19
/*************************************************************************/
20
 
21
import java.io.*;
22
 
23
public class FileTest
24
{
25
 
26
static PrintWriter pw;
27
 
28
public static void
29
dumpFile(File f) throws IOException
30
{
31
    pw.println("Name: " + f.getName());
32
    pw.println("Parent: " + f.getParent());
33
    pw.println("Path: " + f.getPath());
34
    pw.println("Absolute: " + f.getAbsolutePath());
35
    pw.println("Canonical: " + f.getCanonicalPath());
36
    pw.println("String: " + f.toString());
37
}
38
 
39
public static void
40
deleteTempDirs() throws IOException
41
{
42
  File f = new File("tempfiletest/tmp/tmp");
43
  if (!f.delete())
44
    throw new IOException("Could not delete " + f.getPath());
45
 
46
  f = new File("tempfiletest/tmp");
47
  if (!f.delete())
48
    throw new IOException("Could not delete " + f.getPath());
49
 
50
  f = new File("tempfiletest/");
51
  if (!f.delete())
52
    throw new IOException("Could not delete " + f.getPath());
53
}
54
 
55
public static void main(String[] argv)
56
{
57
  System.out.println("Started test of File");
58
 
59
  // This test writes a bunch of things to a file.  That file should
60
  // be "diff-ed" against one generated when this test is run against
61
  // the JDK java.io package.
62
  System.out.println("Test 1: Path Operations Test");
63
  try
64
    {
65
      pw = new PrintWriter(new OutputStreamWriter(new
66
                    FileOutputStream("./file-test.out")));
67
 
68
      dumpFile(new File("/"));
69
      dumpFile(new File("~arenn/foo"));
70
      dumpFile(new File("foo"));
71
      dumpFile(new File("../../../jcl/"));
72
      dumpFile(new File("/tmp/bar.txt"));
73
      dumpFile(new File("/usr"));
74
      dumpFile(new File("../.."));
75
      pw.flush();
76
 
77
      File f = new File("gimme");
78
      if (f.isAbsolute())
79
        throw new IOException("isAbsolute() failed");
80
 
81
      f = new File("/etc/services");
82
      if (!f.isFile())
83
        throw new IOException("isFile() failed");
84
 
85
      pw.println("length: " + f.length());
86
      pw.println("lastModified: " + f.lastModified());
87
      pw.println("hashCode: " + f.hashCode());
88
 
89
      f = new File("/etc/");
90
      if (!f.isDirectory())
91
        throw new IOException("isDirectory() failed");
92
 
93
      pw.close();
94
      System.out.println("PASSED: Conditionally Passed Path Operations Test");
95
    }
96
  catch(IOException e)
97
    {
98
      System.out.println("FAILED: Path Operations Test: " + e);
99
      pw.close();
100
    }
101
 
102
  System.out.println("Test 2: File/Directory Manipulation Test");
103
  try
104
    {
105
      File f = new File("filetest");
106
      if (!f.exists())
107
        throw new IOException("The filetest directory doesn't exist");
108
 
109
      String[] filelist = f.list();
110
      if ((filelist == null) || (filelist.length != 3))
111
        throw new IOException("Failed to read directory list");
112
 
113
      for (int i = 0; i < filelist.length; i++)
114
        System.out.println(filelist[i]);
115
 
116
      System.out.println("Listing /etc/");
117
      f = new File("/etc/");
118
      filelist = f.list();
119
      for (int i = 0; i < filelist.length; i++)
120
        System.out.println(filelist[i]);
121
 
122
      f = new File("tempfiletest/tmp/tmp");
123
      if (!f.mkdirs())
124
        throw new IOException("Failed to create directories: " + f.getPath());
125
 
126
      deleteTempDirs();
127
 
128
      f = new File("tempfiletest/tmp/tmp/");
129
      if (!f.mkdirs())
130
        throw new IOException("Failed to create directories: " + f.getPath());
131
 
132
      deleteTempDirs();
133
 
134
      //f = File.createTempFile("tempfile#old", new File("."));
135
      f = new File("000000");
136
 
137
      if (!f.renameTo(new File("tempfiletemp")))
138
        throw new IOException("Failed to rename file: " + f.getPath());
139
 
140
      if (!f.delete())
141
        throw new IOException("Failed to delete file: " + f.getPath());
142
 
143
      System.out.println("PASSED: File/Directory Manipulation Test");
144
    }
145
  catch(IOException e)
146
    {
147
      System.out.println("FAILED: File/Directory Manipulation Test: " + e);
148
    }
149
 
150
  System.out.println("Test 3: Read/Write Permissions Test");
151
  try
152
    {
153
      if ((new File("/")).canWrite() == true)
154
        throw new IOException("Permission to write / unexpectedly");
155
 
156
      if ((new File("/etc/services")).canRead() == false)
157
        throw new IOException("No permission to read /etc/services");
158
 
159
      System.out.println("PASSED: Read/Write Permissions Test");
160
    }
161
  catch (IOException e)
162
    {
163
      System.out.println("FAILED: Read/Write Permissions Test: " + e);
164
    }
165
 
166
  System.out.println("Test 4: Name Comparison Tests");
167
  try
168
    {
169
      File f1, f2;
170
 
171
      f1 = new File("/etc/");
172
      f2 = new File("/etc/");
173
      if (!f1.equals(f2))
174
        throw new IOException(f1 + " " + f2);
175
 
176
      f2 = new File("/etc");
177
      if (f1.equals(f2))
178
        throw new IOException(f1 + " " + f2);
179
/*
180
      f1 = new File("a");
181
      f2 = new File("b");
182
      if (f1.compareTo(f2) >= 0)
183
        throw new IOException(f1 + " " + f2);
184
 
185
      f1 = new File("z");
186
      f2 = new File("y");
187
      if (f1.compareTo(f2) <= 0)
188
        throw new IOException(f1 + " " + f2);
189
 
190
      f1 = new File("../../jcl/");
191
      f2 = new File(".././.././jcl/.");
192
      if (f1.compareTo(f2) != 0)
193
        throw new IOException(f1 + " " + f2);
194
*/
195
      System.out.println("PASSED: Name Comparison Tests");
196
    }
197
  catch (IOException e)
198
    {
199
      System.out.println("FAILED: Name Comparison Tests: " + e);
200
    }
201
 
202
  System.out.println("Finished test of File");
203
}
204
}
205
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.