Esempio n. 1
0
class ObexServerSimulator(object):
    def __init__(self, name, port, ioSvc):
        self._ioSvc = ioSvc
        self._osName = self.__class__.__name__ + '-' + name
        self._sockName = self._osName
        self._sockPort = port
        self._sockAddr = '127.0.0.1:' + str(self._sockPort)
        self._os = ObexServer(self._osName, self._sockName, self._sockPort,
                              self._ioSvc)

    def getUnixSockAddr(self):
        return self._sockName

    def getTcpSockAddr(self):
        return '127.0.0.1:' + str(self._sockPort)

    def getInjector(self, injName, sockType):
        if not hasattr(self, '_oc') or not self._oc:
            self._oc = CreateObject(objxp.ObexClient, injName, self._ioSvc,
                                    None)
        if sockType == 'unix':
            self._oc.connect(injName, self.getUnixSockAddr(), 0, 0)
        elif sockType == 'tcp':
            self._oc.connect(injName, self.getTcpSockAddr(), 0, 0)
        else:
            self.assertTrue(False)

        cs = WaitUntil(self._ioSvc, lambda: self._oc.getSession(injName))
        return objxp.DynamicCast_ObexRemoteClientSession(cs)

    def delInjector(self, injName):
        if hasattr(self, '_oc'):
            self._oc.disconnect(injName)
Esempio n. 2
0
class ObexRemoteClientTest(TestBase, ObexTestCommon):
    def setUpCommon(self):
        EnableObjStats()
        SetTraceLevel(8)
        self._iosvc = CreateObject(objxp.BasicIoService)
        self._scb = CreateObject(objxp.DefaultSubscriptionCallback)
        self._ccb = CreateObject(objxp.DefaultConnectionCallback)
        self._ocb = CreateObject(objxp.ObexCallbackReceiver, "ocb")
        self._os = CreateObject(objxp.ObexServer, "os", "os", 0, self._iosvc)
        self._oc = CreateObject(objxp.ObexClient, "oc", self._iosvc, self._ccb)
        self._sessionKey = "noncohab"
        self._oc.connect(self._sessionKey, "os", 3000, 0)
        self._clientSession = WaitUntil(
            self._iosvc, lambda: self._oc.getSession(self._sessionKey))
        self.assertTrue(self._clientSession)

    def tearDownCommon(self):
        self._oc.disconnect(self._sessionKey)
        del self._clientSession
        del self._oc
        del self._os
        del self._ocb
        del self._ccb
        del self._scb
        del self._iosvc
        logging.info("ObjStats: " + GetObjStats())
        self.assertFalse(bool(json.loads(GetObjStats())))