def test_get_num_audio_devices(self): os.environ["SDL_AUDIODRIVER"] = "dummy" sdl.init_subsystem(sdl.SDL_INIT_AUDIO) outnum = audio.get_num_audio_devices() self.assertGreaterEqual(outnum, 1) innum = audio.get_num_audio_devices(True) self.assertGreaterEqual(innum, 0) sdl.quit_subsystem(sdl.SDL_INIT_AUDIO)
def quit(): """Quits the underlying SDL2 video subysystem. If no other subsystems are active, this will also call pygame2.sdl.quit(). """ sdl.quit_subsystem(sdl.SDL_INIT_VIDEO) if sdl.was_init(0) != 0: sdl.quit()
def test_init_haptic(self): sdl.init(sdl.SDL_INIT_HAPTIC) ret = sdl.was_init(sdl.SDL_INIT_HAPTIC) if sys.platform.startswith("freebsd"): # not supported yet self.assertNotEqual(ret, sdl.SDL_INIT_HAPTIC) else: self.assertEqual(ret, sdl.SDL_INIT_HAPTIC) sdl.quit_subsystem(sdl.SDL_INIT_HAPTIC)
def test_open_audio(self): os.environ["SDL_AUDIODRIVER"] = "dummy" sdl.init_subsystem(sdl.SDL_INIT_AUDIO) reqspec = audio.SDL_AudioSpec(44100, audio.AUDIO_U16SYS, 2, 8192, self.audiocallback, None) spec = audio.open_audio(reqspec) self.assertIsInstance(spec, audio.SDL_AudioSpec) self.assertEqual(spec.format, reqspec.format) self.assertEqual(spec.freq, reqspec.freq) self.assertEqual(spec.channels, reqspec.channels) audio.close_audio() sdl.quit_subsystem(sdl.SDL_INIT_AUDIO)
def test_open_close_audio_device(self): os.environ["SDL_AUDIODRIVER"] = "dummy" sdl.init_subsystem(sdl.SDL_INIT_AUDIO) reqspec = audio.SDL_AudioSpec(44100, audio.AUDIO_U16SYS, 2, 8192, self.audiocallback, None) outnum = audio.get_num_audio_devices() for x in range(outnum): name = audio.get_audio_device_name(x) self.assertIsNotNone(name) deviceid, spec = audio.open_audio_device(name, False, reqspec, 0) self.assertGreaterEqual(deviceid, 2) self.assertIsInstance(spec, audio.SDL_AudioSpec) self.assertEqual(spec.format, reqspec.format) self.assertEqual(spec.freq, reqspec.freq) self.assertEqual(spec.channels, reqspec.channels) audio.close_audio_device(deviceid) sdl.quit_subsystem(sdl.SDL_INIT_AUDIO)
def test_get_audio_device_name(self): os.environ["SDL_AUDIODRIVER"] = "dummy" sdl.init_subsystem(sdl.SDL_INIT_AUDIO) outnum = audio.get_num_audio_devices() for x in range(outnum): name = audio.get_audio_device_name(x) self.assertIsNotNone(name) innum = audio.get_num_audio_devices(True) for x in range(innum): name = audio.get_audio_device_name(x, True) self.assertIsNotNone(name) self.assertRaises(sdl.SDLError, audio.get_audio_device_name, -1) self.assertRaises(sdl.SDLError, audio.get_audio_device_name, -1, True) sdl.quit_subsystem(sdl.SDL_INIT_AUDIO) self.assertRaises(sdl.SDLError, audio.get_audio_device_name, 0) self.assertRaises(sdl.SDLError, audio.get_audio_device_name, 0, True)
def test_get_current_audio_driver(self): success = 0 for index in range(audio.get_num_audio_drivers()): drivername = audio.get_audio_driver(index) try: os.environ["SDL_AUDIODRIVER"] = drivername # Certain drivers fail without bringing up the correct # return value, such as the esd, if it is not running. sdl.init_subsystem(sdl.SDL_INIT_AUDIO) driver = audio.get_current_audio_driver() # Do not handle wrong return values. if driver is not None: self.assertEqual(drivername, driver) success += 1 except sdl.SDLError: pass else: sdl.quit_subsystem(sdl.SDL_INIT_AUDIO) self.assertGreaterEqual(success, 1, "Could not initialize any sound driver")
def tearDown(self): sdl.quit_subsystem(sdl.SDL_INIT_TIMER) sdl.quit()
def tearDown(self): sdl.quit_subsystem(sdl.SDL_INIT_JOYSTICK) sdl.quit()
def test_init_joystick(self): sdl.init(sdl.SDL_INIT_JOYSTICK) ret = sdl.was_init(sdl.SDL_INIT_JOYSTICK) self.assertEqual(ret, sdl.SDL_INIT_JOYSTICK) sdl.quit_subsystem(sdl.SDL_INIT_JOYSTICK)
def test_init_video(self): sdl.init(sdl.SDL_INIT_VIDEO) ret = sdl.was_init(sdl.SDL_INIT_VIDEO) self.assertEqual(ret, sdl.SDL_INIT_VIDEO) sdl.quit_subsystem(sdl.SDL_INIT_VIDEO)
def test_init_audio(self): sdl.init(sdl.SDL_INIT_AUDIO) ret = sdl.was_init(sdl.SDL_INIT_AUDIO) self.assertEqual(ret, sdl.SDL_INIT_AUDIO) sdl.quit_subsystem(sdl.SDL_INIT_AUDIO)
def test_init_timer(self): sdl.init(sdl.SDL_INIT_TIMER) ret = sdl.was_init(sdl.SDL_INIT_TIMER) self.assertEqual(ret, sdl.SDL_INIT_TIMER) sdl.quit_subsystem(sdl.SDL_INIT_TIMER)
def tearDown(self): sdl.quit_subsystem(sdl.SDL_INIT_EVERYTHING) sdl.quit()
def tearDown(self): sdl.quit_subsystem(sdl.SDL_INIT_VIDEO) sdl.quit()