Ejemplo n.º 1
0
        private IncludeResolveStrategy CreateIncludeResolveStrategy()
        {
            string testDataDirectory = TestData.TestDataDirectory;

            Assert.IsNotNull(testDataDirectory);

            List <string> projectIncludeDirectories = new List <string>
            {
                Path.Combine(testDataDirectory, "DirA"),
                Path.Combine(testDataDirectory, "DirB")
            };

            List <string> interfaceIncludeDirectories = new List <string>
            {
                Path.Combine(testDataDirectory, "DirInterfaces")
            };

            List <string> externalIncludeDirectories = new List <string>
            {
                Path.Combine(testDataDirectory, "DirExternal")
            };

            AnalyzerSettings analyzerSettings         = AnalyzerSettings.CreateDefault();
            List <string>    systemIncludeDirectories = analyzerSettings.SystemIncludeDirectories;

            return(new IncludeResolveStrategy(projectIncludeDirectories, interfaceIncludeDirectories, externalIncludeDirectories, systemIncludeDirectories));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Logger.Init(Assembly.GetExecutingAssembly());

            if (args.Length < 1)
            {
                Logger.LogUserMessage("Usage: DsmSuite.Analyzer.Jdeps <settingsfile>");
            }
            else
            {
                FileInfo settingsFileInfo = new FileInfo(args[0]);
                if (!settingsFileInfo.Exists)
                {
                    AnalyzerSettings.WriteToFile(settingsFileInfo.FullName, AnalyzerSettings.CreateDefault());
                    Logger.LogUserMessage("Settings file does not exist. Default one created");
                }
                else
                {
                    AnalyzerSettings analyzerSettings = AnalyzerSettings.ReadFromFile(settingsFileInfo.FullName);
                    Logger.LoggingEnabled = analyzerSettings.LoggingEnabled;

                    ConsoleAction action = new ConsoleAction(analyzerSettings);
                    action.Execute();
                }
            }
        }
Ejemplo n.º 3
0
        public void TestSolutionNameWithoutGroup()
        {
            string testDataDirectory = TestData.TestDataDirectory;
            string solutionFilename  = Path.GetFullPath(Path.Combine(testDataDirectory, @"..\DsmSuite.sln"));

            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
            SolutionFile     solutionFile     = new SolutionFile(solutionFilename, analyzerSettings, null);

            Assert.AreEqual("DsmSuite.sln", solutionFile.Name);
        }
Ejemplo n.º 4
0
        public void TestSystemIncludeDirectoriesFound()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
            ProjectFile      projectFile      = CreateProjectFile(analyzerSettings);

            projectFile.Analyze();
            Assert.AreEqual(5, projectFile.SystemIncludeDirectories.Count);

            ImmutableHashSet <string> includes = projectFile.SystemIncludeDirectories.ToImmutableHashSet();

            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Windows Kits\8.1\Include\um"));
            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Windows Kits\8.1\Include\shared"));
            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt"));
            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"));
            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include"));
        }
Ejemplo n.º 5
0
        public void TestSourceFilesFound()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            analyzerSettings.Input.RootDirectory = TestData.RootDirectory;
            analyzerSettings.Input.SourceDirectories.Clear();
            analyzerSettings.Input.SourceDirectories.Add(TestData.RootDirectory);
            analyzerSettings.Input.ExternalIncludeDirectories.Clear();
            analyzerSettings.Input.IgnorePaths.Clear();
            analyzerSettings.Analysis.ResolveMethod = ResolveMethod.AddBestMatch;

            SourceDirectory sourceDirectory = new SourceDirectory(analyzerSettings);

            sourceDirectory.Analyze();
            const int numberOfHeaderFiles         = 7;
            const int numberOfImplementationFiles = 5;

            Assert.AreEqual(numberOfHeaderFiles + numberOfImplementationFiles, sourceDirectory.SourceFiles.Count);
        }
Ejemplo n.º 6
0
        public void TestVcxProjectFoundInCorrectFolder()
        {
            string testDataDirectory = TestData.TestDataDirectory;
            string solutionFilename  = Path.GetFullPath(Path.Combine(testDataDirectory, @"..\DsmSuite.sln"));

            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
            SolutionFile     solutionFile     = new SolutionFile(solutionFilename, analyzerSettings, null);

            solutionFile.Analyze();

            Assert.IsTrue(solutionFile.Projects.Count > 0);
            foreach (ProjectFile projectFile in solutionFile.Projects)
            {
                if (projectFile.ProjectName == "DsmSuite.Analyzer.VisualStudio.Test.Data")
                {
                    Assert.AreEqual("Analyzers.VisualStudioAnalyzer", projectFile.SolutionFolder);
                }
            }
        }
