'Drive _SendmsgMixin via sendmsg socket calls to check that
L{IFileDescriptorReceiver.fileDescriptorReceived} is called once
for each file descriptor received in the ancillary messages.
@param ancillaryPacker: A callable that will be given a list of
two file descriptors and should return a two-tuple where:
The first item is an iterable of zero or more (cmsg_level,
cmsg_type, cmsg_data) tuples in the same order as the given
list for actual sending via sendmsg; the second item is an
integer indicating the expected number of FDs to be received.'

def _sendmsgMixinFileDescriptorReceivedDriver(self, ancillaryPacker):

    from socket import socketpair
    from twisted.internet.unix import _SendmsgMixin
    from twisted.python.sendmsg import sendmsg
    def deviceInodeTuple(fd):
        fs = fstat(fd)
        return (fs.st_dev, fs.st_ino)
    @implementer(IFileDescriptorReceiver)
    class FakeProtocol(ConnectableProtocol, ):
        def __init__(self):
            self.fds = []
            self.deviceInodesReceived = []
        def fileDescriptorReceived(self, fd):
            self.fds.append(fd)
            self.deviceInodesReceived.append(deviceInodeTuple(fd))
            close(fd)
    class FakeReceiver(_SendmsgMixin, ):
        bufferSize = 1024
        def __init__(self, skt, proto):
            self.socket = skt
            self.protocol = proto
        def _dataReceived(self, data):
            pass
        def getHost(self):
            pass
        def getPeer(self):
            pass
        def _getLogPrefix(self, o):
            pass
    (sendSocket, recvSocket) = socketpair(AF_UNIX, SOCK_STREAM)
    self.addCleanup(sendSocket.close)
    self.addCleanup(recvSocket.close)
    proto = FakeProtocol()
    receiver = FakeReceiver(recvSocket, proto)
    (fileOneFD, fileOneName) = mkstemp()
    (fileTwoFD, fileTwoName) = mkstemp()
    self.addCleanup(unlink, fileOneName)
    self.addCleanup(unlink, fileTwoName)
    dataToSend = 'some    data    needs    to    be    sent'
    fdsToSend = [fileOneFD, fileTwoFD]
    (ancillary, expectedCount) = ancillaryPacker(fdsToSend)
    sendmsg(sendSocket, dataToSend, ancillary)
    receiver.doRead()
    self.assertEqual(len(proto.fds), expectedCount)
    self.assertFalse(set(fdsToSend).intersection(set(proto.fds)))
    if proto.fds:
        deviceInodesSent = [deviceInodeTuple(fd) for fd in fdsToSend]
        self.assertEqual(deviceInodesSent, proto.deviceInodesReceived)
