Esempio n. 1
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.");
        }
Esempio n. 2
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().");
        }
Esempio n. 3
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.");
        }
Esempio n. 4
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.");
        }
Esempio n. 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);
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 9
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.");
        }
Esempio n. 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.");
        }
Esempio n. 11
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.");
        }
Esempio n. 12
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.");
        }
Esempio n. 13
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.");
        }
Esempio n. 14
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.");
        }
Esempio n. 15
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.");
        }
Esempio n. 16
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.");
        }
Esempio n. 17
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.");
        }
Esempio n. 18
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.");
        }
        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.");
        }
Esempio n. 20
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.");
            }
        }
Esempio n. 21
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.");
        }