public static void AddBlock(CoverageReport.InnerBlockData bData, CoverageReport.InnerBlock inner) { CoverageReport.InnerBlock[] newBlocks = new CoverageReport.InnerBlock[bData.blocks.Length + 1]; bData.blocks.CopyTo(newBlocks, 1); newBlocks[0] = inner; bData.blocks = newBlocks; }
public static void AddMethodBlock(CoverageReport.MethodDescriptor dMethod, CoverageReport.InnerBlock inner) { CoverageReport.InnerBlockData bData = dMethod.insBlocks[0]; CoverageReport.InnerBlock[] newBlocks = new CoverageReport.InnerBlock[bData.blocks.Length + 1]; bData.blocks.CopyTo(newBlocks, 1); newBlocks[0] = inner; bData.blocks = newBlocks; }
public static void AddType(CoverageReport report, CoverageReport.TypeDescriptor dType) { CoverageReport.TypeDescriptor existingType = FindExistingType(report, dType); if (existingType == null) { CoverageReport.TypeDescriptor[] newTypes = new CoverageReport.TypeDescriptor[report.types.Length + 1]; report.types.CopyTo(newTypes, 1); newTypes[0] = dType; report.types = newTypes; return; } foreach (CoverageReport.MethodDescriptor md in dType.methods) { CoverageReport.MethodDescriptor existingMethod = FindExistingMethod(existingType, md); if (existingMethod == null) { CoverageReport.MethodDescriptor[] newMethods = new CoverageReport.MethodDescriptor[existingType.methods.Length + 1]; existingType.methods.CopyTo(newMethods, 1); newMethods[0] = md; existingType.methods = newMethods; continue; } Debug.Assert(md.insBlocks.Length == 1); CoverageReport.InnerBlockData existingBlockData = FindExistingBlockData(existingMethod.insBlocks, md.insBlocks[0]); if (existingBlockData == null) { CoverageReport.InnerBlockData[] newBlocks = new CoverageReport.InnerBlockData[existingMethod.insBlocks.Length + 1]; existingMethod.insBlocks.CopyTo(newBlocks, 1); newBlocks[0] = md.insBlocks[0]; existingMethod.insBlocks = newBlocks; } else { for (int i = 0; i < existingBlockData.blocks.Length; ++i) { CoverageReport.InnerBlock existingBlock = existingBlockData.blocks[i]; CoverageReport.InnerBlock newBlock = FindBlock(md.insBlocks[0].blocks, existingBlock); Debug.Assert(newBlock != null); existingBlock.visitCount += newBlock.visitCount; } } } }
private static CoverageReport.InnerBlockData FindExistingBlockData(CoverageReport.InnerBlockData[] datas, CoverageReport.InnerBlockData bData) { foreach (CoverageReport.InnerBlockData dataBlock in datas) { if (dataBlock.blocks.Length != bData.blocks.Length) { continue; } bool validBlock = true; for (int i = 0; validBlock && i < dataBlock.blocks.Length; ++i) { CoverageReport.InnerBlock existingBlock = dataBlock.blocks[i]; CoverageReport.InnerBlock newBlock = FindBlock(bData.blocks, existingBlock); validBlock = newBlock != null; } if (validBlock) { return(dataBlock); } } return(null); }
private static CoverageReport.InnerBlock FindBlock(CoverageReport.InnerBlock[] blocks, CoverageReport.InnerBlock block) { foreach (CoverageReport.InnerBlock dataBlock in blocks) { if (dataBlock.position != block.position || dataBlock.blockLen != block.blockLen) { continue; } if (dataBlock.fileId == block.fileId && dataBlock.startLine == block.startLine && dataBlock.startColumn == block.startColumn && dataBlock.endLine == block.endLine && dataBlock.endColumn == block.endColumn) { return(dataBlock); } } return(null); }
internal static float GetBlockCoverage(CoverageReport.InnerBlock ib) { return(ib.visitCount > 0 ? 100 : 0); }
public static void ReadReport(CoverageReport report, TextReader reader) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); //Get Main Element PartCoverReport... XmlNode root = xmlDocument.SelectSingleNode("/PartCoverReport"); if (root == null) { throw new Exception("Bad xml format"); } //Look for Main Element's ver attribute... XmlAttribute verAttribute = root.Attributes["ver"]; if (verAttribute == null) { throw new Exception("Bad xml format"); } //Main Element will have a bunch of file Nodes... foreach (XmlNode fileNode in xmlDocument.SelectNodes("/PartCoverReport/file")) { ReportHelper.AddFile ( report, ReportHelper.GetAttributeAsUInt32(fileNode, "id"), ReportHelper.GetAttributeAsString(fileNode, "url") ); } foreach (XmlNode typeNode in xmlDocument.SelectNodes("/PartCoverReport/type")) { CoverageReport.TypeDescriptor dType = new CoverageReport.TypeDescriptor(); dType.assemblyName = ReportHelper.GetAttributeAsString(typeNode, "asm"); dType.typeName = ReportHelper.GetAttributeAsString(typeNode, "name"); dType.flags = ReportHelper.GetAttributeAsUInt32(typeNode, "flags"); foreach (XmlNode methodNode in typeNode.SelectNodes("method")) { CoverageReport.MethodDescriptor dMethod = new CoverageReport.MethodDescriptor(0); dMethod.methodName = ReportHelper.GetAttributeAsString(methodNode, "name"); dMethod.methodSig = ReportHelper.GetAttributeAsString(methodNode, "sig"); dMethod.flags = ReportHelper.GetAttributeAsUInt32(methodNode, "flags"); dMethod.implFlags = ReportHelper.GetAttributeAsUInt32(methodNode, "iflags"); foreach (XmlNode blockNode in methodNode.SelectNodes("code")) { CoverageReport.InnerBlockData dBlock = new CoverageReport.InnerBlockData(); foreach (XmlNode pointNode in blockNode.SelectNodes("pt")) { CoverageReport.InnerBlock dPoint = new CoverageReport.InnerBlock(); dPoint.visitCount = ReportHelper.GetAttributeAsUInt32(pointNode, "visit"); dPoint.position = ReportHelper.GetAttributeAsUInt32(pointNode, "pos"); dPoint.blockLen = ReportHelper.GetAttributeAsUInt32(pointNode, "len"); if (pointNode.Attributes["fid"] != null) { dPoint.fileId = ReportHelper.GetAttributeAsUInt32(pointNode, "fid"); dPoint.startLine = ReportHelper.GetAttributeAsUInt32(pointNode, "sl"); dPoint.startColumn = ReportHelper.GetAttributeAsUInt32(pointNode, "sc"); dPoint.endLine = ReportHelper.GetAttributeAsUInt32(pointNode, "el"); dPoint.endColumn = ReportHelper.GetAttributeAsUInt32(pointNode, "ec"); } ReportHelper.AddBlock(dBlock, dPoint); } ReportHelper.AddBlockData(dMethod, dBlock); } ReportHelper.AddMethod(dType, dMethod); } ReportHelper.AddType(report, dType); } }
public static void ReadReport(CoverageReport report, TextReader reader) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); //Get Main Element PartCoverReport... XmlNode root = xmlDocument.SelectSingleNode("/PartCoverReport"); if (root == null) throw new Exception("Bad xml format"); //Look for Main Element's ver attribute... XmlAttribute verAttribute = root.Attributes["ver"]; if (verAttribute == null) throw new Exception("Bad xml format"); //Main Element will have a bunch of file Nodes... foreach (XmlNode fileNode in xmlDocument.SelectNodes("/PartCoverReport/file")) { ReportHelper.AddFile ( report, ReportHelper.GetAttributeAsUInt32(fileNode, "id"), ReportHelper.GetAttributeAsString(fileNode, "url") ); } foreach(XmlNode typeNode in xmlDocument.SelectNodes("/PartCoverReport/type")) { CoverageReport.TypeDescriptor dType = new CoverageReport.TypeDescriptor(); dType.assemblyName = ReportHelper.GetAttributeAsString(typeNode, "asm"); dType.typeName = ReportHelper.GetAttributeAsString(typeNode, "name"); dType.flags = ReportHelper.GetAttributeAsUInt32(typeNode, "flags"); foreach(XmlNode methodNode in typeNode.SelectNodes("method")) { CoverageReport.MethodDescriptor dMethod = new CoverageReport.MethodDescriptor(0); dMethod.methodName = ReportHelper.GetAttributeAsString(methodNode, "name"); dMethod.methodSig = ReportHelper.GetAttributeAsString(methodNode, "sig"); dMethod.flags = ReportHelper.GetAttributeAsUInt32(methodNode, "flags"); dMethod.implFlags = ReportHelper.GetAttributeAsUInt32(methodNode, "iflags"); foreach(XmlNode blockNode in methodNode.SelectNodes("code")) { CoverageReport.InnerBlockData dBlock = new CoverageReport.InnerBlockData(); foreach(XmlNode pointNode in blockNode.SelectNodes("pt")) { CoverageReport.InnerBlock dPoint = new CoverageReport.InnerBlock(); dPoint.visitCount = ReportHelper.GetAttributeAsUInt32(pointNode, "visit"); dPoint.position = ReportHelper.GetAttributeAsUInt32(pointNode, "pos"); dPoint.blockLen = ReportHelper.GetAttributeAsUInt32(pointNode, "len"); if (pointNode.Attributes["fid"] != null) { dPoint.fileId = ReportHelper.GetAttributeAsUInt32(pointNode, "fid"); dPoint.startLine = ReportHelper.GetAttributeAsUInt32(pointNode, "sl"); dPoint.startColumn = ReportHelper.GetAttributeAsUInt32(pointNode, "sc"); dPoint.endLine = ReportHelper.GetAttributeAsUInt32(pointNode, "el"); dPoint.endColumn = ReportHelper.GetAttributeAsUInt32(pointNode, "ec"); } ReportHelper.AddBlock(dBlock, dPoint); } ReportHelper.AddBlockData(dMethod, dBlock); } ReportHelper.AddMethod(dType, dMethod); } ReportHelper.AddType(report, dType); } }