tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

shader-lib-test.html (20452B)


      1 <html>
      2 <head>
      3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      4 <title>WebGL Shader Conformance Tests</title>
      5 <link rel="stylesheet" href="../../../../resources/js-test-style.css"/>
      6 <script src="../../../../js/js-test-pre.js"></script>
      7 <script src="../../../../js/webgl-test.js"></script>
      8 <script src="../../../../js/webgl-test-utils.js"></script>
      9 <script src="shader-utils.js"></script>
     10 <script src="shader-library.js"></script>
     11 <script src="shader-library-case.js"></script>
     12 </head>
     13 <body>
     14 <div id="description"></div>
     15 <div id="console"></div>
     16 <script>
     17 
     18        description("Testing the .test parser components.");
     19 
     20        var wtu                = WebGLTestUtils;
     21        var successfullyParsed = false;
     22        var parser             = new shaderLibrary.Parser();
     23 
     24 
     25        // this array of functions is processed sequentially.
     26        // returning false will abort
     27        var tests = [
     28 
     29 
     30                function() {
     31                        var result = shaderLibrary.isWhitespace(" ");
     32                        test_result(
     33                                "Checking isWhitespace. Passing \" \". Expecting true",
     34                                result === true, result
     35                        );
     36                        return true;
     37                },
     38                function() {
     39                        var result = shaderLibrary.isWhitespace("q");
     40                        test_result(
     41                                "Checking isWhitespace. Passing \"q\". Expecting false",
     42                                result === false, result
     43                        );
     44                        return true;
     45                },
     46                function() {
     47                        var result = shaderLibrary.isWhitespace(" \r\n\t");
     48                        test_result(
     49                                "Checking isWhitespace. Passing \" \\r\\n\\t\". Expecting true",
     50                                result === true, result
     51                        );
     52                        return true;
     53                },
     54                function() {
     55                        var result = shaderLibrary.isWhitespace(" \r\n\tq");
     56                        test_result(
     57                                "Checking isWhitespace. Passing \" \\r\\n\\tq\". Expecting false",
     58                                result === false, result
     59                        );
     60                        return true;
     61                },
     62 
     63                function() {
     64                        try {
     65                                var result = shaderLibrary.removeExtraIndentation(
     66                                        "\t\t\taaaa\n\t    \t\tbbbb\n\t\t\tcccc\r\n\t\t\tdddd"
     67                                );
     68                        } catch (err) {
     69                                result = "aborted";
     70                        }
     71 
     72                        test_result(
     73                                "Checking removeExtraIndentation. \
     74                                Passing \"\t\t\taaaa\n\t    \t\tbbbb\n\t\t\tcccc\r\n\t\t\tdddd\". \
     75                                Expecting \"aaaa\n\tbbbb\ncccc\ndddd\"",
     76                                result === "aaaa\n\tbbbb\ncccc\ndddd",
     77                                result
     78                        );
     79                        return true;
     80                },
     81 
     82 
     83                function() {
     84                        // looking for private access to the parser object
     85                        var result = (typeof parser.priv != 'undefined');
     86                        test_result("looking for private member access", result, result);
     87                        return result;
     88                },
     89 
     90                function() {
     91                        try {
     92                                var result = parser.priv.parseIntLiteral("42");
     93                        } catch (err) {
     94                                result = "aborted";
     95                        }
     96                        test_result(
     97                                "Checking int parser. Passing \"42\". Expecting 42",
     98                                result === 42, result
     99                        );
    100                        return true;
    101                },
    102                function() {
    103                        try {
    104                                var result = parser.priv.parseIntLiteral("-5");
    105                        } catch (err) {
    106                                result = "aborted";
    107                        }
    108                        test_result(
    109                                "Checking int parser. Passing \"-5\". Expecting -5",
    110                                result === -5, result
    111                        );
    112                        return true;
    113                },
    114                function() {
    115                        try {
    116                                var result = parser.priv.parseIntLiteral("42.9");
    117                        } catch (err) {
    118                                result = "aborted";
    119                        }
    120                        test_result(
    121                                "Checking int parser. Passing \"42.9\". Expecting 42",
    122                                result === 42, result
    123                        );
    124                        return true;
    125                },
    126                function() {
    127                        try {
    128                                var result = parser.priv.parseFloatLiteral("42.9");
    129                        } catch (err) {
    130                                result = "aborted";
    131                        }
    132                        test_result(
    133                                "Checking float parser. Passing \"42.9\". Expecting 42.9",
    134                                result === 42.9, result
    135                        );
    136                        return true;
    137                },
    138 
    139 
    140                function() {
    141                        try {
    142                                var result = parser.priv.parseStringLiteral("\"hello world\"");
    143                        } catch (err) {
    144                                result = "aborted";
    145                        }
    146                        test_result(
    147                                "Checking string parser. Passing \"\"hello world\"\". Expecting \"hello world\"",
    148                                result == "hello world", result
    149                        );
    150                        return true;
    151                },
    152                function() {
    153                        try {
    154                                var result = parser.priv.parseStringLiteral("\"hello world\"extra");
    155                        } catch (err) {
    156                                result = "aborted";
    157                        }
    158                        test_result(
    159                                "Checking string parser. Passing \"\"hello world\"extra\". Expecting \"hello world\"",
    160                                result == "hello world", result
    161                        );
    162                        return true;
    163                },
    164                function() {
    165                        try {
    166                                var result = parser.priv.parseStringLiteral("\"\\\"\\\"\\\"\"\\\"\"");
    167                        } catch (err) {
    168                                result = "aborted";
    169                        }
    170                        test_result(
    171                                "Checking string parser. Passing \"\"\\\"\\\"\\\"\"\\\"\"\". Expecting \"\"\"\"\"",
    172                                result == "\"\"\"", result
    173                        );
    174                        return true;
    175                },
    176                function() {
    177                        try {
    178                                var result = parser.priv.parseStringLiteral("\"newline test\\nnewline test\"");
    179                        } catch (err) {
    180                                result = "aborted";
    181                        }
    182                        test_result(
    183                                "Checking string parser. Passing \"\"newline test\\nnewline test\"\". Expecting \"newline test\nnewline test\"",
    184                                result == "newline test\nnewline test", result
    185                        );
    186                        return true;
    187                },
    188                function() {
    189                        try {
    190                                var result = parser.priv.parseStringLiteral("\"tab test\\ttab test\"");
    191                        } catch (err) {
    192                                result = "aborted";
    193                        }
    194                        test_result(
    195                                "Checking string parser. Passing \"\"tab test\\ttab test\"\". Expecting \"tab test\ttab test\"",
    196                                result == "tab test\ttab test", result
    197                        );
    198                        return true;
    199                },
    200 
    201                function() {
    202                        try {
    203                                var result = parser.priv.parseShaderSource(
    204                                        "\"\"\t\t\taaaa\n\t    \t\tbbbb\n\t\t\tcccc\r\n\t\t\tdddd\"\""
    205                                );
    206                        } catch (err) {
    207                                result = "aborted";
    208                        }
    209 
    210                        test_result(
    211                                "Checking parseShaderSource. \
    212                                Passing \"\"\"\t\t\taaaa\n\t    \t\tbbbb\n\t\t\tcccc\r\n\t\t\tdddd\"\"\". \
    213                                Expecting \"aaaa\n\tbbbb\ncccc\ndddd\"",
    214                                result === "aaaa\n\tbbbb\ncccc\ndddd",
    215                                result
    216                        );
    217                        return true;
    218                },
    219 
    220                function() {
    221                        try {
    222                                var result = parser.priv.advanceTokenTester("bool value = true;", 0);
    223                        } catch (err) {
    224                                result = "aborted";
    225                        }
    226                        test_result(
    227                                "Checking advanceToken. Passing \"bool value = true;\", 0",
    228                                result.idType == parser.priv.Token.TOKEN_BOOL && result.value == "bool",
    229                                result.name + ": " + result.value
    230                        );
    231                },
    232 
    233                function() {
    234                        try {
    235                                var result = parser.priv.advanceTokenTester("bool value = true;", 4);
    236                        } catch (err) {
    237                                result = "aborted";
    238                        }
    239                        test_result(
    240                                "Checking advanceToken. Passing \"bool value = true;\", 4",
    241                                result.idType == parser.priv.Token.TOKEN_IDENTIFIER && result.value == "value",
    242                                result.name + ": " + result.value
    243                        );
    244                },
    245                //*
    246                function() {
    247                        try {
    248                                var result = parser.priv.advanceTokenTester("bool value = true;", 11);
    249                        } catch (err) {
    250                                result = "aborted";
    251                        }
    252                        test_result(
    253                                "Checking advanceToken. Passing \"bool value = true;\", 11",
    254                                result.idType == parser.priv.Token.TOKEN_ASSIGN,
    255                                result.name + ": " + result.value
    256                        );
    257                },
    258                //*/
    259                function() {
    260                        try {
    261                                var result = parser.priv.advanceTokenTester("bool value = true;", 12);
    262                        } catch (err) {
    263                                result = "aborted";
    264                        }
    265                        test_result(
    266                                "Checking advanceToken. Passing \"bool value = true;\", 12",
    267                                result.idType == parser.priv.Token.TOKEN_TRUE && result.value == "true",
    268                                result.name + ": " + result.value
    269                        );
    270                },
    271                function() {
    272                        try {
    273                                var result = parser.priv.advanceTokenTester("bool value = true;", 17);
    274                        } catch (err) {
    275                                result = "aborted";
    276                        }
    277                        test_result(
    278                                "Checking advanceToken. Passing \"bool value = true;\", 17",
    279                                result.idType == parser.priv.Token.TOKEN_SEMI_COLON && result.value == ";",
    280                                result.name + ": " + result.value
    281                        );
    282                },
    283                function() {
    284                        try {
    285                                var result = parser.priv.advanceTokenTester("-7", 0);
    286                        } catch (err) {
    287                                result = "aborted";
    288                        }
    289                        test_result(
    290                                "Checking advanceToken. Passing \"-7\", 0",
    291                                result.idType == parser.priv.Token.TOKEN_MINUS && result.value == "-",
    292                                result.name + ": " + result.value
    293                        );
    294                },
    295                function() {
    296                        try {
    297                                var result = parser.priv.advanceTokenTester("-7", 1);
    298                        } catch (err) {
    299                                result = "aborted";
    300                        }
    301                        test_result(
    302                                "Checking advanceToken. Passing \"-7\", 1",
    303                                result.idType == parser.priv.Token.TOKEN_INT_LITERAL && result.value == "7",
    304                                result.name + ": " + result.value
    305                        );
    306                },
    307                function() {
    308                        try {
    309                                var result = parser.priv.advanceTokenTester("3.145", 0);
    310                        } catch (err) {
    311                                result = "aborted";
    312                        }
    313                        test_result(
    314                                "Checking advanceToken. Passing \"3.145\", 0",
    315                                result.idType == parser.priv.Token.TOKEN_FLOAT_LITERAL && result.value == "3.145",
    316                                result.name + ": " + result.value
    317                        );
    318                },
    319                function() {
    320                        try {
    321                                var result = parser.priv.advanceTokenTester("1.0e+10", 0);
    322                        } catch (err) {
    323                                result = "aborted";
    324                        }
    325                        test_result(
    326                                "Checking advanceToken. Passing \"1.0e+10\", 0",
    327                                result.idType == parser.priv.Token.TOKEN_FLOAT_LITERAL && result.value == "1.0e+10",
    328                                result.name + ": " + result.value
    329                        );
    330                },
    331                function() {
    332                        try {
    333                                var result = parser.priv.advanceTokenTester("1.0e", 0);
    334                        } catch (err) {
    335                                result = "aborted";
    336                        }
    337                        test_result(
    338                                "Checking advanceToken. Passing \"1.0e\", 0",
    339                                result === "aborted",
    340                                result
    341                        );
    342                },
    343                function() {
    344                        try {
    345                                var result = parser.priv.advanceTokenTester("\"\"shader source\"\";", 0);
    346                        } catch (err) {
    347                                result = "aborted";
    348                        }
    349                        test_result(
    350                                "Checking advanceToken. Passing \"\"\"shader source\"\";\", 0",
    351                                result.idType == parser.priv.Token.TOKEN_SHADER_SOURCE && result.value == "\"\"shader source\"\"",
    352                                result.name + ": " + result.value
    353                        );
    354                },
    355                function() {
    356                        try {
    357                                var result = parser.priv.advanceTokenTester("\"string\";", 0);
    358                        } catch (err) {
    359                                result = "aborted";
    360                        }
    361                        test_result(
    362                                "Checking advanceToken. Passing \"\"string\";\", 0",
    363                                result.idType == parser.priv.Token.TOKEN_STRING && result.value == "\"string\"",
    364                                result.name + ": " + result.value
    365                        );
    366                },
    367                function() {
    368                        try {
    369                                var result = parser.priv.advanceTokenTester("\'string\';", 0);
    370                        } catch (err) {
    371                                result = "aborted";
    372                        }
    373                        test_result(
    374                                "Checking advanceToken. Passing \"\'string\';\", 0",
    375                                result.idType == parser.priv.Token.TOKEN_STRING && result.value == "\'string\'",
    376                                result.name + ": " + result.value
    377                        );
    378                },
    379                function() {
    380                        try {
    381                                var result = parser.priv.advanceTokenTester("\'string\";", 0);
    382                        } catch (err) {
    383                                result = "aborted";
    384                        }
    385                        test_result(
    386                                "Checking advanceToken. Passing \"\'string\";\", 0",
    387                                result === "aborted",
    388                                result
    389                        );
    390                },
    391                function() {
    392                        try {
    393                                var result = parser.priv.advanceTokenTester("\'string\\", 0);
    394                        } catch (err) {
    395                                result = "aborted";
    396                        }
    397                        test_result(
    398                                "Checking advanceToken. Passing \"\'string\\\", 0",
    399                                result === "aborted",
    400                                result
    401                        );
    402                },
    403                function() {
    404                        try {
    405                                var result = parser.priv.mapDataTypeToken(parser.priv.Token.TOKEN_INT);
    406                        } catch (err) {
    407                                var result = "aborted";
    408                        }
    409                        test_result(
    410                                "Checking advanceToken. Passing parser.priv.Token.TOKEN_INT",
    411                                result === shaderUtils.DataType.TYPE_INT,
    412                                result
    413                        );
    414                },
    415 
    416                function() {
    417                        successfullyParsed = true;i
    418                        return true;
    419                },
    420 
    421        ];
    422 
    423        var current = 0;
    424 
    425        function test_result(description, result, additional) {
    426                switch (typeof(additional)) {
    427                 case "undefined":
    428                        break;
    429                 case "string":
    430                        description += ": \"" + additional + "\"";
    431                        break;
    432                 default:
    433                        description += ": " + additional;
    434                        break;
    435                }
    436                if (result) {
    437                        testPassed(description);
    438                } else {
    439                        testFailed(description);
    440                }
    441        }
    442 
    443        function do_next() {
    444                if (tests[current]() !== false && tests.length > ++current) {
    445                        setTimeout(do_next, 0);
    446                } else {
    447                        on_complete();
    448                }
    449        }
    450 
    451        function on_complete() {
    452                var testPost = document.createElement('script');
    453                testPost.src = "../../../../js/js-test-post.js";
    454                document.body.appendChild(testPost);
    455        }
    456 
    457        do_next();
    458 
    459 //	
    460 </script>
    461 </body>
    462 </html>