Skip to content

Commit

Permalink
added Google Test project and item templates (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
csoltenborn committed Nov 16, 2017
1 parent 2f92e7b commit c60ccbd
Show file tree
Hide file tree
Showing 25 changed files with 32,479 additions and 32 deletions.
19 changes: 18 additions & 1 deletion GoogleTestAdapter/GoogleTestAdapter.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
VisualStudioVersion = 15.0.27004.2008
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1F754A4D-BD42-4368-8B90-F3C03F24A2F3}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -121,6 +121,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewProjectWizard", "NewProjectWizard\NewProjectWizard.csproj", "{483FE0C7-4E8D-4591-BE45-EAC6B2EA5F4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packaging.GTA", "Packaging.GTA\Packaging.GTA.csproj", "{4735D8CC-FA30-432D-854C-2984A7DA5DD2}"
ProjectSection(ProjectDependencies) = postProject
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689} = {6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packaging.TAfGT", "Packaging.TAfGT\Packaging.TAfGT.csproj", "{B3AEAD11-8EA3-4AB0-9DB0-643BFAAEB9B2}"
EndProject
Expand Down Expand Up @@ -152,6 +155,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FakeGtestDllApplication", "
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FakeGtestDllApplication-x64", "FakeGtestDll\FakeGtestDllApplication-x64.vcxproj", "{05C435E1-603C-4402-B28C-E54932F3131C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectTemplate_GTA", "ProjectTemplate_GTA\ProjectTemplate_GTA.csproj", "{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
VsPackage.Shared\VsPackage.Shared.projitems*{55294b5f-a075-43f2-b0e9-2b11925e8b91}*SharedItemsImports = 4
Expand Down Expand Up @@ -575,6 +580,18 @@ Global
{05C435E1-603C-4402-B28C-E54932F3131C}.Release|x64.Deploy.0 = Release|x64
{05C435E1-603C-4402-B28C-E54932F3131C}.Release|x86.ActiveCfg = Release|x64
{05C435E1-603C-4402-B28C-E54932F3131C}.Release|x86.Build.0 = Release|x64
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|x64.ActiveCfg = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|x64.Build.0 = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|x86.ActiveCfg = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Debug|x86.Build.0 = Debug|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|Any CPU.Build.0 = Release|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|x64.ActiveCfg = Release|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|x64.Build.0 = Release|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|x86.ActiveCfg = Release|Any CPU
{6025D96C-B1A8-4E30-8FD7-5E0A88C6D689}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions GoogleTestAdapter/Packaging.GTA/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.pkgdef
ProjectTemplates/Test/ProjectTemplate_GTA.zip
ItemTemplates/Test/GTestExamples.zip
ItemTemplates/Test/GTest.zip
ItemTemplates/Test/GTest_Traits.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<ProjectType>VC</ProjectType>
<TemplateID>0A5607E4-4889-4EDD-9EB8-C615E32E892F</TemplateID>
<Name>Google Test</Name>
<Description>A Google Test based unit test.</Description>
<Icon>gtest-logo.ico</Icon>
<SortOrder>110</SortOrder>
<DefaultName>tests.cpp</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.cpp" >sample_tests.cpp</ProjectItem>
</TemplateContent>
</VSTemplate>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "gtest\gtest.h"

TEST(test_case_name, test_name)
{
ASSERT_EQ(1, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<ProjectType>VC</ProjectType>
<TemplateID>2DC42E19-51C4-4418-B738-367F29DE1851</TemplateID>
<Name>Google Test sample code</Name>
<Description>Sample code demonstrating Google Test's different test types.</Description>
<Icon>gtest-logo.ico</Icon>
<SortOrder>130</SortOrder>
<DefaultName>gtest_examples.cpp</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.cpp" >gtest_examples.cpp</ProjectItem>
</TemplateContent>
</VSTemplate>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
#include "gtest\gtest.h"
#include "GTA_Traits_1.8.0.h"


// code under test
class IFibonacci
{
public:
virtual unsigned int Fib(unsigned int n) = 0;
};

class RecursiveFibonacci : public IFibonacci
{
public:
unsigned int Fib(unsigned int n) override
{
if (n < 1) throw std::invalid_argument("n must be >=1");

return n == 1 || n == 2 ? 1 : Fib(n - 1) + Fib(n - 2);
}
};

class IterativeFibonacci : public IFibonacci
{
public:
unsigned int Fib(unsigned int n) override
{
if (n < 1) throw std::invalid_argument("n must be >=1");

unsigned int last = 1, result = 1;
for (unsigned int i = 3; i <= n; i++)
{
unsigned int temp = last + result;
last = result;
result = temp;
}
return result;
}
};


// the assertions (to be reused by the different test types of this demo)
void AssertThrowsForZero(IFibonacci* fibonacci)
{
ASSERT_THROW(fibonacci->Fib(0), std::invalid_argument);
}

void AssertComputesCorrectValue(IFibonacci* fibonacci)
{
EXPECT_EQ(1, fibonacci->Fib(1));
EXPECT_EQ(1, fibonacci->Fib(2));
EXPECT_EQ(2, fibonacci->Fib(3));
EXPECT_EQ(3, fibonacci->Fib(4));
EXPECT_EQ(5, fibonacci->Fib(5));
EXPECT_EQ(832040, fibonacci->Fib(30));
}


// simple tests
TEST(SimpleTests, ThrowsForZero)
{
IFibonacci* fibonacci = new IterativeFibonacci();
AssertThrowsForZero(fibonacci);
delete fibonacci;
}

TEST_TRAITS(SimpleTests, ComputesCorrectValue, Type, Complex)
{
IFibonacci* fibonacci = new IterativeFibonacci();
AssertComputesCorrectValue(fibonacci);
delete fibonacci;
}


// text fixtures
class FixtureTests : public testing::Test
{
protected:
static int* some_shared_expensive_resource;
IFibonacci* _fibonacci;

static void SetUpTestCase()
{
some_shared_expensive_resource = new int(0);
}

void SetUp() override
{
_fibonacci = new IterativeFibonacci();
}

void TearDown() override
{
delete _fibonacci;
}

static void TearDownTestCase()
{
delete some_shared_expensive_resource;
}
};

int* FixtureTests::some_shared_expensive_resource = NULL;

TEST_F(FixtureTests, ThrowsForZero)
{
AssertThrowsForZero(_fibonacci);
}

TEST_F_TRAITS(FixtureTests, ComputesCorrectValue, Type, Complex)
{
AssertComputesCorrectValue(_fibonacci);
}


// parameterized tests
class ParameterizedTests : public testing::TestWithParam<IFibonacci*>
{
};

TEST_P(ParameterizedTests, ThrowsForZero)
{
AssertThrowsForZero(GetParam());
}

TEST_P_TRAITS(ParameterizedTests, ComputesCorrectValue, Type, Complex)
{
AssertComputesCorrectValue(GetParam());
}

IterativeFibonacci iterativeFibonacci;
RecursiveFibonacci recursiveFibonacci;

INSTANTIATE_TEST_CASE_P(
GTA,
ParameterizedTests,
testing::Values(&iterativeFibonacci, &recursiveFibonacci)
);


// typed tests
template < typename T >
class TypedTests : public ::testing::Test {
protected:
typename T* _fibonacci;

void SetUp() override
{
_fibonacci = new T;
}

void TearDown() override
{
delete _fibonacci;
}
};

typedef ::testing::Types<RecursiveFibonacci, IterativeFibonacci> FibonacciTypes;
TYPED_TEST_CASE(TypedTests, FibonacciTypes);

TYPED_TEST(TypedTests, ThrowsForZero) {
AssertThrowsForZero(_fibonacci);
}

TYPED_TEST_TRAITS(TypedTests, ComputesCorrectValue, Type, Complex) {
AssertComputesCorrectValue(_fibonacci);
}


// type-parameterized tests
template < typename T >
class TypeParameterizedTests : public ::testing::Test {
protected:
typename T* _fibonacci;

void SetUp() override
{
_fibonacci = new T;
}

void TearDown() override
{
delete _fibonacci;
}
};

TYPED_TEST_CASE_P(TypeParameterizedTests);

TYPED_TEST_P(TypeParameterizedTests, ThrowsForZero) {
AssertThrowsForZero(_fibonacci);
}

TYPED_TEST_P_TRAITS(TypeParameterizedTests, ComputesCorrectValue, Type, Complex) {
AssertComputesCorrectValue(_fibonacci);
}

REGISTER_TYPED_TEST_CASE_P(TypeParameterizedTests, ThrowsForZero, ComputesCorrectValue);

INSTANTIATE_TYPED_TEST_CASE_P(GTA, TypeParameterizedTests, FibonacciTypes);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<ProjectType>VC</ProjectType>
<TemplateID>F8964068-3761-4F60-B462-475F5C6F2C62</TemplateID>
<Name>Google Test with Traits</Name>
<Description>A Google Test based unit test making use of VS/GTA's traits support.</Description>
<Icon>gtest-logo.ico</Icon>
<SortOrder>120</SortOrder>
<DefaultName>tests.cpp</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.cpp" >sample_tests_with_traits.cpp</ProjectItem>
</TemplateContent>
</VSTemplate>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest\gtest.h"
#include "GTA_Traits_1.8.0.h"

TEST_TRAITS(test_case_name, test_name, trait_name1, trait_value1, trait_name2, trait_value2)
{
ASSERT_EQ(1, 1);
}
47 changes: 47 additions & 0 deletions GoogleTestAdapter/Packaging.GTA/Packaging.GTA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,38 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="ItemTemplates\Test\GTest_Traits\gtest-logo.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ItemTemplates\Test\GTest_Traits\GTest_Traits.vstemplate" />
<Content Include="ItemTemplates\Test\GTest\gtest-logo.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ItemTemplates\Test\GTest\GTest.vstemplate" />
<Content Include="ItemTemplates\Test\GTestExamples\gtest-logo.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ItemTemplates\Test\GTestExamples\GTestExamples.vstemplate" />
<Content Include="ItemTemplates\Test\GTestExamples\gtest_examples.cpp" />
<Content Include="ItemTemplates\Test\GTest\sample_tests.cpp" />
<Content Include="ItemTemplates\Test\GTest_Traits\sample_tests_with_traits.cpp" />
<Content Include="ItemTemplates\Test\GTestExamples.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="ItemTemplates\Test\GTest.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="ItemTemplates\Test\GTest_Traits.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="packages.config" />
<Content Include="ProjectTemplates\Test\ProjectTemplate_GTA.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down Expand Up @@ -101,6 +132,7 @@
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>
<ItemGroup />
<PropertyGroup>
<PostBuildEvent>echo At least one file is needed within the lib/native folder to convince VS that our package can be installed into native C++ projects. &gt;"$(TargetDir)_.txt"

Expand All @@ -109,4 +141,19 @@ $(NuGetPackages)NuGet.CommandLine.3.5.0\tools\nuget pack VsPackage.nuspec -NonIn
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(NuGetPackages)MicroBuild.Core.0.2.0\build\MicroBuild.Core.targets" Condition="Exists('$(NuGetPackages)MicroBuild.Core.0.2.0\build\MicroBuild.Core.targets')" />
<PropertyGroup>
<PreBuildEvent>copy "$(SolutionDir)ProjectTemplate_GTA\bin\$(ConfigurationName)\ProjectTemplates\VC\1033\ProjectTemplate_GTA.zip" "$(ProjectDir)ProjectTemplates\Test\ProjectTemplate_GTA.zip"

powershell Compress-Archive -Path '$(ProjectDir)ItemTemplates\Test\GTestExamples\*' -DestinationPath '$(ProjectDir)ItemTemplates\Test\GTestExamples.zip' -Force

powershell Compress-Archive -Path '$(ProjectDir)ItemTemplates\Test\GTest\*' -DestinationPath '$(ProjectDir)ItemTemplates\Test\GTest.zip' -Force

powershell Compress-Archive -Path '$(ProjectDir)ItemTemplates\Test\GTest_Traits\*' -DestinationPath '$(ProjectDir)ItemTemplates\Test\GTest_Traits.zip' -Force</PreBuildEvent>
</PropertyGroup>
<Target Name="AfterClean">
<Delete Files="ItemTemplates\Test\GTest.zip" ContinueOnError="true" />
<Delete Files="ItemTemplates\Test\GTest_Traits.zip" ContinueOnError="true" />
<Delete Files="ItemTemplates\Test\GTestExamples.zip" ContinueOnError="true" />
<Delete Files="ProjectTemplates\Test\ProjectTemplate_GTA.zip" ContinueOnError="true" />
</Target>
</Project>
Loading

0 comments on commit c60ccbd

Please sign in to comment.