Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
2006-10-17 Leszek Ciesielski <skolima@gmail.com>
* ConnectedDataProvider.cs: Connected test are ignored when
no configuration is found.

View File

@@ -0,0 +1,363 @@
// Authors:
// Rafael Mizrahi <rafim@mainsoft.com>
// Erez Lotan <erezl@mainsoft.com>
// Oren Gurfinkel <oreng@mainsoft.com>
// Ofer Borstein
//
// Copyright (c) 2004 Mainsoft Co.
//
// 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 System;
using System.Data;
using System.Data.OracleClient ;
using System.IO;
using System.Collections;
using Sys = System;
using MonoTests.System.Data.Utils.Data;
// Provide All Data required by the diffderent tests e.g.DataTable, DataRow ...
namespace MonoTests.System.Data.Utils {
/// <summary>
/// Types of Database Servers that tests can be run on.
/// </summary>
public enum DataBaseServer {
SQLServer,
Oracle,
DB2,
Sybase,
PostgreSQL,
Unknown
}
public class ConnectedDataProvider {
#region Private
//A string containing all printable charachters.
private const string SAMPLE_STRING = "abcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_+-=[]\\|;:,./<>? ";
#endregion
#region Public
/// <summary>
/// Name of the table in the database, that contain columns of simple types.
/// </summary>
public const string SIMPLE_TYPES_TABLE_NAME = "TYPES_SIMPLE";
/// <summary>
/// Name of the table in the database, that contain columns of extended types.
/// </summary>
public const string EXTENDED_TYPES_TABLE_NAME = "TYPES_EXTENDED";
/// <summary>
/// Name of the table in the database, that contain columns of DB specific types.
/// </summary>
public const string SPECIFIC_TYPES_TABLE_NAME = "TYPES_SPECIFIC";
#endregion
public static string ConnectionString {
get {
string connection_string = Sys.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
if(connection_string == null)
NUnit.Framework.Assert.Ignore ("Please consult README.tests.");
return connection_string;
}
}
// SQLClient does not allow to use the Provider token
// since Provider is always the first parameter(in GHT framework),
// we trim it.
public static string ConnectionStringSQLClient {
get {
return ConnectionString.Substring(ConnectionString.IndexOf(";"));
}
}
/// <summary>
/// Resolves the type of DB server specified by the "ADOConString.txt" file.
/// </summary>
/// <returns>The type of DB server specified by the "ADOConString.txt" file.</returns>
public static DataBaseServer GetDbType() {
return ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString);
}
/// <summary>
/// Resolves the type of DB server that the specified connection refers.
/// </summary>
/// <param name="OleCon">A valid connection object to a DataBase.</param>
/// <returns>The type of DB server that the specified connection refers to.</returns>
public static DataBaseServer GetDbType(Sys.Data.OracleClient.OracleConnection OleCon) {
return ConnectedDataProvider.GetDbType(OleCon.ConnectionString);
}
/// <summary>
/// Resolves the type of DB server that the specified connection string refers.
/// </summary>
/// <param name="ConnectionString">A valid connection string to a DataBase server.</param>
/// <returns>The type of DB server that the specified connection string refers to.</returns>
public static DataBaseServer GetDbType(string ConnectionString) {
return DataBaseServer.Oracle;
}
/// <summary>
/// Creates a DbTypeParametersCollection with default types and data for the TYPES_SIMPLE table.
/// </summary>
/// <returns>The initialized DbTypeParametersCollection</returns>
public static DbTypeParametersCollection GetSimpleDbTypesParameters() {
DbTypeParametersCollection row = new DbTypeParametersCollection(SIMPLE_TYPES_TABLE_NAME);
switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
#region SQLServer
case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
row.Add("bit", true, 1);
row.Add("tinyint", (byte)25, 1);
row.Add("smallint", (Int16)77, 2);
row.Add("int", (Int32)2525, 4);
row.Add("bigint", (Int64)25251414, 8);
row.Add("decimal", 10M, 9); //(Decimal)10
row.Add("numeric", 123123M, 9); //(Decimal)123123
row.Add("float", 17.1414257, 8);
row.Add("real", (float)0.71425, 4);
row.Add("char", "abcdefghij", 10);
row.Add("nchar", "klmnopqrst", 10);
row.Add("varchar", "qwertasdfg", 50);
row.Add("nvarchar", "qwertasdfg", 50);
break;
#endregion
#region Sybase
case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
//row.Add("BIT", true, 1);
row.Add("TINYINT", (byte)25, 1);
row.Add("SMALLINT", (Int16)77, 2);
row.Add("INT", (Int32)2525, 4);
//row.Add("BIGINT", (Int64)25251414, 8);
row.Add("DECIMAL", 10M, 9); //(Decimal)10
row.Add("NUMERIC", 123123M, 9); //(Decimal)123123
row.Add("FLOAT", 17.1414257, 8);
row.Add("REAL", (float)0.71425, 4);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "klmnopqrst", 10);
row.Add("VARCHAR", "qwertasdfg", 50);
row.Add("NVARCHAR", "qwertasdfg", 50);
break;
#endregion
#region ORACLE
case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
row.Add("NUMBER", 21M, 22); //(Decimal)21
row.Add("LONG", SAMPLE_STRING, 2147483647); //Default data type in .NET is system.String.
row.Add("FLOAT", 1.234, 22);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("NVARCHAR", "qwertasdfg", 20);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "abcdefghij", 10);
break;
#endregion
#region DB2
case MonoTests.System.Data.Utils.DataBaseServer.DB2:
row.Add("SMALLINT", (Int16)2, 2);
row.Add("INTEGER", 7777, 4);
row.Add("BIGINT", (Int64)21767267, 8);
row.Add("DECIMAL", 123M, 9); //(decimal)123
row.Add("REAL", (float)0.7, 4);
row.Add("DOUBLE", 1.7, 8);
row.Add("CHARACTER", "abcdefghij", 10);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("LONGVARCHAR", SAMPLE_STRING, 32000);
break;
#endregion
#region PostgreSQL
case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
// PostgreSQL ODBC Type BOOL returns String with value "1"
// so we don't run it on .NET
// if (!GHTEnvironment.IsJavaRunTime())
// {
// row.Add("BOOL", "1", 1);
// }
// else
// {
row.Add("BOOL", (bool)true, 1);
// }
row.Add("INT2", (Int16)21, 2);
row.Add("INT4", (Int32)30000, 4);
row.Add("INT8", (Int64)30001, 8);
row.Add("NUMERIC", (decimal)100000M, 10); //(decimal)100000
row.Add("FLOAT4", (Single)7.23157, 4);
row.Add("FLOAT8", (Double)7.123456, 8);
row.Add("VARCHAR", "qwertasdfg", 10);
row.Add("CHAR", "abcdefghij", 10);
row.Add("NCHAR", "klmnopqrst", 10);
break;
#endregion
}
return row;
}
/// <summary>
/// Creates a DbTypeParametersCollection with default types and data for the TYPES_EXTENDED table.
/// </summary>
/// <returns>The initialized DbTypeParametersCollection</returns>
public static DbTypeParametersCollection GetExtendedDbTypesParameters() {
DbTypeParametersCollection row = new DbTypeParametersCollection(EXTENDED_TYPES_TABLE_NAME);
switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
#region SQLServer
case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
row.Add("text", SAMPLE_STRING, 16);
row.Add("ntext", SAMPLE_STRING, 16);
row.Add("binary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("varbinary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("datetime", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
row.Add("smalldatetime", new DateTime(2004, 8, 9, 20, 30, 00), 4);
break;
#endregion
#region Sybase
case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
row.Add("TEXT", SAMPLE_STRING, 16);
//There is probably a bug in the jdbc driver , we've tried to insert this string using
//sybase command tool and it gave the same result (3850)
row.Add("NTEXT", SAMPLE_STRING.Trim() , 16);
row.Add("BINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("VARBINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("DATETIME", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
row.Add("SMALLDATETIME", new DateTime(2004, 8, 9, 20, 30, 00), 4);
break;
#endregion
#region ORACLE
case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
row.Add("RAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 10);
row.Add("LONGRAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
}, 100);
row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15), 7);
// The .NET Framework provides support for Oracle LOBs in the OracleClient namespace, but not in the Oracle namespace.
// Since Visual MainWin does not support the OracleClient namespace, a partial support for this important feature is provided in the Oracle namespace.
// See ms-help://MS.VSCC.2003/VMW.GH.1033/ghdoc/vmwdoc_ADONET_data_access_limitations_51.htm
#if TARGET_JVM
row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
}, 4000);
row.Add("CLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
, 4000);
row.Add("NCLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
, 4000);
#endif
break;
#endregion
#region DB2
case MonoTests.System.Data.Utils.DataBaseServer.DB2:
row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15, 500).Date);
row.Add("TIME", new TimeSpan(20, 30, 15));
row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500));
row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
});
row.Add("CLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
);
row.Add("DBCLOB", SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
+ SAMPLE_STRING
);
break;
#endregion
#region PostgreSQL
case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
row.Add("BYTEA", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
row.Add("DATE", new DateTime(2004, 8, 9));
row.Add("TEXT", "abcdefg", 16);
row.Add("TIME", new Sys.TimeSpan(02,02,02));
row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
break;
#endregion
}
return row;
}
}
}

