Esempio n. 1
0
        public void XmlRom_SetToNullRomPath_ThrowsArgumentNullException()
        {
            XmlFormatRomTestStorageAccess.Initialize();
            var rom = new XmlRom();

            Assert.Throws <ArgumentNullException>(() => rom.UpdateRomPath(null));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public void ProgramDescription_GetRomWhenRomPathInvalidCfgPathIsNullAndNoAlternatePaths_ReturnsOriginalRom()
        {
            ProgramDescriptionHelpersTestStorage.Initialize();
            var rom = new XmlRom();

            rom.UpdateRomPath("/flargy/bargy/nargy.rom");
            var description = CreateProgramDescription(0x789u, rom);

            Assert.True(object.ReferenceEquals(rom, description.GetRom()));
        }
Esempio n. 6
0
        public void XmlRom_SetToNonexistentRomPath_RemainsInvalid()
        {
            XmlFormatRomTestStorageAccess.Initialize();
            var rom = new XmlRom();

            rom.UpdateRomPath("/oopsie" + TestRomResources.TestRomPath);

            Assert.False(rom.IsValid);
            Assert.Null(rom.ResolvedRom);
        }
Esempio n. 7
0
        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()));
        }
Esempio n. 8
0
        public void ProgramDescription_GetRomWhenRomPathValidAndNoConfig_ReturnsOriginalRom()
        {
            var romPath = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath).First();
            var rom     = new XmlRom();

            rom.UpdateRomPath(romPath);
            var description = CreateProgramDescription(0x357u, rom);

            var romFromDescription = description.GetRom();

            Assert.True(object.ReferenceEquals(rom, romFromDescription));
        }
        public void RomComparerStrictCrcOnlyTests_CompareCorruptAndMissingRoms_ReturnPathCompareResult()
        {
            RomComparerStrictCrcOnlyTestStorageAccess.Initialize();
            var rom0 = new CorruptedTestRom("whos/on/first.rom");
            var rom1 = new XmlRom();

            rom1.UpdateRomPath("/what/is/on/second.bin");

            var compareResult = RomComparerStrictCrcOnly.Default.Compare(rom0, rom1);

            Assert.Equal(string.Compare(rom0.RomPath, rom1.RomPath), compareResult);
        }
Esempio n. 10
0
        public void XmlRom_SetToValidRomPathChangeToAnotherValidPath_RemainsValid()
        {
            var paths = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath, TestRomResources.TestRomMetadataPath);
            var rom   = new XmlRom();

            rom.UpdateRomPath(paths[0]);
            Assert.True(rom.IsValid);
            Assert.Equal(TestRomResources.TestRomCrc, rom.Crc);
            Assert.Equal(paths[0], rom.RomPath);

            rom.UpdateRomPath(paths[1]);

            Assert.True(rom.IsValid);
            Assert.NotNull(rom.ResolvedRom);
            Assert.Equal(RomFormat.Rom, rom.Format);
            Assert.Equal(paths[1], rom.RomPath);
            Assert.Equal(null, rom.ConfigPath);
            Assert.Equal(TestRomResources.TestRomMetadataCrc, rom.Crc);
            Assert.Equal(0u, rom.CfgCrc);
            Assert.True(rom.Validate());
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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());
        }
Esempio n. 13
0
        public void XmlRom_SetToValidRomPathChangeToInvalidPath_BecomesInvalid()
        {
            var romPath = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath).First();
            var rom     = new XmlRom();

            rom.UpdateRomPath(romPath);
            Assert.True(rom.IsValid);
            Assert.Equal(TestRomResources.TestRomCrc, rom.Crc);
            Assert.Equal(romPath, rom.RomPath);

            var invalidPath = "/bad" + romPath;

            rom.UpdateRomPath(invalidPath);

            Assert.False(rom.IsValid);
            Assert.Null(rom.ResolvedRom);
            Assert.Equal(RomFormat.None, rom.Format);
            Assert.Equal(invalidPath, rom.RomPath);
            Assert.Equal(null, rom.ConfigPath);
            Assert.Equal(0u, rom.Crc);
            Assert.Equal(0u, rom.CfgCrc);
            Assert.False(rom.Validate());
        }
        public void RomComparerStrictCrcOnlyTests_CompareMissingRoms_ReturnPathCompareResult()
        {
            RomComparerStrictCrcOnlyTestStorageAccess.Initialize();
            var rom0 = new XmlRom();

            rom0.UpdateRomPath("/where/is/waldo.bin");
            var rom1 = new XmlRom();

            rom1.UpdateRomPath("where/in/the/world/is/carmen/sandiego.rom");

            var compareResult = RomComparerStrictCrcOnly.Default.Compare(rom0, rom1);

            Assert.Equal(string.Compare(rom0.RomPath, rom1.RomPath), compareResult);
        }
Esempio n. 15
0
        public void XmlRom_SetToValidLuigiPath_BecomesValid()
        {
            var romPath = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = new XmlRom();

            rom.UpdateRomPath(romPath);

            Assert.True(rom.IsValid);
            Assert.NotNull(rom.ResolvedRom);
            Assert.Equal(RomFormat.Luigi, rom.Format);
            Assert.Equal(romPath, rom.RomPath);
            Assert.Equal(null, rom.ConfigPath);
            Assert.Equal(TestRomResources.TestBinCrc, rom.Crc);    // LUIGI should return original .BIN ROM's CRC
            Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc); // LUIGI should return original .CFG file's CRC
            Assert.True(rom.Validate());
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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()));
        }
Esempio n. 18
0
        public void ProgramDescription_GetRomWhenRomPathInvalidAndAlternatePathFound_ReturnsAlternateRom()
        {
            var alternatePath = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestCc3Path).First();
            var rom           = new XmlRom();

            rom.UpdateRomPath("/floory/boory/noory.rom");
            var supportFiles = new ProgramSupportFiles(rom);

            supportFiles.AddSupportFile(ProgramFileKind.Rom, "/grub.bin");
            supportFiles.AddSupportFile(ProgramFileKind.Rom, alternatePath);
            supportFiles.AddSupportFile(ProgramFileKind.Rom, "/burg.bin");
            var description = CreateProgramDescription(0x135u, rom);

            description.Files = supportFiles;

            var romFromDescription = description.GetRom();

            Assert.False(object.ReferenceEquals(rom, romFromDescription));
            Assert.Equal(alternatePath, romFromDescription.RomPath);
        }
Esempio n. 19
0
        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());
        }