1
/*******************************************************************************
2
* Copyright (c) 2011 Andrew Gvozdev and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Andrew Gvozdev - initial API and implementation
10
* Sergey Prigogin (Google)
11
*******************************************************************************/
12
package org.eclipse.cdt.codan.core.internal.checkers;
14
import java.io.IOException;
16
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
17
import org.eclipse.cdt.codan.internal.checkers.UnusedSymbolInFileScopeChecker;
20
* Test for {@see UnusedSymbolInFileScopeChecker} class
22
public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
24
public void setUp() throws Exception {
27
UnusedSymbolInFileScopeChecker.ER_UNUSED_VARIABLE_DECLARATION_ID,
28
UnusedSymbolInFileScopeChecker.ER_UNUSED_FUNCTION_DECLARATION_ID,
29
UnusedSymbolInFileScopeChecker.ER_UNUSED_STATIC_FUNCTION_ID);
32
////////////////////////////////////////////////////////////////////////////
33
// extern function declarations
34
////////////////////////////////////////////////////////////////////////////
37
// extern int test_efun();
38
public void testExternFunction_Declaration_Unused() throws IOException {
39
loadCodeAndRun(getAboveComment());
48
public void testExternFunction_Declaration_Used() throws IOException {
49
loadCodeAndRun(getAboveComment());
55
public void testExternFunction_Declaration_FollowedByDefinition() throws IOException {
56
loadCodeAndRun(getAboveComment());
60
////////////////////////////////////////////////////////////////////////////
61
// extern function definitions
62
////////////////////////////////////////////////////////////////////////////
64
// void test_fun(void) {}
65
public void testExternFunction_Definition() throws IOException {
66
loadCodeAndRun(getAboveComment());
70
////////////////////////////////////////////////////////////////////////////
71
// Static function declarations
72
////////////////////////////////////////////////////////////////////////////
74
// static void test_fun(void);
75
public void testStaticFunction_Declaration_Unused() throws IOException {
76
loadCodeAndRun(getAboveComment());
80
// static void test_fun(void);
81
// static void test_fun(void) {}
82
public void testStaticFunction_Declaration_FollowedByDefinition() throws IOException {
83
loadCodeAndRun(getAboveComment());
87
// static void test_fun(void);
91
public void testStaticFunction_Declaration_Used() throws IOException {
92
loadCodeAndRun(getAboveComment());
96
////////////////////////////////////////////////////////////////////////////
97
// Static function definitions
98
////////////////////////////////////////////////////////////////////////////
100
// static void test_fun(void) {}
101
public void testStaticFunction_Definition_Unused() throws IOException {
102
loadCodeAndRun(getAboveComment());
106
// static void test_fun(void);
107
// static void test_fun(void) {}
108
public void testStaticFunction_Definition_Unused_WithDeclaration() throws IOException {
109
loadCodeAndRun(getAboveComment());
113
// static void test_fun(void) {}
117
public void testStaticFunction_Definition_Used() throws IOException {
118
loadCodeAndRun(getAboveComment());
125
// static int test_fun(void) {}
126
public void testStaticFunction_Definition_UsedBeforeDefinition() throws IOException {
127
loadCodeAndRun(getAboveComment());
131
// static int test_fun(void) {}
132
// static int test_fun(int) {}
136
public void testStaticFunction_Definition_Signature() throws IOException {
137
loadCodeAndRunCpp(getAboveComment());
141
// static int test_fun(void) {}
145
public void testStaticFunction_Definition_SynonymLocalScope() throws IOException {
146
loadCodeAndRun(getAboveComment());
150
// static int test_fun(void) {}
151
// void fun(int test_fun) {
153
public void testStaticFunction_Definition_SynonymArgs() throws IOException {
154
loadCodeAndRun(getAboveComment());
158
// static int (test_fun) ();
159
public void testStaticFunction_Definition_InParentheses() throws IOException {
160
loadCodeAndRun(getAboveComment());
164
// static int test_fun(int i) {}
165
// int i = test_fun(X);
166
public void testStaticFunction_Definition_UnknownParameterType() throws IOException {
167
loadCodeAndRunCpp(getAboveComment());
171
// static void test_fun(void) {}
172
// void Class::fun() {
175
public void testStaticFunction_Definition_InQualifiedFunction() throws IOException {
176
loadCodeAndRunCpp(getAboveComment());
180
// static int test_fun(X) {}
181
// int i = test_fun(X);
182
public void testStaticFunction_Definition_UnknownArgumentType() throws IOException {
183
loadCodeAndRunCpp(getAboveComment());
187
////////////////////////////////////////////////////////////////////////////
188
// Extern variables declaration
189
////////////////////////////////////////////////////////////////////////////
191
// extern int test_var;
192
public void testExternVariable_Declaration_Unused() throws IOException {
193
loadCodeAndRun(getAboveComment());
197
// extern int test_var;
201
public void testExternVariable_Declaration_Used() throws IOException {
202
loadCodeAndRun(getAboveComment());
208
public void testExternVariable_Declaration_Combined() throws IOException {
209
loadCodeAndRun(getAboveComment());
214
////////////////////////////////////////////////////////////////////////////
215
// Extern variables definition
216
////////////////////////////////////////////////////////////////////////////
220
public void testGlobalVariable_Definition() throws IOException {
221
loadCodeAndRun(getAboveComment());
225
// extern const int test_var=0; // not quite legal but some compilers allow that
226
public void testExternVariable_Definition1() throws IOException {
227
loadCodeAndRun(getAboveComment());
231
// extern const int test_var;
232
// const int test_var = 0;
233
public void testExternVariable_Definition2() throws IOException {
234
loadCodeAndRun(getAboveComment());
238
////////////////////////////////////////////////////////////////////////////
240
////////////////////////////////////////////////////////////////////////////
242
// static int test_var;
243
public void testStaticVariable_Unused() throws IOException {
244
loadCodeAndRun(getAboveComment());
248
// static int (*test_var)(float, char, char);
249
public void testStaticVariable_Unused_FunctionPointer() throws IOException {
250
loadCodeAndRun(getAboveComment());
254
// static int test_var;
256
public void testStaticVariable_Used_GlobalScope() throws IOException {
257
loadCodeAndRun(getAboveComment());
261
// static int test_var;
265
public void testStaticVariable_Used_LocalScope() throws IOException {
266
loadCodeAndRun(getAboveComment());
270
// static int test_var;
271
// void Class::fun() {
274
public void testStaticVariable_Used_InQualifiedFunction() throws IOException {
275
loadCodeAndRunCpp(getAboveComment());
280
// static Class test_var; // constructor is called here
281
public void testStaticVariable_Used_Constructor() throws IOException {
282
loadCodeAndRunCpp(getAboveComment());
286
// static X test_var; // avoid possible false positive, binding checker would complain anyway
287
public void testExternVariable_Declaration_IgnoreUnresolved() throws IOException {
288
loadCodeAndRun(getAboveComment());
292
// static char* test_var="$Id: UnusedSymbolInFileScopeCheckerTest.java,v 1.2 2011/04/29 11:17:42 agvozdev Exp $";
293
public void testExternVariable_Declaration_CvsIdent() throws IOException {
294
loadCodeAndRun(getAboveComment());
298
// static char* test_var="@(#) $Header: /cvsroot/tools/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java,v 1.2 2011/04/29 11:17:42 agvozdev Exp $";
299
public void testExternVariable_Declaration_SccsIdent() throws IOException {
300
loadCodeAndRun(getAboveComment());
304
// static char test_var[]("@(#) $Id: UnusedSymbolInFileScopeCheckerTest.java,v 1.2 2011/04/29 11:17:42 agvozdev Exp $");
305
public void testExternVariable_Declaration_CvsIdentInitializer() throws IOException {
306
loadCodeAndRunCpp(getAboveComment());