Esempio n. 1
0
        public void KnownScalarsVariantHeader()
        {
            TestType <sbyte>(TypeEnum.Int8);
            TestType <short>(TypeEnum.Int16);
            TestType <int>(TypeEnum.Int32);
            TestType <long>(TypeEnum.Int64);

            TestType <byte>(TypeEnum.UInt8);
            TestType <ushort>(TypeEnum.UInt16);
            TestType <uint>(TypeEnum.UInt32);
            TestType <ulong>(TypeEnum.UInt64);

            TestType <float>(TypeEnum.Float32);
            TestType <double>(TypeEnum.Float64);

            TestType <decimal>(TypeEnum.Decimal);
            TestType <SmallDecimal>(TypeEnum.SmallDecimal);

            TestType <bool>(TypeEnum.Bool);
            TestType <char>(TypeEnum.Utf16Char);
            TestType <UUID>(TypeEnum.UUID);

            TestType <DateTime>(TypeEnum.DateTime);
            TestType <Timestamp>(TypeEnum.Timestamp);

            TestType <Symbol>(TypeEnum.Symbol);
            TestType <Symbol32>(TypeEnum.Symbol32);
            TestType <Symbol64>(TypeEnum.Symbol64);
            TestType <Symbol128>(TypeEnum.Symbol128);
            TestType <Symbol256>(TypeEnum.Symbol256);

            void TestType <T>(TypeEnum expectedTe)
            {
                var h = TypeEnumHelper <T> .DataTypeHeader;

                Assert.AreEqual(expectedTe, h.TEOFS.TypeEnum);
                Assert.IsTrue(h.TEOFS1 == default && h.TEOFS2 == default);
                Assert.IsTrue(h.IsScalar);

                var teofs = new TypeEnumOrFixedSize(expectedTe);

                Assert.AreEqual(BinarySerializer.SizeOf <T>(default(T), out _, SerializationFormat.Binary), DataTypeHeader.Size + teofs.Size);

                Assert.AreEqual(Unsafe.SizeOf <T>(), h.TEOFS.Size);
                Assert.AreEqual(Unsafe.SizeOf <T>(), TypeEnumHelper <T> .FixedSize);
                if (typeof(T) != typeof(DateTime))
                {
                    Assert.AreEqual(TypeHelper <T> .PinnedSize, TypeEnumHelper <T> .FixedSize);
                }
            }
        }
Esempio n. 2
0
        public void CouldGetUnknownFixedSize()
        {
            for (int i = 1; i <= 128; i++)
            {
                var te = new TypeEnumOrFixedSize((byte)i);
                Assert.AreEqual(i, te.Size);
            }

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var _ = new TypeEnumOrFixedSize((byte)0);
            });

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var _ = new TypeEnumOrFixedSize((byte)129);
            });
        }