View File

@@ -0,0 +1,293 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// 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 System;
using System.Data;
using System.Data.OracleClient;
namespace MonoTests.System.Data.Utils.Data
{
/// <summary>
/// Represents a parameter type for use in tests of System.Data.
/// </summary>
public class DbTypeParameter
{
#region Members
//Name of the Database type of this parameter.
private string m_sDbTypeName;
//Value of this parameter.
private object m_oValue;
//Size of this parameter.
private int m_iSize;
//Indicates wheather the size of this DbTypeParameter was initialized.
private bool m_bIsSizeSet = false;
#endregion
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public DbTypeParameter()
{
}
/// <summary>
/// Constructor, Initializes the DbTypeParameter's properties according to specified values.
/// </summary>
/// <param name="a_sTypeName">Specifies the initial parameter type Name for the DbTypeParameter.</param>
/// <param name="a_oValue">Specifies the initial value for the DbTypeParameter.</param>
public DbTypeParameter(string a_sTypeName, object a_oValue)
{
DbTypeName = a_sTypeName;
Value = a_oValue;
}
/// <summary>
/// Constructor, Initializes the DbTypeParameter's properties according to specified values.
/// </summary>
/// <param name="a_sTypeName">Specifies the initial parameter type Name for the DbTypeParameter.</param>
/// <param name="a_oValue">Specifies the initial value for the DbTypeParameter.</param>
/// <param name="a_iSize">Specifies the initial size for the DbTypeParameter.</param>
public DbTypeParameter(string a_sTypeName, object a_oValue, int a_iSize)
{
DbTypeName = a_sTypeName;
Value = a_oValue;
Size = a_iSize;
}
#endregion
#region Properties
public string DbColumnName
{
get
{
return string.Format("T_{0}", m_sDbTypeName);
}
}
public string ParameterName
{
get
{
return String.Format(":T_{0}", m_sDbTypeName);
}
}
public string DbTypeName
{
get
{
return m_sDbTypeName;
}
set
{
m_sDbTypeName = value;
}
}
public object Value
{
get
{
return m_oValue;
}
set
{
m_oValue = value;
}
}
public int Size
{
get
{
if (IsSizeSet)
{
return m_iSize;
}
else
{
throw new InvalidOperationException("DbTypeParameter size was not set.");
}
}
set
{
m_iSize = value;
m_bIsSizeSet = true;
}
}
public bool IsSizeSet
{
get
{
return m_bIsSizeSet;
}
}
public DbType DbType
{
get
{
return GetDefaultDbType(DbTypeName);
}
}
#endregion
#region Methods
public static DbType GetDefaultDbType(string dbTypeName)
{
switch (dbTypeName.ToUpper())
{
case "BIT": //SQLServer.
return DbType.Boolean;
case "TINYINT": //SQLServer.
return DbType.Byte;
case "SMALLINT": //SQLServer & DB2.
return DbType.Int16;
case "INT": //SQLServer.
return DbType.Int32;
case "INTEGER": //DB2
return DbType.Int32;
case "BIGINT": //MSSQLServer &DB2
return DbType.Int64;
case "NUMERIC": //MSSQLServer.
return DbType.Decimal;
case "NUMBER": //Oracle.
return DbType.VarNumeric;
case "DECIMAL": //MSSQLServer & DB2
return DbType.Decimal;
case "FLOAT": //MSSQLServer & Oracle
return DbType.Double;
case "REAL": //MSSQLServer & DB2
return DbType.Single;
case "DOUBLE":
return DbType.Double;
case "CHAR": //MSSQLServer & Oracle.
return DbType.AnsiStringFixedLength;
case "NCHAR": //MSSQLServer & Oracle.
return DbType.AnsiStringFixedLength;
case "VARCHAR": //MSSQLServer, Oracle & DB2.
return DbType.AnsiString;
case "NVARCHAR": //MSSQLServer & Oracle.
return DbType.AnsiString;
case "CHARACTER": //DB2
return DbType.AnsiStringFixedLength;
case "LONGVARCHAR": //DB2
return DbType.String;
case "LONG": //Oracle.
return DbType.AnsiString;
default:
throw new ApplicationException(string.Format("Dont know the default DbType for {0}.", dbTypeName));
}
}
public object ApplyDefaultDataTransformation()
{
if (Value == DBNull.Value)
{
return DBNull.Value;
}
else if (Value.GetType() == typeof(bool))
{
return DefaultBooleanTransformation((bool)Value);
}
else if (Value.GetType() == typeof(byte))
{
return DefaultByteTransformation((byte)Value);
}
else if (Value.GetType() == typeof(Int16))
{
return DefaultInt16Transformation((Int16)Value);
}
else if (Value.GetType() == typeof(int))
{
return DefaultIntTransformation((int)Value);
}
else if (Value.GetType() == typeof(Int64))
{
return DefaultInt64Transformation((Int64)Value);
}
else if (Value.GetType() == typeof(decimal))
{
return DefaultDecimalTransformation((decimal)Value);
}
else if (Value.GetType() == typeof(double))
{
return DefaultDoubleTransformation((double)Value);
}
else if (Value.GetType() == typeof(float))
{
return DefaultFloatTransformation((float)Value);
}
else if (Value.GetType() == typeof(string))
{
return DefaultStringTransformation((string)Value);
}
else
{
throw new ApplicationException(string.Format("No default transformation for type {0}.", Value));
}
}
public static bool DefaultBooleanTransformation(bool val)
{
return !val;
}
public static byte DefaultByteTransformation(byte val)
{
return (byte)(val*2);;
}
public static Int16 DefaultInt16Transformation(Int16 val)
{
return (Int16)(val*2);
}
public static int DefaultIntTransformation(int val)
{
return (int)(val*2);;
}
public static Int64 DefaultInt64Transformation(Int64 val)
{
return (Int64)(val*2);;
}
public static decimal DefaultDecimalTransformation(decimal val)
{
return (decimal)(val*2);;
}
public static double DefaultDoubleTransformation(double val)
{
return (double)(val*2);;
}
public static float DefaultFloatTransformation(float val)
{
return (float)(val*2);;
}
public static string DefaultStringTransformation(string val)
{
return val.ToUpper();;
}
/// <summary>
/// Invalidates the size of this DbTypeParameter.
/// </summary>
public void InvalidateSize()
{
m_bIsSizeSet = false;
}
#endregion
}
}

