浏览代码

added test for CmdMultiCmds
amended CommonUtilities (functions to get geometry parameters)
adaptions in TestCmdSetGeometry (renamed geometry type and changed geometry parameters)

Mario Schuettel 10 年之前
父节点
当前提交
4647e72391

+ 15 - 9
test/unit/editor/CommonUtilities.js

@@ -16,18 +16,24 @@ function mergeParams( defaults, customParams ) {
 }
 
 
-function getParams( type, customParams ) {
+function getGeometryParams( type, customParams ) {
+
+	if ( typeof customParams != "undefined" &&
+		 typeof customParams.geometry != "undefined" &&
+		 typeof customParams.geometry.parameters != "undefined" ) {
+		var customGeometryParams = customParams.geometry.parameters;
+	}
 
 	var defaults = {};
 
 	switch ( type ) {
 
-		case "Box":
+		case "BoxGeometry":
 
 			defaults = { width: 100, height: 100, depth: 100, widthSegments: 1, heightSegments: 1, depthSegments: 1 };
 			break;
 
-		case "Sphere":
+		case "SphereGeometry":
 
 			defaults = { radius: 75, widthSegments: 32, heightSegments: 16, phiStart: 0, phiLength: 6.28, thetaStart: 0.00, thetaLength: 3.14 };
 			break;
@@ -39,17 +45,17 @@ function getParams( type, customParams ) {
 
 	}
 
-	return mergeParams( defaults, customParams );
+	return mergeParams( defaults, customGeometryParams );
 
 }
 
 function getGeometry( type, customParams ) {
 
-	var params = getParams( type, customParams );
+	var params = getGeometryParams( type, customParams );
 
 	switch ( type ) {
 
-		case "Box":
+		case "BoxGeometry":
 
 			return new THREE.BoxGeometry(
 				params['width'],
@@ -60,7 +66,7 @@ function getGeometry( type, customParams ) {
 				params['depthSegments']
 			);
 
-		case "Sphere":
+		case "SphereGeometry":
 
 			return new THREE.SphereGeometry(
 				params['radius'],
@@ -95,12 +101,12 @@ function getObject( name, type, customParams ) {
 
 function aBox( name, customParams ) {
 
-	return getObject( name, "Box", customParams );
+	return getObject( name, "BoxGeometry", customParams );
 }
 
 function aSphere( name, customParams ) {
 
-	return getObject( name, "Sphere", customParams );
+	return getObject( name, "SphereGeometry", customParams );
 
 }
 

+ 67 - 0
test/unit/editor/TestCmdMultiCmds.js

@@ -0,0 +1,67 @@
+module( "CmdMultiCmds" );
+
+test( "Test CmdMultiCmds (Undo and Redo)", function() {
+
+	var editor = new Editor();
+	var box = aBox( 'Multi Command Box' );
+	var boxGeometry1 = { geometry: { parameters: { width: 200, height: 201, depth: 202, widthSegments: 2, heightSegments: 3, depthSegments: 4 } } };
+	var boxGeometry2 = { geometry: { parameters: { width:  50, height:  51, depth:  52, widthSegments: 7, heightSegments: 8, depthSegments: 9 } } };
+	var boxGeometries = [ getGeometry( "BoxGeometry", boxGeometry1 ), getGeometry( "BoxGeometry", boxGeometry2 ) ];
+
+	var cmd = new CmdAddObject( box );
+	cmd.updatable = false;
+	editor.execute( cmd );
+
+	// setup first multi commands
+	var firstMultiCmds = [
+		new CmdSetGeometry( box, boxGeometries[0] ),
+		new CmdSetPosition( box, new THREE.Vector3( 1, 2, 3 ) ),
+		new CmdSetRotation( box, new THREE.Euler( 0.1, 0.2, 0.2 ) ),
+		new CmdSetScale( box, new THREE.Vector3( 1.1, 1.2, 1.3 ) )
+	];
+	firstMultiCmds.map( function( cmd ) {
+		cmd.updatable = false;
+	});
+
+	var firstMultiCmd = new CmdMultiCmds( firstMultiCmds );
+	firstMultiCmd.updatable = false;
+	editor.execute( firstMultiCmd );
+
+
+	// setup second multi commands
+	var secondMultiCmds = [
+		new CmdSetGeometry( box, boxGeometries[1] ),
+		new CmdSetPosition( box, new THREE.Vector3( 4, 5, 6 ) ),
+		new CmdSetRotation( box, new THREE.Euler( 0.4, 0.5, 0.6 ) ),
+		new CmdSetScale( box, new THREE.Vector3( 1.4, 1.5, 1.6 ) )
+	];
+	secondMultiCmds.map( function( cmd ) {
+		cmd.updatable = false;
+	});
+
+	var secondMultiCmd = new CmdMultiCmds( secondMultiCmds );
+	secondMultiCmd.updatable = false;
+	editor.execute( secondMultiCmd );
+
+
+	// test one modified value for each command
+	ok( box.geometry.parameters.widthSegments == 7, "OK, widthSegments has been modified accordingly after two multi executes (expected: 7, actual: " + box.geometry.parameters.widthSegments + ")" );
+	ok( box.position.y == 5, "OK, y position has been modified accordingly after two multi executes (expected: 5, actual: " + box.position.y + ")" );
+	ok( box.rotation.x == 0.4, "OK, x rotation has been modified accordingly after two multi executes (expected: 0.4, actual: " + box.rotation.x + ") " );
+	ok( box.scale.z == 1.6, "OK, z scale has been modified accordingly after two multi executes (expected: 1.6, actual: " + box.scale.z + ")" );
+
+	editor.undo();
+	ok( box.geometry.parameters.widthSegments == 2, "OK, widthSegments has been modified accordingly after undo (expected: 2, actual: " + box.geometry.parameters.widthSegments + ")" );
+	ok( box.position.y == 2, "OK, y position has been modified accordingly after undo (expected: 2, actual: " + box.position.y + ")" );
+	ok( box.rotation.x == 0.1, "OK, x rotation has been modified accordingly after undo (expected: 0.1, actual: " + box.rotation.x + ")" );
+	ok( box.scale.z == 1.3, "OK, z scale has been modified accordingly after undo (expected: 1.3, actual: " + box.scale.z + ")" );
+
+	editor.redo();
+	ok( box.geometry.parameters.widthSegments == 7, "OK, widthSegments has been modified accordingly after two multi executes (expected: 7, actual: " + box.geometry.parameters.widthSegments + ")" );
+	ok( box.position.y == 5, "OK, y position has been modified accordingly after two multi executes (expected: 5, actual: " + box.position.y + ")" );
+	ok( box.rotation.x == 0.4, "OK, x rotation has been modified accordingly after two multi executes (expected: 0.4, actual: " + box.rotation.x + ") " );
+	ok( box.scale.z == 1.6, "OK, z scale has been modified accordingly after two multi executes (expected: 1.6, actual: " + box.scale.z + ")" );
+
+	console.log( box );
+
+});

+ 29 - 32
test/unit/editor/TestCmdSetGeometry.js

@@ -1,15 +1,16 @@
 module( "CmdSetGeometry" );
 
-test( "Test CmdSetGeometry", function() {
+test( "Test CmdSetGeometry (Undo and Redo)", function() {
 
 	var editor = new Editor();
 
 	// initialize objects and geometries
 	var box = aBox( 'Guinea Pig' ); // default ( 100, 100, 100, 1, 1, 1 )
-	var boxGeometry1 = { width: 200, height: 201, depth: 202, widthSegments: 2, heightSegments: 3, depthSegments: 4 };
-	var boxGeometry2 = { width:  50, height:  51, depth:  52, widthSegments: 7, heightSegments: 8, depthSegments: 9 };
+	var boxGeometry1 = { geometry: { parameters: { width: 200, height: 201, depth: 202, widthSegments: 2, heightSegments: 3, depthSegments: 4 } } };
+	var boxGeometry2 = { geometry: { parameters: { width:  50, height:  51, depth:  52, widthSegments: 7, heightSegments: 8, depthSegments: 9 } } };
 	var geometryParams = [ boxGeometry1, boxGeometry2 ];
 
+
 	// add the object
 	var cmd = new CmdAddObject( box );
 	cmd.updatable = false;
@@ -17,45 +18,41 @@ test( "Test CmdSetGeometry", function() {
 
 	for ( var i = 0; i < geometryParams.length; i++ ) {
 
-		var cmd = new CmdSetGeometry( box, new THREE.BoxGeometry(
-			geometryParams[i]['width'],
-			geometryParams[i]['height'],
-			geometryParams[i]['depth'],
-			geometryParams[i]['widthSegments'],
-			geometryParams[i]['heightSegments'],
-			geometryParams[i]['depthSegments']
-		) );
+		var cmd = new CmdSetGeometry( box, getGeometry( "BoxGeometry", geometryParams[ i ] ) );
 		cmd.updatable = false;
 		editor.execute( cmd );
 
-		var params = box.geometry.parameters;
+		var actualParams = box.geometry.parameters;
+		var expectedParams = geometryParams[ i ].geometry.parameters;
 
-		ok( params.width == geometryParams[i]['width'], "OK, box width matches the corresponding value from boxGeometry"  + ( i + 1 ) );
-		ok( params.height == geometryParams[i]['height'], "OK, box height matches the corresponding value from boxGeometry" + ( i + 1 ) );
-		ok( params.depth == geometryParams[i]['depth'], "OK, box depth matches the corresponding value from boxGeometry"  + ( i + 1 ) );
-		ok( params.widthSegments == geometryParams[i]['widthSegments'], "OK, box widthSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
-		ok( params.heightSegments == geometryParams[i]['heightSegments'], "OK, box heightSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
-		ok( params.depthSegments == geometryParams[i]['depthSegments'], "OK, box depthSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
+		ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry"  + ( i + 1 ) );
+		ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry" + ( i + 1 ) );
+		ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry"  + ( i + 1 ) );
+		ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
+		ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
+		ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry"  + ( i + 1 ) );
 
 	}
 
 	editor.undo();
-	var params = box.geometry.parameters;
-	ok( params.width == geometryParams[0]['width'], "OK, box width matches the corresponding value from boxGeometry1 (after undo)");
-	ok( params.height == geometryParams[0]['height'], "OK, box height matches the corresponding value from boxGeometry1 (after undo)");
-	ok( params.depth == geometryParams[0]['depth'], "OK, box depth matches the corresponding value from boxGeometry1 (after undo)");
-	ok( params.widthSegments == geometryParams[0]['widthSegments'], "OK, box widthSegments matches the corresponding value from boxGeometry1 (after undo)");
-	ok( params.heightSegments == geometryParams[0]['heightSegments'], "OK, box heightSegments matches the corresponding value from boxGeometry1 (after undo)");
-	ok( params.depthSegments == geometryParams[0]['depthSegments'], "OK, box depthSegments matches the corresponding value from boxGeometry1 (after undo)");
+	var actualParams = box.geometry.parameters;
+	var expectedParams = geometryParams[ 0 ].geometry.parameters;
+	ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry1 (after undo)");
+	ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry1 (after undo)");
+	ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry1 (after undo)");
+	ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry1 (after undo)");
+	ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry1 (after undo)");
+	ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry1 (after undo)");
 
 	editor.redo();
-	var params = box.geometry.parameters;
-	ok( params.width == geometryParams[1]['width'], "OK, box width matches the corresponding value from boxGeometry2 (after redo)");
-	ok( params.height == geometryParams[1]['height'], "OK, box height matches the corresponding value from boxGeometry2 (after redo)");
-	ok( params.depth == geometryParams[1]['depth'], "OK, box depth matches the corresponding value from boxGeometry2 (after redo)");
-	ok( params.widthSegments == geometryParams[1]['widthSegments'], "OK, box widthSegments matches the corresponding value from boxGeometry2 (after redo)");
-	ok( params.heightSegments == geometryParams[1]['heightSegments'], "OK, box heightSegments matches the corresponding value from boxGeometry2 (after redo)");
-	ok( params.depthSegments == geometryParams[1]['depthSegments'], "OK, box depthSegments matches the corresponding value from boxGeometry2 (after redo)");
+	var actualParams = box.geometry.parameters;
+	var expectedParams = geometryParams[ 1 ].geometry.parameters;
+	ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry2 (after redo)");
+	ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry2 (after redo)");
+	ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry2 (after redo)");
+	ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry2 (after redo)");
+	ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry2 (after redo)");
+	ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry2 (after redo)");
 
 
 });

+ 2 - 0
test/unit/unittests_editor.html

@@ -74,6 +74,7 @@
 <script src="../../editor/js/CmdAddObject.js"></script>
 <script src="../../editor/js/CmdAddScript.js"></script>
 <script src="../../editor/js/CmdMoveObject.js"></script>
+<script src="../../editor/js/CmdMultiCmds.js"></script>
 <script src="../../editor/js/CmdRemoveObject.js"></script>
 <script src="../../editor/js/CmdRemoveScript.js"></script>
 <script src="../../editor/js/CmdSetColor.js"></script>
@@ -95,6 +96,7 @@
 <script src="editor/TestCmdAddObject.js"></script>
 <script src="editor/TestCmdAddScript.js"></script>
 <script src="editor/TestCmdMoveObject.js"></script>
+<script src="editor/TestCmdMultiCmds.js"></script>
 <script src="editor/TestCmdRemoveObject.js"></script>
 <script src="editor/TestCmdRemoveScript.js"></script>
 <script src="editor/TestCmdSetColor.js"></script>