Ejemplo n.º 1
0
        public void Visit(TestCase testCase)
        {
            Code.Require(testCase, "testCase");

            if (ShouldVisit(testCase))
            {
                VSTestCase test = GenerateTestCase(testCase);
                TestCaseUtils.AddTestCase(test, this.DiscoverySink);
            }
        }
        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;
                }
            }
        }