cipconnectionobjecttest.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*******************************************************************************
  2. * Copyright (c) 2017, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #include <CppUTest/TestHarness.h>
  7. #include <stdint.h>
  8. #include <string.h>
  9. extern "C" {
  10. #include "cipconnectionobject.h"
  11. }
  12. TEST_GROUP(CipConnectionObject) {
  13. };
  14. TEST(CipConnectionObject, StateNonExistent) {
  15. CipConnectionObject connection_object = { 0 };
  16. connection_object.state = 0;
  17. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  18. CHECK_EQUAL(kConnectionObjectStateNonExistent, state);
  19. }
  20. TEST(CipConnectionObject, StateConfiguring) {
  21. CipConnectionObject connection_object = { 0 };
  22. connection_object.state = 1;
  23. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  24. CHECK_EQUAL(kConnectionObjectStateConfiguring, state);
  25. }
  26. TEST(CipConnectionObject, StateWaitingForConnectionID) {
  27. CipConnectionObject connection_object = { 0 };
  28. connection_object.state = 2;
  29. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  30. CHECK_EQUAL(kConnectionObjectStateWaitingForConnectionID, state);
  31. }
  32. TEST(CipConnectionObject, StateEstablished) {
  33. CipConnectionObject connection_object = { 0 };
  34. connection_object.state = 3;
  35. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  36. CHECK_EQUAL(kConnectionObjectStateEstablished, state);
  37. }
  38. TEST(CipConnectionObject, StateTimedOut) {
  39. CipConnectionObject connection_object = { 0 };
  40. connection_object.state = 4;
  41. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  42. CHECK_EQUAL(kConnectionObjectStateTimedOut, state);
  43. }
  44. TEST(CipConnectionObject, StateDeferredDelete) {
  45. CipConnectionObject connection_object = { 0 };
  46. connection_object.state = 5;
  47. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  48. CHECK_EQUAL(kConnectionObjectStateDeferredDelete, state);
  49. }
  50. TEST(CipConnectionObject, StateClosing) {
  51. CipConnectionObject connection_object = { 0 };
  52. connection_object.state = 6;
  53. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  54. CHECK_EQUAL(kConnectionObjectStateClosing, state);
  55. }
  56. TEST(CipConnectionObject, StateInvalid) {
  57. CipConnectionObject connection_object = { 0 };
  58. connection_object.state = 7;
  59. ConnectionObjectState state = GetConnectionObjectState(&connection_object);
  60. CHECK_EQUAL(kConnectionObjectStateInvalid, state);
  61. }
  62. TEST(CipConnectionObject, InstanceTypeInvalid) {
  63. CipConnectionObject connection_object = { 0 };
  64. connection_object.instance_type = 4;
  65. ConnectionObjectInstanceType type = GetConnectionObjectInstanceType(&connection_object);
  66. CHECK_EQUAL(kConnectionObjectInstanceTypeInvalid, type);
  67. }
  68. TEST(CipConnectionObject, InstanceTypeIExplicitMessaging) {
  69. CipConnectionObject connection_object = { 0 };
  70. connection_object.instance_type = 0;
  71. ConnectionObjectInstanceType type = GetConnectionObjectInstanceType(&connection_object);
  72. CHECK_EQUAL(kConnectionObjectInstanceTypeExplicitMessaging, type);
  73. }
  74. TEST(CipConnectionObject, InstanceTypeIO) {
  75. CipConnectionObject connection_object = { 0 };
  76. connection_object.instance_type = 1;
  77. ConnectionObjectInstanceType type = GetConnectionObjectInstanceType(&connection_object);
  78. CHECK_EQUAL(kConnectionObjectInstanceTypeIO, type);
  79. }
  80. TEST(CipConnectionObject, InstanceTypeCipBridged) {
  81. CipConnectionObject connection_object = { 0 };
  82. connection_object.instance_type = 2;
  83. ConnectionObjectInstanceType type = GetConnectionObjectInstanceType(&connection_object);
  84. CHECK_EQUAL(kConnectionObjectInstanceTypeCipBridged, type);
  85. }
  86. TEST(CipConnectionObject, TransportClassTriggerDirectionServer) {
  87. CipConnectionObject connection_object = { 0 };
  88. connection_object.transport_class_trigger = 0x80;
  89. ConnectionObjectTransportClassTriggerDirection direction = GetConnectionObjectTransportClassTriggerDirection(&connection_object);
  90. CHECK_EQUAL(kConnectionObjectTransportClassTriggerDirectionServer, direction);
  91. }
  92. TEST(CipConnectionObject, TransportClassTriggerDirectionClient) {
  93. CipConnectionObject connection_object = { 0 };
  94. connection_object.transport_class_trigger = 0x00;
  95. ConnectionObjectTransportClassTriggerDirection direction = GetConnectionObjectTransportClassTriggerDirection(&connection_object);
  96. CHECK_EQUAL(kConnectionObjectTransportClassTriggerDirectionClient, direction);
  97. }
  98. TEST(CipConnectionObject, TransportClassTriggerProductionTriggerInvalid) {
  99. CipConnectionObject connection_object = { 0 };
  100. connection_object.transport_class_trigger = 3 << 4;
  101. ConnectionObjectTransportClassTriggerProductionTrigger production_trigger = GetConnectionObjectTransportClassTriggerProductionTrigger(&connection_object);
  102. CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerInvalid, production_trigger);
  103. }
  104. TEST(CipConnectionObject, TransportClassTriggerProductionTriggerCyclic) {
  105. CipConnectionObject connection_object = { 0 };
  106. connection_object.transport_class_trigger = 0x00;
  107. ConnectionObjectTransportClassTriggerProductionTrigger production_trigger = GetConnectionObjectTransportClassTriggerProductionTrigger(&connection_object);
  108. CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerCyclic, production_trigger);
  109. }
  110. TEST(CipConnectionObject, TransportClassTriggerProductionTriggerChangeOfState) {
  111. CipConnectionObject connection_object = { 0 };
  112. connection_object.transport_class_trigger = 1 << 4;
  113. ConnectionObjectTransportClassTriggerProductionTrigger production_trigger = GetConnectionObjectTransportClassTriggerProductionTrigger(&connection_object);
  114. CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState, production_trigger);
  115. }
  116. TEST(CipConnectionObject, TransportClassTriggerProductionTriggerApplicationObject) {
  117. CipConnectionObject connection_object = { 0 };
  118. connection_object.transport_class_trigger = 2 << 4;
  119. ConnectionObjectTransportClassTriggerProductionTrigger production_trigger = GetConnectionObjectTransportClassTriggerProductionTrigger(&connection_object);
  120. CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject, production_trigger);
  121. }