Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup/nullable-ize UnitTests project #892

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions QuickFIXn/AcceptorSocketDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Net;
using QuickFix.Logger;
Expand All @@ -14,13 +15,20 @@ internal class AcceptorSocketDescriptor
public AcceptorSocketDescriptor(
IPEndPoint socketEndPoint,
SocketSettings socketSettings,
SettingsDictionary sessionDict,
NonSessionLog nonSessionLog)
{
Address = socketEndPoint;
SocketReactor = new ThreadedSocketReactor(Address, socketSettings, sessionDict, this, nonSessionLog);
SocketReactor = new ThreadedSocketReactor(Address, socketSettings, this, nonSessionLog);
}

[Obsolete("Param 'sessionDict' is unused. Use the alt constructor without it.")]
public AcceptorSocketDescriptor(
IPEndPoint socketEndPoint,
SocketSettings socketSettings,
SettingsDictionary sessionDict,
NonSessionLog nonSessionLog) : this(socketEndPoint, socketSettings, nonSessionLog)
{ }

internal void AcceptSession(Session session)
{
lock (_acceptedSessions)
Expand Down
8 changes: 4 additions & 4 deletions QuickFIXn/Fields/Converters/AsciiConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public static class AsciiValidator
public const int ASCII_NINE = 57;
public const int ASCII_MINUS = 45;

/// <summary>
/// TODO can we use NumberFormatInfo or NumberStyles to avoid this bit of ASCII hackery?
/// Validates that a string looks like number (for use before conversion to an int, ulong, etc.).
/// <summary>
/// Validates that a string looks like a number (for use before conversion to an int, ulong, etc.).
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static void Validate(string i)
{
if ((null == i) || (i.Length < 1))
if (i is null || i.Length < 1)
throw new FieldConvertError("The argument string cannot be null or empty");
int asciiValOfFirstChar = System.Convert.ToInt32(i[0]);
if ((asciiValOfFirstChar < ASCII_ZERO) || (asciiValOfFirstChar > ASCII_NINE))
if (asciiValOfFirstChar < ASCII_ZERO || asciiValOfFirstChar > ASCII_NINE)
if (asciiValOfFirstChar != ASCII_MINUS)
throw new FieldConvertError("Could not convert string to int (" + i + "): The first character must be a digit or a minus sign");
}
Expand Down
15 changes: 9 additions & 6 deletions QuickFIXn/IApplicationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ namespace QuickFix
/// and facilitates early interception of such messages. 'Early', in this context,
/// means after structure, length and checksum have been validated, but before any
/// further validation has been performed.
///
/// This interface will not normally be required, and it should be used only with caution:
/// it allows modfications to be made to irregular inbound messages that would otherwise
/// it allows modifications to be made to irregular inbound messages that would otherwise
/// fail validation against the Fix dictionary, an provides an alternative to dictionary
/// customisation as a means of dealing with such messages.
/// </summary>
public interface IApplicationExt : IApplication
{
/// <summary>
/// This callback provides early notification of when an administrative or application message is sent from a counterparty to your FIX engine.
/// This can be useful for doing pre-processing of an inbound message after its structure, checksum and length have been validated, but before
/// any further validation has been performed on it.
/// This callback provides early notification of when an administrative or application
/// message is sent from a counterparty to your FIX engine.
/// This can be useful for doing pre-processing of an inbound message after its structure,
/// checksum and length have been validated, but before
/// any further validation has been performed on it.
/// </summary>
/// <param name="message">received message</param>
/// <param name="sessionID">session on which message received</param>
void FromEarlyIntercept(Message message, SessionID sessionID);
/// <param name="sessionId">session on which message received</param>
void FromEarlyIntercept(Message message, SessionID sessionId);
}
}
2 changes: 1 addition & 1 deletion QuickFIXn/ThreadedSocketAcceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SettingsDictionary

if (!_socketDescriptorForAddress.TryGetValue(socketEndPoint, out var descriptor))
{
descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict, _nonSessionLog);
descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, _nonSessionLog);
_socketDescriptorForAddress[socketEndPoint] = descriptor;
}

Expand Down
1 change: 0 additions & 1 deletion QuickFIXn/ThreadedSocketReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public State ReactorState
internal ThreadedSocketReactor(
IPEndPoint serverSocketEndPoint,
SocketSettings socketSettings,
SettingsDictionary sessionDict,
AcceptorSocketDescriptor? acceptorSocketDescriptor,
NonSessionLog nonSessionLog)
{
Expand Down
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ What's New
* deprecate <Foo>Field.Obj (renamed to Value)
* deprecate <Foo>Field.getValue/setValue (just use Value getter/setter)
* #889 - nullable-ize Examples and fix deprecations (gbirchmeier)
* #892 - nullable-ize UnitTests project (gbirchmeier)
* also deprecate a AcceptorSocketDescriptor ctor due to unused param

### v1.12.0

Expand Down
14 changes: 7 additions & 7 deletions UnitTests/DataDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static XmlNode MakeNode(string xmlString)
if (xmlString.StartsWith('<'))
{
doc.LoadXml(xmlString);
return doc.DocumentElement;
return doc.DocumentElement!;
}
return doc.CreateTextNode(xmlString);
}
Expand All @@ -392,18 +392,18 @@ public void VerifyChildNodeAndReturnNameAtt() {
MakeNode("<sometag name='qty'/>"), parentNode));

