public void Groups() { var file = new LogFileWriter("test2.zip", "LogFileWriterTestsGroups"); var source = new MemoryPool("test", MemoryAddress.StaticAbsolute, 0x123456, 0, 0x1234); source.Add(new MemoryFieldFunc <int>("testInt", (pool) => 123)); source.Add(new MemoryFieldFunc <string>("test", (pool) => "test")); file.Subscribe(source); Assert.AreEqual(1, file.Groups.Count()); Assert.AreEqual(source.Name, file.Groups.FirstOrDefault().Name); Assert.AreEqual(true, file.Groups.FirstOrDefault().Subscribed); Assert.AreEqual(2, file.Groups.FirstOrDefault().Fields.Count()); Assert.AreEqual(true, file.Groups.FirstOrDefault().Fields.Any(x => x.Name == "testInt")); Assert.AreEqual(true, file.Groups.FirstOrDefault().Fields.Any(x => x.Name == "test")); Assert.AreEqual(source, file.Groups.FirstOrDefault().DataSource); file.Subscribe(source); Assert.AreEqual(1, file.Groups.Count()); file.Unsubscribe(source); Assert.AreEqual(1, file.Groups.Count()); // but it's become inactive instead; Assert.AreEqual(false, file.Groups.FirstOrDefault().Subscribed); source.Add(new MemoryFieldFunc <string>("test2", (pool) => "test")); file.Subscribe(source); Assert.AreEqual(1, file.Groups.Count()); Assert.AreEqual(true, file.Groups.FirstOrDefault().Subscribed); Assert.AreEqual(3, file.Groups.FirstOrDefault().Fields.Count()); file.Save(); ZipStorer z = ZipStorer.Open("test2.zip", FileAccess.Read); var files = z.ReadCentralDir(); Assert.AreEqual(3, files.Count); Assert.True(files.Any(x => x.FilenameInZip == "test/Data.bin")); Assert.True(files.Any(x => x.FilenameInZip == "test/Structure.xml")); Assert.True(files.Any(x => x.FilenameInZip == "test/Time.bin")); }
public void DataWithResubscriptions() { var counter = 0; var file = new LogFileWriter("test4.zip", "LogFileWriterTestsDataWithResubscriptions"); var source = new MemoryPool("test", MemoryAddress.StaticAbsolute, 0x123456, 0, 0x1234); source.Add(new MemoryFieldFunc <int>("testInt", (pool) => counter++)); // these are always logged source.Add(new MemoryFieldFunc <string>("test", (pool) => "test")); file.Subscribe(source); // Fill up next 1/2 of data file int i = 0; for (i = 0; i < 1441792 / 2; i++) // 33MiB { file.Update(i); // +24 bytes } file.Unsubscribe(source); file.Update(i++); // does nothing now, but the data thing does miss 1 time . file.Subscribe(source); // Fill up next 1/2 of a data file for (; i < 1441792; i++) // 33MiB { file.Update(i); // +24 bytes } Thread.Sleep(500); // We should have logged 2 data files by now. Assert.True(File.Exists("LogFileWriterTestsDataWithResubscriptions/test/Data.bin")); file.Save(); ZipStorer z = ZipStorer.Open("test4.zip", FileAccess.Read); var files = z.ReadCentralDir(); Assert.AreEqual(3, files.Count); Assert.True(files.Any(x => x.FilenameInZip == "test/Data.bin")); Assert.True(files.Where(x => x.FilenameInZip == "test/Data.bin").FirstOrDefault().FileSize == (1441792 - 1) * 28); Assert.True(files.Any(x => x.FilenameInZip == "test/Structure.xml")); Assert.True(files.Any(x => x.FilenameInZip == "test/Time.bin")); Assert.True(files.Where(x => x.FilenameInZip == "test/Time.bin").FirstOrDefault().FileSize == 1441792 * 8 - 8); }