Files
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

73 lines
2.3 KiB
C++

#include <gtest/gtest.h>
#include <vanetza/asn1/security_profile.hpp>
#include VANETZA_ASN1_SECURITY_HEADER(Latitude.h)
#include VANETZA_ASN1_SECURITY_HEADER(Longitude.h)
#include VANETZA_ASN1_SECURITY_HEADER(TwoDLocation.h)
#include <vanetza/common/position_fix.hpp>
#include <vanetza/security/v3/distance.hpp>
#include <boost/units/cmath.hpp>
using namespace vanetza::security::v3;
namespace units = vanetza::units;
namespace boost {
namespace units {
void PrintTo(const vanetza::units::Length& l, std::ostream* out)
{
*out << l.value() << " m";
}
void PrintTo(const vanetza::units::GeoAngle& a, std::ostream* out)
{
*out << a.value() << " deg";
}
} // namespace units
} // namespace boost
#define EXPECT_ANGLE_EQ(a, b) { \
double a_value = units::GeoAngle { a }.value(); \
double b_value = units::GeoAngle { b }.value(); \
EXPECT_NEAR(a_value, b_value, 1e-6); \
}
#define EXPECT_LENGTH_EQ(a, b) { \
double a_value = units::Length { a }.value(); \
double b_value = units::Length { b }.value(); \
EXPECT_NEAR(a_value, b_value, 1.0); \
}
TEST(Distance, distance)
{
vanetza::PositionFix one;
one.latitude = 48.0 * units::degree;
one.longitude = 11.0 * units::degree;
asn1::TwoDLocation other;
other.latitude = 480000000;
other.longitude = 110000000;
EXPECT_LENGTH_EQ(distance(one, other), 0.0 * units::si::meter);
other.latitude = 481234000;
other.longitude = 109876000;
EXPECT_LENGTH_EQ(distance(one, other), 13752.4 * units::si::meter);
}
TEST(Distance, convert_latitude)
{
EXPECT_ANGLE_EQ(convert_latitude(Vanetza_Security_NinetyDegreeInt_min), -90.0 * units::degree);
EXPECT_ANGLE_EQ(convert_latitude(Vanetza_Security_NinetyDegreeInt_max), 90 * units::degree);
EXPECT_ANGLE_EQ(convert_latitude(0), 0 * units::degree);
EXPECT_FALSE(boost::units::isfinite(convert_latitude(Vanetza_Security_NinetyDegreeInt_unknown)));
}
TEST(Distance, convert_longitude)
{
EXPECT_ANGLE_EQ(convert_longitude(Vanetza_Security_OneEightyDegreeInt_min), -179.999999 * units::degree);
EXPECT_ANGLE_EQ(convert_longitude(Vanetza_Security_OneEightyDegreeInt_max), 180 * units::degree);
EXPECT_ANGLE_EQ(convert_longitude(0), 0 * units::degree);
EXPECT_FALSE(boost::units::isfinite(convert_longitude(Vanetza_Security_OneEightyDegreeInt_unknown)));
}