Home | History | Annotate | Download | only in tools
      1 #!/usr/bin/env python
      2 #
      3 # Copyright (C) 2011 Google Inc.
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 # USAGE
     18 #   $ cd GLES_trace/tools
     19 #   $ python testgenapi.py
     20 
     21 import unittest
     22 from genapi import DataType, ApiCall, getApis, parseArgs
     23 
     24 class TestApiCall(unittest.TestCase):
     25     def test_parsing(self):
     26         apientry = 'void API_ENTRY(glCopyTexSubImage2D)(GLenum target, GLint level, ' \
     27                    'GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, ' \
     28                    'GLsizei height) {'
     29         callsite = 'CALL_GL_API(glCopyTexImage2D, target, level, internalformat, x, y,' \
     30                    'width, height, border);'
     31 
     32         api = ApiCall("GL", apientry, callsite)
     33         self.assertEqual(api.func, "glCopyTexImage2D")
     34         self.assertEqual(api.callsite, 'glCopyTexImage2D(target, level, internalformat, ' \
     35                                         'x, y, width, height, border)')
     36         self.assertEqual(api.ret, 'void')
     37         self.assertEqual(api.arglist, 'GLenum target, GLint level, ' \
     38                    'GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, ' \
     39                    'GLsizei height')
     40 
     41     def test_num_functions_parsed(self):
     42         gl2_apis = getApis('../../GLES2/gl2_api.in', 'GL2')
     43         gl2ext_apis = getApis('../../GLES2/gl2ext_api.in', 'GL2Ext')
     44         gl_apis = getApis('../../GLES_CM/gl_api.in', "GL1")
     45         glext_apis = getApis('../../GLES_CM/glext_api.in', 'GL1Ext')
     46 
     47         self.assertEqual(len(gl2_apis), 142)
     48         self.assertEqual(len(gl2ext_apis), 121)
     49         self.assertEqual(len(gl_apis), 145)
     50         self.assertEqual(len(glext_apis), 140)
     51 
     52     def test_parseArgs(self):
     53         args = parseArgs("void")
     54         self.assertEqual(len(args), 0)
     55 
     56         args = parseArgs("GLchar a")
     57         self.assertEqual(args, [("a", DataType.CHAR)])
     58 
     59         args = parseArgs("GLchar *a")
     60         self.assertEqual(args, [("a", DataType.POINTER)])
     61 
     62         args = parseArgs("GLint exponent[16]")
     63         self.assertEqual(args, [("exponent", DataType.POINTER)])
     64 
     65 if __name__ == '__main__':
     66     unittest.main()
     67