예제 #1
0
파일: Tests.cs 프로젝트: Grille/BinaryView
    public static void Run()
    {
        stream = new MemoryStream();
        bw     = new BinaryViewWriter(stream);
        br     = new BinaryViewReader(stream);

        TUtils.WriteTitle("Run tests...\n");

        TUtils.WriteTitle("test types");
        testTyp(bw.WriteBoolean, br.ReadBoolean, false, true);
        testTyp(bw.WriteChar, br.ReadChar, char.MinValue, char.MaxValue);
        testTyp(bw.WriteByte, br.ReadByte, byte.MinValue, byte.MaxValue);
        testTyp(bw.WriteSByte, br.ReadSByte, sbyte.MinValue, sbyte.MaxValue);
        testTyp(bw.WriteUInt16, br.ReadUInt16, ushort.MinValue, ushort.MaxValue);
        testTyp(bw.WriteInt16, br.ReadInt16, short.MinValue, short.MaxValue);
        testTyp(bw.WriteUInt32, br.ReadUInt32, uint.MinValue, uint.MaxValue);
        testTyp(bw.WriteInt32, br.ReadInt32, int.MinValue, int.MaxValue);
        testTyp(bw.WriteUInt64, br.ReadUInt64, ulong.MinValue, ulong.MaxValue);
        testTyp(bw.WriteInt64, br.ReadInt64, long.MinValue, long.MaxValue);
        testTyp(bw.WriteSingle, br.ReadSingle, float.MinValue, float.MaxValue);
        testTyp(bw.WriteDouble, br.ReadDouble, double.MinValue, double.MaxValue);
        testTyp(bw.WriteDecimal, br.ReadDecimal, decimal.MinValue, decimal.MaxValue);

        TUtils.WriteTitle("test string");
        testString("TestString123", LengthPrefix.Default, CharSizePrefix.Default);
        testString("TestString123", LengthPrefix.Byte, CharSizePrefix.Byte);
        testString("TestString123", LengthPrefix.UInt32, CharSizePrefix.Char);
        testString("Ä'*Ü-.,><%§ÃoÜ╝ô○╝+");

        TUtils.WriteTitle("test unmanaged types");
        testGTyp(false, true);
        testGTyp(char.MinValue, char.MaxValue);
        testGTyp(byte.MinValue, byte.MaxValue);
        testGTyp(sbyte.MinValue, sbyte.MaxValue);
        testGTyp(ushort.MinValue, ushort.MaxValue);
        testGTyp(short.MinValue, short.MaxValue);
        testGTyp(uint.MinValue, uint.MaxValue);
        testGTyp(int.MinValue, int.MaxValue);
        testGTyp(ulong.MinValue, ulong.MaxValue);
        testGTyp(long.MinValue, long.MaxValue);
        testGTyp(float.MinValue, float.MaxValue);
        testGTyp(double.MinValue, double.MaxValue);
        testGTyp(decimal.MinValue, decimal.MaxValue);
        testGTyp(new TUtils.Struct()
        {
            A = 42, B = 3.6f
        });
        testGTyp(new DateTime(2020, 07, 20, 15, 54, 24));
        testGTyp(new Point(10, 42));
        testGTyp(new RectangleF(10, 42, 25.5f, 23));

        TUtils.WriteTitle("test serializable types");
        testSTyp(42);
        testSTyp("Hello World");
        testSTyp(new DateTime(2000, 10, 20));
        testSTyp(new DateTime(2020, 07, 20, 15, 54, 24));
        testSTyp(new Point(2000, 10));
        testSTyp(new RectangleF(10, 42, 25.5f, 23));

        TUtils.WriteTitle("test arrays");
        testGArray(new byte[] { 0, 2, 4, 6 });
        testGArray(new byte[] { 0, 2, 4, 6 }, LengthPrefix.Int64);
        testGArray(new int[] { 0, -2, 4, -6 });
        testGArray(new float[] { 0, -2.5f, 4.25f, -6.66f });
        testGArray(new TUtils.Struct[] { new TUtils.Struct()
                                         {
                                             A = 42, B = 3.6f
                                         }, new TUtils.Struct()
                                         {
                                             A = 36, B = 1.666f
                                         } });
        testArray(bw.WriteStringArray, br.ReadStringArray, new string[] { "ab", "cd", "ef", "gh" });

        TUtils.WriteTitle("test IList");
        testLists();

        TUtils.WriteTitle("test compresion");
        testCompression();

        TUtils.WriteTitle("test map");
        testMap(64, false);

        TUtils.WriteTitle("test map compressed");
        testMap(64, true);

        TUtils.WriteTitle("test speed");
        testSpeed();

        TUtils.WriteResults();
    }