Пример #1
0
        public void WriteEnumTest()
        {
            TestHelper.TestingEnumType[] testEnums = new TestHelper.TestingEnumType[]
            {
                TestHelper.TestingEnumType.EqualTo,
                TestHelper.TestingEnumType.EvenLess,
                TestHelper.TestingEnumType.GreaterThan,
                TestHelper.TestingEnumType.LessThan
            };

            // prepare test buffer
            // Enum         Test value      Encoded As     Encoded Bytes
            //EqualTo       0               0              00000011
            //EvenLess      -2147483648     4294967295     11111111 11111111 11111111 11111111 00001111
            //GreaterThan   1               2              00000010
            //LessThan      -1              1              00000001
            byte[] expected =
            {
                0x00,
                0xFF, 0xFF, 0xFF, 0xFF, 0x0F,
                0x02,
                0x01
            };

            System.IO.MemoryStream output = new System.IO.MemoryStream();
            BinaryWriter           writer = new BinaryWriter(output, BinaryWriterTest.CannedVersion);

            foreach (TestHelper.TestingEnumType e in testEnums)
            {
                writer.Write <TestHelper.TestingEnumType>(string.Empty, e);
            }

            TestHelper.AssertCollectionEquals <byte>(expected, output.ToArray());
        }
Пример #2
0
        public void TotalEnumRoundTripTest()
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();

            BinaryWriter writer = new BinaryWriter(stream, RoundtripTest.CannedVersion);

            TestHelper.TestingEnumType[] Expected = TestHelper.GetEnumValues <TestHelper.TestingEnumType>();

            foreach (var item in Expected)
            {
                writer.Write <TestHelper.TestingEnumType>(string.Empty, item);
            }

            stream.Seek(0L, System.IO.SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream, RoundtripTest.CannedVersion);

            TestHelper.TestingEnumType[] actual = new TestHelper.TestingEnumType[Expected.Length];

            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = reader.ReadEnum <TestHelper.TestingEnumType>(string.Empty);
            }

            TestHelper.AssertCollectionEquals <TestHelper.TestingEnumType>(Expected, actual);
        }