public void TestValidFile() { var df = DataFile.From(Properties.Resources.simple_layout); var result = SpecFile.Parse(df); Assert.False(string.IsNullOrEmpty(result.ToString())); Assert.Equal("bender.v1", result.Format); Assert.Equal("simple_layout", result.Name); Assert.Equal("A simple sample binary layout descriptor that can span multiple lines\n", result.Description); Assert.Equal(new List <string> { "test", "simple" }, result.Extensions); Assert.Equal(9, result.Elements.Count); var el = new Element { IsLittleEndian = true, Elide = false, PrintFormat = Bender.PrintFormat.Ascii, Units = 4, Name = "Undefined", Matrix = null, IsSigned = false }; Assert.Equal(el.IsLittleEndian, result.BaseElement.IsLittleEndian); Assert.Equal(el.Elide, result.BaseElement.Elide); Assert.Equal(el.PrintFormat, result.BaseElement.PrintFormat); Assert.Equal(el.Units, result.BaseElement.Units); Assert.Equal(el.Name, result.BaseElement.Name); Assert.Equal(el.Matrix, result.BaseElement.Matrix); Assert.Equal(el.IsSigned, result.BaseElement.IsSigned); Assert.False(string.IsNullOrEmpty(el.ToString())); }
public void TestParseMatchingSpec() { var spec = SpecFile.Parse(DataFile.FromAscii(TestData.SimpleTest)); var bender = new BinaryParser(spec).Parse(DataFile.From(Properties.Resources.simple_layout_binary)); Assert.NotNull(bender); }
public void TestParseDeferred() { var spec = SpecFile.Parse(DataFile.FromAscii(TestData.TestDeferred)); var bender = new BinaryParser(spec).Parse(DataFile.From(Properties.Resources.test_deferred_binary)); Assert.NotNull(bender); }
public void SpecReadInContextTest() { SpecFile spec = SpecFile.ParseContractFile("..\\..\\Contracts\\test.RnR", SpecFileFormat.Ini); string testBytesStr = @"03 F2 00 00 00 08 00 00 00 04 C8 02 00 B8"; byte[] readBytes = TypeCache.HexPatternStringToByteArray(testBytesStr); MemoryStream readSrc = new MemoryStream(readBytes); MemoryStream writeSrc = new MemoryStream(); using (StreamContext sc = new StreamContext(spec, readSrc, writeSrc)) { Dictionary <string, object> ReqDict = sc.GetContextRequest(); if (!SpecData.ReadAs <short>(ReqDict, "ESP_SuccessFlag").Equals((short)1010)) { Console.WriteLine("*读取数据错误!"); } else { sc.SetPosition(0); Dictionary <string, object> result = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); //result["ESP_SuccessFlag"] = (short)1010; result["ESP_SuccessFlag"] = "Success"; result["ESP_CustomCode"] = (int)0008; result["ESP_LeaveLength"] = (int)4; result["ESP_TransferData"] = TypeCache.HexPatternStringToByteArray(@"C8 02 00 B8"); sc.WriteContextResponse(result); } if (writeSrc.Length > 0) { string result = TypeCache.ByteArrayToHexString(writeSrc.ToArray()); Console.WriteLine(result); Debug.Assert(testBytesStr == result); } else { Console.WriteLine("*没有写入数据!"); } writeSrc.Dispose(); } }
public void ExpressionParseTest() { SpecFile spec = SpecFile.ParseContractFile("..\\..\\Contracts\\test.RnR", SpecFileFormat.Ini); string testBytesStr = @"03 F2 00 00 00 08 00 00 00 04 C8 02 00 B8"; byte[] readBytes = TypeCache.HexPatternStringToByteArray(testBytesStr); MemoryStream readSrc = new MemoryStream(readBytes); using (StreamContext sc = new StreamContext(spec, readSrc)) { Dictionary <string, object> ReqDict = sc.GetContextRequest(); SpecExpression specExp = new SpecExpression("{ ESP_CustomeCode == 8 }"); Debug.Assert(specExp.IsPass(sc)); specExp = new SpecExpression("{ ESP_SuccessFlag == 1010 }"); Debug.Assert(specExp.IsPass(sc)); specExp = new SpecExpression("{ ESP_LeaveLength == 4 }"); Debug.Assert(specExp.IsPass(sc)); } }
private void IdentifyTargets() { // iterate thru traces, looking for potential targets // given a target, check to see if it should be ignoreed (.scan { ignore-target:XXX }) var exesCreated = allProcesses.Where(process => process.files.Any(file => file.created && file.extension == ".exe")); var dllsCreated = allProcesses.Where(process => process.files.Any(file => file.created && file.extension == ".dll")); var libCreated = allProcesses.Except(dllsCreated).Where(process => process.files.Any(file => file.created && file.extension == ".lib")); var defaultTargetRules = (from targetRule in _targetRules where string.IsNullOrEmpty(targetRule.Parameter) && string.IsNullOrEmpty(targetRule.Id) select targetRule); // colate the different target types. var discoveredTargets = exesCreated.SelectMany(process => (from file in process.files where file.created && file.extension == ".exe" && !IgnoredTargets.HasWildcardMatch(file.FullPath, Environment.CurrentDirectory) && process.ToolType == ToolType.Linker select new { file, process, discoveredPath = Environment.CurrentDirectory.RelativePathTo(file.FullPath), targetName = Path.GetFileName(file.FullPath), })); discoveredTargets = discoveredTargets.Union(dllsCreated.SelectMany(process => (from file in process.files where file.created && file.extension == ".dll" && !IgnoredTargets.HasWildcardMatch(file.FullPath, Environment.CurrentDirectory) && process.ToolType == ToolType.Linker select new { file, process, discoveredPath = Environment.CurrentDirectory.RelativePathTo(file.FullPath), targetName = Path.GetFileName(file.FullPath), }))); discoveredTargets = discoveredTargets.Union(libCreated.SelectMany(process => (from file in process.files let relativePath = Environment.CurrentDirectory.RelativePathTo(file.FullPath) where file.created && file.extension == ".lib" && !IgnoredTargets.HasWildcardMatch(file.FullPath, Environment.CurrentDirectory) && process.ToolType == ToolType.Lib select new { file, process, discoveredPath = Environment.CurrentDirectory.RelativePathTo(file.FullPath), targetName = Path.GetFileName(file.FullPath), }))); // apply any rename operations var selectedTargets = from target in discoveredTargets join y in ( from rule in _targetRules from target in discoveredTargets where rule["original-name"].Any() && target.discoveredPath.IsWildcardMatch(rule["original-name"].FirstOrDefault().LValue) select new { rule, matchingPath = target.discoveredPath }) on target.discoveredPath equals y.matchingPath into j from each in j.DefaultIfEmpty() select new { target.file, target.process, target.discoveredPath, targetName = each != null ? each.rule.Parameter : target.targetName, rules = each != null ? defaultTargetRules.UnionSingleItem( each.rule ) : defaultTargetRules }; // rules that didn't have an original-name, are for creating targets from scratch. selectedTargets = selectedTargets.Union(from rule in _targetRules from target in discoveredTargets where !rule["original-name"].Any() && !string.IsNullOrEmpty(rule.Parameter) select new { file = (Toolkit.Trace.File) null, process = (Process) null, discoveredPath = string.Empty, targetName = rule.Parameter, rules = defaultTargetRules.UnionSingleItem( rule ) }); if (!selectedTargets.Any()) { // do more intensive guessing. var mainFiles = from fileList in ScanReports from eachFile in fileList.Files.Values where eachFile.HasMain select eachFile; // guess for files with main() selectedTargets = mainFiles.Where(f => !IgnoreMainFiles.HasWildcardMatch(f.Name)).Aggregate(selectedTargets, (current, f) => current.UnionSingleItem(new { file = (Toolkit.Trace.File) null, process = (Process) null, discoveredPath = string.Empty, targetName = Path.GetFileNameWithoutExtension(f.Name) + ".exe", rules = defaultTargetRules })); } foreach (var t in selectedTargets) { var spec = new SpecFile(); spec.Link.Output = t.targetName; Targets.Add(new Target { SpecFile = spec, LinkProcess = t.process, TargetRules = t.rules, }); } }
public void SpecImportTest() { SpecFile file = SpecFile.ParseContractFile("..\\..\\Contracts\\ResponseBase.spec", SpecFileFormat.Ini); Console.WriteLine(file.AllImportContracts.Length); }
protected void when_it_does_its_thing() { TheResult = new SpecFileParser(_theSpecFile).SpecFile; }
public void TestInvalidFile() { var df = DataFile.FromAscii(TestData.TestInvalidYAML); Assert.Throws <ParseException>(() => SpecFile.Parse(df)); }