2 // OracleParameterTest.cs -
3 // NUnit Test Cases for OracleLob
6 // Leszek Ciesielski <skolima@gmail.com>
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
31 using System.Configuration;
32 using System.Globalization;
33 using System.Threading;
34 using System.Data.OracleClient;
39 namespace MonoTests.System.Data.OracleClient {
42 public class OracleLobTest {
44 String connection_string;
45 OracleConnection connection;
46 OracleCommand command;
49 public void FixtureSetUp ()
51 connection_string = Environment.GetEnvironmentVariable ("MONO_TESTS_ORACLE_CONNECTION_STRING");
52 if(connection_string == null)
53 Assert.Ignore ("Please consult README.tests.");
59 connection = new OracleConnection (connection_string);
62 using (command = connection.CreateCommand ()) {
65 "create table lob_test (id number(10), lobo blob)";
66 command.ExecuteNonQuery ();
71 public void TearDown ()
73 using (command = connection.CreateCommand ()) {
74 command.CommandText = "drop table lob_test";
75 command.ExecuteNonQuery ();
79 connection.Dispose ();
82 [Test] // regression for bug #78898
83 public void PositionIs0BasedTest ()
85 using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
88 "insert into lob_test (id, lobo) values (11, '00000000000000000000000000000')";
89 command.ExecuteNonQuery ();
91 // select for writing test values
93 "select lobo from lob_test where id = 11 for update";
95 using (OracleDataReader reader = command.ExecuteReader ()) {
97 OracleLob lob = reader.GetOracleLob (0);
98 Assert.AreEqual (0, lob.Position, "Lob index is not 0 - based.");
99 lob.Seek (1, SeekOrigin.Current);
100 Assert.AreEqual (1, lob.Position, "Lob seek placed position wrongly.");
101 lob.Seek (0, SeekOrigin.End);
102 Assert.AreEqual (lob.Length , lob.Position, "Lob end is too far away.");
103 TrySeek (lob, -lob.Length, SeekOrigin.End, 0, 1);
104 TrySeek (lob, -lob.Length + 5, SeekOrigin.End, 5, 2);
106 lob.Seek (5, SeekOrigin.End);
107 Assert.Fail ("Illegal seek succeeded.");
109 catch (ArgumentOutOfRangeException) { // exception is required
111 lob.Seek (lob.Length - 5, SeekOrigin.Begin);
112 Assert.AreEqual (lob.Length - 5 , lob.Position, "Lob position has unexpected value.");
113 lob.Seek (0, SeekOrigin.Begin);
114 TryRead (lob, 10, 1);
115 lob.Seek (5, SeekOrigin.Begin);
117 TryRead (lob, 10, 2);
118 lob.Position = lob.Length;
120 lob.Seek (-1, SeekOrigin.Current);
124 Assert.Fail ("Expected records not found.");
130 void TrySeek(OracleLob lob, long offset, SeekOrigin start, long expected, int id)
133 lob.Seek (offset, start);
134 Assert.AreEqual (expected, lob.Position, "Lob position was unexpected [" + id + ']');
136 catch (ArgumentOutOfRangeException) {
137 Assert.Fail ("Unable to perform a legal seek [" + id + ']');
141 void TryRead(OracleLob lob, long expectedCount, int id)
144 long numberRead = lob.Read (new byte [10], 0, 10);
145 Assert.AreEqual (expectedCount, numberRead, "Wrong number of bytes read [" + id + ']');
147 catch (OracleException e) {
149 Assert.Fail ("Unable to perform a legal read [" + id + ']');