1 5 package com.tctest; 6 7 import com.tc.object.config.ConfigVisitor; 8 import com.tc.object.config.DSOClientConfigHelper; 9 import com.tc.object.config.TransparencyClassSpec; 10 import com.tc.simulator.app.ApplicationConfig; 11 import com.tc.simulator.listener.ListenerProvider; 12 import com.tctest.runner.AbstractTransparentApp; 13 14 import java.util.Random ; 15 16 public class ArrayTestApp extends AbstractTransparentApp { 17 18 private String [] myArrayTestRoot; 19 20 public ArrayTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 21 super(appId, cfg, listenerProvider); 22 this.myArrayTestRoot = new String [] { "hee", "hoo", "haa" }; 23 } 24 25 public void run() { 26 Random rand = new Random (); 27 try { 28 synchronized (myArrayTestRoot) { 29 System.out.println(myArrayTestRoot[rand.nextInt(myArrayTestRoot.length)]); 30 } 31 Thread.sleep(1); 32 } catch (Exception e) { 33 e.printStackTrace(); 34 } 35 36 arrayIndexTestCase(); 37 38 testNullArrayAccess(); 39 } 40 41 private void testNullArrayAccess() { 42 Object [] o = null; 43 44 try { 45 if (o[3] == null) { throw new AssertionError (); } 46 } catch (NullPointerException npe) { 47 } 49 } 50 51 private void arrayIndexTestCase() { 52 try { 54 for (int i = 0; true; i++) { 55 Object o = myArrayTestRoot[i]; 56 57 if (o == null) { 59 continue; 60 } 61 } 62 } catch (ArrayIndexOutOfBoundsException aioobe) { 63 } 65 66 try { 67 Object o = myArrayTestRoot[-1]; 68 if (true || o == o) { throw new AssertionError (); } 69 } catch (ArrayIndexOutOfBoundsException aioobe) { 70 } 72 73 } 74 75 public void setArray(String [] blah) { 76 myArrayTestRoot = blah; 77 } 78 79 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 80 String testClass = ArrayTestApp.class.getName(); 81 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 82 83 String methodExpression = "* " + testClass + "*.*(..)"; 84 config.addWriteAutolock(methodExpression); 85 spec.addRoot("myArrayTestRoot", "myArrayTestRoot"); 86 87 } 88 } 89
| Popular Tags
|