Пример #1
0
        public void AssortedMix(bool preserveTypes, int expectedLength)
        {
            KeyValuePair <object, object>[] items = new KeyValuePair <object, object>[] {
                new KeyValuePair <object, object>(true, true),
                new KeyValuePair <object, object>(false, false),
                new KeyValuePair <object, object>(null, null),
                new KeyValuePair <object, object>(int.MinValue, uint.MaxValue),
                new KeyValuePair <object, object>((byte)1, 5.2d),
                new KeyValuePair <object, object>((byte)2, 900.1f),
                new KeyValuePair <object, object>("Hallo!", "Hallo!"),
            };
            if (preserveTypes)
            {
                MsgPackTests.DynamicallyCompactValue = false;
            }
            try {
                MsgPackItem item = MsgPackTests.RoundTripTest <MpMap, KeyValuePair <object, object>[]>(items, expectedLength, MsgPackTypeId.MpMap4);

                KeyValuePair <object, object>[] ret = item.GetTypedValue <KeyValuePair <object, object>[]>();

                Assert.AreEqual(items.Length, ret.Length, string.Concat("Expected ", items.Length, " items but got ", ret.Length, " items in the array."));
                for (int t = ret.Length - 1; t >= 0; t--)
                {
                    if (preserveTypes && t != 2)
                    {
                        Assert.IsTrue(items[t].GetType() == ret[t].GetType(), string.Concat("Expected type ", items[t].GetType(), " items but got ", ret[t].GetType(), "."));
                    }
                    Assert.AreEqual(items[t], ret[t], string.Concat("Expected ", items[t], " but got ", ret[t], " at index ", t));
                }
            } finally {
                MsgPackTests.DynamicallyCompactValue = true;
            }
        }
Пример #2
0
        public void BinaryLengths(int length, int expectedBytes, MsgPackTypeId expedctedType)
        {
            Randomizer rnd = new Randomizer();

            byte[] test = new byte[length];
            rnd.NextBytes(test);
            MsgPackTests.RoundTripTest <MpExt, byte[]>(test, expectedBytes, expedctedType, (sbyte)(rnd.Next(255) - 128));
        }
Пример #3
0
 public void Utf32Test()
 {
     try {
         MpString.DefaultEncoding = Encoding.UTF32;
         MsgPackTests.RoundTripTest <MpString, string>("Hello world!", 50, MsgPackTypeId.MpStr8);
     } finally {
         MpString.DefaultEncoding = Encoding.UTF8;
     }
 }
Пример #4
0
 public void PreserveTypeTest <T>(T value, int expectedLength, MsgPackTypeId expectedType)
 {
     MsgPackTests.DynamicallyCompactValue = false;
     try {
         MsgPackTests.RoundTripTest <MpInt, T>(value, expectedLength, expectedType);
     } finally {
         MsgPackTests.DynamicallyCompactValue = true;
     }
 }
Пример #5
0
        public void EnumTest <T>(T enumDef, MsgPackTypeId expectedType)
        {
            var vals = Enum.GetValues(typeof(T));

            for (int t = vals.Length - 1; t >= 0; t--)
            {
                MsgPackTests.RoundTripTest <MpInt, T>((T)vals.GetValue(t), -1, expectedType);
            }
        }
Пример #6
0
        public void NullableDateTime()
        {
            DateTime?dt = null;

            MsgPackTests.RoundTripTest <MpNull, DateTime?>(dt, 1, MsgPackTypeId.MpNull);

            dt = DateTime.Now;
            MsgPackTests.RoundTripTest <MpDateTime, DateTime?>(dt, 10, MsgPackTypeId.MpFExt8);
        }
Пример #7
0
 public void SignedToUnsigned <T>(bool PreserveType, T value, int expectedLength, MsgPackTypeId expectedType)
 {
     if (PreserveType)
     {
         MsgPackTests.DynamicallyCompactValue = false;
     }
     try {
         MsgPackTests.RoundTripTest <MpInt, T>(value, expectedLength, expectedType);
     } finally {
         MsgPackTests.DynamicallyCompactValue = true;
     }
 }
