aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.core.test/src
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2010-12-12 19:31:08 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2010-12-12 19:31:08 +0000
commitafa2a04de6fd179ce54b00181ffe3ef8bf768632 (patch)
treefcc71919310634c0f6f6b00c649ad52c0a7e2d82 /org.jacoco.core.test/src
parentb05afe34a22469edd5aca5ed83301417f0701679 (diff)
downloadplatform_external_jacoco-afa2a04de6fd179ce54b00181ffe3ef8bf768632.tar.gz
platform_external_jacoco-afa2a04de6fd179ce54b00181ffe3ef8bf768632.tar.bz2
platform_external_jacoco-afa2a04de6fd179ce54b00181ffe3ef8bf768632.zip
Track #66: add probes for switch instructions
Diffstat (limited to 'org.jacoco.core.test/src')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/instr/MethodInstrumenterTest.java56
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java10
2 files changed, 66 insertions, 0 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/MethodInstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/MethodInstrumenterTest.java
index 2e2dd7a9..5f036652 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/instr/MethodInstrumenterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/instr/MethodInstrumenterTest.java
@@ -13,6 +13,7 @@ package org.jacoco.core.instr;
import static org.junit.Assert.assertEquals;
+import org.jacoco.core.internal.flow.LabelInfo;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.asm.ClassVisitor;
@@ -213,4 +214,59 @@ public class MethodInstrumenterTest {
assertEquals(expected, actual);
}
+ @Test
+ public void testVisitTableSwitchInsnWithProbes() {
+ final Label L0 = new Label();
+ final Label L1 = new Label();
+ final Label L2 = new Label();
+ LabelInfo.setProbeId(L0, 0);
+ LabelInfo.setProbeId(L1, 1);
+ instrumenter.visitTableSwitchInsnWithProbes(3, 5, L0, new Label[] { L1,
+ L1, L2 });
+
+ expected.visitTableSwitchInsn(3, 4, L0, new Label[] { L1, L1, L2 });
+ expected.visitLabel(L0);
+ expected.visitVarInsn(Opcodes.ALOAD, 1);
+ expected.visitInsn(Opcodes.ICONST_0);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.BASTORE);
+ expected.visitJumpInsn(Opcodes.GOTO, new Label());
+ expected.visitLabel(L1);
+ expected.visitVarInsn(Opcodes.ALOAD, 1);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.BASTORE);
+ expected.visitJumpInsn(Opcodes.GOTO, new Label());
+
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testVisitLookupSwitchInsnWithProbes() {
+ final Label L0 = new Label();
+ final Label L1 = new Label();
+ final Label L2 = new Label();
+ LabelInfo.setProbeId(L0, 0);
+ LabelInfo.setProbeId(L1, 1);
+ instrumenter.visitLookupSwitchInsnWithProbes(L0,
+ new int[] { 10, 20, 30 }, new Label[] { L1, L1, L2 });
+
+ expected.visitLookupSwitchInsn(L0, new int[] { 10, 20, 30 },
+ new Label[] { L1, L1, L2 });
+ expected.visitLabel(L0);
+ expected.visitVarInsn(Opcodes.ALOAD, 1);
+ expected.visitInsn(Opcodes.ICONST_0);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.BASTORE);
+ expected.visitJumpInsn(Opcodes.GOTO, new Label());
+ expected.visitLabel(L1);
+ expected.visitVarInsn(Opcodes.ALOAD, 1);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.ICONST_1);
+ expected.visitInsn(Opcodes.BASTORE);
+ expected.visitJumpInsn(Opcodes.GOTO, new Label());
+
+ assertEquals(expected, actual);
+ }
+
}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java
index 6cbeb815..20bc1dab 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/LabelInfoTest.java
@@ -13,6 +13,8 @@ package org.jacoco.core.internal.flow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
@@ -40,6 +42,7 @@ public class LabelInfoTest {
assertFalse(LabelInfo.isSuccessor(label));
assertFalse(LabelInfo.isDone(label));
assertEquals(LabelInfo.NO_PROBE, LabelInfo.getProbeId(label));
+ assertNull(LabelInfo.getIntermediateLabel(label));
}
@Test
@@ -103,4 +106,11 @@ public class LabelInfoTest {
assertEquals(123, LabelInfo.getProbeId(label));
}
+ @Test
+ public void testIntermediateLabel() {
+ final Label i = new Label();
+ LabelInfo.setIntermediateLabel(label, i);
+ assertSame(i, LabelInfo.getIntermediateLabel(label));
+ }
+
}