Author: jonpryor
Date: 2005-04-29 16:29:24 -0400 (Fri, 29 Apr 2005)
New Revision: 43804
Modified:
trunk/mcs/class/Mono.Posix/ChangeLog
trunk/mcs/class/Mono.Posix/Makefile
trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog
trunk/mcs/class/Mono.Posix/Mono.Unix/Stdlib.cs
trunk/mcs/class/Mono.Posix/Test/Mono.Unix/ChangeLog
trunk/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
Log:
* Makefile: Ignore warnings 0219 (variable declared and never used) and
0618 (member is obsolete): this is test code, which produces lots of
unused variables and tests [Obsolete] members.
* Test/Mono.Unix/StdioFileStreamTest.cs: Add FilePosition tests; remove
`var = var` lines (added to remove warnings, but now produces other
warnings).
* Mono.Unix/Stdlib.cs: Make FilePosition slightly more useful by
providing a
ToString() override which dumps the fpos_t structure contents into a
hex string. Add Equals(), GetHashCode(), operator==, and operator!=
so FilePosition behaves like a value type.
Modified: trunk/mcs/class/Mono.Posix/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Posix/ChangeLog 2005-04-29 19:50:53 UTC (rev
43803)
+++ trunk/mcs/class/Mono.Posix/ChangeLog 2005-04-29 20:29:24 UTC (rev
43804)
@@ -1,5 +1,11 @@
2005-02-28 Jonathan Pryor <[EMAIL PROTECTED]>
+ * Makefile (TEST_MCS_FLAGS): Ignore warnings 0219 (variable declared and
+ never used) and 0618 (member is obsolete): this is test code, which
+ produces lots of unused variables and tests [Obsolete] members.
+
+2005-02-28 Jonathan Pryor <[EMAIL PROTECTED]>
+
* Mono.Posix_test.dll.sources: Added
Test/Mono.Unix/StdioFileStreamTest.cs.
2005-01-13 Jonathan Pryor <[EMAIL PROTECTED]>
Modified: trunk/mcs/class/Mono.Posix/Makefile
===================================================================
--- trunk/mcs/class/Mono.Posix/Makefile 2005-04-29 19:50:53 UTC (rev 43803)
+++ trunk/mcs/class/Mono.Posix/Makefile 2005-04-29 20:29:24 UTC (rev 43804)
@@ -4,7 +4,7 @@
LIBRARY = Mono.Posix.dll
LIB_MCS_FLAGS = /unsafe /r:$(corlib) /r:System.dll
-TEST_MCS_FLAGS = /r:Mono.Posix.dll /r:System.dll
+TEST_MCS_FLAGS = /r:Mono.Posix.dll /r:System.dll /nowarn:0219,0618
include ../../build/library.make
Modified: trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog 2005-04-29 19:50:53 UTC
(rev 43803)
+++ trunk/mcs/class/Mono.Posix/Mono.Unix/ChangeLog 2005-04-29 20:29:24 UTC
(rev 43804)
@@ -1,3 +1,10 @@
+2005-04-29 Jonathan Pryor <[EMAIL PROTECTED]>
+
+ * Stdlib.cs: Make FilePosition slightly more useful by providing a
+ ToString() override which dumps the fpos_t structure contents into a
+ hex string. Add Equals(), GetHashCode(), operator==, and operator!=
+ so FilePosition behaves like a value type.
+
2005-04-21 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* UnixClient.cs:
Modified: trunk/mcs/class/Mono.Posix/Mono.Unix/Stdlib.cs
===================================================================
--- trunk/mcs/class/Mono.Posix/Mono.Unix/Stdlib.cs 2005-04-29 19:50:53 UTC
(rev 43803)
+++ trunk/mcs/class/Mono.Posix/Mono.Unix/Stdlib.cs 2005-04-29 20:29:24 UTC
(rev 43804)
@@ -176,6 +176,9 @@
public sealed class FilePosition : IDisposable {
+ private static readonly int FilePositionDumpSize =
+ Stdlib.DumpFilePosition (null, new HandleRef (null,
IntPtr.Zero), 0);
+
private HandleRef pos;
public FilePosition ()
@@ -204,10 +207,50 @@
}
}
+ public override string ToString ()
+ {
+ return "(" + base.ToString () + " " + GetDump () + ")";
+ }
+
+ private string GetDump ()
+ {
+ if (FilePositionDumpSize <= 0)
+ return "internal error";
+
+ StringBuilder buf = new StringBuilder
(FilePositionDumpSize+1);
+
+ if (Stdlib.DumpFilePosition (buf, Handle,
FilePositionDumpSize+1) <= 0)
+ return "internal error dumping fpos_t";
+
+ return buf.ToString ();
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (obj == null || GetType() != obj.GetType())
+ return false;
+ return ToString().Equals (obj.ToString());
+ }
+
+ public override int GetHashCode ()
+ {
+ return ToString ().GetHashCode ();
+ }
+
~FilePosition ()
{
Cleanup ();
}
+
+ public static bool operator== (FilePosition lhs, FilePosition
rhs)
+ {
+ return Object.Equals (lhs, rhs);
+ }
+
+ public static bool operator!= (FilePosition lhs, FilePosition
rhs)
+ {
+ return !Object.Equals (lhs, rhs);
+ }
}
#if NET_2_0
@@ -412,6 +455,10 @@
internal static extern IntPtr CreateFilePosition ();
[DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+
EntryPoint="Mono_Posix_Stdlib_DumpFilePosition")]
+ internal static extern int DumpFilePosition (StringBuilder buf,
HandleRef handle, int len);
+
+ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
EntryPoint="Mono_Posix_Stdlib_EOF")]
private static extern int GetEOF ();
Modified: trunk/mcs/class/Mono.Posix/Test/Mono.Unix/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Posix/Test/Mono.Unix/ChangeLog 2005-04-29 19:50:53 UTC
(rev 43803)
+++ trunk/mcs/class/Mono.Posix/Test/Mono.Unix/ChangeLog 2005-04-29 20:29:24 UTC
(rev 43804)
@@ -1,3 +1,8 @@
+2005-04-29 Jonathan Pryor <[EMAIL PROTECTED]>
+
+ * StdioFileStreamTest.cs: Add FilePosition tests; remove `var = var`
+ lines (added to remove warnings, but now produces other warnings).
+
2005-04-28 Jonathan Pryor <[EMAIL PROTECTED]>
* StdlibTest.cs: Calling a P/Invoke function from signal-handler
context is
Modified: trunk/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
===================================================================
--- trunk/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
2005-04-29 19:50:53 UTC (rev 43803)
+++ trunk/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
2005-04-29 20:29:24 UTC (rev 43804)
@@ -370,7 +370,39 @@
DeleteFile (path);
}
+ // HACK: the values for `fp.ToString()' assume glibc, and may
change under
+ // a different C library (due to structure of fpos_t).
[Test]
+ public void PositionAfterWrite ()
+ {
+ string path = TempFolder + DSC + "FST.Position.Test";
+ DeleteFile (path);
+
+ StdioFileStream stream = new StdioFileStream (path,
FileMode.CreateNew,
+ FileAccess.ReadWrite);
+
+ FilePosition fp;
+
+ Assert.AreEqual (0, stream.Position, "test #01");
+ Assert.AreEqual ("(Mono.Unix.FilePosition 00000000",
+ (fp = stream.FilePosition).ToString().Substring
(0, 32), "test#02");
+ fp.Dispose ();
+
+ byte[] message = new byte[]{
+ (byte) 'H', (byte) 'e', (byte) 'l', (byte) 'l',
(byte) 'o', (byte) ' ',
+ (byte) 'W', (byte) 'o', (byte) 'r', (byte) 'l',
(byte) 'd',
+ };
+
+ stream.Write (message, 0, message.Length);
+
+ Assert.AreEqual (11, stream.Position, "test #03");
+ Assert.AreEqual (message.Length, stream.Position, "test
#04");
+ Assert.AreEqual ("(Mono.Unix.FilePosition 0B000000",
+ (fp = stream.FilePosition).ToString().Substring
(0, 32), "test#04");
+ fp.Dispose ();
+ }
+
+ [Test]
public void Seek ()
{
string path = TempFolder + DSC + "FST.Seek.Test";
@@ -491,7 +523,6 @@
try {
long l = stream.Length;
- l = l;
Assert.Fail ();
} catch (Exception e) {
Assert.AreEqual (typeof
(ObjectDisposedException), e.GetType (), "test#04");
@@ -499,12 +530,19 @@
try {
long l = stream.Position;
- l = l;
Assert.Fail ();
} catch (Exception e) {
Assert.AreEqual (typeof
(ObjectDisposedException), e.GetType (), "test#05");
}
+ try {
+ FilePosition fp = stream.FilePosition;
+ fp.Dispose ();
+ Assert.Fail ();
+ } catch (Exception e) {
+ Assert.AreEqual (typeof
(ObjectDisposedException), e.GetType (), "test#05");
+ }
+
Assert.AreEqual (false, stream.CanRead, "test#06");
Assert.AreEqual (false, stream.CanSeek, "test#07");
Assert.AreEqual (false, stream.CanWrite, "test#08");
@@ -604,7 +642,6 @@
try {
stream = new StdioFileStream (path,
FileMode.OpenOrCreate, FileAccess.Write);
int readByte = stream.ReadByte ();
- readByte = readByte;
} finally {
if (stream != null)
stream.Close();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches