diff options
author | 2008-11-14 15:39:19 +0000 | |
---|---|---|
committer | 2008-11-14 15:39:19 +0000 | |
commit | 1c5685d68f1b73270fb814fe04cbb490eb90ba5f (patch) | |
tree | 3d3ada08a934b96fc31531f1327690d7edc6f766 /includes/js/dojox/uuid | |
parent | 104d59099e048688c4dbac37d72137006e396558 (diff) | |
download | scuttle-1c5685d68f1b73270fb814fe04cbb490eb90ba5f.tar.gz scuttle-1c5685d68f1b73270fb814fe04cbb490eb90ba5f.zip |
Minor fix: Remove DOJO library (60Mo) replaced by link to Google CDN (online DOJO library)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@159 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/uuid')
-rw-r--r-- | includes/js/dojox/uuid/README | 43 | ||||
-rw-r--r-- | includes/js/dojox/uuid/Uuid.js | 200 | ||||
-rw-r--r-- | includes/js/dojox/uuid/_base.js | 245 | ||||
-rw-r--r-- | includes/js/dojox/uuid/generateRandomUuid.js | 56 | ||||
-rw-r--r-- | includes/js/dojox/uuid/generateTimeBasedUuid.js | 290 | ||||
-rw-r--r-- | includes/js/dojox/uuid/tests/runTests.html | 10 | ||||
-rw-r--r-- | includes/js/dojox/uuid/tests/uuid.js | 377 |
7 files changed, 0 insertions, 1221 deletions
diff --git a/includes/js/dojox/uuid/README b/includes/js/dojox/uuid/README deleted file mode 100644 index ea6b40e..0000000 --- a/includes/js/dojox/uuid/README +++ /dev/null @@ -1,43 +0,0 @@ -------------------------------------------------------------------------------- -DojoX UUID -------------------------------------------------------------------------------- -Version 0.9 -Release date: 06/21/2007 -------------------------------------------------------------------------------- -Project state: stable -------------------------------------------------------------------------------- -Project authors - Brian Douglas Skinner (skinner@dojotoolkit.org) -------------------------------------------------------------------------------- -Project description - -DojoX UUID is the port of the original Dojo 0.4.x UUID classes. The UUID -classes can be used to represent Universally Unique IDentifiers (UUIDs), as -described in the IETF's RFC 4122: - http://tools.ietf.org/html/rfc4122 - -The DojoX UUID classes provide support for generating both "time-based" UUIDs -and lightweight "random" UUIDs. DojoX UUID does not yet have support for -generating new "name-based" UUIDs, but the dojo.uuid.Uuid class can represent -existing name-based UUIDs, such as UUIDs read from a file or from a server. - -------------------------------------------------------------------------------- -Dependencies: - -DojoX UUID has no dependencies, outside of Dojo Core. -------------------------------------------------------------------------------- -Documentation - -See the API documentation for Dojo (http://dojotoolkit.org/api). -------------------------------------------------------------------------------- -Installation instructions - -Grab the following from the Dojo SVN Repository: -http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/uuid.js -http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/uuid/* - -Install into the following directory structure: -/dojox/uuid/ - -...which should be at the same level as your Dojo checkout. -------------------------------------------------------------------------------- diff --git a/includes/js/dojox/uuid/Uuid.js b/includes/js/dojox/uuid/Uuid.js deleted file mode 100644 index 213ecd1..0000000 --- a/includes/js/dojox/uuid/Uuid.js +++ /dev/null @@ -1,200 +0,0 @@ -if(!dojo._hasResource["dojox.uuid.Uuid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.uuid.Uuid"] = true; -dojo.provide("dojox.uuid.Uuid"); -dojo.require("dojox.uuid"); - -dojox.uuid.Uuid = function(/*String?*/ input){ - // summary: - // This is the constructor for the Uuid class. The Uuid class offers - // methods for inspecting existing UUIDs. - // input: A 36-character string that conforms to the UUID spec. - // examples: - // var uuid; - // uuid = new dojox.uuid.Uuid("3b12f1df-5232-4804-897e-917bf397618a"); - // uuid = new dojox.uuid.Uuid(); // "00000000-0000-0000-0000-000000000000" - // uuid = new dojox.uuid.Uuid(dojox.uuid.generateRandomUuid()); - // uuid = new dojox.uuid.Uuid(dojox.uuid.generateTimeBasedUuid()); - // dojox.uuid.Uuid.setGenerator(dojox.uuid.generateRandomUuid); - // uuid = new dojox.uuid.Uuid(); - // dojox.uuid.assert(!uuid.isEqual(dojox.uuid.NIL_UUID)); - this._uuidString = dojox.uuid.NIL_UUID; - if(input){ - dojox.uuid.assert(dojo.isString(input)); - this._uuidString = input.toLowerCase(); - dojox.uuid.assert(this.isValid()); - }else{ - var ourGenerator = dojox.uuid.Uuid.getGenerator(); - if(ourGenerator){ - this._uuidString = ourGenerator(); - dojox.uuid.assert(this.isValid()); - } - } -}; - -dojox.uuid.Uuid.compare = function(/*dojox.uuid.Uuid*/ uuidOne, /*dojox.uuid.Uuid*/ uuidTwo){ - // summary: - // Given two UUIDs to compare, this method returns 0, 1, or -1. - // description: - // This method is designed to be used by sorting routines, like the - // JavaScript built-in Array sort() method. This implementation is - // intended to match the sample implementation in IETF RFC 4122: - // http://www.ietf.org/rfc/rfc4122.txt - // uuidOne: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec. - // uuidTwo: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec. - - // examples: - // var uuid; - // var generator = dojox.uuid.TimeBasedGenerator; - // var a = new dojox.uuid.Uuid(generator); - // var b = new dojox.uuid.Uuid(generator); - // var c = new dojox.uuid.Uuid(generator); - // var array = new Array(a, b, c); - // array.sort(dojox.uuid.Uuid.compare); - var uuidStringOne = uuidOne.toString(); - var uuidStringTwo = uuidTwo.toString(); - if (uuidStringOne > uuidStringTwo) return 1; // integer - if (uuidStringOne < uuidStringTwo) return -1; // integer - return 0; // integer (either 0, 1, or -1) -}; - -dojox.uuid.Uuid.setGenerator = function(/*Function?*/ generator){ - // summary: - // Sets the default generator, which will be used by the - // "new dojox.uuid.Uuid()" constructor if no parameters - // are passed in. - // generator: A UUID generator function, such as dojox.uuid.generateTimeBasedUuid. - dojox.uuid.assert(!generator || dojo.isFunction(generator)); - dojox.uuid.Uuid._ourGenerator = generator; -}; - -dojox.uuid.Uuid.getGenerator = function(){ - // summary: - // Returns the default generator. See setGenerator(). - return dojox.uuid.Uuid._ourGenerator; // generator (A UUID generator, such as dojox.uuid.TimeBasedGenerator). -}; - -dojox.uuid.Uuid.prototype.toString = function(){ - // summary: - // This method returns a standard 36-character string representing - // the UUID, such as "3b12f1df-5232-4804-897e-917bf397618a". - return this._uuidString; // string -}; - -dojox.uuid.Uuid.prototype.compare = function(/*dojox.uuid.Uuid*/ otherUuid){ - // summary: - // Compares this UUID to another UUID, and returns 0, 1, or -1. - // description: - // This implementation is intended to match the sample implementation - // in IETF RFC 4122: http://www.ietf.org/rfc/rfc4122.txt - // otherUuid: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec. - return dojox.uuid.Uuid.compare(this, otherUuid); // integer (either 0, 1, or -1) -}; - -dojox.uuid.Uuid.prototype.isEqual = function(/*dojox.uuid.Uuid*/ otherUuid){ - // summary: - // Returns true if this UUID is equal to the otherUuid, or false otherwise. - // otherUuid: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec. - return (this.compare(otherUuid) == 0); // boolean -}; - -dojox.uuid.Uuid.prototype.isValid = function(){ - // summary: - // Returns true if the UUID was initialized with a valid value. - return dojox.uuid.isValid(this); -}; - -dojox.uuid.Uuid.prototype.getVariant = function(){ - // summary: - // Returns a variant code that indicates what type of UUID this is. - // Returns one of the enumerated dojox.uuid.variant values. - - // example: - // var uuid = new dojox.uuid.Uuid("3b12f1df-5232-4804-897e-917bf397618a"); - // var variant = uuid.getVariant(); - // dojox.uuid.assert(variant == dojox.uuid.variant.DCE); - // example: - // "3b12f1df-5232-4804-897e-917bf397618a" - // ^ - // | - // (variant "10__" == DCE) - return dojox.uuid.getVariant(this); -}; - -dojox.uuid.Uuid.prototype.getVersion = function(){ - // summary: - // Returns a version number that indicates what type of UUID this is. - // Returns one of the enumerated dojox.uuid.version values. - // example: - // var uuid = new dojox.uuid.Uuid("b4308fb0-86cd-11da-a72b-0800200c9a66"); - // var version = uuid.getVersion(); - // dojox.uuid.assert(version == dojox.uuid.version.TIME_BASED); - // exceptions: - // Throws an Error if this is not a DCE Variant UUID. - if(!this._versionNumber){ - this._versionNumber = dojox.uuid.getVersion(this); - } - return this._versionNumber; // dojox.uuid.version -}; - -dojox.uuid.Uuid.prototype.getNode = function(){ - // summary: - // If this is a version 1 UUID (a time-based UUID), getNode() returns a - // 12-character string with the "node" or "pseudonode" portion of the UUID, - // which is the rightmost 12 characters. - // exceptions: - // Throws an Error if this is not a version 1 UUID. - if (!this._nodeString) { - this._nodeString = dojox.uuid.getNode(this); - } - return this._nodeString; // String (a 12-character string, which will look something like "917bf397618a") -}; - -dojox.uuid.Uuid.prototype.getTimestamp = function(/*String?*/ returnType){ - // summary: - // If this is a version 1 UUID (a time-based UUID), this method returns - // the timestamp value encoded in the UUID. The caller can ask for the - // timestamp to be returned either as a JavaScript Date object or as a - // 15-character string of hex digits. - // returnType: Any of these five values: "string", String, "hex", "date", Date - // returns: - // Returns the timestamp value as a JavaScript Date object or a 15-character string of hex digits. - // examples: - // var uuid = new dojox.uuid.Uuid("b4308fb0-86cd-11da-a72b-0800200c9a66"); - // var date, string, hexString; - // date = uuid.getTimestamp(); // returns a JavaScript Date - // date = uuid.getTimestamp(Date); // - // string = uuid.getTimestamp(String); // "Mon, 16 Jan 2006 20:21:41 GMT" - // hexString = uuid.getTimestamp("hex"); // "1da86cdb4308fb0" - // exceptions: - // Throws an Error if this is not a version 1 UUID. - if(!returnType){returnType = null}; - switch(returnType){ - case "string": - case String: - return this.getTimestamp(Date).toUTCString(); // String (e.g. "Mon, 16 Jan 2006 20:21:41 GMT") - break; - case "hex": - // Return a 15-character string of hex digits containing the - // timestamp for this UUID, with the high-order bits first. - if (!this._timestampAsHexString) { - this._timestampAsHexString = dojox.uuid.getTimestamp(this, "hex"); - } - return this._timestampAsHexString; // String (e.g. "1da86cdb4308fb0") - break; - case null: // no returnType was specified, so default to Date - case "date": - case Date: - // Return a JavaScript Date object. - if (!this._timestampAsDate) { - this._timestampAsDate = dojox.uuid.getTimestamp(this, Date); - } - return this._timestampAsDate; // Date - break; - default: - // we got passed something other than a valid returnType - dojox.uuid.assert(false, "The getTimestamp() method dojox.uuid.Uuid was passed a bogus returnType: " + returnType); - break; - } -}; - -} diff --git a/includes/js/dojox/uuid/_base.js b/includes/js/dojox/uuid/_base.js deleted file mode 100644 index b65e5da..0000000 --- a/includes/js/dojox/uuid/_base.js +++ /dev/null @@ -1,245 +0,0 @@ -if(!dojo._hasResource["dojox.uuid._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.uuid._base"] = true; -dojo.provide("dojox.uuid._base"); - -// Public constants: -dojox.uuid.NIL_UUID = "00000000-0000-0000-0000-000000000000"; -dojox.uuid.version = { - // Enumeration for the different UUID versions. - UNKNOWN: 0, - TIME_BASED: 1, - DCE_SECURITY: 2, - NAME_BASED_MD5: 3, - RANDOM: 4, - NAME_BASED_SHA1: 5 }; -dojox.uuid.variant = { - // Enumeration for the different UUID variants. - NCS: "0", - DCE: "10", - MICROSOFT: "110", - UNKNOWN: "111" }; - -dojox.uuid.assert = function(/*Boolean*/ booleanValue, /*String?*/ message){ - // summary: - // Throws an exception if the assertion fails. - // description: - // If the asserted condition is true, this method does nothing. If the - // condition is false, we throw an error with a error message. - // booleanValue: Must be true for the assertion to succeed. - // message: A string describing the assertion. - // throws: Throws an Error if 'booleanValue' is false. - if(!booleanValue){ - if(!message){ - message = "An assert statement failed.\n" + - "The method dojox.uuid.assert() was called with a 'false' value.\n"; - } - throw new Error(message); - } -}; - -dojox.uuid.generateNilUuid = function(){ - // summary: - // This function returns the Nil UUID: "00000000-0000-0000-0000-000000000000". - // description: - // The Nil UUID is described in section 4.1.7 of - // RFC 4122: http://tools.ietf.org/html/rfc4122#section-4.1.7 - // examples: - // var string = dojox.uuid.generateNilUuid(); - return dojox.uuid.NIL_UUID;; // String -}; - -dojox.uuid.isValid = function(/*String*/ uuidString){ - // summary: - // Returns true if the UUID was initialized with a valid value. - uuidString = uuidString.toString(); - var valid = (dojo.isString(uuidString) && - (uuidString.length == 36) && - (uuidString == uuidString.toLowerCase())); - if(valid){ - var arrayOfParts = uuidString.split("-"); - valid = ((arrayOfParts.length == 5) && - (arrayOfParts[0].length == 8) && - (arrayOfParts[1].length == 4) && - (arrayOfParts[2].length == 4) && - (arrayOfParts[3].length == 4) && - (arrayOfParts[4].length == 12)); - var HEX_RADIX = 16; - for (var i in arrayOfParts) { - var part = arrayOfParts[i]; - var integer = parseInt(part, HEX_RADIX); - valid = valid && isFinite(integer); - } - } - return valid; // boolean -}; - -dojox.uuid.getVariant = function(/*String*/ uuidString){ - // summary: - // Returns a variant code that indicates what type of UUID this is. - // Returns one of the enumerated dojox.uuid.variant values. - // example: - // var variant = dojox.uuid.getVariant("3b12f1df-5232-4804-897e-917bf397618a"); - // dojox.uuid.assert(variant == dojox.uuid.variant.DCE); - // example: - // "3b12f1df-5232-4804-897e-917bf397618a" - // ^ - // | - // (variant "10__" == DCE) - if(!dojox.uuid._ourVariantLookupTable){ - var variant = dojox.uuid.variant; - var lookupTable = []; - - lookupTable[0x0] = variant.NCS; // 0000 - lookupTable[0x1] = variant.NCS; // 0001 - lookupTable[0x2] = variant.NCS; // 0010 - lookupTable[0x3] = variant.NCS; // 0011 - - lookupTable[0x4] = variant.NCS; // 0100 - lookupTable[0x5] = variant.NCS; // 0101 - lookupTable[0x6] = variant.NCS; // 0110 - lookupTable[0x7] = variant.NCS; // 0111 - - lookupTable[0x8] = variant.DCE; // 1000 - lookupTable[0x9] = variant.DCE; // 1001 - lookupTable[0xA] = variant.DCE; // 1010 - lookupTable[0xB] = variant.DCE; // 1011 - - lookupTable[0xC] = variant.MICROSOFT; // 1100 - lookupTable[0xD] = variant.MICROSOFT; // 1101 - lookupTable[0xE] = variant.UNKNOWN; // 1110 - lookupTable[0xF] = variant.UNKNOWN; // 1111 - - dojox.uuid._ourVariantLookupTable = lookupTable; - } - - uuidString = uuidString.toString(); - var variantCharacter = uuidString.charAt(19); - var HEX_RADIX = 16; - var variantNumber = parseInt(variantCharacter, HEX_RADIX); - dojox.uuid.assert((variantNumber >= 0) && (variantNumber <= 16)); - return dojox.uuid._ourVariantLookupTable[variantNumber]; // dojox.uuid.variant -}; - -dojox.uuid.getVersion = function(/*String*/ uuidString){ - // summary: - // Returns a version number that indicates what type of UUID this is. - // Returns one of the enumerated dojox.uuid.version values. - // example: - // var version = dojox.uuid.getVersion("b4308fb0-86cd-11da-a72b-0800200c9a66"); - // dojox.uuid.assert(version == dojox.uuid.version.TIME_BASED); - // exceptions: - // Throws an Error if this is not a DCE Variant UUID. - var errorMessage = "dojox.uuid.getVersion() was not passed a DCE Variant UUID."; - dojox.uuid.assert(dojox.uuid.getVariant(uuidString) == dojox.uuid.variant.DCE, errorMessage); - uuidString = uuidString.toString(); - - // "b4308fb0-86cd-11da-a72b-0800200c9a66" - // ^ - // | - // (version 1 == TIME_BASED) - var versionCharacter = uuidString.charAt(14); - var HEX_RADIX = 16; - var versionNumber = parseInt(versionCharacter, HEX_RADIX); - return versionNumber; // dojox.uuid.version -}; - -dojox.uuid.getNode = function(/*String*/ uuidString){ - // summary: - // If this is a version 1 UUID (a time-based UUID), getNode() returns a - // 12-character string with the "node" or "pseudonode" portion of the UUID, - // which is the rightmost 12 characters. - // exceptions: - // Throws an Error if this is not a version 1 UUID. - var errorMessage = "dojox.uuid.getNode() was not passed a TIME_BASED UUID."; - dojox.uuid.assert(dojox.uuid.getVersion(uuidString) == dojox.uuid.version.TIME_BASED, errorMessage); - - uuidString = uuidString.toString(); - var arrayOfStrings = uuidString.split('-'); - var nodeString = arrayOfStrings[4]; - return nodeString; // String (a 12-character string, which will look something like "917bf397618a") -}; - -dojox.uuid.getTimestamp = function(/*String*/ uuidString, /*String?*/ returnType){ - // summary: - // If this is a version 1 UUID (a time-based UUID), this method returns - // the timestamp value encoded in the UUID. The caller can ask for the - // timestamp to be returned either as a JavaScript Date object or as a - // 15-character string of hex digits. - // returnType: Any of these five values: "string", String, "hex", "date", Date - // returns: - // Returns the timestamp value as a JavaScript Date object or a 15-character string of hex digits. - // examples: - // var uuidString = "b4308fb0-86cd-11da-a72b-0800200c9a66"; - // var date, string, hexString; - // date = dojox.uuid.getTimestamp(uuidString); // returns a JavaScript Date - // date = dojox.uuid.getTimestamp(uuidString, Date); // - // string = dojox.uuid.getTimestamp(uuidString, String); // "Mon, 16 Jan 2006 20:21:41 GMT" - // hexString = dojox.uuid.getTimestamp(uuidString, "hex"); // "1da86cdb4308fb0" - // exceptions: - // Throws an Error if this is not a version 1 UUID. - var errorMessage = "dojox.uuid.getTimestamp() was not passed a TIME_BASED UUID."; - dojox.uuid.assert(dojox.uuid.getVersion(uuidString) == dojox.uuid.version.TIME_BASED, errorMessage); - - uuidString = uuidString.toString(); - if(!returnType){returnType = null}; - switch(returnType){ - case "string": - case String: - return dojox.uuid.getTimestamp(uuidString, Date).toUTCString(); // String (e.g. "Mon, 16 Jan 2006 20:21:41 GMT") - break; - case "hex": - // Return a 15-character string of hex digits containing the - // timestamp for this UUID, with the high-order bits first. - var arrayOfStrings = uuidString.split('-'); - var hexTimeLow = arrayOfStrings[0]; - var hexTimeMid = arrayOfStrings[1]; - var hexTimeHigh = arrayOfStrings[2]; - - // Chop off the leading "1" character, which is the UUID - // version number for time-based UUIDs. - hexTimeHigh = hexTimeHigh.slice(1); - - var timestampAsHexString = hexTimeHigh + hexTimeMid + hexTimeLow; - dojox.uuid.assert(timestampAsHexString.length == 15); - return timestampAsHexString; // String (e.g. "1da86cdb4308fb0") - break; - case null: // no returnType was specified, so default to Date - case "date": - case Date: - // Return a JavaScript Date object. - var GREGORIAN_CHANGE_OFFSET_IN_HOURS = 3394248; - var HEX_RADIX = 16; - - var arrayOfParts = uuidString.split('-'); - var timeLow = parseInt(arrayOfParts[0], HEX_RADIX); - var timeMid = parseInt(arrayOfParts[1], HEX_RADIX); - var timeHigh = parseInt(arrayOfParts[2], HEX_RADIX); - var hundredNanosecondIntervalsSince1582 = timeHigh & 0x0FFF; - hundredNanosecondIntervalsSince1582 <<= 16; - hundredNanosecondIntervalsSince1582 += timeMid; - // What we really want to do next is shift left 32 bits, but the - // result will be too big to fit in an int, so we'll multiply by 2^32, - // and the result will be a floating point approximation. - hundredNanosecondIntervalsSince1582 *= 0x100000000; - hundredNanosecondIntervalsSince1582 += timeLow; - var millisecondsSince1582 = hundredNanosecondIntervalsSince1582 / 10000; - - // Again, this will be a floating point approximation. - // We can make things exact later if we need to. - var secondsPerHour = 60 * 60; - var hoursBetween1582and1970 = GREGORIAN_CHANGE_OFFSET_IN_HOURS; - var secondsBetween1582and1970 = hoursBetween1582and1970 * secondsPerHour; - var millisecondsBetween1582and1970 = secondsBetween1582and1970 * 1000; - var millisecondsSince1970 = millisecondsSince1582 - millisecondsBetween1582and1970; - - var timestampAsDate = new Date(millisecondsSince1970); - return timestampAsDate; // Date - break; - default: - // we got passed something other than a valid returnType - dojox.uuid.assert(false, "dojox.uuid.getTimestamp was not passed a valid returnType: " + returnType); - break; - } -}; - -} diff --git a/includes/js/dojox/uuid/generateRandomUuid.js b/includes/js/dojox/uuid/generateRandomUuid.js deleted file mode 100644 index ec590e9..0000000 --- a/includes/js/dojox/uuid/generateRandomUuid.js +++ /dev/null @@ -1,56 +0,0 @@ -if(!dojo._hasResource["dojox.uuid.generateRandomUuid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.uuid.generateRandomUuid"] = true; -dojo.provide("dojox.uuid.generateRandomUuid"); - -dojox.uuid.generateRandomUuid = function(){ - // summary: - // This function generates random UUIDs, meaning "version 4" UUIDs. - // description: - // A typical generated value would be something like this: - // "3b12f1df-5232-4804-897e-917bf397618a" - // - // For more information about random UUIDs, see sections 4.4 and - // 4.5 of RFC 4122: http://tools.ietf.org/html/rfc4122#section-4.4 - // - // This generator function is designed to be small and fast, - // but not necessarily good. - // - // Small: This generator has a small footprint. Once comments are - // stripped, it's only about 25 lines of code, and it doesn't - // dojo.require() any other modules. - // - // Fast: This generator can generate lots of new UUIDs fairly quickly - // (at least, more quickly than the other dojo UUID generators). - // - // Not necessarily good: We use Math.random() as our source - // of randomness, which may or may not provide much randomness. - // examples: - // var string = dojox.uuid.generateRandomUuid(); - var HEX_RADIX = 16; - - function _generateRandomEightCharacterHexString(){ - // Make random32bitNumber be a randomly generated floating point number - // between 0 and (4,294,967,296 - 1), inclusive. - var random32bitNumber = Math.floor( (Math.random() % 1) * Math.pow(2, 32) ); - var eightCharacterHexString = random32bitNumber.toString(HEX_RADIX); - while(eightCharacterHexString.length < 8){ - eightCharacterHexString = "0" + eightCharacterHexString; - } - return eightCharacterHexString; // for example: "3B12F1DF" - } - - var hyphen = "-"; - var versionCodeForRandomlyGeneratedUuids = "4"; // 8 == binary2hex("0100") - var variantCodeForDCEUuids = "8"; // 8 == binary2hex("1000") - var a = _generateRandomEightCharacterHexString(); - var b = _generateRandomEightCharacterHexString(); - b = b.substring(0, 4) + hyphen + versionCodeForRandomlyGeneratedUuids + b.substring(5, 8); - var c = _generateRandomEightCharacterHexString(); - c = variantCodeForDCEUuids + c.substring(1, 4) + hyphen + c.substring(4, 8); - var d = _generateRandomEightCharacterHexString(); - var returnValue = a + hyphen + b + hyphen + c + d; - returnValue = returnValue.toLowerCase(); - return returnValue; // String -}; - -} diff --git a/includes/js/dojox/uuid/generateTimeBasedUuid.js b/includes/js/dojox/uuid/generateTimeBasedUuid.js deleted file mode 100644 index 20be9f4..0000000 --- a/includes/js/dojox/uuid/generateTimeBasedUuid.js +++ /dev/null @@ -1,290 +0,0 @@ -if(!dojo._hasResource["dojox.uuid.generateTimeBasedUuid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.uuid.generateTimeBasedUuid"] = true; -dojo.provide("dojox.uuid.generateTimeBasedUuid"); - -dojox.uuid.generateTimeBasedUuid = function(/*String?*/ node){ - // summary: - // This function generates time-based UUIDs, meaning "version 1" UUIDs. - // description: - // For more info, see - // http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt - // http://www.infonuovo.com/dma/csdocs/sketch/instidid.htm - // http://kruithof.xs4all.nl/uuid/uuidgen - // http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagcjh_20 - // http://jakarta.apache.org/commons/sandbox/id/apidocs/org/apache/commons/id/uuid/clock/Clock.html - // node: - // A 12-character hex string representing either a pseudo-node or - // hardware-node (an IEEE 802.3 network node). A hardware-node - // will be something like "017bf397618a", always with the first bit - // being 0. A pseudo-node will be something like "f17bf397618a", - // always with the first bit being 1. - // examples: - // string = dojox.uuid.generateTimeBasedUuid(); - // string = dojox.uuid.generateTimeBasedUuid("017bf397618a"); - // dojox.uuid.generateTimeBasedUuid.setNode("017bf397618a"); - // string = dojox.uuid.generateTimeBasedUuid(); // the generated UUID has node == "017bf397618a" - var uuidString = dojox.uuid.generateTimeBasedUuid._generator.generateUuidString(node); - return uuidString; // String -}; - -dojox.uuid.generateTimeBasedUuid.isValidNode = function(/*String?*/ node){ - var HEX_RADIX = 16; - var integer = parseInt(node, HEX_RADIX); - var valid = dojo.isString(node) && node.length == 12 && isFinite(integer); - return valid; // Boolean -}; - -dojox.uuid.generateTimeBasedUuid.setNode = function(/*String?*/ node){ - // summary: - // Sets the 'node' value that will be included in generated UUIDs. - // node: A 12-character hex string representing a pseudoNode or hardwareNode. - dojox.uuid.assert((node === null) || this.isValidNode(node)); - this._uniformNode = node; -}; - -dojox.uuid.generateTimeBasedUuid.getNode = function(){ - // summary: - // Returns the 'node' value that will be included in generated UUIDs. - return this._uniformNode; // String (a 12-character hex string representing a pseudoNode or hardwareNode) -}; - - -dojox.uuid.generateTimeBasedUuid._generator = new function(){ - // Number of hours between October 15, 1582 and January 1, 1970: - this.GREGORIAN_CHANGE_OFFSET_IN_HOURS = 3394248; - - // Number of seconds between October 15, 1582 and January 1, 1970: - // dojox.uuid.generateTimeBasedUuid.GREGORIAN_CHANGE_OFFSET_IN_SECONDS = 12219292800; - - // -------------------------------------------------- - // Private variables: - var _uuidPseudoNodeString = null; - var _uuidClockSeqString = null; - var _dateValueOfPreviousUuid = null; - var _nextIntraMillisecondIncrement = 0; - var _cachedMillisecondsBetween1582and1970 = null; - var _cachedHundredNanosecondIntervalsPerMillisecond = null; - - // -------------------------------------------------- - // Private constants: - var HEX_RADIX = 16; - - function _carry(/* array */ arrayA){ - // summary: - // Given an array which holds a 64-bit number broken into 4 16-bit - // elements, this method carries any excess bits (greater than 16-bits) - // from each array element into the next. - // arrayA: An array with 4 elements, each of which is a 16-bit number. - arrayA[2] += arrayA[3] >>> 16; - arrayA[3] &= 0xFFFF; - arrayA[1] += arrayA[2] >>> 16; - arrayA[2] &= 0xFFFF; - arrayA[0] += arrayA[1] >>> 16; - arrayA[1] &= 0xFFFF; - dojox.uuid.assert((arrayA[0] >>> 16) === 0); - } - - function _get64bitArrayFromFloat(/* float */ x){ - // summary: - // Given a floating point number, this method returns an array which - // holds a 64-bit number broken into 4 16-bit elements. - var result = new Array(0, 0, 0, 0); - result[3] = x % 0x10000; - x -= result[3]; - x /= 0x10000; - result[2] = x % 0x10000; - x -= result[2]; - x /= 0x10000; - result[1] = x % 0x10000; - x -= result[1]; - x /= 0x10000; - result[0] = x; - return result; // Array with 4 elements, each of which is a 16-bit number. - } - - function _addTwo64bitArrays(/* array */ arrayA, /* array */ arrayB){ - // summary: - // Takes two arrays, each of which holds a 64-bit number broken into 4 - // 16-bit elements, and returns a new array that holds a 64-bit number - // that is the sum of the two original numbers. - // arrayA: An array with 4 elements, each of which is a 16-bit number. - // arrayB: An array with 4 elements, each of which is a 16-bit number. - dojox.uuid.assert(dojo.isArray(arrayA)); - dojox.uuid.assert(dojo.isArray(arrayB)); - dojox.uuid.assert(arrayA.length == 4); - dojox.uuid.assert(arrayB.length == 4); - - var result = new Array(0, 0, 0, 0); - result[3] = arrayA[3] + arrayB[3]; - result[2] = arrayA[2] + arrayB[2]; - result[1] = arrayA[1] + arrayB[1]; - result[0] = arrayA[0] + arrayB[0]; - _carry(result); - return result; // Array with 4 elements, each of which is a 16-bit number. - } - - function _multiplyTwo64bitArrays(/* array */ arrayA, /* array */ arrayB){ - // summary: - // Takes two arrays, each of which holds a 64-bit number broken into 4 - // 16-bit elements, and returns a new array that holds a 64-bit number - // that is the product of the two original numbers. - // arrayA: An array with 4 elements, each of which is a 16-bit number. - // arrayB: An array with 4 elements, each of which is a 16-bit number. - dojox.uuid.assert(dojo.isArray(arrayA)); - dojox.uuid.assert(dojo.isArray(arrayB)); - dojox.uuid.assert(arrayA.length == 4); - dojox.uuid.assert(arrayB.length == 4); - - var overflow = false; - if(arrayA[0] * arrayB[0] !== 0){ overflow = true; } - if(arrayA[0] * arrayB[1] !== 0){ overflow = true; } - if(arrayA[0] * arrayB[2] !== 0){ overflow = true; } - if(arrayA[1] * arrayB[0] !== 0){ overflow = true; } - if(arrayA[1] * arrayB[1] !== 0){ overflow = true; } - if(arrayA[2] * arrayB[0] !== 0){ overflow = true; } - dojox.uuid.assert(!overflow); - - var result = new Array(0, 0, 0, 0); - result[0] += arrayA[0] * arrayB[3]; - _carry(result); - result[0] += arrayA[1] * arrayB[2]; - _carry(result); - result[0] += arrayA[2] * arrayB[1]; - _carry(result); - result[0] += arrayA[3] * arrayB[0]; - _carry(result); - result[1] += arrayA[1] * arrayB[3]; - _carry(result); - result[1] += arrayA[2] * arrayB[2]; - _carry(result); - result[1] += arrayA[3] * arrayB[1]; - _carry(result); - result[2] += arrayA[2] * arrayB[3]; - _carry(result); - result[2] += arrayA[3] * arrayB[2]; - _carry(result); - result[3] += arrayA[3] * arrayB[3]; - _carry(result); - return result; // Array with 4 elements, each of which is a 16-bit number. - } - - function _padWithLeadingZeros(/* string */ string, /* int */ desiredLength){ - // summary: - // Pads a string with leading zeros and returns the result. - // string: A string to add padding to. - // desiredLength: The number of characters the return string should have. - - // examples: - // result = _padWithLeadingZeros("abc", 6); - // dojox.uuid.assert(result == "000abc"); - while(string.length < desiredLength){ - string = "0" + string; - } - return string; // string - } - - function _generateRandomEightCharacterHexString() { - // summary: - // Returns a randomly generated 8-character string of hex digits. - - // FIXME: This probably isn't a very high quality random number. - - // Make random32bitNumber be a randomly generated floating point number - // between 0 and (4,294,967,296 - 1), inclusive. - var random32bitNumber = Math.floor( (Math.random() % 1) * Math.pow(2, 32) ); - - var eightCharacterString = random32bitNumber.toString(HEX_RADIX); - while(eightCharacterString.length < 8){ - eightCharacterString = "0" + eightCharacterString; - } - return eightCharacterString; // String (an 8-character hex string) - } - - this.generateUuidString = function(/*String?*/ node){ - // summary: - // Generates a time-based UUID, meaning a version 1 UUID. - // description: - // JavaScript code running in a browser doesn't have access to the - // IEEE 802.3 address of the computer, so if a node value isn't - // supplied, we generate a random pseudonode value instead. - // node: An optional 12-character string to use as the node in the new UUID. - if(node){ - dojox.uuid.assert(dojox.uuid.generateTimeBasedUuid.isValidNode(node)); - }else{ - if(dojox.uuid.generateTimeBasedUuid._uniformNode){ - node = dojox.uuid.generateTimeBasedUuid._uniformNode; - }else{ - if(!_uuidPseudoNodeString){ - var pseudoNodeIndicatorBit = 0x8000; - var random15bitNumber = Math.floor( (Math.random() % 1) * Math.pow(2, 15) ); - var leftmost4HexCharacters = (pseudoNodeIndicatorBit | random15bitNumber).toString(HEX_RADIX); - _uuidPseudoNodeString = leftmost4HexCharacters + _generateRandomEightCharacterHexString(); - } - node = _uuidPseudoNodeString; - } - } - if(!_uuidClockSeqString){ - var variantCodeForDCEUuids = 0x8000; // 10--------------, i.e. uses only first two of 16 bits. - var random14bitNumber = Math.floor( (Math.random() % 1) * Math.pow(2, 14) ); - _uuidClockSeqString = (variantCodeForDCEUuids | random14bitNumber).toString(HEX_RADIX); - } - - // Maybe we should think about trying to make the code more readable to - // newcomers by creating a class called "WholeNumber" that encapsulates - // the methods and data structures for working with these arrays that - // hold 4 16-bit numbers? And then these variables below have names - // like "wholeSecondsPerHour" rather than "arraySecondsPerHour"? - var now = new Date(); - var millisecondsSince1970 = now.valueOf(); // milliseconds since midnight 01 January, 1970 UTC. - var nowArray = _get64bitArrayFromFloat(millisecondsSince1970); - if(!_cachedMillisecondsBetween1582and1970){ - var arraySecondsPerHour = _get64bitArrayFromFloat(60 * 60); - var arrayHoursBetween1582and1970 = _get64bitArrayFromFloat(dojox.uuid.generateTimeBasedUuid._generator.GREGORIAN_CHANGE_OFFSET_IN_HOURS); - var arraySecondsBetween1582and1970 = _multiplyTwo64bitArrays(arrayHoursBetween1582and1970, arraySecondsPerHour); - var arrayMillisecondsPerSecond = _get64bitArrayFromFloat(1000); - _cachedMillisecondsBetween1582and1970 = _multiplyTwo64bitArrays(arraySecondsBetween1582and1970, arrayMillisecondsPerSecond); - _cachedHundredNanosecondIntervalsPerMillisecond = _get64bitArrayFromFloat(10000); - } - var arrayMillisecondsSince1970 = nowArray; - var arrayMillisecondsSince1582 = _addTwo64bitArrays(_cachedMillisecondsBetween1582and1970, arrayMillisecondsSince1970); - var arrayHundredNanosecondIntervalsSince1582 = _multiplyTwo64bitArrays(arrayMillisecondsSince1582, _cachedHundredNanosecondIntervalsPerMillisecond); - - if(now.valueOf() == _dateValueOfPreviousUuid){ - arrayHundredNanosecondIntervalsSince1582[3] += _nextIntraMillisecondIncrement; - _carry(arrayHundredNanosecondIntervalsSince1582); - _nextIntraMillisecondIncrement += 1; - if (_nextIntraMillisecondIncrement == 10000) { - // If we've gotten to here, it means we've already generated 10,000 - // UUIDs in this single millisecond, which is the most that the UUID - // timestamp field allows for. So now we'll just sit here and wait - // for a fraction of a millisecond, so as to ensure that the next - // time this method is called there will be a different millisecond - // value in the timestamp field. - while (now.valueOf() == _dateValueOfPreviousUuid) { - now = new Date(); - } - } - }else{ - _dateValueOfPreviousUuid = now.valueOf(); - _nextIntraMillisecondIncrement = 1; - } - - var hexTimeLowLeftHalf = arrayHundredNanosecondIntervalsSince1582[2].toString(HEX_RADIX); - var hexTimeLowRightHalf = arrayHundredNanosecondIntervalsSince1582[3].toString(HEX_RADIX); - var hexTimeLow = _padWithLeadingZeros(hexTimeLowLeftHalf, 4) + _padWithLeadingZeros(hexTimeLowRightHalf, 4); - var hexTimeMid = arrayHundredNanosecondIntervalsSince1582[1].toString(HEX_RADIX); - hexTimeMid = _padWithLeadingZeros(hexTimeMid, 4); - var hexTimeHigh = arrayHundredNanosecondIntervalsSince1582[0].toString(HEX_RADIX); - hexTimeHigh = _padWithLeadingZeros(hexTimeHigh, 3); - var hyphen = "-"; - var versionCodeForTimeBasedUuids = "1"; // binary2hex("0001") - var resultUuid = hexTimeLow + hyphen + hexTimeMid + hyphen + - versionCodeForTimeBasedUuids + hexTimeHigh + hyphen + - _uuidClockSeqString + hyphen + node; - resultUuid = resultUuid.toLowerCase(); - return resultUuid; // String (a 36 character string, which will look something like "b4308fb0-86cd-11da-a72b-0800200c9a66") - } - -}(); - -} diff --git a/includes/js/dojox/uuid/tests/runTests.html b/includes/js/dojox/uuid/tests/runTests.html deleted file mode 100644 index 41ba177..0000000 --- a/includes/js/dojox/uuid/tests/runTests.html +++ /dev/null @@ -1,10 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title>Dojox.uuid Unit Test Runner</title> - <meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.uuid.tests.uuid"> - </head> - <body> - Redirecting to D.O.H runner. - </body> -</html> diff --git a/includes/js/dojox/uuid/tests/uuid.js b/includes/js/dojox/uuid/tests/uuid.js deleted file mode 100644 index 9cc89e0..0000000 --- a/includes/js/dojox/uuid/tests/uuid.js +++ /dev/null @@ -1,377 +0,0 @@ -if(!dojo._hasResource["dojox.uuid.tests.uuid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojox.uuid.tests.uuid"] = true; -dojo.provide("dojox.uuid.tests.uuid"); -dojo.require("dojox.uuid"); -dojo.require("dojox.uuid.Uuid"); -dojo.require("dojox.uuid.generateRandomUuid"); -dojo.require("dojox.uuid.generateTimeBasedUuid"); - -dojox.uuid.tests.uuid.checkValidityOfUuidString = function(/*String*/uuidString){ - // summary: - // A helper function that's used by the registered test functions - var NIL_UUID = "00000000-0000-0000-0000-000000000000"; - if (uuidString == NIL_UUID) { - // We'll consider the Nil UUID to be valid, so now - // we can just return, with not further checks. - return; - } - - doh.assertTrue(uuidString.length == 36); // UUIDs have 36 characters - - var validCharacters = "0123456789abcedfABCDEF-"; - var character; - var position; - for(var i = 0; i < 36; ++i){ - character = uuidString.charAt(i); - position = validCharacters.indexOf(character); - doh.assertTrue(position != -1); // UUIDs have only valid characters - } - - var arrayOfParts = uuidString.split("-"); - doh.assertTrue(arrayOfParts.length == 5); // UUIDs have 5 sections separated by 4 hyphens - doh.assertTrue(arrayOfParts[0].length == 8); // Section 0 has 8 characters - doh.assertTrue(arrayOfParts[1].length == 4); // Section 1 has 4 characters - doh.assertTrue(arrayOfParts[2].length == 4); // Section 2 has 4 characters - doh.assertTrue(arrayOfParts[3].length == 4); // Section 3 has 4 characters - doh.assertTrue(arrayOfParts[4].length == 12); // Section 4 has 8 characters - - // check to see that the "UUID variant code" starts with the binary bits '10' - var section3 = arrayOfParts[3]; - var HEX_RADIX = 16; - var hex3 = parseInt(section3, HEX_RADIX); - var binaryString = hex3.toString(2); - // alert("section3 = " + section3 + "\n binaryString = " + binaryString); - doh.assertTrue(binaryString.length == 16); // section 3 has 16 bits - doh.assertTrue(binaryString.charAt(0) == '1'); // first bit of section 3 is 1 - doh.assertTrue(binaryString.charAt(1) == '0'); // second bit of section 3 is 0 -} - -dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString = function(/*String*/uuidString){ - // summary: - // A helper function that's used by the registered test functions - dojox.uuid.tests.uuid.checkValidityOfUuidString(uuidString); - var arrayOfParts = uuidString.split("-"); - var section2 = arrayOfParts[2]; - doh.assertTrue(section2.charAt(0) == "1"); // Section 2 starts with a 1 -} - -dojox.uuid.tests.uuid.checkForPseudoNodeBitInTimeBasedUuidString = function(/*String*/uuidString){ - // summary: - // A helper function that's used by the registered test functions - var arrayOfParts = uuidString.split("-"); - var section4 = arrayOfParts[4]; - var firstChar = section4.charAt(0); - var HEX_RADIX = 16; - var hexFirstChar = parseInt(firstChar, HEX_RADIX); - var binaryString = hexFirstChar.toString(2); - var firstBit; - if(binaryString.length == 4){ - firstBit = binaryString.charAt(0); - }else{ - firstBit = '0'; - } - doh.assertTrue(firstBit == '1'); // first bit of section 4 is 1 -} - -doh.register("dojox.uuid.tests.uuid", - [ - /* - function test_uuid_performance(){ - var start = new Date(); - var startMS = start.valueOf(); - var nowMS = startMS; - var i; - var now; - var numTrials = 100000; - - while(nowMS == startMS){ - now = new Date(); - nowMS = now.valueOf(); - } - - startMS = nowMS; - for(i = 0; i < numTrials; ++i){ - var a = dojox.uuid.LightweightGenerator.generate(); - } - now = new Date(); - nowMS = now.valueOf(); - var elapsedMS = nowMS - startMS; - // dojo.log.debug("created " + numTrials + " UUIDs in " + elapsedMS + " milliseconds"); - }, - */ - - function test_uuid_capitalization(){ - var randomLowercaseString = "3b12f1df-5232-4804-897e-917bf397618a"; - var randomUppercaseString = "3B12F1DF-5232-4804-897E-917BF397618A"; - - var timebasedLowercaseString = "b4308fb0-86cd-11da-a72b-0800200c9a66"; - var timebasedUppercaseString = "B4308FB0-86CD-11DA-A72B-0800200C9A66"; - - var uuidRL = new dojox.uuid.Uuid(randomLowercaseString); - var uuidRU = new dojox.uuid.Uuid(randomUppercaseString); - - var uuidTL = new dojox.uuid.Uuid(timebasedLowercaseString); - var uuidTU = new dojox.uuid.Uuid(timebasedUppercaseString); - - doh.assertTrue(uuidRL.isEqual(uuidRU)); - doh.assertTrue(uuidRU.isEqual(uuidRL)); - - doh.assertTrue(uuidTL.isEqual(uuidTU)); - doh.assertTrue(uuidTU.isEqual(uuidTL)); - }, - - function test_uuid_constructor(){ - var uuid, uuidToo; - - var nilUuid = '00000000-0000-0000-0000-000000000000'; - uuid = new dojox.uuid.Uuid(); - doh.assertTrue(uuid == nilUuid); // 'new dojox.uuid.Uuid()' returns the Nil UUID - - var randomUuidString = "3b12f1df-5232-4804-897e-917bf397618a"; - uuid = new dojox.uuid.Uuid(randomUuidString); - doh.assertTrue(uuid.isValid()); - doh.assertTrue(uuid.getVariant() == dojox.uuid.variant.DCE); - doh.assertTrue(uuid.getVersion() == dojox.uuid.version.RANDOM); - uuidToo = new dojox.uuid.Uuid(new String(randomUuidString)); - doh.assertTrue(uuid.isEqual(uuidToo)); - - var timeBasedUuidString = "b4308fb0-86cd-11da-a72b-0800200c9a66"; - uuid = new dojox.uuid.Uuid(timeBasedUuidString); - doh.assertTrue(uuid.isValid()); - doh.assertTrue(uuid.getVariant() == dojox.uuid.variant.DCE); - doh.assertTrue(uuid.getVersion() == dojox.uuid.version.TIME_BASED); - doh.assertTrue(uuid.getNode() == "0800200c9a66"); - var timestamp = uuid.getTimestamp(); - var date = uuid.getTimestamp(Date); - var dateString = uuid.getTimestamp(String); - var hexString = uuid.getTimestamp("hex"); - var now = new Date(); - doh.assertTrue(timestamp.valueOf() == date.valueOf()); - doh.assertTrue(hexString == "1da86cdb4308fb0"); - doh.assertTrue(timestamp < now); - }, - - function test_uuid_generators(){ - var generators = [ - dojox.uuid.generateNilUuid, - dojox.uuid.generateRandomUuid, - dojox.uuid.generateTimeBasedUuid - ]; - - for(var i in generators){ - var generator = generators[i]; - var uuidString = generator(); - - doh.assertTrue((typeof uuidString) == 'string'); - dojox.uuid.tests.uuid.checkValidityOfUuidString(uuidString); - - var uuid = new dojox.uuid.Uuid(uuidString); - if(generator != dojox.uuid.generateNilUuid){ - doh.assertTrue(uuid.getVariant() == dojox.uuid.variant.DCE); - } - - doh.assertTrue(uuid.isEqual(uuid)); - doh.assertTrue(uuid.compare(uuid) == 0); - doh.assertTrue(dojox.uuid.Uuid.compare(uuid, uuid) == 0); - dojox.uuid.tests.uuid.checkValidityOfUuidString(uuid.toString()); - doh.assertTrue(uuid.toString().length == 36); - - if(generator != dojox.uuid.generateNilUuid){ - var uuidStringOne = generator(); - var uuidStringTwo = generator(); - doh.assertTrue(uuidStringOne != uuidStringTwo); - - dojox.uuid.Uuid.setGenerator(generator); - var uuidOne = new dojox.uuid.Uuid(); - var uuidTwo = new dojox.uuid.Uuid(); - doh.assertTrue(generator === dojox.uuid.Uuid.getGenerator()); - dojox.uuid.Uuid.setGenerator(null); - doh.assertTrue(uuidOne != uuidTwo); - doh.assertTrue(!uuidOne.isEqual(uuidTwo)); - doh.assertTrue(!uuidTwo.isEqual(uuidOne)); - - var oneVsTwo = dojox.uuid.Uuid.compare(uuidOne, uuidTwo); // either 1 or -1 - var twoVsOne = dojox.uuid.Uuid.compare(uuidTwo, uuidOne); // either -1 or 1 - doh.assertTrue(oneVsTwo + twoVsOne == 0); - doh.assertTrue(oneVsTwo != 0); - doh.assertTrue(twoVsOne != 0); - - doh.assertTrue(!uuidTwo.isEqual(uuidOne)); - } - - if(generator == dojox.uuid.generateRandomUuid){ - doh.assertTrue(uuid.getVersion() == dojox.uuid.version.RANDOM); - } - - if(generator == dojox.uuid.generateTimeBasedUuid){ - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(uuid.toString()); - doh.assertTrue(uuid.getVersion() == dojox.uuid.version.TIME_BASED); - doh.assertTrue(dojo.isString(uuid.getNode())); - doh.assertTrue(uuid.getNode().length == 12); - var timestamp = uuid.getTimestamp(); - var date = uuid.getTimestamp(Date); - var dateString = uuid.getTimestamp(String); - var hexString = uuid.getTimestamp("hex"); - doh.assertTrue(date instanceof Date); - doh.assertTrue(timestamp.valueOf() == date.valueOf()); - doh.assertTrue(hexString.length == 15); - } - } - }, - - function test_uuid_nilGenerator(){ - var nilUuidString = '00000000-0000-0000-0000-000000000000'; - var uuidString = dojox.uuid.generateNilUuid(); - doh.assertTrue(uuidString == nilUuidString); - }, - - function test_uuid_timeBasedGenerator(){ - var uuid; // an instance of dojox.uuid.Uuid - var string; // a simple string literal - var generator = dojox.uuid.generateTimeBasedUuid; - - var string1 = generator(); - var uuid2 = new dojox.uuid.Uuid(generator()); - var string3 = generator("017bf397618a"); // hardwareNode - var string4 = generator("f17bf397618a"); // pseudoNode - var string5 = generator(new String("017BF397618A")); - - dojox.uuid.generateTimeBasedUuid.setNode("017bf397618a"); - var string6 = generator(); // the generated UUID has node == "017bf397618a" - var uuid7 = new dojox.uuid.Uuid(generator()); // the generated UUID has node == "017bf397618a" - var returnedNode = dojox.uuid.generateTimeBasedUuid.getNode(); - doh.assertTrue(returnedNode == "017bf397618a"); - - function getNode(string){ - var arrayOfStrings = string.split('-'); - return arrayOfStrings[4]; - } - dojox.uuid.tests.uuid.checkForPseudoNodeBitInTimeBasedUuidString(string1); - dojox.uuid.tests.uuid.checkForPseudoNodeBitInTimeBasedUuidString(uuid2.toString()); - dojox.uuid.tests.uuid.checkForPseudoNodeBitInTimeBasedUuidString(string4); - - doh.assertTrue(getNode(string3) == "017bf397618a"); - doh.assertTrue(getNode(string4) == "f17bf397618a"); - doh.assertTrue(getNode(string5) == "017bf397618a"); - doh.assertTrue(getNode(string6) == "017bf397618a"); - doh.assertTrue(uuid7.getNode() == "017bf397618a"); - - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(string1); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(uuid2.toString()); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(string3); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(string4); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(string5); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(string6); - dojox.uuid.tests.uuid.checkValidityOfTimeBasedUuidString(uuid7.toString()); - }, - - function test_uuid_invalidUuids(){ - var uuidStrings = []; - uuidStrings.push("Hello world!"); // not a UUID - uuidStrings.push("3B12F1DF-5232-1804-897E-917BF39761"); // too short - uuidStrings.push("3B12F1DF-5232-1804-897E-917BF39761-8A"); // extra '-' - uuidStrings.push("3B12F1DF-5232-1804-897E917BF39761-8A"); // last '-' in wrong place - uuidStrings.push("HB12F1DF-5232-1804-897E-917BF397618A"); // "HB12F1DF" is not a hex string - - var numberOfFailures = 0; - for(var i in uuidStrings){ - var uuidString = uuidStrings[i]; - try{ - new dojox.uuid.Uuid(uuidString); - }catch (e){ - ++numberOfFailures; - } - } - doh.assertTrue(numberOfFailures == uuidStrings.length); - } - ] -); - - - -/* -function test_uuid_get64bitArrayFromFloat(){ - // summary: - // This is a test we'd like to be able to run, but we can't run it - // because it tests a function which is private in generateTimeBasedUuid - var x = Math.pow(2, 63) + Math.pow(2, 15); - var result = dojox.uuid.generateTimeBasedUuid._get64bitArrayFromFloat(x); - doh.assertTrue(result[0] === 0x8000); - doh.assertTrue(result[1] === 0x0000); - doh.assertTrue(result[2] === 0x0000); - doh.assertTrue(result[3] === 0x8000); - - var date = new Date(); - x = date.valueOf(); - result = dojox.uuid.generateTimeBasedUuid._get64bitArrayFromFloat(x); - var reconstructedFloat = result[0]; - reconstructedFloat *= 0x10000; - reconstructedFloat += result[1]; - reconstructedFloat *= 0x10000; - reconstructedFloat += result[2]; - reconstructedFloat *= 0x10000; - reconstructedFloat += result[3]; - - doh.assertTrue(reconstructedFloat === x); -} - -function test_uuid_addTwo64bitArrays(){ - // summary: - // This is a test we'd like to be able to run, but we can't run it - // because it tests a function which is private in generateTimeBasedUuid - var a = [0x0000, 0x0000, 0x0000, 0x0001]; - var b = [0x0FFF, 0xFFFF, 0xFFFF, 0xFFFF]; - var result = dojox.uuid.generateTimeBasedUuid._addTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 0x1000); - doh.assertTrue(result[1] === 0x0000); - doh.assertTrue(result[2] === 0x0000); - doh.assertTrue(result[3] === 0x0000); - - a = [0x4000, 0x8000, 0x8000, 0x8000]; - b = [0x8000, 0x8000, 0x8000, 0x8000]; - result = dojox.uuid.generateTimeBasedUuid._addTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 0xC001); - doh.assertTrue(result[1] === 0x0001); - doh.assertTrue(result[2] === 0x0001); - doh.assertTrue(result[3] === 0x0000); - - a = [7, 6, 2, 5]; - b = [1, 0, 3, 4]; - result = dojox.uuid.generateTimeBasedUuid._addTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 8); - doh.assertTrue(result[1] === 6); - doh.assertTrue(result[2] === 5); - doh.assertTrue(result[3] === 9); -} - -function test_uuid_multiplyTwo64bitArrays(){ - // summary: - // This is a test we'd like to be able to run, but we can't run it - // because it tests a function which is private in generateTimeBasedUuid - var a = [ 0, 0x0000, 0x0000, 0x0003]; - var b = [0x1111, 0x1234, 0x0000, 0xFFFF]; - var result = dojox.uuid.generateTimeBasedUuid._multiplyTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 0x3333); - doh.assertTrue(result[1] === 0x369C); - doh.assertTrue(result[2] === 0x0002); - doh.assertTrue(result[3] === 0xFFFD); - - a = [0, 0, 0, 5]; - b = [0, 0, 0, 4]; - result = dojox.uuid.generateTimeBasedUuid._multiplyTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 0); - doh.assertTrue(result[1] === 0); - doh.assertTrue(result[2] === 0); - doh.assertTrue(result[3] === 20); - - a = [0, 0, 2, 5]; - b = [0, 0, 3, 4]; - result = dojox.uuid.generateTimeBasedUuid._multiplyTwo64bitArrays(a, b); - doh.assertTrue(result[0] === 0); - doh.assertTrue(result[1] === 6); - doh.assertTrue(result[2] === 23); - doh.assertTrue(result[3] === 20); -} -*/ - -} |