Ejemplo n.º 1
0
        private void WriteClass(ClassCoverageItem item)
        {
            if (item.filtered)
                return;

            writer.WriteStartElement ("class");
            writer.WriteAttributeString ("name", item.name);
            writer.WriteAttributeString ("fullname", item.FullName.Replace ('/', '.'));
            writer.WriteAttributeString ("namespace", item.Namespace);

            WriteCoverage (item);

            writer.WriteStartElement ("source");

            if (item.sourceFile != null) {
                writer.WriteAttributeString ("sourceFile", item.sourceFile.sourceFile);

                StreamReader infile = new StreamReader (item.sourceFile.sourceFile, Encoding.ASCII);
                int[] coverage = item.sourceFile.Coverage;
                int pos = 1;
                while (infile.Peek () > -1) {
                    int count;
                    if ((coverage != null) && (pos < coverage.Length))
                        count = coverage[pos];
                    else
                        count = -1;
                    writer.WriteStartElement ("l");
                    writer.WriteAttributeString ("line", "" + pos);
                    writer.WriteAttributeString ("count", "" + count);
                    string line = infile.ReadLine ();
                    writer.WriteString (line);
                    writer.WriteEndElement ();

                    pos++;
                }
            }

            writer.WriteEndElement ();
        }
Ejemplo n.º 2
0
        private void OnExpanded(QListViewItem item)
        {
            if (item is ClassItem)
            {
                // Create children on-demand
                ClassItem         classItem = (ClassItem)item;
                ClassCoverageItem klass     = classItem.Model;

                if (item.ChildCount() == 0)
                {
                    foreach (MethodCoverageItem method in klass.Methods)
                    {
                        string title = method.name;
                        if (title.Length > 64)
                        {
                            title = title.Substring(0,63) + "...)";
                        }

                        MethodItem methodItem = new MethodItem(classItem,title,method);
                    }
                }
            }
        }
Ejemplo n.º 3
0
	private void ProcessMethod (MethodDefinition monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info)
#endif
	{
		if (entry == null)
			// Compiler generated, abstract method etc.
			return;

		LineNumberEntry[] lines = entry.GetLineNumberTable ().LineNumbers;

		if (lines.Length == 0)
			return;

		int start_line = lines [0].Row;
		int end_line = lines [lines.Length - 1].Row;

		MethodCoverageItem method 
			= new MethodCoverageItem (klass, methodName);

		method.startLine = start_line;
		method.endLine = end_line;
#if USE_REFLECTION
		method.filtered = IsFiltered ("[" + monoMethod.DeclaringType.Assembly + "]" + monoMethod.DeclaringType + "::" + monoMethod.Name);
#else
		method.filtered = IsFiltered ("[" + monoMethod.DeclaringType.Module.Name + "]" + monoMethod.DeclaringType + "::" + monoMethod.Name);
#endif
		klass.methodsByMethod [monoMethod] = method;


		if (klass.sourceFile == null) {
			string sourceFile = entry.CompileUnit.SourceFile.FileName;

			SourceFileCoverageData source = (SourceFileCoverageData)sources [sourceFile];
			if (source == null) {
				source = new SourceFileCoverageData (sourceFile);
				sources [sourceFile] = source;
			}
			klass.sourceFile = source;
		}
			
		computeMethodCoverage (method, lines, cov_info);
	}
Ejemplo n.º 4
0
	private void ProcessMethod (MethodBase monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info)
Ejemplo n.º 5
0
	private ClassCoverageItem ProcessClass (TypeDefinition t)
#endif
	{
		string className = t.FullName;
		int nsindex = className.LastIndexOf (".");
		string namespace2;
		string scopedName;
		if (nsindex == -1) {
			namespace2 = "<GLOBAL>";
			scopedName = className;
		} else if (nsindex == 0) {
			namespace2 = "<GLOBAL>";
			scopedName = className.Substring (1);
		}
		else {
			namespace2 = className.Substring (0, nsindex);
			scopedName = className.Substring (nsindex + 1);
		}

		// Create namespaces
		NamespaceCoverageItem ns = (NamespaceCoverageItem)namespaces [namespace2];
		if (ns == null) {
			string nsPrefix = "";
			foreach (String nsPart in namespace2.Split ('.')) {
				if (nsPrefix == "")
					nsPrefix = nsPart;
				else
					nsPrefix = nsPrefix + "." + nsPart;
				NamespaceCoverageItem ns2 = (NamespaceCoverageItem)namespaces [nsPrefix];
				if (ns2 == null) {
					if (ns == null)
						ns2 = new NamespaceCoverageItem (this, nsPrefix);
					else
						ns2 = new NamespaceCoverageItem (ns, nsPrefix);
					namespaces [nsPrefix] = ns2;
				}
				ns = ns2;
			}					
		}

		ClassCoverageItem klass = (ClassCoverageItem)classes [className];
		if (klass == null) {
			klass = new ClassCoverageItem (ns);
			klass.name_space = namespace2;
			klass.name = scopedName;
			klass.type = t;
			klass.parent = ns;

#if USE_REFLECTION
			klass.filtered = IsFiltered ("[" + t.Assembly + "]" + className);
#else
			klass.filtered = IsFiltered ("[" + t.Module.Name + "]" + className);
#endif
			classes [className] = klass;
		}

		return klass;
	}
