コード例 #1
0
        public void ScanTextWithDuplicateTerms()
        {
            MockTermTable table1 = new MockTermTable("file1");
            MockTerm      term1  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table1);

            term1.AddExclusion("foo exclusion 1");
            term1.AddExclusion("foo exclusion 2");
            table1.AddSearchTerm(term1);

            MockTermTable table2 = new MockTermTable("file1");
            MockTerm      term2  = new MockTerm("foo", 1, "fooClass2", "fooComment2", "fooRecommended", table2);

            term2.AddExclusion("foo exclusion 2");
            term2.AddExclusion("foo exclusion 3");
            table2.AddSearchTerm(term2);

            IList <IScanHit> hits = InternalScanText("'foo exclusion 2' should be excluded, 'foo exclusion 1' and 'foo exclusion 3' should not", new ITermTable[] { table1, table2 });

            Assert.AreEqual(2, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term2, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(39, hits[0].Column, "Column property of hit 0 is incorrect.");
            Assert.IsNotNull(hits[0].Warning, "Hit 0 did not have a warning.");
            Assert.AreEqual(term1, hits[1].Term, "Term property of hit 1 is incorrect.");
            Assert.AreEqual(0, hits[1].Line, "Line property of hit 1 is incorrect.");
            Assert.AreEqual(61, hits[1].Column, "Column property of hit 1 is incorrect.");
            Assert.IsNotNull(hits[1].Warning, "Hit 0 did not have a warning.");
        }
コード例 #2
0
        public void TestIgnore()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            Project project = Utilities.SetupMSBuildProject();

            Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("dupText", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term2Text", 2, "term2Class", "term2Comment", "term2recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 5, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanHit    hit2       = new MockScanHit("file2", 3, 2, "line text 3", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1, hit2 }, true);

            accessor.AddResult(scanResult, project.FullPath);

            IVsEnumTaskItems enumerator = null;

            accessor.EnumTaskItems(out enumerator);
            List <IVsTaskItem> items = Utilities.TasksFromEnumerator(enumerator);

            CodeSweep.VSPackage.Task_Accessor task0Accessor = new CodeSweep.VSPackage.Task_Accessor(new PrivateObject(items[0]));
            CodeSweep.VSPackage.Task_Accessor task1Accessor = new CodeSweep.VSPackage.Task_Accessor(new PrivateObject(items[1]));

            MockTaskList taskList = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            // Ensure cmd is disabled with no selection
            OleMenuCommandService mcs     = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            MenuCommand           command = mcs.FindCommand(new CommandID(CodeSweep.VSPackage.GuidList_Accessor.guidVSPackageCmdSet, (int)CodeSweep.VSPackage.PkgCmdIDList_Accessor.cmdidIgnore));

            // NOTE: simply getting command.Supported or command.Enabled doesn't seem to invoke
            // QueryStatus, so I'll explicitly call the status update method as a workaround.
            accessor.QueryIgnore(null, EventArgs.Empty);

            Assert.IsTrue(command.Supported, "Command not supported.");
            Assert.IsFalse(command.Enabled, "Command enabled with no selection.");

            // Ensure cmd is disabled with an ignored item selected
            task0Accessor.Ignored = true;
            taskList.SetSelected(items[0], true);
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsFalse(command.Enabled, "Command enabled with ignored item selected.");

            // Ensure cmd is enabled with one ignored and one non-ignored item selected
            taskList.SetSelected(items[1], true);
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsTrue(command.Enabled, "Command disabled with a non-ignored item selected.");

            // Fire cmd, ensure selected items are ignored
            command.Invoke();
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsTrue(task0Accessor.Ignored, "Command set ignored task to non-ignored.");
            Assert.IsTrue(task1Accessor.Ignored, "Command did not set non-ignored task to ignored.");

            // Ensure cmd is now disabled
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsFalse(command.Enabled, "Command still enabled after invocation.");
        }
コード例 #3
0
        public void AddResultsThenClear()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            // Add some tasks
            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("term0Text", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term1Text", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            Assert.AreEqual(2, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks.");

            accessor.Clear();

            hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            tasks = Utilities.TasksFromEnumerator(enumerator);
            Assert.AreEqual(0, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks after Clear().");
        }
