public void doTest(TestFileWrapper regressionFile, string fileName) { ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; for (int lineNumber = this.retStartLine; lineNumber <= this.retEndLine; lineNumber++) { EnvDTE.EditPoint tp1 = regressionFile.CreateEditPoint(null); tp1.MoveToLineAndOffset(lineNumber, 1); bool retSuccess; MatchedBlockData retBdata; CommentBlock retBlock; retSuccess = CommentReflowerObj.GetBlockContainingPoint( pset, fileName, tp1, out retBlock, out retBdata); if (retSuccess != this.retSuccess) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected return value"); } if (retSuccess == false) { return; } if (retBdata.mStartLine != this.retStartLine) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected start line value"); } if (retBdata.mEndLine != this.retEndLine) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected end line value"); } if (retBlock.mName != this.retCommentBlockName) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected block name"); } if (retBdata.mIndentation != this.retIndentation) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected indentation"); } } }
public TestTextPoint( TestFileWrapper parent, int lineNum, int lineCharOffset) { mParent = parent; mLineNum = lineNum; if (lineCharOffset < 1) { throw new System.ArgumentException("lineCharOffset must be greater than 1"); } mCharPosition = lineCharOffset - 1; }
static void DoSimpleSingleFileTest( string testName, string fileNamePrefix, string fileNameSuffix ) { string fileName = @"..\..\Input\" + fileNamePrefix + fileNameSuffix; ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; TestFileWrapper regressionFile = new TestFileWrapper(fileName); EnvDTE.EditPoint tp1 = regressionFile.CreateEditPoint(null); tp1.StartOfDocument(); EnvDTE.EditPoint tp2 = regressionFile.CreateEditPoint(null); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2); regressionFile.WriteToFile(@"..\..\Output\" + fileNamePrefix + ".out" + fileNameSuffix); int lineNum = fileCompare(@"..\..\Output\" + fileNamePrefix + ".out" + fileNameSuffix, @"..\..\Compare\" + fileNamePrefix + ".compare" + fileNameSuffix); if (lineNum != -1) { throw new System.ApplicationException( testName + " regression file does not match compare at line " + lineNum); } //now apply again and ensure consitancy tp1.StartOfDocument(); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2); regressionFile.WriteToFile(@"..\..\Output\" + fileNamePrefix + ".out2" + fileNameSuffix); lineNum = fileCompare(@"..\..\Output\" + fileNamePrefix + ".out2" + fileNameSuffix, @"..\..\Compare\" + fileNamePrefix + ".compare" + fileNameSuffix); if (lineNum != -1) { throw new System.ApplicationException( testName + " 2nd run regression file does not match compare at line " + lineNum); } Console.WriteLine(testName + " tests PASSED."); }
static void DoBlockTests() { string fileName = @"..\..\Input\Regression.cpp"; TestFileWrapper regressionFile = new TestFileWrapper(fileName); ///////////////////////////////////////// // first detection tests ///////////////////////////////////////// foreach (GetBlockFromPointRegression val in mBlockPointValues) { val.doTest(regressionFile, fileName); } ////////////////////////////////////////// // now formatting tests one by one ////////////////////////////////////////// ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; EnvDTE.EditPoint[] tp = new EnvDTE.EditPoint[mBlockPointValues.Length]; for (int i = 0; i < mBlockPointValues.Length; i++) { tp[i] = regressionFile.CreateEditPoint(null); tp[i].MoveToLineAndOffset(mBlockPointValues[i].retStartLine, 1); } for (int i = 0; i < tp.Length; i++) { try { CommentReflowerObj.WrapBlockContainingPoint(pset, fileName, tp[i]); } catch (Exception) { if (mBlockPointValues[i].retSuccess == true) { throw; } } } regressionFile.WriteToFile(@"..\..\Output\Regression.out.cpp"); int lineNum = fileCompare(@"..\..\Output\Regression.out.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "One by One Block regression file does not match compare at line " + lineNum); } //////////////////////////////////////// // now formatting tests all at once //////////////////////////////////////// TestFileWrapper regressionFile2 = new TestFileWrapper(fileName); EnvDTE.EditPoint tp1 = regressionFile2.CreateEditPoint(null); tp1.StartOfDocument(); EnvDTE.EditPoint tp2 = regressionFile2.CreateEditPoint(null); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2); regressionFile2.WriteToFile(@"..\..\Output\Regression.out2.cpp"); lineNum = fileCompare(@"..\..\Output\Regression.out2.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "Whole block regression file does not match compare at line " + lineNum); } //now apply again and ensure consitancy tp1.StartOfDocument(); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2); regressionFile2.WriteToFile(@"..\..\Output\Regression.out3.cpp"); lineNum = fileCompare(@"..\..\Output\Regression.out3.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "Whole block second run regression file does not match compare at line " + lineNum); } Console.WriteLine("Block detection and formatting tests PASSED."); }
static void DoBlockTests() { string fileName = @"..\..\Input\Regression.cpp"; TestFileWrapper regressionFile = new TestFileWrapper(fileName); ///////////////////////////////////////// // first detection tests ///////////////////////////////////////// foreach (GetBlockFromPointRegression val in mBlockPointValues) { val.doTest(regressionFile, fileName); } ////////////////////////////////////////// // now formatting tests one by one ////////////////////////////////////////// ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; EnvDTE.EditPoint[] tp = new EnvDTE.EditPoint[mBlockPointValues.Length]; for (int i=0; i < mBlockPointValues.Length; i++) { tp[i] = regressionFile.CreateEditPoint(null); tp[i].MoveToLineAndOffset(mBlockPointValues[i].retStartLine,1); } for (int i=0; i < tp.Length; i++) { try { CommentReflowerObj.WrapBlockContainingPoint(pset,fileName,tp[i]); } catch (Exception) { if (mBlockPointValues[i].retSuccess == true) { throw; } } } regressionFile.WriteToFile(@"..\..\Output\Regression.out.cpp"); int lineNum = fileCompare(@"..\..\Output\Regression.out.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "One by One Block regression file does not match compare at line " + lineNum); } //////////////////////////////////////// // now formatting tests all at once //////////////////////////////////////// TestFileWrapper regressionFile2 = new TestFileWrapper(fileName); EnvDTE.EditPoint tp1 = regressionFile2.CreateEditPoint(null); tp1.StartOfDocument(); EnvDTE.EditPoint tp2 = regressionFile2.CreateEditPoint(null); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset,fileName,tp1,tp2); regressionFile2.WriteToFile(@"..\..\Output\Regression.out2.cpp"); lineNum = fileCompare(@"..\..\Output\Regression.out2.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "Whole block regression file does not match compare at line " + lineNum); } //now apply again and ensure consitancy tp1.StartOfDocument(); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset,fileName,tp1,tp2); regressionFile2.WriteToFile(@"..\..\Output\Regression.out3.cpp"); lineNum = fileCompare(@"..\..\Output\Regression.out3.cpp", @"..\..\Compare\Regression.compare.cpp"); if (lineNum != -1) { throw new System.ApplicationException( "Whole block second run regression file does not match compare at line " + lineNum); } Console.WriteLine("Block detection and formatting tests PASSED."); }
public void doTest(TestFileWrapper regressionFile, string fileName) { ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; for (int lineNumber = this.retStartLine; lineNumber <= this.retEndLine; lineNumber++) { EnvDTE.EditPoint tp1 = regressionFile.CreateEditPoint(null); tp1.MoveToLineAndOffset(lineNumber,1); bool retSuccess; MatchedBlockData retBdata; CommentBlock retBlock; retSuccess = CommentReflowerObj.GetBlockContainingPoint( pset, fileName, tp1, out retBlock, out retBdata); if (retSuccess != this.retSuccess) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected return value"); } if (retSuccess == false) { return; } if (retBdata.mStartLine != this.retStartLine) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected start line value"); } if (retBdata.mEndLine != this.retEndLine) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected end line value"); } if (retBlock.mName != this.retCommentBlockName) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected block name"); } if (retBdata.mIndentation != this.retIndentation) { throw new System.ApplicationException( "Blockpoint Regression test line " + lineNumber.ToString() + " does not match expected indentation"); } } }
static void DoSimpleSingleFileTest( string testName, string fileNamePrefix, string fileNameSuffix ) { string fileName = @"..\..\Input\"+fileNamePrefix+fileNameSuffix; ParameterSet pset = new ParameterSet(); pset.mUseTabsToIndent = true; TestFileWrapper regressionFile = new TestFileWrapper(fileName); EnvDTE.EditPoint tp1 = regressionFile.CreateEditPoint(null); tp1.StartOfDocument(); EnvDTE.EditPoint tp2 = regressionFile.CreateEditPoint(null); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset,fileName,tp1,tp2); regressionFile.WriteToFile(@"..\..\Output\"+fileNamePrefix+".out"+fileNameSuffix); int lineNum = fileCompare(@"..\..\Output\"+fileNamePrefix+".out"+fileNameSuffix, @"..\..\Compare\"+fileNamePrefix+".compare"+fileNameSuffix); if (lineNum != -1) { throw new System.ApplicationException( testName + " regression file does not match compare at line " + lineNum); } //now apply again and ensure consitancy tp1.StartOfDocument(); tp2.EndOfDocument(); CommentReflowerObj.WrapAllBlocksInSelection(pset,fileName,tp1,tp2); regressionFile.WriteToFile(@"..\..\Output\"+fileNamePrefix+".out2"+fileNameSuffix); lineNum = fileCompare(@"..\..\Output\"+fileNamePrefix+".out2"+fileNameSuffix, @"..\..\Compare\"+fileNamePrefix+".compare"+fileNameSuffix); if (lineNum != -1) { throw new System.ApplicationException( testName + " 2nd run regression file does not match compare at line " + lineNum); } Console.WriteLine(testName + " tests PASSED."); }