Пример #8
0
        public void EnumDictionaryUse()
        {
            Dictionary <myEnum, object> objectProps = new Dictionary <myEnum, object>();

            objectProps.Add(myEnum.SomeString, "Hallo!");
            objectProps.Add(myEnum.SomeInt, 5);
            objectProps.Add(myEnum.SomeBool, true);
            objectProps.Add(myEnum.SomeNothing, null);
            objectProps.Add(myEnum.SomeFloat, 3.5f);

            MsgPackItem item = MsgPackTests.RoundTripTest <MpMap, Dictionary <myEnum, object> >(objectProps, 21, MsgPackTypeId.MpMap4);
        }
Пример #9
0
        public void TypicalDictionaryUse()
        {
            Dictionary <string, object> objectProps = new Dictionary <string, object>();

            objectProps.Add("string", "Hallo!");
            objectProps.Add("int", 5);
            objectProps.Add("bool", true);
            objectProps.Add("nothing", null);
            objectProps.Add("float", 3.5f);

            MsgPackItem item = MsgPackTests.RoundTripTest <MpMap, Dictionary <string, object> >(objectProps, 46, MsgPackTypeId.MpMap4);
        }
Пример #10
0
        public void BinaryLengths(int length, int expectedBytes, MsgPackTypeId expedctedType)
        {
            Randomizer rnd = new Randomizer();

            byte[] test = new byte[length];
            rnd.NextBytes(test);
            if (test.Length > 0)
            {
                test[0] = 150; // prevent using implemented extension!
            }
            MsgPackTests.RoundTripTest <MpExt, byte[]>(test, expectedBytes, expedctedType, (sbyte)(rnd.Next(255) - 128));
        }
Пример #11
0
        // [TestCase(0x7FEFFFF9, 0x7FEFFFF9 + 6, MsgPackTypeId.MpArray32)] // Out of memory on my machine
        public void ArrayLengths(int length, int expectedBytes, MsgPackTypeId expedctedType)
        {
            object[] test            = new object[length];
            int      additionalBytes = FillArrayWithRandomNumbers(test);

            additionalBytes -= test.Length;
            MsgPackItem item = MsgPackTests.RoundTripTest <MpArray, object[]>(test, expectedBytes + additionalBytes, expedctedType);

            object[] ret = item.GetTypedValue <object[]>();

            Assert.AreEqual(length, ret.Length, string.Concat("Expected ", length, " items but got ", ret.Length, " items in the array."));
            for (int t = ret.Length - 1; t >= 0; t--)
            {
                Assert.AreEqual(test[t], ret[t], string.Concat("Expected ", test[t], " but got ", ret[t], " at index ", t));
            }
        }
Пример #12
0
        // [TestCase(0x7FEFFFF9, 0x7FEFFFF9 + 6, MsgPackTypeId.MpMap32)] // Out of memory on my machine
        public void MapLengths(int length, int expectedBytes, MsgPackTypeId expedctedType)
        {
            KeyValuePair <object, object>[] test = new KeyValuePair <object, object> [length];
            for (int t = test.Length - 1; t >= 0; t--)
            {
                test[t] = new KeyValuePair <object, object>(null, null);
            }
            int         additionalBytes = test.Length;
            MsgPackItem item            = MsgPackTests.RoundTripTest <MpMap, KeyValuePair <object, object>[]>(test, expectedBytes + additionalBytes, expedctedType);

            KeyValuePair <object, object>[] ret = item.GetTypedValue <KeyValuePair <object, object>[]>();

            Assert.AreEqual(length, ret.Length, string.Concat("Expected ", length, " items but got ", ret.Length, " items in the map."));
            for (int t = ret.Length - 1; t >= 0; t--)
            {
                Assert.AreEqual(test[t], ret[t], string.Concat("Expected ", test[t], " but got ", ret[t], " at index ", t));
            }
        }
