From: Timothy S. <pe...@us...> - 2004-08-01 16:47:44
|
Update of /cvsroot/pyode/pyode/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23500/tests Modified Files: test_xode.py Log Message: - Added support for TriMesh to the XODE parser. - Changed TriMeshData.build to use dGeomTriMeshDataBuildSimple instead of dGeomTriMeshBuildSingle1. Index: test_xode.py =================================================================== RCS file: /cvsroot/pyode/pyode/tests/test_xode.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_xode.py 16 Jul 2004 11:45:17 -0000 1.2 --- test_xode.py 1 Aug 2004 16:47:36 -0000 1.3 *************** *** 6,10 **** from xode import node, transform, parser, errors ! test_doc = '''<?xml version="1.0"?> <xode> <world name="world1"> --- 6,10 ---- from xode import node, transform, parser, errors ! test_doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode> <world name="world1"> *************** *** 152,155 **** --- 152,180 ---- </xode>''' + trimesh_doc='''<?xml version="1.0" encoding="iso-8859-1"?> + <xode> + <world> + <space> + <geom name="trimesh1"> + <trimesh> + <vertices> + <v x="0" y="1" z="1" /> + <v x="1" y="2" z="2" /> + <v x="2" y="0" z="1" /> + <v x="0" y="1" z="2" /> + <v x="2" y="2" z="1" /> + </vertices> + <triangles> + <t ia="1" ib="2" ic="3" /> + <t ia="2" ib="1" ic="4" /> + <t ia="3" ib="2" ic="1" /> + </triangles> + </trimesh> + </geom> + </space> + </world> + </xode> + ''' + def feq(n1, n2, error=0.1): """ *************** *** 490,493 **** --- 515,547 ---- self.assertEqual(t.m[r][c], 0) + class TestTriMeshParser(unittest.TestCase): + def setUp(self): + self.p = parser.Parser() + self.root = self.p.parseString(trimesh_doc) + self.trimesh1 = self.root.namedChild('trimesh1').getODEObject() + + def testInstance(self): + self.assert_(isinstance(self.trimesh1, ode.GeomTriMesh)) + + def testTriangles(self): + triangles = [(1, 2, 3), + (2, 1, 4), + (3, 2, 1)] + + vertices = [(0.0, 1.0, 1.0), + (1.0, 2.0, 2.0), + (2.0, 0.0, 1.0), + (0.0, 1.0, 2.0), + (2.0, 2.0, 1.0)] + + for i in range(len(triangles)): + tri = self.trimesh1.getTriangle(i) + + ref = [] + for v in triangles[i]: + ref.append(vertices[v-1]) + + self.assertEqual(tri, tuple(ref)) + class TestInvalid(unittest.TestCase): def setUp(self): *************** *** 496,508 **** class TestInvalidTags(TestInvalid): def testRoot(self): ! self.assertRaises(errors.InvalidError, self.p.parseString, ! '<?xml version="1.0"?>\n<test></test>') def testRootChild(self): ! self.assertRaises(errors.ChildError, self.p.parseString, ! '<?xml version="1.0"?>\n<xode><test/></xode>') def testWorldChild(self): ! doc = '''<?xml version="1.0"?> <xode><world> <test/> --- 550,564 ---- class TestInvalidTags(TestInvalid): def testRoot(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> ! <test></test>''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testRootChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> ! <xode><test/></xode>''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) def testWorldChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world> <test/> *************** *** 512,516 **** def testSpaceChild(self): ! doc = '''<?xml version="1.0"?> <xode><world><space> <test/> --- 568,572 ---- def testSpaceChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space> <test/> *************** *** 520,524 **** def testMassChild(self): ! doc = '''<?xml version="1.0"?> <xode><world><space> <body> --- 576,580 ---- def testMassChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space> <body> *************** *** 532,547 **** def testJointChild(self): ! doc = '''<?xml version="1.0"?> <xode><world><space><joint><test/></joint></space></world></xode>''' self.assertRaises(errors.ChildError, self.p.parseString, doc) def testGeomChild(self): ! doc = '''<?xml version="1.0"?> <xode><world><space><geom><test/></geom></space></world></xode>''' self.assertRaises(errors.ChildError, self.p.parseString, doc) class TestInvalidBody(TestInvalid): def testBadVector(self): ! doc = '''<?xml version="1.0"?> <xode><world> <body> --- 588,610 ---- def testJointChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space><joint><test/></joint></space></world></xode>''' self.assertRaises(errors.ChildError, self.p.parseString, doc) def testGeomChild(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space><geom><test/></geom></space></world></xode>''' self.assertRaises(errors.ChildError, self.p.parseString, doc) + def testTriMeshChild(self): + doc = '''<?xml version="1.0" encoding="iso-8859-1"?> + <xode><world><space><geom><trimesh><test/> + </trimesh></geom></space></world></xode> + ''' + self.assertRaises(errors.ChildError, self.p.parseString, doc) + class TestInvalidBody(TestInvalid): def testBadVector(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world> <body> *************** *** 553,557 **** def testBodyEnable(self): ! doc = '''<?xml version="1.0"?> <xode><world> <body enabled="unsure"> --- 616,620 ---- def testBodyEnable(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world> <body enabled="unsure"> *************** *** 562,566 **** def testFiniteRotationMode(self): ! doc = '''<?xml version="1.0"?> <xode><world> <body> --- 625,629 ---- def testFiniteRotationMode(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world> <body> *************** *** 572,576 **** def testFiniteRotationAxes(self): ! doc = '''<?xml version="1.0"?> <xode><world> <body> --- 635,639 ---- def testFiniteRotationAxes(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world> <body> *************** *** 583,587 **** class TestInvalidJoint(TestInvalid): def testEqualLinks(self): ! doc = '''<?xml version="1.0"?> <xode><world><space> <joint> --- 646,650 ---- class TestInvalidJoint(TestInvalid): def testEqualLinks(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space> <joint> *************** *** 594,598 **** def testNoType(self): ! doc = '''<?xml version="1.0"?> <xode><world><space> <joint/> --- 657,661 ---- def testNoType(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space> <joint/> *************** *** 602,606 **** def testWrongType(self): ! doc = '''<?xml version="1.0"?> <xode><world><space name="space1"> <body name="body1"/> --- 665,669 ---- def testWrongType(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space name="space1"> <body name="body1"/> *************** *** 615,619 **** def testMisplacedReference(self): ! doc = '''<?xml version="1.0"?> <xode><world><space name="space1"> <body name="body1"/> --- 678,682 ---- def testMisplacedReference(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space name="space1"> <body name="body1"/> *************** *** 631,635 **** class TestInvalidGeom(TestInvalid): def testNoType(self): ! doc = '''<?xml version="1.0"?> <xode><world><space> <geom/> --- 694,698 ---- class TestInvalidGeom(TestInvalid): def testNoType(self): ! doc = '''<?xml version="1.0" encoding="iso-8859-1"?> <xode><world><space> <geom/> |