Rename DTL to DateTimeLong

This commit is contained in:
Serge Camille
2020-08-17 19:14:28 +02:00
parent 4be5765fc9
commit a1d87de2d9
6 changed files with 41 additions and 41 deletions

View File

@@ -81,7 +81,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\TestLongStruct.cs" />
<Compile Include="TypeTests\ClassTests.cs" />
<Compile Include="TypeTests\DtlTests.cs" />
<Compile Include="TypeTests\DateTimeLongTests.cs" />
<Compile Include="TypeTests\DateTimeTests.cs" />
<Compile Include="TypeTests\StringExTests.cs" />
<Compile Include="TypeTests\StringTests.cs" />

View File

@@ -4,7 +4,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace S7.Net.UnitTest.TypeTests
{
public static class DtlTests
public static class DateTimeLongTests
{
private static readonly DateTime SampleDateTime = new DateTime(1993, 12, 25, 8, 12, 34, 567);
@@ -12,12 +12,12 @@ namespace S7.Net.UnitTest.TypeTests
private static readonly byte[] SpecMinByteArray =
{
0x07, 0xB2, 0x01, 0x01, (byte) (int) (Types.Dtl.SpecMinimumDateTime.DayOfWeek + 1), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x07, 0xB2, 0x01, 0x01, (byte) (int) (Types.DateTimeLong.SpecMinimumDateTime.DayOfWeek + 1), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
private static readonly byte[] SpecMaxByteArray =
{
0x08, 0xD6, 0x04, 0x0B, (byte) (int) (Types.Dtl.SpecMaximumDateTime.DayOfWeek + 1), 0x17, 0x2F, 0x10, 0x32, 0xE7, 0x01, 0x80
0x08, 0xD6, 0x04, 0x0B, (byte) (int) (Types.DateTimeLong.SpecMaximumDateTime.DayOfWeek + 1), 0x17, 0x2F, 0x10, 0x32, 0xE7, 0x01, 0x80
};
[TestClass]
@@ -32,97 +32,97 @@ namespace S7.Net.UnitTest.TypeTests
[TestMethod]
public void SpecMinimum()
{
AssertFromByteArrayEquals(Types.Dtl.SpecMinimumDateTime, SpecMinByteArray);
AssertFromByteArrayEquals(Types.DateTimeLong.SpecMinimumDateTime, SpecMinByteArray);
}
[TestMethod]
public void SpecMaximum()
{
AssertFromByteArrayEquals(Types.Dtl.SpecMaximumDateTime, SpecMaxByteArray);
AssertFromByteArrayEquals(Types.DateTimeLong.SpecMaximumDateTime, SpecMaxByteArray);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnLessThan12Bytes()
{
Types.Dtl.FromByteArray(new byte[11]);
Types.DateTimeLong.FromByteArray(new byte[11]);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnMoreTHan12Bytes()
{
Types.Dtl.FromByteArray(new byte[13]);
Types.DateTimeLong.FromByteArray(new byte[13]);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnInvalidYear()
{
Types.Dtl.FromByteArray(MutateSample(0, 0xa0));
Types.DateTimeLong.FromByteArray(MutateSample(0, 0xa0));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnZeroMonth()
{
Types.Dtl.FromByteArray(MutateSample(2, 0x00));
Types.DateTimeLong.FromByteArray(MutateSample(2, 0x00));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnTooLargeMonth()
{
Types.Dtl.FromByteArray(MutateSample(2, 0x13));
Types.DateTimeLong.FromByteArray(MutateSample(2, 0x13));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnZeroDay()
{
Types.Dtl.FromByteArray(MutateSample(3, 0x00));
Types.DateTimeLong.FromByteArray(MutateSample(3, 0x00));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnTooLargeDay()
{
Types.Dtl.FromByteArray(MutateSample(3, 0x32));
Types.DateTimeLong.FromByteArray(MutateSample(3, 0x32));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnInvalidHour()
{
Types.Dtl.FromByteArray(MutateSample(5, 0x24));
Types.DateTimeLong.FromByteArray(MutateSample(5, 0x24));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnInvalidMinute()
{
Types.Dtl.FromByteArray(MutateSample(6, 0x60));
Types.DateTimeLong.FromByteArray(MutateSample(6, 0x60));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnInvalidSecond()
{
Types.Dtl.FromByteArray(MutateSample(7, 0x60));
Types.DateTimeLong.FromByteArray(MutateSample(7, 0x60));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnInvalidNanosecondsFirstDigit()
{
Types.Dtl.FromByteArray(MutateSample(8, 0x3B));
Types.DateTimeLong.FromByteArray(MutateSample(8, 0x3B));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnZeroDayOfWeek()
{
Types.Dtl.FromByteArray(MutateSample(4, 0));
Types.DateTimeLong.FromByteArray(MutateSample(4, 0));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnTooLargeDayOfWeek()
{
Types.Dtl.FromByteArray(MutateSample(4, 8));
Types.DateTimeLong.FromByteArray(MutateSample(4, 8));
}
private static void AssertFromByteArrayEquals(DateTime expected, params byte[] bytes)
{
Assert.AreEqual(expected, Types.Dtl.FromByteArray(bytes));
Assert.AreEqual(expected, Types.DateTimeLong.FromByteArray(bytes));
}
private static byte[] MutateSample(int index, byte value) =>
@@ -141,30 +141,30 @@ namespace S7.Net.UnitTest.TypeTests
[TestMethod]
public void SpecMinimum()
{
AssertToByteArrayEquals(Types.Dtl.SpecMinimumDateTime, SpecMinByteArray);
AssertToByteArrayEquals(Types.DateTimeLong.SpecMinimumDateTime, SpecMinByteArray);
}
[TestMethod]
public void SpecMaximum()
{
AssertToByteArrayEquals(Types.Dtl.SpecMaximumDateTime, SpecMaxByteArray);
AssertToByteArrayEquals(Types.DateTimeLong.SpecMaximumDateTime, SpecMaxByteArray);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnTimeBeforeSpecMinimum()
{
Types.Dtl.ToByteArray(new DateTime(1950, 1, 1));
Types.DateTimeLong.ToByteArray(new DateTime(1950, 1, 1));
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void ThrowsOnTimeAfterSpecMaximum()
{
Types.Dtl.ToByteArray(new DateTime(2790, 1, 1));
Types.DateTimeLong.ToByteArray(new DateTime(2790, 1, 1));
}
private static void AssertToByteArrayEquals(DateTime value, params byte[] expected)
{
CollectionAssert.AreEqual(expected, Types.Dtl.ToByteArray(value));
CollectionAssert.AreEqual(expected, Types.DateTimeLong.ToByteArray(value));
}
}
}

View File

@@ -189,8 +189,8 @@
DateTime,
/// <summary>
/// DTL variable type
/// DateTimeLong variable type
/// </summary>
Dtl
DateTimeLong
}
}

View File

@@ -156,14 +156,14 @@ namespace S7.Net
{
return DateTime.ToArray(bytes);
}
case VarType.Dtl:
case VarType.DateTimeLong:
if (varCount == 1)
{
return Dtl.FromByteArray(bytes);
return DateTimeLong.FromByteArray(bytes);
}
else
{
return Dtl.ToArray(bytes);
return DateTimeLong.ToArray(bytes);
}
default:
return null;
@@ -199,7 +199,7 @@ namespace S7.Net
return varCount * 4;
case VarType.DateTime:
return varCount * 8;
case VarType.Dtl:
case VarType.DateTimeLong:
return varCount * 12;
default:
return 0;

View File

@@ -64,8 +64,8 @@ namespace S7.Net.Protocol
return Types.String.ToByteArray(stringVal, stringVal.Length);
case "DateTime[]":
return Types.DateTime.ToByteArray((System.DateTime[]) value);
case "Dtl[]":
return Types.Dtl.ToByteArray((System.DateTime[])value);
case "DateTimeLong[]":
return Types.DateTimeLong.ToByteArray((System.DateTime[])value);
default:
throw new InvalidVariableTypeException();
}

View File

@@ -5,9 +5,9 @@ using System.IO;
namespace S7.Net.Types
{
/// <summary>
/// Contains the methods to convert between <see cref="T:System.DateTime" /> and S7 representation of DTL values.
/// Contains the methods to convert between <see cref="T:System.DateTime" /> and S7 representation of DateTimeLong (DTL) values.
/// </summary>
public static class Dtl
public static class DateTimeLong
{
/// <summary>
/// The minimum <see cref="T:System.DateTime" /> value supported by the specification.
@@ -49,7 +49,7 @@ namespace S7.Net.Types
if (bytes.Length % 12 != 0)
{
throw new ArgumentOutOfRangeException(nameof(bytes), bytes.Length,
$"Parsing an array of Dtl requires a multiple of 12 bytes of input data, input data is '{bytes.Length}' long.");
$"Parsing an array of DateTimeLong requires a multiple of 12 bytes of input data, input data is '{bytes.Length}' long.");
}
var cnt = bytes.Length / 12;
@@ -70,7 +70,7 @@ namespace S7.Net.Types
if (bytes.Length != 12)
{
throw new ArgumentOutOfRangeException(nameof(bytes), bytes.Length,
$"Parsing a Dtl requires exactly 12 bytes of input data, input data is {bytes.Length} bytes long.");
$"Parsing a DateTimeLong requires exactly 12 bytes of input data, input data is {bytes.Length} bytes long.");
}
@@ -94,7 +94,7 @@ namespace S7.Net.Types
/// Converts a <see cref="T:System.DateTime" /> value to a byte array.
/// </summary>
/// <param name="dateTime">The DateTime value to convert.</param>
/// <returns>A byte array containing the S7 DTL representation of <paramref name="dateTime" />.</returns>
/// <returns>A byte array containing the S7 DateTimeLong representation of <paramref name="dateTime" />.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the value of
/// <paramref name="dateTime" /> is before <see cref="P:SpecMinimumDateTime" />
@@ -105,13 +105,13 @@ namespace S7.Net.Types
if (dateTime < SpecMinimumDateTime)
{
throw new ArgumentOutOfRangeException(nameof(dateTime), dateTime,
$"Date time '{dateTime}' is before the minimum '{SpecMinimumDateTime}' supported in S7 DTL representation.");
$"Date time '{dateTime}' is before the minimum '{SpecMinimumDateTime}' supported in S7 DateTimeLong representation.");
}
if (dateTime > SpecMaximumDateTime)
{
throw new ArgumentOutOfRangeException(nameof(dateTime), dateTime,
$"Date time '{dateTime}' is after the maximum '{SpecMaximumDateTime}' supported in S7 DTL representation.");
$"Date time '{dateTime}' is after the maximum '{SpecMaximumDateTime}' supported in S7 DateTimeLong representation.");
}
var stream = new MemoryStream(12);
@@ -147,7 +147,7 @@ namespace S7.Net.Types
/// Converts an array of <see cref="T:System.DateTime" /> values to a byte array.
/// </summary>
/// <param name="dateTimes">The DateTime values to convert.</param>
/// <returns>A byte array containing the S7 DTL representations of <paramref name="dateTimes" />.</returns>
/// <returns>A byte array containing the S7 DateTimeLong representations of <paramref name="dateTimes" />.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when any value of
/// <paramref name="dateTimes" /> is before <see cref="P:SpecMinimumDateTime" />