New test.
[mono.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient.jvm / OracleDataReader / OracleDataReader_GetBytes_IIBII.cs
1 // 
2 // Copyright (c) 2006 Mainsoft Co.
3 // 
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23
24 using System;
25 using System.Data;
26 using System.Data.OracleClient;
27
28 using MonoTests.System.Data.Utils;
29
30 using MonoTests.System.Data.Utils.Data;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Data.OracleClient
35 {
36         [TestFixture]
37         public class OracleDataReader_GetBytes_IIBII : GHTBase
38         {
39                 int testTypesInvocations;
40                 Exception exp = null;
41                 public static void Main()
42                 {
43                         OracleDataReader_GetBytes_IIBII tc = new OracleDataReader_GetBytes_IIBII();
44                         Exception exp = null;
45                         try
46                         {
47                                 tc.BeginTest("OracleDataReader_GetBytes_IIBII");
48                                 tc.run();
49                         }
50                         catch(Exception ex){exp = ex;}
51                         finally {tc.EndTest(exp);}
52                 }
53
54                 [Test]
55                 public void run()
56                 {
57                         DoTestTypes(ConnectedDataProvider.GetSimpleDbTypesParameters());
58                         DoTestTypes(ConnectedDataProvider.GetExtendedDbTypesParameters());
59                 }
60                 public void DoTestTypes(DbTypeParametersCollection row)
61                 {
62                         testTypesInvocations++;
63                         exp = null;
64                         string rowId = "43966_" + this.testTypesInvocations.ToString();
65                                 OracleConnection con =null;
66                                 OracleDataReader rdr = null;
67
68                         try
69                         {
70                                 row.ExecuteInsert(rowId);
71                                 row.ExecuteSelectReader(rowId, out rdr, out con);
72                                 while (rdr.Read())
73                                 {
74                                         //Run over all the columns in the result set row.
75                                         //For each column, try to read it as a byte array.
76                                         for (int i=0; i<row.Count; i++)
77                                         {
78                                                 if (row[i].Value.GetType() == typeof(byte[])) //The value in the result set should be a byte array.
79                                                 {
80                                                         try
81                                                         {
82                                                                 BeginCase(string.Format("Calling GetBytes() on a field of dbtype {0}", row[i].DbTypeName));
83                                                                 byte[] origBytes = (byte[])row[i].Value;
84                                                                 byte[] retBytes = new byte[origBytes.Length];
85                                                                 rdr.GetBytes(i, 0, retBytes, 0, origBytes.Length);
86                                                                 Compare(origBytes, retBytes);
87                                                         }
88                                                         catch (Exception ex)
89                                                         {
90                                                                 exp = ex;
91                                                         }
92                                                         finally
93                                                         {
94                                                                 EndCase(exp);
95                                                                 exp = null;
96                                                         }
97                                                 }
98                                                 else //The value in the result set should NOT be byte array. In this case an Invalid case exception should be thrown.
99                                                 {
100                                                         try
101                                                         {
102                                                                 BeginCase(string.Format("Calling GetBytes() on a field of dbtype {0}", row[i].DbTypeName));
103                                                                 byte[] retBytes = new byte[1];
104                                                                 rdr.GetBytes(i, 0, retBytes, 0, 1);
105                                                                 ExpectedExceptionNotCaught("InvalidCastException");
106                                                         }
107                                                         catch (InvalidCastException ex)
108                                                         {
109                                                                 ExpectedExceptionCaught(ex);
110                                                         }
111                                                         catch (Exception ex)
112                                                         {
113                                                                 exp = ex;
114                                                         }
115                                                         finally
116                                                         {
117                                                                 EndCase(exp);
118                                                                 exp = null;
119                                                         }
120                                                 }
121                                         }
122                                 }
123                         }
124                         finally
125                         {
126                                 row.ExecuteDelete(rowId);
127                                 if (rdr != null && !rdr.IsClosed)
128                                 {
129                                         rdr.Close();
130                                 }
131
132                                 if (con != null && con.State != ConnectionState.Closed)
133                                 {
134                                         con.Close();
135                                 }
136                         }
137                 }
138
139         }
140
141 }