Ejemplo n.º 1
0
        /// <summary>
        /// Parses a TestCase log node.
        /// </summary>
        /// <param name="node">The TestCase Xml node to parse.</param>
        /// <param name="path">The QualifiedNameBuilder which hosts the current fully qualified path.</param>
        /// <param name="collection">The test result collection which will host the result.</param>
        private static void ParseTestCaseLog(XmlNode node, QualifiedNameBuilder path, IDictionary <string, TestResult> collection)
        {
            // Temporarily push TestCase on TestSuite name builder to acquire the fully qualified name of the TestCase
            path.Push(node.Attributes[Xml.Name].Value);

            var currentPath = path.ToString();

            // Acquire result record of this TestCase
            TestResult result = null;

            if (!collection.TryGetValue(currentPath, out result))
            {
                result = new TestResult(collection);
                collection[currentPath] = result;
            }

            // Reset path to original value
            path.Pop();

            XmlNode testingTime = node.SelectSingleNode(Xml.TestingTime);

            if (testingTime != null)
            {
                // Boost test testing time is listed in microseconds
                result.Duration += ulong.Parse(testingTime.InnerText, CultureInfo.InvariantCulture);
            }

            ParseTestCaseLogEntries(node.ChildNodes, result);
        }
        /// <summary>
        /// Asserts general test properties
        /// </summary>
        /// <param name="tests">The enumeration of discovered tests</param>
        /// <param name="qualifiedName">The qualified test name which is to be tested</param>
        /// <param name="source">The source from which the test should have been discovered</param>
        /// <param name="info">Optional source file information related to the test under question</param>
        private void AssertVSTestCaseProperties(IEnumerable <VSTestCase> tests, QualifiedNameBuilder qualifiedName, string source, SourceFileInfo info)
        {
            VSTestCase test = tests.FirstOrDefault((_test) => (_test.FullyQualifiedName == qualifiedName.ToString()));

            Assert.That(test, Is.Not.Null);
            Assert.That(test.DisplayName, Is.EqualTo(qualifiedName.Peek()));
            Assert.That(test.Source, Is.EqualTo(source));
            Assert.That(test.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));

            if (info != null)
            {
                Assert.That(test.CodeFilePath, Is.EqualTo(info.File));
                Assert.That(test.LineNumber, Is.EqualTo(info.LineNumber));
            }

            Assert.That(test.Traits.Count(), Is.EqualTo(1));

            Trait trait = test.Traits.First();

            Assert.That(trait.Name, Is.EqualTo(VSTestModel.TestSuiteTrait));

            string suite = qualifiedName.Pop().ToString();

            if (string.IsNullOrEmpty(suite))
            {
                suite = qualifiedName.MasterTestSuite;
            }

            Assert.That(trait.Value, Is.EqualTo(suite));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a TestSuite log node.
        /// </summary>
        /// <param name="node">The TestSuite Xml node to parse.</param>
        /// <param name="path">The QualifiedNameBuilder which hosts the current fully qualified path.</param>
        /// <param name="collection">The test result collection which will host the result.</param>
        private static void ParseTestSuiteLog(XmlNode node, QualifiedNameBuilder path, IDictionary <string, TestResult> collection)
        {
            path.Push(node.Attributes[Xml.Name].Value);

            ParseTestUnitsLog(node.ChildNodes, path, collection);

            path.Pop();
        }
        /// <summary>
        /// Asserts general test details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="fqn">The expected test case fully qualified name</param>
        /// <param name="source">The expected test case source</param>
        private void AssertTestDetails(VSTestCase vsTest, QualifiedNameBuilder fqn, string source)
        {
            Assert.That(vsTest, Is.Not.Null);
            Assert.That(vsTest.DisplayName, Is.EqualTo(fqn.Peek()));
            Assert.That(vsTest.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));
            Assert.That(vsTest.Source, Is.EqualTo(source));

            string suite = fqn.Pop().ToString();

            if (string.IsNullOrEmpty(suite))
            {
                suite = QualifiedNameBuilder.DefaultMasterTestSuiteName;
            }

            Assert.That(vsTest.Traits.Where((trait) => (trait.Name == VSTestModel.TestSuiteTrait) && (trait.Value == suite)).Count(), Is.EqualTo(1));
        }
        /// <summary>
        /// Creates a new TestCase object.
        /// </summary>
        /// <param name="sourceExe">Name of the project executable</param>
        /// <param name="sourceInfo">.cpp file path and TestCase line number</param>
        /// <param name="suite">The suite in which testcase is present</param>
        /// <param name="testCaseName">Name of the testcase</param>
        /// <param name="isEnabled">The enabling status of the testcase</param>
        /// <returns>The created TestCase object</returns>
        public static TestCase CreateTestCase(string sourceExe, SourceFileInfo sourceInfo, QualifiedNameBuilder suite, string testCaseName, bool isEnabled = true)
        {
            suite.Push(testCaseName);

            string qualifiedName = suite.ToString();

            suite.Pop();

            var testCase = new TestCase(qualifiedName, BoostTestExecutor.ExecutorUri, sourceExe)
            {
                CodeFilePath = sourceInfo.File,
                LineNumber   = sourceInfo.LineNumber,
                DisplayName  = testCaseName,
            };

            GroupViaTraits(suite.ToString(), testCase, isEnabled);

            return(testCase);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Given a fully qualified name of a <b>test case</b>, generates the respective test unit hierarchy.
        /// </summary>
        /// <param name="fullyQualifiedName">The fully qualified name of the <b>test case</b></param>
        /// <returns>The test case hierarchy represented by the provided fully qualified name</returns>
        /// <remarks>The parameter 'fullyQualifiedName' will be modified and emptied in due process</remarks>
        private static TestCase FromFullyQualifiedName(QualifiedNameBuilder fullyQualifiedName)
        {
            // Reverse the fully qualified name stack i.e. Master Test Suite should be first element and Test Case should be last element
            Stack <string> hierarchy = new Stack <string>();

            while (fullyQualifiedName.Peek() != null)
            {
                hierarchy.Push(fullyQualifiedName.Peek());
                fullyQualifiedName.Pop();
            }

            TestSuite parent = null;

            // Treat each entry (except for the last) as a test suite
            while (hierarchy.Count > 1)
            {
                parent = new TestSuite(hierarchy.Peek(), parent);
                hierarchy.Pop();
            }

            // Treat the last entry as a test case
            return((hierarchy.Count == 1) ? new TestCase(hierarchy.Peek(), parent) : null);
        }
        private static void DiscoverBoostTests(CppSourceFile cppSourceFile, string source, ITestCaseDiscoverySink discoverySink)
        {
            string[] code = cppSourceFile.SourceCode.TrimEnd(new[] { ' ', '\n', '\r' }).Split('\n');

            SourceFileInfo sourceInfo = new SourceFileInfo(cppSourceFile.FileName, 0);

            QualifiedNameBuilder suite = new QualifiedNameBuilder();

            // Push the equivalent of the Master Test Suite
            suite.Push(QualifiedNameBuilder.DefaultMasterTestSuiteName);

            var templateLists = new Dictionary <string, IEnumerable <string> >();

            for (sourceInfo.LineNumber = 1; sourceInfo.LineNumber <= code.Length; ++sourceInfo.LineNumber)
            {
                string line = code[sourceInfo.LineNumber - 1];

                string[] splitMacro   = SplitMacro(line);
                string   desiredMacro = splitMacro[0].Trim();

                switch (desiredMacro)
                {
                case Constants.TypedefListIdentifier:
                case Constants.TypedefMplListIdentifier:
                case Constants.TypedefBoostMplListIdentifier:
                {
                    var templateList = ParseTemplateList(splitMacro);
                    templateLists.Add(templateList.Key, templateList.Value);
                    break;
                }

                case Constants.TestCaseTemplateIdentifier:
                {
                    var templateTest = ParseTemplateTestCase(splitMacro, templateLists, sourceInfo, code, ref line);

                    foreach (string testCaseDataType in templateTest.Value)
                    {
                        string testCaseNameWithDataType = templateTest.Key + '<' + testCaseDataType + '>';
                        var    testCase = TestCaseUtils.CreateTestCase(source, sourceInfo, suite, testCaseNameWithDataType);
                        TestCaseUtils.AddTestCase(testCase, discoverySink);
                    }
                    break;
                }

                case Constants.FixtureTestSuiteIdentifier:
                case Constants.AutoTestSuiteIdentifier:
                {
                    string suiteName = ParseBeginTestSuite(splitMacro, sourceInfo, code, ref line);
                    suite.Push(suiteName);
                    break;
                }

                case Constants.FixtureTestCaseIdentifier:
                case Constants.AutoTestCaseIdentifier:
                case Constants.DataTestCaseIdentifier:
                {
                    string testCaseName = ParseTestCase(splitMacro, sourceInfo, code, ref line);
                    var    testCase     = TestCaseUtils.CreateTestCase(source, sourceInfo, suite, testCaseName);
                    TestCaseUtils.AddTestCase(testCase, discoverySink);
                    break;
                }

                case Constants.FixtureDataTestCaseIdentifier:
                {
                    string testCaseName = ParseDataTestCaseF(splitMacro, sourceInfo, code, ref line);
                    var    testCase     = TestCaseUtils.CreateTestCase(source, sourceInfo, suite, testCaseName);
                    TestCaseUtils.AddTestCase(testCase, discoverySink);
                    break;
                }

                case Constants.AutoTestSuiteEndIdentifier:
                {
                    suite.Pop();
                    break;
                }

                default:
                    break;
                }
            }
        }