1 package org.apache.commons.javaflow.bytecode.transformation.tests; 2 3 import org.apache.commons.javaflow.Continuation; 4 import org.apache.commons.javaflow.bytecode.transformation.AbstractTransformerTestCase; 5 import org.apache.commons.javaflow.bytecode.transformation.rewrite.Simple; 6 import org.apache.commons.javaflow.bytecode.transformation.rewrite.SimpleSynchronized; 7 import org.apache.commons.javaflow.bytecode.transformation.rewrite.SimpleTryCatch; 8 9 public abstract class AbstractSimpleTestCase extends AbstractTransformerTestCase { 10 11 public void testSimpleSuspend() throws Exception { 12 final Simple r = new Simple(); 13 final Continuation c = Continuation.startWith(r); 14 assertTrue(c != null); 15 } 16 17 public void testSimpleTryCatchWithoutException() throws Exception { 18 final SimpleTryCatch r = new SimpleTryCatch(false); 19 Continuation c; 20 21 c = Continuation.startWith(r); 22 assertTrue(c != null); 23 assertTrue(r.a); 24 assertFalse(r.b); 25 assertFalse(r.c); 26 assertFalse(r.d); 27 assertFalse(r.e); 28 assertFalse(r.f); 29 30 c = Continuation.continueWith(c); 31 assertTrue(c != null); 32 assertTrue(r.a); 33 assertTrue(r.b); 34 assertFalse(r.c); 35 assertFalse(r.d); 36 assertTrue(r.e); 37 assertFalse(r.f); 38 39 c = Continuation.continueWith(c); 40 assertTrue(c != null); 41 assertTrue(r.a); 42 assertTrue(r.b); 43 assertFalse(r.c); 44 assertFalse(r.d); 45 assertTrue(r.e); 46 assertTrue(r.f); 47 } 48 49 public void testSimpleTryCatchWithException() throws Exception { 50 final SimpleTryCatch r = new SimpleTryCatch(true); 51 Continuation c; 52 53 c = Continuation.startWith(r); 54 assertTrue(c != null); 55 assertTrue(r.a); 56 assertFalse(r.b); 57 assertFalse(r.c); 58 assertFalse(r.d); 59 assertFalse(r.e); 60 assertFalse(r.f); 61 62 c = Continuation.continueWith(c); 63 assertTrue(c != null); 64 assertTrue(r.a); 65 assertFalse(r.b); 66 assertTrue(r.c); 67 assertFalse(r.d); 68 assertFalse(r.e); 69 assertFalse(r.f); 70 71 c = Continuation.continueWith(c); 72 assertTrue(c != null); 73 assertTrue(r.a); 74 assertTrue(r.b); 75 assertFalse(r.c); 76 assertFalse(r.d); 77 assertTrue(r.e); 78 assertTrue(r.f); 79 } 80 81 public void testSimpleSynchronized() throws Exception { 82 final SimpleSynchronized r = new SimpleSynchronized(); 83 Continuation c; 84 85 c = Continuation.startWith(r); 86 assertTrue(c != null); 87 assertTrue(r.a); 88 assertFalse(r.b); 89 assertFalse(r.c); 90 assertFalse(r.d); 91 assertFalse(r.e); 92 assertFalse(r.f); 93 94 c = Continuation.continueWith(c); 95 assertTrue(c != null); 96 assertTrue(r.a); 97 assertTrue(r.b); 98 assertTrue(r.c); 99 assertFalse(r.d); 100 assertFalse(r.e); 101 assertFalse(r.f); 102 103 c = Continuation.continueWith(c); 104 assertTrue(c != null); 105 assertTrue(r.a); 106 assertTrue(r.b); 107 assertTrue(r.c); 108 assertTrue(r.d); 109 assertTrue(r.e); 110 assertFalse(r.f); 111 112 c = Continuation.continueWith(c); 113 assertTrue(c != null); 114 assertTrue(r.a); 115 assertTrue(r.b); 116 assertTrue(r.c); 117 assertTrue(r.d); 118 assertTrue(r.e); 119 assertTrue(r.f); 120 } 121 }