private void FullSerializeAndDeserialize() { // use the sample data to fake a project var srcProject = BuildSampleProject2(); var expectedTitle = SampleRomData.GetSampleUtf8CartridgeTitle(); srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0); srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0); // extract the bytes that would normally be in the SMC file (they only exist in code for this sample data) var romFileBytes = srcProject.Data.RomByteSource.Bytes.Select(e => e?.Byte ?? 0).ToList().ToList(); // save it to create an output byte stream, we'd normally write this to the disk var serializer = new ProjectXmlSerializer(); var outputBytes = serializer.Save(srcProject); // now do the reverse and load our output back as the input var(deserializedProject, warning) = serializer.Load(outputBytes); // final step, the loading process doesn't save the actual SMC file bytes, so we do it ourselves here deserializedProject.Project.Data.RomByteSource.SetBytesFrom(romFileBytes); // now we can do a full compare between the original project, and the project which has been cycled through // serialization and deserialization Assert.True(warning == ""); Assert.True(srcProject.Equals(deserializedProject.Project)); deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0); deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0); CartNameTests.TestRomCartTitle(deserializedProject.Project, expectedTitle); }
public static void CartNameInHeader() { // use the sample data to fake a project var srcProject = LoadSaveTest.BuildSampleProject2(); var expectedTitle = SampleRomData.GetSampleUtf8CartridgeTitle(); TestRomCartTitle(srcProject, expectedTitle); }
public static void BugfixRemoveLabelWhenSnesAddressSpaceEmpty1() { var project = SampleRomData.CreateSampleProject(); project.Data.Labels.Invoking(labelProvider => labelProvider .RemoveLabel(0xFF)) .Should().NotThrow <NullReferenceException>(); TestRemoveLabelFromNullByteIndex(project.Data.SnesAddressSpace); }
public static Project BuildSampleProject2() { var project2 = new Project { Data = SampleRomData.CreateSampleData().Data, }; project2.CacheVerificationInfo(); return(project2); }
/// <summary> /// Generate a sample of assembly output with the given settings /// </summary> /// <param name="baseSettings">Existing settings to base this generation on</param> /// <returns>Output of assembly generation as text</returns> /// <remarks> /// This is handy for UI and other areas where you want to quickly demo what the effect /// will be of various setting changes. We'll use a built-in sample ROM as our data source. /// </remarks> public static LogCreatorOutput.OutputResult GetSampleAssemblyOutput(LogWriterSettings baseSettings) { var sampleRomData = SampleRomData.CreateSampleData(); var lc = new LogCreator { Settings = baseSettings with { Structure = LogWriterSettings.FormatStructure.SingleFile, FileOrFolderOutPath = "", OutputToString = true, RomSizeOverride = sampleRomData.OriginalRomSizeBeforePadding, },
public static void TestGetFlatByteNonPadded() { // Get a byte from the sample data that is a real (i.e. non-padded) byte var sampleData = SampleRomData.CreateSampleData(); const int romOffset = 0x0A; const int snesAddress = 0x808000 + romOffset; var flatByte = ByteGraphUtil.BuildFlatDataFrom(sampleData.Data.SnesAddressSpace, snesAddress); Assert.NotNull(flatByte); Assert.NotNull(flatByte.Byte); Assert.Equal(0xC2, flatByte.Byte.Value); }
public static void TestGetFlatByteInRange() { // Get a byte from the sample data that is a padded (i.e. for sample ROMs we can create them with a different // size than their source data. in this one, we pad the ROM from a few hundred bytes and add zero'd bytes // until we reach 32k bytes). This test is mostly testing that we built the sample data correctly, in real // world scenarios, this would never fail because we're not doing padding. var sampleData = SampleRomData.CreateSampleData(); const int romOffset = 0xEB; const int snesAddress = 0x808000 + romOffset; Assert.True(romOffset >= sampleData.OriginalRomSizeBeforePadding); var flatByte = ByteGraphUtil.BuildFlatDataFrom(sampleData.Data.SnesAddressSpace, snesAddress); Assert.NotNull(flatByte); Assert.NotNull(flatByte.Byte); Assert.Equal(0x00, flatByte.Byte.Value); }