Esempio n. 1
0
    def test_publisher_constructor(self):
        callbacks = PublisherEventCallbacks()
        liveliness_callback = Mock()
        deadline_callback = Mock()

        # No arg
        publisher = self.node.create_publisher(EmptyMsg, 'test_topic', 10)
        self.assertEqual(len(publisher.event_handlers), 0)
        self.node.destroy_publisher(publisher)

        # Arg with no callbacks
        publisher = self.node.create_publisher(
            EmptyMsg, 'test_topic', 10, event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers), 0)
        self.node.destroy_publisher(publisher)

        # Arg with one of the callbacks
        callbacks.deadline = deadline_callback
        publisher = self.node.create_publisher(
            EmptyMsg, 'test_topic', 10, event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers), 1)
        self.node.destroy_publisher(publisher)

        # Arg with both callbacks
        callbacks.liveliness = liveliness_callback
        publisher = self.node.create_publisher(
            EmptyMsg, 'test_topic', 10, event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers), 2)
        self.node.destroy_publisher(publisher)
Esempio n. 2
0
    def test_publisher_constructor(self):
        callbacks = PublisherEventCallbacks()
        liveliness_callback = Mock()
        deadline_callback = Mock()
        incompatible_qos_callback = Mock()
        expected_num_event_handlers = 0 if self.is_fastrtps else 1

        # No arg
        publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10)
        self.assertEqual(len(publisher.event_handlers),
                         expected_num_event_handlers)
        self.node.destroy_publisher(publisher)

        # Arg with no callbacks
        publisher = self.node.create_publisher(EmptyMsg,
                                               self.topic_name,
                                               10,
                                               event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers),
                         expected_num_event_handlers)
        self.node.destroy_publisher(publisher)

        # Arg with one of the callbacks
        callbacks.deadline = deadline_callback
        expected_num_event_handlers += 1
        publisher = self.node.create_publisher(EmptyMsg,
                                               self.topic_name,
                                               10,
                                               event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers),
                         expected_num_event_handlers)
        self.node.destroy_publisher(publisher)

        # Arg with two callbacks
        callbacks.liveliness = liveliness_callback
        expected_num_event_handlers += 1
        publisher = self.node.create_publisher(EmptyMsg,
                                               self.topic_name,
                                               10,
                                               event_callbacks=callbacks)
        self.assertEqual(len(publisher.event_handlers),
                         expected_num_event_handlers)
        self.node.destroy_publisher(publisher)

        # Arg with three callbacks
        callbacks.incompatible_qos = incompatible_qos_callback
        try:
            publisher = self.node.create_publisher(EmptyMsg,
                                                   self.topic_name,
                                                   10,
                                                   event_callbacks=callbacks)
            self.assertEqual(len(publisher.event_handlers), 3)
            self.node.destroy_publisher(publisher)
        except UnsupportedEventTypeError:
            self.assertTrue(self.is_fastrtps)