def test_valid(self): " Test if generated objects are valid" vert_obj = ShaderObject.vertex() frag_obj = ShaderObject.fragment() bad_obj = ShaderObject(8000, owned=True) borrowed_obj = ShaderObject(glCreateShader(GL_VERTEX_SHADER), owned=True) self.assertTrue(vert_obj.valid(), 'vertex shader is not valid') self.assertTrue(frag_obj.valid(), 'fragment shader is not valid') self.assertTrue(borrowed_obj.valid(), 'other vertex shader is not valid') self.assertFalse(bad_obj.valid(), 'bad shader is valid') self.assertTrue(vert_obj, 'vertex shader is not valid') self.assertFalse(bad_obj, 'bad shader is valid')
def test_freeing(self): " Test if the shaders are freed correctly" vert_obj = ShaderObject.vertex() # Warning, borrowed_obj do not own the underlying shader so it will not be freed automatically borrowed_obj = ShaderObject(glCreateShader(GL_VERTEX_SHADER), owned=False) borrowed_sid = borrowed_obj.sid sid = vert_obj.sid del vert_obj del borrowed_obj gc.collect() self.assertEqual(GL_FALSE, glIsShader(sid), 'shader object is still valid') self.assertEqual(GL_TRUE, glIsShader(borrowed_sid), 'shader object was deleted') #Free the shader object glDeleteShader(borrowed_sid)
def test_eq(self): vert_obj = ShaderObject.vertex() vert_obj_clone = ShaderObject(vert_obj.sid) self.assertEqual(vert_obj, vert_obj_clone, 'vert and vert clone are not equal')