Exemplo n.º 1
0
        static void SafeTest()
        {
            System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]);
            StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.OpenOrCreate);
            Ar = new StreamCollection <TestClass>(System.IO.File.Open(Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate));
s:

            var Role = random.Next(0, 5);

            switch (Role)
            {
            case 0:
            {
                var Pos  = random.Next(0, Ar.Length);
                var Data = new TestClass()
                {
                    Bytes = new byte[random.Next(0, 50)]
                };
                Data.count = Data.Bytes.Length;
                StreamLoger.run(() => {
                        Ar.Insert(Data, Pos);
                        var OldData = Ar[Pos];
                        if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length)
                        {
                            throw new Exception();
                        }
                    });
            }
            break;

            case 1:
                if (Ar.Length > 0)
                {
                    var Pos  = random.Next(0, Ar.Length - 1);
                    var Data = new TestClass()
                    {
                        Bytes = new byte[random.Next(0, 50)]
                    };
                    Data.count = Data.Bytes.Length;
                    StreamLoger.run(() =>
                    {
                        Ar[Pos]     = Data;
                        var OldData = Ar[Pos];
                        if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length)
                        {
                            throw new Exception();
                        }
                    });
                }
                break;

            case 2:
                if (Ar.Length > 0)
                {
                    var Pos = random.Next(0, Ar.Length);
                    StreamLoger.run(() =>
                    {
                        var InnerData = Ar[Pos];
                    });
                }
                break;

            case 3:
                if (Ar.Length > 0)
                {
                    var Pos = random.Next(0, Ar.Length - 1);
                    StreamLoger.run(() =>
                    {
                        Ar.DeleteByPosition(Pos);
                    });
                }
                break;

            case 4:
                StreamLoger.run(() =>
                {
                    var newar = Ar.Serialize().Deserialize(Ar);
                    //newar.Info.Browse(newar);
                });
                break;
            }
            goto s;
        }
Exemplo n.º 2
0
        static void SafeTest()
        {
            System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]);
            StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.OpenOrCreate);

s:

            var Role = random.Next(0, 3);

            switch (Role)
            {
            case 0:
            {
                var Pos  = random.Next(0, Ar_Check.Length);
                var Data = random.Next(int.MinValue, int.MaxValue).ToString();
                StreamLoger.run(() =>
                    {
                        Ar_Check.Insert(Data, Pos);
                        Insert(ref Ar_True, Data, Pos);
                        if (Ar_Check.Length != Ar_True.Length)
                        {
                            throw new Exception();
                        }
                        DebugAr();
                    });
            }
            break;

            case 1:
                if (Ar_Check.Length > 0)
                {
                    var Pos  = random.Next(0, Ar_Check.Length - 1);
                    var Data = random.Next(int.MinValue, int.MaxValue).ToString();
                    StreamLoger.run(() =>
                    {
                        Ar_Check[Pos] = Data;
                        Ar_True[Pos]  = Data;
                        DebugAr();
                    });
                }
                break;

            case 2:
                if (Ar_Check.Length > 0)
                {
                    var Pos = random.Next(0, Ar_Check.Length - 1);
                    StreamLoger.run(() =>
                    {
                        Ar_Check.DeleteByPosition(Pos);
                        DeleteByPosition(ref Ar_True, Pos);
                        if (Ar_Check.Length != Ar_True.Length)
                        {
                            throw new Exception();
                        }
                        DebugAr();
                    });
                }
                break;
            }
            goto s;
        }
Exemplo n.º 3
0
        static void SafeTestBinary()
        {
            System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]);
            StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.OpenOrCreate);

s:

            var Role = random.Next(0, 3);

            switch (Role)
            {
            case 0:
            {
                var Data = random.Next(int.MinValue, int.MaxValue).ToString();
                StreamLoger.run(() =>
                    {
                        var LastLen = Ar_Check.Length;
                        Ar_Check.BinaryInsert(Data);
                        BinaryInsert(ref Ar_True, Data);
                        if (Ar_Check.Length != LastLen + 1)
                        {
                            throw new Exception();
                        }
                        DebugAr();
                    });
            }
            break;

            case 1:
                if (Ar_Check.Length > 0)
                {
                    var Pos = random.Next(0, Ar_Check.Length - 1);
                    StreamLoger.run(() =>
                    {
                        var LastLen = Ar_Check.Length;
                        Ar_Check.BinaryDelete(Ar_Check[Pos]);
                        BinaryDelete(ref Ar_True, Ar_True[Pos]);
                        if (Ar_Check.Length != LastLen - 1)
                        {
                            throw new Exception();
                        }
                        DebugAr();
                    });
                }
                break;

            case 2:
                if (Ar_Check.Length > 0)
                {
                    var Pos = random.Next(0, Ar_Check.Length - 1);
                    StreamLoger.run(() =>
                    {
                        var LastLen  = Ar_Check.Length;
                        var CheckPos = Ar_Check.BinarySearch(Ar_Check[Pos]);
                        var TruePos  = System.Array.BinarySearch(Ar_True, Ar_True[Pos]);
                        if (CheckPos.Index != TruePos)
                        {
                            throw new Exception();
                        }
                        if (CheckPos.Value != Ar_True[Pos])
                        {
                            throw new Exception();
                        }
                        DebugAr();
                    });
                }
                break;
            }
            goto s;
        }