Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b69f416b1dd877dbad0b89dbf089c50754490894 (plain) (blame)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*******************************************************************************
 * Copyright (c) 2009, 2011 Alena Laskavaia
 * 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:
 *    Alena Laskavaia  - initial API and implementation
 *    Felipe Martinez  - ReturnCheckerTest implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;

import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.ReturnChecker;

/**
 * Test for {@see ReturnCheckerTest} class
 *
 */
public class ReturnCheckerTest extends CheckerTestCase {
	@Override
	public void setUp() throws Exception {
		super.setUp();
		enableProblems(ReturnChecker.RET_NORET_ID,ReturnChecker.RET_ERR_VALUE_ID,ReturnChecker.RET_NO_VALUE_ID);
	}
	//	dummy() {
	//	  return; // error here on line 2
	//	}
	public void testDummyFunction() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors(); // because return type if not defined, usually people don't care
	}

	//	void void_function(void) {
	//	  return; // no error here
	//	}
	public void testVoidFunction() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

	//	int integer_return_function(void) {
	//	  if (global) {
	//		if (global == 100) {
	//			return; // error here on line 4
	//		}
	//	  }
	//	}
	public void testBasicTypeFunction() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(4);
	}

	//
	//	struct My_Struct {
	//	int a;
	//	};
	//
	//	 struct My_Struct struct_return_function(void) {
	//	return; // error here on line 6
	//	}
	public void testUserDefinedFunction() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(6);
	}

	//	 typedef unsigned int uint8_t;
	//
	//	uint8_t return_typedef(void) {
	//	return; // error here on line 4
	//	}
	public void testTypedefReturnFunction() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(4);
	}

	//	typedef unsigned int uint8_t;
	//
	//	uint8_t (*return_fp_no_typedef(void))(void)
	//	{
	//			return; // error here on line 5
	//	}
	public void testFunctionPointerReturnFunction() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(5);
	}

	//	void test() {
	//		  class A {
	//		   public:
	//		    void m() {
	//		      return; // should not be an error here
	//		    }
	//		  };
	//		}
	public void testInnerFunction_Bug315525() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}

	//	void test() {
	//		  class A {
	//		   public:
	//		    int m() {
	//		      return; // should be an error here
	//		    }
	//		  };
	//		}
	public void testInnerFunction_Bug316154() {
		loadCodeAndRunCpp(getAboveComment());
		checkErrorLine(5);
	}

	//	class c {
	//		c() {
	//			return 0;
	//		}
	//
	//		~c() {
	//			return;
	//		}
	//	};
	public void testContructorRetValue() {
		loadCodeAndRunCpp(getAboveComment());
		checkErrorLine(3, ReturnChecker.RET_ERR_VALUE_ID);
	}

	//	class c {
	//		c() {
	//			return;
	//		}
	//
	//		~c() {
	//			return;
	//		}
	//	};
	public void testContructor_Bug323602() {
		IProblemPreference macro = getPreference(ReturnChecker.RET_NO_VALUE_ID, ReturnChecker.PARAM_IMPLICIT);
		macro.setValue(Boolean.TRUE);
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}

	//	void f()
	//	{
	//	    [](int r){return r;}(5);
	//	}
	public void testLambda_Bug332285() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}
//	void f()
//	{
//	    if ([](int r){return r == 0;}(0))
//	        ;
//	}
	public void testLambda2_Bug332285() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}

	//	void g()
	//	{
	//		int r;
	//	    ({return r;});
	//	}
	public void testGccExtensions() {
		loadCodeAndRunCpp(getAboveComment());
		checkErrorLine(4);
	}

	//	auto f() -> void
	//	{
	//	}
	public void testVoidLateSpecifiedReturnType_Bug337677() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}

	//	auto f() -> void*
	//	{
	//	}
	public void testVoidPointerLateSpecifiedReturnType_Bug337677() {
		loadCodeAndRunCpp(getAboveComment());
		checkErrorLine(1);
	}

//	int f()
//	{
//	    if (g())
//	        h();
//	    else
//	        return 0;
//	}
	public void testBranches_Bug342906() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(1);
	}

//	int f()
//	{
//	    switch (g()) {
//	      case 1: h(); break;
//	      case 2:
//	        return 0;
//	}
	public void testSwitch() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(1);
	}

	//int bar(int foo)
	//{
	//    if(foo)
	//        return 0;
	//    else
	//        return 0;
	//}
	public void testBranches_Bug343767() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}
//	int f()
//	{
//	    switch (g()) {
//	      case 1: return 1;
//	      case 2:
//	        return 0;
//	}
	public void testBranchesSwitch_Bug343767() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}
	//int bar(int foo)
	//{
	//    if(foo)
	//        return 0;
	//    else
	//        if (g()) return 0;
	//        else return 1;
	//}
	public void testBranches2_Bug343767() {
		loadCodeAndRunCpp(getAboveComment());
		checkNoErrors();
	}
	//int bar(int foo)
	//{
	//    while(foo) {
	//        return 0;
	//    }
	//}
	public void testWhile() {
		loadCodeAndRunCpp(getAboveComment());
		checkErrorLine(1);
	}

	//	int
	//	fp_goto(int a)
	//	{
	//	if (a) {
	//	goto end;
	//	}
	//	end:
	//	return (a);
	//	}
	public void testGoto_Bug346559() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

}

Back to the top