event.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
  3. */
  4. #include <gtest/gtest.h>
  5. #include <uavcan/protocol/dynamic_node_id_server/event.hpp>
  6. #include "event_tracer.hpp"
  7. TEST(dynamic_node_id_server_EventTracer, EventCodeToString)
  8. {
  9. using namespace uavcan::dynamic_node_id_server;
  10. // Simply checking some error codes
  11. ASSERT_STREQ("Error", IEventTracer::getEventName(TraceError));
  12. ASSERT_STREQ("RaftAppendEntriesCallFailure", IEventTracer::getEventName(TraceRaftAppendEntriesCallFailure));
  13. ASSERT_STREQ("RaftDiscoveryReceived", IEventTracer::getEventName(TraceRaftDiscoveryReceived));
  14. ASSERT_STREQ("DiscoveryNodeRestartDetected", IEventTracer::getEventName(TraceDiscoveryNodeRestartDetected));
  15. ASSERT_STREQ("AllocationUnexpectedStage", IEventTracer::getEventName(TraceAllocationUnexpectedStage));
  16. }
  17. TEST(dynamic_node_id_server_EventTracer, EnvironmentSelfTest)
  18. {
  19. using namespace uavcan::dynamic_node_id_server;
  20. EventTracer tracer;
  21. ASSERT_EQ(0, tracer.getNumEvents());
  22. tracer.onEvent(TraceRaftAppendEntriesCallFailure, 123);
  23. ASSERT_EQ(1, tracer.getNumEvents());
  24. tracer.onEvent(TraceRaftAppendEntriesCallFailure, -456);
  25. ASSERT_EQ(2, tracer.getNumEvents());
  26. tracer.onEvent(TraceError, -0xFFFFFFFFFFFFFFFLL);
  27. ASSERT_EQ(3, tracer.getNumEvents());
  28. ASSERT_EQ(0, tracer.countEvents(TraceAllocationActivity));
  29. ASSERT_EQ(2, tracer.countEvents(TraceRaftAppendEntriesCallFailure));
  30. ASSERT_EQ(1, tracer.countEvents(TraceError));
  31. ASSERT_EQ(-456, tracer.getLastEventArgumentOrFail(TraceRaftAppendEntriesCallFailure));
  32. ASSERT_EQ(-0xFFFFFFFFFFFFFFFLL, tracer.getLastEventArgumentOrFail(TraceError));
  33. }