public void XmlRom_SetToValidBinPathChangeCfgPath_BinCrcUnchangedAndCfgCrcUpdatesImmediately() { var paths = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath, TestRomResources.TestCfgMetadataPath); var rom = new XmlRom(); rom.UpdateRomPath(paths[0]); rom.UpdateConfigPath(paths[1]); Assert.True(rom.IsValid); Assert.NotNull(rom.ResolvedRom); Assert.Equal(RomFormat.Bin, rom.Format); Assert.Equal(paths[0], rom.RomPath); Assert.Equal(paths[1], rom.ConfigPath); Assert.Equal(TestRomResources.TestBinCrc, rom.Crc); Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc); rom.UpdateConfigPath(paths[2]); var crcChanged = true; var crc = rom.RefreshCrc(out crcChanged); var cfgCrcChanged = true; var cfgCrc = rom.RefreshCfgCrc(out cfgCrcChanged); Assert.False(crcChanged); Assert.Equal(TestRomResources.TestBinCrc, rom.Crc); Assert.Equal(TestRomResources.TestBinCrc, crc); Assert.False(cfgCrcChanged); Assert.Equal(TestRomResources.TestMetadataCfgCrc, cfgCrc); Assert.Equal(TestRomResources.TestMetadataCfgCrc, rom.CfgCrc); }
public void ProgramDescription_GetRomWhenRomPathsInvalidAndAlternatePathsFound_ReturnsAlternateRom() { var alternatePaths = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath); var rom = new XmlRom(); rom.UpdateRomPath("/fleery/beery/neery.bin"); rom.UpdateConfigPath("/fleery/beery/neery.cfg"); var supportFiles = new ProgramSupportFiles(rom); supportFiles.AddSupportFile(ProgramFileKind.Rom, "/grab.bin"); supportFiles.AddSupportFile(ProgramFileKind.Rom, alternatePaths[0]); supportFiles.AddSupportFile(ProgramFileKind.Rom, "/barg.bin"); supportFiles.AddSupportFile(ProgramFileKind.CfgFile, "/grab.cfg"); supportFiles.AddSupportFile(ProgramFileKind.CfgFile, alternatePaths[1]); supportFiles.AddSupportFile(ProgramFileKind.CfgFile, "/barg.cfg"); var description = CreateProgramDescription(0x246u, rom); description.Files = supportFiles; var romFromDescription = description.GetRom(); Assert.False(object.ReferenceEquals(rom, romFromDescription)); Assert.Equal(alternatePaths[0], romFromDescription.RomPath); Assert.Equal(alternatePaths[1], romFromDescription.ConfigPath); }
public void XmlRom_SetToValidBinThenModifyBin_RefreshCrcChanges() { IReadOnlyList <string> paths; var storageAccess = XmlFormatRomTestStorageAccess.Initialize(out paths, TestRomResources.TestBinPath, TestRomResources.TestCfgPath); var testBinToModifyPath = paths[0]; var rom = new XmlRom(); rom.UpdateRomPath(testBinToModifyPath); rom.UpdateConfigPath(paths[1]); Assert.True(rom.IsValid); Assert.NotNull(rom.ResolvedRom); Assert.Equal(RomFormat.Bin, rom.Format); Assert.Equal(testBinToModifyPath, rom.RomPath); Assert.Equal(paths[1], rom.ConfigPath); Assert.Equal(TestRomResources.TestBinCrc, rom.Crc); Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc); using (var binStream = storageAccess.Open(testBinToModifyPath)) { binStream.Seek(0, System.IO.SeekOrigin.End); var dataToAppend = Enumerable.Repeat((byte)0xFF, 128).ToArray(); binStream.Write(dataToAppend, 0, 128); binStream.Seek(0, System.IO.SeekOrigin.Begin); } var crcChanged = false; var crc = rom.RefreshCrc(out crcChanged); Assert.True(crcChanged); Assert.NotEqual(TestRomResources.TestBinCrc, crc); }
public void XmlRom_SetToNullCfgPath_CfgCrcRemainsZero() { XmlFormatRomTestStorageAccess.Initialize(); var rom = new XmlRom(); rom.UpdateConfigPath(null); Assert.Equal(null, rom.ConfigPath); Assert.Equal(0u, rom.CfgCrc); }
public void ProgramDescription_GetRomWhenRomAndCfgPathsInvalidAndNoAlternatePaths_ReturnsOriginalRom() { ProgramDescriptionHelpersTestStorage.Initialize(); var rom = new XmlRom(); rom.UpdateRomPath("/floogy/boogy/noogy.bin"); rom.UpdateConfigPath("/floogy/boogy/noogy.cfg"); var description = CreateProgramDescription(0x987u, rom); Assert.True(object.ReferenceEquals(rom, description.GetRom())); }
public void XmlRom_SetToNonexistentCfgPath_CfgPathChanges() { XmlFormatRomTestStorageAccess.Initialize(); var rom = new XmlRom(); var invalidCfgPath = "/ooops" + TestRomResources.TestCfgPath; rom.UpdateConfigPath(invalidCfgPath); Assert.Equal(invalidCfgPath, rom.ConfigPath); Assert.Equal(0u, rom.CfgCrc); }
public void ProgramDescription_GetRomWhenRomPathValidAndCfgPathInvalidAndNoAlternates_ReturnsOriginalRom() { var romPath = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath).First(); var rom = new XmlRom(); rom.UpdateConfigPath("/flangy/bangy/nangy.cfg"); rom.UpdateRomPath(romPath); var description = CreateProgramDescription(0x468u, rom); var romFromDescription = description.GetRom(); Assert.True(object.ReferenceEquals(rom, romFromDescription)); }
public void ProgramDescription_GetRomWhenRomAndCfgPathsInvalidAndUnbalancedAlternatePaths_ThrowsInvalidOperationException() { ProgramDescriptionHelpersTestStorage.Initialize(); var rom = new XmlRom(); rom.UpdateRomPath("/fleggy/beggy/neggy.bin"); rom.UpdateConfigPath("/fleggy/beggy/neggy.cfg"); var supportFiles = new ProgramSupportFiles(rom); supportFiles.AddSupportFile(ProgramFileKind.Rom, "/biff!"); var description = CreateProgramDescription(0x654u, rom); description.Files = supportFiles; var exception = Assert.Throws <InvalidOperationException>(() => description.GetRom()); Assert.Equal(Resources.Strings.ProgramDescription_MissingAlternateCfgFile, exception.Message); }
public void ProgramDescription_GetRomWhenRomAndCfgPathsInvalidAndAlternatePathsNotFound_ReturnsOriginalRom() { ProgramDescriptionHelpersTestStorage.Initialize(); var rom = new XmlRom(); rom.UpdateRomPath("/flooty/booty/nooty.bin"); rom.UpdateConfigPath("/flooty/booty/nooty.cfg"); var supportFiles = new ProgramSupportFiles(rom); supportFiles.AddSupportFile(ProgramFileKind.Rom, "/banff.bin"); supportFiles.AddSupportFile(ProgramFileKind.Rom, "/barff.bin"); supportFiles.AddSupportFile(ProgramFileKind.CfgFile, "/banff.cfg"); supportFiles.AddSupportFile(ProgramFileKind.CfgFile, "/barff.cfg"); var description = CreateProgramDescription(0x321u, rom); description.Files = supportFiles; Assert.True(object.ReferenceEquals(rom, description.GetRom())); }
public void XmlRom_SetToValidBinThenModifyCfg_RefreshCfgCrcChanges() { IReadOnlyList <string> paths; var storageAccess = XmlFormatRomTestStorageAccess.Initialize(out paths, TestRomResources.TestBinPath, TestRomResources.TestCfgPath); var testCfgToModifyPath = paths[1]; var rom = new XmlRom(); rom.UpdateRomPath(paths[0]); rom.UpdateConfigPath(testCfgToModifyPath); Assert.True(rom.IsValid); Assert.NotNull(rom.ResolvedRom); Assert.Equal(RomFormat.Bin, rom.Format); Assert.Equal(paths[0], rom.RomPath); Assert.Equal(testCfgToModifyPath, rom.ConfigPath); Assert.Equal(TestRomResources.TestBinCrc, rom.Crc); Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc); using (var cfgStream = storageAccess.Open(testCfgToModifyPath)) { cfgStream.Seek(0, System.IO.SeekOrigin.End); var cfgToAppend = @" [vars] name = ""wut?"" "; var cfgDataToAppend = System.Text.Encoding.UTF8.GetBytes(cfgToAppend); cfgStream.Write(cfgDataToAppend, 0, cfgDataToAppend.Length); cfgStream.Seek(0, System.IO.SeekOrigin.Begin); } var cfgCrcChanged = false; var cfgCrc = rom.RefreshCfgCrc(out cfgCrcChanged); Assert.True(cfgCrcChanged); Assert.NotEqual(TestRomResources.TestCfgCrc, cfgCrc); Assert.Equal("wut?", rom.GetBinFileMetadata().LongNames.First()); }
public void XmlRom_SetToValidRomPathChangeToValidBinPathWithDifferentFormat_RemainsValid() { var paths = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath, TestRomResources.TestBinPath, TestRomResources.TestCfgPath); var rom = new XmlRom(); rom.UpdateRomPath(paths[0]); Assert.True(rom.IsValid); Assert.Equal(TestRomResources.TestRomCrc, rom.Crc); Assert.Equal(paths[0], rom.RomPath); Assert.Equal(RomFormat.Rom, rom.Format); rom.UpdateRomPath(paths[1]); rom.UpdateConfigPath(paths[2]); Assert.True(rom.IsValid); Assert.NotNull(rom.ResolvedRom); Assert.Equal(RomFormat.Bin, rom.Format); Assert.Equal(paths[1], rom.RomPath); Assert.Equal(paths[2], rom.ConfigPath); Assert.Equal(TestRomResources.TestBinCrc, rom.Crc); Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc); Assert.True(rom.Validate()); }