public void TestNotEmpty()
        {
            MemoryStream xvaStream = new MemoryStream();
            VirtualMachineBuilder vmb = new VirtualMachineBuilder();

            MemoryStream ms = new MemoryStream();
            for (int i = 0; i < 1024 * 1024; ++i)
            {
                ms.Position = i * 10;
                ms.WriteByte((byte)(i ^ (i >> 8) ^ (i >> 16) ^ (i >> 24)));
            }

            vmb.AddDisk("Foo", ms, Ownership.Dispose);
            vmb.Build(xvaStream);

            Assert.AreNotEqual(0, xvaStream.Length);

            VirtualMachine vm = new VirtualMachine(xvaStream);
            List<Disk> disks = new List<Disk>(vm.Disks);
            Assert.AreEqual(1, disks.Count);
            Assert.AreEqual(10 * 1024 * 1024, disks[0].Capacity);

            Stream diskContent = disks[0].Content;
            for (int i = 0; i < 1024 * 1024; ++i)
            {
                diskContent.Position = i * 10;
                if ((byte)(i ^ (i >> 8) ^ (i >> 16) ^ (i >> 24)) != diskContent.ReadByte())
                {
                    Assert.Fail("Mismatch at offset " + i);
                }
            }
        }
예제 #2
0
 internal Disk(VirtualMachine vm, string id, string displayname, string location, long capacity)
 {
     _vm = vm;
     _id = id;
     _displayName = displayname;
     _location = location;
     _capacity = capacity;
 }
        public void TestEmpty()
        {
            MemoryStream xvaStream = new MemoryStream();
            VirtualMachineBuilder vmb = new VirtualMachineBuilder();
            vmb.AddDisk("Foo", new MemoryStream(), Ownership.Dispose);
            vmb.Build(xvaStream);

            Assert.AreNotEqual(0, xvaStream.Length);

            VirtualMachine vm = new VirtualMachine(xvaStream);
            List<Disk> disks = new List<Disk>(vm.Disks);
            Assert.AreEqual(1, disks.Count);
            Assert.AreEqual(0, disks[0].Capacity);
        }
예제 #4
0
        public override VirtualDisk OpenDisk(FileLocator locator, string path, string extraInfo, Dictionary<string, string> parameters, FileAccess access)
        {
            VirtualMachine machine = new VirtualMachine(locator.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), Ownership.Dispose);

            int diskIndex;
            if (!int.TryParse(extraInfo, out diskIndex))
            {
                diskIndex = 0;
            }

            int i = 0;
            foreach (var disk in machine.Disks)
            {
                if (i == diskIndex)
                {
                    return disk;
                }

                ++i;
            }

            return null;
        }