Beispiel #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);
        }
Beispiel #2
0
        public void LuigiFormatRom_LoadScrambledForAnyLuigiWithMetadataRequestTestBlock_VerifyTestBlockNotFound()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiWithMetadatdaScrambledForAnyDevicePath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Null(rom.LocateDataBlock <LuigiTestDataBlock>());
        }
Beispiel #3
0
        public void LuigiFormatRom_LoadScrambledForAnyLuigi_VerifyTargetDeviceUniqueId()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiScrambledForAnyDevicePath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Equal(LuigiScrambleKeyBlock.AnyLTOFlashId, rom.TargetDeviceUniqueId);
        }
Beispiel #4
0
        public void LuigiFormatRom_Load_VerifyCrc24()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Equal(0x0035f671u, rom.Crc24);
        }
Beispiel #5
0
        public void RomFormatRom_LoadCorruptedRom_ReturnsNullRom()
        {
            var romPath = RomFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomBadHeaderPath).First();
            var rom     = Rom.Create(romPath, null);

            Assert.Null(rom);
        }
Beispiel #6
0
        public void LuigiFormatRom_LoadStandardLuigi_VerifyTargetDeviceUniqueId()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.True(string.IsNullOrEmpty(rom.TargetDeviceUniqueId));
        }
Beispiel #7
0
        public void BinFormatRom_Load_VerifyCrc()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            Assert.Equal(TestRomResources.TestBinCrc, rom.Crc);
            Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc);
        }
Beispiel #8
0
        public void LuigiFormatRom_Load_VerifyCrc()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.Create(romPath, null);

            Assert.Equal(TestRomResources.TestBinCrc, rom.Crc);
            Assert.Equal(TestRomResources.TestCfgCrc, rom.CfgCrc);
        }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the AlternateRom type.
 /// </summary>
 /// <param name="romPath">The alternate path for the ROM described by <paramref name="originalRom"/>.</param>
 /// <param name="configPath">The alternate configuration file path for the ROM described by <paramref name="originalRom"/>.</param>
 /// <param name="originalRom">The original ROM.</param>
 public AlternateRom(string romPath, string configPath, IRom originalRom)
 {
     Alternate  = Rom.Create(romPath, configPath);
     RomPath    = Alternate.RomPath;
     ConfigPath = Alternate.ConfigPath;
     IsValid    = Alternate.IsValid;
     Original   = originalRom;
 }
Beispiel #10
0
        public void ProgramDescription_IsMatchingProgramDescriptionWithMatchingProgramIdentifierMatchingRomFormatCfgCrcMustMatchWithCodeInfoHasMismatchedCode_ReturnsFalse()
        {
            var romPaths    = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom         = Rom.Create(romPaths[0], romPaths[1]);
            var description = new TestProgramDescription(rom, "tod");

            Assert.False(description.IsMatchingProgramDescription(new ProgramIdentifier(rom.Crc, rom.CfgCrc), RomFormat.Bin, cfgCrcMustMatch: true, code: "tag"));
        }
Beispiel #11
0
        public void BinFormatRom_LoadAndValidateRomWithOddFileSize_RomFormatIdentifiedCorrectly()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestIntPath, TestRomResources.TestCfgPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            Assert.NotNull(rom);
            Assert.Equal(RomFormat.Bin, rom.Format);
            Assert.True(rom.Validate());
        }
Beispiel #12
0
        public void BinFormatRom_GetMetadataFromCorruptCfgFile_DoesNotThrow()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinMetadataPath, TestRomResources.TestCfgCorruptMetadataPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            var metadata = rom.GetBinFileMetadata();

            Assert.NotNull(metadata);
        }
Beispiel #13
0
        public void BinFormatRom_GetMetadata_ReturnsExpectedMetadata()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinMetadataPath, TestRomResources.TestCfgMetadataPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            var metadata = rom.GetBinFileMetadata();

            Assert.NotNull(metadata);
        }
Beispiel #14
0
        public void RomFormatRom_LoadAndValidateRom_RomFormatIdentifiedCorrectly(string testRomPath, RomFormat expectedRomFormat)
        {
            var romPath = RomFormatRomTestStorageAccess.Initialize(testRomPath).First();
            var rom     = Rom.Create(romPath, null);

            Assert.NotNull(rom);
            Assert.Equal(expectedRomFormat, rom.Format);
            Assert.True(rom.Validate());
        }
Beispiel #15
0
        public void RomFormatRom_GetMetadata_ReturnsNullMetadata()
        {
            var romPath = RomFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath).First();

            var rom      = Rom.Create(romPath, null);
            var metadata = rom.GetRomFileMetadata();

            Assert.Null(metadata);
        }
Beispiel #16
0
        public void BinFormatRom_LoadAndValidateRomWithoutCfgPath_RomFormatIdentifiedCorrectly()
        {
            var path = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinPath).First();
            var rom  = Rom.Create(path, null);

            Assert.NotNull(rom);
            Assert.Equal(RomFormat.Bin, rom.Format);
            Assert.True(rom.Validate());
        }
Beispiel #17
0
        public void Rom_GetLuigiHeaderFromLuigiRom_ReturnsHeader()
        {
            var romPath = RomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.Create(romPath, null);

            Assert.NotNull(rom);

            Assert.NotNull(Rom.GetLuigiHeader(rom));
        }
