Пример #1
0
 public void AddMethod(MethodCoverageItem method)
 {
     if (methods == null)
     {
         methods = new ArrayList();
     }
     methods.Add(method);
 }
Пример #2
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.LineNumbers;

            // DEBUG
            //if( cov_info == null )
            //	Console.WriteLine( lines.Length );
            // DEBUG

            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.SourceFile.FileName;

                SourceFileCoverageData source = (SourceFileCoverageData)sources [sourceFile];
                //Console.WriteLine( source );
                if (source == null)
                {
                    source = new SourceFileCoverageData(sourceFile);
                    sources [sourceFile] = source;
                }
                klass.sourceFile = source;
            }

            computeMethodCoverage(method, lines, cov_info);
        }
Пример #3
0
        //
        // Return a range of source lines which have something to do with OFFSET.
        //
        private bool GetSourceRangeFor(int offset, MethodCoverageItem method,
                                       LineNumberEntry[] lines,
                                       ref int startLine, ref int endLine)
        {
            for (int i = 0; i < lines.Length; ++i)
            {
                if (offset >= lines [i].Offset)
                {
                    if (i == lines.Length - 1)
                    {
                        startLine = lines [i].Row;
                        endLine   = lines [i].Row;
                        return(true);
                    }
                    else if (offset < lines [i + 1].Offset)
                    {
                        startLine = lines [i].Row;
                        endLine   = lines [i + 1].Row - 1;
                        return(true);
                    }
                }
            }

            if (offset <= lines [0].Offset)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < lines.Length; ++i)
                {
                    Console.WriteLine(lines [i]);
                }
                throw new Exception("Unable to determine source range for offset " + offset + " in " + method.name);
            }
        }
Пример #4
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);
	}
Пример #5
0
	//
	// Return a range of source lines which have something to do with OFFSET.
	//
	private bool GetSourceRangeFor (int offset, MethodCoverageItem method,
					   LineNumberEntry[] lines,
					   ref int startLine, ref int endLine)
	{
		for (int i = 0; i < lines.Length; ++i) {
			if (offset >= lines [i].Offset)
				if (i == lines.Length - 1) {
					startLine = lines [i].Row;
					endLine = lines [i].Row;
					return true;
				}
				else if (offset < lines [i + 1].Offset) {
					startLine = lines [i].Row;
					endLine = lines [i + 1].Row - 1;
					return true;
				}
		}

		if (offset <= lines [0].Offset) {
			return false;
		}
		else {
			for (int i = 0; i < lines.Length; ++i)
				Console.WriteLine (lines [i]);
			throw new Exception ("Unable to determine source range for offset " + offset + " in " + method.name);
		}
	}
Пример #6
0
	private void computeMethodCoverage (MethodCoverageItem method, LineNumberEntry[] lines, string cov_info)
	{

		ClassCoverageItem klass = method.Class;
		SourceFileCoverageData source = klass.sourceFile;

		source.AddMethod (method);

		int nlines = method.endLine - method.startLine + 1;

		int[] coverage = new int [nlines];

		if (cov_info == null) {
			for (int i = 0; i < nlines; ++i)
				coverage [i] = 0;
		}
		else {
			for (int i = 0; i < nlines; ++i)
				coverage [i] = -1;

			// Hand crafted parsing code since this is performance critical
			int pos = 0;
			int prev_offset = 0;
			while (pos < cov_info.Length) {
				int pos2 = cov_info.IndexOfAny (digits, pos);
				if (pos2 == -1)
					break;
				pos = cov_info.IndexOfAny (ws, pos2);
				if (pos == -1)
					break;

				int offset = parsePositiveInteger (cov_info, pos2);

				pos2 = cov_info.IndexOfAny (digits, pos);
				if (pos2 == -1)
					break;
				pos = cov_info.IndexOfAny (ws, pos2);

				int count = parsePositiveInteger (cov_info, pos2);

				offset += prev_offset;
				prev_offset = offset;

				int line1 = 0;
				int line2 = 0;

				bool found = GetSourceRangeFor (offset, method, lines, ref line1, ref line2);

				/*
				  if (found && (entry.Name.IndexOf ("Find") != -1)) {
				  Console.WriteLine ("OFFSET: " + offset + " " + line1 + ":" + line2);
				  }
				*/

				if (found) {
					for (int i = line1; i < line2 + 1; ++i)
						if ((i >= method.startLine) && (i <= method.endLine))
							if (coverage [i - method.startLine] < count)
								coverage [i - method.startLine] = count;
				}
			}
		}

		int hit = 0;
		int missed = 0;

		for (int i = 0; i < nlines; ++i) {
			int count = coverage [i];
			if (count > 0)
				hit ++;
			else if (count == 0)
				missed ++;
		}

		method.setCoverage (hit, missed);

		method.lineCoverage = coverage;
	}
Пример #7
0
        private void computeMethodCoverage(MethodCoverageItem method, LineNumberEntry[] lines, string cov_info)
        {
            ClassCoverageItem      klass  = method.Class;
            SourceFileCoverageData source = klass.sourceFile;

            source.AddMethod(method);

            int nlines = method.endLine - method.startLine + 1;

            int[] coverage = new int [nlines];

            if (cov_info == null)
            {
                for (int i = 0; i < nlines; ++i)
                {
                    coverage [i] = 0;
                }
            }
            else
            {
                for (int i = 0; i < nlines; ++i)
                {
                    coverage [i] = -1;
                }

                // Hand crafted parsing code since this is performance critical
                int pos         = 0;
                int prev_offset = 0;
                while (pos < cov_info.Length)
                {
                    int pos2 = cov_info.IndexOfAny(digits, pos);
                    if (pos2 == -1)
                    {
                        break;
                    }
                    pos = cov_info.IndexOfAny(ws, pos2);
                    if (pos == -1)
                    {
                        break;
                    }

                    int offset = parsePositiveInteger(cov_info, pos2);

                    pos2 = cov_info.IndexOfAny(digits, pos);
                    if (pos2 == -1)
                    {
                        break;
                    }
                    pos = cov_info.IndexOfAny(ws, pos2);

                    int count = parsePositiveInteger(cov_info, pos2);

                    offset     += prev_offset;
                    prev_offset = offset;

                    int line1 = 0;
                    int line2 = 0;

                    bool found = GetSourceRangeFor(offset, method, lines, ref line1, ref line2);

                    /*
                     * if (found && (entry.Name.IndexOf ("Find") != -1)) {
                     * Console.WriteLine ("OFFSET: " + offset + " " + line1 + ":" + line2);
                     * }
                     */

                    if (found)
                    {
                        for (int i = line1; i < line2 + 1; ++i)
                        {
                            if ((i >= method.startLine) && (i <= method.endLine))
                            {
                                if (coverage [i - method.startLine] < count)
                                {
                                    coverage [i - method.startLine] = count;
                                }
                            }
                        }
                    }
                }
            }

            int hit    = 0;
            int missed = 0;

            for (int i = 0; i < nlines; ++i)
            {
                int count = coverage [i];
                if (count > 0)
                {
                    hit++;
                }
                else if (count == 0)
                {
                    missed++;
                }
            }

            method.setCoverage(hit, missed);

            method.lineCoverage = coverage;
        }
	public void AddMethod (MethodCoverageItem method) {
		if (methods == null)
			methods = new ArrayList ();
		methods.Add (method);
	}