cipconnectionobjecttest.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. }