Merge pull request #3913 from omwok/master
[mono.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient.Oci / OciDefineHandleTest.cs
1 //
2 // OracleParameterTest.cs -
3 //      NUnit Test Cases for OciDefineHandle
4 //
5 // Author:
6 //      Leszek Ciesielski  <skolima@gmail.com>
7 //
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using NUnit.Framework;
31 using System.Configuration;
32 using System.Globalization;
33 using System.Threading;
34 using System.Data.OracleClient;
35 using System.Data;
36 using System;
37
38 namespace MonoTests.System.Data.OracleClient {
39
40         [TestFixture]
41         public class OciDefineHandleTest {
42
43                 String connection_string;
44                 OracleConnection connection;
45                 OracleCommand command;
46
47                 // test string
48                 string test_value = "  sim\u4FF5ply\u65E5 tri\u672Cm te\u4F00st      ";
49                 string test_value2 = "  simply \u672Ctrim\u4F00 test in\u65E5 query  \u4FF5    ";
50
51                 [TestFixtureSetUp]
52                 public void FixtureSetUp ()
53                 {
54                         connection_string = Environment.GetEnvironmentVariable ("MONO_TESTS_ORACLE_CONNECTION_STRING");
55                         if(connection_string == null)
56                                 Assert.Ignore ("Please consult README.tests.");
57                 }
58
59                 [SetUp]
60                 public void SetUp ()
61                 {
62                         connection = new OracleConnection (connection_string);
63                         connection.Open ();
64                         using (command = connection.CreateCommand ()) {
65                                 // create the tables
66                                 command.CommandText =
67                                                 "create table utf8test (id number(10), text nvarchar2(64), text2 nvarchar2(64) )";
68                                 command.ExecuteNonQuery ();
69                         }
70                 }
71
72                 [TearDown]
73                 public void TearDown ()
74                 {
75                         using (command = connection.CreateCommand ()) {
76                                 command.CommandText = "drop table utf8test";
77                                 command.ExecuteNonQuery ();
78                         }
79
80                         connection.Close ();
81                         connection.Dispose ();
82                 }
83
84                 [Test] // regression for bug #79004
85                 public void TrimsUnicodeStringsTest ()
86                 {
87                         using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
88
89                                 // insert test values
90                                 command.CommandText =
91                                                 "insert into utf8test (id,text,text2) values (:id,:txt,'" + test_value2 + "')";
92                                 command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
93                                 command.Parameters.Add( new OracleParameter ("TXT", OracleType.NVarChar));
94                                 command.Parameters ["ID"].Value = 101;
95                                 command.Parameters ["TXT"].Value = test_value;
96                                 command.ExecuteNonQuery ();
97
98                                 // read test values
99                                 command.CommandText =
100                                                 "select text,text2 from utf8test where id = 101";
101                                 command.Parameters.Clear ();
102                                 using (OracleDataReader reader = command.ExecuteReader ()) {
103                                         if (reader.Read ()) {
104                                                 Assert.AreEqual (test_value, reader.GetString (0), "Passed through bind value mismatched");
105                                                 Assert.AreEqual (test_value2, reader.GetString (1), "Directly passed value mismatched");
106                                         }
107                                         else {
108                                                 Assert.Fail ("Expected records not found.");
109                                         }
110                                 }
111                         }
112                 }
113         }
114 }