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).
131 lines
3.2 KiB
C++
131 lines
3.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include <vanetza/common/bit_number.hpp>
|
|
#include <vanetza/security/v2/validity_restriction.hpp>
|
|
#include <vanetza/security/v2/tests/check_validity_restriction.hpp>
|
|
#include <vanetza/security/tests/serialization.hpp>
|
|
|
|
using namespace vanetza::security::v2;
|
|
|
|
TEST(Duration, Raw)
|
|
{
|
|
uint16_t a = 0x8007;
|
|
uint16_t b = 7;
|
|
|
|
Duration dur1(b, Duration::Units::Years);
|
|
Duration dur2(a);
|
|
|
|
EXPECT_EQ(dur1.raw(), a);
|
|
EXPECT_EQ(dur2.raw(), a);
|
|
}
|
|
|
|
TEST(Duration, Unit)
|
|
{
|
|
const uint16_t raw = 0x8007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.unit(), Duration::Units::Years);
|
|
}
|
|
|
|
TEST(Duration, Value)
|
|
{
|
|
const uint16_t raw = 0x8007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 7);
|
|
}
|
|
|
|
TEST(Duration, ToSeconds_Seconds)
|
|
{
|
|
const uint16_t raw = 0x0007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 7);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::seconds(7));
|
|
}
|
|
|
|
TEST(Duration, ToSeconds_Minutes)
|
|
{
|
|
const uint16_t raw = 0x2007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 7);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::minutes(7));
|
|
}
|
|
|
|
TEST(Duration, ToSeconds_Hours)
|
|
{
|
|
const uint16_t raw = 0x4007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 7);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::hours(7));
|
|
}
|
|
|
|
TEST(Duration, ToSeconds_Sixty_Hour_Blocks)
|
|
{
|
|
const uint16_t raw = 0x6007;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 7);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::hours(7 * 60));
|
|
}
|
|
|
|
TEST(Duration, ToSeconds_Years)
|
|
{
|
|
const uint16_t raw = 0x8002;
|
|
Duration duration(raw);
|
|
|
|
EXPECT_EQ(duration.raw(), raw);
|
|
EXPECT_EQ(duration.value(), 2);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::seconds(2 * 31556925));
|
|
}
|
|
|
|
TEST(Duration, ToSecondsMax)
|
|
{
|
|
Duration duration(0xffff, Duration::Units::Years);
|
|
EXPECT_EQ(duration.value(), 0x1fff);
|
|
EXPECT_EQ(duration.unit(), Duration::Units::Years);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::seconds(static_cast<int64_t>(31556925) * 0x1fff));
|
|
}
|
|
|
|
TEST(Duration, ToSecondsInvalidUnit)
|
|
{
|
|
Duration duration(0xffff);
|
|
EXPECT_EQ(duration.to_seconds(), std::chrono::seconds::min());
|
|
}
|
|
|
|
TEST(ValidityRestriction, Serialization)
|
|
{
|
|
std::list<ValidityRestriction> list;
|
|
list.push_back(EndValidity { 0x548736 });
|
|
list.push_back(StartAndEndValidity { 0x54, 0x5712});
|
|
list.push_back(StartAndDurationValidity { 0x5712, Duration(13, Duration::Units::Hours)});
|
|
list.push_back(GeographicRegion { CircularRegion {} });
|
|
|
|
check(list, serialize_roundtrip(list));
|
|
}
|
|
|
|
TEST(ValidityRestriction, WebValidator_Size)
|
|
{
|
|
std::list<ValidityRestriction> list;
|
|
StartAndEndValidity start;
|
|
start.start_validity = 12345;
|
|
start.end_validity = 4786283;
|
|
list.push_back(start);
|
|
|
|
IdentifiedRegion id;
|
|
id.region_dictionary = RegionDictionary::UN_Stats;
|
|
id.region_identifier = 150;
|
|
id.local_region.set(0);
|
|
list.push_back(GeographicRegion { id });
|
|
|
|
EXPECT_EQ(15, get_size(list));
|
|
// TODO: compare raw bytes
|
|
}
|