private void Verify(SerializedSignature ssig, string outputFilename)
 {
     using (FileUnitTester fut = new FileUnitTester(outputFilename))
     {
         XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter);
         x.Formatting = Formatting.Indented;
         XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(ssig.GetType());
         ser.Serialize(x, ssig);
         fut.AssertFilesEqual();
     }
 }
		public void SudWrite()
		{
			Project_v1 ud = new Project_v1();
			ud.Input.Address = "0x1000:0x0";
			ud.Output.DisassemblyFilename = "foo.asm";
			ud.Output.IntermediateFilename = "foo.cod";
			Procedure_v1 proc = new Procedure_v1();
			proc.Name = "foo";
			proc.Signature = new SerializedSignature
			{
				ReturnValue = new Argument_v1
				{
					Kind = new Register_v1("eax")
				},
				Arguments = new Argument_v1[]
				{
					new Argument_v1
					{
						Kind = new StackVariable_v1(),
						Type = new PrimitiveType_v1(Domain.SignedInt, 4)
					},
					new Argument_v1
					{
						Kind = new StackVariable_v1(),
						Type = new PrimitiveType_v1(Domain.SignedInt, 4)
					}
				}
			};
			ud.UserProcedures.Add(proc);

			using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt"))
			{
			    var writer = new FilteringXmlWriter(fut.TextWriter);
				writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v1));
				ser.Serialize(writer, ud);
				fut.AssertFilesEqual();
			}
		}
        public void SlibCodeWrite()
        {
            var proj = new Project_v2
            {
                Inputs = {
                    new DecompilerInput_v2 {
                        UserGlobalData = {
                            new GlobalDataItem_v2 
                            {
                                 Address = "00100000",
                                 Name = "foo",
                                 DataType = new ArrayType_v1 {
                                     ElementType = new PointerType_v1 {
                                          PointerSize = 4,
                                          DataType = new CodeType_v1()
                                     },
                                     Length = 10,
                                 }
                            }
                        }
                    }
                }
            };
            var ser = SerializedLibrary.CreateSerializer_v2(typeof(Project_v2));
            var sw = new StringWriter();
            var writer = new FilteringXmlWriter(sw);
            writer.Formatting = Formatting.Indented;
            ser.Serialize(writer, proj);

            Debug.Print(sw.ToString());
            var sExp = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Decompiler/v2"">
  <input>
    <global>
      <Address>00100000</Address>
      <arr length=""10"">
        <ptr size=""4"">
          <code />
        </ptr>
      </arr>
      <Name>foo</Name>
    </global>
  </input>
  <output />
</project>";
            Assert.AreEqual(sExp, sw.ToString());
        }
		private void Verify(SerializedLibrary slib, string outputFile)
		{
			using (FileUnitTester fut = new FileUnitTester(outputFile))
			{
				XmlTextWriter writer = new FilteringXmlWriter(fut.TextWriter);
				writer.Formatting = Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(slib.GetType());
				ser.Serialize(writer, slib);

				fut.AssertFilesEqual();
			}
		}
 public void SudSaveProject()
 {
     Project project = new Project
     {
         Programs = 
         {
             new Program
             {
                 Image = new LoadedImage(Address.SegPtr(0x1000, 0), new byte[100]),
                 DisassemblyFilename = "foo.asm",
                 IntermediateFilename = "foo.cod",
                 UserProcedures = new SortedList<Address,Procedure_v1> 
                 {
                     { 
                         Address.SegPtr(0x1000, 0x10), 
                         new Procedure_v1
                         {
                             Name = "foo",
                             Signature = new SerializedSignature
                             {
                                 ReturnValue = new Argument_v1 { Kind = new Register_v1("eax") },
                                 Arguments = new Argument_v1[]
                                 {
                                     new Argument_v1
                                     {
                                         Kind = new StackVariable_v1(),
                                         Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                     },
                                     new Argument_v1
                                     {
                                         Kind = new StackVariable_v1(),
                                         Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                     }
                                 }
                             }
                         }
                     }
                 },
                 UserGlobalData =
                 {
                     { 
                       Address.SegPtr(0x2000, 0) ,
                       new GlobalDataItem_v2 {
                            Address = Address.SegPtr(0x2000, 0).ToString(),
                            DataType = new StringType_v2 { 
                                Termination=StringType_v2.ZeroTermination, 
                                CharType = new PrimitiveType_v1 { Domain = Domain.Character, ByteSize = 1 }
                            }
                       }
                       }
                 }
             }
         }
     };
     using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
     {
         FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
         writer.Formatting = System.Xml.Formatting.Indented;
         XmlSerializer ser = SerializedLibrary.CreateSerializer_v2(typeof(Project_v2));
         Project_v2 ud = new ProjectSaver().Save(project);
         ser.Serialize(writer, ud);
         fut.AssertFilesEqual();
     }
 }