Example #1
0
        public void AlternateRom_ChangeAlternateRom_RefreshCrcChangesCrc()
        {
            IReadOnlyList <string> paths;
            var storageAccess    = AlternateRomTestStorageAccess.Initialize(out paths, TestRomResources.TestBinPath, TestRomResources.TestCfgPath, TestRomResources.TestBinPath);
            var rom              = Rom.Create(paths[0], paths[1]);
            var alternateBinPath = paths[2];
            var alternate        = new AlternateRom(alternateBinPath, null, rom);

            Assert.NotNull(alternate);
            Assert.True(alternate.IsValid);
            Assert.Equal(0u, alternate.CfgCrc);
            Assert.Equal(TestRomResources.TestBinCrc, alternate.Crc);

            using (var binStream = storageAccess.Open(alternateBinPath))
            {
                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        = alternate.RefreshCrc(out crcChanged);

            Assert.True(crcChanged);
            Assert.Equal(crc, alternate.Crc);
            Assert.NotEqual(TestRomResources.TestBinCrc, crc);
            Assert.Equal(alternate.Crc, alternate.Alternate.Crc);
            Assert.NotEqual(alternate.Original.Crc, alternate.Crc);
            Assert.NotEqual(alternate.Original.Crc, alternate.Alternate.Crc);
        }
Example #2
0
        public void AlternateRom_ChangeAlternateCfgPath_RefreshCfgCrcChangesCrc()
        {
            IReadOnlyList <string> paths;
            var storageAccess    = AlternateRomTestStorageAccess.Initialize(out paths, TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var alternateBinPath = paths[0];
            var alternateCfgPath = paths[1];
            var alternate        = new AlternateRom(alternateBinPath, alternateCfgPath, null);

            Assert.NotNull(alternate);
            Assert.True(alternate.IsValid);
            Assert.Equal(TestRomResources.TestCfgCrc, alternate.CfgCrc);

            using (var cfgStream = storageAccess.Open(alternateCfgPath))
            {
                cfgStream.Seek(0, System.IO.SeekOrigin.End);
                var cfgToAppend =
                    @"
[vars]
name = ""Weener Weener Cheekeen Deeener""
";
                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        = alternate.RefreshCfgCrc(out cfgCrcChanged);

            Assert.True(cfgCrcChanged);
            Assert.NotEqual(TestRomResources.TestCfgCrc, cfgCrc);
            Assert.Equal(cfgCrc, alternate.CfgCrc);
            Assert.Equal(cfgCrc, alternate.Alternate.CfgCrc);
            Assert.Equal("Weener Weener Cheekeen Deeener", alternate.GetBinFileMetadata().LongNames.First());
        }
Example #3
0
        public void AlternateRom_CreateWithNonExistentCfgPath_ThrowsNullReferenceException()
        {
            var alternateBinPath = AlternateRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath).First();
            var alternateCfgPath = "/Resources/TestWithMissingCfgPath/tagalong.cfg";

            Assert.Throws <NullReferenceException>(() => new AlternateRom(alternateBinPath, alternateCfgPath, null));
        }
Example #4
0
        public void AlternateRom_CreateWithNonExistentPaths_ThrowsNullReferenceException()
        {
            AlternateRomTestStorageAccess.Initialize();
            var alternateBinPath = "/Resources/TestWithNonexistentPaths/tagalong.bin";
            var alternateCfgPath = "/Resources/TestWithNonexistentPaths/tagalong.cfg";

            Assert.Throws <NullReferenceException>(() => new AlternateRom(alternateBinPath, alternateCfgPath, null));
        }
Example #5
0
        public void AlternateRom_CreateWithNullAlternateBinPath_ThrowsArgumentNullException()
        {
            var paths = AlternateRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath, TestRomResources.TestCfgPath);

            var rom = Rom.Create(paths[0], paths[1]);

            Assert.NotNull(rom);
            var alternateCfgPath = paths[2];

            Assert.Throws <ArgumentNullException>(() => new AlternateRom(null, alternateCfgPath, rom));
        }
Example #6
0
        public void AlternateRom_CreateWithNullOriginalRom_AlternateIsValid()
        {
            var paths = AlternateRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);

            var alternateBinPath = paths[0]; // "/Resources/TestWithNullOriginalROM/tagalong.bin";
            var alternateCfgPath = paths[1]; // "/Resources/TestWithNullOriginalROM/tagalong.cfg";
            var alternate        = new AlternateRom(alternateBinPath, alternateCfgPath, null);

            Assert.NotNull(alternate);
            Assert.True(alternate.IsValid);
            Assert.Null(alternate.Original);
            Assert.NotNull(alternate.Alternate);
            Assert.Equal(alternateBinPath, alternate.RomPath);
            Assert.Equal(alternateCfgPath, alternate.ConfigPath);
            Assert.Equal(TestRomResources.TestBinCrc, alternate.Crc);
            Assert.Equal(TestRomResources.TestCfgCrc, alternate.CfgCrc);
            Assert.True(alternate.Validate());
        }
Example #7
0
        public void AlternateRom_CreateWithNullAlternateCfgPath_CreatesAlternateWithNullCfgPath()
        {
            var paths = AlternateRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath, TestRomResources.TestBinPath);

            var rom = Rom.Create(paths[0], paths[1]);

            Assert.NotNull(rom);
            var alternateBinPath = paths[2];
            var alternate        = new AlternateRom(alternateBinPath, null, rom);

            Assert.NotNull(alternate);
            Assert.True(alternate.IsValid);
            Assert.NotNull(alternate.Original);
            Assert.NotNull(alternate.Alternate);
            Assert.NotEqual(rom.RomPath, alternate.RomPath);
            Assert.NotEqual(rom.ConfigPath, alternate.ConfigPath);
            Assert.Null(alternate.ConfigPath);
            Assert.Equal(rom.Format, alternate.Format);
            Assert.Equal(rom.Crc, alternate.Crc);
            Assert.Equal(rom.Crc, alternate.Crc);
            Assert.NotEqual(rom.CfgCrc, alternate.CfgCrc);
            Assert.Equal(0u, alternate.CfgCrc);
            Assert.True(alternate.Validate());
        }
Example #8
0
        public void AlternateRom_CreateWithNullArguments_ThrowsArgumentNullException()
        {
            AlternateRomTestStorageAccess.Initialize();

            Assert.Throws <ArgumentNullException>(() => new AlternateRom(null, null, null));
        }