41
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* JUnit tests for function parameters parsing
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
import static org.junit.Assert.assertTrue;
|
|
21 |
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import org.junit.Assert;
|
|
24 |
import org.junit.Test;
|
|
25 |
import com.nokia.tracecompiler.source.*;
|
|
26 |
import com.nokia.tracecompiler.document.*;
|
|
27 |
|
|
28 |
public class ParseFunctionParametersTest {
|
|
29 |
|
|
30 |
/**
|
|
31 |
* SourceDocumentFactory
|
|
32 |
*/
|
|
33 |
SourceDocumentFactory iFactory = null;
|
|
34 |
|
|
35 |
public static void main(String[] args) {
|
|
36 |
org.junit.runner.JUnitCore.main(ParseFunctionParametersTest.class
|
|
37 |
.getName());
|
|
38 |
}
|
|
39 |
|
|
40 |
/**
|
|
41 |
* jUnit test to test function parameter parsing
|
|
42 |
*/
|
|
43 |
@Test
|
|
44 |
public void testFunctionParameterParsing() {
|
|
45 |
|
|
46 |
FileDocumentMonitor monitor = new FileDocumentMonitor();
|
|
47 |
iFactory = monitor.getFactory();
|
|
48 |
|
|
49 |
ArrayList<String> expectedParameterNames = new ArrayList<String>();
|
|
50 |
ArrayList<String> expectedParameterTypes = new ArrayList<String>();
|
|
51 |
String functionHeader;
|
|
52 |
|
|
53 |
// Function header 1
|
|
54 |
|
|
55 |
// First expected parameter
|
|
56 |
expectedParameterNames.add("aLenght"); //$NON-NLS-1$
|
|
57 |
expectedParameterTypes.add("TUint32"); //$NON-NLS-1$
|
|
58 |
|
|
59 |
// Second expected parameter
|
|
60 |
expectedParameterNames.add("aWidth"); //$NON-NLS-1$
|
|
61 |
expectedParameterTypes.add("TUint16"); //$NON-NLS-1$
|
|
62 |
|
|
63 |
// Third expected parameter
|
|
64 |
expectedParameterNames.add("aDelay"); //$NON-NLS-1$
|
|
65 |
expectedParameterTypes.add("TUint32"); //$NON-NLS-1$
|
|
66 |
|
|
67 |
// construct the function header
|
|
68 |
functionHeader = "DHelloWorld::DHelloWorld(TUint32 aLenght, TUint16 aWidth, TUint32 aDelay)\n" //$NON-NLS-1$
|
|
69 |
+ "{"; //$NON-NLS-1$
|
|
70 |
|
|
71 |
System.out.println("Execute test to function header 1"); //$NON-NLS-1$
|
|
72 |
executeTest(expectedParameterNames, expectedParameterTypes,
|
|
73 |
functionHeader);
|
|
74 |
|
|
75 |
// Function header 2
|
|
76 |
|
|
77 |
// Clear expected names and types arrays
|
|
78 |
expectedParameterNames.clear();
|
|
79 |
expectedParameterTypes.clear();
|
|
80 |
|
|
81 |
// construct the function header
|
|
82 |
functionHeader = "EXPORT_C DMessageHandler::DMessageHandler()\n" //$NON-NLS-1$
|
|
83 |
+ ": iWriter( NULL )\n" //$NON-NLS-1$
|
|
84 |
+ ", iSettings( NULL )\n" //$NON-NLS-1$
|
|
85 |
+ "{"; //$NON-NLS-1$
|
|
86 |
|
|
87 |
System.out.println("Execute test to function header 2"); //$NON-NLS-1$
|
|
88 |
executeTest(expectedParameterNames, expectedParameterTypes,
|
|
89 |
functionHeader);
|
|
90 |
|
|
91 |
// Test headers those caused defects in TraceCompiler version 2.1.0 and
|
|
92 |
// 2.1.1
|
|
93 |
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
94 |
// x
|
|
95 |
|
|
96 |
System.out
|
|
97 |
.println("Execute tests to function headers those caused defects in TraceCompiler version 2.1.0 and 2.1.1"); //$NON-NLS-1$
|
|
98 |
|
|
99 |
// Clear expected names and types arrays
|
|
100 |
expectedParameterNames.clear();
|
|
101 |
expectedParameterTypes.clear();
|
|
102 |
|
|
103 |
// First expected parameter
|
|
104 |
expectedParameterNames.add("aObserver"); //$NON-NLS-1$
|
|
105 |
expectedParameterTypes.add("MModemLcsServerObserver"); //$NON-NLS-1$
|
|
106 |
|
|
107 |
// Second expected parameter
|
|
108 |
expectedParameterNames.add("aIsiMsgObserver"); //$NON-NLS-1$
|
|
109 |
expectedParameterTypes.add("MModemLcsIsiMsgObserver"); //$NON-NLS-1$
|
|
110 |
|
|
111 |
// construct the function header
|
|
112 |
functionHeader = "Cmodemlcsserverrrc::Cmodemlcsserverrrc(MModemLcsServerObserver *aObserver, MModemLcsIsiMsgObserver* aIsiMsgObserver):\n" //$NON-NLS-1$
|
|
113 |
+ " CActive(EPriorityStandard) // Standard priority\n" //$NON-NLS-1$
|
|
114 |
+ "{"; //$NON-NLS-1$
|
|
115 |
|
|
116 |
executeTest(expectedParameterNames, expectedParameterTypes,
|
|
117 |
functionHeader);
|
|
118 |
|
|
119 |
// Clear expected names and types arrays
|
|
120 |
expectedParameterNames.clear();
|
|
121 |
expectedParameterTypes.clear();
|
|
122 |
|
|
123 |
// First expected parameter
|
|
124 |
expectedParameterNames.add("aDriver"); //$NON-NLS-1$
|
|
125 |
expectedParameterTypes.add("RMeDriver"); //$NON-NLS-1$
|
|
126 |
|
|
127 |
// Second expected parameter
|
|
128 |
expectedParameterNames.add("aMaxMsgLength"); //$NON-NLS-1$
|
|
129 |
expectedParameterTypes.add("TUint16"); //$NON-NLS-1$
|
|
130 |
|
|
131 |
// construct the function header
|
|
132 |
functionHeader = "CNpeSendData::CNpeSendData(RMeDriver* aDriver, TUint16 aMaxMsgLength): CActive(EPriorityStandard),\n" //$NON-NLS-1$
|
|
133 |
+ "iDriver(aDriver),\n" //$NON-NLS-1$
|
|
134 |
+ "iMaxMsgLength(aMaxMsgLength)\n" //$NON-NLS-1$
|
|
135 |
+ "{"; //$NON-NLS-1$
|
|
136 |
|
|
137 |
executeTest(expectedParameterNames, expectedParameterTypes,
|
|
138 |
functionHeader);
|
|
139 |
|
|
140 |
// Same expected parameter names and types are used as previous case
|
|
141 |
|
|
142 |
// construct the function header
|
|
143 |
functionHeader = "CNpeReceiveData::CNpeReceiveData(RMeDriver* aDriver, TUint16 aMaxMsgLength): CActive(EPriorityStandard),\n" //$NON-NLS-1$
|
|
144 |
+ "iDriver(aDriver),\n" //$NON-NLS-1$
|
|
145 |
+ "iMaxMsgLength(aMaxMsgLength)\n" //$NON-NLS-1$
|
|
146 |
+ "{"; //$NON-NLS-1$
|
|
147 |
|
|
148 |
executeTest(expectedParameterNames, expectedParameterTypes,
|
|
149 |
functionHeader);
|
|
150 |
// x
|
|
151 |
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
152 |
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Execute test for function header
|
|
157 |
*
|
|
158 |
* @param expectedParameterNames
|
|
159 |
* expected parameter names
|
|
160 |
* @param expectedParameterTypes
|
|
161 |
* expected parameter types
|
|
162 |
* @param functionHeader
|
|
163 |
* function header to be parsed
|
|
164 |
*/
|
|
165 |
private void executeTest(ArrayList<String> expectedParameterNames,
|
|
166 |
ArrayList<String> expectedParameterTypes,
|
|
167 |
final String functionHeader) {
|
|
168 |
|
|
169 |
// first test the parser on an unwrapped string
|
|
170 |
SourceParser sourceParser = new SourceParser(iFactory, iFactory
|
|
171 |
.createDocument(functionHeader));
|
|
172 |
|
|
173 |
// ArrayList<String> actualTokens = new ArrayList<String>();
|
|
174 |
ArrayList<SourceParameter> actualParameters = new ArrayList<SourceParameter>();
|
|
175 |
|
|
176 |
// parse string
|
|
177 |
try {
|
|
178 |
sourceParser.parseFunctionParameters(0, actualParameters);
|
|
179 |
|
|
180 |
} catch (SourceParserException e) {
|
|
181 |
Assert.fail(e.getMessage());
|
|
182 |
}
|
|
183 |
|
|
184 |
checkContents(actualParameters, expectedParameterNames,
|
|
185 |
expectedParameterTypes);
|
|
186 |
}
|
|
187 |
|
|
188 |
/**
|
|
189 |
* Check contents
|
|
190 |
*
|
|
191 |
* @param actualParameters
|
|
192 |
* actual parsed parameters
|
|
193 |
* @param expectedParameterNames
|
|
194 |
* expected parameter names
|
|
195 |
* @param expectedParameterTypes
|
|
196 |
* expected parameter types
|
|
197 |
*/
|
|
198 |
private static void checkContents(
|
|
199 |
final ArrayList<SourceParameter> actualParameters,
|
|
200 |
final ArrayList<String> expectedParameterNames,
|
|
201 |
final ArrayList<String> expectedParameterTypes) {
|
|
202 |
|
|
203 |
// Confirm count of parsed parameters
|
|
204 |
|
|
205 |
System.out.println("Confirm count of parsed parameters:"); //$NON-NLS-1$
|
|
206 |
System.out.println("actualParameters.size() = " + actualParameters.size()); //$NON-NLS-1$
|
|
207 |
System.out.println("expectedParameterNames() = " + expectedParameterNames.size()); //$NON-NLS-1$
|
|
208 |
assertTrue(actualParameters.size() == expectedParameterNames.size());
|
|
209 |
for (int i = 0; i < actualParameters.size(); i++) {
|
|
210 |
|
|
211 |
// Confirm parsed parameter names
|
|
212 |
|
|
213 |
System.out.println("Confirm parsed parameter names:"); //$NON-NLS-1$
|
|
214 |
System.out.println("actualParameters name = " + actualParameters.get(i).getName()); //$NON-NLS-1$
|
|
215 |
System.out.println("expectedParameter name = " + expectedParameterNames.get(i)); //$NON-NLS-1$
|
|
216 |
assertTrue(actualParameters.get(i).getName().compareTo(
|
|
217 |
expectedParameterNames.get(i)) == 0);
|
|
218 |
|
|
219 |
// Confirm parsed parameter types
|
|
220 |
|
|
221 |
System.out.println("Confirm parsed parameter types:"); //$NON-NLS-1$
|
|
222 |
System.out.println("actualParameters type = " + actualParameters.get(i).getType()); //$NON-NLS-1$
|
|
223 |
System.out.println("expectedParameter type = " + expectedParameterTypes.get(i)); //$NON-NLS-1$
|
|
224 |
assertTrue(actualParameters.get(i).getType().compareTo(
|
|
225 |
expectedParameterTypes.get(i)) == 0);
|
|
226 |
}
|
|
227 |
}
|
|
228 |
}
|