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
|
/*******************************************************************************
* Copyright (c) 2005, 2012 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 6, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IMacro;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.util.List;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.tests.IntegratedCModelTest;
/**
* IMacroTest - Class for testing IMacro
*
* @author bnicolle
*
*/
public class IMacroTests extends IntegratedCModelTest {
/**
* @returns a test suite named after this class
* containing all its public members named "test*"
*/
public static Test suite() {
TestSuite suite= new TestSuite( IMacroTests.class.getName() );
suite.addTest( new IMacroTests("testGetElementName"));
// TODO Bug# 38740: suite.addTest( new IMacroTest("testGetIdentifierList"));
// TODO Bug# 38740: suite.addTest( new IMacroTest("testGetTokenSequence"));
return suite;
}
/**
* @param name
*/
public IMacroTests(String name) {
super(name);
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
@Override
public String getSourcefileSubdir() {
return "resources/cmodel/";
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
@Override
public String getSourcefileResource() {
return "IMacroTest.h";
}
public void testGetElementName() throws CModelException {
ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ICElement.C_MACRO );
String expectedList[] = new String[] {
"SINGLETON",
"NUMBER",
"PRINT"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getElementName() );
}
}
public void testGetIdentifierList() throws CModelException {
ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ICElement.C_MACRO );
String expectedList[] = new String[] {
"",
"",
"string,msg"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getIdentifierList() );
}
}
public void testGetTokenSequence() throws CModelException {
ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ICElement.C_MACRO );
String expectedList[] = new String[] {
"",
"1",
"printf(string, msg)"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getTokenSequence() );
}
}
}
|