示例#1
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);
        }