コード例 #1
0
ファイル: UnitTestBrowser.cs プロジェクト: powerumc/vutpp
        private void AddItem(ProjectItem projectItem, USE_DOCUMENT useDocument)
        {
            if (IsRunning() == true)
                return;

            TestRule rule;
            if (projectItem != null && (rule = TestRule.CheckProject(projectItem.ContainingProject)) != null)
            {
                TreeNode projectNode = FindByKey(TestList.Nodes, projectItem.ContainingProject.UniqueName);
                if (projectNode != null)
                {
                    ScanProjectItem(projectItem, projectNode, useDocument, rule);
                    //                    TestList.Sort();
                }
            }
        }
コード例 #2
0
ファイル: UnitTestBrowser.cs プロジェクト: powerumc/vutpp
        private void Reparse(ProjectItem projectItem, TestRule rule, USE_DOCUMENT useDocument)
        {
            if (projectItem == null)
                return;

            Project project = projectItem.ContainingProject;
            if (project == null)
                return;

            TreeNode parseNode = Parse(projectItem, useDocument, rule);
            if (parseNode == null || parseNode.Nodes.Count == 0)
            {
                RemoveItem(projectItem);
                return;
            }

            string filename = projectItem.get_FileNames(1);

            TreeNode projectNode = FindByKey(TestList.Nodes, projectItem.ContainingProject.UniqueName);
            if (projectNode != null)
            {
                ProcessReparse(parseNode, projectNode, filename);
                ProcessScan(parseNode, projectNode, rule);
                ClearEmptySuite(projectNode);
            }
        }
コード例 #3
0
ファイル: UnitTestBrowser.cs プロジェクト: powerumc/vutpp
        private void ScanProjectItem(ProjectItem item, TreeNode projectNode, USE_DOCUMENT useDocument, TestRule rule)
        {
            TreeNode parseNode = Parse(item, useDocument, rule);
            if (parseNode != null && parseNode.Nodes.Count != 0)
            {
                ProcessScan(parseNode, projectNode, rule);
            }

            foreach (ProjectItem child in item.ProjectItems)
            {
                ScanProjectItem(child, projectNode, useDocument, rule);
            }
        }
