Skip to content

Commit

Permalink
Improved test coverage for:
Browse files Browse the repository at this point in the history
PolygonPipeline
TextureAtlas
Camera2DController
CameraColumbusViewController
CameraControllerCollection
CameraEventHandler
CameraFreeLookController
Camera
Polyline
  • Loading branch information
kristiancalhoun committed May 16, 2012
1 parent 6bafe3e commit 53bc31d
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 20 deletions.
27 changes: 14 additions & 13 deletions Specs/Core/PolygonPipelineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ defineSuite([

it("computeSubdivision", function() {
var positions = [
new Cartesian3(0.0, 1.0, 2.0),
new Cartesian3(3.0, 4.0, 5.0),
new Cartesian3(6.0, 7.0, 8.0)
new Cartesian3(0.0, 0.0, 90.0),
new Cartesian3(0.0, 90.0, 0.0),
new Cartesian3(90.0, 0.0, 0.0)
];
var indices = [0, 1, 2];
var subdivision = PolygonPipeline.computeSubdivision(positions, indices, 1);
expect(subdivision.attributes.position.values[0]).toEqual(0);
expect(subdivision.attributes.position.values[1]).toEqual(1);
expect(subdivision.attributes.position.values[2]).toEqual(2);
expect(subdivision.attributes.position.values[3]).toEqual(3);
expect(subdivision.attributes.position.values[4]).toEqual(4);
expect(subdivision.attributes.position.values[5]).toEqual(5);
expect(subdivision.attributes.position.values[6]).toEqual(6);
expect(subdivision.attributes.position.values[7]).toEqual(7);
expect(subdivision.attributes.position.values[8]).toEqual(8);
var subdivision = PolygonPipeline.computeSubdivision(positions, indices, 60.0);

expect(subdivision.attributes.position.values[0]).toEqual(0.0);
expect(subdivision.attributes.position.values[1]).toEqual(0.0);
expect(subdivision.attributes.position.values[2]).toEqual(90.0);
expect(subdivision.attributes.position.values[3]).toEqual(0.0);
expect(subdivision.attributes.position.values[4]).toEqual(90.0);
expect(subdivision.attributes.position.values[5]).toEqual(0.0);
expect(subdivision.attributes.position.values[6]).toEqual(90.0);
expect(subdivision.attributes.position.values[7]).toEqual(0.0);
expect(subdivision.attributes.position.values[8]).toEqual(0.0);

expect(subdivision.indexLists[0].values[0]).toEqual(0);
expect(subdivision.indexLists[0].values[1]).toEqual(1);
Expand Down
6 changes: 6 additions & 0 deletions Specs/Renderer/TextureAtlasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@ defineSuite([
atlas = context.createTextureAtlas([greenImage, blueImage], PixelFormat.RGBA, -1);
}).toThrow();
});

it("throws without context", function() {
expect(function() {
return new TextureAtlas();
}).toThrow();
});
});
131 changes: 131 additions & 0 deletions Specs/Scene/Camera2DControllerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
defineSuite([
'Scene/Camera2DController',
'Scene/Camera',
'Scene/OrthographicFrustum',
'Core/Cartographic2',
'Core/Cartesian3',
'Core/Ellipsoid',
'Core/Math',
'Core/Transforms'
], function(
Camera2DController,
Camera,
OrthographicFrustum,
Cartographic2,
Cartesian3,
Ellipsoid,
CesiumMath,
Transforms) {
"use strict";
/*global document,describe,it,expect,beforeEach,afterEach*/

var position;
var up;
var dir;
var right;
var camera;
var frustum;
var moverate;
var zoomrate;
var controller;
var ellipsoid;

beforeEach(function() {
ellipsoid = Ellipsoid.getWgs84();
camera = new Camera(document);

moverate = 3.0;
zoomrate = 1.0;
position = new Cartesian3();
up = Cartesian3.getUnitY();
dir = Cartesian3.getUnitZ().negate();
right = dir.cross(up);

frustum = new OrthographicFrustum();
frustum.near = 1;

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi May 21, 2012

Contributor

This file is inconsistent with numeric values. If a whole number is intended to be floating-point, append a .0 for human readers. Otherwise, leave it alone if a human reader should think of it as an integer.

frustum.far = 2;
frustum.left = -2;
frustum.right = 2;
frustum.top = 1;
frustum.bottom = -1;

camera = new Camera(document);
camera.position = position;
camera.up = up;
camera.direction = dir;
camera.right = right;
camera.frustum = frustum;

controller = new Camera2DController(document, camera, ellipsoid);
});

afterEach(function() {
try {

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi May 21, 2012

Contributor

Why the try...catch here? When do we expect it to throw?

This comment has been minimized.

Copy link
@kristiancalhoun

kristiancalhoun May 21, 2012

Author Contributor

This change was made in a couple of other places too. Destroying the controller after it has already been destroyed in the isDestroyed test throws an exception.

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi May 21, 2012

Contributor

Same comment for all camera-related tests.

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi May 21, 2012

Contributor

How about controller = controller && !controller.isDestroyed() && controller.destroy();?

controller = controller && controller.destroy();
} catch(e) {}
});

it("setReferenceFrame", function() {
var transform = Transforms.eastNorthUpToFixedFrame(ellipsoid.cartographicDegreesToCartesian(new Cartographic2(-75.0, 40.0)));
controller.setReferenceFrame(transform, ellipsoid);
expect(controller.getEllipsoid()).toBe(ellipsoid);
expect(controller._camera.transform).toBe(transform);
});

it("setEllipsoid", function() {
controller.setEllipsoid(Ellipsoid.getUnitSphere());
expect(controller.getEllipsoid().equals(Ellipsoid.getUnitSphere())).toEqual(true);
});

it("moveUp", function() {
controller.moveUp(moverate);
expect(camera.position.equalsEpsilon(new Cartesian3(0, moverate, 0), CesiumMath.EPSILON10)).toEqual(true);
});

it("moveDown", function() {
controller.moveDown(moverate);
expect(camera.position.equalsEpsilon(new Cartesian3(0, -moverate, 0), CesiumMath.EPSILON10)).toEqual(true);
});

it("moveRight", function() {
controller.moveRight(moverate);
expect(camera.position.equalsEpsilon(new Cartesian3(moverate, 0, 0), CesiumMath.EPSILON10)).toEqual(true);
});

it("moveLeft", function() {
controller.moveLeft(moverate);
expect(camera.position.equalsEpsilon(new Cartesian3(-moverate, 0, 0), CesiumMath.EPSILON10)).toEqual(true);
});

it("zoomOut", function() {
controller.zoomOut(zoomrate);
expect(frustum.right).toEqualEpsilon(3, CesiumMath.EPSILON10);
expect(frustum.left).toEqual(-3, CesiumMath.EPSILON10);
expect(frustum.top).toEqual(1.5, CesiumMath.EPSILON10);
expect(frustum.bottom).toEqual(-1.5, CesiumMath.EPSILON10);
});

it("zoomIn", function() {
controller.zoomIn(zoomrate);
expect(frustum.right).toEqualEpsilon(1, CesiumMath.EPSILON10);
expect(frustum.left).toEqual(-1, CesiumMath.EPSILON10);
expect(frustum.top).toEqual(0.5, CesiumMath.EPSILON10);
expect(frustum.bottom).toEqual(-0.5, CesiumMath.EPSILON10);
});

it("zoomIn throws with null OrthogrphicFrustum properties", function() {
var camera = new Camera(document);
var frustum = new OrthographicFrustum();

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi May 21, 2012

Contributor

Why not write less code? camera.frustum = new OrthographicFrustum();

camera.frustum = frustum;
var c2dc = new Camera2DController(document, camera, ellipsoid);
expect(function () {
c2dc.zoomIn(moverate);
}).toThrow();
});

it("isDestroyed", function() {
expect(controller.isDestroyed()).toEqual(false);
controller.destroy();
expect(controller.isDestroyed()).toEqual(true);
});
});
29 changes: 29 additions & 0 deletions Specs/Scene/CameraColumbusViewControllerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defineSuite([
'Scene/CameraColumbusViewController',
'Scene/Camera'
], function(
CameraColumbusViewController,
Camera) {
"use strict";
/*global document,describe,it,expect,beforeEach,afterEach*/

var controller;
var camera;

beforeEach(function() {
camera = new Camera(document);
controller = new CameraColumbusViewController(document, camera);
});

afterEach(function() {
try {
controller = controller && controller.destroy();
} catch(e) {}
});

it("isDestroyed", function() {
expect(controller.isDestroyed()).toEqual(false);
controller.destroy();
expect(controller.isDestroyed()).toEqual(true);
});
});
135 changes: 135 additions & 0 deletions Specs/Scene/CameraControllerCollectionSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
defineSuite([
'Scene/CameraControllerCollection',
'Scene/Camera',
'Scene/Camera2DController',
'Scene/CameraFreeLookController',
'Scene/CameraSpindleController',
'Core/Cartographic3',
'Core/Ellipsoid'
], function(
CameraControllerCollection,
Camera,
Camera2DController,
CameraFreeLookController,
CameraSpindleController,
Cartographic3,
Ellipsoid) {
"use strict";
/*global document,describe,it,expect,beforeEach,afterEach*/

var camera;
var collection;

beforeEach(function() {
camera = new Camera(document);
collection = camera.getControllers();
});

afterEach(function() {
try {
collection = collection && collection.destroy();
} catch(e) {}
});

it("add2D", function() {
expect(function() {
collection.add2D();
}).not.toThrow();
expect(collection.getLength()).toEqual(1);
});

it("addSpindle", function() {
expect(function() {
collection.addSpindle();
}).not.toThrow();
expect(collection.getLength()).toEqual(1);
});

it("addFreeLook", function() {
expect(function() {
collection.addFreeLook();
}).not.toThrow();
expect(collection.getLength()).toEqual(1);
});

it("addColumbusView", function() {
expect(function() {
collection.addColumbusView();
}).not.toThrow();
expect(collection.getLength()).toEqual(1);
});

it("addFlight", function() {
expect(function() {
collection.addFlight({
destination : Ellipsoid.getWgs84().cartographicDegreesToCartesian(new Cartographic3(-118.26, 34.19, 100000.0)), // Los Angeles
duration : 4.0
});
}).not.toThrow();
expect(collection.getLength()).toEqual(1);
});

it("get throws without index", function() {
expect(function() {
collection.get();
}).toThrow();
});

it("get", function() {
expect(collection.addSpindle()).toBe(collection.get(0));
});

it("contains", function() {
var spindle = collection.addSpindle();
expect(collection.contains(spindle)).toEqual(true);
collection.remove(spindle);
expect(collection.contains(spindle)).toEqual(false);
});

it("does not contain", function() {
expect(collection.contains(new CameraFreeLookController(document, camera))).toEqual(false);
expect(collection.contains()).toEqual(false);
});

it("update", function() {
collection.add2D();
collection.addColumbusView();
expect(function() {
collection.update();
}).not.toThrow();
expect(collection.getLength()).toEqual(2);
});

it("update removes expired controllers", function() {
var flight = collection.addFlight({
destination : Ellipsoid.getWgs84().cartographicDegreesToCartesian(new Cartographic3(-118.26, 34.19, 100000.0)), // Los Angeles
duration : 4.0
});
flight._canceled = true;
expect(collection.getLength()).toEqual(1);
collection.update();
expect(collection.getLength()).toEqual(0);
});

it("remove", function() {
expect(collection.remove(collection.addSpindle())).toEqual(true);
});

it("remove returns false without controller", function() {
expect(collection.remove()).toEqual(false);
});

it("removeAll", function() {
collection.addSpindle();
collection.addFreeLook();
expect(collection.getLength()).toEqual(2);
collection.removeAll();
expect(collection.getLength()).toEqual(0);
});

it("isDestroyed", function() {
expect(collection.isDestroyed()).toEqual(false);
collection.destroy();
expect(collection.isDestroyed()).toEqual(true);
});
});
Loading

0 comments on commit 53bc31d

Please sign in to comment.