01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: OIDTest.java,v 1.3 2002/11/08 05:06:26 jackknifebarber Exp $
09: */
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: * Tests the functionality of the {@link OID} class.
20: *
21: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
22: * @version $Revision: 1.3 $
23: */
24:
25: public class OIDTest extends TestCase {
26: /**
27: * Used by the JUnit framework to construct tests. Normally, programmers
28: * would never explicitly use this constructor.
29: *
30: * @param name Name of the <tt>TestCase</tt>.
31: */
32:
33: public OIDTest(String name) {
34: super (name);
35: }
36:
37: /**
38: * Test the functionality of the {@link OID} class.
39: */
40:
41: public void testOID() {
42: int[] x = new int[] { 0, 1, 2, OID.MAX_CLASSID - 2,
43: OID.MAX_CLASSID - 1, OID.MAX_CLASSID };
44: int[] y = new int[] { 0, 1, 2, OID.MAX_OBJIDHI - 2,
45: OID.MAX_OBJIDHI - 1, OID.MAX_OBJIDHI };
46: int[] z = new int[] { 0, 1, 2, OID.MAX_OBJIDLO - 2,
47: OID.MAX_OBJIDLO - 1, OID.MAX_OBJIDLO };
48:
49: Random rnd = new Random(0);
50:
51: for (int i = 0; i < x.length; ++i) {
52: for (int j = 0; j < y.length; ++j) {
53: for (int k = 0; k < z.length; ++k) {
54: tryOneOID(x[i], y[j], z[k]);
55:
56: tryOneOID(rnd.nextInt(OID.MAX_CLASSID), rnd
57: .nextInt(OID.MAX_OBJIDHI), rnd
58: .nextInt(OID.MAX_OBJIDLO));
59: }
60: }
61: }
62: }
63:
64: private void tryOneOID(int x, int y, int z) {
65: OID id1 = new OID(x, y, z);
66:
67: assertEquals(x, id1.getClassID());
68:
69: String s = id1.toString();
70:
71: assertEquals(OID.MAX_LENGTH, s.length());
72: assertEquals('-', s.charAt(3));
73: assertEquals('-', s.charAt(10));
74:
75: String allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
76:
77: for (int i = 0; i < OID.MAX_LENGTH; ++i)
78: assertTrue(allowedChars.indexOf(s.charAt(i)) >= 0);
79:
80: int x1 = Integer.parseInt(s.substring(0, 3), 32);
81: int y1 = Integer.parseInt(s.substring(4, 10), 32);
82: int z1 = Integer.parseInt(s.substring(11), 32);
83:
84: assertEquals(x, x1);
85: assertEquals(y, y1);
86: assertEquals(z, z1);
87:
88: OID id2 = new OID(s.toLowerCase());
89: OID id3 = new OID(s.toUpperCase());
90: OID id4 = new OID(id1.longValue());
91:
92: assertEquals(id1, id2);
93: assertEquals(id2, id3);
94: assertEquals(id3, id4);
95: assertEquals(id4, id1);
96: }
97: }
|