Skip to content

Commit dc38946

Browse files
committed
Tests for co_pdo_trigger_with_obj
Add unit test for co_pdo_trigger_with_obj
1 parent 370956d commit dc38946

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

test/test_pdo.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,39 @@ TEST_F (PdoTest, TxAcyclic)
728728
EXPECT_EQ (0x181u, mock_os_channel_send_id);
729729
}
730730

731+
TEST_F (PdoTest, TriggerWithObj)
732+
{
733+
net.state = STATE_OP;
734+
735+
net.pdo_tx[0].transmission_type = 0xFF;
736+
net.pdo_tx[0].inhibit_time = 0;
737+
738+
// Should trigger PDO
739+
mock_co_obj_find_result = find_obj (0x6000);
740+
mock_co_entry_find_result = find_entry (mock_co_obj_find_result, 0);
741+
co_pdo_trigger_with_obj (&net, 0x6000, 0);
742+
EXPECT_EQ (0x1u, mock_os_channel_send_calls);
743+
744+
// Should not trigger PDO, not mapped
745+
mock_co_obj_find_result = find_obj (0x6001);
746+
mock_co_entry_find_result = find_entry (mock_co_obj_find_result, 0);
747+
co_pdo_trigger_with_obj (&net, 0x6001, 0);
748+
EXPECT_EQ (0x1u, mock_os_channel_send_calls);
749+
750+
// Should not trigger PDO, does not exist
751+
mock_co_obj_find_result = NULL;
752+
mock_co_entry_find_result = NULL;
753+
co_pdo_trigger_with_obj (&net, 0x6002, 0);
754+
EXPECT_EQ (0x1u, mock_os_channel_send_calls);
755+
756+
// Should not trigger PDO, invalid cob-id
757+
net.pdo_tx[0].cobid = CO_COBID_INVALID | 0x181;
758+
mock_co_obj_find_result = find_obj (0x6000);
759+
mock_co_entry_find_result = find_entry (mock_co_obj_find_result, 0);
760+
co_pdo_trigger_with_obj (&net, 0x6000, 0);
761+
EXPECT_EQ (0x1u, mock_os_channel_send_calls);
762+
}
763+
731764
TEST_F (PdoTest, SparsePdo)
732765
{
733766
const co_obj_t * obj1533 = find_obj (0x1533);

test/test_util.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ class TestBase : public ::testing::Test
128128
{0, OD_NOTIFY | OD_RO | OD_TPDO, DTYPE_UNSIGNED32, 32, 0, &value6000},
129129
};
130130

131+
const co_entry_t OD6001[1] = {
132+
{0, OD_NOTIFY | OD_RO | OD_TPDO, DTYPE_UNSIGNED32, 32, 1, NULL},
133+
};
134+
131135
uint16_t value6003_07;
132136
uint8_t value6003_08;
133137
uint32_t value6003_09;
@@ -159,7 +163,7 @@ class TestBase : public ::testing::Test
159163
{0, OD_RW | OD_RPDO, DTYPE_UNSIGNED32, 32, 0, &value7000},
160164
};
161165

162-
const co_obj_t test_od[36] = {
166+
const co_obj_t test_od[37] = {
163167
// clang-format off
164168
{0x1000, OTYPE_VAR, 0, OD1000, NULL},
165169
{0x1001, OTYPE_VAR, 0, OD1001, co_od1001_fn},
@@ -194,6 +198,7 @@ class TestBase : public ::testing::Test
194198
{0x2000, OTYPE_ARRAY, 8, OD2000, NULL},
195199
{0x2001, OTYPE_RECORD, 2, OD2001, cb2001},
196200
{0x6000, OTYPE_VAR, 0, OD6000, NULL},
201+
{0x6001, OTYPE_VAR, 0, OD6001, NULL},
197202
{0x6003, OTYPE_RECORD, 12, OD6003, NULL},
198203
{0x7000, OTYPE_VAR, 0, OD7000, NULL},
199204
{0, OTYPE_NULL, 0, NULL, NULL},

0 commit comments

Comments
 (0)