Beispiel #1
0
        public void Split_Tripple()
        {
            byte[] what = { 0, 0, 1, 2, 3, 5, 6, 7, 1, 2, 5, 0, 0, 1, 2, 4, 5 };

            foreach (var bufSize in BUF_SIZES)
            {
                using (var ms = new MemoryStream(what))
                {
                    int i = 0;
                    foreach (var segment in StreamHelpers.StreamSplitNew(ms, new byte[] { 1, 2 }, bufSize))
                    {
                        if (i == 0)
                        {
                            Assert.IsTrue((new byte[] { 3, 5, 6, 7 }).SequenceEqual(segment.Item1.Take(segment.Item2)));
                        }
                        else if (i == 0)
                        {
                            Assert.IsTrue((new byte[] { 5, 0, 0 }).SequenceEqual(segment.Item1.Take(segment.Item2)));
                        }
                        i++;
                    }
                    Assert.AreEqual(2, i);
                }
            }
        }
Beispiel #2
0
        public void BytesSplitNew_MatchMiddle()
        {
            byte[] what     = { 0, 1, 2, 3, 4, 5 };
            var    segments = StreamHelpers.BytesSplitNew(what, what.Length, new byte[] { 3 }).ToArray();

            Assert.AreEqual(0, segments.Length);
        }
Beispiel #3
0
        public void BytesSplitNew_MatchFinish_ReturnOuter()
        {
            byte[] what     = { 0, 1, 2, 3, 4, 5 };
            var    segments = StreamHelpers.BytesSplitNew(what, what.Length, new byte[] { 5 }, true).ToArray();

            Assert.AreEqual(1, segments.Length);
            Assert.IsTrue((new byte[] { 0, 1, 2, 3, 4 }).SequenceEqual(what.Skip(segments[0].Item1).Take(segments[0].Item2)));
        }
Beispiel #4
0
        public void BytesSplitNew_DoubleBy()
        {
            byte[] what     = { 1, 2, 3, 4, 1, 2 };
            var    segments = StreamHelpers.BytesSplitNew(what, what.Length, new byte[] { 1, 2 }).ToArray();

            Assert.AreEqual(1, segments.Length);
            Assert.IsTrue((new byte[] { 3, 4 }).SequenceEqual(what.Skip(segments[0].Item1).Take(segments[0].Item2)));
        }
Beispiel #5
0
 public void CopyTo_Multi2Multi()
 {
     using (MemoryStream src = new MemoryStream(new byte[] { 0, 1, 2, 3 }), dst = new MemoryStream())
     {
         StreamHelpers.CopyTo(src, dst, 0, 4);
         Assert.AreEqual(4, dst.Length);
     }
 }
Beispiel #6
0
 public void CopyTo_Single2Single()
 {
     using (MemoryStream src = new MemoryStream(new byte[] { 0 }), dst = new MemoryStream())
     {
         StreamHelpers.CopyTo(src, dst, 0, 0);
         Assert.AreEqual(1, dst.Length);
     }
 }
Beispiel #7
0
 public void CopyTo_SingleWithEmptyLength()
 {
     using (MemoryStream src = new MemoryStream(new byte[] { 0 }), dst = new MemoryStream())
     {
         StreamHelpers.CopyTo(src, dst, 0, -1);
         Assert.AreEqual(0, dst.Length);
     }
 }
Beispiel #8
0
 public void CopyTo_Empty2Empty()
 {
     using (MemoryStream src = new MemoryStream(), dst = new MemoryStream())
     {
         StreamHelpers.CopyTo(src, dst, 0, src.Length);
         Assert.AreEqual(0, dst.Length);
     }
 }
Beispiel #9
0
        public void FindIndex_EmptyWhat()
        {
            byte[] where = { 0 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);
        }
Beispiel #10
0
        public void FindIndex_WhatIsLonger()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 1, where.Length - 1, new byte[] { 0, 1, 2, 3, 4, 5, 6 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);
        }
