PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_blocks.cpp File Reference

Unit tests for PROFINET block parsing, serialization, and decoding. More...

#include <gtest/gtest.h>
#include "profinet/blocks.h"
#include "profinet/indices.h"
#include "profinet/wire.h"
+ Include dependency graph for test_blocks.cpp:

Go to the source code of this file.

Functions

 TEST_F (BlocksTest, ParseBlockHeader)
 
 TEST_F (BlocksTest, ParseBlockHeaderRejectsTooShortData)
 
 TEST_F (BlocksTest, Align4)
 
 TEST_F (BlocksTest, ParseModuleDiffBlockAllOk)
 
 TEST_F (BlocksTest, ParseModuleDiffBlockWrongSubmodule)
 
 TEST_F (BlocksTest, ParseModuleDiffBlockRejectsWrongBlockType)
 
 TEST_F (BlocksTest, ParseModuleDiffBlockTooShortReturnsEmpty)
 
 TEST_F (BlocksTest, ParseRealIdentificationDataV10)
 
 TEST_F (BlocksTest, ParseRealIdentificationDataTooShortReturnsEmpty)
 
 TEST_F (BlocksTest, IODWriteMultipleBuilderBuildsValidPacket)
 
 TEST_F (BlocksTest, ExpectedSubmoduleBlockReqBuildsInputBlock)
 
 TEST_F (BlocksTest, ExpectedSubmoduleBlockReqInputOutputIncludesTwoDataDescriptions)
 
 TEST_F (BlocksTest, ExpectedSubmoduleBlockReqNoIoProducesOneDataDescription)
 
 TEST_F (BlocksTest, ParsePortStatistics)
 
 TEST_F (BlocksTest, ParsePortStatisticsTooShortReturnsNullopt)
 
 TEST_F (BlocksTest, ParsePdPortDataRealParsesSlotAndSubslot)
 
 TEST_F (BlocksTest, ParsePdPortDataRealDecodesAsciiPortId)
 
 TEST_F (BlocksTest, ParsePdPortDataRealDecodesExtendedLatin1PortId)
 
 TEST_F (BlocksTest, ParsePdPortDataRealParsesPeer)
 
 TEST_F (BlocksTest, ParsePdPortDataRealDecodesExtendedLatin1PeerIds)
 
 TEST_F (BlocksTest, ParsePdPortDataRealParsesMauType)
 
 TEST_F (BlocksTest, ParsePdPortDataRealParsesPortProperties)
 
 TEST_F (BlocksTest, ParsePdPortDataRealParsesCompletePortData)
 
 TEST_F (BlocksTest, ParsePdPortDataRealHandlesEmptyData)
 
 TEST_F (BlocksTest, ParsePdPortDataRealHandlesMissingPortIdLength)
 
 TEST_F (BlocksTest, ParsePdPortDataRealHandlesTruncatedPortId)
 
 TEST_F (BlocksTest, ParsePdPortDataRealHandlesMissingPeerCount)
 
 TEST_F (BlocksTest, DISABLED_ParsePdPortDataRealHandlesTruncatedPeerPortId)
 

Detailed Description

Unit tests for PROFINET block parsing, serialization, and decoding.

Verifies the parsing and construction of PROFINET block data implemented by blocks.cpp.

The tests cover:

  • Block header parsing and validation.
  • 4-byte alignment handling.
  • Module Difference block parsing and state evaluation.
  • Real Identification Data parsing.
  • IOD Write Multiple request construction and response parsing.
  • Expected Submodule Block request construction for different I/O types.
  • Port statistics parsing.
  • PD port data parsing, including peers, link state, boundaries, and media information.
  • Latin-1 to UTF-8 conversion of port and peer identifiers.
  • Handling of truncated and incomplete block data.

Definition in file test_blocks.cpp.

Function Documentation

◆ TEST_F() [1/28]

TEST_F ( BlocksTest  ,
Align4   
)
Test:
align4 rounds up correctly

Definition at line 149 of file test_blocks.cpp.

References profinet::blocks::Align4().

+ Here is the call graph for this function:

◆ TEST_F() [2/28]

