~ubuntu-branches/ubuntu/intrepid/pyxine/intrepid-proposed

« back to all changes in this revision

Viewing changes to test/cstruct_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Joe Wreschnig
  • Date: 2003-11-11 12:13:24 UTC
  • Revision ID: james.westby@ubuntu.com-20031111121324-y3z5cd02mf87o0gn
Tags: upstream-0.1alpha2
ImportĀ upstreamĀ versionĀ 0.1alpha2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: cstruct_test.py,v 1.1.1.1 2003/02/08 00:42:19 dairiki Exp $
 
2
#
 
3
# Copyright (C) 2003  Geoffrey T. Dairiki <dairiki@dairiki.org>
 
4
#
 
5
# This file is part of Pyxine, Python bindings for xine.
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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.
 
20
 
 
21
import unittest
 
22
from pyxine import cstruct, libxine
 
23
 
 
24
class CstructTests(unittest.TestCase):
 
25
    def setUp(self):
 
26
        raw = libxine.px_make_input_event(1,2,3,4)
 
27
        self.e = cstruct.xine_event_t(raw)
 
28
 
 
29
    def test_simple(self):
 
30
        e = self.e
 
31
        self.failUnlessEqual(e.type, 1)
 
32
 
 
33
    def test_set_type(self):
 
34
        e = self.e
 
35
        e.type = 42
 
36
        self.failUnlessEqual(e.type, 42)
 
37
    
 
38
    def test_input_event(self):
 
39
        e = self.e
 
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)
 
44
 
 
45
    # FIXME: test more complicated (**) accessors.
 
46
 
 
47
_n_TestSubclasses = 0
 
48
 
 
49
class SuperTests(unittest.TestCase):
 
50
    class TestClass(object):
 
51
        __p = 2
 
52
    
 
53
        def m(self):
 
54
            return 1
 
55
 
 
56
        def _get_p(self):
 
57
            return self.__p
 
58
        def _set_p(self, val):
 
59
            self.__p = val
 
60
        p = property(_get_p, _set_p)
 
61
 
 
62
    class TestSubclass(TestClass):
 
63
 
 
64
        def __init__(self):
 
65
            self.__super = cstruct.super(SuperTests.TestSubclass, self)
 
66
            global _n_TestSubclasses
 
67
            _n_TestSubclasses = _n_TestSubclasses + 1
 
68
 
 
69
        def __del__(self):
 
70
            global _n_TestSubclasses
 
71
            _n_TestSubclasses = _n_TestSubclasses - 1
 
72
 
 
73
        def m(self):
 
74
            return "SUPER: %d" % self.__super.m()
 
75
 
 
76
        def _set_p_sub(self, val):
 
77
            self.__super.p = 2 * val
 
78
        
 
79
        p = property(lambda self: "SUPER: %s" % self.__super.p, _set_p_sub)
 
80
 
 
81
    def test_method(self):
 
82
        ts = self.TestSubclass()
 
83
        self.failUnlessEqual(ts.m(), "SUPER: 1")
 
84
 
 
85
    def test_get_prop(self):
 
86
        ts = self.TestSubclass()
 
87
        self.failUnlessEqual(ts.p, "SUPER: 2")
 
88
 
 
89
    def test_set_prop(self):
 
90
        ts = self.TestSubclass()
 
91
        ts.p = 2
 
92
        self.failUnlessEqual(ts.p, "SUPER: 4")
 
93
 
 
94
    def test_destruction(self):
 
95
        ts = self.TestSubclass()
 
96
        del ts
 
97
        self.failUnlessEqual(_n_TestSubclasses, 0)
 
98
        
 
99
if __name__ == '__main__':
 
100
    unittest.main()