public unsafe void DecimalRead()
        {
            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        writer.Write(count * 12347822345.34m);
                    }

                data = ms.ToArray();
            }

            fixed(byte *pData = data)
            {
                BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length);

                for (int count = 0; count < 256; count++)
                {
                    Assert.AreEqual(reader.ReadDecimal(), count * 12347822345.34m, "UnsafeBinaryMemoryReader Decimal incompatible to BinaryWriter.");
                }
            }
        }
        public unsafe void DecimalLimits()
        {
            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                    writer.Write(2873645.2345m);

                data = ms.ToArray();
            }

            fixed(byte *pData = data)
            {
                BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length - 1);

                try
                {
                    reader.ReadDecimal();

                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }
                catch (OutOfMemoryException) { }
                catch (Exception)
                {
                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }

                BinaryMemoryWriter writer = new BinaryMemoryWriter(pData, data.Length - 1);

                try
                {
                    writer.Write(2873645.2345m);

                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }
                catch (OutOfMemoryException) { }
                catch (Exception)
                {
                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }
            }
        }
Beispiel #3
0
        public unsafe void DecimalLimits()
        {
            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                    writer.Write(1827364.2134324m);

                data = ms.ToArray();
            }

            fixed(byte *pData = data)
            {
                BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length);

                try
                {
                    reader.ReadDecimal();
                }
                catch
                {
                    Assert.Fail("Should not have thrown an Exception.");
                }

                BinaryMemoryWriter writer = new BinaryMemoryWriter(pData, data.Length);

                try
                {
                    writer.Write(1827364.2134324m);
                }
                catch
                {
                    Assert.Fail("Should not have thrown an Exception.");
                }
            }
        }