tor-browser

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

es3fApiCase.js (5113B)


      1 /*-------------------------------------------------------------------------
      2 * drawElements Quality Program OpenGL ES Utilities
      3 * ------------------------------------------------
      4 *
      5 * Copyright 2014 The Android Open Source Project
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *      http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 *
     19 */
     20 'use strict';
     21 goog.provide('functional.gles3.es3fApiCase');
     22 goog.require('framework.common.tcuTestCase');
     23 goog.require('framework.opengl.gluStrUtil');
     24 
     25 goog.scope(function() {
     26 
     27    var es3fApiCase = functional.gles3.es3fApiCase;
     28    var gluStrUtil = framework.opengl.gluStrUtil;
     29    var tcuTestCase = framework.common.tcuTestCase;
     30 
     31    // format numbers as they appear in gl.h
     32    var getHexStr = function(num) {
     33        var numstr = num.toString(16);
     34        var prefix = '0x';
     35        for (
     36            var padding = (num < 0x10000 ? 4 : 8) - numstr.length;
     37            padding-- > 0;
     38        ) prefix += '0';
     39        return prefix + numstr;
     40    };
     41 
     42    /**
     43    * Base class for all the API tests.
     44    * @constructor
     45    * @extends {tcuTestCase.DeqpTest}
     46    * @param {string} name
     47    * @param {string} desc
     48    */
     49    es3fApiCase.ApiCase = function(name, desc, gl) {
     50        gl = gl || window.gl;
     51        if (this.test === undefined) {
     52            throw new Error('Unimplemented virtual function: es3fApiCase.ApiCase.test');
     53        }
     54        tcuTestCase.DeqpTest.call(this, name, desc);
     55 
     56        this.m_gl = gl;
     57        this.m_pass = true;
     58        this.m_comment = '';
     59 
     60    };
     61 
     62    es3fApiCase.ApiCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
     63    es3fApiCase.ApiCase.prototype.constructor = es3fApiCase.ApiCase;
     64 
     65    /**
     66     * @param {boolean} condition
     67     * @param {string=} message
     68     */
     69    es3fApiCase.ApiCase.prototype.check = function(condition, message) {
     70        if (this.m_pass && !condition) {
     71            bufferedLogToConsole('Condition is false. Test failed.');
     72            if (message)
     73                this.m_comment += ' ' + message;
     74            this.m_pass = condition;
     75        }
     76        return condition;
     77    };
     78 
     79    es3fApiCase.ApiCase.prototype.iterate = function() {
     80 
     81        this.test();
     82 
     83        if (this.m_pass)
     84            testPassed(this.m_comment);
     85        else
     86            testFailedOptions(this.m_comment, true);
     87 
     88        return tcuTestCase.IterateResult.STOP;
     89    };
     90 
     91    /**
     92    * @param {Array<number>|number} expected
     93    * @return {boolean} returns true if gl.getError returns an expected error code and false otherwise.
     94    */
     95    es3fApiCase.ApiCase.prototype.expectError = function(expected) {
     96        if (expected.constructor === Number)
     97            expected = [expected];
     98 
     99        var err = this.m_gl.getError();
    100        var conformant = expected.indexOf(err) >= 0;
    101 
    102        if (!conformant) {
    103 
    104            var l = expected.length;
    105            var msg = 'Expected ';
    106 
    107            if (l > 1)
    108                msg += (l == 2 ? 'either ' : 'one of ');
    109 
    110            for (var i = 0; i < l; ++i) msg += (
    111                (gluStrUtil.getErrorName(expected[i]) || getHexStr(expected[i])) +
    112                (l - i == 2 ? ' or ' : ', ')
    113            );
    114 
    115            msg += 'but got ' + (gluStrUtil.getErrorName(err) || getHexStr(err)) + '.';
    116 
    117            this.testFailed(msg);
    118 
    119        }
    120 
    121        return conformant;
    122    };
    123 
    124    es3fApiCase.ApiCase.prototype.testFailed = function(comment) {
    125        bufferedLogToConsole(comment);
    126        if (this.m_pass) {
    127            this.m_comment = comment;
    128            this.m_pass = false;
    129        }
    130    };
    131 
    132    es3fApiCase.ApiCase.prototype.expectThrowNoError = function(f) {
    133        try {
    134            f();
    135            this.testFailed("should have thrown exception");
    136        } catch (e) {
    137            this.expectError(this.m_gl.NO_ERROR);
    138        }
    139    }
    140 
    141    /**
    142    * Base class for all the API tests.
    143    * @constructor
    144    * @extends {es3fApiCase.ApiCase}
    145    * @param {string} name
    146    * @param {string} desc
    147    * @param {function(this:es3fApiCase.ApiCaseCallback)} callback
    148    */
    149    es3fApiCase.ApiCaseCallback = function(name, desc, gl, callback) {
    150        this.test = callback;
    151        es3fApiCase.ApiCase.call(this, name, desc, gl);
    152    };
    153    es3fApiCase.ApiCaseCallback.prototype = Object.create(es3fApiCase.ApiCase.prototype);
    154    es3fApiCase.ApiCaseCallback.prototype.constructor = es3fApiCase.ApiCaseCallback;
    155 
    156 /*
    157    es3fApiCase.ApiCase.prototype.expectError // (error) or (error0, error1)
    158    es3fApiCase.ApiCase.prototype.getSupportedExtensions // (number numSupportedValues, number extension, [number] values )
    159    es3fApiCase.ApiCase.prototype.checkBooleans // (char value, char expected);
    160 //*/
    161 });