Example #1
0
        /// <exception cref="System.IO.IOException"></exception>
        private void AssertValidState()
        {
            NUnit.Framework.Assert.AreEqual(data.Length, dataPtr, "test filled example result"
                                            );
            delta = deltaBuf.ToByteArray();
            NUnit.Framework.Assert.AreEqual(@base.Length, BinaryDelta.GetBaseSize(delta));
            NUnit.Framework.Assert.AreEqual(data.Length, BinaryDelta.GetResultSize(delta));
            var appliedDelta = BinaryDelta.Apply(@base, delta);

            Assert.AreEqual(data.Length, appliedDelta.Length);
            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], appliedDelta[i]);
            }

            // Assert that a single bulk read produces the correct result.
            //
            byte[]      act = new byte[data.Length];
            DeltaStream @in = Open();

            NUnit.Framework.Assert.AreEqual(data.Length, @in.GetSize());
            NUnit.Framework.Assert.AreEqual(data.Length, @in.Read(act));
            NUnit.Framework.Assert.AreEqual(-1, @in.Read());
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, act), "bulk read has same content"
                                          );
            // Assert that smaller tiny reads have the same result too.
            //
            act = new byte[data.Length];
            @in = Open();
            int read = 0;

            while (read < data.Length)
            {
                int n = @in.Read(act, read, 128);
                if (n <= 0)
                {
                    break;
                }
                read += n;
            }
            NUnit.Framework.Assert.AreEqual(data.Length, read);
            NUnit.Framework.Assert.AreEqual(-1, @in.Read());
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, act), "small reads have same content"
                                          );
        }
Example #2
0
        public virtual void TestSkip()
        {
            Init(32, 15);
            Copy(2, 2);
            Insert("ab");
            Insert("cd");
            Copy(4, 4);
            Copy(0, 2);
            Insert("efg");
            AssertValidState();
            for (int p = 0; p < data.Length; p++)
            {
                byte[] act = new byte[data.Length];
                System.Array.Copy(data, 0, act, 0, p);
                DeltaStream @in = Open();
                IOUtil.SkipFully(@in, p);
                NUnit.Framework.Assert.AreEqual(data.Length - p, @in.Read(act, p, data.Length - p
                                                                          ));
                NUnit.Framework.Assert.AreEqual(-1, @in.Read());
                NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, act), "skipping " + p);
            }
            // Skip all the way to the end should still recognize EOF.
            DeltaStream in_1 = Open();

            IOUtil.SkipFully(in_1, data.Length);
            NUnit.Framework.Assert.AreEqual(-1, in_1.Read());
            NUnit.Framework.Assert.AreEqual(0, in_1.Skip(1));
            // Skip should not open the base as we move past it, but it
            // will open when we need to start copying data from it.
            bool[] opened = new bool[1];
            in_1 = new _DeltaStream_180(this, opened, new ByteArrayInputStream(delta));
            IOUtil.SkipFully(in_1, 7);
            NUnit.Framework.Assert.IsFalse(opened[0], "not yet open");
            NUnit.Framework.Assert.AreEqual(data[7], in_1.Read());
            NUnit.Framework.Assert.IsTrue(opened[0], "now open");
        }