Răsfoiți Sursa

added stress tests
added negative tests

Mario Schuettel 9 ani în urmă
părinte
comite
b3064ed0ad

+ 49 - 0
test/unit/editor/TestMassUndoAndRedo.js

@@ -0,0 +1,49 @@
+module("MassUndoAndRedo");
+
+test( "MassUndoAndRedo (stress test)", function() {
+
+	var editor = new Editor();
+
+	var MAX_OBJECTS = 100;
+
+	// add objects
+	var i = 0;
+	while( i < MAX_OBJECTS ) {
+
+		var object = aSphere( 'Sphere #' + i );
+		var cmd = new CmdAddObject( object );
+		cmd.updatable = false;
+		editor.execute( cmd );
+
+		i++;
+
+	}
+
+	ok( editor.scene.children.lenght = MAX_OBJECTS,
+		"OK, " + MAX_OBJECTS + " objects have been added" );
+
+	// remove all objects
+	i = 0;
+	while( i < MAX_OBJECTS ) {
+
+		editor.undo();
+		i++;
+
+	}
+
+
+	ok( editor.scene.children.length == 0,
+		"OK, all objects have been removed by undos" );
+
+
+	i = 0;
+	while( i < MAX_OBJECTS ) {
+
+		editor.redo();
+		i++;
+
+	}
+
+	ok( editor.scene.children.lenght = MAX_OBJECTS,
+		"OK, " + MAX_OBJECTS + " objects have been added again by redos" );
+});

+ 50 - 0
test/unit/editor/TestNegativeCases.js

@@ -0,0 +1,50 @@
+module("NegativeCases");
+
+test( "Test unwanted situations ", function() {
+
+	var editor = new Editor();
+
+	// illegal
+	editor.undo();
+	ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history");
+	ok( editor.history.redos.length == 0, "OK, (illegal) undo did not affect the redo history");
+
+	// illegal
+	editor.redo();
+	ok( editor.history.undos.length == 0, "OK, (illegal) redo did not affect the undo history");
+	ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history");
+
+
+	var box = aBox();
+	var cmd = new CmdAddObject( box );
+	cmd.updatable = false;
+	editor.execute( cmd );
+
+	ok( editor.history.undos.length == 1, "OK, execute changed undo history");
+	ok( editor.history.redos.length == 0, "OK, execute did not change redo history");
+
+	// illegal
+	editor.redo();
+	ok( editor.history.undos.length == 1, "OK, (illegal) redo did not affect the undo history");
+	ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history");
+
+
+	editor.undo();
+	ok( editor.history.undos.length == 0, "OK, undo changed the undo history");
+	ok( editor.history.redos.length == 1, "OK, undo changed the redo history");
+
+	// illegal
+	editor.undo();
+	ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history");
+	ok( editor.history.redos.length == 1, "OK, (illegal) undo did not affect the redo history");
+
+	editor.redo();
+	ok( editor.history.undos.length == 1, "OK, redo changed the undo history");
+	ok( editor.history.redos.length == 0, "OK, undo changed the redo history");
+
+	// illegal
+	editor.redo();
+	ok( editor.history.undos.length == 1, "OK, (illegal) did not affect the undo history");
+	ok( editor.history.redos.length == 0, "OK, (illegal) did not affect the redo history");
+
+});

+ 2 - 0
test/unit/unittests_editor.html

@@ -118,6 +118,8 @@
 <script src="editor/TestCmdSetValue.js"></script>
 <script src="editor/TestNestedDoUndoRedo.js"></script>
 <script src="editor/TestSerialization.js"></script>
+<script src="editor/TestNegativeCases.js"></script>
+<script src="editor/TestMassUndoAndRedo.js"></script>
 
 </body>
 </html>