Skip to content

Commit 42d182a

Browse files
committed
1. changed the feature name.
2. remove dependency on cdt 3. fix bug for = sizeof 4. leading unknown macro will be part of the return type now.
1 parent 4d0ff31 commit 42d182a

18 files changed

+57
-20
lines changed

org.cpputest.plugin.feature/feature.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<feature
3-
id="org.cpputest.plugin.general.feature"
4-
label="cppUTestFeature"
3+
id="org.cpputest.stubber.feature"
4+
label="C/C++ Stub Mock Generator"
55
version="1.0.0.qualifier"
66
provider-name="odd-e.com">
77

8-
<description url="http://www.example.com/description">
9-
[Enter Feature Description here.]
8+
<description url="https://github.com/terryyin/CppUTestEclipsePlugin/">
9+
The stub/mock generating feature.
1010
</description>
1111

1212
<copyright url="http://www.example.com/copyright">

org.cpputest.plugin.feature/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>1.0.0-SNAPSHOT</version>
1010
</parent>
1111
<groupId>org.cpputest.plugin</groupId>
12-
<artifactId>org.cpputest.plugin.general.feature</artifactId>
12+
<artifactId>org.cpputest.stubber.feature</artifactId>
1313
<version>1.0.0-SNAPSHOT</version>
1414
<packaging>eclipse-feature</packaging>
1515
<build>

org.cpputest.plugin.unittest/src/org/cpputest/parser/impl/test/CppFunctionSignatureReadingTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testParseFunctionWithPriorMacroOnPreviousLine() {
6868
parts.add(CppPart.EndOfFunctionSignature(new Token(")")));
6969
units = getLanguageUnits(parts);
7070
assertEquals(1, units.size());
71-
assertEquals("void foo()", units.get(0).getCode().toString());
71+
assertEquals("EXTRA void foo()", units.get(0).getCode().toString());
7272
}
7373

7474
@Test
@@ -79,7 +79,7 @@ public void testParseFunctionWithPriorMacroOnPreviousLineWhenReturnTypeIsAPointe
7979
parts.add(CppPart.AddToFunctionName(new Token("foo")));
8080
parts.add(CppPart.EndOfFunctionSignature(new Token(")")));
8181
units = getLanguageUnits(parts);
82-
assertEquals("CHAR * foo()", units.get(0).getCode().toString());
82+
assertEquals("EXTRA CHAR * foo()", units.get(0).getCode().toString());
8383
}
8484
@Test
8585
public void testParseFunctionWithPriorMacroOnSameLine() {

org.cpputest.plugin.unittest/src/org/cpputest/parser/impl/test/PotentialLanguagePartsTest.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void testSemicolonInGlobal() {
2929
String[] strs = {";","int"};
3030
List<CppPart> parts = getPotentialParts(getTokens(strs));
3131
assertEquals(2, parts.size());
32-
assertEquals(CppPart.EndOfGlobalStatement(new Token(";")), parts.get(0));
32+
assertEquals(CppPart.EndOfGlobalStatement(), parts.get(0));
3333
assertEquals(CppPart.StartNewFunction(new Token("int")), parts.get(1));
3434
}
3535
@Test
@@ -98,6 +98,16 @@ public void testTypeDefContentShouldBeIgnored() {
9898
assertEquals(2, parts.size());
9999
assertEquals(CppPart.StartNewFunction(new Token("SHOULD_BE_ABILE_TO_SEE")), parts.get(1));
100100
}
101+
102+
@Test
103+
public void testGlobalAssignment() {
104+
String[] strs = {"int", "a","=","b",";"};
105+
List<CppPart> parts = getPotentialParts(getTokens(strs));
106+
assertEquals(CppPart.StartNewFunction(new Token("int")), parts.get(0));
107+
assertEquals(CppPart.AddToFunctionName(new Token("a")), parts.get(1));
108+
assertEquals(CppPart.Assignment(), parts.get(2));
109+
assertEquals(CppPart.EndOfGlobalStatement(), parts.get(3));
110+
}
101111

102112
private Iterable<Token> getTokens(String[] strs) {
103113
List<Token> tokens = new ArrayList<Token>();

org.cpputest.plugin.unittest/src/org/cpputest/parser/impl/test/SignatureBuilderTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testMoveFunctionNameToReturnTypeWhenAddToFunctionNameMoreThanOnce()
2727
.addToFunctionDeclaration("int")
2828
.addToFunctionDeclaration("fun")
2929
.build();
30-
assertEquals("int fun()", signature.getCode().toString());
30+
assertEquals("MACRO int fun()", signature.getCode().toString());
3131
}
3232
@Test
3333
public void testConstReturnType() {
@@ -46,7 +46,7 @@ public void testExtraStuffBeforePointerReturnType() {
4646
.addToFunctionDeclaration("fun")
4747
.build();
4848
assertEquals("fun", signature.getFunctionName());
49-
assertEquals("int * fun()", signature.getCode().toString());
49+
assertEquals("EXTRA int * fun()", signature.getCode().toString());
5050
}
5151

5252
}

org.cpputest.plugin.unittest/src/org/cpputest/parser/test/CppSourceCodeReaderEndToEndTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,12 @@ public void testShouldReturnOneIteratorReadSignatureFromStringWithOneFunction()
2525
assertTrue(it.hasNext());
2626
assertEquals("void fun()", it.next().getCode().toString());
2727
}
28+
@Test
29+
public void testSizeofIsNotAFunction() {
30+
CppSourceCodeReader reader = new CppSourceCodeReader();
31+
Iterable<CppLangFunctionSignature> iterable = reader.signatures("int a = sizeof(b);");
32+
Iterator<CppLangFunctionSignature> it = iterable.iterator();
33+
assertFalse(it.hasNext());
34+
}
2835

