2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2017-04-05 21:35:12 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2017, United States Government
|
2015-05-13 23:42:35 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2015-05-13 23:42:35 +00:00
|
|
|
* "License"); you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2015-05-13 23:42:35 +00:00
|
|
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
|
|
* this source code distribution or the Licensing information page available
|
|
|
|
* at runtime from the About dialog for additional information.
|
|
|
|
*****************************************************************************/
|
2014-12-02 03:45:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/GLChart"],
|
|
|
|
function (GLChart) {
|
|
|
|
|
|
|
|
describe("A WebGL chart", function () {
|
2014-12-02 19:08:21 +00:00
|
|
|
var mockCanvas,
|
|
|
|
mockGL,
|
|
|
|
glChart;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
mockCanvas = jasmine.createSpyObj("canvas", ["getContext"]);
|
2014-12-02 19:08:21 +00:00
|
|
|
mockGL = jasmine.createSpyObj(
|
|
|
|
"gl",
|
|
|
|
[
|
|
|
|
"createShader",
|
|
|
|
"compileShader",
|
|
|
|
"shaderSource",
|
|
|
|
"attachShader",
|
|
|
|
"createProgram",
|
|
|
|
"linkProgram",
|
|
|
|
"useProgram",
|
|
|
|
"enableVertexAttribArray",
|
|
|
|
"getAttribLocation",
|
|
|
|
"getUniformLocation",
|
|
|
|
"createBuffer",
|
|
|
|
"lineWidth",
|
|
|
|
"enable",
|
|
|
|
"blendFunc",
|
|
|
|
"viewport",
|
|
|
|
"clear",
|
|
|
|
"uniform2fv",
|
|
|
|
"uniform4fv",
|
|
|
|
"bufferData",
|
|
|
|
"bindBuffer",
|
|
|
|
"vertexAttribPointer",
|
|
|
|
"drawArrays"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockGL.ARRAY_BUFFER = "ARRAY_BUFFER";
|
|
|
|
mockGL.DYNAMIC_DRAW = "DYNAMIC_DRAW";
|
|
|
|
mockGL.TRIANGLE_FAN = "TRIANGLE_FAN";
|
|
|
|
mockGL.LINE_STRIP = "LINE_STRIP";
|
|
|
|
|
|
|
|
// Echo back names for uniform locations, so we can
|
|
|
|
// test which of these are set for certain operations.
|
|
|
|
mockGL.getUniformLocation.andCallFake(function (a, name) {
|
|
|
|
return name;
|
|
|
|
});
|
|
|
|
|
|
|
|
mockCanvas.getContext.andReturn(mockGL);
|
|
|
|
|
|
|
|
glChart = new GLChart(mockCanvas);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows the canvas to be cleared", function () {
|
|
|
|
glChart.clear();
|
|
|
|
expect(mockGL.clear).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2016-09-03 13:16:54 +00:00
|
|
|
it("does not construct if WebGL is unavailable", function () {
|
2014-12-02 19:08:21 +00:00
|
|
|
mockCanvas.getContext.andReturn(undefined);
|
|
|
|
expect(function () {
|
|
|
|
return new GLChart(mockCanvas);
|
|
|
|
}).toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows dimensions to be set", function () {
|
|
|
|
glChart.setDimensions([120, 120], [0, 10]);
|
|
|
|
expect(mockGL.uniform2fv)
|
|
|
|
.toHaveBeenCalledWith("uDimensions", [120, 120]);
|
|
|
|
expect(mockGL.uniform2fv)
|
|
|
|
.toHaveBeenCalledWith("uOrigin", [0, 10]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows lines to be drawn", function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
var testBuffer = [0, 1, 3, 8],
|
|
|
|
testColor = [0.25, 0.33, 0.66, 1.0],
|
2014-12-02 19:08:21 +00:00
|
|
|
testPoints = 2;
|
|
|
|
glChart.drawLine(testBuffer, testColor, testPoints);
|
|
|
|
expect(mockGL.bufferData).toHaveBeenCalledWith(
|
|
|
|
mockGL.ARRAY_BUFFER,
|
|
|
|
testBuffer,
|
|
|
|
mockGL.DYNAMIC_DRAW
|
|
|
|
);
|
|
|
|
expect(mockGL.uniform4fv)
|
|
|
|
.toHaveBeenCalledWith("uColor", testColor);
|
|
|
|
expect(mockGL.drawArrays)
|
|
|
|
.toHaveBeenCalledWith("LINE_STRIP", 0, testPoints);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows squares to be drawn", function () {
|
|
|
|
var testMin = [0, 1],
|
|
|
|
testMax = [10, 10],
|
2016-05-19 18:29:13 +00:00
|
|
|
testColor = [0.25, 0.33, 0.66, 1.0];
|
2014-12-02 19:08:21 +00:00
|
|
|
|
|
|
|
glChart.drawSquare(testMin, testMax, testColor);
|
|
|
|
|
|
|
|
expect(mockGL.uniform4fv)
|
|
|
|
.toHaveBeenCalledWith("uColor", testColor);
|
|
|
|
expect(mockGL.drawArrays)
|
|
|
|
.toHaveBeenCalledWith("TRIANGLE_FAN", 0, 4);
|
|
|
|
});
|
2015-02-10 00:07:05 +00:00
|
|
|
|
|
|
|
it("uses buffer sizes reported by WebGL", function () {
|
|
|
|
// Make sure that GLChart uses the GL buffer size, which may
|
|
|
|
// differ from what canvas requested. WTD-852
|
|
|
|
mockCanvas.width = 300;
|
|
|
|
mockCanvas.height = 150;
|
|
|
|
mockGL.drawingBufferWidth = 200;
|
|
|
|
mockGL.drawingBufferHeight = 175;
|
|
|
|
|
|
|
|
glChart.clear();
|
|
|
|
|
|
|
|
expect(mockGL.viewport).toHaveBeenCalledWith(0, 0, 200, 175);
|
|
|
|
});
|
2014-12-02 03:45:23 +00:00
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|