Ejemplo n.º 7
0
        public void TestExternalIncludeDirectoriesFound()
        {
            string           externalDir1     = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\DsmSuite.Analyzer.VisualStudio.Test\External1"));
            string           externalDir2     = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\DsmSuite.Analyzer.VisualStudio.Test\External2"));
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            analyzerSettings.ExternalIncludeDirectories.Add(new ExternalIncludeDirectory {
                Path = externalDir1, ResolveAs = "External1"
            });
            analyzerSettings.ExternalIncludeDirectories.Add(new ExternalIncludeDirectory {
                Path = externalDir2, ResolveAs = "External2"
            });
            ProjectFile projectFile = CreateProjectFile(analyzerSettings);

            projectFile.Analyze();
            Assert.AreEqual(2, projectFile.ExternalIncludeDirectories.Count);

            ImmutableHashSet <string> includes = projectFile.ExternalIncludeDirectories.ToImmutableHashSet();

            Assert.IsTrue(includes.Contains(externalDir1));
            Assert.IsTrue(includes.Contains(externalDir2));
        }
Ejemplo n.º 8
0
        public void TestAnalyzeFindsIncludes()
        {
            string        testDataDirectory = TestData.TestDataDirectory;
            FileInfo      fileInfo1         = new FileInfo(Path.Combine(testDataDirectory, @"DirA\ClassA2.cpp"));
            List <string> projectIncludes   = new List <string>
            {
                Path.Combine(testDataDirectory, "DirA"),
                Path.Combine(testDataDirectory, "DirB"),
                Path.Combine(testDataDirectory, "DirC"),
                Path.Combine(testDataDirectory, "DirD")
            };
            List <string> interfaceIncludes = new List <string>
            {
                Path.Combine(testDataDirectory, "DirInterfaces")
            };
            List <string> externalIncludes = new List <string>();

            projectIncludes.Add(Path.Combine(testDataDirectory, "DirExternal"));
            List <string> systemIncludes = AnalyzerSettings.CreateDefault().SystemIncludeDirectories;

            IncludeResolveStrategy includeResolveStrategy = new IncludeResolveStrategy(projectIncludes, interfaceIncludes, externalIncludes, systemIncludes);
            SourceFile             sourceFile             = new SourceFile(fileInfo1, null, includeResolveStrategy);

            sourceFile.Analyze();

            ImmutableHashSet <string> includes = sourceFile.Includes.ToImmutableHashSet();

            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirA\ClassA2.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirA\ClassA1.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirB\ClassB1.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirC\ClassC1.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirD\ClassD1.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirExternal\External.h")));
            Assert.IsTrue(includes.Contains(Path.Combine(testDataDirectory, @"DirInterfaces\ClassA3.h")));
            Assert.IsTrue(includes.Contains(@"C:\Program Files (x86)\Windows Kits\8.1\Include\um\windows.h"));
            Assert.AreEqual(8, sourceFile.Includes.Count);
        }
Ejemplo n.º 9
0
        public void TestAnalyzePhysicalView()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            analyzerSettings.ExternalIncludeDirectories.Clear();
            analyzerSettings.ViewMode      = ViewMode.PhysicalView;
            analyzerSettings.InputFilename = Path.Combine(TestData.SolutionDirectory, "DsmSuite.sln");
            analyzerSettings.ExternalIncludeDirectories.Add(new ExternalIncludeDirectory {
                Path = Path.Combine(TestData.TestDataDirectory, "DirExternal"), ResolveAs = "External"
            });
            analyzerSettings.InterfaceIncludeDirectories.Add(Path.Combine(TestData.TestDataDirectory, "DirInterfaces"));
            analyzerSettings.RootDirectory = TestData.SolutionDirectory;

            DsiModel dataModel = new DsiModel("Test", Assembly.GetExecutingAssembly());

            Analyzer.VisualStudio.Analysis.Analyzer analyzer = new Analyzer.VisualStudio.Analysis.Analyzer(dataModel, analyzerSettings, null);
            analyzer.Analyze();

            HashSet <string> elementNames = new HashSet <string>();
            Dictionary <string, HashSet <string> > providerNames = new Dictionary <string, HashSet <string> >();

            foreach (IDsiElement element in dataModel.GetElements())
            {
                elementNames.Add(element.Name);

                foreach (IDsiRelation relation in dataModel.GetRelationsOfConsumer(element.Id))
                {
                    if (!providerNames.ContainsKey(element.Name))
                    {
                        providerNames[element.Name] = new HashSet <string>();
                    }

                    IDsiElement provider = dataModel.FindElementById(relation.ProviderId);
                    providerNames[element.Name].Add(provider.Name);
                }
            }

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA3.h"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.Identical.ClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.Identical.CopyClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.NotIdentical.ClassA1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirIDL.IInterface1.idl"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface1_i.c"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.MyTypeLibrary.tlb"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirIDL.IInterface2.idl"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface2.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface2_i.c"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.DsmSuite.Analyzer.VisualStudio.Test.Data.tlb"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.targetver.h"));

            Assert.IsTrue(elementNames.Contains("External.External.h"));

            HashSet <string> classA2ProviderNames = providerNames["DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.cpp"];

            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.h"));

            Assert.IsTrue(classA2ProviderNames.Contains("External.External.h"));

            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA3.h"));
        }
Ejemplo n.º 10
0
        private ProjectFile CreateProjectFile()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            return(CreateProjectFile(analyzerSettings));
        }