added enum handling to parser; updated comments in test files produced in system test file generation

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@104 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mkarlesky
2009-05-22 21:50:00 +00:00
parent 461f0d3fb9
commit 9d608d61d3
5 changed files with 178 additions and 29 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ class CMockConfig
:mock_prefix => 'Mock',
:plugins => ['cexception', 'ignore'],
:includes => [],
:attributes => ['static', 'inline', 'extern', '__ramfunc', '__irq', '__fiq'],
:attributes => ['static', 'inline', 'extern', 'auto', 'register', '__ramfunc', '__irq', '__fiq'],
:tab => ' ',
:expect_call_count_type => 'unsigned short',
:enforce_strict_ordering => false,
+76 -5
View File
@@ -529,20 +529,25 @@ module CMockFunctionPrototype
if r5
r3 = r5
else
r6 = _nt_type_void_ptr
r6 = _nt_type_enum
if r6
r3 = r6
else
r7 = _nt_type_primitive
r7 = _nt_type_void_ptr
if r7
r3 = r7
else
r8 = _nt_type_custom
r8 = _nt_type_primitive
if r8
r3 = r8
else
self.index = i3
r3 = nil
r9 = _nt_type_custom
if r9
r3 = r9
else
self.index = i3
r3 = nil
end
end
end
end
@@ -695,6 +700,72 @@ module CMockFunctionPrototype
return r0
end
module TypeEnum0
def space
elements[1]
end
def name
elements[2]
end
def space
elements[3]
end
end
def _nt_type_enum
start_index = index
if node_cache[:type_enum].has_key?(index)
cached = node_cache[:type_enum][index]
@index = cached.interval.end if cached
return cached
end
i0, s0 = index, []
if input.index('enum', index) == index
r1 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 4
else
terminal_parse_failure('enum')
r1 = nil
end
s0 << r1
if r1
r2 = _nt_space
s0 << r2
if r2
r3 = _nt_name
s0 << r3
if r3
r4 = _nt_space
s0 << r4
if r4
r6 = _nt_type_const_and_ptr_suffix
if r6
r5 = r6
else
r5 = instantiate_node(SyntaxNode,input, index...index)
end
s0 << r5
end
end
end
end
if s0.last
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(TypeEnum0)
else
self.index = i0
r0 = nil
end
node_cache[:type_enum][start_index] = r0
return r0
end
module TypeVoidPtr0
def space
elements[1]
@@ -52,6 +52,7 @@ grammar CMockFunctionPrototype
const?
( type_struct /
type_union /
type_enum /
type_void_ptr /
type_primitive /
type_custom ) <TypeNode>
@@ -65,6 +66,10 @@ grammar CMockFunctionPrototype
'union' space name space type_const_and_ptr_suffix?
end
rule type_enum
'enum' space name space type_const_and_ptr_suffix?
end
rule type_void_ptr
'void' space type_const_and_ptr_suffix
end
@@ -7,20 +7,30 @@
:types: |
struct THING { int a; int b; };
union JUNK { int a; char b; };
union STARS_AND_STRIPES { int a; char b; };
enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };
:mockable: |
void foo_struct(struct THING*, struct THING);
void foo_union(union JUNK*, union JUNK);
struct THING foobar_struct(void);
union JUNK foobar_union(void);
void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
union STARS_AND_STRIPES foobar_union(void);
void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY foobar_enum(void);
:source:
:header: |
void exercise_struct(struct THING* a, struct THING b);
void exercise_union(union JUNK* a, union JUNK b);
struct THING return_struct(void);
union JUNK return_union(void);
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
union STARS_AND_STRIPES return_union(void);
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY return_enum(void);
:code: |
void exercise_struct(struct THING* a, struct THING b)
@@ -28,21 +38,32 @@
foo_struct(a, b);
}
void exercise_union(union JUNK* a, union JUNK b)
{
foo_union(a, b);
}
struct THING return_struct(void)
{
return foobar_struct();
}
union JUNK return_union(void)
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
{
foo_union(a, b);
}
union STARS_AND_STRIPES return_union(void)
{
return foobar_union();
}
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
{
foo_enum(a, b);
}
enum HOKEY_POKEY return_enum(void)
{
return foobar_enum();
}
:tests:
:common: |
struct THING struct1;
@@ -52,12 +73,15 @@
struct THING struct5;
struct THING struct6;
union JUNK union1;
union JUNK union2;
union JUNK union3;
union JUNK union4;
union JUNK union5;
union JUNK union6;
union STARS_AND_STRIPES union1;
union STARS_AND_STRIPES union2;
union STARS_AND_STRIPES union3;
union STARS_AND_STRIPES union4;
union STARS_AND_STRIPES union5;
union STARS_AND_STRIPES union6;
enum HOKEY_POKEY enum1;
enum HOKEY_POKEY enum2;
void setUp(void)
{
@@ -85,6 +109,9 @@
union4.a = 4;
union5.a = 5;
union6.a = 5;
enum1 = OUT;
enum2 = IN;
}
void tearDown(void) {}
@@ -168,7 +195,7 @@
test()
{
foobar_union_ExpectAndReturn(union5);
TEST_ASSERT_EQUAL_JUNK(union6, return_union());
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
}
- :pass: FALSE
@@ -177,16 +204,62 @@
test()
{
foobar_union_ExpectAndReturn(union4);
TEST_ASSERT_EQUAL_JUNK(union5, return_union());
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
}
- :pass: TRUE
:should: 'successfully pass enum values'
:code: |
test()
{
foo_enum_Expect(OUT, &enum1);
exercise_enum(OUT, &enum1);
}
- :pass: FALSE
:should: 'blow up on bad enum pointer comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(IN, &enum2);
}
- :pass: FALSE
:should: 'blow up on bad enum comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
}
- :pass: TRUE
:should: 'compare returned enums as equal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(OUT, return_enum());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(IN, return_enum());
}
:unity_helper:
:header: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
void AssertEqualJUNKUnion(union JUNK expected, union JUNK actual);
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);
#define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
#define TEST_ASSERT_EQUAL_JUNK(expected, actual) {AssertEqualJUNKUnion(expected, actual);}
#define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}
:code: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
@@ -195,7 +268,7 @@
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
}
void AssertEqualJUNKUnion(union JUNK expected, union JUNK actual)
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
+1 -1
View File
@@ -107,7 +107,7 @@ class SystemTestGenerator
out.puts('')
tests[:units].each_with_index do |test, index|
out.puts('// ' + test[:should])
out.puts('// should ' + test[:should])
out.puts(test[:code].gsub!(/test\(\)/, "void test#{index+1}(void)"))
out.puts('')
end