Пример #13
0
        public void AssortedMix(int expectedLength)
        {
            KeyValuePair <object, object>[] items = new KeyValuePair <object, object>[] {
                new KeyValuePair <object, object>(true, true),
                new KeyValuePair <object, object>(false, false),
                new KeyValuePair <object, object>(null, null),
                new KeyValuePair <object, object>(int.MinValue, uint.MaxValue),
                new KeyValuePair <object, object>((byte)1, 5.2d),
                new KeyValuePair <object, object>((byte)2, 900.1f),
                new KeyValuePair <object, object>("Hallo!", "Hallo!"),
            };
            MsgPackItem item = MsgPackTests.RoundTripTest <MpMap, KeyValuePair <object, object>[]>(items, expectedLength, MsgPackTypeId.MpMap4);

            KeyValuePair <object, object>[] ret = item.GetTypedValue <KeyValuePair <object, object>[]>();

            Assert.AreEqual(items.Length, ret.Length, string.Concat("Expected ", items.Length, " items but got ", ret.Length, " items in the array."));
            for (int t = ret.Length - 1; t >= 0; t--)
            {
                Assert.AreEqual(items[t], ret[t], string.Concat("Expected ", items[t], " but got ", ret[t], " at index ", t));
            }
        }
Пример #14
0
        private void RoundTripWithLocalAndUniversalTime(DateTime dt, MsgPackTypeId expectedType)
        {
            int expectedSize;

            switch (expectedType)
            {
            case MsgPackTypeId.MpFExt4: expectedSize = 6; break;

            case MsgPackTypeId.MpFExt8: expectedSize = 10; break;

            case MsgPackTypeId.MpExt8: expectedSize = 15; break;

            case MsgPackTypeId.MpNull: expectedSize = 1; break;

            default: throw new NotImplementedException();
            }

            DateTime local = new DateTime(dt.Ticks, DateTimeKind.Local);
            DateTime utc   = new DateTime(dt.Ticks, DateTimeKind.Utc);

            MsgPackTests.RoundTripTest <MpDateTime, DateTime>(utc, expectedSize, expectedType);
            MsgPackTests.RoundTripTest <MpDateTime, DateTime>(local, expectedSize, expectedType);
        }
Пример #15
0
        public void AssortedMix(int expectedLength)
        {
            object[] items = new object[] {
                true,
                false,
                null,
                128,
                -30,
                5.2d,
                900.1f,
                "Hallo!",
                new byte[] { 1, 2, 3 },
                new object[] { true, null, "yes" }
            };
            MsgPackItem item = MsgPackTests.RoundTripTest <MpArray, object[]>(items, expectedLength, MsgPackTypeId.MpArray4);

            object[] ret = item.GetTypedValue <object[]>();

            Assert.AreEqual(items.Length, ret.Length, string.Concat("Expected ", items.Length, " items but got ", ret.Length, " items in the array."));
            for (int t = ret.Length - 1; t >= 0; t--)
            {
                Assert.AreEqual(items[t], ret[t], string.Concat("Expected ", items[t], " but got ", ret[t], " at index ", t));
            }
        }
