[mono-vb] FileSystem additions
Rob.Tillie@Student.tUL.EDU
Rob.Tillie@Student.tUL.EDU
Fri, 18 Jun 2004 23:15:11 +0200
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C45579.571452D0
Content-Type: text/plain
Hello,
Here's the implementation for FileLen and FileDateTime including unit tests.
To Jambunathan: I think you meant by 'self-containing' patches that I should
sent them as small as possible, so this is a patch with only two methods.
Greetz,
-- Rob.
------_=_NextPart_000_01C45579.571452D0
Content-Type: application/octet-stream;
name="FileSystem.patch"
Content-Disposition: attachment;
filename="FileSystem.patch"
Index: class/Microsoft.VisualBasic/Microsoft.VisualBasic/FileSystem.cs
===================================================================
RCS file: /mono/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic/FileSystem.cs,v
retrieving revision 1.9
diff -u -r1.9 FileSystem.cs
--- class/Microsoft.VisualBasic/Microsoft.VisualBasic/FileSystem.cs 17 Jun 2004 12:37:44 -0000 1.9
+++ class/Microsoft.VisualBasic/Microsoft.VisualBasic/FileSystem.cs 18 Jun 2004 21:08:48 -0000
@@ -159,21 +159,34 @@
System.IO.File.Copy(Source,Destination,true);
}
- [MonoTODO("Needs testing")]
- public static System.DateTime FileDateTime (System.String PathName)
+ public static DateTime FileDateTime (string PathName)
{
- // A better exception handling is needed : exceptions
- // are not the same as 'GetLastWriteTime'
- return System.IO.File.GetLastWriteTime (PathName);
+ if (PathName == null || PathName.Length == 0 ||
+ PathName.IndexOf ('*') != -1 || PathName.IndexOf ('?') != -1) {
+ ExceptionUtils.VbMakeException (VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException (
+ VBUtils.GetResourceString("Argument_InvalidValue1", "PathName"));
+ }
+
+ FileInfo f = new FileInfo (PathName);
+ if (!f.Exists) {
+ DirectoryInfo d = new DirectoryInfo (PathName);
+ if (!d.Exists)
+ throw (FileNotFoundException)
+ ExceptionUtils.VbMakeException (VBErrors.FileNotFound);
+ return d.LastWriteTime;
+ }
+
+ return f.LastWriteTime;
}
- [MonoTODO("Needs Testing")]
- public static System.Int64 FileLen(System.String PathName)
+ public static long FileLen (string PathName)
{
- FileInfo MyFile=new FileInfo(PathName);
- if ( !MyFile.Exists )
- throw new System.ArgumentException(PathName + " does not exists");
- return (System.Int64)MyFile.Length;
+ FileInfo MyFile = new FileInfo (PathName);
+ if (!MyFile.Exists)
+ throw new FileNotFoundException ("FileSystem_PathNotFound1", "PathName");
+
+ return MyFile.Length;
}
[MonoTODO]
public static Microsoft.VisualBasic.FileAttribute GetAttr (System.String PathName) {
------_=_NextPart_000_01C45579.571452D0
Content-Type: application/octet-stream;
name="FileSystemTests.patch"
Content-Disposition: attachment;
filename="FileSystemTests.patch"
Index: class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic/FileSystemTest.cs
===================================================================
RCS file: /mono/mcs/class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic/FileSystemTest.cs,v
retrieving revision 1.3
diff -u -r1.3 FileSystemTest.cs
--- class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic/FileSystemTest.cs 17 Jun 2004 12:37:44 -0000 1.3
+++ class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic/FileSystemTest.cs 18 Jun 2004 21:05:58 -0000
@@ -83,6 +83,56 @@
string dir = FileSystem.CurDir ();
AssertEquals ("CurDir#01", Environment.CurrentDirectory, dir);
}
+
+ [Test]
+ [ExpectedException (typeof(FileNotFoundException))]
+ public void FileLenArgs ()
+ {
+ FileSystem.FileLen ("c:\\foodir\nonexistentfile.txt");
+ }
+
+ [Test]
+ public void TestFileLen ()
+ {
+ string dir = Directory.GetCurrentDirectory ();
+ DirectoryInfo info = new DirectoryInfo (dir);
+ FileInfo[] files = info.GetFiles ();
+
+ foreach (FileInfo file in files) {
+ long length = FileSystem.FileLen (file.FullName);
+ AssertEquals ("FileLen#01", file.Length, length);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof(ArgumentException))]
+ public void FileDateTimeArgs1 ()
+ {
+ FileSystem.FileDateTime ("");
+ }
+
+ [Test]
+ [ExpectedException (typeof(FileNotFoundException))]
+ public void FileDateTimeArgs2 ()
+ {
+ FileSystem.FileDateTime ("c:\\foodir\notexistentfile.txt");
+ }
+
+ [Test]
+ public void TestFileDateTime ()
+ {
+ string dir = Directory.GetCurrentDirectory ();
+ DirectoryInfo info = new DirectoryInfo (dir);
+ FileInfo[] files = info.GetFiles ();
+
+ foreach (FileInfo file in files) {
+ DateTime dt = FileSystem.FileDateTime (file.FullName);
+ AssertEquals ("FileDateTime#01", file.LastWriteTime, dt);
+ }
+
+ DateTime time = FileSystem.FileDateTime (dir);
+ AssertEquals ("FileDateTime#02", info.LastWriteTime, time);
+ }
/*
[Test]
[ExpectedException(typeof(ArgumentException))]
------_=_NextPart_000_01C45579.571452D0--