Ejemplo n.º 1
0
        /**
         * A convenience function to check if a function takes no arguments
         * (CDT's DOM treats a function with no arguments differently from one
         * with a single "void" argument).
         *
         * @param element the method handle to check.
         *
         * @return true if the function has no arguments; otherwise, false.
         */
        private bool IsMethodParameterless(VCCodeFunction function)
        {
            if (function.Parameters.Count == 0)
            {
                return(true);
            }
            else if (function.Parameters.Count > 1)
            {
                return(false);
            }
            else
            {
                VCCodeParameter parameter =
                    (VCCodeParameter)function.Parameters.Item(1);

                return(parameter.Type.AsString == "void");
            }
        }
Ejemplo n.º 2
0
        /**
         * Checks a method inside a test suite class to determine if it
         * is a valid test method (void return value, no arguments, name
         * begins with "test"). If so, it is added to the suite's list of
         * tests.
         *
         * @param element the method handle to be checked.
         */
        private void CheckMethod(VCCodeFunction function)
        {
            string name     = function.Name;
            int    lineNum  = function.StartPoint.Line;
            bool   isStatic = function.IsShared;

            if (name.StartsWith("Test") || name.StartsWith("test"))
            {
                if (function.Type.AsString == "void" &&
                    IsMethodParameterless(function))
                {
                    testCases.Add(new TestCase(function));
                }
            }
            else if (name == "createSuite")
            {
                if (isStatic &&
                    function.Type.AsString.IndexOf('*') >= 0 &&
                    IsMethodParameterless(function))
                {
                    createLineNumber = lineNum;
                }
            }
            else if (name == "destroySuite")
            {
                CodeElements parameters = function.Parameters;

                if (parameters.Count == 1)
                {
                    VCCodeParameter parameter =
                        (VCCodeParameter)parameters.Item(1);

                    if (isStatic &&
                        parameter.Type.AsString.IndexOf('*') >= 0 &&
                        function.Type.AsString == "void")
                    {
                        destroyLineNumber = lineNum;
                    }
                }
            }
        }