Пример #16
0
        public void AssortedMix(bool preserveTypes, int expectedLength)
        {
            object[] items = new object[] {
                true,
                false,
                null,
                128,
                -30,
                5.2d,
                900.1f,
                "Hallo!",
                new byte[] { 1, 2, 3 },
                new object[] { true, null, "yes" }
            };
            if (preserveTypes)
            {
                MsgPackTests.DynamicallyCompactValue = false;
            }
            try {
                MsgPackItem item = MsgPackTests.RoundTripTest <MpArray, object[]>(items, expectedLength, MsgPackTypeId.MpArray4);

                object[] ret = item.GetTypedValue <object[]>();

                Assert.AreEqual(items.Length, ret.Length, string.Concat("Expected ", items.Length, " items but got ", ret.Length, " items in the array."));
                for (int t = ret.Length - 1; t >= 0; t--)
                {
                    if (preserveTypes && t != 2)
                    {
                        Assert.IsTrue(items[t].GetType() == ret[t].GetType(), string.Concat("Expected type ", items[t].GetType(), " items but got ", ret[t].GetType(), "."));
                    }
                    Assert.AreEqual(items[t], ret[t], string.Concat("Expected ", items[t], " but got ", ret[t], " at index ", t));
                }
            } finally {
                MsgPackTests.DynamicallyCompactValue = true;
            }
        }
Пример #17
0
 public void RoundTripUInt64(ulong value)
 {
     MsgPackTests.RoundTripTest <MpInt, ulong>(value, 9, MsgPackTypeId.MpULong);
 }
Пример #18
0
 public void RoundTripUInt32(uint value)
 {
     MsgPackTests.RoundTripTest <MpInt, uint>(value, 5, MsgPackTypeId.MpUInt);
 }
Пример #19
0
 public void RoundTripUInt16(ushort value)
 {
     MsgPackTests.RoundTripTest <MpInt, ushort>(value, 3, MsgPackTypeId.MpUShort);
 }
Пример #20
0
 public void RoundTripInt8(sbyte value)
 {
     MsgPackTests.RoundTripTest <MpInt, sbyte>(value, 2, MsgPackTypeId.MpSByte);
 }
Пример #21
0
 public void RoundTripUint8(byte value)
 {
     MsgPackTests.RoundTripTest <MpInt, byte>(value, 2, MsgPackTypeId.MpUByte);
 }
Пример #22
0
 public void RoundTripTestTrue()
 {
     MsgPackTests.RoundTripTest <MpBool, bool>(true, 1, MsgPackTypeId.MpBoolTrue);
 }
Пример #23
0
        // [TestCase(0x7FEFFFF9, 0x7FEFFFF9 + 6, MsgPackTypeId.MpStr32)] // Out of memory on my machine
        public void LongerStrings(int length, int expectedBytes, MsgPackTypeId expedctedType)
        {
            string test = new string(' ', length);

            MsgPackTests.RoundTripTest <MpString, string>(test, expectedBytes, expedctedType);
        }
Пример #24
0
 public void AutoCompactTest <T>(T value, int expectedLength, MsgPackTypeId expectedType)
 {
     MsgPackTests.RoundTripTest <MpInt, T>(value, expectedLength, expectedType);
 }
Пример #25
0
 public void RoundTripFloat64(double value)
 {
     MsgPackTests.RoundTripTest <MpFloat, double>(value, 9, MsgPackTypeId.MpDouble);
 }
Пример #26
0
 public void SignedToUnsigned <T>(T value, int expectedLength, MsgPackTypeId expectedType)
 {
     MsgPackTests.RoundTripTest <MpInt, T>(value, expectedLength, expectedType);
 }
Пример #27
0
 public void RoundTripTest(string value, int expectedBytes, MsgPackTypeId expedctedType)
 {
     MsgPackTests.RoundTripTest <MpString, string>(value, expectedBytes, expedctedType);
 }
Пример #28
0
 public void RoundTripTest()
 {
     MsgPackTests.RoundTripTest <MpNull, Object>(null, 1, MsgPackTypeId.MpNull);
 }
Пример #29
0
 public void RoundTripNegativeFixnum(sbyte value)
 {
     MsgPackTests.RoundTripTest <MpInt, sbyte>(value, 1, MsgPackTypeId.MpBytePart);
 }
Пример #30
0
 public void RoundTripTestFalse()
 {
     MsgPackTests.RoundTripTest <MpBool, bool>(false, 1, MsgPackTypeId.MpBoolFalse);
 }