static_cache_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <gtest/gtest.h>
31 #include <tf2/time_cache.h>
32 #include <sys/time.h>
33 #include <stdexcept>
34 
35 #include <geometry_msgs/TransformStamped.h>
36 
37 #include <cmath>
38 
39 using namespace tf2;
40 
41 
43 {
44  stor.translation_.setValue(0.0, 0.0, 0.0);
45  stor.rotation_.setValue(0.0, 0.0, 0.0, 1.0);
46 }
47 
48 TEST(StaticCache, Repeatability)
49 {
50  unsigned int runs = 100;
51 
52  tf2::StaticCache cache;
53 
54  TransformStorage stor;
55  setIdentity(stor);
56 
57  for ( uint64_t i = 1; i < runs ; i++ )
58  {
59  stor.frame_id_ = CompactFrameID(i);
60  stor.stamp_ = ros::Time().fromNSec(i);
61 
62  cache.insertData(stor);
63 
64 
65  cache.getData(ros::Time().fromNSec(i), stor);
66  EXPECT_EQ(stor.frame_id_, i);
67  EXPECT_EQ(stor.stamp_, ros::Time().fromNSec(i));
68 
69  }
70 }
71 
72 TEST(StaticCache, DuplicateEntries)
73 {
74 
75  tf2::StaticCache cache;
76 
77  TransformStorage stor;
78  setIdentity(stor);
79  stor.frame_id_ = CompactFrameID(3);
80  stor.stamp_ = ros::Time().fromNSec(1);
81 
82  cache.insertData(stor);
83 
84  cache.insertData(stor);
85 
86 
87  cache.getData(ros::Time().fromNSec(1), stor);
88 
89  //printf(" stor is %f\n", stor.transform.translation.x);
90  EXPECT_TRUE(!std::isnan(stor.translation_.x()));
91  EXPECT_TRUE(!std::isnan(stor.translation_.y()));
92  EXPECT_TRUE(!std::isnan(stor.translation_.z()));
93  EXPECT_TRUE(!std::isnan(stor.rotation_.x()));
94  EXPECT_TRUE(!std::isnan(stor.rotation_.y()));
95  EXPECT_TRUE(!std::isnan(stor.rotation_.z()));
96  EXPECT_TRUE(!std::isnan(stor.rotation_.w()));
97 }
98 
99 int main(int argc, char **argv){
100  testing::InitGoogleTest(&argc, argv);
101  return RUN_ALL_TESTS();
102 }
void setIdentity(geometry_msgs::Transform &tx)
Definition: buffer_core.cpp:92
uint32_t CompactFrameID
Time & fromNSec(uint64_t t)
tf2::Quaternion rotation_
TEST(StaticCache, Repeatability)
virtual bool getData(ros::Time time, TransformStorage &data_out, std::string *error_str=0)
Virtual methods.
Storage for transforms and their parent.
CompactFrameID frame_id_
int main(int argc, char **argv)
virtual bool insertData(const TransformStorage &new_data)
Insert data into the cache.


tf2
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Thu Jan 4 2018 03:35:01