socket_timer_tests.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = {
  26. socket: -1,
  27. last_update : 0
  28. };
  29. SocketTimerSetSocket(&timer, 1);
  30. CHECK_EQUAL( 1, timer.socket );
  31. }
  32. TEST(SocketTimer, UpdateSocketTimer) {
  33. SocketTimer timer = {
  34. socket: -1,
  35. last_update : 0
  36. };
  37. SocketTimerSetLastUpdate(&timer, 10);
  38. CHECK_EQUAL( 10, SocketTimerGetLastUpdate(&timer) );
  39. }
  40. TEST(SocketTimer, ClearSocketTimer) {
  41. SocketTimer timer = {
  42. socket : 5,
  43. last_update : 100
  44. };
  45. SocketTimerClear(&timer);
  46. CHECK_EQUAL(-1, timer.socket);
  47. CHECK_EQUAL(0, timer.last_update);
  48. }