public void ConditionalInclusionsComplexExpressionEvaluationFail() { #region setup var definesHandler = new Defines(); //no defines supplied var filter = new ConditionalInclusionsFilter(new ExpressionEvaluation()); const string nameSpace = "BoostTestAdapterNunit.Resources.SourceFiltering."; const string unfilteredSourceCodeResourceName = "ConditionalInclusionsComplexEvaluationFail.cpp"; string sourceCodeOriginal = TestHelper.ReadEmbeddedResource(nameSpace + unfilteredSourceCodeResourceName); string sourceCodeExpected = sourceCodeOriginal; var cppSourceFile = new CppSourceFile() { FileName = nameSpace + unfilteredSourceCodeResourceName, SourceCode = sourceCodeOriginal }; #endregion #region excercise filter.Filter(cppSourceFile, definesHandler); #endregion #region verify Assert.AreEqual(sourceCodeExpected, cppSourceFile.SourceCode); //no filtering should be done due to inability to evaluate an expression #endregion }
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 }
public void ConditionalInclusionsComplexExpressionEvaluationSuccess() { #region setup var definesHandler = new Defines(); var expectedNonSubstitutionTokens = new HashSet<string>() { "VERSION", "HALF", "THIRD", "DEBUG", "SIN", "MAX", "CUBE", "fPRINT", "ASSERT", }; var expectedSubtitutionTokens = new Dictionary<string, object>() { {"LEVEL", "19"}, {"EVER", ";;"}, {"BIG", "(512)"}, {"PRINT", "cout << #x"}, }; var filter = new ConditionalInclusionsFilter(new ExpressionEvaluation()); const string nameSpace = "BoostTestAdapterNunit.Resources.SourceFiltering."; const string unfilteredSourceCodeResourceName = "ConditionalInclusionsComplexEvaluationSuccess_UnfilteredSourceCode.cpp"; const string filteredSourceCodeResourceName = "ConditionalInclusionsComplexEvaluationSuccess_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(expectedNonSubstitutionTokens, definesHandler.NonSubstitutionTokens); Assert.AreEqual(expectedSubtitutionTokens, definesHandler.SubstitutionTokens); #endregion }