Ejemplo n.º 1
0
        public void ScanWithAllPassingFiles()
        {
            List <string> filePaths = new List <string>();

            filePaths.Add(Utilities.CreateTempTxtFile(""));
            filePaths.Add(Utilities.CreateTempTxtFile("some text"));
            filePaths.Add(Utilities.CreateTempTxtFile("some more text"));

            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(filePaths, new List <ITermTable>());

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

            int count = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 3, "Results list did not contain 3 entries in return value from Scanner.Scanner.Scan with 3 passing files.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a scan over all files in the project.
        /// </summary>
        /// <returns>False if any violations are found, true otherwise.</returns>
        /// <remarks>
        /// If any violations are found, a message will be sent to standard output.  If this task
        /// is running the VS IDE with the CodeSweep package loaded, the message will also be
        /// placed in the task list.
        /// </remarks>
        public override bool Execute()
        {
            _ignoreInstances = new List <IIgnoreInstance>(Factory.DeserializeIgnoreInstances(_ignoreInstancesString, Path.GetDirectoryName(_project)));

            IMultiFileScanResult result = Scanner.Factory.GetScanner().Scan(GetFilesToScan(), GetTermTables(), OutputScanResults);

            if (_signalErrorIfTermsFound)
            {
                return(result.PassedScan == result.Attempted);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs a scan over all files in the project.
        /// </summary>
        /// <returns>False if any violations are found, true otherwise.</returns>
        /// <remarks>
        /// If any violations are found, a message will be sent to standard output.  If this task
        /// is running the VS IDE with the CodeSweep package loaded, the message will also be
        /// placed in the task list.
        /// </remarks>
        public override bool Execute()
        {
            if (!string.IsNullOrEmpty(HostIdeProcId))
            {
                _host = GetHostObject(int.Parse(HostIdeProcId));
            }

            _ignoreInstancesList = new List <IIgnoreInstance>(Factory.DeserializeIgnoreInstances(IgnoreInstances, Path.GetDirectoryName(Project)));

            IMultiFileScanResult result = Scanner.Factory.GetScanner().Scan(GetFilesToScan(), GetTermTables(), OutputScanResults);

            if (SignalErrorIfTermsFound)
            {
                return(result.PassedScan == result.Attempted);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 5
0
        public void ScanWithEmptyList()
        {
            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(new List <string>(), new List <ITermTable>());

            Assert.AreEqual(result.Attempted, 0, "Attempted != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.FailedScan, 0, "FailedScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.PassedScan, 0, "PassedScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.UnableToScan, 0, "UnableToScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.IsNotNull(result.Results, "Results property was null in return value from Scanner.Scanner.Scan with empty list.");

            int count = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 0, "Results list was not empty in return value from Scanner.Scanner.Scan with empty list.");
        }