Beispiel #1
0
        public static bool Verify <TAuthenticationClass>(TAuthenticationResultType receivedValue, TAuthenticationResultType computedValue) where TAuthenticationClass : CalculatorAuthenticationBase <TAuthenticationResultType>, new()
        {
            TAuthenticationClass authenticator = new TAuthenticationClass();
            DeserializeStatus    status        = new DeserializeStatus();

            return(authenticator.Verify(status, receivedValue, computedValue));
        }
Beispiel #2
0
        protected void VerifyResults <TClassToTest, TReturnType>(TClassToTest testClass, TReturnType expectedCrc, TReturnType computedCrc) where TClassToTest : CalculatorAuthenticationBase <TReturnType>
        {
            DeserializeStatus status = new DeserializeStatus();

            Assert.That(testClass.Verify(status, expectedCrc, computedCrc), Is.True);
            Assert.That(computedCrc, Is.EqualTo(expectedCrc));
        }
Beispiel #3
0
        protected virtual void TestField <TTypeSerializer, TValueType>(TTypeSerializer typeSerializer, MessageSerializedPropertyInfo propertyInfo, TValueType valueToUse, byte[] expectedArray)
            where TTypeSerializer : TypeSerializerBase <TValueType>
        {
            byte[] serializedArray = typeSerializer.Serialize(valueToUse);
            Assert.That(serializedArray, Is.EqualTo(expectedArray), "Serialize");

            DeserializeStatus status     = new DeserializeStatus();
            int        currentArrayIndex = 0;
            TValueType deserializedValue = typeSerializer.Deserialize(expectedArray, ref currentArrayIndex, expectedArray.Length, ref status);

            VerifyDeserialized(deserializedValue, valueToUse, propertyInfo, expectedArray);

            CheckToString(typeSerializer, propertyInfo, valueToUse, expectedArray);
        }
Beispiel #4
0
        protected virtual void TestListField <TTypeSerializer, TListType, TValueType>(TTypeSerializer typeSerializer, MessageSerializedPropertyInfo propertyInfo, TListType listToUse, byte[] expectedArray)
            where TTypeSerializer : TypeSerializerBase <TValueType>
            where TListType : IEnumerable <TValueType>, IList, new()
        {
            byte[] serializedArray = typeSerializer.Serialize(listToUse);
            Assert.That(serializedArray, Is.EqualTo(expectedArray), "Serialize");

            DeserializeStatus status    = new DeserializeStatus();
            int       currentArrayIndex = 0;
            TListType deserializedList  = typeSerializer.DeserializeList <TListType>(expectedArray, ref currentArrayIndex, expectedArray.Length, ref status);

            VerifyDeserializedList <TListType, TValueType>(deserializedList, listToUse, propertyInfo, expectedArray);

            ToStringFormatProperties formatProperties = ToStringFormatProperties.Default;
            string expectedToStringResult             = GetExpectedListToString <TListType, TValueType>(propertyInfo, listToUse, formatProperties);
            string toStringResult = typeSerializer.ToString(listToUse, 0, formatProperties, true);

            Assert.That(toStringResult, Is.EqualTo(expectedToStringResult), "ToString");
        }
Beispiel #5
0
            public override int Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status)
            {
                // GetNumeric expects there to be the correct number of bytes for the type it is converting to
                // So we need to first get the 3 bytes we want and get them in little endian order
                // This is so when we resize to 4 bytes the 0x00 for the MSB will be correctly put at the end
                // Then when we call GetNumeric we make sure to indicate that the bytes are currently in little endian order
                byte[] workingArray = ArrayOps.GetSubArray(bytes, currentArrayIndex, 3, ArrayOps.EndiannessRequiresReversal(_propertyInfo.MessagePropertyAttribute.Endianness, Endiannesses.Little));
                Array.Resize(ref workingArray, 4);
                int value = ArrayOps.GetNumeric <int>(workingArray, Endiannesses.Little);

                currentArrayIndex += 3;
                return(value);
            }
Beispiel #6
0
        public override TNumericType Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status)
        {
            if (length == -1)
            {
                length = GetLength();
            }

            TNumericType returnValue = ArrayOps.GetNumeric <TNumericType>(bytes, currentArrayIndex, length, _propertyInfo.MessagePropertyAttribute.Endianness);

            currentArrayIndex += length;
            return(returnValue);
        }
Beispiel #7
0
 public override TSerializableType Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status)
 {
     return(Serializer.Instance.Deserialize <TSerializableType>(bytes, ref currentArrayIndex));
 }
Beispiel #8
0
 public override int Deserialize(byte[] bytes, ref int currentArrayIndex, int length, ref DeserializeStatus status)
 {
     currentArrayIndex += 3;
     return(_lastSerialized);
 }
Beispiel #9
0
 public DeserializeResults()
 {
     Object = null;
     Status = new DeserializeStatus();
 }