2936
}

org.cpputest.plugin/META-INF/MANIFEST.MF

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Bundle-Vendor: odd-e.com
88
Require-Bundle: org.eclipse.ui,
99
org.eclipse.core.runtime,
1010
org.junit,
11-
org.eclipse.cdt;bundle-version="7.0.2",
1211
org.eclipse.core.resources
1312
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
1413
Bundle-ActivationPolicy: lazy

org.cpputest.plugin/src/org/cpputest/parser/impl/CppTokensToPotentialLanguagePartsTranslator.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class CppTokensToPotentialLanguagePartsTranslator{
88
private enum State {
9-
GLOBAL, DEC, NAMESPACE, DEC_TO_IMP, IMP, FUNCTION_NAME, TYPEDEF
9+
GLOBAL, DEC, NAMESPACE, DEC_TO_IMP, IMP, FUNCTION_NAME, TYPEDEF, GLOBAL_ASSIGNMENT
1010
}
1111
public CppTokensToPotentialLanguagePartsTranslator() {
1212
}
@@ -66,6 +66,8 @@ protected CppPart input(Token token) {
6666
return _GLOBAL(token);
6767
case FUNCTION_NAME:
6868
return _GLOBAL(token);
69+
case GLOBAL_ASSIGNMENT:
70+
return _GLOBAL_ASSIGNMENT(token);
6971
case DEC:
7072
return _DEC(token);
7173
case NAMESPACE:
@@ -81,7 +83,11 @@ protected CppPart input(Token token) {
8183
}
8284

8385
private CppPart _GLOBAL(Token token){
84-
if (token.isTypeDef()) {
86+
if (token.isAssignment()) {
87+
set_state(State.GLOBAL_ASSIGNMENT);
88+
return CppPart.Assignment();
89+
}
90+
else if (token.isTypeDef()) {
8591
set_state(State.TYPEDEF);
8692
return CppPart.Typedef();
8793
}
@@ -94,7 +100,7 @@ else if (token.equals("::"))
94100
set_state(State.NAMESPACE);
95101
else if (token.isSemicolon()) {
96102
set_state(State.GLOBAL);
97-
return CppPart.EndOfGlobalStatement(token);
103+
return CppPart.EndOfGlobalStatement();
98104
}
99105
else {
100106
if (get_state() == State.FUNCTION_NAME)
@@ -104,6 +110,13 @@ else if (token.isSemicolon()) {
104110
}
105111
return null;
106112
}
113+
private CppPart _GLOBAL_ASSIGNMENT(Token token) {
114+
if (token.isSemicolon()) {
115+
set_state(State.GLOBAL);
116+
return CppPart.EndOfGlobalStatement();
117+
}
118+
return null;
119+
}
107120
private CppPart _TYPEDEF(Token token) {
108121
if (token.isSemicolon())
109122
set_state(State.GLOBAL);

org.cpputest.plugin/src/org/cpputest/parser/impl/Token.java

+4
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ public boolean isTypeDef() {
9090
return token.equals("typedef");
9191
}
9292

93+
public boolean isAssignment() {
94+
return token.equals("=");
95+
}
96+
9397
}

org.cpputest.plugin/src/org/cpputest/parser/langunit/SignatureBuilder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ private boolean addTokenToCurrentTryOfReturnTyeAndFunctionName(
4848
else if (currentDecidedReturnType.equals("const"))
4949
addToReturnType(partOfFunctionDeclaration);
5050
else if (hasFunctionName) {
51-
return false;
51+
addToReturnType(signature.getFunctionName());
52+
signature.setFunctionName(partOfFunctionDeclaration);
5253
}
5354
else if (partOfFunctionDeclaration.equals("*"))
5455
addToReturnType(partOfFunctionDeclaration);

org.cpputest.plugin/src/org/cpputest/parser/parts/impl/parts/CppPart.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class CppPart {
66
public enum Type {
77
MAYBE_NEW_FUNCTION, END_OF_FUNCTION_SIGNATURE, PART_OF_LONG_FUNCTION_NAME
8-
, MAYBE_PART_OF_FUNCTION_NAME, PARAMETER, END_OF_FUNCTION, TOKEN, END_OF_GLOBAL_STATEMENT, PREPROCESSOR, TYPEDEF}
8+
, MAYBE_PART_OF_FUNCTION_NAME, PARAMETER, END_OF_FUNCTION, TOKEN, END_OF_GLOBAL_STATEMENT, PREPROCESSOR, TYPEDEF, ASSIGNMENT}
99
private Type type;
1010
private final Token token;
1111
private CppPart(Type type, Token token){
@@ -36,13 +36,16 @@ public static CppPart EndOfFunction() {
3636
public static CppPart Token(org.cpputest.parser.impl.Token token2) {
3737
return new CppPart(Type.TOKEN, token2);
3838
}
39-
public static CppPart EndOfGlobalStatement(Token token2) {
40-
return new CppPart(Type.END_OF_GLOBAL_STATEMENT, token2);
39+
public static CppPart EndOfGlobalStatement() {
40+
return new CppPart(Type.END_OF_GLOBAL_STATEMENT, null);
4141
}
4242

4343
public static CppPart Typedef() {
4444
return new CppPart(Type.TYPEDEF, null);
4545
}
46+
public static CppPart Assignment() {
47+
return new CppPart(Type.ASSIGNMENT, null);
48+
}
4649

4750
@Override
4851
public String toString() {

update-site/site.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<site>
3-
<feature url="features/org.cpputest.plugin.general.feature_1.0.0.jar" id="org.cpputest.plugin.general.feature" version="1.0.0">
3+
<feature url="features/org.cpputest.stubber.feature_1.0.0.jar" id="org.cpputest.stubber.feature" version="1.0.0">
44
<category name="CppUTest"/>
55
</feature>
66
<category-def name="CppUTest" label="CppUTest"/>

update-site/target/site.zip

34.5 KB
Binary file not shown.

update-site/target/site/artifacts.jar

10 Bytes
Binary file not shown.

update-site/target/site/content.jar

32 Bytes
Binary file not shown.
Binary file not shown.

update-site/target/site/site.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<site>
3-
<feature url="features/org.cpputest.plugin.general.feature_1.0.0.201207110635.jar" id="org.cpputest.plugin.general.feature" version="1.0.0.201207110635">
3+
<feature url="features/org.cpputest.stubber.feature_1.0.0.201207110824.jar" id="org.cpputest.stubber.feature" version="1.0.0.201207110824">
44
<category name="CppUTest"/>
55
</feature>
66
<category-def name="CppUTest" label="CppUTest"/>

0 commit comments

Comments
 (0)