Beispiel #11
0
 public Tuple <long, long>[] split(byte[] what, byte[] by,
                                   long whatFirst = 0, long?whatLast = null, long byFirst = 0, long?byLast = null, int seekBuffSize = 1)
 {
     using (var stream = new MemoryStream(what))
     {
         var res = StreamHelpers.Split(stream, by, whatFirst, whatLast, byFirst, byLast, seekBuffSize).ToArray();
         return(res);
     }
 }
Beispiel #12
0
        public void FindIndex_IdxFinishBy1()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5, 0 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 1, where.Length - 1, new byte[] { 0 });
            Assert.AreEqual(6, whatIdx);
        }
Beispiel #13
0
 public long find(byte[] where, byte[] what,
                  long whereFirst = 0, long?whereLast = null, long whatFirst = 0, long?whatLast = null, int seekBuffSize = 1)
 {
     using (var stream = new MemoryStream(where))
     {
         long pos = StreamHelpers.Find(stream, what, whereFirst, whereLast, whatFirst, whatLast, seekBuffSize);
         return(pos);
     }
 }
Beispiel #14
0
 public void CopyTo_MultiWithFirstLast()
 {
     using (MemoryStream src = new MemoryStream(new byte[] { 0, 1, 2, 3, 5 }), dst = new MemoryStream())
     {
         StreamHelpers.CopyTo(src, dst, 1, 3);
         Assert.AreEqual(3, dst.Length);
         Assert.AreEqual(1, dst.GetBuffer()[0]);
         Assert.AreEqual(2, dst.GetBuffer()[1]);
         Assert.AreEqual(3, dst.GetBuffer()[2]);
     }
 }
Beispiel #15
0
        public void Split_EmptyInARow()
        {
            byte[] what = { 0, 1, 2, 0, 1, 2 };

            foreach (var bufSize in BUF_SIZES)
            {
                using (var ms = new MemoryStream(what))
                {
                    var segments = StreamHelpers.StreamSplitNew(ms, new byte[] { 0, 1, 2 }, bufSize).ToArray();
                    Assert.AreEqual(0, segments.Length);
                }
            }
        }
Beispiel #16
0
        public void Split_Double2()
        {
            byte[] what = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 1, 2 };

            foreach (var bufSize in BUF_SIZES)
            {
                using (var ms = new MemoryStream(what))
                {
                    var segments = StreamHelpers.StreamSplitNew(ms, new byte[] { 0, 1, 2 }, bufSize).ToArray();
                    Assert.AreEqual(1, segments.Length);
                    Assert.IsTrue((new byte[] { 3, 4, 5, 0, 0, 0 }).SequenceEqual(segments[0].Item1.Take(segments[0].Item2)));
                }
            }
        }
Beispiel #17
0
        public void FindIndex_IdxStart()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 0 });
            Assert.AreEqual(0, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 0, 1 });
            Assert.AreEqual(0, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 0, 1, 2, 3, 4, 5 });
            Assert.AreEqual(0, whatIdx);
        }
Beispiel #18
0
        public void FindIndex_IdxNotFound()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 6 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 0, 0 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 1, 2, 3, 3 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);
        }
Beispiel #19
0
        public void FindIndex_IdxFinish()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 5 });
            Assert.AreEqual(5, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 4, 5 });
            Assert.AreEqual(4, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 3, 4, 5 });
            Assert.AreEqual(3, whatIdx);
        }
Beispiel #20
0
        public void FindIndex_IdxMiddle()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 1 });
            Assert.AreEqual(1, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 2, 3 });
            Assert.AreEqual(2, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length, new byte[] { 2, 3, 4 });
            Assert.AreEqual(2, whatIdx);
        }