コード例 #4
0
ファイル: UnitTestBrowser.cs プロジェクト: powerumc/vutpp
        private TreeNode Parse(ProjectItem item, USE_DOCUMENT useDocument, TestRule rule)
        {
            string fileName = item.get_FileNames(1);

            if (fileName.ToLower().EndsWith(".cpp") == false)
                return null;

            TreeNode projectNode = new TreeNode();

            IParseInput pi = null;
            if (useDocument != USE_DOCUMENT.NOT)
            {
                IEnumerator itr = m_dte.Documents.GetEnumerator();
                while( itr.MoveNext() == true )
                {
                    Document document = (Document)itr.Current;
                    if( document != null && document.ProjectItem == item )
                    {
                        TextDocument td = (TextDocument)document.Object("TextDocument");
                        if (td != null)
                        {
                            pi = new ParseInputTextDocument(td);
                        }
                        break;
                    }
                }
            }

            if(pi == null)
                pi = new ParseInputFile(fileName);

            TreeNode suiteNode = null, testNode = null;
            int lineIndex = 1;
            string strLine;

            int suiteBraceCount = 0, testBraceCount = 0;
            char[] trimFilter = { ' ', '\r', '\n', '\t' };
            char[] commands = { '{', '}', '\"', '\'', '/', '(' };
            char[] commandsSeperator = { ',', ')' };

            char command = '\0';
            bool bProcessString = false, bProcessComment = false;

            while ((strLine = pi.GetLine()) != null)
            {
                int index = 0;
                while (index != -1 && ((command != '\0' && (index = strLine.IndexOf(command, index)) != -1) || (command == '\0' && (index = strLine.IndexOfAny(commands, index)) != -1)))
                {
                    command = strLine[index];

                    if( bProcessComment == false || command == '/' )
                    {
                        switch (command)
                        {
                            case '\"':
                            case '\'':
                                if (bProcessString == true)
                                {
                                    command = '\0';
                                    bProcessString = false;
                                }
                                else
                                    bProcessString = true;
                                break;

                            case '/':
                                if (index + 1 < strLine.Length && strLine[index + 1] == '/')
                                {
                                    index = -1;
                                    command = '\0';
                                }
                                else if (index > 0 && strLine[index - 1] == '*')
                                {
                                    if (bProcessComment == false)
                                    {
                                        pi.Release();
                                        return null;
                                    }
                                    bProcessComment = false;
                                    command = '\0';
                                }
                                else if (index + 1 < strLine.Length && strLine[index + 1] == '*')
                                    bProcessComment = true;
                                else
                                    command = '\0';
                                break;

                            case '{':
                                if (rule.SuiteType == SUITE_TYPE.BRACE && suiteNode != null)
                                    suiteBraceCount++;
                                if (testNode != null)
                                    testBraceCount++;
                                command = '\0';
                                break;

                            case '}':
                                if( rule.SuiteType == SUITE_TYPE.BRACE && suiteNode != null )
                                {
                                    if (--suiteBraceCount == 0)
                                        suiteNode = null;
                                }
                                if( testNode != null )
                                {
                                    if (--testBraceCount == 0)
                                    {
                                        TreeNodeTag tag = (TreeNodeTag)testNode.Tag;
                                        tag.line_end = lineIndex;
                                        testNode.Tag = tag;
                                        testNode = null;
                                    }
                                }
                                command = '\0';
                                break;

                            case '(':
                            {
                                string strCommand = strLine.Substring(0, index).Trim(trimFilter);
                                int keyIndex = rule.Keywords.IndexOfKey(strCommand);
                                if( keyIndex != -1 )
                                {
                                    TestKeyword keyword = (TestKeyword)rule.Keywords.GetByIndex(keyIndex);
                                    ArrayList commandNames = new ArrayList();

                                    while( strLine[index] != ')' )
                                    {
                                        int newIndex = strLine.IndexOfAny(commandsSeperator, index + 1);
                                        if (newIndex == -1)
                                        {
                                            pi.Release();
                                            return null;
                                        }
                                        commandNames.Add( strLine.Substring(index + 1, newIndex - index - 1).Trim(trimFilter) );
                                        index = newIndex;
                                    }
                                    switch(keyword.Type)
                                    {
                                        case TESTKEYWORD_TYPE.SUITE:
                                            if (rule.SuiteType == SUITE_TYPE.BRACE)
                                                suiteNode = AddSuite(projectNode, (string)commandNames[keyword.NameIndex], rule);
                                            break;

                                        case TESTKEYWORD_TYPE.SUITE_BEGIN:
                                            if (rule.SuiteType == SUITE_TYPE.BEGIN_END)
                                                suiteNode = AddSuite(projectNode, (string)commandNames[keyword.NameIndex], rule);
                                            break;

                                        case TESTKEYWORD_TYPE.SUITE_END:
                                            if (rule.SuiteType == SUITE_TYPE.BEGIN_END)
                                                suiteNode = null;
                                            break;

                                        case TESTKEYWORD_TYPE.TEST:
                                            switch( rule.SuiteType )
                                            {
                                                case SUITE_TYPE.NOT_USE:
                                                    testNode = AddTest(projectNode, null, (string)commandNames[keyword.NameIndex], strLine.Trim(), fileName, lineIndex, -1, rule);
                                                    break;

                                                case SUITE_TYPE.WITH_TEST:
                                                    suiteNode = AddSuite(projectNode, (string)commandNames[keyword.SuiteIndex], rule);
                                                    testNode = AddTest(projectNode, suiteNode, (string)commandNames[keyword.NameIndex], strLine.Trim(), fileName, lineIndex, -1, rule);
                                                    suiteNode = null;
                                                    break;

                                                default:
                                                    if( suiteNode == null )
                                                        suiteNode = AddSuite(projectNode, "DefaultSuite", rule);
                                                    testNode = AddTest(projectNode, suiteNode, (string)commandNames[keyword.NameIndex], strLine.Trim(), fileName, lineIndex, -1, rule);
                                                    break;
                                            }
                                            break;
                                    }
                                }
                                command = '\0';
                            }
                                break;
                        }
                    }
                    if (index != -1)
                        index++;
                }
                lineIndex++;
            }
            pi.Release();
            return projectNode;
        }