Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/sensor/internal/ordered_multi_queue.h"
00018
00019 #include <vector>
00020
00021 #include "absl/memory/memory.h"
00022 #include "gtest/gtest.h"
00023
00024 namespace cartographer {
00025 namespace sensor {
00026 namespace {
00027
00028 class OrderedMultiQueueTest : public ::testing::Test {
00029 protected:
00030
00031 const QueueKey kFirst{1, "a"};
00032 const QueueKey kSecond{1, "b"};
00033 const QueueKey kThird{2, "b"};
00034
00035 void SetUp() {
00036 for (const auto& queue_key : {kFirst, kSecond, kThird}) {
00037 queue_.AddQueue(queue_key, [this](std::unique_ptr<Data> data) {
00038 if (!values_.empty()) {
00039 EXPECT_GE(data->GetTime(), values_.back()->GetTime());
00040 }
00041 values_.push_back(std::move(data));
00042 });
00043 }
00044 }
00045
00046 std::unique_ptr<Data> MakeImu(const int ordinal) {
00047 return MakeDispatchable(
00048 "imu", ImuData{common::FromUniversal(ordinal), Eigen::Vector3d::Zero(),
00049 Eigen::Vector3d::Zero()});
00050 }
00051
00052 std::vector<std::unique_ptr<Data>> values_;
00053 OrderedMultiQueue queue_;
00054 };
00055
00056 TEST_F(OrderedMultiQueueTest, Ordering) {
00057 queue_.Add(kFirst, MakeImu(0));
00058 queue_.Add(kFirst, MakeImu(4));
00059 queue_.Add(kFirst, MakeImu(5));
00060 queue_.Add(kFirst, MakeImu(6));
00061 EXPECT_TRUE(values_.empty());
00062 queue_.Add(kSecond, MakeImu(0));
00063 queue_.Add(kSecond, MakeImu(1));
00064 EXPECT_TRUE(values_.empty());
00065 queue_.Add(kThird, MakeImu(0));
00066 queue_.Add(kThird, MakeImu(2));
00067 EXPECT_EQ(values_.size(), 4);
00068 queue_.Add(kSecond, MakeImu(3));
00069 EXPECT_EQ(values_.size(), 5);
00070 queue_.Add(kSecond, MakeImu(7));
00071 queue_.Add(kThird, MakeImu(8));
00072 queue_.Flush();
00073
00074 EXPECT_EQ(11, values_.size());
00075 for (size_t i = 0; i < values_.size() - 1; ++i) {
00076 EXPECT_LE(values_[i]->GetTime(), values_[i + 1]->GetTime());
00077 }
00078 }
00079
00080 TEST_F(OrderedMultiQueueTest, MarkQueueAsFinished) {
00081 queue_.Add(kFirst, MakeImu(1));
00082 queue_.Add(kFirst, MakeImu(2));
00083 queue_.Add(kFirst, MakeImu(3));
00084 EXPECT_TRUE(values_.empty());
00085 queue_.MarkQueueAsFinished(kFirst);
00086 EXPECT_TRUE(values_.empty());
00087 queue_.MarkQueueAsFinished(kSecond);
00088 EXPECT_TRUE(values_.empty());
00089 queue_.MarkQueueAsFinished(kThird);
00090
00091 EXPECT_EQ(3, values_.size());
00092 for (size_t i = 0; i < values_.size(); ++i) {
00093 EXPECT_EQ(i + 1, common::ToUniversal(values_[i]->GetTime()));
00094 }
00095 }
00096
00097 TEST_F(OrderedMultiQueueTest, CommonStartTimePerTrajectory) {
00098 queue_.Add(kFirst, MakeImu(0));
00099 queue_.Add(kFirst, MakeImu(1));
00100 queue_.Add(kFirst, MakeImu(2));
00101 queue_.Add(kFirst, MakeImu(3));
00102 queue_.Add(kSecond, MakeImu(2));
00103 EXPECT_TRUE(values_.empty());
00104 queue_.Add(kThird, MakeImu(4));
00105 EXPECT_EQ(values_.size(), 2);
00106 queue_.MarkQueueAsFinished(kFirst);
00107 EXPECT_EQ(values_.size(), 2);
00108 queue_.MarkQueueAsFinished(kSecond);
00109 EXPECT_EQ(values_.size(), 4);
00110 queue_.MarkQueueAsFinished(kThird);
00111 EXPECT_EQ(values_.size(), 4);
00112 }
00113
00114 }
00115 }
00116 }