public RootItem CreateViewForCaseCoverage(MetaDataDescriptor mdata, CaseCoverageDescriptor ccdata, string srcRootPath)
        {
            if (mdata == null) throw new ArgumentNullException("null input: mdata");
            if (ccdata == null) throw new ArgumentNullException("null input: ccdata");
            m_mdata = mdata;
            bool srcView = !string.IsNullOrEmpty(srcRootPath);
            if (srcView && !mdata.HasSrcFileData)
                throw new ArgumentException("source file data view requested for metadata with incomplete SourceFile debug info");

            m_view = new RootItem();
            m_packageMap = new Dictionary<string, PackageItem>();
            m_srcFileMap = new Dictionary<string, SrcFileItem>();
            m_classMap = new Dictionary<string, ClassItem>();
            PackageItem packageItem = null;

            foreach (string key in mdata.ClassMap.Keys)
            {
                ClassDescriptor cls = mdata.ClassMap[key];
                string packageVMName = cls.PackageVMName;

                if (!m_packageMap.ContainsKey(packageVMName))
                {
                    string packageName = packageVMName.Length == 0 ? "default package" : VMNameConvert.VMNameToJavaName(packageVMName);
                    packageItem = new PackageItem(m_view, packageName, packageVMName);
                    m_packageMap.Add(packageVMName, packageItem);
                    m_view.AddChild(packageItem);
                }
                else packageItem = m_packageMap[packageVMName];

                SrcFileItem srcfileItem = null;
                if (srcView)
                {
                    string srcFileName = cls.SrcFileName;
                    if (srcFileName == null)
                        throw new ArgumentNullException("src file name = null");

                    string fullSrcFileName = VMNameConvert.CombineVMName(packageVMName, srcFileName);

                    if (!m_srcFileMap.ContainsKey(fullSrcFileName))
                    {
                        srcfileItem = new SrcFileItem(packageItem, srcFileName, fullSrcFileName);
                        m_srcFileMap.Add(fullSrcFileName, srcfileItem);

                        packageItem.AddChild(srcfileItem);
                    }
                    else srcfileItem = m_srcFileMap[fullSrcFileName];
                }

                CaseCoverageDataHolder data = ccdata.GetCoverage(cls);

                if (data != null)
                {
                    if (data.Stamp != cls.Stamp)
                        throw new Exception("class stamp mismatch:" + VMNameConvert.VMNameToJavaName(cls.ClassVMName));
                }

                HashSet<string>[][] coverage = (data != null ? data.CaseCoverage : null);

                ClassItem classItem = srcView ? new ClassItem(srcfileItem, cls, coverage) : new ClassItem(packageItem, cls, coverage);
                MethodDescriptor[] methods = cls.Methods;

                for (int m = 0; m < methods.Length; ++m)
                {
                    MethodDescriptor method = methods[m];

                    if ((method.Status & DataConstants.METHOD_NO_BLOCK_DATA) != 0)
                        continue;
                    MethodItem methodItem = new MethodItem(classItem, m, method.Name, method.Descriptor, method.FirstLine);
                    classItem.AddChild(methodItem);
                    for (int b = 0; b < method.BlockMap.Length; b++)
                    {
                        BlockItem blockItem = new BlockItem(methodItem, b, method.BlockMap[b], method.BlockSizes[b]);
                        methodItem.AddChild(blockItem);
                    }
                }

                if (srcView)
                {
                    srcfileItem.AddChild(classItem);
                    m_classMap.Add(classItem.Name, classItem);
                }
                else
                    packageItem.AddChild(classItem);

            }
            ComputeHashCode(srcRootPath);
            return m_view;
        }
Exemplo n.º 2
0
        private static ReportDataModel CreateModuleForCttr(string emFilePath, CttCaseCollection ecFilesPaths, string srcPath)
        {
            EmmaBinaryReader ebre = new EmmaBinaryReader(emFilePath);
            MetaDataDescriptor edata = (MetaDataDescriptor)LoadEmmaFile(ebre);
            ebre.Close();
            CaseCoverageDescriptor ccdata = new CaseCoverageDescriptor();

            foreach (CttCase cttCase in ecFilesPaths.CoverageFilePaths)
            {
                EmmaBinaryReader ebrc = new EmmaBinaryReader(cttCase.ResultPath);
                CoverageDataDescriptor cdata = (CoverageDataDescriptor)LoadEmmaFile(ebrc);
                ebrc.Close();

                ccdata.MergeCaseCoverageData(cdata, cttCase.CaseId);
            }

            ReportDataModel previous = new Report.ReportDataModel();
            RootItem root = previous.CreateViewForCaseCoverage(edata, ccdata, srcPath);
            return previous;
        }