Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 006a4df48123ce2d5112e4657e4532ba54a36c82 (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
/*******************************************************************************
 * Copyright (c) 2011, 2015 Marc-Andre Laperle and others.
 * 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-Andre Laperle - Initial API and implementation
 *     Sergey Prigogin (Google)
 *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;

import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker;
import org.eclipse.core.resources.IMarker;

public class ProblemBindingCheckerTest extends CheckerTestCase {
	@Override
	public boolean isCpp() {
		return true;
	}

	@Override
	public void setUp() throws Exception {
		super.setUp();
		enableProblems(
				ProblemBindingChecker.ERR_ID_AmbiguousProblem, ProblemBindingChecker.ERR_ID_Candidates,
				ProblemBindingChecker.ERR_ID_CircularReferenceProblem, ProblemBindingChecker.ERR_ID_FieldResolutionProblem,
				ProblemBindingChecker.ERR_ID_FunctionResolutionProblem, ProblemBindingChecker.ERR_ID_InvalidArguments,
				ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem,
				ProblemBindingChecker.ERR_ID_MemberDeclarationNotFoundProblem, ProblemBindingChecker.ERR_ID_MethodResolutionProblem,
				ProblemBindingChecker.ERR_ID_OverloadProblem, ProblemBindingChecker.ERR_ID_RedeclarationProblem,
				ProblemBindingChecker.ERR_ID_RedefinitionProblem, ProblemBindingChecker.ERR_ID_TypeResolutionProblem,
				ProblemBindingChecker.ERR_ID_VariableResolutionProblem);
	}

	// int main () {
	//     struct X {} x;
	//     fun(x.y);
	// }
	public void testFieldInFunctionCall_338683() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
	}

	//	struct A {
	//	  A(int x, int y);
	//	};
	//
	//	void test() {
	//	  A a("hi", 1, 2);
	//	}
	public void testImplicitConstructorCall_404774() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(6, ProblemBindingChecker.ERR_ID_InvalidArguments);
	}

	// int main () {
	//   struct X {} x;
	//   x.b(
	//       x.y(),
	//       x.y(
	//           x.y),
	//       x.y(
	//           x.y(
	//               a,
	//               fun(
	//                   x.b(),
	//                   x.y,
	//                   a.b()))));
	// }
	public void testVariousFieldMethodCombinations_338683() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(4, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(5, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(6, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
		checkErrorLine(7, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(8, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(9, ProblemBindingChecker.ERR_ID_VariableResolutionProblem);
		checkErrorLine(10, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
		checkErrorLine(11, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
		checkErrorLine(12, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
		checkErrorLine(13, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
	}

	// #define MACRO(code) code
	// int main() {
	//   MACRO(foo());
	//   return 0;
	// }
	public void testDontUnderlineWholeMacro_341089() {
		loadCodeAndRun(getAboveComment());
		IMarker marker = checkErrorLine(3, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
		assertFalse(marker.getAttribute(IMarker.MESSAGE, "").contains("MACRO"));  //$NON-NLS-1$//$NON-NLS-2$
	}

	//	auto d = 42_waldo;
	public void testNonexistentUDLOperator_484619() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(1, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
	}

	//	struct R {};
	//	R operator "" _waldo(const char*, unsigned long);  // expects a string literal
	//	auto d = 42_waldo;                                 // passing an integer
	public void testUDLOperatorWithWrongType_484619() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3, ProblemBindingChecker.ERR_ID_InvalidArguments);
	}
}

Back to the top