comparison tests/swig_tests/resource_tests.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children d2f1e81fbe2c
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 #!/usr/bin/env python
2 import sys
3 from swig_test_utils import *
4 from serializers import *
5 from serializers.xmlanimation import XMLAnimationLoader
6
7 class TestPool(unittest.TestCase):
8
9 def setUp(self):
10 self.engine = getEngine()
11
12 def tearDown(self):
13 del self.engine
14
15 def testImagePool(self):
16 pool = self.engine.getImagePool()
17 self.assert_(pool)
18 self.assert_(pool.getResourceCount(fife.RES_LOADED) == 0)
19 id = pool.addResourceFromFile('tests/data/beach_e1.png')
20 self.assertEqual(pool.getResourceCount(fife.RES_LOADED), 0)
21 self.assertEqual(pool.getResourceCount(fife.RES_NON_LOADED), 1)
22 img = pool.getImage(id)
23 self.assertEqual(pool.getResourceCount(fife.RES_LOADED), 1)
24 self.assertEqual(pool.getResourceCount(fife.RES_NON_LOADED), 0)
25
26 def testImagePoolFail(self):
27 pool = self.engine.getImagePool()
28 id = pool.addResourceFromFile('bogus_image.png')
29 self.assertRaises(RuntimeError,pool.getImage,id)
30
31 def testAnimationPool(self):
32 pool = self.engine.getAnimationPool()
33 animationloader = XMLAnimationLoader(self.engine.getImagePool(), self.engine.getVFS())
34 pool.addResourceLoader(animationloader)
35
36 self.assert_(pool)
37 self.assert_(pool.getResourceCount(fife.RES_LOADED) == 0)
38 id = pool.addResourceFromFile('tests/data/wolf_walk/wolf_walk_sw.xml')
39 self.assertEqual(pool.getResourceCount(fife.RES_LOADED), 0)
40 self.assertEqual(pool.getResourceCount(fife.RES_NON_LOADED), 1)
41 animation = pool.getAnimation(id)
42 self.assertEqual(pool.getResourceCount(fife.RES_LOADED), 1)
43 self.assertEqual(pool.getResourceCount(fife.RES_NON_LOADED), 0)
44
45 def testAnimationPoolFail(self):
46 pool = self.engine.getAnimationPool()
47 animationloader = XMLAnimationLoader(self.engine.getImagePool(), self.engine.getVFS())
48 pool.addResourceLoader(animationloader)
49
50 id = pool.addResourceFromFile('bogus_animation.xml')
51 #self.assertRaises(RuntimeError, pool.getAnimation, id) #<- this test still passes, but crashes python on exit
52
53 TEST_CLASSES = [TestPool]
54
55 if __name__ == '__main__':
56 unittest.main()