DictionaryParseException dpx = Assert.Throws<DictionaryParseException>(
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("foo"), parentNode); });
Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx!.Message);
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("foo"), parentNode); })!;
Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx.Message);

dpx = Assert.Throws<DictionaryParseException>(
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); });
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'", dpx!.Message);
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); })!;
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'", dpx.Message);

// alt error message, where parent has no name
parentNode = MakeNode("<parentnode/>");
dpx = Assert.Throws<DictionaryParseException>(
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); });
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx!.Message);
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); })!;
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx.Message);
}
}
}
3 changes: 0 additions & 3 deletions UnitTests/DataDictionary_ValidateTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#nullable enable

using System;
using NUnit.Framework;
using QuickFix;
using QuickFix.DataDictionary;
Expand Down
22 changes: 11 additions & 11 deletions UnitTests/Fields/Converters/DecimalConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ public class DecimalConverterTests {
[Test]
public void Convert()
{
Assert.That(DecimalConverter.Convert(new Decimal(4.23322)), Is.EqualTo("4.23322"));
Assert.That(DecimalConverter.Convert(new Decimal(-4.23322)), Is.EqualTo("-4.23322"));
Assert.That(DecimalConverter.Convert(4.23322m), Is.EqualTo("4.23322"));
Assert.That(DecimalConverter.Convert(-4.23322m), Is.EqualTo("-4.23322"));
Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(new Decimal(4332.33)));
Assert.That(DecimalConverter.Convert("3.000000000021874E-4"), Is.EqualTo(0.0003000000000021874M));
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("2.32a34"); });
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("+1.2"); });
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("(1.2)"); });
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(""); });
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null); });
Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null!); });

// check for a different culture than en-XX
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "tr-TR" );
Assert.That( DecimalConverter.Convert( "4332.33" ), Is.EqualTo( new Decimal( 4332.33 ) ) );
Assert.That( DecimalConverter.Convert( "-2.33" ), Is.EqualTo( new Decimal( -2.33 ) ) );
Assert.That( DecimalConverter.Convert( new Decimal( 4.23322 ) ), Is.EqualTo( "4.23322" ) );
Assert.That( DecimalConverter.Convert( new Decimal( -4.23322 ) ), Is.EqualTo( "-4.23322" ) );
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("tr-TR");
Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(4332.33m));
Assert.That(DecimalConverter.Convert("-2.33"), Is.EqualTo(-2.33m));
Assert.That(DecimalConverter.Convert(4.23322m), Is.EqualTo("4.23322"));
Assert.That(DecimalConverter.Convert(-4.23322m), Is.EqualTo("-4.23322"));
}

[Test]
public void Convert_WithoutLeadingTrailingZeros()
{
Assert.That(DecimalConverter.Convert("23."), Is.EqualTo(new Decimal(23)));
Assert.That(DecimalConverter.Convert(".23"), Is.EqualTo(new Decimal(0.23)));
Assert.That(DecimalConverter.Convert("-.23"), Is.EqualTo(new Decimal(-0.23)));
Assert.That(DecimalConverter.Convert("23."), Is.EqualTo(23m));
Assert.That(DecimalConverter.Convert(".23"), Is.EqualTo(0.23m));
Assert.That(DecimalConverter.Convert("-.23"), Is.EqualTo(-0.23m));
}
}
2 changes: 1 addition & 1 deletion UnitTests/Fields/Converters/IntConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public void Convert()
Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("AB"); });
Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("2.3234"); });
Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(""); });
Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(null); });
Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(null!); });
}
}
43 changes: 20 additions & 23 deletions UnitTests/FileStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
using System.IO;
using NUnit.Framework;
using System.Threading;
using QuickFix;
using QuickFix.Store;

