/// <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> /// Parses a TestCase node. /// </summary> /// <param name="node">The XPathNavigator pointing to a TestCase node.</param> /// <param name="parent">The parent TestSuite to which TestUnits are attached to.</param> /// <param name="collection">The TestResultCollection which will host the result.</param> private static void ParseTestCaseReport(XPathNavigator node, TestSuite parent, TestResultCollection collection) { QualifiedNameBuilder fullname = new QualifiedNameBuilder(parent); fullname.Push(node.GetAttribute(Xml.Name, string.Empty)); TestCase testCase = null; // If the test is already available, reuse it TestResult current = collection[fullname.ToString()]; if (current != null) { testCase = current.Unit as TestCase; } // Else construct and add it to the appropriate parent if (testCase == null) { testCase = new TestCase(fullname.Peek(), parent); } TestResult result = ParseTestResult(node, testCase, collection); // Aggregate results. Common use-case in BOOST_DATA_TEST_CASE. collection[fullname.ToString()] = Aggregate(result, current); }
/// <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> /// 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); }
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; } } }