public void AddTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); }
public void SectorCollectionConstructorTest() { SectorCollection target = new SectorCollection(); Assert.IsNotNull(target); Assert.IsTrue(target.Count == 0); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == 1); }
public void CountTest() { int count = 0; SectorCollection target = new SectorCollection(); // TODO: Initialize to an appropriate value int actual; actual = target.Count; Assert.IsTrue(actual == count); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == actual + 1); for (int i = 0; i < 5000; i++) { target.Add(s); } Assert.IsTrue(target.Count == actual + 1 + 5000); }
public void GetEnumeratorTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); int cnt = 0; foreach (Sector s in target) { cnt++; } Assert.IsTrue(cnt == target.Count); }
public void RegisterSector(Sector sector) { if (sector == null) { throw new ArgumentNullException("sector"); } if (sector.Manager != null) { throw new ArgumentException("Given sector is already registered in some context.", "sector"); } sector.Manager = this; registeredSectors.Add(sector); foreach (WorldObject worldObject in sector.RegisteredObjects) { RegisterObject(worldObject); } }
public void CountTest() { int count = 0; SectorCollection target = new SectorCollection(); // TODO: Initialize to an appropriate value int actual; actual = target.Count; Assert.IsTrue(actual == count); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == actual + 1); for (int i = 0; i < 5000; i++) target.Add(s); Assert.IsTrue(target.Count == actual + 1 + 5000); }
public void ItemTest() { int count = 37; SectorCollection target = new SectorCollection(); int index = 0; Sector expected = new Sector(4096); target.Add(null); Sector actual; target[index] = expected; actual = target[index]; Assert.AreEqual(expected, actual); Assert.IsNotNull(actual); Assert.IsTrue(actual.Id == expected.Id); actual = null; try { actual = target[count + 100]; } catch (Exception ex) { Assert.IsTrue(ex is CFException); } try { actual = target[-1]; } catch (Exception ex) { Assert.IsTrue(ex is CFException); } }
private void Init(Stream stream) { // stream size sanity checker // compound files are always blocks of 512 bytes Debug.Assert((stream.Length % 512) == 0); // read in the first sector StorageSector sector = new StorageSector(stream); // interpret sector as header sector HeaderSector header = new HeaderSector(sector.GetStream()); // read in all remaining sectors SectorCollection sectors = new SectorCollection((int)(stream.Length / Constants.SECTOR_SIZE)); while (stream.Position != stream.Length) { sector = new StorageSector(stream); sectors.Add(sector); } // build the fat index List <Sect> index = new List <Sect>((int)(Constants.MAX_SECT * header.SectFatCount)); // read first 109 fat entries for (int i = 0; i < header.SectFat.Length; ++i) { Sect fatSect = header.SectFat[i]; if (!fatSect.IsFree) { FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream()); index.AddRange(fat.SectFat); sectors[fatSect] = fat; } } // read remaining fat entries int difCount; Sect difIndex; for (difIndex = header.SectDifStart, difCount = 0; !difIndex.IsEndOfChain && difCount < header.SectDifCount; ++difCount) { DifSector dif = new DifSector(((StorageSector)sectors[difIndex]).GetStream()); sectors[difIndex] = dif; for (int i = 0; i < dif.SectFat.Length; ++i) { Sect fatSect = dif.SectFat[i]; if (!fatSect.IsFree) { FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream()); index.AddRange(fat.SectFat); sectors[fatSect] = fat; } } difIndex = dif.NextDif; } Debug.Assert(difCount == header.SectDifCount); // read in mini fat sectors Debug.Assert(index.Count == (header.SectFatCount * Constants.MAX_SECT)); Debug.Assert(index.Capacity == index.Count); Sect[] fatSects = index.ToArray(); Sect miniFatSect; int miniFatCount; for (miniFatSect = header.SectMiniFatStart, miniFatCount = 0; !miniFatSect.IsEndOfChain && miniFatCount < header.SectMiniFatCount; miniFatSect = fatSects[miniFatSect.ToInt()], ++miniFatCount) { MiniFatSector miniFat = new MiniFatSector(((StorageSector)sectors[miniFatSect]).GetStream()); sectors[miniFatSect] = miniFat; } Debug.Assert(miniFatCount == header.SectMiniFatCount); // read in directory sectors DirectorySectorEntryCollection dirs = new DirectorySectorEntryCollection(); for (Sect dirSect = header.SectDirStart; !dirSect.IsEndOfChain; dirSect = fatSects[dirSect.ToInt()]) { DirectorySector dir = new DirectorySector(((StorageSector)sectors[dirSect]).GetStream()); foreach (DirectorySectorEntry entry in dir.Entries) { dirs.Add(entry); } sectors[dirSect] = dir; } _directory = new Directory(dirs, sectors, fatSects); }
public void ItemTest() { int count = 37; SectorCollection target = new SectorCollection(); int index = 0; Sector expected = new Sector(4096); target.Add(null); Sector actual; target[index] = expected; actual = target[index]; Assert.AreEqual(expected, actual); Assert.IsNotNull(actual); Assert.IsTrue(actual.Id == expected.Id); actual = null; try { actual = target[count + 100]; } catch (Exception ex) { Assert.IsTrue(ex is ArgumentOutOfRangeException); } try { actual = target[-1]; } catch (Exception ex) { Assert.IsTrue(ex is ArgumentOutOfRangeException); } }
public void GetEnumeratorTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); int cnt = 0; foreach (Sector s in target) { cnt++; } Assert.IsTrue(cnt == target.Count); }
public void AddTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); }
public void SectorCollectionConstructorTest() { SectorCollection target = new SectorCollection(); Assert.IsNotNull(target); Assert.IsTrue(target.Count == 0); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == 1); }
/// <summary> /// Load compound file from an existing stream. /// </summary> /// <param name="stream">Stream to load compound file from</param> private void Load(Stream stream) { try { _header = new Header(); _directoryEntries = new List<IDirectoryEntry>(); SourceStream = stream; _header.Read(stream); var numberOfSectors = Ceiling(((stream.Length - GetSectorSize())/(double) GetSectorSize())); if (stream.Length > 0x7FFFFF0) TransactionLockAllocated = true; _sectors = new SectorCollection(); for (var i = 0; i < numberOfSectors; i++) _sectors.Add(null); LoadDirectories(); RootStorage = new CFStorage(this, _directoryEntries[0]); } catch (Exception) { if (stream != null) stream.Close(); throw; } }
private void Init(Stream stream) { // stream size sanity checker // compound files are always blocks of 512 bytes Debug.Assert((stream.Length % 512) == 0); // read in the first sector StorageSector sector = new StorageSector(stream); // interpret sector as header sector HeaderSector header = new HeaderSector(sector.GetStream()); // read in all remaining sectors SectorCollection sectors = new SectorCollection((int)(stream.Length / Constants.SECTOR_SIZE)); while(stream.Position != stream.Length) { sector = new StorageSector(stream); sectors.Add(sector); } // build the fat index List<Sect> index = new List<Sect>((int)(Constants.MAX_SECT * header.SectFatCount)); // read first 109 fat entries for(int i = 0; i < header.SectFat.Length; ++i) { Sect fatSect = header.SectFat[i]; if(!fatSect.IsFree) { FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream()); index.AddRange(fat.SectFat); sectors[fatSect] = fat; } } // read remaining fat entries int difCount; Sect difIndex; for(difIndex = header.SectDifStart, difCount = 0; !difIndex.IsEndOfChain && difCount < header.SectDifCount; ++difCount) { DifSector dif = new DifSector(((StorageSector)sectors[difIndex]).GetStream()); sectors[difIndex] = dif; for(int i = 0; i < dif.SectFat.Length; ++i) { Sect fatSect = dif.SectFat[i]; if(!fatSect.IsFree) { FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream()); index.AddRange(fat.SectFat); sectors[fatSect] = fat; } } difIndex = dif.NextDif; } Debug.Assert(difCount == header.SectDifCount); // read in mini fat sectors Debug.Assert(index.Count == (header.SectFatCount * Constants.MAX_SECT)); Debug.Assert(index.Capacity == index.Count); Sect[] fatSects = index.ToArray(); Sect miniFatSect; int miniFatCount; for(miniFatSect = header.SectMiniFatStart, miniFatCount = 0; !miniFatSect.IsEndOfChain && miniFatCount < header.SectMiniFatCount; miniFatSect = fatSects[miniFatSect.ToInt()], ++miniFatCount) { MiniFatSector miniFat = new MiniFatSector(((StorageSector)sectors[miniFatSect]).GetStream()); sectors[miniFatSect] = miniFat; } Debug.Assert(miniFatCount == header.SectMiniFatCount); // read in directory sectors DirectorySectorEntryCollection dirs = new DirectorySectorEntryCollection(); for(Sect dirSect = header.SectDirStart; !dirSect.IsEndOfChain; dirSect = fatSects[dirSect.ToInt()]) { DirectorySector dir = new DirectorySector(((StorageSector)sectors[dirSect]).GetStream()); foreach(DirectorySectorEntry entry in dir.Entries) dirs.Add(entry); sectors[dirSect] = dir; } _directory = new Directory(dirs, sectors, fatSects); }