Example #1
0
        public void Constructor_CreatesHandle()
        {
            // Arrange
            var gl = Substitute.For<IOpenGL30>();
            gl.CreateShader((uint)ShaderType.VertexShader).Returns(1u);

            // Act
            var newShader = new VertexShader(gl, "Foo");

            // Assert
            Assert.AreEqual(1, newShader.Handle);
            Assert.AreEqual("Foo", newShader.Code);
        }
Example #2
0
        public void GetCompileResults_ReturnsString()
        {
            // Arrange

            var gl = Substitute.For<IOpenGL30>();
            gl.CreateShader(Arg.Any<uint>()).Returns(1u);

            gl.WhenForAnyArgs(g => g.GetShaderiv(0, (uint)ShaderParameters.InfoLogLength, Arg.Any<int[]>()))
                .Do(x => ((int[])x[2])[0] = 1 );

            var result = new string(' ', 1024);

            gl.WhenForAnyArgs(g => g.GetShaderInfoLog(Arg.Any<uint>(), Arg.Any<int>(), Arg.Any<int[]>(), ref result))
                .Do( x =>
                    {
                        ((int[])x[2])[0] = 1;
                        x[3] = "A";
                    });
            var shader = new VertexShader(gl, "Foo");

            // Act
            var results = shader.GetCompilationResults();

            // Assert
            Assert.AreEqual("A", results.Message);
        }
Example #3
0
        public void Compile_Succeeds_SetsShaderSource()
        {
            // Arrange
            var gl = Substitute.For<IOpenGL30>();
            gl.CreateShader(Arg.Any<uint>()).Returns(1u);

            gl.WhenForAnyArgs(g => g.GetShaderiv(Arg.Any<uint>(), Arg.Any<uint>(), Arg.Any<int[]>()))
              .Do(
                  x =>
                  {
                      if ((ShaderParameters)x[1] == ShaderParameters.CompileStatus)
                          ((int[])x[2])[0] = (int)GLboolean.True;
                  });

            var shader = new VertexShader(gl, "Foo");

            // Act
            shader.Compile();

            // Assert
            gl.Received().ShaderSource(1, 1, Arg.Is<string[]>(s => s.SequenceEqual(new [] { "Foo"} )), Arg.Is<int[]>(s => s.SequenceEqual(new [] { 3 })) );
            gl.Received().CompileShader(1);
        }
Example #4
0
        public void Compile_CompilationFails_ThrowsShaderCompilationResults_ReturnsMessage_SuccessIsFalse()
        {
            // Arrange
            var gl = Substitute.For<IOpenGL30>();
            gl.CreateShader(Arg.Any<uint>()).Returns(1u);

            gl.WhenForAnyArgs(g => g.GetShaderiv(Arg.Any<uint>(), Arg.Any<uint>(), Arg.Any<int[]>()))
              .Do(
                  x =>
                  {
                      if ((ShaderParameters)x[1] == ShaderParameters.InfoLogLength)
                          ((int[])x[2])[0] = 1;
                  });
            var log = new string(' ', 1024);
            gl.WhenForAnyArgs(g => g.GetShaderInfoLog(Arg.Any<uint>(), Arg.Any<int>(), Arg.Any<int[]>(), ref log))
                .Do(x =>
                {
                    (x[3]) = "A";
                });
            var shader = new VertexShader(gl, "Foo");

            // Act
            var exception = Assert.Catch<ShaderCompilationException>(shader.Compile);

            // Assert
            Assert.IsNotNull(exception.CompilationResults);
            Assert.AreEqual(false, exception.CompilationResults.Success);
            Assert.AreEqual("A", exception.CompilationResults.Message);
        }