Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
f63e2a14
Commit
f63e2a14
authored
Aug 01, 2017
by
misterg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
7755e5d2
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
334 additions
and
28 deletions
+334
-28
.gitignore
.gitignore
+2
-0
BUILD.bazel
BUILD.bazel
+292
-0
WORKSPACE
WORKSPACE
+2
-0
sample10_unittest.cc
googletest/samples/sample10_unittest.cc
+3
-1
sample1_unittest.cc
googletest/samples/sample1_unittest.cc
+3
-6
sample2_unittest.cc
googletest/samples/sample2_unittest.cc
+3
-1
sample3_unittest.cc
googletest/samples/sample3_unittest.cc
+4
-4
sample4_unittest.cc
googletest/samples/sample4_unittest.cc
+3
-1
sample5_unittest.cc
googletest/samples/sample5_unittest.cc
+2
-2
sample6_unittest.cc
googletest/samples/sample6_unittest.cc
+3
-1
sample7_unittest.cc
googletest/samples/sample7_unittest.cc
+11
-10
sample8_unittest.cc
googletest/samples/sample8_unittest.cc
+3
-1
sample9_unittest.cc
googletest/samples/sample9_unittest.cc
+3
-1
No files found.
.gitignore
View file @
f63e2a14
# Ignore CI build directory
build/
xcuserdata
cmake-build-debug/
.idea/
BUILD.bazel
0 → 100644
View file @
f63e2a14
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
config_setting(
name = "win",
values = {"cpu": "x64_windows_msvc"},
)
cc_library(
name = "gmock",
srcs = glob(
include = [
"googlemock/src/*.cc",
"googlemock/include/gmock/**/*.h",
],
exclude = [
"googlemock/src/gmock-all.cc",
],
),
hdrs = glob([
"googlemock/include/gmock/*.h",
]),
includes = [
"googlemock",
"googlemock/include",
],
linkopts = select({
":win": [],
"//conditions:default": ["-pthread"],
}),
deps = [
":gtest",
],
)
cc_library(
name = "gtest",
srcs = glob(
include = [
"googletest/src/*.cc",
"googletest/src/*.h",
"googletest/include/gtest/**/*.h",
],
exclude = [
"googletest/src/gtest-all.cc",
"googletest/src/gtest_main.cc",
],
),
hdrs = glob([
"googletest/include/gtest/*.h",
]),
copts = select(
{
":win": [],
"//conditions:default": ["-pthread"],
},
),
includes = [
"googletest",
"googletest/include",
],
linkopts = select({
":win": [],
"//conditions:default": [
"-pthread",
],
}),
)
cc_library(
name = "gtest_main",
srcs = glob(
include = [
"googletest/src/gtest_main.cc",
],
),
hdrs = glob([
"googletest/include/gtest/*.h",
"googletest/include/gtest/**/*.h",
]),
includes = [
"googletest",
"googletest/include",
],
deps = [":gmock"],
)
"""googletest own tests """
#on windows exclude gtest-tuple.h and gtest-tuple_test.cc
filegroup(
name = "win_only_test_files",
srcs = glob(
include = [
"googletest/test/gtest-*.cc",
"googletest/test/*.h",
"googletest/include/gtest/**/*.h",
],
exclude = [
"googletest/src/gtest-unittest-api_test.cc",
"googletest/include/gtest/internal/gtest-tuple.h",
"googletest/test/gtest-tuple_test.cc",
"googletest/src/gtest-all.cc",
"googletest/test/gtest_all_test.cc",
"googletest/test/gtest-death-test_ex_test.cc",
"googletest/test/gtest-listener_test.cc",
"googletest/test/gtest-unittest-api_test.cc",
"googletest/test/gtest-param-test_test.cc",
],
),
)
filegroup(
name = "default_test_files",
srcs = glob(
include = [
"googletest/test/gtest-*.cc",
"googletest/test/*.h",
"googletest/include/gtest/**/*.h",
],
exclude = [
"googletest/src/gtest-unittest-api_test.cc",
"googletest/src/gtest-all.cc",
"googletest/test/gtest_all_test.cc",
"googletest/test/gtest-death-test_ex_test.cc",
"googletest/test/gtest-listener_test.cc",
"googletest/test/gtest-unittest-api_test.cc",
"googletest/test/gtest-param-test_test.cc",
],
),
)
cc_test(
name = "gtest_all_test",
size = "small",
srcs = select({
":win": [":win_only_test_files"],
"//conditions:default": [":default_test_files"],
}),
copts = select({
":win": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
"//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
}),
includes = [
"googletest",
"googletest/include",
"googletest/include/internal",
"googletest/test",
],
linkopts = select({
":win": [],
"//conditions:default": [
"-pthread",
],
}),
deps = [":gtest_main"],
)
""" these googletest tests have their own main()"""
cc_test(
name = "gtest-death-test",
size = "small",
srcs = [
"googletest/test/gtest-death-test_ex_test.cc",
],
copts = [
"-DGTEST_ENABLE_CATCH_EXCEPTIONS_=1",
],
deps = [
":gtest_main",
],
)
cc_test(
name = "gtest-listener_test",
size = "small",
srcs = [
"googletest/test/gtest-listener_test.cc",
],
deps = [
":gtest_main",
],
)
cc_test(
name = "gtest-unittest-api_test",
size = "small",
srcs = [
"googletest/test/gtest-unittest-api_test.cc",
],
deps = [
":gtest_main",
],
)
cc_test(
name = "gtest-param-test_test",
size = "small",
srcs = [
"googletest/test/gtest-param-test2_test.cc",
"googletest/test/gtest-param-test_test.cc",
"googletest/test/gtest-param-test_test.h",
],
deps = [
":gtest_main",
],
)
""" googletest samples"""
cc_library(
name = "googletest_sample_lib",
srcs = [
"googletest/samples/sample1.cc",
"googletest/samples/sample2.cc",
"googletest/samples/sample4.cc",
],
hdrs = [
"googletest/samples/prime_tables.h",
"googletest/samples/sample1.h",
"googletest/samples/sample2.h",
"googletest/samples/sample3-inl.h",
"googletest/samples/sample4.h",
],
deps = ["gtest"],
)
cc_test(
name = "googletest_samples",
size = "small",
srcs = glob(
include = [
"googletest/samples/sample*.cc",
"googletest/samples/sample*.h",
],
exclude = [
"googletest/samples/sample1.cc",
"googletest/samples/sample2.cc",
"googletest/samples/sample4.cc",
"googletest/samples/prime_tables.h",
"googletest/samples/sample1.h",
"googletest/samples/sample2.h",
"googletest/samples/sample3-inl.h",
"googletest/samples/sample4.h",
"googletest/samples/sample9_unittest.cc",
"googletest/samples/sample10_unittest.cc",
],
),
includes = [
"googletest/samples",
],
deps = [
":googletest_sample_lib",
":gtest_main",
],
)
""" googletest samples 9 and 10 have their own main()"""
cc_test(
name = "googletest_sample9",
size = "small",
srcs = glob(
include = [
"googletest/samples/sample9_unittest.cc",
],
),
includes = [
"googletest/samples",
],
deps = [
":gtest",
],
)
cc_test(
name = "googletest_sample10",
size = "small",
srcs = glob(
include = [
"googletest/samples/sample10_unittest.cc",
],
),
includes = [
"googletest/samples",
],
deps = [
":gtest",
],
)
WORKSPACE
0 → 100644
View file @
f63e2a14
workspace(name = "com_google_googletest")
\ No newline at end of file
googletest/samples/sample10_unittest.cc
View file @
f63e2a14
...
...
@@ -35,7 +35,7 @@
#include <stdlib.h>
#include "gtest/gtest.h"
namespace
{
using
::
testing
::
EmptyTestEventListener
;
using
::
testing
::
InitGoogleTest
;
using
::
testing
::
Test
;
...
...
@@ -142,3 +142,4 @@ int main(int argc, char **argv) {
}
return
RUN_ALL_TESTS
();
}
}
// namespace
\ No newline at end of file
googletest/samples/sample1_unittest.cc
View file @
f63e2a14
...
...
@@ -46,7 +46,7 @@
#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace
{
// Step 2. Use the TEST macro to define your tests.
//
...
...
@@ -72,7 +72,6 @@
//
// </TechnicalDetails>
// Tests Factorial().
// Tests factorial of negative numbers.
...
...
@@ -100,9 +99,7 @@ TEST(FactorialTest, Negative) {
}
// Tests factorial of 0.
TEST
(
FactorialTest
,
Zero
)
{
EXPECT_EQ
(
1
,
Factorial
(
0
));
}
TEST
(
FactorialTest
,
Zero
)
{
EXPECT_EQ
(
1
,
Factorial
(
0
));
}
// Tests factorial of positive numbers.
TEST
(
FactorialTest
,
Positive
)
{
...
...
@@ -112,7 +109,6 @@ TEST(FactorialTest, Positive) {
EXPECT_EQ
(
40320
,
Factorial
(
8
));
}
// Tests IsPrime()
// Tests negative input.
...
...
@@ -139,6 +135,7 @@ TEST(IsPrimeTest, Positive) {
EXPECT_FALSE
(
IsPrime
(
6
));
EXPECT_TRUE
(
IsPrime
(
23
));
}
}
// namespace
// Step 3. Call RUN_ALL_TESTS() in main().
//
...
...
googletest/samples/sample2_unittest.cc
View file @
f63e2a14
...
...
@@ -42,7 +42,7 @@
#include "sample2.h"
#include "gtest/gtest.h"
namespace
{
// In this example, we test the MyString class (a simple string).
// Tests the default c'tor.
...
...
@@ -107,3 +107,4 @@ TEST(MyString, Set) {
s
.
Set
(
NULL
);
EXPECT_STREQ
(
NULL
,
s
.
c_string
());
}
}
// namespace
\ No newline at end of file
googletest/samples/sample3_unittest.cc
View file @
f63e2a14
...
...
@@ -67,7 +67,7 @@
#include "gtest/gtest.h"
// To use a test fixture, derive a class from testing::Test.
class
QueueTest
:
public
testing
::
Test
{
class
QueueTest
Smpl3
:
public
testing
::
Test
{
protected
:
// You should make the members protected s.t. they can be
// accessed from sub-classes.
...
...
@@ -120,13 +120,13 @@ class QueueTest : public testing::Test {
// instead of TEST.
// Tests the default c'tor.
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
TEST_F
(
QueueTest
Smpl3
,
DefaultConstructor
)
{
// You can access data in the test fixture here.
EXPECT_EQ
(
0u
,
q0_
.
Size
());
}
// Tests Dequeue().
TEST_F
(
QueueTest
,
Dequeue
)
{
TEST_F
(
QueueTest
Smpl3
,
Dequeue
)
{
int
*
n
=
q0_
.
Dequeue
();
EXPECT_TRUE
(
n
==
NULL
);
...
...
@@ -144,7 +144,7 @@ TEST_F(QueueTest, Dequeue) {
}
// Tests the Queue::Map() function.
TEST_F
(
QueueTest
,
Map
)
{
TEST_F
(
QueueTest
Smpl3
,
Map
)
{
MapTester
(
&
q0_
);
MapTester
(
&
q1_
);
MapTester
(
&
q2_
);
...
...
googletest/samples/sample4_unittest.cc
View file @
f63e2a14
...
...
@@ -31,7 +31,7 @@
#include "gtest/gtest.h"
#include "sample4.h"
namespace
{
// Tests the Increment() method.
TEST
(
Counter
,
Increment
)
{
Counter
c
;
...
...
@@ -43,3 +43,4 @@ TEST(Counter, Increment) {
EXPECT_EQ
(
1
,
c
.
Increment
());
EXPECT_EQ
(
2
,
c
.
Increment
());
}
}
// namespace
\ No newline at end of file
googletest/samples/sample5_unittest.cc
View file @
f63e2a14
...
...
@@ -49,7 +49,7 @@
#include "sample3-inl.h"
#include "gtest/gtest.h"
#include "sample1.h"
namespace
{
// In this sample, we want to ensure that every test finishes within
// ~5 seconds. If a test takes longer to run, we consider it a
// failure.
...
...
@@ -191,7 +191,7 @@ TEST_F(QueueTest, Dequeue) {
EXPECT_EQ
(
1u
,
q2_
.
Size
());
delete
n
;
}
}
// namespace
// If necessary, you can derive further test fixtures from a derived
// fixture itself. For example, you can derive another fixture from
// QueueTest. Google Test imposes no limit on how deep the hierarchy
...
...
googletest/samples/sample6_unittest.cc
View file @
f63e2a14
...
...
@@ -36,7 +36,7 @@
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
// First, we define some factory functions for creating instances of
// the implementations. You may be able to skip this step if all your
// implementations can be constructed the same way.
...
...
@@ -222,3 +222,4 @@ INSTANTIATE_TYPED_TEST_CASE_P(OnTheFlyAndPreCalculated, // Instance name
PrimeTableImplementations
);
// Type list
#endif // GTEST_HAS_TYPED_TEST_P
}
// namespace
\ No newline at end of file
googletest/samples/sample7_unittest.cc
View file @
f63e2a14
...
...
@@ -39,7 +39,7 @@
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
#if GTEST_HAS_PARAM_TEST
using
::
testing
::
TestWithParam
;
...
...
@@ -65,9 +65,9 @@ PrimeTable* CreatePreCalculatedPrimeTable() {
// can refer to the test parameter by GetParam(). In this case, the test
// parameter is a factory function which we call in fixture's SetUp() to
// create and store an instance of PrimeTable.
class
PrimeTableTest
:
public
TestWithParam
<
CreatePrimeTableFunc
*>
{
class
PrimeTableTest
Smpl7
:
public
TestWithParam
<
CreatePrimeTableFunc
*>
{
public
:
virtual
~
PrimeTableTest
()
{
delete
table_
;
}
virtual
~
PrimeTableTest
Smpl7
()
{
delete
table_
;
}
virtual
void
SetUp
()
{
table_
=
(
*
GetParam
())();
}
virtual
void
TearDown
()
{
delete
table_
;
...
...
@@ -78,7 +78,7 @@ class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> {
PrimeTable
*
table_
;
};
TEST_P
(
PrimeTableTest
,
ReturnsFalseForNonPrimes
)
{
TEST_P
(
PrimeTableTest
Smpl7
,
ReturnsFalseForNonPrimes
)
{
EXPECT_FALSE
(
table_
->
IsPrime
(
-
5
));
EXPECT_FALSE
(
table_
->
IsPrime
(
0
));
EXPECT_FALSE
(
table_
->
IsPrime
(
1
));
...
...
@@ -87,7 +87,7 @@ TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) {
EXPECT_FALSE
(
table_
->
IsPrime
(
100
));
}
TEST_P
(
PrimeTableTest
,
ReturnsTrueForPrimes
)
{
TEST_P
(
PrimeTableTest
Smpl7
,
ReturnsTrueForPrimes
)
{
EXPECT_TRUE
(
table_
->
IsPrime
(
2
));
EXPECT_TRUE
(
table_
->
IsPrime
(
3
));
EXPECT_TRUE
(
table_
->
IsPrime
(
5
));
...
...
@@ -96,7 +96,7 @@ TEST_P(PrimeTableTest, ReturnsTrueForPrimes) {
EXPECT_TRUE
(
table_
->
IsPrime
(
131
));
}
TEST_P
(
PrimeTableTest
,
CanGetNextPrime
)
{
TEST_P
(
PrimeTableTest
Smpl7
,
CanGetNextPrime
)
{
EXPECT_EQ
(
2
,
table_
->
GetNextPrime
(
0
));
EXPECT_EQ
(
3
,
table_
->
GetNextPrime
(
2
));
EXPECT_EQ
(
5
,
table_
->
GetNextPrime
(
3
));
...
...
@@ -112,10 +112,9 @@ TEST_P(PrimeTableTest, CanGetNextPrime) {
//
// Here, we instantiate our tests with a list of two PrimeTable object
// factory functions:
INSTANTIATE_TEST_CASE_P
(
OnTheFlyAndPreCalculated
,
PrimeTableTest
,
Values
(
&
CreateOnTheFlyPrimeTable
,
&
CreatePreCalculatedPrimeTable
<
1000
>
));
INSTANTIATE_TEST_CASE_P
(
OnTheFlyAndPreCalculated
,
PrimeTableTestSmpl7
,
Values
(
&
CreateOnTheFlyPrimeTable
,
&
CreatePreCalculatedPrimeTable
<
1000
>
));
#else
...
...
@@ -128,3 +127,4 @@ INSTANTIATE_TEST_CASE_P(
TEST
(
DummyTest
,
ValueParameterizedTestsAreNotSupportedOnThisPlatform
)
{}
#endif // GTEST_HAS_PARAM_TEST
}
\ No newline at end of file
googletest/samples/sample8_unittest.cc
View file @
f63e2a14
...
...
@@ -37,7 +37,7 @@
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
#if GTEST_HAS_COMBINE
// Suppose we want to introduce a new, improved implementation of PrimeTable
...
...
@@ -171,3 +171,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
TEST
(
DummyTest
,
CombineIsNotSupportedOnThisPlatform
)
{}
#endif // GTEST_HAS_COMBINE
}
\ No newline at end of file
googletest/samples/sample9_unittest.cc
View file @
f63e2a14
...
...
@@ -35,7 +35,7 @@
#include <stdio.h>
#include "gtest/gtest.h"
namespace
{
using
::
testing
::
EmptyTestEventListener
;
using
::
testing
::
InitGoogleTest
;
using
::
testing
::
Test
;
...
...
@@ -158,3 +158,4 @@ int main(int argc, char **argv) {
return
ret_val
;
}
}
// namespace
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment