<!--

/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>

<script>
"use strict";
var wtu = WebGLTestUtils;
description("Tests calling WebGL APIs with various types");

var context = wtu.create3DContext();
var program = wtu.loadStandardProgram(context);
var shader = wtu.loadStandardVertexShader(context);

assertMsg(program != null, "Program Compiled");
assertMsg(shader != null, "Shader Compiled");

var loc = context.getUniformLocation(program, "u_modelViewProjMatrix");
assertMsg(loc != null, "getUniformLocation succeeded");

var buffer = context.createBuffer();
context.bindBuffer(context.ARRAY_BUFFER, buffer);
var texture = context.createTexture();
context.bindTexture(context.TEXTURE_2D, texture);
context.useProgram(program);

var args = [
  { type: "number", value: 0 },
  { type: "number", value: 2 },
  { type: "string that is NaN", value: "foo", },
  { type: "string that is number", value: "2", },
  { type: "null", value: null },
  { type: "Empty Array", value: [] },
  { type: "Object", value: {} },
  { type: "Array of Number", value: [2] },
  { type: "Array of String", value: ["foo"] },
  { type: "Array of String that is number", value: ["0"] },
  { type: "Array of String that is number", value: ["2"] },
  { type: "TypedArray", value: new Float32Array(1) }
];

var argument;

for (var i = 0; i < args.length; ++i) {
  argument = args[i].value;
  var func1 = shouldBeUndefined;
  var func2 = shouldBeNonNull;
  if (argument == 2) {
    func2 = shouldBeNull;
  }
  var func3 = shouldBeNull;
  debug("");
  debug("testing type of " + args[i].type + " : value = " + argument);
  func1("context.bindAttribLocation(program, argument, 'foo')");
  func1("context.blendColor(argument, argument, argument, argument)");
  func1("context.bufferData(context.ARRAY_BUFFER, argument, context.STATIC_DRAW)");
  func1("context.bufferData(context.ARRAY_BUFFER, new Float32Array(10), context.STATIC_DRAW)");
  func1("context.bufferSubData(context.ARRAY_BUFFER, argument, new Float32Array(2))");
  func1("context.clear(argument)")
  func1("context.clearColor(argument, 0, 0, 0)");
  func1("context.clearColor(0, argument, 0, 0)");
  func1("context.clearColor(0, 0, argument, 0)");
  func1("context.clearColor(0, 0, 0, argument)");
  func1("context.clearDepth(argument)");
  func1("context.clearStencil(argument)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, argument, context.RGBA, 0, 0, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, argument, 0, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, argument, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, argument, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, 0, argument, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, argument, 0, 0, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, argument, 0, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, argument, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, argument, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, argument, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, argument, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, 0, argument)");
  func1("context.depthMask(argument)");
  func1("context.depthRange(argument, 1)");
  func1("context.depthRange(0, argument)");
  func1("context.drawArrays(context.POINTS, argument, 1)");
  func1("context.drawArrays(context.POINTS, 0, argument)");
  //func1("context.drawElements(...)");
  func1("context.enableVertexAttribArray(argument)");
  func1("context.disableVertexAttribArray(argument)");
  func2("context.getActiveAttrib(program, argument)");
  func2("context.getActiveUniform(program, argument)");
  func3("context.getParameter(argument)");
  func1("context.lineWidth(argument)");
  func1("context.polygonOffset(argument, 0)");
  func1("context.polygonOffset(0, argument)");
  //func1("context.readPixels(...)");
  //func1("context.renderbufferStorage(...)");
  func1("context.sampleCoverage(argument, 0)");
  func1("context.sampleCoverage(0, argument)");
  func1("context.scissor(argument, 0, 10, 10)");
  func1("context.scissor(0, argument, 10, 10)");
  func1("context.scissor(0, 0, argument, 10)");
  func1("context.scissor(0, 0, 10, argument)");
  func1("context.shaderSource(shader, argument)");
  func1("context.stencilFunc(context.NEVER, argument, 255)");
  func1("context.stencilFunc(context.NEVER, 0, argument)");
  //func1("context.stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)");
  func1("context.stencilMask(argument)");
  //func1("context.stencilMaskSeparate(context.FRONT, argument);
  //func1("context.texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView pixels)");
  //func1("context.texParameterf(GLenum target, GLenum pname, GLfloat param)");
  //func1("context.texParameteri(GLenum target, GLenum pname, GLint param)");
  //func1("context.texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,GLsizei width, GLsizei height,GLenum format, GLenum type, ArrayBufferView pixels)");
  func1("context.uniform1i(loc, argument)");
  func1("context.uniform2i(loc, argument, 0)");
  func1("context.uniform2i(loc, 0, argument)");
  func1("context.uniform3i(loc, argument, 0, 0)");
  func1("context.uniform3i(loc, 0, argument, 0)");
  func1("context.uniform3i(loc, 0, 0, argument)");
  func1("context.uniform4i(loc, argument, 0, 0, 0)");
  func1("context.uniform4i(loc, 0, argument, 0, 0)");
  func1("context.uniform4i(loc, 0, 0, argument, 0)");
  func1("context.uniform4i(loc, 0, 0, 0, argument)");
  func1("context.uniform1f(loc, argument)");
  func1("context.uniform2f(loc, argument, 0)");
  func1("context.uniform2f(loc, 0, argument)");
  func1("context.uniform3f(loc, argument, 0, 0)");
  func1("context.uniform3f(loc, 0, argument, 0)");
  func1("context.uniform3f(loc, 0, 0, argument)");
  func1("context.uniform4f(loc, argument, 0, 0, 0)");
  func1("context.uniform4f(loc, 0, argument, 0, 0)");
  func1("context.uniform4f(loc, 0, 0, argument, 0)");
  func1("context.uniform4f(loc, 0, 0, 0, argument)");
}

var successfullyParsed = true;
</script>

<script src="../../resources/js-test-post.js"></script>
</body>
</html>

