Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/security/v2/tests/int_x.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

108 lines
2.1 KiB
C++

#include <vanetza/security/v2/int_x.hpp>
#include <vanetza/security/v2/length_coding.hpp>
#include <vanetza/security/tests/serialization.hpp>
#include <gtest/gtest.h>
using vanetza::ByteBuffer;
using vanetza::security::v2::IntX;
TEST(IntX, set_and_get)
{
IntX a;
EXPECT_EQ(0, a.get());
a.set(static_cast<int8_t>(89));
EXPECT_EQ(89, a.get());
a.set(static_cast<uint32_t>(0x12345678));
EXPECT_EQ(0x12345678, a.get());
}
TEST(IntX, get_size)
{
IntX a;
EXPECT_EQ(1, get_size(a));
a.set(static_cast<int8_t>(89));
EXPECT_EQ(1, get_size(a));
a.set(127);
EXPECT_EQ(1, get_size(a));
a.set(128);
EXPECT_EQ(2, get_size(a));
a.set(0x23);
EXPECT_EQ(1, get_size(a));
a.set(static_cast<uint32_t>(0x00130033));
EXPECT_EQ(3, get_size(a));
a.set(static_cast<uint32_t>(0x00230033));
EXPECT_EQ(4, get_size(a));
a.set(static_cast<uint32_t>(0x33003300));
EXPECT_EQ(5, get_size(a));
}
TEST(IntX, encode)
{
IntX a;
EXPECT_EQ((ByteBuffer { 0x00 }), a.encode());
a.set(127);
EXPECT_EQ((ByteBuffer { 127 }), a.encode());
a.set(128);
EXPECT_EQ((ByteBuffer { 0x80, 128 }), a.encode());
a.set(0x00120034);
EXPECT_EQ((ByteBuffer { 0xd2, 0x00, 0x34 }), a.encode());
a.set(0x00320034);
EXPECT_EQ((ByteBuffer { 0xe0, 0x32, 0x00, 0x34 }), a.encode());
}
TEST(IntX, decode)
{
ByteBuffer buf { 0xe0, 0x32, 0x00, 0x34 };
auto decoded = IntX::decode(buf);
ASSERT_TRUE(!!decoded);
EXPECT_EQ(0x320034, decoded->get());
}
TEST(IntX, decode_one_null_byte)
{
ByteBuffer buf { 0x00 };
auto decoded = IntX::decode(buf);
ASSERT_TRUE(!!decoded);
EXPECT_EQ(0, decoded->get());
}
TEST(IntX, decode_empty)
{
ByteBuffer buf;
auto decoded = IntX::decode(buf);
EXPECT_FALSE(!!decoded);
}
TEST(IntX, decode_broken)
{
ByteBuffer buf { 0xff, 0xff };
auto decoded = IntX::decode(buf);
EXPECT_FALSE(!!decoded);
}
TEST(IntX, serialization)
{
IntX x;
x.set(0);
EXPECT_EQ(x, serialize_roundtrip(x));
x.set(255);
EXPECT_EQ(x, serialize_roundtrip(x));
x.set(0x123456);
EXPECT_EQ(x, serialize_roundtrip(x));
}