示例#1
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);
        }
示例#2
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);
        }