Ejemplo n.º 1
0
        public void EnumBitStreamer_TestNoneSentinelEncoding()
        {
            const int k_bit_count = 32;

            using (var ms = new System.IO.MemoryStream())
                using (var s = new IO.BitStream(ms))
                {
                    const NoneSentinelEncodedEnum kExpectedValue = NoneSentinelEncodedEnum.Three;
                    var value = kExpectedValue;

                    s.StreamMode = System.IO.FileAccess.Write;
                    NoneSentinelEncodedEnumStreamer.Stream(s, ref value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    NoneSentinelEncodedEnumStreamer.Stream(s, ref value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);

                    //////////////////////////////////////////////////////////////////////////
                    // Test the instance interface
                    var streamer_instance = NoneSentinelEncodedEnumStreamer.Instance;
                    s.SeekToStart();

                    s.StreamMode = System.IO.FileAccess.Write;
                    streamer_instance.Stream(s, ref value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    streamer_instance.Stream(s, ref value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);
                }
        }
Ejemplo n.º 2
0
        public void Enum_BitStreamerUpCastTest()
        {
            const int k_bit_count = 64;

            using (var ms = new System.IO.MemoryStream())
                using (var s = new IO.BitStream(ms))
                {
                    const System.TypeCode kExpectedValue = System.TypeCode.String;
                    var value = kExpectedValue;

                    s.StreamMode = System.IO.FileAccess.Write;
                    TypeCodeStreamer64.Write(s, value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    TypeCodeStreamer64.Read(s, out value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);

                    //////////////////////////////////////////////////////////////////////////
                    // Test the instance interface
                    var streamer_instance = TypeCodeStreamer64.Instance;
                    s.SeekToStart();

                    s.StreamMode = System.IO.FileAccess.Write;
                    streamer_instance.Write(s, value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    streamer_instance.Read(s, out value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);
                }
        }
Ejemplo n.º 3
0
        public void Enum_BitStreamerUsingUnderlyingTypeTest()
        {
            const int k_bit_count = 32;

            using (var ms = new System.IO.MemoryStream())
                using (var s = new IO.BitStream(ms))
                {
                    const EnumBinaryStreamerTest.UInt32Enum kExpectedValue = EnumBinaryStreamerTest.UInt32Enum.DeadBeef;
                    var value = kExpectedValue;

                    s.StreamMode = System.IO.FileAccess.Write;
                    UInt32EnumStreamer.Write(s, value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    UInt32EnumStreamer.Read(s, out value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);

                    //////////////////////////////////////////////////////////////////////////
                    // Test the instance interface
                    var streamer_instance = UInt32EnumStreamer.Instance;
                    s.SeekToStart();

                    s.StreamMode = System.IO.FileAccess.Write;
                    streamer_instance.Write(s, value, k_bit_count);
                    s.Flush(); s.SeekToStart();
                    s.StreamMode = System.IO.FileAccess.Read;
                    streamer_instance.Read(s, out value, k_bit_count);

                    Assert.AreEqual(kExpectedValue, value);
                }
        }