Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c798cdebc11a1de58c4bf7fd8f8178f9f0f69e64 (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
/*******************************************************************************
 * Copyright (c) 2011 Google, Inc 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:
 *	   Sergey Prigogin (Google) - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.index.tests;

import junit.framework.TestSuite;

import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;

/**
 * Tests for header files included in multiple variants.
 *
 * The first line of each comment section preceding a test contains the name of the file
 * to put the contents of the section to. To request the AST of a file, put an asterisk after
 * the file name.
 */
public class IndexMultiVariantHeaderTest extends IndexBindingResolutionTestBase {

	public IndexMultiVariantHeaderTest() {
		setStrategy(new SinglePDOMTestNamedFilesStrategy(true));
	}

	public static TestSuite suite() {
		return suite(IndexMultiVariantHeaderTest.class);
	}
	
	// test.h
	//	#ifdef func
	//	#undef func
	//	#endif
	//
	//	#define func(x) foo ## x

	// test.c *
	//	#include "test.h"
	//
	//	void func(1)() {}
	//
	//	#undef func
	//	#define func(x) bar ## x
	//
	//	void func(2)() {}
	//
	//	#include "test.h"
	//	void func(3)() {}
	public void testExampleFromBug197989_Comment0() throws Exception {
		IFunction f1 = getBindingFromASTName("func(1)", 7, IFunction.class);
		assertEquals("foo1", f1.getName());
		IFunction f2 = getBindingFromASTName("func(2)", 7, IFunction.class);
		assertEquals("bar2", f2.getName());
		IFunction f3 = getBindingFromASTName("func(3)", 7, IFunction.class);
		assertEquals("foo3", f3.getName());
	}

	// stddef.h
	//	#if !defined(_STDDEF_H) || defined(__need_NULL)
	//
	//	#if !defined(__need_NULL)
	//	#define _STDDEF_H
	//	#endif /* !defined(__need_NULL) */
	//
	//	#if defined(_STDDEF_H) || defined(__need_NULL)
	//	#define NULL 0
	//	#endif /* defined(_STDDEF_H) || defined(__need_NULL)  */
	//	#undef __need_NULL
	//
	//	#if defined(_STDDEF_H)
	//	typedef unsigned int size_t;
	//	#endif /* defined(_STDDEF_H) */
	//
	//	#endif /* !defined(_STDDEF_H) || defined(__need_NULL) */

	// a.h
	//  #ifndef A_H_
	//  #define A_H_
	//	#include "stddef.h"
	//	#endif /* A_H_ */

	// a.cpp *
	//	#define __need_NULL
	//	#include "stddef.h"
	//	void f1(char* p) {}
	//	void test() {
	//	  f1(NULL);
	//	}

	// b.cpp
	//	#include "stddef.h"
	//	#include "a.h"

	// c.cpp *
	//	#include "a.h"
	//	void f2(char* p, size_t t) {}
	//	void test() {
	//	  f2(NULL, 1);
	//	}
	public void testExampleFromBug197989_Comment73() throws Exception {
		getBindingFromASTName("f1(NULL)", 2, ICPPFunction.class);
		getBindingFromASTName("f2(NULL, 1)", 2, ICPPFunction.class);
	}

	// a.h
	//	external int X;

	// b.h
	//	#define X y
	//	#include "a.h"
	//	#undef X
	//	#define X z
	//	#include "a.h"

	// a.cpp *
	//	#define X x
	//	#include "a.h"
	//  static void test() {
	//	  x = 0;
	//	}

	// b.cpp *
	//	#include "b.h"
	//  static void test() {
	//	  y = 0;
	//	  z = 0;
	//	}
	public void _testSignificantMacroDetection() throws Exception {
		// TODO(sprigogin): For this test to work REPORT_SIGNIFICANT_MACROS flag
		// should be passed to CPreprocessor.expandMacro method. See
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=197989#c92 for details.
		getBindingFromASTName("x = 0", 1, ICPPVariable.class);
		getBindingFromASTName("y = 0", 1, ICPPVariable.class);
		getBindingFromASTName("z = 0", 1, ICPPVariable.class);
	}
}

Back to the top