Example #1
0
        public void TestZap()
        {
            BlockListImpl list = new BlockListImpl();

            // verify that you can zap anything
            for (int j = -2; j < 10; j++)
            {
                list.Zap(j);
            }
            RawDataBlock[] blocks = new RawDataBlock[5];

            for (int j = 0; j < 5; j++)
            {
                blocks[j] =
                    new RawDataBlock(new MemoryStream(new byte[512]));
            }
            ListManagedBlock[] tmp = (ListManagedBlock[])blocks;

            list.SetBlocks(tmp);
            for (int j = -2; j < 10; j++)
            {
                list.Zap(j);
            }

            // verify that all blocks are gone
            for (int j = 0; j < 5; j++)
            {
                try
                {
                    list.Remove(j);
                    Assert.Fail("removing item " + j + " should not have succeeded");
                }
                catch (IOException )
                {
                }
            }
        }
Example #2
0
        public void TestRemove()
        {
            BlockListImpl list = new BlockListImpl();
            RawDataBlock[] blocks = new RawDataBlock[5];
            byte[] data = new byte[512 * 5];

            for (int j = 0; j < 5; j++)
            {
                for (int k = j * 512; k < (j * 512) + 512; k++)
                {
                    data[k] = (byte)j;
                }
            }
            MemoryStream stream = new MemoryStream(data);

            for (int j = 0; j < 5; j++)
            {
                blocks[j] = new RawDataBlock(stream);
            }
            ListManagedBlock[] tmp = (ListManagedBlock[])blocks;
            list.SetBlocks(tmp);

            // verify that you can't Remove illegal indices
            for (int j = -2; j < 10; j++)
            {
                if ((j < 0) || (j >= 5))
                {
                    try
                    {
                        list.Remove(j);
                        Assert.Fail("removing item " + j + " should have Assert.Failed");
                    }
                    catch (IOException )
                    {
                    }
                }
            }

            // verify we can safely and correctly Remove all blocks
            for (int j = 0; j < 5; j++)
            {
                byte[] outPut = list.Remove(j).Data;

                for (int k = 0; k < 512; k++)
                {
                    Assert.AreEqual(data[(j * 512) + k], outPut[k], "testing block " + j + ", index " + k);
                }
            }

            // verify that all blocks are gone
            for (int j = 0; j < 5; j++)
            {
                try
                {
                    list.Remove(j);
                    Assert.Fail("removing item " + j + " should not have succeeded");
                }
                catch (IOException )
                {
                }
            }
        }