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 <stdexcept>
33 
34 #include <geometry_msgs/TransformStamped.h>
35 
36 #include <cmath>
37 
38 using namespace tf2;
39 
40 
42 {
43  stor.translation_.setValue(0.0, 0.0, 0.0);
44  stor.rotation_.setValue(0.0, 0.0, 0.0, 1.0);
45 }
46 
47 TEST(StaticCache, Repeatability)
48 {
49  unsigned int runs = 100;
50 
51  tf2::StaticCache cache;
52 
53  TransformStorage stor;
54  setIdentity(stor);
55 
56  for ( uint64_t i = 1; i < runs ; i++ )
57  {
58  stor.frame_id_ = CompactFrameID(i);
59  stor.stamp_ = ros::Time().fromNSec(i);
60 
61  cache.insertData(stor);
62 
63 
64  cache.getData(ros::Time().fromNSec(i), stor);
65  EXPECT_EQ(stor.frame_id_, i);
66  EXPECT_EQ(stor.stamp_, ros::Time().fromNSec(i));
67 
68  }
69 }
70 
71 TEST(StaticCache, DuplicateEntries)
72 {
73 
74  tf2::StaticCache cache;
75 
76  TransformStorage stor;
77  setIdentity(stor);
78  stor.frame_id_ = CompactFrameID(3);
79  stor.stamp_ = ros::Time().fromNSec(1);
80 
81  cache.insertData(stor);
82 
83  cache.insertData(stor);
84 
85 
86  cache.getData(ros::Time().fromNSec(1), stor);
87 
88  //printf(" stor is %f\n", stor.transform.translation.x);
89  EXPECT_TRUE(!std::isnan(stor.translation_.x()));
90  EXPECT_TRUE(!std::isnan(stor.translation_.y()));
91  EXPECT_TRUE(!std::isnan(stor.translation_.z()));
92  EXPECT_TRUE(!std::isnan(stor.rotation_.x()));
93  EXPECT_TRUE(!std::isnan(stor.rotation_.y()));
94  EXPECT_TRUE(!std::isnan(stor.rotation_.z()));
95  EXPECT_TRUE(!std::isnan(stor.rotation_.w()));
96 }
97 
98 int main(int argc, char **argv){
99  testing::InitGoogleTest(&argc, argv);
100  return RUN_ALL_TESTS();
101 }
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 Mon Jun 27 2022 02:43:06