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.
139 lines
4.4 KiB
C++
139 lines
4.4 KiB
C++
#include <gtest/gtest.h>
|
|
#include <vanetza/asn1/asn1c_wrapper.hpp>
|
|
#include <vanetza/asn1/its/VanetzaTest.h>
|
|
|
|
using namespace vanetza::asn1;
|
|
typedef vanetza::asn1::asn1c_wrapper<VanetzaTest_t> test_wrapper;
|
|
typedef vanetza::asn1::asn1c_oer_wrapper<VanetzaTest_t> test_oer_wrapper;
|
|
|
|
TEST(asn1c_wrapper, create) {
|
|
EXPECT_NO_THROW({
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
});
|
|
}
|
|
|
|
TEST(asn1c_wrapper, constants) {
|
|
EXPECT_EQ(42, VanetzaTest__field_magicValue);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, size) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
EXPECT_EQ(wrapper.size(), 5);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, oer_size) {
|
|
test_oer_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
EXPECT_EQ(wrapper.size(), 7);
|
|
|
|
OCTET_STRING_fromString(&wrapper->string, "12345");
|
|
EXPECT_EQ(wrapper.size(), 8);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, dereferencing) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
ASSERT_NE(wrapper->field, 3);
|
|
wrapper->field = 3;
|
|
EXPECT_EQ((*wrapper).field, 3);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, copy) {
|
|
test_wrapper wrapper_orig(asn_DEF_VanetzaTest);
|
|
wrapper_orig->field = 5;
|
|
test_wrapper wrapper_copy = wrapper_orig;
|
|
EXPECT_EQ(wrapper_copy->field, 5);
|
|
wrapper_copy->field = 6;
|
|
EXPECT_EQ(wrapper_orig->field, 5);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, self_assignment) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
ASSERT_EQ(wrapper.size(), 5);
|
|
wrapper = wrapper;
|
|
EXPECT_EQ(wrapper.size(), 5);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, validate) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
EXPECT_TRUE(wrapper.validate());
|
|
OCTET_STRING_fromString(&wrapper->string, "ABCD"); // non-numerics
|
|
EXPECT_FALSE(wrapper.validate());
|
|
std::string msg;
|
|
EXPECT_FALSE(wrapper.validate(msg));
|
|
EXPECT_FALSE(msg.empty());
|
|
}
|
|
|
|
TEST(asn1c_wrapper, compare) {
|
|
test_wrapper wrapper1(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper1->string, "1234");
|
|
test_wrapper wrapper2(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper2->string, "1234");
|
|
test_wrapper wrapper3(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper3->string, "0123");
|
|
test_wrapper wrapper4(asn_DEF_VanetzaTest);
|
|
wrapper4->field = 5;
|
|
OCTET_STRING_fromString(&wrapper4->string, "1234");
|
|
|
|
// .compare()
|
|
EXPECT_EQ(wrapper1.compare(wrapper1), 0);
|
|
EXPECT_EQ(wrapper1.compare(wrapper2), 0);
|
|
EXPECT_EQ(wrapper1.compare(wrapper3), 1);
|
|
EXPECT_EQ(wrapper1.compare(wrapper4), -1);
|
|
|
|
// operators == and !=
|
|
EXPECT_TRUE(wrapper1 == wrapper1);
|
|
EXPECT_TRUE(wrapper1 == wrapper2);
|
|
EXPECT_FALSE(wrapper1 == wrapper3);
|
|
EXPECT_TRUE(wrapper1 != wrapper3);
|
|
EXPECT_TRUE(wrapper1 != wrapper4);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, print) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
EXPECT_EQ(wrapper.print(), 0);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, encode) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
OCTET_STRING_fromString(&wrapper->string, "1234");
|
|
wrapper->field = 8;
|
|
vanetza::ByteBuffer buf = wrapper.encode();
|
|
EXPECT_EQ(wrapper.size(), buf.size());
|
|
// No idea if this is the correct ASN.1 PER equivalent
|
|
EXPECT_EQ(vanetza::ByteBuffer({ 0x04, 0x02, 0x11, 0xA2, 0x80 }), buf);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, decode_valid) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
const vanetza::ByteBuffer buffer { 0x04, 0x02, 0x11, 0xA2, 0x80 };
|
|
bool result = wrapper.decode(buffer);
|
|
ASSERT_TRUE(result);
|
|
EXPECT_EQ(8, wrapper->field);
|
|
ASSERT_EQ(4, wrapper->string.size);
|
|
EXPECT_STREQ("1234", (const char*)(wrapper->string.buf));
|
|
}
|
|
|
|
TEST(asn1c_wrapper, decode_invalid) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
const vanetza::ByteBuffer buffer { 0x12 };
|
|
bool result = wrapper.decode(buffer);
|
|
// should have failed because of short buffer
|
|
ASSERT_FALSE(result);
|
|
}
|
|
|
|
TEST(asn1c_wrapper, decode_range) {
|
|
test_wrapper wrapper(asn_DEF_VanetzaTest);
|
|
const vanetza::ByteBuffer buffer { 0xC0, 0xFF, 0xEE, 0x04, 0x02, 0x11, 0xA2, 0x80, 0x08, 0x15 };
|
|
auto begin = std::next(buffer.begin(), 3);
|
|
auto end = std::prev(buffer.end(), 2);
|
|
ASSERT_TRUE(wrapper.decode(begin, end));
|
|
EXPECT_EQ(8, wrapper->field);
|
|
EXPECT_EQ(4, wrapper->string.size);
|
|
EXPECT_STREQ("1234", (const char*)(wrapper->string.buf));
|
|
}
|