Esempio n. 1
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);
        }
Esempio n. 2
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);
        }