Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmake_gtest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evili del Rio i Silvan
cmake_gtest
Commits
01c13e97
Commit
01c13e97
authored
9 years ago
by
Evili del Rio i Silvan
Browse files
Options
Downloads
Patches
Plain Diff
Added correct GMock support and a simple Mock object
parent
2d5e29c6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ext/gtest/CMakeLists.txt
+2
-0
2 additions, 0 deletions
ext/gtest/CMakeLists.txt
tests/CMakeLists.txt
+6
-1
6 additions, 1 deletion
tests/CMakeLists.txt
tests/silly_test.cpp
+27
-0
27 additions, 0 deletions
tests/silly_test.cpp
with
35 additions
and
1 deletion
ext/gtest/CMakeLists.txt
+
2
−
0
View file @
01c13e97
...
...
@@ -17,10 +17,12 @@ ExternalProject_Add(googletest
# Specify include dir
ExternalProject_Get_Property
(
googletest source_dir
)
set
(
GTEST_INCLUDE_DIRS
${
source_dir
}
/googletest/include PARENT_SCOPE
)
set
(
GMOCK_INCLUDE_DIRS
${
source_dir
}
/googlemock/include PARENT_SCOPE
)
# Specify MainTest's link libraries
ExternalProject_Get_Property
(
googletest binary_dir
)
set
(
GTEST_LIBS_DIR
${
binary_dir
}
/googlemock/gtest PARENT_SCOPE
)
set
(
GMOCK_LIBS_DIR
${
binary_dir
}
/googlemock PARENT_SCOPE
)
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
+
6
−
1
View file @
01c13e97
...
...
@@ -4,7 +4,11 @@ include_directories(
)
# Include main source dir
include_directories
(
${${
PROJECT_NAME_STR
}
_SOURCE_DIR
}
/src
${
GTEST_INCLUDE_DIRS
}
)
include_directories
(
${${
PROJECT_NAME_STR
}
_SOURCE_DIR
}
/src
${
GTEST_INCLUDE_DIRS
}
${
GMOCK_INCLUDE_DIRS
}
)
# Exclude tests from coverage
set
(
CTEST_CUSTOM_COVERAGE_EXCLUDE *
)
...
...
@@ -19,6 +23,7 @@ add_executable(unit_test ${SRCS})
add_dependencies
(
unit_test googletest
)
target_link_libraries
(
unit_test
${
GTEST_LIBS_DIR
}
/libgtest.a
${
GTEST_LIBS_DIR
}
/libgtest_main.a
${
GMOCK_LIBS_DIR
}
/libgmock.a
${
GMOCK_LIBS_DIR
}
/libgmock_main.a
${
CMAKE_THREAD_LIBS_INIT
}
)
# Add tests...
...
...
This diff is collapsed.
Click to expand it.
tests/silly_test.cpp
+
27
−
0
View file @
01c13e97
#include
"gtest/gtest.h"
#include
"gmock/gmock.h"
using
::
testing
::
Return
;
class
Thing
{
private:
int
ans
;
public:
Thing
()
:
ans
(
42
)
{};
virtual
int
lue
()
{
return
ans
;
}
};
class
MockThing
:
public
Thing
{
public:
MOCK_METHOD0
(
lue
,
int
());
};
// Just a dummy test that it will fail!
TEST
(
silly_test
,
silly_test
)
{
...
...
@@ -6,3 +24,12 @@ TEST(silly_test, silly_test) {
int
b
=
1
;
EXPECT_EQ
(
a
,
b
)
<<
"a ("
<<
a
<<
") should be equal to b ("
<<
b
<<
")"
;
}
TEST
(
silly_test
,
silly_mock
)
{
MockThing
m
;
EXPECT_CALL
(
m
,
lue
()).
WillOnce
(
Return
(
44
));
int
a
=
m
.
lue
();
EXPECT_EQ
(
a
,
42
)
<<
"The answer to Life, the Universe and Everything should be 42!!!"
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment