فهرست منبع

Adds test for extended port

CapXilinx 9 سال پیش
والد
کامیت
aba62cc5c4
3فایلهای تغییر یافته به همراه18 افزوده شده و 2 حذف شده
  1. 2 2
      source/src/cip/cipepath.c
  2. 4 0
      source/src/cip/cipepath.h
  3. 12 0
      source/tests/cip/cipepathtest.cpp

+ 2 - 2
source/src/cip/cipepath.c

@@ -173,7 +173,7 @@ void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
 unsigned int GetPathPortSegmentLinkAddressSize(const char *const cip_path) {
 //  OPENER_ASSERT(false == GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path),
 //                "Call to non existent extended link address size\n");
-  OPENER_ASSERT(false == GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path));
+  OPENER_ASSERT(true == GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path));
   return *(cip_path + 1);
 }
 
@@ -182,7 +182,7 @@ unsigned int GetPathPortSegmentExtendedPortNumber(const char *const cip_path) {
 //                "There is no extended port available!\n");
   OPENER_ASSERT(kPortSegmentExtendedPort == GetPathPortSegmentPortIdentifier(cip_path));
   const unsigned int kExtendedPortSegmentPosition =
-      GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 3 : 2;
+      GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
   return cip_path[kExtendedPortSegmentPosition]
       + (cip_path[kExtendedPortSegmentPosition + 1] << 8);
 }

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

@@ -71,5 +71,9 @@ unsigned int GetPathPortSegmentPortIdentifier(const char *const cip_path);
 void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
                                       char *const cip_path);
 
+unsigned int GetPathPortSegmentLinkAddressSize(const char *const cip_path);
+
+unsigned int GetPathPortSegmentExtendedPortNumber(const char *const cip_path);
+
 
 #endif /* SRC_CIP_CIPEPATH_H_ */

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

@@ -92,3 +92,15 @@ TEST(CipEpath, SetPortSegmentPortIdentifier) {
   SetPathPortSegmentPortIdentifier(15, message);
   CHECK_EQUAL(15, (unsigned int)(message[0]));
 }
+
+TEST(CipEpath, GetPortSegmentLinkAddressSize) {
+  const char message[] = {0x10,0x04};
+  unsigned int size = GetPathPortSegmentLinkAddressSize(message);
+  CHECK_EQUAL(4, size);
+}
+
+TEST(CipEpath, GetPortSegmentExtendedPortNumberNoExtendedAddress) {
+  const char message[] = {0x0F, 0x22, 0x64};
+  unsigned int extended_port = GetPathPortSegmentExtendedPortNumber(message);
+  CHECK_EQUAL(25634, extended_port);
+}