Ejemplo n.º 6
0
        public CoverageView(QWidget parent, String fileName) : base(parent)
        {
            SetRootIsDecorated(true);
            AddColumn("Classes");
            AddColumn("Lines Hit");
            AddColumn("Lines Missed");
            AddColumn("Coverage");

            sourceViews = new Hashtable();

            // TODO: Why the cast ?
            SetColumnAlignment(1, (int)Qt.AlignmentFlags.AlignCenter);
            SetColumnAlignment(2, (int)Qt.AlignmentFlags.AlignCenter);
            SetColumnAlignment(3, (int)Qt.AlignmentFlags.AlignCenter);

            QObject.Connect(this, SIGNAL("doubleClicked(QListViewItem)"),
                            this, SLOT("OnDoubleClick(QListViewItem)"));

            QObject.Connect(this,SIGNAL("expanded(QListViewItem)"),
                            this,SLOT("OnExpanded(QListViewItem)"));

            // TODO: This is not supported by current Qt#
            try {
                QObject.Connect(this,SIGNAL("contextMenuRequested(QListViewItem,QPoint,int)"),
                                this,SLOT("OnContextMenu(QListViewItem, QPoint, Int32)"));
            }
            catch (Exception) {
            }

            QPixmap namespaceOpenPixmap   = new QPixmap(namespace_open_xpm);
            QPixmap namespaceClosedPixmap = new QPixmap(namespace_closed_xpm);
            QPixmap classPixmap           = new QPixmap(class_xpm);

            model = new CoverageModel();
            foreach (string filter in DEFAULT_FILTERS)
            {
                model.AddFilter(filter);
            }
            model.ReadFromFile(fileName);

            QListViewItem rootItem = new TreeItem(this,"PROJECT",model);

            rootItem.SetOpen(true);

            Hashtable classes2 = model.Classes;

            namespaces = new Hashtable();

            foreach (string name in classes2.Keys)
            {
                ClassCoverageItem klass = (ClassCoverageItem)classes2 [name];

                if (klass.filtered)
                {
                    continue;
                }

                string        namespace2 = klass.name_space;
                NamespaceItem nsItem     = (NamespaceItem)namespaces [namespace2];
                if (nsItem == null)
                {
                    // Create namespaces
                    String        nsPrefix   = "";
                    QListViewItem parentItem = rootItem;
                    foreach (String nsPart in namespace2.Split('.'))
                    {
                        if (nsPrefix == "")
                        {
                            nsPrefix = nsPart;
                        }
                        else
                        {
                            nsPrefix = nsPrefix + "." + nsPart;
                        }

                        NamespaceCoverageItem nsModel = (NamespaceCoverageItem)model.Namespaces [nsPrefix];
                        if (nsModel.filtered)
                        {
                            break;
                        }

                        nsItem = (NamespaceItem)namespaces [nsPrefix];
                        if (nsItem == null)
                        {
                            nsItem = new NamespaceItem(parentItem,nsPrefix,
                                                       nsModel);
                            nsItem.SetOpen(true);
                            nsItem.SetPixmap(0,namespaceOpenPixmap);
                            namespaces [nsPrefix] = nsItem;
                        }
                        parentItem = nsItem;
                    }
                }

                if (nsItem != null)
                {
                    ClassItem classItem = new ClassItem(nsItem,klass.name,klass);
                    classItem.SetPixmap(0,classPixmap);
                    if (klass.ChildCount > 0)
                    {
                        classItem.SetExpandable(true);
                    }
                }
            }
        }
