-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Google Test project and item templates (#177)
- Loading branch information
1 parent
2f92e7b
commit c60ccbd
Showing
25 changed files
with
32,479 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest/GTest.vstemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+3.69 KB
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest/gtest-logo.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest/sample_tests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
15 changes: 15 additions & 0 deletions
15
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTestExamples/GTestExamples.vstemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+3.69 KB
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTestExamples/gtest-logo.ico
Binary file not shown.
199 changes: 199 additions & 0 deletions
199
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTestExamples/gtest_examples.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
15 changes: 15 additions & 0 deletions
15
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest_Traits/GTest_Traits.vstemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+3.69 KB
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest_Traits/gtest-logo.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
GoogleTestAdapter/Packaging.GTA/ItemTemplates/Test/GTest_Traits/sample_tests_with_traits.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.