Fixed bug 78898 in OracleLob (index was 1-based instead of 0) and added regression...
authorLeszek 'skolima' Ciesielski <skolima@gmail.com>
Tue, 12 Sep 2006 10:31:25 +0000 (10:31 -0000)
committerLeszek 'skolima' Ciesielski <skolima@gmail.com>
Tue, 12 Sep 2006 10:31:25 +0000 (10:31 -0000)
svn path=/trunk/mcs/; revision=65292

mcs/class/System.Data.OracleClient/ChangeLog
mcs/class/System.Data.OracleClient/System.Data.OracleClient.jvm/OracleLob.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleLob.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient_test.dll.sources
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/ChangeLog
mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleLobTest.cs [new file with mode: 0644]

index 8d1322d6953a8f997c26f014d5bc0689979451e3..0610a59e28ea60cc6d348b990f9522870b171670 100644 (file)
@@ -1,4 +1,8 @@
-2006-08-21     Leszek Ciesielski <skolima@gmail.com>
+2006-09-12      Leszek Ciesielski <skolima@gmail.com>
+
+        * OracleLob.cs : fix for bug 78898
+
+2006-09-11     Leszek Ciesielski <skolima@gmail.com>
 
        * OracleCommand.cs : fix for bug 78765 and 79284
        * OracleParameter.cs : fix for bug 78509 and 79284
