Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4ed70d6dbb5a0e0e38db960749ecb6953779e042 (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
/*******************************************************************************
 * Copyright (c) 2015 Mentor Graphics Corporation.
 * 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:
 *     Mohamed Azab (Mentor Graphics) - Initial implementation.
 *******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;

public class CPPParameterGuessingTests extends AbstractContentAssistTest {
	private static final String HEADER_FILE_NAME = "PGTest.h";
	private static final String SOURCE_FILE_NAME = "PGTest.cpp";

	//	{PGTest.h}
	//	class aClass {
	//	public:
	//		int aField;
	//		void aMethod(char c);
	//		void aMethod(char c, int x);
	//	};
	//
	//	class bClass : aClass {
	//	};
	//
	//	void overload(int x, aClass a);
	//	void overload(int x, aClass* aPtr);
	//	int piab(aClass a, bClass b);
	//	template<class T>void tFunc(T x, T y);

	public CPPParameterGuessingTests(String name) {
		super(name, true);
	}

	public static Test suite() {
		return BaseTestCase.suite(CPPParameterGuessingTests.class, "_");
	}

	@Override
	protected IFile setUpProjectContent(IProject project) throws Exception {
		String headerContent = readTaggedComment(HEADER_FILE_NAME);
		StringBuilder sourceContent = getContentsForTest(1)[0];
		sourceContent.insert(0, "#include \"" + HEADER_FILE_NAME + "\"\n");
		assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
		return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
	}

	protected void assertParametersGuesses(Map<String, String[][]> expected)
			throws Exception {
		assertContentAssistResults(getBuffer().length() - 1, 0, expected, true,
				false, false, CompareType.REPLACEMENT);
	}

	//	void foo(){
	//		aClass* aTypePtr;
	//		bClass bTypeObj;
	//		piab(
	public void testIndirectTypes() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("piab(a, b)", new String[][] { { "*aTypePtr", "bTypeObj" },
				{ "bTypeObj" } });
		assertParametersGuesses(resultsMap);
	}

	//	void foo(){
	//		int intVal;
	//		aClass aTypeObj;
	//		overload(
	public void testOverloadedFunction() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("overload(x, a)", new String[][] { { "intVal" }, { "aTypeObj" } });
		resultsMap.put("overload(x, aPtr)",
				new String[][] { { "intVal" }, { "&aTypeObj" } });
		assertParametersGuesses(resultsMap);
	}

	//	void foo(){
	//		aClass aTypeObj;
	//		tFunc<aClass> (
	public void testTemplateFunction() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("tFunc<aClass> (x, y)", new String[][] { { "aTypeObj" }, { "bTypeObj" } });
		assertParametersGuesses(resultsMap);
	}

	//	struct container {
	//		aClass* aTypePtr;
	//	};
	//
	//	void foo(){
	//		char charX, charY, charZ;
	//		container containerObj;
	//		containerObj.aTypePtr = new aClass();
	//		containerObj.aTypePtr->
	public void testOverloadedMethod() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("aMethod(c)", new String[][] { { "charX", "charY", "charZ" } });
		resultsMap.put("aMethod(c, x)", new String[][] { { "charX", "charY", "charZ" },
				{ "charX", "charY", "charZ" } });
		assertParametersGuesses(resultsMap);
	}

	//	void testParameterNameMatching(int lngName, int shrt);
	//
	//	void foo() {
	//		int lng;
	//		int shrtNameMatch;
	//		testParameter
	public void testParameterNameMatching() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("testParameterNameMatching(lngName, shrt)", new String[][] {
				{ "lng", "shrtNameMatch" }, { "lng", "shrtNameMatch" } });
		assertParametersGuesses(resultsMap);
	}

	//	class cClass : bClass {
	//	public:
	//		cClass(int inCall) {
	//			char charX, charY;
	//			aClass::
	public void testInsideConstructor() throws Exception {
		Map<String, String[][]> resultsMap = new HashMap<>();
		resultsMap.put("aMethod(c)", new String[][] { { "charX", "charY", "inCall" } });
		resultsMap.put("aMethod(c, x)", new String[][] {
				{ "charX", "charY", "inCall"}, { "charX", "charY", "inCall" } });
		assertParametersGuesses(resultsMap);
	}
}

Back to the top