import unittest
from unittest.mock import MagicMock, patch
import sys

# Mock OpenGL.GL before importing ShaderManager
gl_mock = MagicMock()
# Setup some constants
gl_mock.GL_VERTEX_SHADER = 0x8B31
gl_mock.GL_FRAGMENT_SHADER = 0x8B30
gl_mock.GL_COMPILE_STATUS = 0x8B81
gl_mock.GL_LINK_STATUS = 0x8B82
gl_mock.GL_TEXTURE0 = 0x84C0
gl_mock.GL_TEXTURE_2D = 0x0DE1
gl_mock.GL_TRIANGLE_STRIP = 0x0005

opengl_mock = MagicMock()
sys.modules['OpenGL'] = opengl_mock
sys.modules['OpenGL.GL'] = gl_mock
opengl_mock.GL = gl_mock

from src.shader_manager import ShaderManager

class TestPostProcess(unittest.TestCase):
 def setUp(self):
  gl_mock.reset_mock()
  # Mock return values for shader compilation
  gl_mock.glCreateProgram.return_value = 1
  gl_mock.glCreateShader.return_value = 2
  gl_mock.glGetShaderiv.return_value = 1 # GL_TRUE
  gl_mock.glGetProgramiv.return_value = 1 # GL_TRUE
  gl_mock.glGetUniformLocation.return_value = 10
  
 def test_setup_post_process_shader(self):
  sm = ShaderManager()
  sm.setup_post_process_shader()
  self.assertEqual(sm.pp_program, 1)
  gl_mock.glCreateProgram.assert_called()
  gl_mock.glLinkProgram.assert_called_with(1)

 def test_render_post_process(self):
  sm = ShaderManager()
  sm.pp_program = 1
  sm.render_post_process(texture_id=5, width=800, height=600, time=1.0)
  
  gl_mock.glUseProgram.assert_any_call(1)
  gl_mock.glActiveTexture.assert_called_with(gl_mock.GL_TEXTURE0)
  gl_mock.glBindTexture.assert_any_call(gl_mock.GL_TEXTURE_2D, 5)
  gl_mock.glUniform1f.assert_called()
  gl_mock.glDrawArrays.assert_called_with(gl_mock.GL_TRIANGLE_STRIP, 0, 4)
  gl_mock.glUseProgram.assert_any_call(0)

if __name__ == '__main__':
 unittest.main()