index a7f9a1e73f1ea02ec71c273f241b0dad15c15a43..e8762de4501f4893974e715f14b915b9bf7bb928 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Data.OracleClient {
                OracleType type;
 
                long length = -1;
-               long position = 1;
+               long position = 0;
 
                #endregion // Fields
 
@@ -275,7 +275,7 @@ namespace System.Data.OracleClient {
                                        newPosition += offset;
                                        break;
                                case SeekOrigin.End:
-                                       newPosition = Length - offset;
+                                       newPosition = Length + offset;
                                        break;
                        }
 
index 8eceff99b9802922c43b06ac4a4b0cc0cd4875af..32900220dd36faa3b08cd594f613824a932a8664 100644 (file)
@@ -35,7 +35,7 @@ namespace System.Data.OracleClient {
                OracleType type;
 
                long length = -1;
-               long position = 1;
+               long position = 0;
 
                #endregion // Fields
 
@@ -316,7 +316,7 @@ namespace System.Data.OracleClient {
                        int bytesRead;
                        byte[] output = new byte[count];
 
-                       bytesRead = locator.Read (output, (uint) Position, (uint) count, LobType == OracleType.Blob);
+                       bytesRead = locator.Read (output, (uint) Position + 1, (uint) count, LobType == OracleType.Blob);
                        output.CopyTo (buffer, offset);
                        position += bytesRead;
                        return bytesRead;
@@ -335,7 +335,7 @@ namespace System.Data.OracleClient {
                                newPosition += offset;
                                break;
                        case SeekOrigin.End:
-                               newPosition = Length - offset;
+                               newPosition = Length + offset;
                                break;
                        }
 
@@ -380,7 +380,7 @@ namespace System.Data.OracleClient {
                                Array.Copy (buffer, offset, value, 0, count);
                        }
 
-                       position += locator.Write (value, (uint) Position, (uint) value.Length, LobType);
+                       position += locator.Write (value, (uint) Position + 1, (uint) value.Length, LobType);
                }
 
                #endregion // Methods
index 399eac563cfdfc8f3b10bc7f0878488efb69e375..14e6ca6d5ca6d0de23ac82b5bb01369e9667a65a 100755 (executable)
@@ -1,3 +1,4 @@
 System.Data.OracleClient/OraclePermissionAttributeTest.cs
 System.Data.OracleClient/OracleCommandTest.cs
 System.Data.OracleClient/OracleParameterTest.cs
+System.Data.OracleClient/OracleLobTest.cs
index 84d6a4656abe878b6e867d4248acd3591dcc704b..10e65815b77b639b1c47e7f970e6901a34ab497d 100644 (file)
@@ -1,3 +1,8 @@
+2006-09-12  Leszek Ciesielski  <skolima@gmail.com>
+
+        * OracleLobTest.cs: New. Regression tests for class
+        OracleLob.
+
 2006-09-11  Leszek Ciesielski  <skolima@gmail.com>
 
        * OracleCommandTest.cs: New. Regression tests for class
diff --git a/mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleLobTest.cs b/mcs/class/System.Data.OracleClient/Test/System.Data.OracleClient/OracleLobTest.cs
new file mode 100644 (file)
index 0000000..91bb85d
--- /dev/null
@@ -0,0 +1,152 @@
+//
+// OracleParameterTest.cs -
+//      NUnit Test Cases for OracleLob
+//
+// Author:
+//      Leszek Ciesielski  <skolima@gmail.com>
+//
+// Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System.Configuration;
+using System.Globalization;
+using System.Threading;
+using System.Data.OracleClient;
+using System.Data;
+using System.IO;
+using System;
+
+namespace MonoTests.System.Data.OracleClient {
+
+        [TestFixture]
+        public class OracleLobTest {
+
+                String connection_string;
+                OracleConnection connection;
+                OracleCommand command;
+
+                [TestFixtureSetUp]
+                public void FixtureSetUp ()
+                {
+                        connection_string = ConfigurationSettings.AppSettings.Get ("OracleConnectionString");
+                        if(connection_string == null)
+                                Assert.Ignore ("Please consult README.tests.");
+                }
+
+                [SetUp]
+                public void SetUp ()
+                {
+                        connection = new OracleConnection (connection_string);
+                        connection.Open ();
+                        command = connection.CreateCommand ();
+
+                        // create the tables
+                        command.CommandText =
+                                        "create table lob_test (id number(10), lobo blob)";
+                        command.ExecuteNonQuery ();
+                }
+
+                [TearDown]
+                public void TearDown ()
+                {
+                        command = connection.CreateCommand ();
+                        command.CommandText = "drop table lob_test";
+                        command.ExecuteNonQuery ();
+
+                        connection.Close ();
+                        connection.Dispose ();
+                }
+
+                [Test] // regression for bug #78898
+                public void PositionIs0BasedTest ()
+                {
+                        command = connection.CreateCommand (); // reusing command from SetUp causes parameter names mismatch
+
+                        // insert test values
+                        command.CommandText =
+                                        "insert into lob_test (id, lobo) values (11, '00000000000000000000000000000')";
+                        command.ExecuteNonQuery ();
+
+                        // select for writing test values
+                        command.CommandText =
+                                        "select lobo from lob_test where id = 11 for update";
+
+                        using (OracleDataReader reader = command.ExecuteReader ()) {
+                                if (reader.Read ()) {
+                                        OracleLob lob = reader.GetOracleLob (0);
+                                        Assert.AreEqual (0, lob.Position, "Lob index is not 0 - based.");
+                                        lob.Seek (1, SeekOrigin.Current);
+                                        Assert.AreEqual (1, lob.Position, "Lob seek placed position wrongly.");
+                                        lob.Seek (0, SeekOrigin.End);
+                                        Assert.AreEqual (lob.Length , lob.Position, "Lob end is too far away.");
+                                        TrySeek (lob, -lob.Length, SeekOrigin.End, 0, 1);
+                                        TrySeek (lob, -lob.Length + 5, SeekOrigin.End, 5, 2);
+                                        try {
+                                                lob.Seek (5, SeekOrigin.End);
+                                                Assert.Fail ("Illegal seek succeeded.");
+                                        }
+                                        catch (ArgumentOutOfRangeException) { // exception is required
+                                        }
+                                        lob.Seek (lob.Length - 5, SeekOrigin.Begin);
+                                        Assert.AreEqual (lob.Length - 5 , lob.Position, "Lob position has unexpected value.");
+                                        lob.Seek (0, SeekOrigin.Begin);
+                                        TryRead (lob, 10, 1);
+                                        lob.Seek (5, SeekOrigin.Begin);
+                                        lob.Position = 0;
+                                        TryRead (lob, 10, 2);
+                                        lob.Position = lob.Length;
+                                        TryRead (lob, 0, 3);
+                                        lob.Seek (-1, SeekOrigin.Current);
+                                        TryRead (lob, 1, 4);
+                                }
+                                else {
+                                        Assert.Fail ("Expected records not found.");
+                                }
+                        }
+                }
+
+                void TrySeek(OracleLob lob, long offset, SeekOrigin start, long expected, int id)
+                {
+                        try {
+                                lob.Seek (offset, start);
+                                Assert.AreEqual (expected, lob.Position, "Lob position was unexpected [" + id + ']');
+                        }
+                        catch (ArgumentOutOfRangeException) {
+                                Assert.Fail ("Unable to perform a legal seek [" + id + ']');
+                        }
+                }
+
+                void TryRead(OracleLob lob, long expectedCount, int id)
+                {
+                        try {
+                                long numberRead = lob.Read (new byte [10], 0, 10);
+                                Assert.AreEqual (expectedCount, numberRead, "Wrong number of bytes read [" + id + ']');
+                        }
+                        catch (OracleException e) {
+                                if (e.Code == 24801)
+                                        Assert.Fail ("Unable to perform a legal read [" + id + ']');
+                                else throw;
+                        }
+                }
+        }
+}