panic_broadcaster.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
  3. */
  4. #include <gtest/gtest.h>
  5. #include <uavcan/protocol/panic_broadcaster.hpp>
  6. #include "helpers.hpp"
  7. TEST(PanicBroadcaster, Basic)
  8. {
  9. InterlinkedTestNodesWithSysClock nodes;
  10. uavcan::PanicBroadcaster panicker(nodes.a);
  11. SubscriberWithCollector<uavcan::protocol::Panic> sub(nodes.b);
  12. uavcan::GlobalDataTypeRegistry::instance().reset();
  13. uavcan::DefaultDataTypeRegistrator<uavcan::protocol::Panic> _reg1;
  14. ASSERT_LE(0, sub.start());
  15. panicker.panic("I lost my towel!"); // Only the first 7 chars allowed
  16. ASSERT_STREQ("I lost ", panicker.getReason().c_str());
  17. ASSERT_TRUE(panicker.isPanicking());
  18. nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10));
  19. ASSERT_TRUE(sub.collector.msg.get());
  20. ASSERT_STREQ("I lost ", sub.collector.msg->reason_text.c_str());
  21. sub.collector.msg.reset();
  22. nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(300));
  23. ASSERT_TRUE(sub.collector.msg.get());
  24. ASSERT_STREQ("I lost ", sub.collector.msg->reason_text.c_str());
  25. sub.collector.msg.reset();
  26. nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(300));
  27. ASSERT_TRUE(sub.collector.msg.get());
  28. ASSERT_STREQ("I lost ", sub.collector.msg->reason_text.c_str());
  29. sub.collector.msg.reset();
  30. panicker.dontPanic();
  31. ASSERT_FALSE(panicker.isPanicking());
  32. nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(300));
  33. ASSERT_FALSE(sub.collector.msg.get());
  34. }