Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include .C files (with extern "C") and include files in higher folders than project file #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Coverage-x86/Coverage-x86.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<OutputFile>$(SolutionDir)/CoverageExt/Resources/$(TargetName)$(TargetExt)</OutputFile>
Expand Down
1 change: 1 addition & 0 deletions Coverage/Coverage.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>dbghelp.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
7 changes: 5 additions & 2 deletions Coverage/CoverageRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ struct CoverageRunner
{
CallbackInfo* info = reinterpret_cast<CallbackInfo*>(userContext);

if (info->fileInfo->PathMatches(lineInfo->FileName))
if ((info->fileInfo->PathMatches(lineInfo->FileName) || info->fileInfo->FileTopLevelMatches(lineInfo->FileName)) && info->fileInfo->FileTypeMatches(lineInfo->FileName))
{
auto file = lineInfo->FileName;
#ifdef _DEBUG
std::cout << "file name to process: " << lineInfo->FileName << std::endl;
#endif

PVOID addr = reinterpret_cast<PVOID>(lineInfo->Address);
auto it = info->breakpointsToSet.find(addr);
Expand Down Expand Up @@ -809,7 +812,7 @@ struct CoverageRunner
// Get information from PC
if (SymGetLineFromAddr64(process->Handle, stack.AddrPC.Offset, &dwDisplacement, &line))
{
if (coverageContext.PathMatches(line.FileName))
if ((coverageContext.PathMatches(line.FileName) || coverageContext.FileTopLevelMatches(line.FileName)) && coverageContext.FileTypeMatches(line.FileName))
{
std::string filename(line.FileName);

Expand Down
49 changes: 48 additions & 1 deletion Coverage/FileCallbackInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ struct FileCallbackInfo
std::swap(lineData, newLineData);
}

bool FileTopLevelMatches(const char* filename)
{
const char* ptr = filename;
const char* gt = sourcePath.data();
const char* gte = gt + sourcePath.size();

int index = 0;

// check top level directory (ex C:\source, c:\work, c:\projects) and make sure source at least is same top level
for (; *ptr && gt != gte && index < 7; ++ptr, ++gt)
{
char lhs = tolower(*gt);
char rhs = tolower(*ptr);
if (lhs != rhs)
{
return false;
}

index++;
}

return true;
}

bool PathMatches(const char* filename)
{
const char* ptr = filename;
Expand All @@ -85,12 +109,35 @@ struct FileCallbackInfo
{
char lhs = tolower(*gt);
char rhs = tolower(*ptr);
if (lhs != rhs) { return false; }
if (lhs != rhs)
{
return false;
}
}

return true;
}

bool FileTypeMatches(const char* filename)
{
bool isCorrect = false;
std::string filenameStr(filename);

int pos = filenameStr.find_last_of('.');

if (pos != std::string::npos)
{
std::string filetype = filenameStr.substr(pos);

if (filetype.compare("C") == 0 || filetype.compare("c") == 0 || filetype.compare("cpp") == 0 || filetype.compare("CPP"))
{
isCorrect = true;
}
}

return isCorrect;
}

FileLineInfo *LineInfo(const std::string& filename, DWORD64 lineNumber)
{
auto it = lineData.find(filename);
Expand Down
2 changes: 1 addition & 1 deletion CoverageExt/CoverageExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void StartImpl(string solutionFolder, string platform, string dllFolder,
{
File.Delete(resultFile);
}

// Find the executables for Coverage.exe
string location = typeof(CoverageExecution).Assembly.Location;
string folder = Path.GetDirectoryName(location);
Expand Down
Binary file modified CoverageExt/CoverageExt.vsix
Binary file not shown.
7 changes: 5 additions & 2 deletions CoverageExt/CoverageExtPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ private void ProjectContextMenuItemCallback(object sender, EventArgs e)
}
}

Settings.Instance.TriggerRedraw();
if (Settings.Instance != null)
{
Settings.Instance.TriggerRedraw();
}
}

private void FileContextMenuItem_BeforeQueryStatus(object sender, EventArgs e)
Expand All @@ -261,7 +264,7 @@ private void FileContextMenuItem_BeforeQueryStatus(object sender, EventArgs e)
var activeDocument = dte.ActiveDocument;
var fullName = activeDocument.FullName;

if (fullName.EndsWith(".h") || fullName.EndsWith(".cpp"))
if (fullName.EndsWith(".h") || fullName.EndsWith(".cpp") || fullName.EndsWith(".c"))
{
menuCommand.Visible = true;
}
Expand Down
Binary file modified CoverageExt/Resources/Coverage-x64.exe
Binary file not shown.
Binary file modified CoverageExt/Resources/Coverage-x64d.exe
Binary file not shown.
Binary file modified CoverageExt/Resources/Coverage-x86.exe
Binary file not shown.
Binary file modified CoverageExt/Resources/Coverage-x86d.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion CoverageExt/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="9A15C37B-BC55-41A6-8B2C-CD50D43BED43" Version="2.37" Language="en-US" Publisher="NubiloSoft" />
<Identity Id="9A15C37B-BC55-41A6-8B2C-CD50D43BED43" Version="2.46" Language="en-US" Publisher="NubiloSoft" />
<DisplayName>CPP Code Coverage Extension</DisplayName>
<Description xml:space="preserve">CPP Code Coverage is a Visual Studio extension that measures code coverage and profiling data.

Expand Down
10 changes: 7 additions & 3 deletions MinimumTest/MinimumTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\MinimumTestHigherFileInclude;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UseFullPaths>true</UseFullPaths>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -146,7 +146,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\MinimumTestHigherFileInclude;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UseFullPaths>true</UseFullPaths>
</ClCompile>
Expand All @@ -160,9 +160,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\MinimumTestHigherFileInclude\TestCHighFile.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="TestCFile.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\MinimumTestHigherFileInclude\TestCHighFile.c" />
<ClCompile Include="TestCFile.c" />
<ClCompile Include="unittest1.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions MinimumTest/MinimumTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestCFile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\MinimumTestHigherFileInclude\TestCHighFile.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="unittest1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestCFile.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\MinimumTestHigherFileInclude\TestCHighFile.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include=".runsettings" />
Expand Down
55 changes: 55 additions & 0 deletions MinimumTest/TestCFile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "TestCFile.h"

#ifdef __cplusplus
extern "C" {

#endif

int testCFunction1(int x)
{
int result = 0;
if (x == 0)
{
result = x + 1;
}
else
{
result = 0xff;
}

return result;
}


int testCFunction2(char *str)
{
int result = 0;

if (*str == '\0')
{
result = 0;
}

return result;
}

void doWhileTest(int x)
{
do
{
x++;

} while (x < 10);
}

void whileTest(int x)
{
while (x < 10)
{
x++;
}
}

#ifdef __cplusplus
}
#endif
19 changes: 19 additions & 0 deletions MinimumTest/TestCFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#ifdef __cplusplus
extern "C" {

#endif

int testCFunction1(int x);

int testCFunction2(char* str);

void doWhileTest(int x);

void whileTest(int x);


#ifdef __cplusplus
}
#endif
79 changes: 79 additions & 0 deletions MinimumTest/unittest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,91 @@
#include <DbgHelp.h>
#pragma warning(default: 4091)

#include "TestCFile.h"
#include "TestCHighFile.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

typedef int(__cdecl *InvokeMethodSignature)();

namespace MinimumTest
{
TEST_CLASS(UnitTestCHighFile)
{
public:

TEST_METHOD(TestMethodC1HighNoElse)
{
testCFunctionHigh1(0);
}

TEST_METHOD(testCFunction2ExecuteExceptionThrown)
{
bool caught = false;
try
{
char* data = '\0';
testCFunctionHigh2(data);
}
catch (...)
{
caught = true;
}
if (!caught)
{
Assert::Fail(L"No exception thrown while one was expected!");
}
}

TEST_METHOD(doWhileHighTest1)
{
doWhileHighTest(0);
}

TEST_METHOD(whileTestHIgh1)
{
whileHighTest(0);
}
};

TEST_CLASS(UnitTestCFile)
{
public:

TEST_METHOD(TestMethodC1NoElse)
{
testCFunction1(0);
}

TEST_METHOD(testCFunction2ExecuteExceptionThrown)
{
bool caught = false;
try
{
char* data = '\0';
testCFunction2(data);
}
catch (...)
{
caught = true;
}
if (!caught)
{
Assert::Fail(L"No exception thrown while one was expected!");
}
}

TEST_METHOD(doWhileTest1)
{
doWhileTest(0);
}

TEST_METHOD(whileTest1)
{
whileTest(0);
}
};

TEST_CLASS(UnitTest1)
{
public:
Expand Down
Loading