aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/Target01.java
blob: ca521d0f925f756ed42f5157d228a3bd0cd32caf (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*******************************************************************************
 * Copyright (c) 2009, 2013 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:
 *    Marc R. Hoffmann - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.core.test.validation.targets;

import static org.jacoco.core.test.validation.targets.Stubs.f;
import static org.jacoco.core.test.validation.targets.Stubs.i2;
import static org.jacoco.core.test.validation.targets.Stubs.nop;
import static org.jacoco.core.test.validation.targets.Stubs.t;

import java.util.Collections;

/**
 * This target exercises a set of common Java control structures.
 */
public class Target01 implements Runnable {

	public void run() {

		// 1. Unconditional execution
		nop(); // $line-unconditional$

		// 2. Missed if block
		if (f()) { // $line-iffalse$
			nop(); // $line-missedif$
		} else {
			nop(); // $line-executedelse$
		}

		// 3. Executed if block
		if (t()) { // $line-iftrue$
			nop(); // $line-executedif$
		} else {
			nop(); // $line-missedelse$
		}

		// 4. Missed while block
		while (f()) { // $line-whilefalse$
			nop(); // $line-missedwhile$
		}

		// 5. Always executed while block
		while (t()) { // $line-whiletrue$
			if (t()) {
				break;
			}
		}

		// 6. Executed while block
		int i = 0;
		while (i++ < 3) { // $line-whiletruefalse$
			nop(); // $line-executedwhile$
		}

		// 7. Executed do while block
		do {
			nop(); // $line-executeddowhile$
		} while (f());

		// 8. Missed for block
		for (nop(); f(); nop()) { // $line-missedforincrementer$
			nop(); // $line-missedfor$
		}

		// 9. Executed for block
		for (int j = 0; j < 1; j++) { // $line-executedforincrementer$
			nop(); // $line-executedfor$
		}

		// 10. Missed for each block
		for (Object o : Collections.emptyList()) { // $line-missedforeachincrementer$
			nop(o); // $line-missedforeach$
		}

		// 11. Executed for each block
		for (Object o : Collections.singleton(new Object())) { // $line-executedforeachincrementer$
			nop(o); // $line-executedforeach$
		}

		// 12. Table switch with hit
		switch (i2()) { // $line-tswitch1$
		case 1:
			nop(); // $line-tswitch1case1$
			break;
		case 2:
			nop(); // $line-tswitch1case2$
			break;
		case 3:
			nop(); // $line-tswitch1case3$
			break;
		default:
			nop(); // $line-tswitch1default$
			break;
		}

		// 13. Continued table switch with hit
		switch (i2()) { // $line-tswitch2$
		case 1:
			nop(); // $line-tswitch2case1$
		case 2:
			nop(); // $line-tswitch2case2$
		case 3:
			nop(); // $line-tswitch2case3$
		default:
			nop(); // $line-tswitch2default$
		}

		// 14. Table switch without hit
		switch (i2()) { // $line-tswitch3$
		case 3:
			nop(); // $line-tswitch3case1$
			break;
		case 4:
			nop(); // $line-tswitch3case2$
			break;
		case 5:
			nop(); // $line-tswitch3case3$
			break;
		default:
			nop(); // $line-tswitch3default$
			break;
		}

		// 15. Lookup switch with hit
		switch (i2()) { // $line-lswitch1$
		case -123:
			nop(); // $line-lswitch1case1$
			break;
		case 2:
			nop(); // $line-lswitch1case2$
			break;
		case 456:
			nop(); // $line-lswitch1case3$
			break;
		default:
			nop(); // $line-lswitch1default$
			break;
		}

		// 16. Continued lookup switch with hit
		switch (i2()) { // $line-lswitch2$
		case -123:
			nop(); // $line-lswitch2case1$
		case 2:
			nop(); // $line-lswitch2case2$
		case 456:
			nop(); // $line-lswitch2case3$
		default:
			nop(); // $line-lswitch2default$
		}

		// 17. Lookup switch without hit
		switch (i2()) { // $line-lswitch3$
		case -123:
			nop(); // $line-lswitch3case1$
			break;
		case 456:
			nop(); // $line-lswitch3case2$
			break;
		case 789:
			nop(); // $line-lswitch3case3$
			break;
		default:
			nop(); // $line-lswitch3default$
			break;
		}

		// 18. Break statement
		while (true) {
			if (t()) {
				break; // $line-executedbreak$
			}
			nop(); // $line-missedafterbreak$
		}

		// 19. Continue statement
		for (int j = 0; j < 1; j++) {
			if (t()) {
				continue; // $line-executedcontinue$
			}
			nop(); // $line-missedaftercontinue$
		}

		runReturn();
		runImplicitReturn();

	}

	private void runReturn() {

		// 20. Return statement
		if (t()) {
			return; // $line-return$
		}
		nop(); // $line-afterreturn$

	}

	private void runImplicitReturn() {

		// 21. Implicit return
	} // $line-implicitreturn$

	public static void main(String[] args) {
		new Target01().run();
	}

}