Overview:
Scan project dir for .cpp files
public void ScanProjectDir(ProjectInfo projectInfo)
{
WriteLine(3, "ScanProjectDir-Begin");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(projectInfo.sourceDirPath);
var files = dir.GetFiles("*.cpp", System.IO.SearchOption.AllDirectories);
foreach (var file in files)
{
ParseFile(projectInfo, file);
}
WriteLine(3, "ScanProjectDir-End");
}
Parsing a source file
During parsing a hard coded set of test macros is searched. Depending on the type of found macro the relevant test case information is extracted at different positions within the macro:
private void ParseFile(ProjectInfo projectInfo, System.IO.FileInfo in_file)
{
WriteLine(3, "ParseFile-Begin " + in_file.FullName);
WriteLine(2, "File " + in_file.FullName);
string[] lines = System.IO.File.ReadAllLines(in_file.FullName);
int numLines = lines.Length;
ParseInfo parseInfo = new ParseInfo(in_file.FullName);
while (parseInfo.lineIdx < numLines)
{
string line = lines[parseInfo.lineIdx];
if (LineContainsMacro("TTB_TEST_FUNC_DESC",line))
{
MacroInfo macro = ReadMacro(projectInfo, parseInfo,
"TTB_TEST_FUNC_DESC", line, lines);
if (macro != null)
{
parseInfo.description = macro.param2;
projectInfo.appType = AppType.TTB;
parseInfo.RemoveAllTestGroups();
parseInfo.AddTestGroup(in_file.Name);
CreateTestFuncInfo(projectInfo, parseInfo);
}
}
else if (LineContainsMacro("TTB_TEST_FUNC",line))
{
MacroInfo macro = ReadMacro(projectInfo, parseInfo,
"TTB_TEST_FUNC", line, lines);
if (macro != null)
{
parseInfo.description = macro.param1;
projectInfo.appType = AppType.TTB;
parseInfo.RemoveAllTestGroups();
parseInfo.AddTestGroup(in_file.Name);
CreateTestFuncInfo(projectInfo, parseInfo);
}
}
else if (LineContainsMacro("BOOST_AUTO_TEST_CASE_TEMPLATE", line))
{
MacroInfo macro = ReadMacro(projectInfo, parseInfo,
"BOOST_AUTO_TEST_CASE_TEMPLATE", line, lines);
if (macro != null)
{
parseInfo.description = macro.param1;
parseInfo.description += "*";
projectInfo.appType = AppType.BOOST;
CreateTestFuncInfo(projectInfo, parseInfo);
}
}
else if (LineContainsMacro("BOOST_AUTO_TEST_CASE",line))
{
MacroInfo macro = ReadMacro(projectInfo, parseInfo,
"BOOST_AUTO_TEST_CASE", line, lines);
if (macro != null)
{
parseInfo.description = macro.param1;
projectInfo.appType = AppType.BOOST;
CreateTestFuncInfo(projectInfo, parseInfo);
}
}
else if(LineContainsMacro("TTB_BOOST_TEST_CASE",line))
Storing info for each test case
private void CreateTestFuncInfo(ProjectInfo projectInfo, ParseInfo parseInfo)
{
string[] groupNames = parseInfo.GetTestGroupHierarchyString().Split(new Char[] { '/'}, StringSplitOptions.RemoveEmptyEntries);
string groupHierarchyString = "";
List<string> groups = new System.Collections.Generic.List<string>();
if (groupNames.Length == 0)
{
if (!projectInfo.testFuncWithoutTestGroupFound)
{
projectInfo.testFuncWithoutTestGroupFound = true;
groups.Add(ProjectInfo.NO_TESTSUITE_STR);
TestGroupEntry tg = new TestGroupEntry(projectInfo.appType == AppType.BOOST);
tg.fileFullPath = parseInfo.fileFullPath;
tg.lineNum = parseInfo.GetLineNum();
tg.AddTestGroupHierarchy(groups);
projectInfo.testGroups.Add(tg);
}
}
else
{
foreach (string grp in groupNames)
{
groups.Add(grp);
groupHierarchyString += (groupHierarchyString.Length > 0 ? "/" : "");
groupHierarchyString += grp;
if (projectInfo.testGroups.Find(x => (x.GetTestGroupHierarchyString() == groupHierarchyString)) == null)
{
TestGroupEntry tg = new TestGroupEntry(projectInfo.appType == AppType.BOOST);
tg.fileFullPath = parseInfo.fileFullPath;
tg.lineNum = parseInfo.GetLineNum();
tg.AddTestGroupHierarchy(groups);
projectInfo.testGroups.Add(tg);
}
}
}
TestFuncEntry tf = new TestFuncEntry(projectInfo.appType == AppType.BOOST);
tf.testFunc = parseInfo.description;
tf.fileFullPath = parseInfo.fileFullPath;
tf.lineNum = parseInfo.GetLineNum();
tf.AddTestGroupHierarchy(parseInfo.testGroups);
projectInfo.testFuncs.Add(tf);
WriteLine(3, "CreateTestFuncInfo: " + tf.testFunc + " within group: " + tf.GetTestGroupHierarchyString()
+ " file: " + tf.fileFullPath + " line: " + tf.lineNum);
}