TEST_F ( BlocksTest  ,
DISABLED_ParsePdPortDataRealHandlesTruncatedPeerPortId   
)
Test:
ParsePdPortDataReal stops when a peer port ID is truncated.

Definition at line 810 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [3/28]

TEST_F ( BlocksTest  ,
ExpectedSubmoduleBlockReqBuildsInputBlock   
)
Test:
ExpectedSubmoduleBlockReq builds well-formed INPUT block

Definition at line 315 of file test_blocks.cpp.

References profinet::blocks::ExpectedSubmoduleBlockReq::AddSubmodule(), profinet::wire::Reader::SkipTo(), profinet::blocks::ExpectedSubmoduleBlockReq::ToBytes(), and profinet::wire::Reader::U16().

+ Here is the call graph for this function:

◆ TEST_F() [4/28]

TEST_F ( BlocksTest  ,
ExpectedSubmoduleBlockReqInputOutputIncludesTwoDataDescriptions   
)
Test:
ExpectedSubmoduleBlockReq INPUT_OUTPUT includes two DataDescriptions

Definition at line 347 of file test_blocks.cpp.

References profinet::blocks::ExpectedSubmoduleBlockReq::AddSubmodule(), and profinet::blocks::ExpectedSubmoduleBlockReq::ToBytes().

+ Here is the call graph for this function:

◆ TEST_F() [5/28]

TEST_F ( BlocksTest  ,
ExpectedSubmoduleBlockReqNoIoProducesOneDataDescription   
)
Test:
ExpectedSubmoduleBlockReq NO_IO produces exactly one DataDescription

Definition at line 375 of file test_blocks.cpp.

References profinet::blocks::ExpectedSubmoduleBlockReq::AddSubmodule(), and profinet::blocks::ExpectedSubmoduleBlockReq::ToBytes().

+ Here is the call graph for this function:

◆ TEST_F() [6/28]

TEST_F ( BlocksTest  ,
IODWriteMultipleBuilderBuildsValidPacket   
)
Test:
IODWriteMultipleBuilder builds a valid multi-write packet

Definition at line 264 of file test_blocks.cpp.

References profinet::blocks::IODWriteMultipleBuilder::AddWrite(), profinet::blocks::IODWriteMultipleBuilder::Build(), profinet::wire::Reader::SkipTo(), profinet::wire::Reader::U16(), and profinet::WRITE_MULTIPLE.

+ Here is the call graph for this function:

◆ TEST_F() [7/28]

TEST_F ( BlocksTest  ,
ParseBlockHeader   
)
Test:
parse_block_header parses a 6-byte header

Definition at line 125 of file test_blocks.cpp.

References profinet::blocks::ParseBlockHeader().

+ Here is the call graph for this function:

◆ TEST_F() [8/28]

TEST_F ( BlocksTest  ,
ParseBlockHeaderRejectsTooShortData   
)
Test:
parse_block_header rejects too-short data

Definition at line 141 of file test_blocks.cpp.

References profinet::blocks::ParseBlockHeader().

+ Here is the call graph for this function:

◆ TEST_F() [9/28]

TEST_F ( BlocksTest  ,
ParseModuleDiffBlockAllOk   
)
Test:
parse_module_diff_block: all OK

Definition at line 164 of file test_blocks.cpp.

References profinet::MODULE_STATE_PROPER_MODULE, profinet::blocks::ParseModuleDiffBlock(), and profinet::SUBMODULE_STATE_OK.

+ Here is the call graph for this function:

◆ TEST_F() [10/28]

TEST_F ( BlocksTest  ,
ParseModuleDiffBlockRejectsWrongBlockType   
)
Test:
parse_module_diff_block: wrong block type throws

Definition at line 209 of file test_blocks.cpp.

References profinet::blocks::ParseModuleDiffBlock().

+ Here is the call graph for this function:

◆ TEST_F() [11/28]

TEST_F ( BlocksTest  ,
ParseModuleDiffBlockTooShortReturnsEmpty   
)
Test:
parse_module_diff_block: too-short data returns empty block

Definition at line 219 of file test_blocks.cpp.

References profinet::blocks::ParseModuleDiffBlock().

+ Here is the call graph for this function:

◆ TEST_F() [12/28]

