Skip to content

Commit

Permalink
<SWAUTO-3496> Fix crash when deleting Capture FB after creating it fr…
Browse files Browse the repository at this point in the history
…om status
  • Loading branch information
sedovmo committed Nov 8, 2024
1 parent 5b42a90 commit d8b1f47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion asam_cmp_data_sink/src/data_sink_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void DataSinkFb::addCaptureModuleFromStatus(int index)
const auto newFb = createWithImplementation<IFunctionBlock, CaptureFb>(
context, functionBlocks, fbId, dataPacketsPublisher, capturePacketsPublisher, std::move(deviceStatus));
functionBlocks.addItem(newFb);
capturePacketsPublisher.subscribe(newFb.getPropertyValue("DeviceId"), newFb.as<IAsamCmpPacketsSubscriber>(true));
++captureModuleId;
}

Expand Down
28 changes: 25 additions & 3 deletions asam_cmp_data_sink/tests/test_data_sink_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ TEST_F(DataSinkFbTest, FunctionBlockType)
ASSERT_EQ(type.getDescription(), "ASAM CMP Data Sink");
}

TEST_F(DataSinkFbTest, AddCaptureModuleFromStatus)
TEST_F(DataSinkFbTest, AddCaptureModuleFromStatusReadOnly)
{
auto proc = daq::Procedure([]() {});
EXPECT_THROW(funcBlock.setPropertyValue("AddCaptureModuleFromStatus", proc), daq::AccessDeniedException);
}

TEST_F(DataSinkFbTest, AddCaptureModuleFromStatus)
{
statusHandler->processStatusPacket(cmPacket);
statusHandler->processStatusPacket(ifPacket);

Expand Down Expand Up @@ -158,11 +161,27 @@ TEST_F(DataSinkFbTest, AddCaptureModuleFromStatus)
ASSERT_EQ(interfaceFb.getFunctionBlocks(streamFilter).getCount(), 1);
}

TEST_F(DataSinkFbTest, AddCaptureModuleEmpty)
TEST_F(DataSinkFbTest, RemoveCaptureFromStatus)
{
static const uint16_t deviceId = 1;
cmPacket->setDeviceId(deviceId);
statusHandler->processStatusPacket(cmPacket);

funcBlock.getPropertyValue("AddCaptureModuleFromStatus").execute(0);
capturePacketPublisher.publish(deviceId, cmPacket);

funcBlock.getPropertyValue("RemoveCaptureModule").execute(0);
ASSERT_NO_THROW(capturePacketPublisher.publish(deviceId, cmPacket));
}

TEST_F(DataSinkFbTest, AddCaptureModuleEmptyReadOnly)
{
auto proc = daq::Procedure([]() {});
EXPECT_THROW(funcBlock.setPropertyValue("AddCaptureModuleEmpty", proc), daq::AccessDeniedException);
}

TEST_F(DataSinkFbTest, AddCaptureModuleEmpty)
{
ProcedurePtr func = funcBlock.getPropertyValue("AddCaptureModuleEmpty");
func();
func();
Expand All @@ -187,11 +206,14 @@ TEST_F(DataSinkFbTest, UpdateDeviceInfo)
ASSERT_EQ(propVal.toStdString(), vendorDataAsString);
}

TEST_F(DataSinkFbTest, RemoveCaptureModule)
TEST_F(DataSinkFbTest, RemoveCaptureModuleReadOnly)
{
auto proc = daq::Procedure([]() {});
EXPECT_THROW(funcBlock.setPropertyValue("RemoveCaptureModule", proc), daq::AccessDeniedException);
}

TEST_F(DataSinkFbTest, RemoveCaptureModule)
{
ASSERT_EQ(funcBlock.getFunctionBlocks().getCount(), 0);
ProcedurePtr addFunc = funcBlock.getPropertyValue("AddCaptureModuleEmpty");
addFunc();
Expand Down

0 comments on commit d8b1f47

Please sign in to comment.