|
| 1 | +// Copyright (c) 2024 Dexory. All rights reserved. |
| 2 | +// |
| 3 | +// Redistribution and use in source and binary forms, with or without |
| 4 | +// modification, are permitted provided that the following conditions are met: |
| 5 | +// |
| 6 | +// * Redistributions of source code must retain the above copyright |
| 7 | +// notice, this list of conditions and the following disclaimer. |
| 8 | +// |
| 9 | +// * Redistributions in binary form must reproduce the above copyright |
| 10 | +// notice, this list of conditions and the following disclaimer in the |
| 11 | +// documentation and/or other materials provided with the distribution. |
| 12 | +// |
| 13 | +// * Neither the name of the Willow Garage 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 HOLDER 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 | +#include <gtest/gtest.h> |
| 30 | + |
| 31 | +#include "tf2/LinearMath/Quaternion.h" |
| 32 | +#include "tf2/LinearMath/Vector3.h" |
| 33 | +#include "tf2/time.h" |
| 34 | +#include "tf2/transform_storage.h" |
| 35 | + |
| 36 | +class TransformStorageTest : public ::testing::Test |
| 37 | +{ |
| 38 | +protected: |
| 39 | + tf2::TransformStorage createTransformStorage() |
| 40 | + { |
| 41 | + const tf2::CompactFrameID frame_id(0); |
| 42 | + const tf2::CompactFrameID child_frame_id(1); |
| 43 | + const tf2::TimePoint stamp(tf2::TimePointZero); |
| 44 | + const tf2::Quaternion rotation(0.0, 0.0, 0.0, 1.0); |
| 45 | + const tf2::Vector3 translation(0.0, 0.0, 0.0); |
| 46 | + return tf2::TransformStorage(stamp, rotation, translation, frame_id, child_frame_id); |
| 47 | + } |
| 48 | +}; |
| 49 | + |
| 50 | +TEST_F(TransformStorageTest, EqualityOperator) { |
| 51 | + // Create a dummy storage, set to identity |
| 52 | + tf2::TransformStorage transformStorage1 = createTransformStorage(); |
| 53 | + |
| 54 | + // tf2::Quaternion rotation_; |
| 55 | + { |
| 56 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 57 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 58 | + transformStorage2.rotation_.setValue(1.0, 0.0, 0.0, 0.0); |
| 59 | + ASSERT_FALSE(transformStorage1 == transformStorage2); |
| 60 | + } |
| 61 | + // tf2::Vector3 translation_; |
| 62 | + { |
| 63 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 64 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 65 | + transformStorage2.translation_.setValue(1.0, 0.0, 0.0); |
| 66 | + ASSERT_FALSE(transformStorage1 == transformStorage2); |
| 67 | + } |
| 68 | + // TimePoint stamp_; |
| 69 | + { |
| 70 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 71 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 72 | + transformStorage2.stamp_ = tf2::TimePoint(tf2::durationFromSec(1.0)); |
| 73 | + ASSERT_FALSE(transformStorage1 == transformStorage2); |
| 74 | + } |
| 75 | + // CompactFrameID frame_id_; |
| 76 | + { |
| 77 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 78 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 79 | + transformStorage2.frame_id_ = 55; |
| 80 | + ASSERT_FALSE(transformStorage1 == transformStorage2); |
| 81 | + } |
| 82 | + // CompactFrameID child_frame_id_; |
| 83 | + { |
| 84 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 85 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 86 | + transformStorage2.translation_.setValue(1.0, 0.0, 0.0); |
| 87 | + ASSERT_FALSE(transformStorage1 == transformStorage2); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +TEST_F(TransformStorageTest, InequalityOperator) { |
| 92 | + // Create a dummy storage, set to identity |
| 93 | + tf2::TransformStorage transformStorage1 = createTransformStorage(); |
| 94 | + |
| 95 | + // tf2::Quaternion rotation_; |
| 96 | + { |
| 97 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 98 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 99 | + transformStorage2.rotation_.setValue(1.0, 0.0, 0.0, 0.0); |
| 100 | + ASSERT_TRUE(transformStorage1 != transformStorage2); |
| 101 | + } |
| 102 | + // tf2::Vector3 translation_; |
| 103 | + { |
| 104 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 105 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 106 | + transformStorage2.translation_.setValue(1.0, 0.0, 0.0); |
| 107 | + ASSERT_TRUE(transformStorage1 != transformStorage2); |
| 108 | + } |
| 109 | + // TimePoint stamp_; |
| 110 | + { |
| 111 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 112 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 113 | + transformStorage2.stamp_ = tf2::TimePoint(tf2::durationFromSec(1.0)); |
| 114 | + ASSERT_TRUE(transformStorage1 != transformStorage2); |
| 115 | + } |
| 116 | + // CompactFrameID frame_id_; |
| 117 | + { |
| 118 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 119 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 120 | + transformStorage2.frame_id_ = 55; |
| 121 | + ASSERT_TRUE(transformStorage1 != transformStorage2); |
| 122 | + } |
| 123 | + // CompactFrameID child_frame_id_; |
| 124 | + { |
| 125 | + tf2::TransformStorage transformStorage2 = createTransformStorage(); |
| 126 | + ASSERT_TRUE(transformStorage1 == transformStorage2); |
| 127 | + transformStorage2.translation_.setValue(1.0, 0.0, 0.0); |
| 128 | + ASSERT_TRUE(transformStorage1 != transformStorage2); |
| 129 | + } |
| 130 | +} |
0 commit comments