Просмотр исходного кода

Adds tests for electronic key format

CapXilinx 9 лет назад
Родитель
Сommit
765c84a7cd
3 измененных файлов с 19 добавлено и 5 удалено
  1. 0 5
      source/src/cip/cipepath.c
  2. 7 0
      source/src/cip/cipepath.h
  3. 12 0
      source/tests/cip/cipepathtest.cpp

+ 0 - 5
source/src/cip/cipepath.c

@@ -55,11 +55,6 @@ const unsigned int kPortSegmentExtendedPort = 15; /**< Reserved port segment por
 #define NETWORK_SEGMENT_SUBTYPE_PRODUCTION_INHIBIT_TIME_IN_MICROSECONDS_MESSAGE_VALUE 0x10
 #define NETWORK_SEGMENT_SUBTYPE_EXTENDED_NETWORK_MESSAGE_VALUE 0x1F
 
-typedef enum {
-  kElectronicKeySegmentFormatReserved,
-  kElectronicKeySegmentFormatKeyFormat4
-} ElectronicKeySegmentFormat;
-
 #define ELECTRONIC_KEY_SEGMENT_KEY_FORMAT_4_MESSAGE_VALUE 0x04
 
 typedef enum {

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

@@ -60,6 +60,11 @@ typedef enum network_segment_subtype {
   kNetworkSegmentSubtypeExtendedNetworkSegment
 } NetworkSegmentSubtype;
 
+typedef enum {
+  kElectronicKeySegmentFormatReserved,
+  kElectronicKeySegmentFormatKeyFormat4
+} ElectronicKeySegmentFormat;
+
 SegmentType GetPathSegmentType(const char *const cip_path);
 
 void SetPathSegmentType(SegmentType segment_type, char *const cip_path);
@@ -87,4 +92,6 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(const
 
 LogicalSegmentSpecialTypeLogicalFormat GetPathLogicalSegmentSpecialTypeLogicalType(const char *const cip_path);
 
+ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(const char *const cip_path);
+
 #endif /* SRC_CIP_CIPEPATH_H_ */

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

@@ -244,3 +244,15 @@ TEST(CipEpath, GetLogicalSegmentSpecialTypeLogicalTypeElectronicKey) {
   LogicalSegmentSpecialTypeLogicalFormat special_type = GetPathLogicalSegmentSpecialTypeLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentSpecialTypeLogicalFormatElectronicKey, special_type);
 }
+
+TEST(CipEpath, GetPathLogicalSegmentElectronicKeyFormatReserved) {
+  const char message[] = {0x34, 0x00};
+  ElectronicKeySegmentFormat key_format = GetPathLogicalSegmentElectronicKeyFormat(message);
+  CHECK_EQUAL(kElectronicKeySegmentFormatReserved, key_format);
+}
+
+TEST(CipEpath, GetPathLogicalSegmentElectronicKeyFormat4) {
+  const char message[] = {0x34, 0x04};
+  ElectronicKeySegmentFormat key_format = GetPathLogicalSegmentElectronicKeyFormat(message);
+  CHECK_EQUAL(kElectronicKeySegmentFormatKeyFormat4, key_format);
+}