Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7370b7f6d0d1d679d8be79e36ff102d4e3e87456 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.net4j.util.tests;

import org.eclipse.net4j.util.UUIDGenerator;
import org.eclipse.net4j.util.io.IOUtil;

/**
 * @author Eike Stepper
 * @since 4.0
 */
public class UUIDGeneratorTest extends AbstractOMTest
{
  public void testCodec()
  {
    byte[] uuid = new byte[16];
    long start = System.currentTimeMillis();

    for (int b3 = Byte.MIN_VALUE; b3 <= Byte.MAX_VALUE; b3++)
    {
      IOUtil.OUT().println(b3);
      for (int b2 = Byte.MIN_VALUE; b2 <= Byte.MAX_VALUE; b2++)
      {
        for (int b1 = Byte.MIN_VALUE; b1 <= Byte.MAX_VALUE; b1++)
        {
          for (int off = 0; off < 13; off++)
          {
            check(uuid, b1, b2, b3, off);
          }
        }
      }
    }

    IOUtil.OUT().println("Millis: " + (System.currentTimeMillis() - start));
  }

  private static void check(byte[] uuid, int b1, int b2, int b3, int off)
  {
    uuid[0 + off] = (byte)b1;
    uuid[2 + off] = (byte)b2;
    uuid[3 + off] = (byte)b3;

    String encoded = UUIDGenerator.DEFAULT.encode(uuid);
    byte[] decoded = UUIDGenerator.DEFAULT.decode(encoded);

    for (int i = 0; i < 3; i++)
    {
      assertEquals(uuid[i + off], decoded[i + off]);
    }
  }
}

Back to the top