Beispiel #21
0
        public void CopyTo_MultiWithFirstLast2NonEmpty()
        {
            var dstBytes = new byte[] { 6, 7, 8, 9, 10, 11 };

            using (MemoryStream src = new MemoryStream(new byte[] { 0, 1, 2, 3, 4 }), dst = new MemoryStream(dstBytes))
            {
                StreamHelpers.CopyTo(src, dst, 1, 4);
                Assert.AreEqual(6, dst.Length);
                Assert.AreEqual(1, dstBytes[0]);
                Assert.AreEqual(2, dstBytes[1]);
                Assert.AreEqual(3, dstBytes[2]);
                Assert.AreEqual(4, dstBytes[3]);
                Assert.AreEqual(10, dstBytes[4]);
                Assert.AreEqual(11, dstBytes[5]);
            }
        }
Beispiel #22
0
        public void Split_Single1()
        {
            byte[] what = { 0, 1, 0, 3, 4, 5 };

            foreach (var bufSize in BUF_SIZES)
            {
                using (var ms = new MemoryStream(what))
                {
                    int i = 0;
                    foreach (var segment in StreamHelpers.StreamSplitNew(ms, new byte[] { 0 }, 30))
                    {
                        if (i == 0)
                        {
                            Assert.IsTrue((new byte[] { 1 }).SequenceEqual(segment.Item1.Take(segment.Item2)));
                        }
                        i++;
                    }
                    Assert.AreEqual(1, i);
                }
            }
        }
Beispiel #23
0
        public void Split_RepeatingByPrefix()
        {
            byte[] what = { 0, 0, 0, 0, 1, 2, (byte)'a', (byte)'b', (byte)'c', (byte)'a', 0, 0, 0, 0, 1, 2 };

            foreach (var bufSize in BUF_SIZES)
            {
                using (var ms = new MemoryStream(what))
                {
                    int i = 0;
                    foreach (var segment in StreamHelpers.StreamSplitNew(ms, new byte[] { 0, 0, 0, 1, 2 }, bufSize))
                    {
                        if (i == 0)
                        {
                            Assert.IsTrue((new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'a', 0 }).SequenceEqual(segment.Item1.Take(segment.Item2)));
                        }

                        i++;
                    }
                    Assert.AreEqual(1, i);
                }
            }
        }
Beispiel #24
0
        public void FindIndex_WhereBoundary()
        {
            byte[] where = { 0, 1, 2, 3, 4, 5 };

            int whatIdx;

            whatIdx = StreamHelpers.FindIndex(where, 1, where.Length - 1, new byte[] { 0, 1 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 1, where.Length - 1, new byte[] { 1, 2, 3 });
            Assert.AreEqual(1, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 2, where.Length - 2, new byte[] { 1, 2, 3 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length - 2, new byte[] { 1, 2, 3 });
            Assert.AreEqual(1, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 0, where.Length - 3, new byte[] { 1, 2, 3 });
            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);

            whatIdx = StreamHelpers.FindIndex(where, 2, where.Length - 1, new byte[] { 2, 3, 4 });
            Assert.AreEqual(2, whatIdx);
        }
Beispiel #25
0
 public void FindIndex_ErrorNullWhere()
 {
     StreamHelpers.FindIndex(new byte[] { }, 0, 0, null);
 }
Beispiel #26
0
        public void BytesSplitNew_NullWhat()
        {
            var segments = StreamHelpers.BytesSplitNew((byte[])null, 0, new byte[] {}).ToArray();

            Assert.AreEqual(0, segments.Length);
        }
Beispiel #27
0
        public void FindIndex_ErrorNullWhat()
        {
            int whatIdx = StreamHelpers.FindIndex((byte[])null, 0, 0, new byte[] { });

            Assert.AreEqual(StreamHelpers.NOT_FOUND_POS, whatIdx);
        }
Beispiel #28
0
        public void BytesSplitNew_NullBy()
        {
            byte[] what = { 0, 1, 2, 3, 4, 5 };

            var segments = StreamHelpers.BytesSplitNew(what, what.Length, null).ToArray();
        }