Пример #1
0
    def test_SDL_LogGetSetOutputFunction(self):
        logentries = []

        def __log(userdata, category, priority, message):
            if userdata:
                userdata = ctypes.cast(userdata, ctypes.c_char_p).value
            logentries.append((userdata, category, priority, message,))

        # setUp should have set our output function already.
        origfunc = log.SDL_LogOutputFunction()
        origdata = ctypes.c_void_p(0)
        log.SDL_LogGetOutputFunction(ctypes.byref(origfunc),
                                     ctypes.byref(origdata))
        self.assertFalse(origdata)
        logcount = len(self.logdata)
        origfunc(None, 0, 0, b"test_log_get_set_output_function")
        self.assertEqual(len(self.logdata), logcount + 1)
        self.assertEqual(self.logdata[logcount][3],
                         b"test_log_get_set_output_function")

        logptr = log.SDL_LogOutputFunction(__log)
        userdata = ctypes.c_char_p(b"Testobject")
        log.SDL_LogSetOutputFunction(logptr, userdata)
        ptr = log.SDL_LogOutputFunction()
        userdata = ctypes.c_void_p(0)
        log.SDL_LogGetOutputFunction(ctypes.byref(ptr), ctypes.byref(userdata))
        userdata = ctypes.cast(userdata, ctypes.c_char_p)
        self.assertEqual(userdata.value, b"Testobject")
        log.SDL_Log(b"output test")
        self.assertEqual(logentries[0],
                         (b"Testobject", log.SDL_LOG_CATEGORY_APPLICATION,
                          log.SDL_LOG_PRIORITY_INFO, b"output test"))

        log.SDL_LogSetOutputFunction(origfunc, userdata)
Пример #2
0
    def setUp(self):
        self.logdata = []

        def logfunc(userdata, category, priority, message):
            if userdata:
                userdata = ctypes.cast(userdata, ctypes.c_char_p).value
            self.logdata.append((userdata, category, priority, message,))

        # bind to the TestCase, so we do not loose the reference.
        self.funcptr = log.SDL_LogOutputFunction(logfunc)
        log.SDL_LogSetOutputFunction(self.funcptr, None)
        log.SDL_LogSetAllPriority(log.SDL_LOG_PRIORITY_VERBOSE)
Пример #3
0
 def teardown_method(self):
     log.SDL_LogSetOutputFunction(log.SDL_LogOutputFunction(), None)
     del self.funcptr
Пример #4
0
 def tearDown(self):
     log.SDL_LogSetOutputFunction(log.SDL_LogOutputFunction(), None)
     del self.funcptr