blob: a3b57bc695d0068f3415008934b67489eebbb348 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*******************************************************************************
* Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation.java7.targets;
import static org.jacoco.core.test.validation.targets.Stubs.nop;
/**
* This test target is a switch statement with a String.
*/
public class StringSwitchTarget {
private static void covered(Object s) {
switch (String.valueOf(s)) { // assertFullyCovered(0, 4)
case "a":
nop("case a"); // assertFullyCovered()
break;
case "b":
nop("case b"); // assertFullyCovered()
break;
case "\0a":
nop("case \0a"); // assertFullyCovered()
break;
default:
nop("case default"); // assertFullyCovered()
break;
}
}
private static void notCovered(Object s) {
switch (String.valueOf(s)) { // assertNotCovered(4, 0)
case "a":
nop("case a");
break;
case "b":
nop("case b");
break;
case "\0a":
nop("case \0a");
break;
default:
nop("default");
break;
}
}
private static void handwritten(String s) {
int c = -1;
switch (s.hashCode()) { // assertFullyCovered(2, 1)
case 97:
if ("a".equals(s)) { // assertFullyCovered(1, 1)
c = 0;
} else if ("\0a".equals(s)) {
c = 1;
}
break;
case 98:
if ("b".equals(s)) {
c = 2;
}
break;
}
switch (c) { // assertFullyCovered(3, 1)
case 0:
nop("case a"); // assertFullyCovered()
break;
case 1:
nop("case \0a"); // assertNotCovered()
break;
case 2:
nop("case b");
break;
default:
nop("default");
break;
}
}
/**
* In this case javac generates <code>LOOKUPSWITCH</code> for second switch.
*/
private static void lookupswitch(Object s) {
switch (String.valueOf(s)) { // assertNotCovered(3, 0)
case "a":
nop("case a");
break;
case "b":
nop("case b");
break;
default:
nop("default");
break;
}
}
private static void default_is_first(Object s) {
switch (String.valueOf(s)) { // assertFullyCovered(0, 2)
default:
nop("default");
break;
case "a":
nop("case a");
break;
}
}
public static void main(String[] args) {
covered("");
covered("a");
covered("b");
covered("\0a");
handwritten("a");
default_is_first("");
default_is_first("a");
}
}
|