Esempio n. 1
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntryWithOverlappingCrcs_MergesCrcs()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_existing_with_overlapping_crcs_groups.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 6);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(1, "My dev ROM");

            entry.AddCrc(3);
            entry.AddCrc(5);
            Assert.True(database.AddEntry(entry));

            var newEntry = new UserSpecifiedProgramInformation(2, "My other dev ROM");

            newEntry.AddCrc(3);
            newEntry.AddCrc(4);
            newEntry.AddCrc(5);
            newEntry.AddCrc(6);
            Assert.True(database.GroupWithExistingEntry(newEntry, entry));
            var expectedCrcs = new[] { 1u, 2u, 3u, 4u, 5u, 6u };

            Assert.Equal(expectedCrcs, entry.Crcs.OrderBy(c => c.Crc).Select(c => c.Crc));
        }
Esempio n. 2
0
        public void UserSpecifiedProgramInformationTable_InitializeNonExistentDatabase_CreatesExpectedDatabase()
        {
            UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(null);
            var databaseFilePath = "/nobody/home.xml";

            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath);

            Assert.NotNull(database);
            Assert.Empty(database.Programs);
        }
Esempio n. 3
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntryWithNullNewAndExistingEntry_ReturnsFalse()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_null_entries.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 2);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;

            Assert.False(database.GroupWithExistingEntry(null, null));
        }
Esempio n. 4
0
        public void UserSpecifiedProgramInformationTable_AddDatabaseEntry_AddsEntry()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/add_entry_to_database.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 0);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x98765432, "My dev ROM");

            Assert.True(database.AddEntry(entry));
        }
Esempio n. 5
0
        public void UserSpecifiedProgramInformationTable_Initialize_CreatesExpectedDatabase(int numberOfEntries)
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/initialize_with_no_entries_path.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, numberOfEntries);

            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath);

            Assert.NotNull(database);
            Assert.Equal(numberOfEntries, database.Programs.Count());
        }
Esempio n. 6
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntryWithNewEntryAndNullExistingEntry_ReturnsFalse()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_new_entry_null_existing.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 1);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;

            var newEntry = new UserSpecifiedProgramInformation(0x23457689, "My new dev ROM");

            Assert.False(database.GroupWithExistingEntry(newEntry, null));
        }
Esempio n. 7
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntryWithNullNewEntry_ThrowsNullReferenceException()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_null_new_entry.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 3);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x23457689, "My dev ROM");

            Assert.True(database.AddEntry(entry));

            Assert.Throws <NullReferenceException>(() => database.GroupWithExistingEntry(null, entry));
        }
Esempio n. 8
0
        public void UserSpecifiedProgramInformationTable_AddDuplicateDatabaseEntry_DoesNotAddEntry()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/add_duplicate_entry_to_database.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 8);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x23457689, "My dev ROM");

            Assert.True(database.AddEntry(entry));

            entry = new UserSpecifiedProgramInformation(0x23457689, "My other dev ROM");
            Assert.False(database.AddEntry(entry));
        }
Esempio n. 9
0
        public void UserSpecifiedProgramInformationTable_InitializeFromCorruptDatabase_CreatesExpectedDatabase()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/initialize_from_corrupt_database.xml";
            var numberOfEntries  = 0;

            storageAccess.AddDatabaseFile(databaseFilePath, numberOfEntries);
            storageAccess.IntroduceCorruption(databaseFilePath);

            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath);

            Assert.NotNull(database);
            Assert.Equal(numberOfEntries, database.Programs.Count());
        }
Esempio n. 10
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntryWithNoMatchingEntry_DoesNotGroupEntry()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_nonexisting_entry_does_not_group.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 9);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x98765432, "My dev ROM");

            Assert.True(database.AddEntry(entry));

            var newEntry = new UserSpecifiedProgramInformation(0x23457689, "My other dev ROM");

            Assert.False(database.GroupWithExistingEntry(entry, newEntry));
        }
Esempio n. 11
0
        public void UserSpecifiedProgramInformationTable_GroupWithExistingEntry_GroupsEntries()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/group_existing_groups.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 87);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x23457689, "My dev ROM");

            Assert.True(database.AddEntry(entry));

            var newEntry = new UserSpecifiedProgramInformation(0x98765432, "My other dev ROM");

            Assert.True(database.GroupWithExistingEntry(newEntry, entry));
            var expectedCrcs = new[] { 0x23457689u, 0x98765432u };

            Assert.Equal(expectedCrcs, entry.Crcs.Select(c => c.Crc));
        }
Esempio n. 12
0
        public void ProgramInformationTable_Initialize_()
        {
            IReadOnlyList <string> romPaths;
            var storageAccess     = ProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var database0FilePath = "/testing/database/user_specified_database_0.xml";

            storageAccess.AddDatabaseFile(database0FilePath, 2);
            var database1FilePath = "/testing/database/user_specified_database_1.xml";

            storageAccess.AddDatabaseFile(database1FilePath, 3);
            var database2FilePath = "/testing/database/user_specified_bogus_database.xml";

            var database = ProgramInformationTable.Initialize(
                new[]
            {
                new ProgramInformationTableDescriptor(database0FilePath, p => UserSpecifiedProgramInformationTable.Initialize(p)),
                new ProgramInformationTableDescriptor(database1FilePath, p => UserSpecifiedProgramInformationTable.Initialize(p)),
                new ProgramInformationTableDescriptor(database2FilePath, p => UserSpecifiedProgramInformationTable.Initialize(p)),
            });

            Assert.NotNull(database);
        }
Esempio n. 13
0
        public void UserSpecifiedProgramInformationTable_FindProgramWithProgramIdentifier_FindsProgramAsExpected(uint crc, bool expectedFound)
        {
            IReadOnlyList <string> romPaths;
            var storageAccess    = UserSpecifiedProgramInformationTableTestsStorageAccess.Initialize(out romPaths, null);
            var databaseFilePath = "/testing/database/find_by_program_info.xml";

            storageAccess.AddDatabaseFile(databaseFilePath, 4);
            var database = UserSpecifiedProgramInformationTable.Initialize(databaseFilePath) as UserSpecifiedProgramInformationTable;
            var entry    = new UserSpecifiedProgramInformation(0x98765432u, "My findable ROM");

            database.AddEntry(entry);

            var foundInfo = database.FindProgram(new ProgramIdentifier(crc, 0));

            if (expectedFound)
            {
                Assert.True(object.ReferenceEquals(entry, foundInfo));
            }
            else
            {
                Assert.Null(foundInfo);
            }
        }