Ejemplo n.º 7
0
	private void WriteClass (ClassCoverageItem item) {
		if (item.filtered)
			return;

		// start class
		writer.WriteStartElement ("class");
		writer.WriteAttributeString ("name", item.name);
		writer.WriteAttributeString ("fullname", item.FullName.Replace('/', '.'));
		writer.WriteAttributeString ("namespace", item.Namespace);
		WriteCoverage (item);
		
		//		start source
		writer.WriteStartElement ("source");

		if (item.sourceFile != null) 
		{
			writer.WriteAttributeString ("sourceFile", item.sourceFile.sourceFile);

			int[] coverage = item.sourceFile.Coverage;
			
			foreach( MethodCoverageItem method in item.Methods )
			{
				int sum = 0;
				int length = method.endLine - method.startLine;
				for( int index = method.startLine; index < method.endLine; index++ )
				{
					if( coverage[index] > 0 )
						sum++;
				}
				if( length == 0 )
					continue;
				
				writer.WriteStartElement ("Method");
				writer.WriteAttributeString ("type", item.FullName);
				writer.WriteAttributeString ("method", method.Name);
				writer.WriteAttributeString ("coverage", "" + ((float)sum)/length );
				writer.WriteAttributeString ("length", "" + length );
				writer.WriteEndElement ();
			}
		}
		else
		{
		}
		// end source
		writer.WriteEndElement ();
		// end class
		writer.WriteEndElement ();
	}
Ejemplo n.º 8
0
 public MethodCoverageItem(ClassCoverageItem parent, String name)
     : base(parent)
 {
     this.name = name;
 }
Ejemplo n.º 9
0
        public CoverageView(string fileName, ProgressBar status)
        {
            store = new TreeStore(typeof(string), typeof(string), typeof(string), typeof(string), typeof(object));
            tree  = new TreeView(store);

            CellRendererText renderer         = new CellRendererText();
            CellRendererText coverageRenderer = new CellRendererText();

            // LAME: Why is this property a float instead of a double ?
            renderer.Xalign = 0.5f;

            tree.AppendColumn("Classes", new CellRendererText(), "text", 0);
            tree.AppendColumn("Lines Hit", renderer, "text", 1);
            tree.AppendColumn("Lines Missed", renderer, "text", 2);
            tree.AppendColumn("Coverage", coverageRenderer, "text", 3);

            tree.GetColumn(0).Resizable = true;
            tree.GetColumn(1).Alignment = 0.0f;
            tree.GetColumn(1).Resizable = true;
            tree.GetColumn(2).Alignment = 0.0f;
            tree.GetColumn(2).Resizable = true;
            tree.GetColumn(3).Alignment = 0.0f;
            tree.GetColumn(3).Resizable = true;
            tree.GetColumn(3).SetCellDataFunc(coverageRenderer, new TreeCellDataFunc(RenderCoverage));

            tree.HeadersVisible = true;

            model = new CoverageModel();
            foreach (string filter in DEFAULT_FILTERS)
            {
                model.AddFilter(filter);
            }
            this.status     = status;
            model.Progress += Progress;
            model.ReadFromFile(fileName);

            TreeItem root = new TreeItem(store, null, model, "PROJECT");

            Hashtable classes2 = model.Classes;

            namespaces = new Hashtable();
            string[] sorted_names = new string [classes2.Count];
            classes2.Keys.CopyTo(sorted_names, 0);
            Array.Sort(sorted_names);
            Progress("Building tree", 0.95);
            foreach (string name in sorted_names)
            {
                ClassCoverageItem klass = (ClassCoverageItem)classes2 [name];

                if (klass.filtered)
                {
                    continue;
                }

                string   namespace2 = klass.name_space;
                TreeItem nsItem     = (TreeItem)namespaces [namespace2];
                if (nsItem == null)
                {
                    nsItem = new TreeItem(store, root, (CoverageItem)model.Namespaces [namespace2], namespace2);
                    //				nsItem.SetPixmap (0, namespaceOpenPixmap);
                    namespaces [namespace2] = nsItem;
                }

                if (nsItem.model.filtered)
                {
                    continue;
                }

                ClassItem classItem = new ClassItem(store, nsItem, klass, klass.name);

                if (klass.ChildCount != 0)
                {
                    TreeIter treeIter = store.AppendNode(classItem.iter);
                    store.SetValues(treeIter, "<loading>");
                }
            }

            tree.ExpandRow(store.GetPath(root.Iter), false);

            // it becomes very hard to navigate if everything is expanded
            //foreach (string ns in namespaces.Keys)
            //	tree.ExpandRow (store.GetPath (((TreeItem)namespaces [ns]).Iter), false);

            tree.RowExpanded      += new RowExpandedHandler(OnRowExpanded);
            tree.RowCollapsed     += new RowCollapsedHandler(OnRowCollapsed);
            tree.ButtonPressEvent += new ButtonPressEventHandler(OnButtonPress);
            tree.Selection.Mode    = SelectionMode.Single;

            source_views = new Hashtable();
            window_maps  = new Hashtable();
            Progress("Done", 1.0);
            // LAME: Why doesn't widgets visible by default ???
            tree.Show();
        }