Пример #1
0
        /// <summary>
        /// Checks whether any previously uncovered locations are covered in this new run
        /// </summary>
        internal void CheckForNewlyCoveredLocations()
        {
            foreach (var fss in this.FactorySuggestionsDictionary.Values)
            {
                foreach (var pucls in fss.locationStoreSpecificSequences.Values)
                {
                    if (pucls.IsDormat())
                    {
                        continue;
                    }

                    if (!pucls.AlreadyCovered && this.IsPrevUncoveredLocationCovered(pucls))
                    {
                        //this.Log.LogMessage("debug", "Covered the location: " + pucls.CodeLocation.ToString());
                        //StringBuilder sb = new StringBuilder();
                        //foreach (Method m in this.LastExecutedMethodCallSequence)
                        //{
                        //   sb.Append(m.ToString() + "\n");
                        //}
                        //this.Log.LogMessage("debug", "Sequence recorded: " + sb.ToString());

                        pucls.HitSequence = new MethodSignatureSequence();
                        foreach (Method m in this.LastExecutedFactoryMethodCallSequence)
                        {
                            pucls.HitSequence.Sequence.Add(MethodOrFieldAnalyzer.GetMethodSignature(m));
                        }
                        pucls.AlreadyCovered = true;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets a method store from a method signature
        /// </summary>
        /// <param name="msignature"></param>
        /// <param name="ms"></param>
        /// <returns></returns>
        public bool TryGetMethodStoreFromSignature(string msignature, out MethodStore ms)
        {
            foreach (var key in this.MethodDictionary.Keys)
            {
                string keysig = MethodOrFieldAnalyzer.GetMethodSignature(key);
                if (keysig == msignature)
                {
                    ms = this.MethodDictionary[key];
                    return(true);
                }
            }

            ms = null;
            return(false);
        }
Пример #3
0
        /// <summary>
        /// Accepts a method and returns the persistent string form "assemblyname#typename#methodsignature" of the method.
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public static string GetPersistentStringFormOfMethod(Method m)
        {
            var            assemblyname = m.Definition.Module.Assembly.Location;
            string         typename;
            TypeDefinition typedef = null;

            if (!m.Definition.TryGetDeclaringType(out typedef))
            {
                SafeDebug.AssumeNotNull(typedef, "Type definition is empty");
                typename = PexMeConstants.PexMeDummyTypeName;
            }
            else
            {
                typename = typedef.FullName;
            }

            var signature = MethodOrFieldAnalyzer.GetMethodSignature(m);

            return(assemblyname + PexMeConstants.PexMePersistenceFormSeparator
                   + typename + PexMeConstants.PexMePersistenceFormSeparator + signature);
        }
Пример #4
0
        /// <summary>
        /// Adds a field to an unsuccessful code location.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="fields"></param>
        public void AddFieldsOfUncoveredCodeLocations(CodeLocation location, SafeList <Field> fields, FieldModificationType fmt,
                                                      Term condition, string terms, int fitnessval, TypeEx explorableType, SafeList <TypeEx> allFieldTypes)
        {
            //No need to process this location.
            if (fields.Count == 0)
            {
                return;
            }

            Field  targetField;
            TypeEx declaringType;   //This declaring type is considered as explorable type in the rest of the analysis

            if (!PexMeFactoryGuesser.GetTargetExplorableField(this, fields, out targetField, out declaringType))
            {
                this.Log.LogError(WikiTopics.MissingWikiTopic, "factoryguesser",
                                  "Failed to retrieve the target field for uncovered location " + location.ToString());
                return;
            }

            //Compare the declaring type and actual explorable type.
            //If there is a inheritance relation, use the actual one
            if (explorableType.IsAssignableTo(declaringType))
            {
                declaringType = explorableType;
            }

            var uclskey = UncoveredCodeLocationStore.GetKey(location.ToString(), declaringType.ToString(), condition.UniqueIndex);
            UncoveredCodeLocationStoreList uclslist;

            if (!this.unCoveredLocationDic.TryGetValue(uclskey, out uclslist))
            {
                uclslist                           = new UncoveredCodeLocationStoreList();
                uclslist.Location                  = location;
                uclslist.ExplorableType            = declaringType.ToString();
                uclslist.TermIndex                 = condition.UniqueIndex;
                this.unCoveredLocationDic[uclskey] = uclslist;
            }

            var ucls = new UncoveredCodeLocationStore();

            ucls.Location       = location;
            ucls.ExplorableType = declaringType;
            ucls.TargetField    = targetField;
            ucls.AllFields.AddRange(fields);
            ucls.AllFieldTypes.AddRange(allFieldTypes);
            ucls.TermIndex = condition.UniqueIndex;
            //add the sequence of method calls
            ucls.MethodCallSequence = new MethodSignatureSequence();
            foreach (var m in this.LastExecutedFactoryMethodCallSequence)
            {
                ucls.MethodCallSequence.Sequence.Add(MethodOrFieldAnalyzer.GetMethodSignature(m));
            }
            ucls.IsADefectDetectingSequence = this.DefectDetectingSequence;
            ucls.CUTMethodCallSequence      = this.LastExecutedCUTMethodCallSequence;

            if (!uclslist.StoreList.Contains(ucls))
            {
                ucls.TextualTerms.Add(terms);
                ucls.DesiredFieldModificationType = fmt;
                ucls.Fitnessvalue = fitnessval;
                uclslist.StoreList.Add(ucls);
            }
        }