1 21 22 package org.apache.derbyTesting.unitTests.services; 23 24 import org.apache.derbyTesting.unitTests.harness.T_Generic; 25 import org.apache.derbyTesting.unitTests.harness.T_Fail; 26 27 import org.apache.derby.catalog.UUID; 28 29 import org.apache.derby.iapi.services.monitor.Monitor; 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 33 34 import org.apache.derby.iapi.services.uuid.UUIDFactory; 35 36 40 41 public class T_UUIDFactory extends T_Generic { 42 43 protected UUIDFactory factory; 44 boolean resultSoFar; 45 46 public T_UUIDFactory() { 47 super(); 48 } 49 50 protected String getModuleToTestProtocolName() { 51 52 return "A.Dummy.Name"; 53 } 54 55 61 protected void runTests() throws T_Fail { 62 63 factory = Monitor.getMonitor().getUUIDFactory(); 64 if (factory == null) { 65 throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " module not started."); 66 } 67 68 if (!testUUID()) 69 throw T_Fail.testFailMsg("testUUID indicated failure"); 70 } 71 72 73 76 77 protected boolean testUUID() { 78 resultSoFar = true; 79 80 UUID uuid1 = factory.createUUID(); 81 UUID uuid2 = factory.createUUID(); 82 83 if (uuid1.equals(uuid2)){ 84 String message = 86 "UUID factory created matching UUIDS '%0' and '%1'"; 87 out.printlnWithHeader(message); 88 resultSoFar = false; 89 } 90 91 if (!uuid1.equals(uuid1)){ 92 String message = 94 "UUID '%0' does not equal itself"; 95 resultSoFar = false; 96 } 97 98 if (uuid1.hashCode() != uuid1.hashCode()){ 99 String message = 101 "UUID '%0' does not hash to the same thing twice."; 102 out.printlnWithHeader(message); 103 resultSoFar = false; 104 } 105 106 108 String suuid1 = uuid1.toString(); 109 UUID uuid3 = factory.recreateUUID(suuid1); 110 if (!uuid3.equals(uuid1)){ 111 String message = 113 "Couldn't recreate UUID: " 114 + uuid3.toString() 115 + " != " 116 + uuid1.toString(); 117 out.printlnWithHeader(message); 118 resultSoFar = false; 119 } 120 121 124 testUUIDConversions(out, "7878FCD0-DA09-11d0-BAFE-0060973F0942"); 126 127 testUUIDConversions(out, "80706050-4030-2010-8070-605040302010"); 129 testUUIDConversions(out, "f0e0d0c0-b0a0-9080-7060-504030201000"); 130 testUUIDConversions(out, "00000000-0000-0000-0000-000000000000"); 131 testUUIDConversions(out, "ffffffff-ffff-ffff-ffff-ffffffffffff"); 132 133 testUUIDConversions(out, factory.createUUID().toString()); 135 testUUIDConversions(out, factory.createUUID().toString()); 136 137 return resultSoFar; 138 139 } 140 141 private void testUUIDConversions(HeaderPrintWriter out, String uuidstring) 142 { 143 UUID uuid = factory.recreateUUID(uuidstring); 144 if (!uuidstring.equalsIgnoreCase(uuid.toString())){ 145 String message = 147 "Couldn't recreate UUID String: " 148 + uuidstring 149 + " != " 150 + uuid.toString(); 151 out.printlnWithHeader(message); 152 resultSoFar = false; 153 } 154 155 byte[] uuidByteArray = uuid.toByteArray(); 156 UUID uuid_b = factory.recreateUUID(uuidByteArray); 157 if (!uuid_b.equals(uuid)) 158 { 159 String badByteArrayString = ""; 161 for (int ix = 0; ix < 16; ix++) 162 { 163 badByteArrayString += 164 Integer.toHexString(0x00ff&uuidByteArray[ix])+"."; 165 } 166 167 String message = 168 "Conversion error: " 169 + uuidstring 170 + " != " 171 + badByteArrayString; 172 out.printlnWithHeader(message); 173 resultSoFar = false; 174 } 175 } 176 } 177 | Popular Tags |