public void AnalyzeSummary()
        {
            Console.WriteLine("Hello");

            using (var project = new DataProject <CompleteWorkingSet>(LocalProj, LocalProj, SrcmlLoc))
            {
                project.Update();
                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try
                {
                    // Step 1.   Build the call graph
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());
                    //Console.Read();
                    var methods = globalNamespace.GetDescendants <MethodDefinition>();
                    int i       = 0;
                    // Step 2.   Testing
                    Console.WriteLine("======  test 1 ========= ");
                    foreach (MethodDefinition method in methods)
                    {
                        Console.WriteLine("Method Name : {0}", method.GetFullName());
                        //colect basic ID information
                        var declaringClass = method.GetAncestors <TypeDefinition>().FirstOrDefault();
                        var className      = "";
                        if (declaringClass != null)
                        {
                            className = declaringClass.Name;
                        }
                        var nameSpaceName = GetNamespaceByMethod(method);


                        //for testing
                        //if (className != "CPlusPlusCodeParserTests") {
                        //    continue;
                        //}
                        //if (className != "BuiltInTypeFactoryTests") {
                        //    continue;
                        //}

                        //if (i > 10)
                        //{
                        //    continue;
                        //}


                        //if (method.Name != "CreateRequest_ETag")
                        //{
                        //    continue;
                        //}

                        if (IsTestCase(method))
                        {
                            SwumSummary swumSummary = new SwumSummary(method);
                            swumSummary.BasicSummary();
                            TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
                            //analyzer.GetTestingObject();
                            string desc = swumSummary.Describe();
                            //writetext.WriteLine(method.Name + "  ,  " + desc);
                            Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

                            TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
                            tcSummary.NameSpaceName = nameSpaceName;
                            tcSummary.ClassName     = className;
                            tcSummary.MethodName    = method.Name;

                            AllTestSummary.Add(tcSummary);
                            var stmts = method.GetDescendants <Statement>();

                            //delete me
                            //using (StreamWriter sw = File.AppendText(@"D:\d.csv"))
                            //{
                            //   var number = stmts.Count() + 2;
                            //   sw.WriteLine(method.Name + "," + number);
                            //    sw.Close();
                            //}
                            i++;
                        }
                    }
                }
                finally
                {
                    project.WorkingSet.ReleaseReadLock();
                }
            }


            //Console.ReadLine();
            //string dataDir = @"TESTNAIVE_1.0";
            //using (var project = new DataProject<CompleteWorkingSet>(dataDir, this.LocalProj, this.SrcmlLoc)) {

            //    //Console.WriteLine("============================");
            //    //string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
            //    //DateTime start = DateTime.Now, end;
            //    //Console.WriteLine("============================");
            //    //using (var unknownLog = new StreamWriter(unknownLogPath)) {
            //    //    project.UnknownLog = unknownLog;
            //    //    project.UpdateAsync().Wait();

            //    //}
            //    //end = DateTime.Now;
            //    project.Update();
            //    NamespaceDefinition globalNamespace;
            //    project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
            //    try {

            //        // Step 1.   Build the call graph
            //        Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
            //        Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants<NamespaceDefinition>().Count());
            //        Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants<TypeDefinition>().Count());
            //        Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants<MethodDefinition>().Count());
            //        var methods = globalNamespace.GetDescendants<MethodDefinition>();
            //        int i = 0;
            //        StreamWriter writetext = new StreamWriter("write.csv");
            //        foreach (var method in methods) {
            //            //colect basic ID information
            //            var declaringClass = method.GetAncestors<TypeDefinition>().FirstOrDefault();
            //            var className = "";
            //            if (declaringClass != null) {
            //                className = declaringClass.Name;
            //            }
            //            var nameSpaceName = GetNamespaceByMethod(method);


            //            //for testing
            //            //if (className != "CPlusPlusCodeParserTests") {
            //            //    continue;
            //            //}
            //            //if (className != "BuiltInTypeFactoryTests") {
            //            //    continue;
            //            //}
            //            //if (className == "ProgamElementTests" || className == "CPlusPlusCodeParserTests") {
            //            //    continue;
            //            //}

            //            //if (className != "CPlusPlusCodeParserTests") {

            //            //    continue;
            //            //}


            //            //if (className != "SourceLocationTests") {
            //            //    continue;
            //            //}


            //            //if (method.Name != "TestContains_DifferentLines") {
            //            //    continue;
            //            //}


            //            //if (method.Name != "TestSiblingsBeforeSelf_MissingChild") {
            //            //    continue;
            //            //}

            //            //if (i > 30) {
            //            //    continue;
            //            //}

            //            if (IsTestCase(method)) {
            //                i++;
            //                SwumSummary swumSummary = new SwumSummary(method);
            //                swumSummary.BasicSummary();
            //                TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
            //                //analyzer.GetTestingObject();
            //                string desc = swumSummary.Describe();
            //                //writetext.WriteLine(method.Name + "  ,  " + desc);
            //                Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

            //                TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
            //                tcSummary.NameSpaceName = nameSpaceName;
            //                tcSummary.ClassName = className;
            //                tcSummary.MethodName = method.Name;

            //                AllTestSummary.Add(tcSummary);
            //                i++;
            //            }


            //        }
            //        writetext.Close();
            //        //Console.WriteLine("total i :" + i);



            //    } finally {
            //        project.WorkingSet.ReleaseReadLock();
            //    }
            //}
        }
示例#2
0
 //When the list "methodsInfo" does not contain the information of a method "m", we could generate a new "desMethod" class for "m" and save the new class into lists.
 public desMethod newMethodInfo(MethodDefinition m)
 {
     desMethod typeM;
     SwumSummary swumSummary = new SwumSummary(m);
     swumSummary.BasicSummary();
     List<MethodDefinition> followers = new List<MethodDefinition>();
     List<MethodDefinition> finals = new List<MethodDefinition>();
     string desc = swumSummary.Describe();
     InvokeCallGraphGenerator tracer = new InvokeCallGraphGenerator(m, cgm);
     followers = tracer.traceToMethod();
     finals = tracer.traceToLastMethod();
     typeM = new desMethod(m, desc, followers, finals);
     methodsInfo.Add(typeM);
     return typeM;
 }