Example #1
0
        public void testGenerateRandomBasedUUID()
        {
            // this test will attempt to check for reasonable behavior of the
            // generateRandomBasedUUID method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // for the random UUID generator, we will generate a bunch of
            // random UUIDs
            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] = uuid_gen.GenerateRandomBasedUUID();
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version (type-4)
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_RANDOM_BASED);

            // check that all uuids were unique
            // NOTE: technically, this test 'could' fail, but statistically
            // speaking it should be extremely unlikely unless the implementation
            // of (Secure)Random is bad
            checkUUIDArrayForUniqueness(uuid_array);
        }
Example #2
0
        public UUIDGeneratorViewModel()
        {
            UUIDGenerator   = new UUIDGenerator(AppLogger);
            CopyUUIDCommand = new RelayCommand(() => PlatformShim.CopyToClipboard(UUIDGenerator.UUID));

            bool uuidGenerateFunction() => UUIDGenerator.Initiate();

            ExecuteTaskCommand = new RelayCommand(async() => await InitiateProcessAsync(uuidGenerateFunction, ExecuteTaskCommand), () => !IsBusy);
        }
        public UUIDGeneratorViewModel()
        {
            UUIDGenerator   = new UUIDGenerator(AppLogger);
            CopyUUIDCommand = new RelayCommand(() => Clipboard.SetText(UUIDGenerator.UUID ?? string.Empty));

            bool sortLinesFunction() => UUIDGenerator.Initiate();

            ExecuteTaskCommand = new RelayCommand(async() => await InitiateProcessAsync(sortLinesFunction, ExecuteTaskCommand), () => !IsBusy);
        }
Example #4
0
        public void testGenerateTimeBasedUUID()
        {
            // this test will attempt to check for reasonable behavior of the
            // generateTimeBasedUUID method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // first check that given a number of calls to generateTimeBasedUUID,
            // all returned UUIDs order after the last returned UUID
            // we'll check this by generating the UUIDs into one array and sorting
            // then in another and checking the order of the two match
            // change the number in the array statement if you want more or less
            // UUIDs to be generated and tested
            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // before we generate all the uuids, lets get the start time
            long start_time = Environment.TickCount;

            // high-resolution timer
            Stopwatch timer = Stopwatch.StartNew();

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] = uuid_gen.GenerateTimeBasedUUID();
            }

            timer.Stop();

            // now capture the end time
            long end_time = start_time + timer.ElapsedTicks;

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version (type-1)
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_TIME_BASED);

            // check that all the uuids were generated with correct order
            checkUUIDArrayForCorrectOrdering(uuid_array);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);

            // check that all uuids have timestamps between the start and end time
            checkUUIDArrayForCorrectCreationTime(uuid_array, start_time, end_time);
        }
Example #5
0
        public void testGenerateRandomBasedUUIDWithRandom()
        {
            // this test will attempt to check for reasonable behavior of the
            // generateRandomBasedUUID method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // first, check that a null passed in causes the appropriate exception
            try
            {
                UUID uuid = uuid_gen.GenerateRandomBasedUUID((Random)null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            // for the random UUID generator, we will generate a bunch of
            // random UUIDs using a (Secure)Random instance we generated
            Random secure_random = new Random();

            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] = uuid_gen.GenerateRandomBasedUUID(secure_random);
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version (type-4)
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_RANDOM_BASED);

            // check that all uuids were unique
            // NOTE: technically, this test 'could' fail, but statistically
            // speaking it should be extremely unlikely unless the
            // implementation of SecureRandom is bad
            checkUUIDArrayForUniqueness(uuid_array);
        }
Example #6
0
        public void testGetInstance()
        {
            // really, there isn't a lot to test here
            // we'll make sure that getInstance returns the same
            // reference when called twice since it is supposed to
            // be a singleton class factory
            UUIDGenerator uuid_gen1 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen2 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen3 = UUIDGenerator.Current;

            assertTrue("uuid_gen1 == uuid_gen2 was not true",
                       uuid_gen1 == uuid_gen2);
            assertTrue("uuid_gen2 == uuid_gen3 was not true",
                       uuid_gen2 == uuid_gen3);
            assertTrue("uuid_gen1 == uuid_gen3 was not true",
                       uuid_gen1 == uuid_gen3);
        }
