diff --git a/Coverage-x86/Coverage-x86.vcxproj b/Coverage-x86/Coverage-x86.vcxproj index c1b123a..f7fb71b 100644 --- a/Coverage-x86/Coverage-x86.vcxproj +++ b/Coverage-x86/Coverage-x86.vcxproj @@ -90,6 +90,7 @@ Level3 Disabled true + %(PreprocessorDefinitions) $(SolutionDir)/CoverageExt/Resources/$(TargetName)$(TargetExt) diff --git a/Coverage/Coverage.vcxproj b/Coverage/Coverage.vcxproj index 7b2a568..c4e361f 100644 --- a/Coverage/Coverage.vcxproj +++ b/Coverage/Coverage.vcxproj @@ -95,6 +95,7 @@ Disabled true $(IntDir)vc$(PlatformToolsetVersion).pdb + %(PreprocessorDefinitions) 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) diff --git a/Coverage/CoverageRunner.h b/Coverage/CoverageRunner.h index 30e201e..267d600 100644 --- a/Coverage/CoverageRunner.h +++ b/Coverage/CoverageRunner.h @@ -38,9 +38,12 @@ struct CoverageRunner { CallbackInfo* info = reinterpret_cast(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(lineInfo->Address); auto it = info->breakpointsToSet.find(addr); @@ -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); diff --git a/Coverage/FileCallbackInfo.h b/Coverage/FileCallbackInfo.h index c6d5a26..603dd51 100644 --- a/Coverage/FileCallbackInfo.h +++ b/Coverage/FileCallbackInfo.h @@ -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; @@ -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); diff --git a/CoverageExt/CoverageExecution.cs b/CoverageExt/CoverageExecution.cs index 1402d3e..9c751a3 100644 --- a/CoverageExt/CoverageExecution.cs +++ b/CoverageExt/CoverageExecution.cs @@ -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); diff --git a/CoverageExt/CoverageExt.vsix b/CoverageExt/CoverageExt.vsix index 6409901..5645651 100644 Binary files a/CoverageExt/CoverageExt.vsix and b/CoverageExt/CoverageExt.vsix differ diff --git a/CoverageExt/CoverageExtPackage.cs b/CoverageExt/CoverageExtPackage.cs index 71a7335..f68dcaf 100644 --- a/CoverageExt/CoverageExtPackage.cs +++ b/CoverageExt/CoverageExtPackage.cs @@ -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) @@ -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; } diff --git a/CoverageExt/Resources/Coverage-x64.exe b/CoverageExt/Resources/Coverage-x64.exe index 429d452..2830641 100644 Binary files a/CoverageExt/Resources/Coverage-x64.exe and b/CoverageExt/Resources/Coverage-x64.exe differ diff --git a/CoverageExt/Resources/Coverage-x64d.exe b/CoverageExt/Resources/Coverage-x64d.exe index 3a975a5..25a1cab 100644 Binary files a/CoverageExt/Resources/Coverage-x64d.exe and b/CoverageExt/Resources/Coverage-x64d.exe differ diff --git a/CoverageExt/Resources/Coverage-x86.exe b/CoverageExt/Resources/Coverage-x86.exe index b57047a..6064c61 100644 Binary files a/CoverageExt/Resources/Coverage-x86.exe and b/CoverageExt/Resources/Coverage-x86.exe differ diff --git a/CoverageExt/Resources/Coverage-x86d.exe b/CoverageExt/Resources/Coverage-x86d.exe index 1a21341..37979ef 100644 Binary files a/CoverageExt/Resources/Coverage-x86d.exe and b/CoverageExt/Resources/Coverage-x86d.exe differ diff --git a/CoverageExt/source.extension.vsixmanifest b/CoverageExt/source.extension.vsixmanifest index 5e08a5f..9156367 100644 --- a/CoverageExt/source.extension.vsixmanifest +++ b/CoverageExt/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + CPP Code Coverage Extension CPP Code Coverage is a Visual Studio extension that measures code coverage and profiling data. diff --git a/MinimumTest/MinimumTest.vcxproj b/MinimumTest/MinimumTest.vcxproj index e4cc8e7..f2bb4f6 100644 --- a/MinimumTest/MinimumTest.vcxproj +++ b/MinimumTest/MinimumTest.vcxproj @@ -106,11 +106,11 @@ NotUsing Level3 Disabled - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + ..\MinimumTestHigherFileInclude;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) _DEBUG;%(PreprocessorDefinitions) true Async - Default + EnableFastChecks Windows @@ -146,7 +146,7 @@ MaxSpeed true true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + ..\MinimumTestHigherFileInclude;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) NDEBUG;%(PreprocessorDefinitions) true @@ -160,9 +160,13 @@ + + + + diff --git a/MinimumTest/MinimumTest.vcxproj.filters b/MinimumTest/MinimumTest.vcxproj.filters index 6c091f0..e0530c5 100644 --- a/MinimumTest/MinimumTest.vcxproj.filters +++ b/MinimumTest/MinimumTest.vcxproj.filters @@ -18,11 +18,23 @@ Header Files + + Header Files + + + Header Files + Source Files + + Source Files + + + Source Files + diff --git a/MinimumTest/TestCFile.c b/MinimumTest/TestCFile.c new file mode 100644 index 0000000..f7c1881 --- /dev/null +++ b/MinimumTest/TestCFile.c @@ -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 \ No newline at end of file diff --git a/MinimumTest/TestCFile.h b/MinimumTest/TestCFile.h new file mode 100644 index 0000000..b8cca54 --- /dev/null +++ b/MinimumTest/TestCFile.h @@ -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 \ No newline at end of file diff --git a/MinimumTest/unittest1.cpp b/MinimumTest/unittest1.cpp index 6d395d9..745c57e 100644 --- a/MinimumTest/unittest1.cpp +++ b/MinimumTest/unittest1.cpp @@ -9,12 +9,91 @@ #include #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: diff --git a/MinimumTestHigherFileInclude/TestCHighFile.c b/MinimumTestHigherFileInclude/TestCHighFile.c new file mode 100644 index 0000000..4160aed --- /dev/null +++ b/MinimumTestHigherFileInclude/TestCHighFile.c @@ -0,0 +1,55 @@ +#include "TestCHighFile.h" + +#ifdef __cplusplus +extern "C" { + +#endif + +int testCFunctionHigh1(int x) +{ + int result = 0; + if (x == 0) + { + result = x + 1; + } + else + { + result = 0xff; + } + + return result; +} + + +int testCFunctionHigh2(char *str) +{ + int result = 0; + + if (*str == '\0') + { + result = 0; + } + + return result; +} + +void doWhileHighTest(int x) +{ + do + { + x++; + + } while (x < 10); +} + +void whileHighTest(int x) +{ + while (x < 10) + { + x++; + } +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/MinimumTestHigherFileInclude/TestCHighFile.h b/MinimumTestHigherFileInclude/TestCHighFile.h new file mode 100644 index 0000000..52dffb5 --- /dev/null +++ b/MinimumTestHigherFileInclude/TestCHighFile.h @@ -0,0 +1,19 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { + +#endif + + int testCFunctionHigh1(int x); + + int testCFunctionHigh2(char* str); + + void doWhileHighTest(int x); + + void whileHighTest(int x); + + +#ifdef __cplusplus +} +#endif \ No newline at end of file