123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>Virtual World Framework</title>
- <script type="text/javascript" src="qunit.js"></script>
- <script type="text/javascript" src="../lib/async.js"></script>
- <script type="text/javascript" src="../lib/crypto.js"></script>
- <script type="text/javascript" src="../lib/md5.js"></script>
- <script type="text/javascript" src="../lib/alea.js"></script>
- <script type="text/javascript" src="../lib/mash.js"></script>
- <script type="text/javascript" src="../lib/vwf.js"></script>
- <script type="text/javascript" src="../lib/require.js"></script>
- <script type="text/javascript">
- require( {
- baseUrl: "../lib",
- paths: {
- jquery: "jquery-1.10.2.min",
- },
- }, [
- "domReady",
- "utility.js",
- // This is the common model implementation and an example model that connects the
- // simulation to a WebGL scene manager.
- "jquery",
- "vwf/configuration",
- "vwf/kernel/model",
- "vwf/model/javascript",
- "vwf/model/object",
- "vwf/model/stage/log",
- "vwf/kernel/view",
- "vwf/kernel/utility",
- "vwf/utility",
- "logger",
- ], function( ready, testUtility ) {
- // Verify that prototype-based inheritance in VWF works the same way as in JavaScript.
- ready( function() {
- vwf.initialize(
- /* models */ [ "vwf/model/javascript", "vwf/model/object" ],
- /* views */ [ ]
- );
- test( "Models", function() {
- equal( vwf.models.actual[0].module.id, "vwf/model/javascript", "JavaScript Model" );
- equal( vwf.models.actual[1].module.id, "vwf/model/object", "Object Model" );
- } );
- test( "Views", function() {
- expect(0);
- } );
- // Validate the fixture.
- test( "Property Inheritance fixture JS", function() {
- var fixture = createFixtureJS( "empty", "value", "accessor" );
- equal( fixture.top.tag, "top", "top tag" );
- ok( ! fixture.top.hasOwnProperty( "property" ) ); // "empty" type
- ok( ! fixture.top.hasOwnProperty( "property_" ) ); // "empty" type
- equal( fixture.middle.tag, "middle", "middle tag" );
- ok( fixture.middle.hasOwnProperty( "property" ) ); // "value" type
- ok( ! fixture.middle.hasOwnProperty( "property_" ) ); // "value" type
- equal( fixture.bottom.tag, "bottom", "bottom tag" );
- ok( fixture.bottom.hasOwnProperty( "property" ) ); // "accessor" type
- ok( fixture.bottom.hasOwnProperty( "property_" ) ); // "accessor" type
- } );
- // Validate the fixture.
- asyncTest( "Property Inheritance fixture VWF", function() {
- createFixtureVWF( "empty", "value", "accessor", function( fixture, cleanup ) {
- equal( vwf.execute( fixture.top, "this.tag" ), "top", "top tag" );
- ok( ! vwf.execute( fixture.top, "this.hasOwnProperty( 'property' )" ) ); // "empty" type
- // ok( ! fixture.top.hasOwnProperty( "property_" ) ); // "empty" type // TODO: vwf/model/javascript internals
-
- equal( vwf.execute( fixture.middle, "this.tag" ), "middle", "middle tag" );
- ok( vwf.execute( fixture.middle, "this.hasOwnProperty( 'property' )" ) ); // "value" type
- // ok( ! fixture.middle.hasOwnProperty( "property_" ) ); // "value" type // TODO: vwf/model/javascript internals
-
- equal( vwf.execute( fixture.bottom, "this.tag" ), "bottom", "bottom tag" );
- ok( vwf.execute( fixture.bottom, "this.hasOwnProperty( 'property' )" ) ); // "accessor" type
- // ok( fixture.bottom.hasOwnProperty( "property_" ) ); // "accessor" type // TODO: vwf/model/javascript internals
-
- cleanup();
- start();
- } );
- } );
- // With no prior values, gets return undefined, and sets apply directly to the top.
- test( "Property Inheritance JS: empty, empty, empty", function() {
- var fixture = createFixtureJS( "empty", "empty", "empty" );
- equal( fixture.top.property, undefined, "top before" );
- equal( fixture.middle.property, undefined, "middle before" );
- equal( fixture.bottom.property, undefined, "bottom before" );
- fixture.top.property = "UpDaTeD";
- equal( fixture.top.property, "UpDaTeD", "top after" );
- equal( fixture.middle.property, undefined, "middle after" );
- equal( fixture.bottom.property, undefined, "bottom after" );
- } );
- // With no prior values, gets return undefined, and sets apply directly to the top.
- asyncTest( "Property Inheritance VWF: empty, empty, empty", function() {
- createFixtureVWF( "empty", "empty", "empty", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), undefined, "top before" );
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" );
- equal( vwf.getProperty( fixture.top, "property" ), "UpDaTeD", "top after" );
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: empty, empty, value", function() {
- var fixture = createFixtureJS( "empty", "empty", "value" );
- equal( fixture.top.property, "bottom", "top before" );
- equal( fixture.middle.property, "bottom", "middle before" );
- equal( fixture.bottom.property, "bottom", "bottom before" );
- fixture.top.property = "UpDaTeD";
- equal( fixture.top.property, "UpDaTeD", "top after" );
- equal( fixture.middle.property, "bottom", "middle after" );
- equal( fixture.bottom.property, "bottom", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: empty, empty, value", function() {
- createFixtureVWF( "empty", "empty", "value", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "bottom", "top before" );
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" );
- equal( vwf.getProperty( fixture.top, "property" ), "UpDaTeD", "top after" );
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: empty, empty, accessor", function() {
- var fixture = createFixtureJS( "empty", "empty", "accessor" );
- equal( fixture.top.property, "BOTTOM", "top before" ); // via accessor on bottom
- ok( ! fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.middle.property, "BOTTOM", "middle before" );
- equal( fixture.bottom.property, "BOTTOM", "bottom before" );
- fixture.top.property = "UpDaTeD"; // through accessor on bottom
- equal( fixture.top.property, "UPDATED", "top after" ); // via accessor on bottom using value on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "updated" );
- equal( fixture.middle.property, "BOTTOM", "middle after" );
- equal( fixture.bottom.property, "BOTTOM", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: empty, empty, accessor", function() {
- createFixtureVWF( "empty", "empty", "accessor", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "BOTTOM", "top before" ); // via accessor on bottom
- // ok( ! fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" ); // through accessor on bottom
- equal( vwf.getProperty( fixture.top, "property" ), "UPDATED", "top after" );
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "updated" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: value, empty, empty", function() {
- var fixture = createFixtureJS( "value", "empty", "empty" );
- equal( fixture.top.property, "top", "top before" );
- equal( fixture.middle.property, undefined, "middle before" );
- equal( fixture.bottom.property, undefined, "bottom before" );
- fixture.top.property = "UpDaTeD";
- equal( fixture.top.property, "UpDaTeD", "top after" );
- equal( fixture.middle.property, undefined, "middle after" );
- equal( fixture.bottom.property, undefined, "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: value, empty, empty", function() {
- createFixtureVWF( "value", "empty", "empty", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "top", "top before" );
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" );
- equal( vwf.getProperty( fixture.top, "property" ), "UpDaTeD", "top after" );
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: value, empty, value", function() {
- var fixture = createFixtureJS( "value", "empty", "value" );
- equal( fixture.top.property, "top", "top before" );
- equal( fixture.middle.property, "bottom", "middle before" );
- equal( fixture.bottom.property, "bottom", "bottom before" );
- fixture.top.property = "UpDaTeD";
- equal( fixture.top.property, "UpDaTeD", "top after" );
- equal( fixture.middle.property, "bottom", "middle after" );
- equal( fixture.bottom.property, "bottom", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: value, empty, value", function() {
- createFixtureVWF( "value", "empty", "value", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "top", "top before" );
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" );
- equal( vwf.getProperty( fixture.top, "property" ), "UpDaTeD", "top after" );
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: value, empty, accessor", function() {
- var fixture = createFixtureJS( "value", "empty", "accessor" );
- equal( fixture.top.property, "top", "top before" );
- ok( ! fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.middle.property, "BOTTOM", "middle before" );
- equal( fixture.bottom.property, "BOTTOM", "bottom before" );
- fixture.top.property = "UpDaTeD"; // not using accessor on bottom
- equal( fixture.top.property, "UpDaTeD", "top after" );
- ok( ! fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.middle.property, "BOTTOM", "middle after" );
- equal( fixture.bottom.property, "BOTTOM", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: value, empty, accessor", function() {
- createFixtureVWF( "value", "empty", "accessor", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "top", "top before" );
- // ok( ! fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" ); // not using accessor on bottom
- equal( vwf.getProperty( fixture.top, "property" ), "UpDaTeD", "top after" );
- // ok( ! fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: accessor, empty, empty", function() {
- var fixture = createFixtureJS( "accessor", "empty", "empty" );
- equal( fixture.top.property, "TOP", "top before" ); // via accessor on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "top" );
- equal( fixture.middle.property, undefined, "middle before" );
- equal( fixture.bottom.property, undefined, "bottom before" );
- fixture.top.property = "UpDaTeD"; // through accessor on top
- equal( fixture.top.property, "UPDATED", "top after" ); // via accessor on top using value on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "updated" );
- equal( fixture.middle.property, undefined, "middle after" );
- equal( fixture.bottom.property, undefined, "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: accessor, empty, empty", function() {
- createFixtureVWF( "accessor", "empty", "empty", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "TOP", "top before" ); // via accessor on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "top" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" ); // through accessor on top
- equal( vwf.getProperty( fixture.top, "property" ), "UPDATED", "top after" ); // via accessor on top using value on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "updated" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), undefined, "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), undefined, "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: accessor, empty, value", function() {
- var fixture = createFixtureJS( "accessor", "empty", "value" );
- equal( fixture.top.property, "TOP", "top before" ); // via accessor on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "top" );
- equal( fixture.middle.property, "bottom", "middle before" );
- equal( fixture.bottom.property, "bottom", "bottom before" );
- fixture.top.property = "UpDaTeD"; // through accessor on top
- equal( fixture.top.property, "UPDATED", "top after" ); // via accessor on top using value on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "updated" );
- equal( fixture.middle.property, "bottom", "middle after" );
- equal( fixture.bottom.property, "bottom", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: accessor, empty, value", function() {
- createFixtureVWF( "accessor", "empty", "value", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "TOP", "top before" ); // via accessor on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "top" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" ); // through accessor on top
- equal( vwf.getProperty( fixture.top, "property" ), "UPDATED", "top after" ); // via accessor on top using value on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "updated" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "bottom", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "bottom", "bottom after" );
- cleanup();
- start();
- } );
- } );
- test( "Property Inheritance JS: accessor, empty, accessor", function() {
- var fixture = createFixtureJS( "accessor", "empty", "accessor" );
- equal( fixture.top.property, "TOP", "top before" ); // via accessor on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "top" );
- equal( fixture.middle.property, "BOTTOM", "middle before" );
- equal( fixture.bottom.property, "BOTTOM", "bottom before" );
- fixture.top.property = "UpDaTeD"; // through accessor on top
- equal( fixture.top.property, "UPDATED", "top after" ); // via accessor on top using value on top
- ok( fixture.top.hasOwnProperty( "property_" ) );
- equal( fixture.top.property_, "updated" );
- equal( fixture.middle.property, "BOTTOM", "middle after" );
- equal( fixture.bottom.property, "BOTTOM", "bottom after" );
- } );
- asyncTest( "Property Inheritance VWF: accessor, empty, accessor", function() {
- createFixtureVWF( "accessor", "empty", "accessor", function( fixture, cleanup ) {
- equal( vwf.getProperty( fixture.top, "property" ), "TOP", "top before" ); // via accessor on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "top" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle before" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom before" );
- vwf.setProperty( fixture.top, "property", "UpDaTeD" ); // through accessor on top
- equal( vwf.getProperty( fixture.top, "property" ), "UPDATED", "top after" ); // via accessor on top using value on top
- // ok( fixture.top.hasOwnProperty( "property_" ) ); // TODO: vwf/model/object internals
- // equal( fixture.top.property_, "updated" ); // TODO: vwf/model/object internals
- equal( vwf.getProperty( fixture.middle, "property" ), "BOTTOM", "middle after" );
- equal( vwf.getProperty( fixture.bottom, "property" ), "BOTTOM", "bottom after" );
- cleanup();
- start();
- } );
- } );
- // == Helper functions =====================================================================
- // Create a regular JavaScript object with three levels of inheritance using the given
- // constructors. Tag each level with a unique identifier.
- function createFixtureJS( top, middle, bottom ) {
- // Factories for constructor functions for the various cases.
- var factories = {
- // No "property" property.
- empty: function( tag ) {
- return function() {
- this.tag = tag;
- }
- },
- // "property" as a simple value type.
- value: function( tag ) {
- return function() {
- Object.defineProperty( this, "property", {
- value: tag,
- writable: true
- } );
- this.tag = tag;
- }
- },
- // "property" with getter and setter functions.
- accessor: function( tag ) {
- return function() {
- Object.defineProperty( this, "property", {
- get: function() { return this.property_.toUpperCase() },
- set: function( value ) { this.property_ = value.toLowerCase() }
- } );
- this.property_ = tag;
- this.tag = tag;
- }
- },
- };
- // Construct the three-level inheritance pattern: top : middle : bottom.
- var bc = factories[bottom]( "bottom" ); // constructor
- var bi = new bc(); // instance
- var mc = factories[middle]( "middle" ); mc.prototype = bi; // constructor
- var mi = new mc(); // instance
- var tc = factories[top]( "top" ); tc.prototype = mi; // constructor
- var ti = new tc(); // instance
- // Return the instances at all three levels.
- return { top: ti, middle: mi, bottom: bi };
- }
- // Create a VWF object with three levels of inheritance using the given configurations.
- function createFixtureVWF( top, middle, bottom, callback ) {
- // Factories for property initializers for the various cases.
- var factories = {
- // No "property" property.
- empty: function( tag ) {
- return undefined;
- },
- // "property" as a simple value type.
- value: function( tag ) {
- return {
- property: { value: tag, create: true }
- };
- },
- // "property" with getter and setter functions.
- accessor: function( tag ) {
- return {
- property: {
- get: "return this.property && this.property.toUpperCase()",
- set: "this.property = value.toLowerCase()",
- value: tag
- }
- };
- },
- };
- // Construct the three-level inheritance pattern: top : middle : bottom.
- var bottomProperties = factories[bottom]( "bottom" );
- var middleProperties = factories[middle]( "middle" );
- var topProperties = factories[top]( "top" );
- vwf.createNode( { extends: "http://vwf.example.com/node.vwf", properties: bottomProperties }, function( bottomID ) {
- vwf.execute( bottomID, "this.tag = 'bottom'" );
- vwf.createNode( { extends: bottomID, properties: middleProperties }, function( middleID ) {
- vwf.execute( middleID, "this.tag = 'middle'" );
- vwf.createNode( { extends: middleID, properties: topProperties }, function( topID ) {
- vwf.execute( topID, "this.tag = 'top'" );
- callback( { top: topID, middle: middleID, bottom: bottomID }, function() {
- vwf.deleteNode( topID );
- vwf.deleteNode( middleID );
- vwf.deleteNode( bottomID );
- } );
- } );
- } );
- } );
- }
- } );
- } );
- </script>
- <link rel="stylesheet" type="text/css" href="qunit.css" />
- </head>
- <body>
- <h1 id="qunit-header">Virtual World Framework</h1>
- <h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
- <h2 id="qunit-userAgent"></h2>
- <ol id="qunit-tests"></ol>
- <div id="qunit-fixture">test markup, will be hidden</div>
- </body>
- </html>
|