1 10 11 package com.triactive.jdo.store.test; 12 13 import com.triactive.jdo.store.OID; 14 import java.util.Random ; 15 import junit.framework.Test; 16 import junit.framework.TestCase; 17 18 19 25 26 public class OIDTest extends TestCase 27 { 28 34 35 public OIDTest(String name) 36 { 37 super(name); 38 } 39 40 41 44 45 public void testOID() 46 { 47 int[] x = new int[] { 0, 1, 2, OID.MAX_CLASSID - 2, OID.MAX_CLASSID - 1, OID.MAX_CLASSID }; 48 int[] y = new int[] { 0, 1, 2, OID.MAX_OBJIDHI - 2, OID.MAX_OBJIDHI - 1, OID.MAX_OBJIDHI }; 49 int[] z = new int[] { 0, 1, 2, OID.MAX_OBJIDLO - 2, OID.MAX_OBJIDLO - 1, OID.MAX_OBJIDLO }; 50 51 Random rnd = new Random (0); 52 53 for (int i = 0; i < x.length; ++i) 54 { 55 for (int j = 0; j < y.length; ++j) 56 { 57 for (int k = 0; k < z.length; ++k) 58 { 59 tryOneOID(x[i], y[j], z[k]); 60 61 tryOneOID(rnd.nextInt(OID.MAX_CLASSID), 62 rnd.nextInt(OID.MAX_OBJIDHI), 63 rnd.nextInt(OID.MAX_OBJIDLO)); 64 } 65 } 66 } 67 } 68 69 70 private void tryOneOID(int x, int y, int z) 71 { 72 OID id1 = new OID(x, y, z); 73 74 assertEquals(x, id1.getClassID()); 75 76 String s = id1.toString(); 77 78 assertEquals(OID.MAX_LENGTH, s.length()); 79 assertEquals('-', s.charAt(3)); 80 assertEquals('-', s.charAt(10)); 81 82 String allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-"; 83 84 for (int i = 0; i < OID.MAX_LENGTH; ++i) 85 assertTrue(allowedChars.indexOf(s.charAt(i)) >= 0); 86 87 int x1 = Integer.parseInt(s.substring(0, 3), 32); 88 int y1 = Integer.parseInt(s.substring(4, 10), 32); 89 int z1 = Integer.parseInt(s.substring(11), 32); 90 91 assertEquals(x, x1); 92 assertEquals(y, y1); 93 assertEquals(z, z1); 94 95 OID id2 = new OID(s.toLowerCase()); 96 OID id3 = new OID(s.toUpperCase()); 97 OID id4 = new OID(id1.longValue()); 98 99 assertEquals(id1, id2); 100 assertEquals(id2, id3); 101 assertEquals(id3, id4); 102 assertEquals(id4, id1); 103 } 104 } 105 | Popular Tags |