Example #7
0
        public void testGetDummyAddress()
        {
            // this test will attempt to check for reasonable behavior of the
            // getDummyAddress method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // for the random UUID generator, we will generate a bunch of
            // dummy ethernet addresses
            // NOTE: although creating a bunch of dummy ethernet addresses
            // is not the normal mode of operation, we'return testing for
            // generally good behavior, so we'll create a bunch to make sure the
            // general patterns are observed
            PhysicalAddress[] ethernet_address_array =
                new PhysicalAddress[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < ethernet_address_array.Length; i++)
            {
                ethernet_address_array[i] = uuid_gen.GetDummyAddress();
            }

            PhysicalAddress null_ethernet_address = new PhysicalAddress(new byte[6]);

            for (int i = 0; i < ethernet_address_array.Length; i++)
            {
                byte[] ethernet_address = ethernet_address_array[i].GetAddressBytes();
                // check that none of the EthernetAddresses are null
                assertNotEquals("dummy EthernetAddress was null",
                                null_ethernet_address.GetAddressBytes(),
                                ethernet_address);

                // check that the "broadcast" bit is set in the created address

                /* 08-Feb-2004, TSa: Fixed as per fix to actual code; apparently
                 *   broadcast bit is LSB, not MSB.
                 */
                assertEquals("dummy EthernetAddress was not broadcast",
                             0x01,
                             (ethernet_address[0] & 0x01));
            }
        }
Example #8
0
        // Creates a New RTSUnitInstance on the Given Team with the Given Data at the Given Position
        public RTSUnit(RTSTeam team, RTSUnitData data, Vector2 position)
        {
            // Identification
            UUID    = UUIDGenerator.GetUUID();
            Team    = team;
            Squad   = null;
            gridPos = position;

            // Set From Common Data
            Data   = data;
            Health = Data.Health;

            // Default Information
            height             = 0;
            ViewDirection      = Vector2.UnitX;
            CollisionGeometry  = Data.ICollidableShape.Clone() as ICollidable;
            MovementMultiplier = 1f;
            Resources          = 0;
        }
Example #9
0
        // Constructor
        public RTSBuilding(RTSTeam team, RTSBuildingData data, Vector2 position)
        {
            // Identification
            UUID       = UUIDGenerator.GetUUID();
            Team       = team;
            gridPos    = position;
            viewedInfo = new BitArray(GameState.MAX_PLAYERS);
            viewedInfo.SetAll(false);

            Data                      = data;
            gridPos.X                += (Data.GridSize.X - 1);
            gridPos.Y                += (Data.GridSize.Y - 1);
            height                    = 0;
            Health                    = Data.Health;
            bAmount                   = Data.BuildAmount;
            CollisionGeometry         = Data.ICollidableShape.Clone() as ICollidable;
            ViewDirection             = Vector2.UnitX;
            CollisionGeometry.Center += GridPosition;
            bControllers              = new List <ACBuildingButtonController>();
        }
Example #10
0
        public void testGetHashAlgorithm()
        {
            // really, there isn't a lot to test here
            // we'll make sure that getHashAlgorithm returns the same
            // reference when called more then once from more then one instance
            // since it is supposed to be a shared MessageDigest
            UUIDGenerator uuid_gen1 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen2 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen3 = UUIDGenerator.Current;

            assertTrue("uuid_gen1 == uuid_gen2 was not true",
                       uuid_gen1 == uuid_gen2);
            assertTrue("uuid_gen2 == uuid_gen3 was not true",
                       uuid_gen2 == uuid_gen3);
            assertTrue("uuid_gen1 == uuid_gen3 was not true",
                       uuid_gen1 == uuid_gen3);

            MD5 message_digest1 = uuid_gen1.GetHashAlgorithm();
            MD5 message_digest2 = uuid_gen1.GetHashAlgorithm();
            MD5 message_digest3 = uuid_gen2.GetHashAlgorithm();
            MD5 message_digest4 = uuid_gen2.GetHashAlgorithm();
            MD5 message_digest5 = uuid_gen3.GetHashAlgorithm();
            MD5 message_digest6 = uuid_gen3.GetHashAlgorithm();

            assertTrue("message_digest1 == message_digest2 was not true",
                       message_digest1 == message_digest2);
            assertTrue("message_digest2 == message_digest3 was not true",
                       message_digest2 == message_digest3);
            assertTrue("message_digest3 == message_digest4 was not true",
                       message_digest3 == message_digest4);
            assertTrue("message_digest4 == message_digest5 was not true",
                       message_digest4 == message_digest5);
            assertTrue("message_digest5 == message_digest6 was not true",
                       message_digest5 == message_digest6);
            assertTrue("message_digest6 == message_digest1 was not true",
                       message_digest6 == message_digest1);
        }
Example #11
0
        public void testGetRandomNumberGenerator()
        {
            // really, there isn't a lot to test here
            // we'll make sure that getRandomNumberGenerator returns the same
            // reference when called more then once from more then one instance
            // since it is supposed to be a shared generator
            UUIDGenerator uuid_gen1 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen2 = UUIDGenerator.Current;
            UUIDGenerator uuid_gen3 = UUIDGenerator.Current;

            assertTrue("uuid_gen1 == uuid_gen2 was not true",
                       uuid_gen1 == uuid_gen2);
            assertTrue("uuid_gen2 == uuid_gen3 was not true",
                       uuid_gen2 == uuid_gen3);
            assertTrue("uuid_gen1 == uuid_gen3 was not true",
                       uuid_gen1 == uuid_gen3);

            Random secure_rand1 = uuid_gen1.GetRandomNumberGenerator();
            Random secure_rand2 = uuid_gen1.GetRandomNumberGenerator();
            Random secure_rand3 = uuid_gen2.GetRandomNumberGenerator();
            Random secure_rand4 = uuid_gen2.GetRandomNumberGenerator();
            Random secure_rand5 = uuid_gen3.GetRandomNumberGenerator();
            Random secure_rand6 = uuid_gen3.GetRandomNumberGenerator();

            assertTrue("secure_rand1 == secure_rand2 was not true",
                       secure_rand1 == secure_rand2);
            assertTrue("secure_rand2 == secure_rand3 was not true",
                       secure_rand2 == secure_rand3);
            assertTrue("secure_rand3 == secure_rand4 was not true",
                       secure_rand3 == secure_rand4);
            assertTrue("secure_rand4 == secure_rand5 was not true",
                       secure_rand4 == secure_rand5);
            assertTrue("secure_rand5 == secure_rand6 was not true",
                       secure_rand5 == secure_rand6);
            assertTrue("secure_rand6 == secure_rand1 was not true",
                       secure_rand6 == secure_rand1);
        }
Example #12
0
        public void testGenerateTagURIBasedUUIDWithMessageDigest()
        {
            String TEST_AUTHORITY = "www.safehaus.org";
            MD5    MESSAGE_DIGEST = MD5.Create();

            // this test will attempt to check for reasonable behavior of the
            // generateTagURIBasedUUID method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // first, check that a null passed in causes the appropriate exception
            try
            {
                UUID uuid = uuid_gen.GenerateTagURIBasedUUID(null, MESSAGE_DIGEST);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            try
            {
                TagURI test_tag =
                    new TagURI(TEST_AUTHORITY, "test id", DateTime.Now);
                UUID uuid = uuid_gen.GenerateTagURIBasedUUID(test_tag, null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            try
            {
                UUID uuid = uuid_gen.GenerateTagURIBasedUUID(null, null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                TagURI test_tag =
                    new TagURI(TEST_AUTHORITY, "test id" + i,
                               DateTime.Now);
                uuid_array[i] =
                    uuid_gen.GenerateTagURIBasedUUID(test_tag, MESSAGE_DIGEST);
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_NAME_BASED);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);

            // now, lets make sure generating two sets of tag based uuid with the
            // same args always gives the same result
            uuid_array = new UUID[SIZE_OF_TEST_ARRAY];
            UUID[] uuid_array2 = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                TagURI test_tag =
                    new TagURI(TEST_AUTHORITY, "test id" + i,
                               DateTime.Now);
                uuid_array[i] =
                    uuid_gen.GenerateTagURIBasedUUID(test_tag, MESSAGE_DIGEST);
                uuid_array2[i] =
                    uuid_gen.GenerateTagURIBasedUUID(test_tag, MESSAGE_DIGEST);
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);
            checkUUIDArrayForNonNullUUIDs(uuid_array2);

            // check that all the uuids were correct variant and version
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_NAME_BASED);
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array2, UUID.TYPE_NAME_BASED);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);
            checkUUIDArrayForUniqueness(uuid_array2);

            // check that both arrays are equal to one another
            assertEquals("expected both arrays to be equal, they were not!",
                         uuid_array, uuid_array2);
        }