View File

@@ -0,0 +1,486 @@
//
// Copyright (c) 2006 Mainsoft Co.
//
// 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 System;
using System.IO;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Data.Utils
{
public class GHTBase
{
#region Constructors
/// <summary>Constructor
/// <param name="Logger">Custom TextWriter to log to</param>
/// <param name="LogOnSuccess">False to log only failed TestCases, True to log all</param>
/// </summary>
protected GHTBase(TextWriter Logger, bool LogOnSuccess)
{
this._logger = Logger;
this._logOnSuccess = LogOnSuccess;
}
/// <summary>Constructor, log to Console
/// <param name="LogOnSuccess">False to log only failed TestCases, True to log all</param>
/// </summary>
protected GHTBase(bool LogOnSuccess):this(Console.Out, LogOnSuccess){}
/// <summary>Constructor, log to Console only when Failed
/// </summary>
protected GHTBase():this(Console.Out, false){}
#endregion
#region protected methods
public void GHTSetLogger(TextWriter Logger)
{
this._logger = Logger;
}
/// <summary>Begin Test which containes TestCases
/// <param name="testName">Test name, used on logs</param>
/// </summary>
public virtual void BeginTest(string testName)
{
//set test name
this._testName = testName;
//reset the Failure Counter and the TestCase Number
UniqueId.ResetCounters();
if(this._logOnSuccess == true)
Log(string.Format("*** Starting Test: [{0}] ***", this._testName));
}
/// <summary>Begin TestCase
/// <param name="Description">TestCase Description, used on logs</param>
/// </summary>
public void BeginCase(string Description)
{
//Previous TestCase must be ended before beginning a new one.
if (_testCase != null) throw new Exception("Previous Case not Ended");
//init the new TestCase with Unique TestCase Number and Description
_testCase = new UniqueId(Description);
if(this._logOnSuccess == true)
Log(string.Format("Starting Case: [{0}]", _testCase.ToString()));
}
/// <summary>Compare two objects (using Object.Equals)
/// </summary>
protected bool Compare(object a, object b)
{
Assert.AreEqual(b, a);
//signal that the Compare method has been called
this._testCase.CompareInvoked = true;
//a string that holds the description of the objects for log
string ObjectData;
//check if one of the objects is null
if (a == null && b != null)
{
ObjectData = "Object a = null" + ", Object b.ToString() = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
this._testCase.Success = false; //objects are different, TestCase Failed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if the other object is null
if (a != null && b == null)
{
ObjectData = "Object a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + "), Object b = null";
this._testCase.Success = false; //objects are different, TestCase Failed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if both objects are null
if ( (a == null && b == null) )
{
ObjectData = "Object a = null, Object b = null";
this._testCase.Success = true; //both objects are null, TestCase Succeed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
ObjectData = "Object a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + "), Object b.ToString = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
//use Object.Equals to compare the objects
this._testCase.Success = (a.Equals(b));
LogCompareResult(ObjectData);
return this._testCase.Success;
}
/// <summary>Compare two Object Arrays.
/// <param name="a">First array.</param>
/// <param name="b">Second array.</param>
/// <param name="Sorted">Used to indicate if both arrays are sorted.</param>
/// </summary>
protected bool Compare(Array a, Array b)
{
Assert.AreEqual(b, a);
//signal that the Compare method has been called
this._testCase.CompareInvoked=true;
//a string that holds the description of the objects for log
string ObjectData;
//check if both objects are null
if ( (a == null && b == null) )
{
ObjectData = "Array a = null, Array b = null";
this._testCase.Success = true; //both objects are null, TestCase Succeed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if one of the objects is null.
//(If both were null, we wouldn't have reached here).
if (a == null || b == null)
{
string aData = (a==null) ? "null" : "'" + a.ToString() + "' (" + a.GetType().FullName + ")";
string bData = (b==null) ? "null" : "'" +b.ToString() + "' (" + b.GetType().FullName + ")";
ObjectData = "Array a = " + aData + ", Array b = " + bData;
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if both arrays are of the same rank.
if (a.Rank != b.Rank)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Rank = {0}, Array b.Rank = {1}", a.Rank, b.Rank);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Do not handle multi dimentional arrays.
if (a.Rank != 1)
{
this._testCase.Success = false;
ObjectData = "Multi-dimension array comparison is not supported";
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if both arrays are of the same length.
if (a.Length != b.Length)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Length = {0}, Array b.Length = {1}", a.Length, b.Length);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
ObjectData = "Array a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + ") Array b.ToString = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
//Compare elements of the Array.
int iLength = a.Length;
for (int i=0; i<iLength; i++)
{
object aValue = a.GetValue(i);
object bValue = b.GetValue(i);
if (aValue == null && bValue == null)
{
continue;
}
if (aValue == null || bValue == null || !aValue.Equals(bValue) )
{
string aData = (aValue==null) ? "null" : "'" + aValue.ToString() + "' (" + aValue.GetType().FullName + ")";
string bData = (bValue==null) ? "null" : "'" + bValue.ToString() + "' (" + bValue.GetType().FullName + ")";
ObjectData = string.Format("Array a[{0}] = {1}, Array b[{0}] = {2}", i, aData, bData);
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
}
this._testCase.Success = true;
LogCompareResult(ObjectData);
return this._testCase.Success;
}
/// <summary>
/// Intentionally fail a testcase, without calling the compare method.
/// </summary>
/// <param name="message">The reason for the failure.</param>
protected void Fail(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = false;
//Log(string.Format("TestCase \"{0}\" Failed: [{1}]", _testCase.ToString(), message));
Assert.Fail(message);
}
/// <summary>
/// Intentionally cause a testcase to pass, without calling the compare message.
/// </summary>
/// <param name="message">The reason for passing the test.</param>
protected void Pass(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = true;
if (this._logOnSuccess)
{
Log(string.Format("TestCase \"{0}\" Passed: [{1}]", _testCase.ToString(), message));
}
}
/// <summary>
/// Marks this testcase as success, but logs the reason for skipping regardless of _logOnSuccess value.
/// </summary>
/// <param name="message">The reason for skipping the test.</param>
protected void Skip(string message)
{
this._testCase.CompareInvoked = true;
this._testCase.Success = true;
Log(string.Format("TestCase \"{0}\" Skipped: [{1}]", _testCase.ToString(), message));
}
/// <summary>
/// Intentionally fail a testcase when an expected exception is not thrown.
/// </summary>
/// <param name="exceptionName">The name of the expected exception type.</param>
protected void ExpectedExceptionNotCaught(string exceptionName)
{
this.Fail(string.Format("Expected {0} was not caught.", exceptionName));
}
/// <summary>
/// Intentionally cause a testcase to pass, when an expected exception is thrown.
/// </summary>
/// <param name="ex"></param>
protected void ExpectedExceptionCaught(Exception ex)
{
this.Pass(string.Format("Expected {0} was caught.", ex.GetType().FullName));
}
/// <summary>End TestCase
/// <param name="ex">Exception object if exception occured during the TestCase, null if not</param>
/// </summary>
protected void EndCase(Exception ex)
{
//check if BeginCase was called. cannot end an unopen TestCase
if(_testCase == null)
{
throw new Exception("BeginCase was not called");
}
else
{
//if Exception occured during the test - log the error and faile the TestCase.
if(ex != null)
{
_testCase.Success=false;
Log(string.Format("TestCase: \"{0}\" Error: [Failed With Unexpected {1}: \n\t{2}]", _testCase.ToString(), ex.GetType().FullName, ex.Message + "\n" + ex.StackTrace ));
_testCase = null;
throw ex;
}
else
{
//check if Compare was called
if (_testCase.CompareInvoked == true)
{
if(this._logOnSuccess == true) Log(string.Format("Finished Case: [{0}] ", _testCase.ToString()));
}
else
{
//if compare was not called, log error message
Log(string.Format("TestCase \"{0}\" Warning: [TestCase didn't invoke the Compare mehtod] ", _testCase.ToString()));
}
}
//Terminate TestCase (set TestCase to null)
_testCase = null;
}
}
/// <summary>End Test
/// <param name="ex">Exception object if exception occured during the Test, null if not</param>
/// </summary>
public void EndTest(Exception ex)
{
//if all test cases succeeded but an exception occured - set exit code to -1
//if we wont set it to -1, the exit code will be 0 !!!
if (UniqueId.FailureCounter == 0 && ex != null)
{
Environment.ExitCode = -1;
}
else
{
//set exitcode to the count of failed TestCases
Environment.ExitCode = UniqueId.FailureCounter;
}
//if exception occured - log error
if(ex != null)
{
Log(string.Format("Unexpected Exception accured in Test [{0}] - {1} \n {2}" , this._testName, ex.Message ,ex.StackTrace));
}
if(this._logOnSuccess)
{
Log(string.Format("*** Finished Test: [{0}] ***", this._testName));
}
}
public int GHTGetExitCode()
{
return UniqueId.FailureCounter;
}
/// <summary>logger
/// <param name="text">string message to log</param>
/// </summary>
protected void Log(string text)
{
// _loggerBuffer = _loggerBuffer + "\n" + "GHTBase:Logger - " + text;
// _logger.WriteLine("GHTBase:Logger - " + text);
}
//used to log the results from the compare methods
private void LogCompareResult(string ObjectData)
{
if(this._testCase.Success == false)
{
Log(string.Format("TeseCase \"{0}\" Error: [Failed while comparing(" + ObjectData + ")] ", _testCase.ToString() ));
}
else
if(this._logOnSuccess == true)
Log(string.Format("TestCase \"{0}\" Passed ", _testCase.ToString()));
}
protected int TestCaseNumber
{
get
{
return _testCase.CaseNumber;
}
}
#endregion
#region private fields
private TextWriter _logger;
public string _loggerBuffer; // a public clone string of the _logger (used in web tests)
private string _testName;
private UniqueId _testCase;
private bool _logOnSuccess;
#endregion
}
//holds all the info on a TestCase
internal class UniqueId
{
//holds the unique name of the test case
//this name must be recieved from the test case itself
//when calling BeginCase.
//example: BeginCase("MyName")
private string _caseName;
//maintains the number generated for this test case
private static int _caseNumber;
//maintains the number of failed test case
private static int _FailureCounter;
internal static int FailureCounter
{
get
{
return _FailureCounter;
}
}
//indicate if the Compare method has been invoked AND containes compare objects message (ToString)
private bool _CompareInvoked;
internal bool CompareInvoked
{
get
{
return _CompareInvoked;
}
set
{
_CompareInvoked = value;
}
}
//reset the static counters when a new Test (not TestCase !!) begin
internal static void ResetCounters()
{
_FailureCounter = 0;
_caseNumber = 0;
}
//signal if a TestCase failed, if failed - increment the _FailureCounter
private bool _success;
internal bool Success
{
get
{
return this._success;
}
set
{
this._success = value;
if (value == false)
{
_FailureCounter++;
}
}
}
//Ctor, Recieve the name for the test case
//generate a unique number and apply it to the test case
internal UniqueId(string Name)
{
this._caseName = Name;
//this._caseNumber = ++UniqueId._counter;
_caseNumber++;
}
internal int CaseNumber
{
get
{
return _caseNumber;
}
}
public override string ToString()
{
return string.Format("\"{0}\" #{1}", this._caseName, _caseNumber);
}
}
}