Exemplo n.º 1
0
        public void Applying_diff_calculated_as_new_multiple_times()
        {
            const int size = 4096;

            var fst = new byte[size];
            var sec = new byte[size];

            var r = new Random(1);

            for (int i = 0; i < 10; i++)
            {
                fst[i] = (byte)r.Next(0, 255);
                sec[(size - 1) - i] = (byte)r.Next(0, 255);
            }

            var result = new byte[size];

            foreach (var page in new[] { fst, sec })
            {
                fixed(byte *ptr = page)
                fixed(byte *diffPtr   = new byte[size])
                fixed(byte *resultPtr = result)
                {
                    var diffPages = new DiffPages
                    {
                        Output = diffPtr,
                    };

                    diffPages.ComputeNew(ptr, size);

                    Assert.True(diffPages.IsDiff);

                    new DiffApplier
                    {
                        Destination = resultPtr,
                        Diff        = diffPtr,
                        Size        = page.Length,
                        DiffSize    = diffPages.OutputSize
                    }.Apply(true);
                }
            }

            Assert.Equal(sec, result);
        }
Exemplo n.º 2
0
        public void CanComputeSmallDifferenceFromNew()
        {
            var fst = new byte[4096];


            fst[12]++;
            fst[433]++;

            fixed(byte *one = fst)
            fixed(byte *tmp = new byte[4096])
            {
                var diffPages = new DiffPages
                {
                    Output = tmp,
                };

                diffPages.ComputeNew(one, 4096);

                Assert.Equal(96, diffPages.OutputSize);
            }
        }