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).
102 lines
2.7 KiB
C++
102 lines
2.7 KiB
C++
#include <gtest/gtest.h>
|
|
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
|
#include <vanetza/asn1/packet_visitor.hpp>
|
|
#include <vanetza/asn1/its/VanetzaTest.h>
|
|
#include <vanetza/net/packet_variant.hpp>
|
|
#include <boost/variant/apply_visitor.hpp>
|
|
|
|
using namespace vanetza;
|
|
|
|
class TestWrapper : public asn1::asn1c_wrapper<VanetzaTest_t>
|
|
{
|
|
public:
|
|
TestWrapper() : asn1::asn1c_wrapper<VanetzaTest_t>(asn_DEF_VanetzaTest) {}
|
|
};
|
|
|
|
|
|
TEST(PacketVisitor, fresh)
|
|
{
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
EXPECT_EQ(visitor.get_shared_wrapper(), std::shared_ptr<TestWrapper>());
|
|
}
|
|
|
|
TEST(PacketVisitor, deserialize_buffer)
|
|
{
|
|
PacketVariant packet;
|
|
{
|
|
TestWrapper wrapper;
|
|
wrapper->field = 23;
|
|
CohesivePacket cohesive { wrapper.encode(), OsiLayer::Application };
|
|
packet = std::move(cohesive);
|
|
}
|
|
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
auto result = boost::apply_visitor(visitor, packet);
|
|
ASSERT_TRUE(result);
|
|
EXPECT_EQ((*result)->field, 23);
|
|
}
|
|
|
|
TEST(PacketVisitor, deserialize_start)
|
|
{
|
|
PacketVariant packet;
|
|
{
|
|
TestWrapper wrapper;
|
|
wrapper->field = 23;
|
|
CohesivePacket cohesive { wrapper.encode(), OsiLayer::Session };
|
|
packet = std::move(cohesive);
|
|
}
|
|
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
EXPECT_TRUE(boost::apply_visitor(visitor, packet));
|
|
visitor.start_deserialization_at(OsiLayer::Application);
|
|
EXPECT_FALSE(boost::apply_visitor(visitor, packet));
|
|
}
|
|
|
|
TEST(PacketVisitor, cast_chunk)
|
|
{
|
|
PacketVariant packet;
|
|
const VanetzaTest_t* ptr = nullptr;
|
|
{
|
|
ChunkPacket chunk;
|
|
TestWrapper wrapper;
|
|
wrapper->field = 42;
|
|
ptr = &(*wrapper);
|
|
chunk[OsiLayer::Application] = std::move(wrapper);
|
|
packet = std::move(chunk);
|
|
}
|
|
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
auto result = boost::apply_visitor(visitor, packet);
|
|
ASSERT_TRUE(result);
|
|
EXPECT_EQ(&(**result), ptr);
|
|
EXPECT_EQ((*result)->field, 42);
|
|
}
|
|
|
|
TEST(PacketVisitor, deserialize_chunk)
|
|
{
|
|
PacketVariant packet;
|
|
{
|
|
ChunkPacket chunk;
|
|
TestWrapper wrapper;
|
|
wrapper->field = 123;
|
|
chunk[OsiLayer::Application] = wrapper.encode();
|
|
packet = std::move(chunk);
|
|
}
|
|
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
visitor.allow_chunk_deserialization(false);
|
|
EXPECT_FALSE(boost::apply_visitor(visitor, packet));
|
|
|
|
visitor.allow_chunk_deserialization(true);
|
|
EXPECT_TRUE(boost::apply_visitor(visitor, packet));
|
|
}
|
|
|
|
TEST(PacketVisitor, failed)
|
|
{
|
|
asn1::PacketVisitor<TestWrapper> visitor;
|
|
PacketVariant packet { ChunkPacket {} };
|
|
auto result = boost::apply_visitor(visitor, packet);
|
|
EXPECT_FALSE(result);
|
|
EXPECT_FALSE(visitor.get_shared_wrapper());
|
|
}
|