123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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();
- }
- });
|