socket_timer_tests.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*******************************************************************************
  2. * Copyright (c) 2016, 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 "socket_timer.h"
  11. }
  12. TEST_GROUP(SocketTimer){
  13. };
  14. TEST(SocketTimer, GetAvailableEmptySocketTimer) {
  15. SocketTimer timers[10];
  16. SocketTimerArrayInitialize(timers, 10);
  17. POINTERS_EQUAL(&timers[0], SocketTimerArrayGetEmptySocketTimer(timers, 10));
  18. }
  19. TEST(SocketTimer, NoEmptySocketTimerAvailable) {
  20. SocketTimer timers[10];
  21. memset(timers, 0, sizeof(timers));
  22. POINTERS_EQUAL(NULL, SocketTimerArrayGetEmptySocketTimer(timers, 10));
  23. }
  24. TEST(SocketTimer, SetSocket) {
  25. SocketTimer timer = { socket : -1, last_update : 0 };
  26. SocketTimerSetSocket(&timer, 1);
  27. CHECK_EQUAL(1, timer.socket);
  28. }
  29. TEST(SocketTimer, UpdateSocketTimer) {
  30. SocketTimer timer = { socket : -1, last_update : 0 };
  31. SocketTimerSetLastUpdate(&timer, 10);
  32. CHECK_EQUAL(10, SocketTimerGetLastUpdate(&timer));
  33. }
  34. TEST(SocketTimer, ClearSocketTimer) {
  35. SocketTimer timer = { socket : 5, last_update : 100 };
  36. SocketTimerClear(&timer);
  37. CHECK_EQUAL(-1, timer.socket);
  38. CHECK_EQUAL(0, timer.last_update);
  39. }