Beispiel #18
0
        public void LuigiFormatRom_LoadAndValidateRom_RomFormatIdentifiedCorrectly()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.Create(romPath, null);

            Assert.NotNull(rom);
            Assert.Equal(RomFormat.Luigi, rom.Format);
            Assert.True(rom.Validate());
        }
Beispiel #19
0
        public void ProgramDescription_IsMatchingProgramDescriptionWithMatchingProgramIdentifierMatchingRomFormatCfgCrcMustMatch_ReturnsTrue()
        {
            var romPaths = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom      = Rom.Create(romPaths[0], romPaths[1]);

            var description = CreateProgramDescription(rom.Crc, rom);

            Assert.True(description.IsMatchingProgramDescription(new ProgramIdentifier(rom.Crc, rom.CfgCrc), RomFormat.Bin, cfgCrcMustMatch: true));
        }
Beispiel #20
0
        public void RomFormatRom_GetMetadata_ReturnsExpectedMetadata()
        {
            var romPath = RomFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomMetadataPath).First();

            var rom      = Rom.Create(romPath, null);
            var metadata = rom.GetRomFileMetadata();

            Assert.NotNull(metadata);
            VerifyExpectedMetadata(metadata, lastVersionMetadataIsCorrupt: false);
        }
Beispiel #21
0
        public void LuigiFormatRomFromFuture_Load_DoesNotLoadAsLuigiFormatRom()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromFuturePath).First();
            var rom     = Rom.Create(romPath, null);

            // At this time, the ROM *just happens* to pass the .bin format tests! Depending on
            // many factors, differently "fake corrupted" ROMs could fail to load or not.
            // This test is OK with a null or .bin result.
            Assert.True((rom == null) || (rom.Format == RomFormat.Bin));
        }
Beispiel #22
0
        public void RomFormatRom_RefreshCfgCrc_NeverRefreshes()
        {
            var romPath = RomFormatRomTestStorageAccess.Initialize(TestRomResources.TestRomPath).First();
            var rom     = Rom.Create(romPath, null);

            var changed = true;

            Assert.Equal(0u, rom.RefreshCfgCrc(out changed));
            Assert.False(changed);
        }
Beispiel #23
0
        public void BinFormatRom_RefreshCfgCrc_NeverRefreshes()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            var changed = true;

            Assert.Equal(TestRomResources.TestCfgCrc, rom.RefreshCfgCrc(out changed));
            Assert.False(changed);
        }
Beispiel #24
0
        public void LuigiFormatRom_GetMetadata_ReturnsExpectedMetadata()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiWithMetadataPath).First();

            var rom      = Rom.Create(romPath, null);
            var metadata = rom.GetLuigiFileMetadata();

            Assert.NotNull(metadata);
            VerifyExpectedMetadata(metadata);
        }
Beispiel #25
0
        public void LuigiFormatRom_LoadScrambledLuigis_VerifyTargetDeviceUniqueIds()
        {
            var paths = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiScrambledForDevice0Path, TestRomResources.TestLuigiScrambledForDevice1Path);
            var rom0  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(paths[0], null));
            var rom1  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(paths[1], null));

            Assert.NotEqual(rom0.TargetDeviceUniqueId, rom1.TargetDeviceUniqueId);
            Assert.Equal(TestRomResources.TestLuigiScrambledForDevice0UniqueId, rom0.TargetDeviceUniqueId);
            Assert.Equal(TestRomResources.TestLuigiScrambledForDevice1UniqueId, rom1.TargetDeviceUniqueId);
        }
Beispiel #26
0
        public void ProgramDescription_GetRomWhenRomAndConfigPathsValidAlternatesAreDefined_ReturnsOriginalRom()
        {
            var romPaths    = ProgramDescriptionHelpersTestStorage.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom         = Rom.Create(romPaths[0], romPaths[1]);
            var description = CreateProgramDescription(0x579u, rom);

            var romFromDescription = description.GetRom();

            Assert.True(object.ReferenceEquals(rom, romFromDescription));
        }
Beispiel #27
0
        public void BinFormatRom_ReplaceCfgPath_CfgPathChanges()
        {
            var paths = BinFormatRomTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgPath);
            var rom   = Rom.Create(paths[0], paths[1]);

            var fakeCfgPath = "/Resources/tugalong.cfg";

            ((BinFormatRom)rom).ReplaceCfgPath(fakeCfgPath);

            Assert.Equal(fakeCfgPath, rom.ConfigPath);
        }
Beispiel #28
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));
        }
Beispiel #29
0
        public void BinFormatRom_GetMetadataFromCorruptCfgFile_BehavesAsExpected()
        {
            IReadOnlyList <string> paths;
            var storageAccess = BinFormatRomTestStorageAccess.Initialize(out paths, TestRomResources.TestBinMetadataPath, TestRomResources.TestCfgBadMetadataPath);
            var rom           = Rom.Create(paths[0], paths[1]);

            var corrupted = storageAccess.IntroduceCorruption(paths[1]);

            Assert.True(corrupted);
            AssertMetadataBehavior(rom);
        }
Beispiel #30
0
        public void RomComparer_CompareNullToRomsAsObjects_ProducesCorrectResult(RomComparison comparisonMode)
        {
            var    romPath = RomComparerTestStorageAccess.Initialize(TestRomResources.TestRomPath).First();
            object rom0    = null;
            object rom1    = Rom.Create(romPath, null);

            using (var comparer = RomComparer.GetComparer(comparisonMode))
            {
                Assert.Equal(-1, comparer.Compare(rom0, rom1));
            }
        }