@defer.inlineCallbacks
    def test_long_content_delivery_UDH_SmppsConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        yield self.prepareRoutingsAndStartConnector()

        # Bind
        yield self.smppc_factory.connectAndBind()

        # Install mocks
        self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

        # Build a UDH
        baseUdh = []
        baseUdh.append(struct.pack('!B', 5)) # Length of User Data Header
        baseUdh.append(struct.pack('!B', 0)) # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
        baseUdh.append(struct.pack('!B', 3)) # Length of the header, excluding the first two fields; equal to 03
        baseUdh.append(struct.pack('!B', int(id_generator(size = 2, chars=string.digits)))) # msg_ref_num
        baseUdh.append(struct.pack('!B', 3)) # total_segments

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr = '1234',
            destination_addr = '4567',
            short_message = '',
            esm_class = EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT, [EsmClassGsmFeatures.UDHI_INDICATOR_SET]),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        udh_part1 = copy.deepcopy(baseUdh)
        pdu_part2 = copy.deepcopy(basePdu)
        udh_part2 = copy.deepcopy(baseUdh)
        pdu_part3 = copy.deepcopy(basePdu)
        udh_part3 = copy.deepcopy(baseUdh)
        udh_part1.append(struct.pack('!B', 1)) # segment_seqnum
        pdu_part1.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part1.params['short_message'] = ''.join(udh_part1)+'__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part2.append(struct.pack('!B', 2)) # segment_seqnum
        pdu_part2.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part2.params['short_message'] = ''.join(udh_part2)+'__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part3.append(struct.pack('!B', 3)) # segment_seqnum
        pdu_part3.params['more_messages_to_send'] = MoreMessagesToSend.NO_MORE_MESSAGES
        pdu_part3.params['short_message'] = ''.join(udh_part3)+'__3rd_part_end.'
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 3)
        # First received pdu
        received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[0][0][0]
        self.assertEqual(received_pdu_1.seqNum, 1)
        self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_1.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_1.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_1.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_1.params['short_message'][6:], pdu_part1.params['short_message'][6:])
        # Second received pdu
        received_pdu_2 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[1][0][0]
        self.assertEqual(received_pdu_2.seqNum, 2)
        self.assertEqual(received_pdu_2.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_2.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_2.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_2.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_2.params['short_message'][6:], pdu_part2.params['short_message'][6:])
        # Third received pdu
        received_pdu_3 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[2][0][0]
        self.assertEqual(received_pdu_3.seqNum, 3)
        self.assertEqual(received_pdu_3.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_3.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_3.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_3.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_3.params['short_message'][6:], pdu_part3.params['short_message'][6:])

        # Unbind and disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        yield self.stopSmppClientConnectors()
dataset/ETHPy150Open jookies/jasmin/jasmin/routing/test/test_routing_deliver_sm.py/DeliverSmSmppThrowingTestCases.test_long_content_delivery_UDH_SmppsConnector/original