Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/common/tests/object_container.cpp
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

118 lines
2.4 KiB
C++

#include <gtest/gtest.h>
#include <vanetza/common/object_container.hpp>
using namespace vanetza;
struct ObjectA
{
int a = 1;
};
struct ObjectB
{
int b = 2;
};
struct ObjectC
{
int c = 3;
};
template<typename T>
std::unique_ptr<T> create_unique()
{
return std::unique_ptr<T> { new T() };
}
TEST(ObjectContainer, size)
{
ObjectContainer c;
EXPECT_EQ(0, c.size());
c.insert(create_unique<ObjectA>());
EXPECT_EQ(1, c.size());
c.insert(create_unique<ObjectA>());
EXPECT_EQ(1, c.size());
c.insert(create_unique<ObjectB>());
EXPECT_EQ(2, c.size());
c.clear();
EXPECT_EQ(0, c.size());
}
TEST(ObjectContainer, insert)
{
ObjectContainer c;
EXPECT_TRUE(c.insert(create_unique<ObjectA>()));
EXPECT_FALSE(c.insert(create_unique<ObjectA>()));
EXPECT_TRUE(c.insert(create_unique<ObjectB>()));
}
TEST(ObjectContainer, find)
{
ObjectContainer c;
EXPECT_EQ(nullptr, c.find<ObjectA>());
auto a = create_unique<ObjectA>();
ObjectA* pa = a.get();
auto b = create_unique<ObjectB>();
ObjectB* pb = b.get();
c.insert(std::move(a));
c.insert(std::move(b));
EXPECT_EQ(pa, c.find<ObjectA>());
EXPECT_EQ(pb, c.find<ObjectB>());
}
TEST(ObjectContainer, erase)
{
ObjectContainer c;
c.insert(create_unique<ObjectA>());
ASSERT_EQ(1, c.size());
c.erase<ObjectB>();
EXPECT_EQ(1, c.size());
c.erase<ObjectA>();
EXPECT_EQ(0, c.size());
c.insert(create_unique<ObjectA>());
c.insert(create_unique<ObjectB>());
c.insert(create_unique<ObjectC>());
c.erase<ObjectB>();
EXPECT_EQ(2, c.size());
EXPECT_NE(nullptr, c.find<ObjectA>());
EXPECT_EQ(nullptr, c.find<ObjectB>());
EXPECT_NE(nullptr, c.find<ObjectC>());
}
TEST(ObjectContainer, move)
{
ObjectContainer c1;
c1.insert(create_unique<ObjectA>());
c1.insert(create_unique<ObjectB>());
c1.insert(create_unique<ObjectC>());
ASSERT_EQ(3, c1.size());
auto* pa = c1.find<ObjectA>();
auto* pb = c1.find<ObjectB>();
auto* pc = c1.find<ObjectC>();
ObjectContainer c2 = std::move(c1);
EXPECT_EQ(0, c1.size());
EXPECT_EQ(3, c2.size());
EXPECT_EQ(pa, c2.find<ObjectA>());
EXPECT_EQ(pb, c2.find<ObjectB>());
EXPECT_EQ(pc, c2.find<ObjectC>());
}
TEST(ObjectContainer, get)
{
ObjectContainer c;
EXPECT_EQ(nullptr, c.find<ObjectA>());
ObjectA& a = c.get<ObjectA>();
EXPECT_EQ(1, a.a);
}