TEST_F ( BlocksTest  ,
ParseModuleDiffBlockWrongSubmodule   
)
Test:
parse_module_diff_block: wrong submodule reports mismatch

Definition at line 185 of file test_blocks.cpp.

References profinet::MODULE_STATE_PROPER_MODULE, profinet::blocks::ParseModuleDiffBlock(), and profinet::SUBMODULE_STATE_WRONG_SUBMODULE.

+ Here is the call graph for this function:

◆ TEST_F() [13/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealDecodesAsciiPortId   
)
Test:
ParsePdPortDataReal decodes an ASCII port ID.

Definition at line 561 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [14/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealDecodesExtendedLatin1PeerIds   
)
Test:
ParsePdPortDataReal converts extended Latin-1 peer IDs to UTF-8.

Definition at line 629 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal(), and profinet::blocks::PeerInfo::portId.

+ Here is the call graph for this function:

◆ TEST_F() [15/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealDecodesExtendedLatin1PortId   
)
Test:
ParsePdPortDataReal converts extended Latin-1 port ID bytes to UTF-8.

Definition at line 577 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [16/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealHandlesEmptyData   
)
Test:
ParsePdPortDataReal returns the supplied slot and subslot for empty data.

Definition at line 742 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [17/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealHandlesMissingPeerCount   
)
Test:
ParsePdPortDataReal handles data ending immediately after the port ID.

Definition at line 794 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [18/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealHandlesMissingPortIdLength   
)
Test:
ParsePdPortDataReal handles data ending after slot and subslot.

Definition at line 761 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [19/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealHandlesTruncatedPortId   
)
Test:
ParsePdPortDataReal handles a port ID whose declared length exceeds the data.

Definition at line 776 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [20/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealParsesCompletePortData   
)
Test:
ParsePdPortDataReal parses a complete PD port data structure.

Definition at line 695 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal(), and profinet::blocks::PeerInfo::portId.

+ Here is the call graph for this function:

◆ TEST_F() [21/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealParsesMauType   
)
Test:
ParsePdPortDataReal parses the MAU type.

Definition at line 655 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [22/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealParsesPeer   
)
Test:
ParsePdPortDataReal parses a peer port, chassis ID and MAC address.

Definition at line 599 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal(), and profinet::blocks::PeerInfo::portId.

+ Here is the call graph for this function:

◆ TEST_F() [23/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealParsesPortProperties   
)
Test:
ParsePdPortDataReal parses boundaries, link state and media type.

Definition at line 670 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [24/28]

TEST_F ( BlocksTest  ,
ParsePdPortDataRealParsesSlotAndSubslot   
)
Test:
ParsePdPortDataReal parses the slot and subslot from the payload.

Definition at line 546 of file test_blocks.cpp.

References profinet::blocks::ParsePdPortDataReal().

+ Here is the call graph for this function:

◆ TEST_F() [25/28]

TEST_F ( BlocksTest  ,
ParsePortStatistics   
)
Test:
parse_port_statistics parses a 26-byte body

Definition at line 407 of file test_blocks.cpp.

References profinet::blocks::ParsePortStatistics(), profinet::wire::PutU16(), and profinet::wire::PutU32().

+ Here is the call graph for this function:

◆ TEST_F() [26/28]

TEST_F ( BlocksTest  ,
ParsePortStatisticsTooShortReturnsNullopt   
)
Test:
parse_port_statistics returns nullopt on too-short data

Definition at line 430 of file test_blocks.cpp.

References profinet::blocks::ParsePortStatistics().

+ Here is the call graph for this function:

◆ TEST_F() [27/28]

TEST_F ( BlocksTest  ,
ParseRealIdentificationDataTooShortReturnsEmpty   
)
Test:
parse_real_identification_data returns empty on too-short data

Definition at line 250 of file test_blocks.cpp.

References profinet::blocks::ParseRealIdentificationData().

+ Here is the call graph for this function:

◆ TEST_F() [28/28]

TEST_F ( BlocksTest  ,
ParseRealIdentificationDataV10   
)
Test:
parse_real_identification_data v1.0 parses slot/subslot structure

Definition at line 233 of file test_blocks.cpp.

References profinet::blocks::ParseRealIdentificationData().

+ Here is the call graph for this function: