public void TestFile(string filename) { MemoryStream writeStream = new MemoryStream(); MemoryStream readStream = new MemoryStream(); WebAssemblyFile file = new WebAssemblyFile(); // Read and save file file.ParseAsWASM(filename, false); file.SaveAsWASM(writeStream); // Assert that BinarySize is in fact correct. No need to test individual sizeofs as writeStream is summed anyways Assert.AreEqual <long>(writeStream.Position, file.BinarySize()); using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { fs.CopyTo(readStream); } // Sanity check size on disk is in fact what we read Assert.AreEqual((new FileInfo(filename)).Length, readStream.Position); // Check that streams are the same Assert.AreEqual(writeStream.Position, readStream.Position); // Todo: For large files, should do buffered comparisons rather than using .ToArray() // ToArray doesn't require us to seek back to 0 //writeStream.Seek(0, SeekOrigin.Begin); //readStream.Seek(0, SeekOrigin.Begin); Assert.IsTrue(writeStream.ToArray().SequenceEqual(readStream.ToArray())); }
public static int Main(string[] args) { Options options = new Options(args); if (options.Help) { logger.Info(options.GetHelp()); return(1); } else { logger.Info($"{Process.GetCurrentProcess().ProcessName} {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}"); if (options.Debug) { LogManager.Configuration.Variables["minimumLogLevel"] = "Trace"; LogManager.ReconfigExistingLoggers(); } else if (options.Verbose) { LogManager.Configuration.Variables["minimumLogLevel"] = "Debug"; LogManager.ReconfigExistingLoggers(); } } try { WebAssemblyFile file = new WebAssemblyFile(); file.ParseAsWASM(options.Filenames[0], options.Strict); if (options.Run != null) { logger.Debug($"Setting start section to {options.Run}."); file.start = new StartSection((uint)options.Run); } if (options.Run != null || options.Execute) { WebAssemblyInterpreter interpreter = new WebAssemblyInterpreter(file); return(interpreter.Run()); } } catch (Exception ex) { logger.Fatal(ex, $"Exception: {ex.Message}"); } return(0); }