コード例 #4
0
        public void TestReset()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(term);

            CodeSweep.Scanner.MatchFinder_Accessor accessor = new CodeSweep.Scanner.MatchFinder_Accessor(new ITermTable[] { table });

            IList <IScanHit> hits1 = InternalScanText("foo bar ", accessor);

            Assert.AreEqual(1, hits1.Count, "First search returned wrong number of hits.");
            Assert.AreEqual(0, hits1[0].Column, "Column property of first hit is incorrect.");

            IList <IScanHit> hits2 = InternalScanText("foo bar", accessor);

            // This is what happens if you DON'T call Reset...
            Assert.AreEqual(1, hits2.Count, "Second search returned wrong number of hits.");
            Assert.AreEqual(8, hits2[0].Column, "Column property of second hit is incorrect.");

            accessor.Reset();

            IList <IScanHit> hits3 = InternalScanText("foo bar", accessor);

            Assert.AreEqual(1, hits3.Count, "Third search returned wrong number of hits.");
            Assert.AreEqual(0, hits3[0].Column, "Column property of third hit is incorrect.");
        }
コード例 #5
0
        private bool TestTokenMatchWithSpecificSurround(string before, string after)
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText(before + "foo" + after, new ITermTable[] { table });

            return(hits.Count == 1);
        }
コード例 #6
0
        public void ScanTextWithTermInMiddleOfExclusion()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("abcdef", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("this time the term (abcdef) is in the middle");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("foo - this time the term (abcdef) is in the middle - bar", new ITermTable[] { table });

            Assert.AreEqual(0, hits.Count, "Search returned wrong number of hits.");
        }
コード例 #7
0
        public void ScanTextWithTermAtEndOfExclusion()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("abcdef", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("the text at the end of this exclusion is abcdef");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("the text at the end of this exclusion is abcdef", new ITermTable[] { table });

            Assert.AreEqual(0, hits.Count, "Search returned wrong number of hits.");
        }
コード例 #8
0
        public void ScanTextWithTermAppearingMultipleTimesInExclusion()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("smurf", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("a smurf a day keeps the smurf away");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("foo - a smurf a day keeps the smurf away - bar", new ITermTable[] { table });

            Assert.AreEqual(0, hits.Count, "Search returned wrong number of hits.");
        }
コード例 #9
0
        public void ScanTextWithTermPartiallyOverlappingExclusion()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("a foo is not a fo");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("a foo is not a foo bar", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(15, hits[0].Column, "Column property of hit 0 is incorrect.");
        }
コード例 #10
0
        public void ScanTextWithDifferentCase()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("this Foo is excluded");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("THIS FOO IS EXCLUDED, BUT THIS FOO IS NOT", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(31, hits[0].Column, "Column property of hit 0 is incorrect.");
        }
コード例 #11
0
        private void InternalScanWithInvalidEntries(bool useCallback)
        {
            IScanner target = Factory.GetScanner();

            List <string> filePaths = new List <string>();

            // Hold a file open with non-shared access so it can't be opened by the scanner.
            string     holdOpen = Utilities.CreateTempTxtFile("some text");
            FileStream file     = File.Open(holdOpen, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);

            filePaths.Add("z:\nonexistant.cpp");
            filePaths.Add(Utilities.CreateTempTxtFile("line 1\nline 2\nline 3"));
            filePaths.Add(holdOpen);

            MockTermTable table = new MockTermTable("file");

            IMultiFileScanResult scanResults;

            if (useCallback)
            {
                List <IScanResult> callbackResults = new List <IScanResult>();
                scanResults = target.Scan(filePaths, new ITermTable[] { table }, delegate(IScanResult result) { callbackResults.Add(result); });

                int i = 0;
                foreach (IScanResult result in scanResults.Results)
                {
                    Assert.AreEqual(callbackResults[i++], result);
                }
            }
            else
            {
                scanResults = target.Scan(filePaths, new ITermTable[] { table });
            }

            file.Close();

            Assert.AreEqual(3, scanResults.Attempted, "Attempted != 3 in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");
            Assert.AreEqual(0, scanResults.FailedScan, "FailedScan != 0 in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");
            Assert.AreEqual(1, scanResults.PassedScan, "PassedScan != 1 in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");
            Assert.AreEqual(2, scanResults.UnableToScan, "UnableToScan != 2 in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");
            Assert.IsNotNull(scanResults.Results, "Results property was null in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");

            int count = 0;

            foreach (IScanResult scanResult in scanResults.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 3, "Results list did not contain 3 entries in return value from Scanner.Scanner.Scan with 1 passing / 2 invalid files.");
        }