Example #13
0
        public void testGenerateNameBasedUUIDNameSpaceNameAndMessageDigest()
        {
            UUID NAMESPACE_UUID = new UUID(UUID.NAMESPACE_URL);

            // this test will attempt to check for reasonable behavior of the
            // generateNameBasedUUID method

            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // first, check that a null passed in causes the appropriate exception
            try
            {
                UUID uuid =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, null, MD5.Create());
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            try
            {
                UUID uuid =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, "test name", null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            try
            {
                UUID uuid =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, null, null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, "test name" + i, MD5.Create());
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_NAME_BASED);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] =
                    uuid_gen.GenerateNameBasedUUID(
                        null, "test name" + i, MD5.Create());
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_NAME_BASED);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);

            // now, lets make sure generating two sets of name based uuid with the
            // same args always gives the same result
            uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, "test name" + i, MD5.Create());
            }

            UUID[] uuid_array2 = new UUID[SIZE_OF_TEST_ARRAY];

            // now create the array of uuids
            for (int i = 0; i < uuid_array2.Length; i++)
            {
                uuid_array2[i] =
                    uuid_gen.GenerateNameBasedUUID(
                        NAMESPACE_UUID, "test name" + i, MD5.Create());
            }

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);
            checkUUIDArrayForNonNullUUIDs(uuid_array2);

            // check that all the uuids were correct variant and version
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_NAME_BASED);
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array2, UUID.TYPE_NAME_BASED);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);
            checkUUIDArrayForUniqueness(uuid_array2);

            // check that both arrays are equal to one another
            assertEquals("expected both arrays to be equal, they were not!",
                         uuid_array, uuid_array2);
        }
Example #14
0
        public void testGenerateTimeBasedUUIDWithEthernetAddress()
        {
            // we need a instance to use
            UUIDGenerator uuid_gen = UUIDGenerator.Current;

            // this test will attempt to check for reasonable behavior of the
            // generateTimeBasedUUID(EthernetAddress) method
            PhysicalAddress ethernet_address =
                uuid_gen.GetDummyAddress();

            // first, check that a null passed in causes the appropriate exception
            try
            {
                UUID uuid = uuid_gen.GenerateTimeBasedUUID(null);
                fail("Expected exception not thrown");
            }
            catch (NullReferenceException)
            {
                // expected exception caught, do nothing
            }
            catch (Exception ex)
            {
                fail("unexpected exception caught: " + ex);
            }

            // check that given a number of calls to generateTimeBasedUUID,
            // all returned UUIDs order after the last returned UUID
            // we'll check this by generating the UUIDs into one array and sorting
            // then in another and checking the order of the two match
            // change the number in the array statement if you want more or less
            // UUIDs to be generated and tested
            UUID[] uuid_array = new UUID[SIZE_OF_TEST_ARRAY];

            // before we generate all the uuids, lets get the start time
            long start_time = Environment.TickCount;

            // high-resolution timer
            Stopwatch timer = Stopwatch.StartNew();

            // now create the array of uuids
            for (int i = 0; i < uuid_array.Length; i++)
            {
                uuid_array[i] = uuid_gen.GenerateTimeBasedUUID(ethernet_address);
            }

            timer.Stop();

            // now capture the end time
            long end_time = start_time + timer.ElapsedTicks;

            // check that none of the UUIDs are null
            checkUUIDArrayForNonNullUUIDs(uuid_array);

            // check that all the uuids were correct variant and version (type-1)
            checkUUIDArrayForCorrectVariantAndVersion(
                uuid_array, UUID.TYPE_TIME_BASED);

            // check that all the uuids were generated with correct order
            checkUUIDArrayForCorrectOrdering(uuid_array);

            // check that all uuids were unique
            checkUUIDArrayForUniqueness(uuid_array);

            // check that all uuids have timestamps between the start and end time
            checkUUIDArrayForCorrectCreationTime(uuid_array, start_time, end_time);

            // check that all UUIDs have the correct ethernet address in the UUID
            checkUUIDArrayForCorrectEthernetAddress(uuid_array, ethernet_address);
        }
Example #15
0
 private void UUIDGeneratorUC_Load(object sender, EventArgs e)
 {
     _uuidGenerator = new UUIDGenerator();
     _errorProvider = new StandardErrorProvider();
 }