Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/common/tests/object_container.cpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but
that tree was gitignored, so a clone of this repository could not build the
firmware it ships. It is now committed here as ordinary files in its own
folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP
bridge's signature verification (--trust) used on the bench. Nothing is
fetched from or pushed to the colleague's repository; this repository and
its remotes carry everything. The folder's own .gitignore keeps build output,
downloaded components and private key material out, as it did there; the
committed file set is identical to that repository's tracked files.

The ESP32-C5 is still flashed from obu-firmware/, which only takes
vanetza-idf from microbu-esp32c5/, so the two stay separate folders.
FLASHING.md says how to take a newer version of the colleague's tree (copy
it over the folder, rebuild, test, commit).
2026-09-23 17:46:40 +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);
}