コード例 #12
0
        public void ScanTextWithSingleCharTermHit()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("d", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("the term I want to find\nis \"d\".  Is it here?", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Failed to find a single-character term.");
            Assert.AreEqual(term, hits[0].Term, "Term property of hit is incorrect.");
            Assert.AreEqual(1, hits[0].Line, "Line property of hit is incorrect.");
            Assert.AreEqual("is \"d\".  Is it here?", hits[0].LineText, "LineText property of hit is incorrect.");
            Assert.AreEqual(4, hits[0].Column, "Column property of hit is incorrect.");
        }
コード例 #13
0
        public void ScanTextWithExclusionPresentButSeparateFromTerm()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("this foo is excluded");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("this foo is excluded; this foo is not", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(27, hits[0].Column, "Column property of hit 0 is incorrect.");
        }
コード例 #14
0
        public void ScanWithDifferentEncodings()
        {
            List <string> filePaths = new List <string>();

            filePaths.Add(Utilities.CreateTempTxtFile("first file", Encoding.Unicode));
            filePaths.Add(Utilities.CreateTempTxtFile("second file", Encoding.BigEndianUnicode));
            filePaths.Add(Utilities.CreateTempTxtFile("third file", Encoding.UTF32));
            filePaths.Add(Utilities.CreateTempTxtFile("fourth file", Encoding.UTF8));
            filePaths.Add(Utilities.CreateTempTxtFile("fifth file", Encoding.UTF7));
            filePaths.Add(Utilities.CreateTempTxtFile("sixth file", Encoding.ASCII));

            // TODO: what about different code pages within the ASCII encoding?

            List <ITermTable> termTables = new List <ITermTable>();

            MockTermTable table = new MockTermTable("file");

            table.AddSearchTerm(new MockTerm("first", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("second", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("third", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("fourth", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("fifth", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("sixth", 1, "class", "comment", "recommended", table));

            termTables.Add(table);

            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(filePaths, termTables);

            Assert.AreEqual(6, result.Attempted, "Attempted count incorrect.");
            Assert.AreEqual(6, result.FailedScan, "FailedScan count incorrect.");
            Assert.AreEqual(0, result.PassedScan, "PassedScan count incorrect.");
            Assert.AreEqual(0, result.UnableToScan, "UnableToScan count incorrect.");

            int fileIndex = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                int count = 0;
                foreach (IScanHit hits in scanResult.Results)
                {
                    ++count;
                }
                Assert.AreEqual(1, count, "Result " + fileIndex.ToString() + " did not have the expected number of hits.");
                ++fileIndex;
            }
        }
コード例 #15
0
        public void ScanTextWithMultipleExclusions()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term.AddExclusion("first foo");
            term.AddExclusion("second foo");
            term.AddExclusion("third foo");
            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("this first-foo will not exclude, but this second foo will, as will this third foo", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term, hits[0].Term, "Term property of hit is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit is incorrect.");
            Assert.AreEqual(11, hits[0].Column, "Column property of hit is incorrect.");
        }
コード例 #16
0
        public void ScanTextWithOverlappingTermHit()
        {
            MockTermTable table     = new MockTermTable("file1");
            MockTerm      bigTerm   = new MockTerm("abc def", 1, "fooClass", "fooComment", "fooRecommended", table);
            MockTerm      smallTerm = new MockTerm("abc", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(bigTerm);
            table.AddSearchTerm(smallTerm);
            IList <IScanHit> hits = InternalScanText("foo abc def bar", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(bigTerm, hits[0].Term, "Term property of hit is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit is incorrect.");
            Assert.AreEqual("foo abc def bar", hits[0].LineText, "LineText property of hit is incorrect.");
            Assert.AreEqual(4, hits[0].Column, "Column property of hit is incorrect.");
        }
コード例 #17
0
        private void InternalScanWithSomeFailingFiles(bool useCallback)
        {
            IScanner target = Factory.GetScanner();

            MockTermTable table = new MockTermTable("file");

            table.AddSearchTerm(new MockTerm("foo", 1, "", "", "", table));
            table.AddSearchTerm(new MockTerm("bar", 1, "", "", "", table));

            List <string> filePaths = new List <string>();

            filePaths.Add(Utilities.CreateTempTxtFile("line 1\nfoo\nline 3"));
            filePaths.Add(Utilities.CreateTempTxtFile("line 1\nline 2\nline 3"));
            filePaths.Add(Utilities.CreateTempTxtFile("bar"));

            IMultiFileScanResult scanResults;

            if (useCallback)
            {
                List <IScanResult> callbackResults = new List <IScanResult>();
                scanResults = target.Scan(filePaths, new ITermTable[] { table }, delegate(IScanResult result) { callbackResults.Add(result); });

                int i = 0;
                foreach (IScanResult result in scanResults.Results)
                {
                    Assert.AreEqual(callbackResults[i++], result);
                }
            }
            else
            {
                scanResults = target.Scan(filePaths, new ITermTable[] { table });
            }

            Assert.AreEqual(scanResults.Attempted, 3, "Attempted != 3 in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");
            Assert.AreEqual(scanResults.FailedScan, 2, "FailedScan != 2 in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");
            Assert.AreEqual(scanResults.PassedScan, 1, "PassedScan != 1 in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");
            Assert.AreEqual(scanResults.UnableToScan, 0, "UnableToScan != 0 in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");
            Assert.IsNotNull(scanResults.Results, "Results property was null in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");

            int count = 0;

            foreach (IScanResult scanResult in scanResults.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 3, "Results list did not contain 3 entries in return value from Scanner.Scanner.Scan with 1 passing / 2 failing files.");
        }
コード例 #18
0
        public void ScanTextWithOtherTermsAppearingInExclusion()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term1 = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term1.AddExclusion("a foo is not a bar");
            MockTerm term2 = new MockTerm("bar", 1, "barClass", "barComment", "fooRecommended", table);

            table.AddSearchTerm(term1);
            table.AddSearchTerm(term2);
            IList <IScanHit> hits = InternalScanText("a foo is not a bar", new ITermTable[] { table });

            Assert.AreEqual(1, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term2, hits[0].Term, "Term property of hit is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit is incorrect.");
            Assert.AreEqual(15, hits[0].Column, "Column property of hit is incorrect.");
        }
コード例 #19
0
        public void ScanTextWithAdjacentTerms()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term1 = new MockTerm("foo.", 1, "fooClass", "fooComment", "fooRecommended", table);
            MockTerm      term2 = new MockTerm(".bar", 1, "barClass", "barComment", "fooRecommended", table);

            table.AddSearchTerm(term1);
            table.AddSearchTerm(term2);
            IList <IScanHit> hits = InternalScanText("foo..bar", new ITermTable[] { table });

            Assert.AreEqual(2, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term1, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Column, "Column property of hit 0 is incorrect.");
            Assert.AreEqual(term2, hits[1].Term, "Term property of hit 1 is incorrect.");
            Assert.AreEqual(0, hits[1].Line, "Line property of hit 1 is incorrect.");
            Assert.AreEqual(4, hits[1].Column, "Column property of hit 1 is incorrect.");
        }
コード例 #20
0
        public void ScanTextWithOverlappingExclusionsWhenSecondExclusionIsInvalidatedFirst()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term1 = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            term1.AddExclusion("abc foo then bar and some more text");
            MockTerm term2 = new MockTerm("bar", 1, "barClass", "barComment", "fooRecommended", table);

            term2.AddExclusion("foo then bar and some more");
            table.AddSearchTerm(term1);
            table.AddSearchTerm(term2);
            IList <IScanHit> hits = InternalScanText("abc foo then bar and some morINVALIDATED", new ITermTable[] { table });

            Assert.AreEqual(2, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(term1, hits[0].Term, "Term property of hit 0 is incorrect.");
            Assert.AreEqual(0, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual(4, hits[0].Column, "Column property of hit 0 is incorrect.");
            Assert.AreEqual(term2, hits[1].Term, "Term property of hit 1 is incorrect.");
            Assert.AreEqual(0, hits[1].Line, "Line property of hit 1 is incorrect.");
            Assert.AreEqual(13, hits[1].Column, "Column property of hit 1 is incorrect.");
        }
コード例 #21
0
        public void AddResultTest()
        {
            CodeSweep.VSPackage.ScannerHost_Accessor accessor = new CodeSweep.VSPackage.ScannerHost_Accessor(_serviceProvider);

            MockTermTable  table      = new MockTermTable("scannedFile");
            MockTerm       term       = new MockTerm("term text", 0, "term class", "term comment", "recommended", table);
            MockScanHit    hit        = new MockScanHit("scannedFile", 5, 6, "line text", term, null);
            MockScanResult scanResult = new MockScanResult("scannedFile", new IScanHit[] { hit }, true);

            List <int>   resultCounts = new List <int>();
            MockTaskList taskList     = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            taskList.OnRefreshTasks += delegate(object sender, MockTaskList.RefreshTasksArgs args)
            {
                resultCounts.Add(Utilities.TasksOfProvider(args.Provider).Count);
            };

            accessor.AddResult(scanResult, "c:\\projFile");

            Assert.AreEqual(1, resultCounts.Count, "Task list was not updated by AddResult.");
            Assert.AreEqual(1, resultCounts[0], "Refresh did not enumerate one task.");
        }
コード例 #22
0
        public void ScanTextWithDifferentNewlines()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(term);
            IList <IScanHit> hits = InternalScanText("\nthis foo is on line 1\rthis foo is on line 2\r\nthis foo is on line 3\n\rthis foo is on line 5\n\nthis foo is on line 7\r\rthis foo is on line 9", new ITermTable[] { table });

            Assert.AreEqual(6, hits.Count, "Search returned wrong number of hits.");
            Assert.AreEqual(1, hits[0].Line, "Line property of hit 0 is incorrect.");
            Assert.AreEqual("this foo is on line 1", hits[0].LineText, "LineText property of hit 0 is incorrect.");
            Assert.AreEqual(2, hits[1].Line, "Line property of hit 1 is incorrect.");
            Assert.AreEqual("this foo is on line 2", hits[1].LineText, "LineText property of hit 1 is incorrect.");
            Assert.AreEqual(3, hits[2].Line, "Line property of hit 2 is incorrect.");
            Assert.AreEqual("this foo is on line 3", hits[2].LineText, "LineText property of hit 2 is incorrect.");
            Assert.AreEqual(5, hits[3].Line, "Line property of hit 3 is incorrect.");
            Assert.AreEqual("this foo is on line 5", hits[3].LineText, "LineText property of hit 3 is incorrect.");
            Assert.AreEqual(7, hits[4].Line, "Line property of hit 4 is incorrect.");
            Assert.AreEqual("this foo is on line 7", hits[4].LineText, "LineText property of hit 4 is incorrect.");
            Assert.AreEqual(9, hits[5].Line, "Line property of hit 5 is incorrect.");
            Assert.AreEqual("this foo is on line 9", hits[5].LineText, "LineText property of hit 5 is incorrect.");
        }
コード例 #23
0
        public void AddDuplicateTermsAndVerifyWarningAppearsOnce()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("dupText", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("dupText", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockTerm       term2      = new MockTerm("term2Text", 2, "term2Class", "term2Comment", "term2recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, "warning 1");
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, "warning 2");
            MockScanHit    hit2       = new MockScanHit("file2", 3, 2, "line text 3", term2, "warning 3");
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1, hit2 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            // Verify there are three hits plus two warnings.
            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            Assert.AreEqual(5, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks.");

            string[] termValues = new string[5] {
                "dupText", "dupText", "dupText", "term2Text", "term2Text"
            };
            int[] priorityValues = new int[5] {
                0, 0, 3, 2, 2
            };
            string[] classValues = new string[5] {
                "term0Class", "term0Class", "term1Class", "term2Class", "term2Class"
            };
            string[] replacementValues = new string[5] {
                "", "term0recommended", "term1recommended", "", "term2recommended"
            };
            string[] commentValues = new string[5] {
                "warning 1", "term0Comment", "term1Comment", "warning 3", "term2Comment"
            };
            string[] fileValues = new string[5] {
                "", "file0", "file1", "", "file2"
            };

            for (int taskIndex = 0; taskIndex < tasks.Count; ++taskIndex)
            {
                uint   type;
                object val;
                uint   flags;
                string acc;

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Term, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " term type is wrong.");
                Assert.AreEqual(termValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " term text is wrong.");

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Comment, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_LINKTEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " comment type is wrong.");
                Assert.AreEqual(commentValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " comment text is wrong.");

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Replacement, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " replacement type is wrong.");
                Assert.AreEqual(replacementValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " replacement text is wrong.");
            }
        }
コード例 #24
0
        public void TestEnumerator()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            // Add some tasks
            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("term0Text", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term1Text", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            IVsTaskItem[] items = new IVsTaskItem[3] {
                null, null, null
            };
            uint[] fetched = new uint[1] {
                0
            };
            hr = enumerator.Next(3, items, fetched);
            Assert.AreEqual(VSConstants.S_FALSE, hr, "Next returned wrong hresult with celt too high.");
            Assert.AreEqual((uint)2, fetched[0], "Next returned wrong value for fetched with celt too high.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt too high.");
            Assert.IsNotNull(items[1], "Next failed to set second item with celt too high.");
            Assert.IsNull(items[2], "Next set third item with celt too high.");

            hr = enumerator.Reset();
            Assert.AreEqual(VSConstants.S_OK, hr, "Reset returned wrong hresult.");

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 0;
            hr         = enumerator.Next(2, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt at max.");
            Assert.AreEqual((uint)2, fetched[0], "Next returned wrong value for fetched with celt at max.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt at max.");
            Assert.IsNotNull(items[1], "Next failed to set second item with celt at max.");

            enumerator.Reset();

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 0;
            hr         = enumerator.Next(1, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt lower than max.");
            Assert.AreEqual((uint)1, fetched[0], "Next returned wrong value for fetched with celt lower than max.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt lower than max.");
            Assert.IsNull(items[1], "Next set second item with celt lower than max.");

            enumerator.Reset();

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 1;
            hr         = enumerator.Next(0, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt = 0.");
            Assert.AreEqual((uint)0, fetched[0], "Next returned wrong value for fetched with celt = 0.");
            Assert.IsNull(items[0], "Next set first item with celt = 0.");

            enumerator.Reset();

            hr = enumerator.Skip(0);
            Assert.AreEqual(VSConstants.S_OK, hr, "Skip(0) returned wrong hresult.");

            hr = enumerator.Skip(1);
            Assert.AreEqual(VSConstants.S_OK, hr, "Skip(1) returned wrong hresult.");

            hr = enumerator.Skip(2);
            Assert.AreEqual(VSConstants.S_FALSE, hr, "Skip(2) returned wrong hresult.");

            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            IVsEnumTaskItems enumerator2 = null;

            hr = enumerator.Clone(out enumerator2);
            Assert.AreEqual(VSConstants.S_OK, hr, "Clone returned wrong hresult.");

            List <IVsTaskItem> tasks2 = Utilities.TasksFromEnumerator(enumerator2);

            Assert.IsTrue(CodeSweep.Utilities.OrderedCollectionsAreEqual(tasks, tasks2), "Clone did not produce an equivalent collection.");
        }