-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
FbDecFloat16SupportTests.cs
140 lines (127 loc) · 4.64 KB
/
FbDecFloat16SupportTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/
//$Authors = Jiri Cincura (jiri@cincura.net)
using System;
using System.Numerics;
using System.Threading.Tasks;
using FirebirdSql.Data.TestsBase;
using FirebirdSql.Data.Types;
using NUnit.Framework;
namespace FirebirdSql.Data.FirebirdClient.Tests;
[TestFixtureSource(typeof(FbServerTypeTestFixtureSource), nameof(FbServerTypeTestFixtureSource.Default))]
[TestFixtureSource(typeof(FbServerTypeTestFixtureSource), nameof(FbServerTypeTestFixtureSource.Embedded))]
public class FbDecFloat16SupportTests : FbTestsBase
{
public FbDecFloat16SupportTests(FbServerType serverType, bool compression, FbWireCrypt wireCrypt)
: base(serverType, compression, wireCrypt, false)
{ }
[SetUp]
public override async Task SetUp()
{
await base.SetUp();
if (!EnsureServerVersionAtLeast(new Version(4, 0, 0, 0)))
return;
}
static readonly object[] TestValues = new[]
{
new object[] { (FbDecFloat)0, "0" },
new object[] { (FbDecFloat)1, "1" },
new object[] { (FbDecFloat)(-1), "-1" },
new object[] { (FbDecFloat)6, "6" },
new object[] { (FbDecFloat)(-6), "-6" },
new object[] { FbDecFloat.NegativeZero, "-0" },
new object[] { FbDecFloat.PositiveInfinity, "inf" },
new object[] { FbDecFloat.NegativeInfinity, "-inf" },
new object[] { FbDecFloat.PositiveNaN, "nan" },
new object[] { FbDecFloat.NegativeNaN, "-nan" },
new object[] { FbDecFloat.PositiveSignalingNaN, "snan" },
new object[] { FbDecFloat.NegativeSignalingNaN, "-snan" },
new object[] { (FbDecFloat)0.1, "0.1" },
new object[] { (FbDecFloat)(-0.1), "-0.1" },
new object[] { (FbDecFloat)6.6, "6.6" },
new object[] { (FbDecFloat)(-6.6), "-6.6" },
new object[] { new FbDecFloat(10, 34), "100000000000000000000000000000000000" },
new object[] { new FbDecFloat(-10, 34), "-100000000000000000000000000000000000" },
new object[] { new FbDecFloat(BigInteger.Parse("123000000001"), -10), "123.000000001E-1" },
new object[] { new FbDecFloat(BigInteger.Parse("-123000000001"), -10), "-123.000000001E-1" },
};
[TestCaseSource(nameof(TestValues))]
public async Task ReadsValueCorrectly(FbDecFloat value, string castValue)
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = $"select cast('{castValue}' as decfloat(16)) from rdb$database";
var result = (FbDecFloat)await cmd.ExecuteScalarAsync();
Assert.AreEqual(value, result);
}
}
[TestCaseSource(nameof(TestValues))]
public async Task PassesValueCorrectly(FbDecFloat value, string dummy)
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = "select cast(@value as decfloat(16)) from rdb$database";
cmd.Parameters.AddWithValue("value", value);
var result = (FbDecFloat)await cmd.ExecuteScalarAsync();
Assert.AreEqual(value, result);
}
}
[Test]
public async Task ReadsValueNullCorrectly()
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = "select cast(null as decfloat(16)) from rdb$database";
var result = (DBNull)await cmd.ExecuteScalarAsync();
Assert.AreEqual(DBNull.Value, result);
}
}
[Test]
public async Task PassesValueNullCorrectly()
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = "select cast(@value as decfloat(16)) from rdb$database";
cmd.Parameters.AddWithValue("value", DBNull.Value);
var result = (DBNull)await cmd.ExecuteScalarAsync();
Assert.AreEqual(DBNull.Value, result);
}
}
[Test]
public async Task SelectEmptyResultSet()
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = "select cast(null as decfloat(16)) from rdb$database where 0=1";
await using (var reader = await cmd.ExecuteReaderAsync())
{
Assert.DoesNotThrowAsync(reader.ReadAsync);
}
}
}
[Test]
public async Task SimpleSelectSchemaTableTest()
{
await using (var cmd = Connection.CreateCommand())
{
cmd.CommandText = "select cast(null as decfloat(16)) from rdb$database";
await using (var reader = await cmd.ExecuteReaderAsync())
{
var schema = await reader.GetSchemaTableAsync();
Assert.AreEqual(typeof(FbDecFloat), schema.Rows[0].ItemArray[5]);
}
}
}
}