Beispiel #1
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));
            }
        }
Beispiel #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);
        }