Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void XmlRom_SetToNullRomPath_ThrowsArgumentNullException()
        {
            XmlFormatRomTestStorageAccess.Initialize();
            var rom = new XmlRom();

            Assert.Throws <ArgumentNullException>(() => rom.UpdateRomPath(null));
        }
Ejemplo n.º 4
0
        public void XmlRom_CreateUninitializedRomAnd_ValidateThrowsArgumentNullException()
        {
            XmlFormatRomTestStorageAccess.Initialize();
            var rom = new XmlRom();

            Assert.Throws <ArgumentNullException>(() => rom.Validate());
        }
Ejemplo n.º 5
0
        public void XmlRom_SetToNullCfgPath_CfgCrcRemainsZero()
        {
            XmlFormatRomTestStorageAccess.Initialize();
            var rom = new XmlRom();

            rom.UpdateConfigPath(null);

            Assert.Equal(null, rom.ConfigPath);
            Assert.Equal(0u, rom.CfgCrc);
        }
Ejemplo 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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
0
        public void XmlRom_SetToValidRomPath_BecomesValid()
        {
            var romPath = XmlFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath).First();
            var rom     = new XmlRom();

            rom.UpdateRomPath(romPath);

            Assert.True(rom.IsValid);
            Assert.NotNull(rom.ResolvedRom);
            Assert.Equal(RomFormat.Rom, rom.Format);
            Assert.Equal(romPath, rom.RomPath);
            Assert.Equal(null, rom.ConfigPath);
            Assert.Equal(TestRomResources.TestRomCrc, rom.Crc);
            Assert.Equal(0u, rom.CfgCrc);
            Assert.True(rom.Validate());
        }
Ejemplo 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());
        }
Ejemplo n.º 11
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());
        }
Ejemplo 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());
        }