<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/test-eval.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
"use strict";
description("Test that functions returning strings really do return strings (and not e.g. null)");
debug("");

var validVertexShaderString =
  "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }";
var validFragmentShaderString =
  "precision mediump float; varying vec4 vColor; void main() { gl_FragColor = vColor; }";

function shouldReturnString(_a)
{
  var exception;
  var _av;
  try {
     _av = TestEval(_a);
  } catch (e) {
     exception = e;
  }

  if (exception)
    testFailed(_a + ' should return a string. Threw exception ' + exception);
  else if (typeof _av == "string")
    testPassed(_a + ' returns a string');
  else
    testFailed(_a + ' should return a string.  Returns: "' + _av + '"');
}

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");
if (!gl) {
  testFailed("context does not exist");
} else {
  var vs = gl.createShader(gl.VERTEX_SHADER);
  shouldReturnString("gl.getShaderSource(vs)");
  shouldReturnString("gl.getShaderInfoLog(vs)");
  gl.shaderSource(vs, validVertexShaderString);
  gl.compileShader(vs);
  shouldReturnString("gl.getShaderSource(vs)");
  shouldReturnString("gl.getShaderInfoLog(vs)");

  var fs = gl.createShader(gl.FRAGMENT_SHADER);
  shouldReturnString("gl.getShaderSource(fs)");
  shouldReturnString("gl.getShaderInfoLog(fs)");
  gl.shaderSource(fs, validFragmentShaderString);
  gl.compileShader(fs);
  shouldReturnString("gl.getShaderSource(fs)");
  shouldReturnString("gl.getShaderInfoLog(fs)");

  var prog = gl.createProgram();
  shouldReturnString("gl.getProgramInfoLog(prog)");
  gl.attachShader(prog, vs);
  gl.attachShader(prog, fs);
  gl.linkProgram(prog);
  shouldReturnString("gl.getProgramInfoLog(prog)");

  // Make sure different numbers of extensions doesn't result in
  // different test output.
  var exts = gl.getSupportedExtensions();
  var allPassed = true;
  for (var ii = 0; ii < exts.length; ++ii) {
    var s = exts[ii];
    if (typeof s != "string") {
      shouldReturnString("gl.getSupportedExtensions()[" + s + "]");
      allPassed = false;
    }
  }
  if (allPassed) {
    testPassed('getSupportedExtensions() returns an array of strings');
  }

  shouldReturnString("gl.getParameter(gl.VENDOR)");
  shouldReturnString("gl.getParameter(gl.RENDERER)");
  shouldReturnString("gl.getParameter(gl.VERSION)");
  shouldReturnString("gl.getParameter(gl.SHADING_LANGUAGE_VERSION)");
}

debug("");
var successfullyParsed = true;

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

</body>
</html>
