Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
f36096a9
Commit
f36096a9
authored
8 years ago
by
Jeremie Deray
Browse files
Options
Downloads
Patches
Plain Diff
fix test cmake & add gtest_stamp
parent
feb3e0ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!82
Gtest
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/CMakeLists.txt
+6
-0
6 additions, 0 deletions
test/CMakeLists.txt
test/gtest_time_stamp.cpp
+114
-0
114 additions, 0 deletions
test/gtest_time_stamp.cpp
with
120 additions
and
0 deletions
test/CMakeLists.txt
+
6
−
0
View file @
f36096a9
# Retrieve googletest from github & compile
add_subdirectory
(
${
PROJECT_SOURCE_DIR
}
/test/gtest
)
# Include config.h directory at first.
include_directories
(
${
PROJECT_BINARY_DIR
}
/conf/
)
include_directories
(
${
GTEST_INCLUDE_DIRS
}
)
# Create a specific test executable for gtest_example
wolf_add_gtest
(
gtest_example gtest_example.cpp
)
target_link_libraries
(
gtest_example
${
PROJECT_NAME
}
)
wolf_add_gtest
(
gtest_time_stamp gtest_time_stamp.cpp
)
target_link_libraries
(
gtest_time_stamp
${
PROJECT_NAME
}
)
This diff is collapsed.
Click to expand it.
test/gtest_time_stamp.cpp
0 → 100644
+
114
−
0
View file @
f36096a9
#include
"utils_gtest.h"
#include
"../src/time_stamp.h"
#include
<thread>
TEST
(
WolfTestTimeStamp
,
TimeStampInitNow
)
{
wolf
::
TimeStamp
start
;
// If we don't sleep, start == time_stamp sometimes.
// And sometimes start <= time_stamp ...
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
microseconds
(
1
));
ASSERT_NE
(
start
.
get
(),
0
);
wolf
::
TimeStamp
time_stamp
;
// std::cout << std::fixed;
// std::cout << std::setprecision(15);
// std::cout << start.get() << " | " << time_stamp.get() << std::endl;
ASSERT_NE
(
time_stamp
.
get
(),
start
.
get
());
ASSERT_LT
(
start
.
get
(),
time_stamp
.
get
());
PRINTF
(
"All good at WolfTestTimeStamp::TimeStampInitNow !
\n
"
);
}
TEST
(
WolfTestTimeStamp
,
TimeStampInitScalar
)
{
wolf
::
Scalar
val
(
101010
);
wolf
::
TimeStamp
start
(
val
);
ASSERT_EQ
(
start
.
get
(),
val
);
ASSERT_EQ
(
start
.
getSeconds
(),
val
);
ASSERT_EQ
(
start
.
getNanoSeconds
(),
0
);
std
::
stringstream
ss
;
start
.
print
(
ss
);
ASSERT_STREQ
(
"101010.0000000000"
,
ss
.
str
().
c_str
());
PRINTF
(
"All good at WolfTestTimeStamp::TimeStampInitScalar !
\n
"
);
}
TEST
(
WolfTestTimeStamp
,
TimeStampInitScalarSecNano
)
{
wolf
::
Scalar
sec
(
101010
);
wolf
::
Scalar
nano
(
202020
);
wolf
::
Scalar
val
(
101010.000202020
);
wolf
::
TimeStamp
start
(
sec
,
nano
);
// start.get -> 101010.000202020004508
ASSERT_EQ
(
start
.
get
(),
val
);
ASSERT_EQ
(
start
.
getSeconds
(),
sec
);
ASSERT_EQ
(
start
.
getNanoSeconds
(),
nano
);
std
::
stringstream
ss
;
start
.
print
(
ss
);
ASSERT_STREQ
(
"101010.0002020200"
,
ss
.
str
().
c_str
());
PRINTF
(
"All good at WolfTestTimeStamp::TimeStampInitScalarSecNano !
\n
"
);
}
TEST
(
WolfTestTimeStamp
,
TimeStampEquality
)
{
wolf
::
TimeStamp
start
;
wolf
::
TimeStamp
time_stamp
(
start
);
// error: no match for ‘operator==’
//ASSERT_EQ(time_stamp, start);
ASSERT_EQ
(
time_stamp
.
get
(),
start
.
get
());
time_stamp
.
setToNow
();
ASSERT_NE
(
time_stamp
.
get
(),
start
.
get
());
time_stamp
=
start
;
ASSERT_EQ
(
time_stamp
.
get
(),
start
.
get
());
PRINTF
(
"All good at WolfTestTimeStamp::TimeStampEquality !
\n
"
);
}
TEST
(
WolfTestTimeStamp
,
TimeStampInequality
)
{
wolf
::
TimeStamp
start
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
microseconds
(
1
));
wolf
::
TimeStamp
time_stamp
;
// error: no match for ‘operator!=’
//ASSERT_NE(time_stamp, start);
ASSERT_LT
(
start
,
time_stamp
);
// error: no match for ‘operator>’
//ASSERT_GT(time_stamp, start);
PRINTF
(
"All good at WolfTestTimeStamp::TimeStampInequality !
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
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