Răsfoiți Sursa

Simple Serialization Test

Daniel 9 ani în urmă
părinte
comite
b13b29a30e
2 a modificat fișierele cu 105 adăugiri și 0 ștergeri
  1. 104 0
      test/unit/editor/TestCmdSerialization.js
  2. 1 0
      test/unit/unittests_editor.html

+ 104 - 0
test/unit/editor/TestCmdSerialization.js

@@ -0,0 +1,104 @@
+module( "Serialization" );
+
+test( "Test Serialization (simple)", function() {
+
+	// setup
+	var editor = new Editor();
+
+	var box = aBox( 'The Box' );
+	var light = aPointlight( 'The PointLight' );
+	var camera = aPerspectiveCamera( 'The Camera' );
+
+	var addObject = function () {
+
+		// Test Add
+		var cmd = new CmdAddObject( box );
+		cmd.updatable = false;
+
+		editor.execute( cmd );
+
+	};
+
+	var addScript = function () {
+
+		// Test Add
+
+		var cmd = new CmdAddObject( box );
+		editor.execute( cmd );
+
+		var cmd = new CmdAddScript( box, { "name":"test","source":"console.log(\"hello world\");" } );
+		cmd.updatable = false;
+
+		editor.execute( cmd );
+
+	};
+
+	var moveObject = function () {
+
+		// create some objects
+		var anakinsName = 'Anakin Skywalker';
+		var lukesName   = 'Luke Skywalker';
+		var anakinSkywalker = aSphere( anakinsName );
+		var lukeSkywalker   = aBox( lukesName );
+
+		editor.execute( new CmdAddObject( anakinSkywalker ) );
+		editor.execute( new CmdAddObject( lukeSkywalker ) );
+
+		// Tell Luke, Anakin is his father
+		editor.execute( new CmdMoveObject( lukeSkywalker, anakinSkywalker ) );
+
+	};
+
+	var functions = [ addObject, addScript, moveObject ];
+
+	// Forward tests
+
+	for (var i = 0; i < functions.length ; i++ ) {
+
+		functions[i]();
+
+		// Check for correct serialization
+
+		var history = JSON.stringify( editor.history.toJSON() );
+
+		editor.history.clear();
+
+		editor.history.fromJSON( JSON.parse( history ) );
+
+		editor.history.goToState( 0 );
+		editor.history.goToState( 1000 );
+
+		var history2 = JSON.stringify( editor.history.toJSON() );
+
+		ok( history == history2 , "OK, forward serializing was successful " );
+
+		editor.clear();
+
+	}
+
+	// Backward tests
+
+	for (var i = 0; i < functions.length ; i++ ) {
+
+		functions[i]();
+
+		editor.history.goToState( 0 );
+
+		var history = JSON.stringify( editor.history.toJSON() );
+
+		editor.history.clear();
+
+		editor.history.fromJSON( JSON.parse( history ) );
+
+		editor.history.goToState( 1000 );
+		editor.history.goToState( 0 );
+
+		var history2 = JSON.stringify( editor.history.toJSON() );
+
+		ok( history == history2 , "OK, backward serializing was successful " );
+
+		editor.clear();
+
+	}
+
+});

+ 1 - 0
test/unit/unittests_editor.html

@@ -117,6 +117,7 @@
 <script src="editor/TestCmdSetUuid.js"></script>
 <script src="editor/TestCmdSetValue.js"></script>
 <script src="editor/TestNestedDoUndoRedo.js"></script>
+<script src="editor/TestCmdSerialization.js"></script>
 
 </body>
 </html>