character-set.html (3108B)
1 <!-- 2 Copyright (c) 2020 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>Character Set</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"></script> 15 <script src="../../../js/glsl-conformance-test.js"></script> 16 </head> 17 <body> 18 19 <div id="description"></div> 20 <div id="console"></div> 21 <canvas id="canvas" width="2" height="2"> </canvas> 22 <script> 23 "use strict"; 24 // See http://crbug.com/1108588 for original failing case. 25 // Check "OpenGL Registry The OpenGL ES Shading Language" 26 // Section 3.2 Character Sets For more info 27 description("This test checks character set validation for glsl."); 28 29 debug(""); 30 debug("Canvas.getContext"); 31 32 let wtu = WebGLTestUtils; 33 let gl = wtu.create3DContext("canvas"); 34 let consoleDiv = document.getElementById("console"); 35 if (!gl) { 36 testFailed("context does not exist"); 37 } else { 38 testPassed("context exists"); 39 40 debug(""); 41 debug("Checking shader character set validation and compilation"); 42 43 runTest(); 44 } 45 46 function testShaderSource(shaderSource, msg) { 47 if (!quietMode()) { 48 wtu.addShaderSource(consoleDiv, "test fragment shader", shaderSource); 49 } 50 51 let shader = gl.createShader(gl.FRAGMENT_SHADER); 52 if (shader == null) { 53 testFailed("*** Error: unable to create shader '" + shaderSource + "'"); 54 return; 55 } 56 57 gl.shaderSource(shader, shaderSource); 58 wtu.glErrorShouldBe(gl, gl.NO_ERROR, msg); 59 } 60 61 function MUST(ifTruthy) { 62 return ifTruthy ? 'MUST' : 'MUST NOT'; 63 } 64 65 function runTest() { 66 67 const BAD_STRINGS = [ 68 '$', 69 '"', 70 '一些注释', 71 '#line 42 "foo.glsl"', 72 ]; 73 const TESTS = [ 74 ['in identifier', s => s, false], 75 ['in comment', s => `// ${s}`, true, true], 76 ['in ifdef-out', s => `#if 0 \n${s} \n#endif`, true], 77 ['in ifdef-out #preproc', s => `#if 0 \n#${s} \n#endif`, true], 78 ['in #preproc', s => `#${s}`, false], 79 ['in comment after #define', s => `#define TEST // ${s}`, true], // Regression test for crbug.com/940865 80 ]; 81 82 const glsl_tests = []; 83 84 for (const s of BAD_STRINGS) { 85 for (const [where, template, validCompile] of TESTS) { 86 const st = template(s); 87 const src = ` 88 precision mediump float; 89 ${st} 90 void main() { 91 gl_FragColor = vec4(1, 0, 0, 1); 92 }`.trim(); 93 94 testShaderSource(src, `shaderSource allows Out-of-charset string '${s}' ${where} until compilation.`); 95 96 glsl_tests.push( 97 { 98 fShaderSource: src, 99 fShaderSuccess: validCompile, 100 linkSuccess: validCompile, 101 passMsg: `Out-of-charset string '${s}' ${where} ${MUST(validCompile)} compile.` 102 } 103 ); 104 } 105 } 106 107 GLSLConformanceTester.runTests(glsl_tests); 108 } 109 110 debug(""); 111 var successfullyParsed = true; 112 113 </script> 114 </body> 115 </html>