Skip to content

Commit

Permalink
tests: add acceptance filters
Browse files Browse the repository at this point in the history
  • Loading branch information
coderkalyan committed Nov 11, 2021
1 parent 7d2d582 commit 79ad956
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ gen_test_matrix(test_private
"-Wno-missing-declarations")

gen_test_matrix(test_public
"test_public_tx.cpp;test_public_rx.cpp;test_public_roundtrip.cpp;test_self.cpp"
"test_public_tx.cpp;test_public_rx.cpp;test_public_roundtrip.cpp;test_self.cpp;test_filters.cpp"
""
"-Wmissing-declarations")
54 changes: 54 additions & 0 deletions tests/test_filters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This software is distributed under the terms of the MIT License.
// Copyright (c) 2016-2021 UAVCAN Development Team.

#include "exposed.hpp"
#include "helpers.hpp"

TEST_CASE("FilterSubject")
{
const heartbeat_subject_id = 7509;
CanardFilter heartbeat_config = canardMakeFilterForSubject(heartbeat_subject_id);
REQUIRE(heartbeat_config.extended_can_id & (heartbeat_subject_id << OFFSET_SUBJECT_ID));
REQUIRE(heartbeat_config.extended_mask & FLAG_SERVICE_NOT_MESSAGE);
REQUIRE(heartbeat_config.extended_mask & FLAG_RESERVED_07);
REQUIRE(heartbeat_config.extended_mask & (CANARD_SUBJECT_ID_MAX << OFFSET_SUBJECT_ID));
}

TEST_CASE("FilterService")
{
const access_service_id = 7509;
const node_id = 42;
CanardFilter access_config = canardMakeFilterForService(access_service_id, node_id);
REQUIRE(access_config.extended_can_id & (access_subject_id << OFFSET_SERVICE_ID));
REQUIRE(access_config.extended_can_id & (node_id << OFFSET_DST_NODE_ID));
REQUIRE(access_config.extended_can_id & FLAG_SERVICE_NOT_MESSAGE);
REQUIRE(access_config.extended_mask & FLAG_SERVICE_NOT_MESSAGE);
REQUIRE(access_config.extended_mask & FLAG_RESERVED_23);
REQUIRE(access_config.extended_mask & (CANARD_SERVICE_ID_MAX << OFFSET_SERVICE_ID));
REQUIRE(access_config.extended_mask & (CANARD_NODE_ID_MAX << OFFSET_DST_NODE_ID));
}

TEST_CASE("FilterServices")
{
const node_id = 42;
access_config = canardMakeFilterForServices(node_id);
REQUIRE(access_config.extended_can_id & (node_id << OFFSET_DST_NODE_ID));
REQUIRE(access_config.extended_can_id & FLAG_SERVICE_NOT_MESSAGE);
REQUIRE(access_config.extended_mask & FLAG_SERVICE_NOT_MESSAGE);
REQUIRE(access_config.extended_mask & FLAG_RESERVED_23);
REQUIRE(access_config.extended_mask & (CANARD_NODE_ID_MAX << OFFSET_DST_NODE_ID));
}

TEST_CASE("Consolidate")
{
const heartbeat_subject_id = 7509;
CanardFilter heartbeat_config = canardMakeFilterForSubject(heartbeat_subject_id);

const access_service_id = 7509;
const node_id = 42;
CanardFilter access_config = canardMakeFilterForService(access_service_id, node_id);

CanardFilter combined = canardConsolidateFilters(&heartbeat_config, &access_config);
REQUIRE((combined.extended_mask | heartbeat_config.extended_mask) == heartbeat_config.extended_mask);
REQUIRE((combined.extended_mask | access_config.extended_mask) == access_config.extended_mask);
}

0 comments on commit 79ad956

Please sign in to comment.