namespace UnitTests
{
[TestFixture]
public class FileStoreTests
{
private FileStore _store;
private FileStoreFactory _factory;
private FileStore? _store;
private FileStoreFactory? _factory;

private QuickFix.SessionSettings _settings;
private QuickFix.SessionID _sessionID;
private QuickFix.SessionSettings _settings = new();
private QuickFix.SessionID _sessionId = new("unset", "unset", "unset");

private string _storeDirectory;
private string _storeDirectory = "unset";

[SetUp]
public void Setup()
Expand All @@ -26,34 +27,30 @@ public void Setup()
if (System.IO.Directory.Exists(_storeDirectory))
System.IO.Directory.Delete(_storeDirectory, true);

_sessionID = new QuickFix.SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP");
_sessionId = new QuickFix.SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP");

QuickFix.SettingsDictionary config = new QuickFix.SettingsDictionary();
config.SetString(QuickFix.SessionSettings.CONNECTION_TYPE, "initiator");
config.SetString(QuickFix.SessionSettings.FILE_STORE_PATH, _storeDirectory);

_settings = new QuickFix.SessionSettings();
_settings.Set(_sessionID, config);
_settings.Set(_sessionId, config);
_factory = new FileStoreFactory(_settings);

_store = (FileStore)_factory.Create(_sessionID);
_store = (FileStore)_factory.Create(_sessionId);
}

void RebuildStore()
{
if(_store != null)
{
_store.Dispose();
}

_store = (FileStore)_factory.Create(_sessionID);
_store?.Dispose();
_store = (FileStore)_factory!.Create(_sessionId);
}


[TearDown]
public void Teardown()
{
_store.Dispose();
_store!.Dispose();
Directory.Delete(_storeDirectory, true);
}

Expand All @@ -79,7 +76,7 @@ public void GenerateFileNamesTest()
[Test]
public void NextSenderMsgSeqNumTest()
{
Assert.AreEqual(1, _store.NextSenderMsgSeqNum);
Assert.AreEqual(1, _store!.NextSenderMsgSeqNum);
_store.NextSenderMsgSeqNum = 5;
Assert.AreEqual(5, _store.NextSenderMsgSeqNum);
RebuildStore();
Expand All @@ -89,7 +86,7 @@ public void NextSenderMsgSeqNumTest()
[Test]
public void IncNextSenderMsgSeqNumTest()
{
_store.IncrNextSenderMsgSeqNum();
_store!.IncrNextSenderMsgSeqNum();
Assert.AreEqual(2, _store.NextSenderMsgSeqNum);
RebuildStore();
Assert.AreEqual(2, _store.NextSenderMsgSeqNum);
Expand All @@ -98,7 +95,7 @@ public void IncNextSenderMsgSeqNumTest()
[Test]
public void NextTargetMsgSeqNumTest()
{
Assert.AreEqual(1, _store.NextTargetMsgSeqNum);
Assert.AreEqual(1, _store!.NextTargetMsgSeqNum);
_store.NextTargetMsgSeqNum = 6;
Assert.AreEqual(6, _store.NextTargetMsgSeqNum);
RebuildStore();
Expand All @@ -108,7 +105,7 @@ public void NextTargetMsgSeqNumTest()
[Test]
public void IncNextTargetMsgSeqNumTest()
{
_store.IncrNextTargetMsgSeqNum();
_store!.IncrNextTargetMsgSeqNum();
Assert.AreEqual(2, _store.NextTargetMsgSeqNum);
RebuildStore();
Assert.AreEqual(2, _store.NextTargetMsgSeqNum);
Expand All @@ -119,7 +116,7 @@ public void IncNextTargetMsgSeqNumTest()
public void TestSeqNumLimitsForContinuousMarkets()
{
// Given the next seqnums are UInt64.MaxValue - 1
_store.NextSenderMsgSeqNum = System.UInt64.MaxValue - 1;
_store!.NextSenderMsgSeqNum = System.UInt64.MaxValue - 1;
_store.NextTargetMsgSeqNum = _store.NextSenderMsgSeqNum;

// When the next seqnums are incremented
Expand Down Expand Up @@ -157,7 +154,7 @@ public void TestSeqNumLimitsForContinuousMarkets()
public void ResetTest()
{
// seq nums reset
_store.NextTargetMsgSeqNum = 5;
_store!.NextTargetMsgSeqNum = 5;
_store.NextSenderMsgSeqNum = 4;
_store.Reset();
Assert.AreEqual(1, _store.NextTargetMsgSeqNum);
Expand All @@ -179,7 +176,7 @@ public void ResetTest()
[Test]
public void CreationTimeTest()
{
DateTime d1 = _store.CreationTime.Value;
DateTime d1 = _store!.CreationTime!.Value;
RebuildStore();
DateTime d2 = _store.CreationTime.Value;
Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d1, d2);
Expand All @@ -194,7 +191,7 @@ public void CreationTimeTest()
[Test]
public void GetTest()
{
_store.Set(1, "dude");
_store!.Set(1, "dude");
_store.Set(2, "pude");
_store.Set(3, "ok");
_store.Set(4, "ohai");
Expand Down
Loading
Loading