1
# $Id: cstruct_test.py,v 1.1.1.1 2003/02/08 00:42:19 dairiki Exp $
3
# Copyright (C) 2003 Geoffrey T. Dairiki <dairiki@dairiki.org>
5
# This file is part of Pyxine, Python bindings for xine.
7
# Pyxine is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
12
# Pyxine is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
from pyxine import cstruct, libxine
24
class CstructTests(unittest.TestCase):
26
raw = libxine.px_make_input_event(1,2,3,4)
27
self.e = cstruct.xine_event_t(raw)
29
def test_simple(self):
31
self.failUnlessEqual(e.type, 1)
33
def test_set_type(self):
36
self.failUnlessEqual(e.type, 42)
38
def test_input_event(self):
40
ie = cstruct.xine_input_data_t(e.data)
41
self.failUnlessEqual(ie.button, 2)
42
self.failUnlessEqual(ie.x, 3)
43
self.failUnlessEqual(ie.y, 4)
45
# FIXME: test more complicated (**) accessors.
49
class SuperTests(unittest.TestCase):
50
class TestClass(object):
58
def _set_p(self, val):
60
p = property(_get_p, _set_p)
62
class TestSubclass(TestClass):
65
self.__super = cstruct.super(SuperTests.TestSubclass, self)
66
global _n_TestSubclasses
67
_n_TestSubclasses = _n_TestSubclasses + 1
70
global _n_TestSubclasses
71
_n_TestSubclasses = _n_TestSubclasses - 1
74
return "SUPER: %d" % self.__super.m()
76
def _set_p_sub(self, val):
77
self.__super.p = 2 * val
79
p = property(lambda self: "SUPER: %s" % self.__super.p, _set_p_sub)
81
def test_method(self):
82
ts = self.TestSubclass()
83
self.failUnlessEqual(ts.m(), "SUPER: 1")
85
def test_get_prop(self):
86
ts = self.TestSubclass()
87
self.failUnlessEqual(ts.p, "SUPER: 2")
89
def test_set_prop(self):
90
ts = self.TestSubclass()
92
self.failUnlessEqual(ts.p, "SUPER: 4")
94
def test_destruction(self):
95
ts = self.TestSubclass()
97
self.failUnlessEqual(_n_TestSubclasses, 0)
99
if __name__ == '__main__':