Przeglądaj źródła

Adds additional unit tests for etpath

CapXilinx 9 lat temu
rodzic
commit
9af90c9521

+ 3 - 1
source/src/cip/cipepath.c

@@ -242,6 +242,7 @@ LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
 
 LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
     const char *const cip_path) {
+  OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
   const unsigned int kLogicalFormatMask = 0x03;
   const unsigned int logical_format = (*cip_path) & kLogicalFormatMask;
   LogicalSegmentLogicalFormat result = kLogicalSegmentLogicalFormatEightBit;
@@ -266,7 +267,7 @@ LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
 LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(const char *const cip_path) {
 //  OPENER_ASSERT(LOGICAL_SEGMENT_TYPE_EXTENDED_kLogicalSegmentLogicalTypeExtendedLogicalMessageValue == GetPathLogicalSegmentLogicalType(cip_path),
 //                "Trying to extract non-existent extended logical type");
-  OPENER_ASSERT(LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL_MESSAGE_VALUE == GetPathLogicalSegmentLogicalType(cip_path));
+  OPENER_ASSERT(kLogicalSegmentLogicalTypeExtendedLogical == GetPathLogicalSegmentLogicalType(cip_path));
   const unsigned int extended_logical_type = *(cip_path + 1);
   LogicalSegmentExtendedLogicalType result = kLogicalSegmentExtendedLogicalTypeReserved;
   switch(extended_logical_type) {
@@ -284,6 +285,7 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(const
 LogicalSegmentSpecialTypeLogicalFormat GetPathLogicalSegmentSpecialTypeLogicalType(const char *const cip_path) {
 //  OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path), "Not a logical segment!\n");
   OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
+  OPENER_ASSERT(kLogicalSegmentLogicalTypeSpecial == GetPathLogicalSegmentLogicalType(cip_path));
   const unsigned int kLogicalFormatMask = 0x03;
   const unsigned int logical_format = (*cip_path) & kLogicalFormatMask;
 

+ 7 - 0
source/src/cip/cipepath.h

@@ -80,4 +80,11 @@ void SetPathPortSegmentExtendedPortIdentifier(
 
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(const char *const cip_path);
 
+LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
+    const char *const cip_path);
+
+LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(const char *const cip_path);
+
+LogicalSegmentSpecialTypeLogicalFormat GetPathLogicalSegmentSpecialTypeLogicalType(const char *const cip_path);
+
 #endif /* SRC_CIP_CIPEPATH_H_ */

+ 72 - 0
source/tests/cip/cipepathtest.cpp

@@ -172,3 +172,75 @@ TEST(CipEpath, GetLogicalSegmentLogicalTypeExtendedLogical) {
   const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeExtendedLogical, type);
 }
+
+TEST(CipEpath, GetLogicalSegmentLogicalFormatEightBits) {
+  const char message[] = {0x20};
+  const LogicalSegmentLogicalFormat format = GetPathLogicalSegmentLogicalFormat(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalFormatEightBit, format);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalFormatSixteenBits) {
+  const char message[] = {0x21};
+  const LogicalSegmentLogicalFormat format = GetPathLogicalSegmentLogicalFormat(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalFormatSixteenBit, format);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalFormatThirtyTwoBits) {
+  const char message[] = {0x22};
+  const LogicalSegmentLogicalFormat format = GetPathLogicalSegmentLogicalFormat(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalFormatThirtyTwoBit, format);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeReserved) {
+  const char message[] = {0x3C, 0x00};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeReserved, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeArrayIndex) {
+  const char message[] = {0x3C, 0x01};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeArrayIndex, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeIndirectArrayIndex) {
+  const char message[] = {0x3C, 0x02};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeIndirectArrayIndex, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeBitIndex) {
+  const char message[] = {0x3C, 0x03};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeBitIndex, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeIndirectBitIndex) {
+  const char message[] = {0x3C, 0x04};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeIndirectBitIndex, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeStructureMemberNumber) {
+  const char message[] = {0x3C, 0x05};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeStructureMemberNumber, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeStructureMemberHandle) {
+  const char message[] = {0x3C, 0x06};
+  const LogicalSegmentExtendedLogicalType extended_type = GetPathLogicalSegmentExtendedLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeStructureMemberHandle, extended_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentSpecialTypeLogicalTypeReserved) {
+  const char message[] = {0x35};
+  LogicalSegmentSpecialTypeLogicalFormat special_type = GetPathLogicalSegmentSpecialTypeLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentSpecialTypeLogicalFormatReserved, special_type);
+}
+
+TEST(CipEpath, GetLogicalSegmentSpecialTypeLogicalTypeElectronicKey) {
+  const char message[] = {0x34};
+  LogicalSegmentSpecialTypeLogicalFormat special_type = GetPathLogicalSegmentSpecialTypeLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentSpecialTypeLogicalFormatElectronicKey, special_type);
+}