Esempio n. 1
0
 /// <summary>
 /// Registers the ANSI-Compliant Predefined Macros
 /// </summary>
 private static void RegisterAnsiCompliantPredefinedMacros(Defines definesHandler)
 {
     definesHandler.Define("__DATE__", "");
     definesHandler.Define("__FILE__", "");
     definesHandler.Define("__LINE__", "");
     definesHandler.Define("__TIME__", "");
     definesHandler.Define("__TIMESTAMP__", "");
 }
        public void ConditionalInclusionsIfTests()
        {
            #region setup

            var definesHandler = new Defines();

            definesHandler.Define("DEBUG", "");
            definesHandler.Define("NDEBUG", "");
            definesHandler.Define("DEBUGGER", "");

            var expectedPreprocessorDefines = new HashSet <string>()
            {
                "DEBUG",
                "NDEBUG",
                "DEBUGGER",
                "DLEVEL"
            };

            var filter = new ConditionalInclusionsFilter(new ExpressionEvaluation());

            const string nameSpace = "BoostTestAdapterNunit.Resources.SourceFiltering.";
            const string unfilteredSourceCodeResourceName = "ConditionalInclusionsIfTests_UnFilteredSourceCode.cpp";
            const string filteredSourceCodeResourceName   = "ConditionalInclusionsIfTests_FilteredSourceCode.cpp";

            string sourceCodeOriginal = TestHelper.ReadEmbeddedResource(nameSpace + unfilteredSourceCodeResourceName);
            string sourceCodeExpected = TestHelper.ReadEmbeddedResource(nameSpace + filteredSourceCodeResourceName);

            var cppSourceFile = new CppSourceFile()
            {
                FileName   = nameSpace + unfilteredSourceCodeResourceName,
                SourceCode = sourceCodeOriginal
            };

            #endregion

            #region excercise

            filter.Filter(cppSourceFile, definesHandler);

            #endregion

            #region verify

            Assert.AreEqual(sourceCodeExpected, cppSourceFile.SourceCode);
            Assert.AreEqual(expectedPreprocessorDefines, definesHandler.NonSubstitutionTokens);
            Assert.AreEqual(0, definesHandler.SubstitutionTokens.Count);

            #endregion
        }
Esempio n. 3
0
        /// <summary>
        /// Populates the provided definesHandler with the preprocessor defines available within the compiler argument
        /// </summary>
        /// <param name="compiler">The base Visual Studio C++ compiler configuration</param>
        /// <param name="definesHandler">The target structure which will host the extracted preprocessor definitions</param>
        private static void GetPreprocessorDefines(VCCLCompilerTool compiler, Defines definesHandler)
        {
            string definitions   = compiler.PreprocessorDefinitions.Trim();
            string undefinitions = compiler.UndefinePreprocessorDefinitions.Trim();

            if (definitions.Length > 0)
            {
                string[] preProcessorDefinesArray = definitions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string preProcessorDefine in preProcessorDefinesArray)
                {
                    // the below code is to support valued defines as per https://msdn.microsoft.com/en-us/library/vstudio/hhzbb5c8%28v=vs.100%29.aspx

                    Match matchResult = RegexPreProcesserDefines.Match(preProcessorDefine);

                    if (matchResult.Success)
                    {
                        definesHandler.Define(matchResult.Groups[1].Value.Trim(), matchResult.Groups[2].Value);
                    }
                    else
                    {
                        if (!preProcessorDefine.Contains("$(INHERIT)"))
                        {
                            definesHandler.Define(preProcessorDefine.Trim(), "1");
                            //by default user assigned pre-processor defines have a value of 1
                        }
                    }
                }
            }

            if (undefinitions.Length > 0)
            {
                string[] preProcessorUnDefinesArray = undefinitions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var preProcessorUnDefine in preProcessorUnDefinesArray)
                {
                    if (!preProcessorUnDefine.Contains("$(NOINHERIT)"))
                    {
                        definesHandler.UnDefine(preProcessorUnDefine.Trim());
                    }
                }
            }
        }
        /// <summary>
        /// Given a parameter list of strings, generates a Defines structure
        /// where pairs of strings are treated as a definition and its value.
        /// </summary>
        /// <param name="definitions">The string pair definitions array from which to generate the Defines structue</param>
        /// <returns>A Defines structure built out of string pairs available in the definitions array</returns>
        private Defines GenerateDefines(string[] definitions)
        {
            Assert.That(definitions.Length % 2, Is.EqualTo(0));

            Defines definesHandler = new Defines();

            for (int i = 1; i < definitions.Length; i += 2)
            {
                definesHandler.Define(definitions[i - 1], definitions[i]);
            }

            return(definesHandler);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers the Microsoft specific PreDefined compiler defines
        /// </summary>
        private static Defines RegisterMicrosoftPreDefinedCompilerMacros(Defines definesHandler)
        {
            /*
             * taken off https://msdn.microsoft.com/en-us/library/b0084kay(v=vs.110).aspx
             *
             * Only a limited number of pre defined macros is taken off the list present on Microsoft's website. The general philosophy used
             * is that the ones selected are those which are always present. i.e. that their presence is not dependent on the compiler settings, processor
             * architecture used.
             *
             */

            definesHandler.Define("__COUNTER__", "");
            definesHandler.Define("__cplusplus", "");
            definesHandler.Define("__FUNCDNAME__", "");
            definesHandler.Define("__FUNCSIG__", "");
            definesHandler.Define("__FUNCTION__", "");
            definesHandler.Define("_INTEGRAL_MAX_BITS", "");
            definesHandler.Define("_MSC_BUILD", "");
            definesHandler.Define("_MSC_FULL_VER", "");
            definesHandler.Define("_MSC_VER", "");
            definesHandler.Define("_WIN32", "");

            return(definesHandler);
        }
        /// <summary>
        /// Acquires the pre-processor definitions used by the project
        /// </summary>
        /// <param name="projectInfo">The Visual Studio project</param>
        /// <returns>The pre-processor definitions specified within the project</returns>
        private static Defines GetDefines(ProjectInfo projectInfo)
        {
            /*
             * it is important that the pre-processor defines at project level are not modified
             * because every source file in the project has to have the same starting point.
             */

            //call to cpy ctor
            Defines defines = new Defines(projectInfo.DefinesHandler);

            // Additional Boost definitions

            // NOTE These definitions are generally assumed to be available since
            //      we are operating in a BOOST Test context
            if (!defines.IsDefined("BOOST_VERSION"))
            {
                defines.Define("BOOST_VERSION", "0");
            }

            return(defines);
        }
        /// <summary>
        /// Registers the Microsoft specific PreDefined compiler defines
        /// </summary>
        private static Defines RegisterMicrosoftPreDefinedCompilerMacros(Defines definesHandler)
        {
            /*
             * taken off https://msdn.microsoft.com/en-us/library/b0084kay(v=vs.110).aspx
             *
             * Only a limited number of pre defined macros is taken off the list present on Microsoft's website. The general philosophy used
             * is that the ones selected are those which are always present. i.e. that their presence is not dependent on the compiler settings, processor
             * architecture used.
             *
             */

            definesHandler.Define("__COUNTER__", "");
            definesHandler.Define("__cplusplus", "");
            definesHandler.Define("__FUNCDNAME__", "");
            definesHandler.Define("__FUNCSIG__", "");
            definesHandler.Define("__FUNCTION__", "");
            definesHandler.Define("_INTEGRAL_MAX_BITS", "");
            definesHandler.Define("_MSC_BUILD", "");
            definesHandler.Define("_MSC_FULL_VER", "");
            definesHandler.Define("_MSC_VER", "");
            definesHandler.Define("_WIN32", "");

            return definesHandler;
        }
 /// <summary>
 /// Registers the ANSI-Compliant Predefined Macros
 /// </summary>
 private static void RegisterAnsiCompliantPredefinedMacros(Defines definesHandler)
 {
     definesHandler.Define("__DATE__", "");
     definesHandler.Define("__FILE__", "");
     definesHandler.Define("__LINE__", "");
     definesHandler.Define("__TIME__", "");
     definesHandler.Define("__TIMESTAMP__", "");
 }
        /// <summary>
        /// Populates the provided definesHandler with the preprocessor defines available within the compiler argument
        /// </summary>
        /// <param name="compiler">The base Visual Studio C++ compiler configuration</param>
        /// <param name="definesHandler">The target structure which will host the extracted preprocessor definitions</param>
        private static void GetPreprocessorDefines(VCCLCompilerTool compiler, Defines definesHandler)
        {
            string definitions = compiler.PreprocessorDefinitions.Trim();
            string undefinitions = compiler.UndefinePreprocessorDefinitions.Trim();

            if (definitions.Length > 0)
            {
                string[] preProcessorDefinesArray = definitions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string preProcessorDefine in preProcessorDefinesArray)
                {
                    // the below code is to support valued defines as per https://msdn.microsoft.com/en-us/library/vstudio/hhzbb5c8%28v=vs.100%29.aspx

                    Match matchResult = RegexPreProcesserDefines.Match(preProcessorDefine);

                    if (matchResult.Success)
                    {
                        definesHandler.Define(matchResult.Groups[1].Value.Trim(), matchResult.Groups[2].Value);
                    }
                    else
                    {
                        if (!preProcessorDefine.Contains("$(INHERIT)"))
                        {
                            definesHandler.Define(preProcessorDefine.Trim(), "1");
                            //by default user assigned pre-processor defines have a value of 1
                        }
                    }
                }
            }

            if (undefinitions.Length > 0)
            {
                string[] preProcessorUnDefinesArray = undefinitions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var preProcessorUnDefine in preProcessorUnDefinesArray)
                {
                    if (!preProcessorUnDefine.Contains("$(NOINHERIT)"))
                    {
                        definesHandler.UnDefine(preProcessorUnDefine.Trim());
                    }
                }
            }
        }