added more system tests; refined existing

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@114 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mkarlesky
2009-05-27 18:43:49 +00:00
parent f2786f116a
commit e56e2a4acd
4 changed files with 107 additions and 62 deletions
+88 -47
View File
@@ -913,6 +913,13 @@ module CMockFunctionPrototype
end end
module TypePrimitive2 module TypePrimitive2
def space
elements[1]
end
end
module TypePrimitive3
def space def space
elements[2] elements[2]
end end
@@ -1007,68 +1014,102 @@ module CMockFunctionPrototype
if r8 if r8
r7 = r8 r7 = r8
else else
i12, s12 = index, []
if input.index('long', index) == index if input.index('long', index) == index
r12 = instantiate_node(SyntaxNode,input, index...(index + 4)) r13 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 4 @index += 4
else else
terminal_parse_failure('long') terminal_parse_failure('long')
r13 = nil
end
s12 << r13
if r13
r14 = _nt_space
s12 << r14
if r14
if input.index('long', index) == index
r15 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 4
else
terminal_parse_failure('long')
r15 = nil
end
s12 << r15
end
end
if s12.last
r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
r12.extend(TypePrimitive2)
else
self.index = i12
r12 = nil r12 = nil
end end
if r12 if r12
r7 = r12 r7 = r12
else else
if input.index('int', index) == index if input.index('long', index) == index
r13 = instantiate_node(SyntaxNode,input, index...(index + 3)) r16 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 3 @index += 4
else else
terminal_parse_failure('int') terminal_parse_failure('long')
r13 = nil r16 = nil
end end
if r13 if r16
r7 = r13 r7 = r16
else else
if input.index('short', index) == index if input.index('int', index) == index
r14 = instantiate_node(SyntaxNode,input, index...(index + 5)) r17 = instantiate_node(SyntaxNode,input, index...(index + 3))
@index += 5 @index += 3
else else
terminal_parse_failure('short') terminal_parse_failure('int')
r14 = nil r17 = nil
end end
if r14 if r17
r7 = r14 r7 = r17
else else
if input.index('char', index) == index if input.index('short', index) == index
r15 = instantiate_node(SyntaxNode,input, index...(index + 4)) r18 = instantiate_node(SyntaxNode,input, index...(index + 5))
@index += 4 @index += 5
else else
terminal_parse_failure('char') terminal_parse_failure('short')
r15 = nil r18 = nil
end end
if r15 if r18
r7 = r15 r7 = r18
else else
if input.index('float', index) == index if input.index('char', index) == index
r16 = instantiate_node(SyntaxNode,input, index...(index + 5)) r19 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 5 @index += 4
else else
terminal_parse_failure('float') terminal_parse_failure('char')
r16 = nil r19 = nil
end end
if r16 if r19
r7 = r16 r7 = r19
else else
if input.index('double', index) == index if input.index('float', index) == index
r17 = instantiate_node(SyntaxNode,input, index...(index + 6)) r20 = instantiate_node(SyntaxNode,input, index...(index + 5))
@index += 6 @index += 5
else else
terminal_parse_failure('double') terminal_parse_failure('float')
r17 = nil r20 = nil
end end
if r17 if r20
r7 = r17 r7 = r20
else else
self.index = i7 if input.index('double', index) == index
r7 = nil r21 = instantiate_node(SyntaxNode,input, index...(index + 6))
@index += 6
else
terminal_parse_failure('double')
r21 = nil
end
if r21
r7 = r21
else
self.index = i7
r7 = nil
end
end end
end end
end end
@@ -1078,22 +1119,22 @@ module CMockFunctionPrototype
end end
s0 << r7 s0 << r7
if r7 if r7
r18 = _nt_space r22 = _nt_space
s0 << r18 s0 << r22
if r18 if r22
r20 = _nt_type_const_and_ptr_suffix r24 = _nt_type_const_and_ptr_suffix
if r20 if r24
r19 = r20 r23 = r24
else else
r19 = instantiate_node(SyntaxNode,input, index...index) r23 = instantiate_node(SyntaxNode,input, index...index)
end end
s0 << r19 s0 << r23
end end
end end
end end
if s0.last if s0.last
r0 = instantiate_node(SyntaxNode,input, i0...index, s0) r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(TypePrimitive2) r0.extend(TypePrimitive3)
else else
self.index = i0 self.index = i0
r0 = nil r0 = nil
+1 -1
View File
@@ -88,7 +88,7 @@ grammar CMockFunctionPrototype
# at least one clause has to exist, not all can be '?' optional; # at least one clause has to exist, not all can be '?' optional;
# hence the long and int variations instead of an optional long followed by optional everything else # hence the long and int variations instead of an optional long followed by optional everything else
(('unsigned' / 'signed') space)? (('unsigned' / 'signed') space)?
(('long' space 'int') / 'long' / 'int' / 'short' / 'char' / 'float' / 'double') space (('long' space 'int') / ('long' space 'long') / 'long' / 'int' / 'short' / 'char' / 'float' / 'double') space
type_const_and_ptr_suffix? type_const_and_ptr_suffix?
end end
@@ -13,7 +13,7 @@
} POINT_T; } POINT_T;
:mockable: | :mockable: |
// typedef edge case; must be in mockable.h (simulating preprocessed header) // typedef edge case; must be in mockable.h for test to compile
typedef void VOID_TYPE_CRAZINESS; typedef void VOID_TYPE_CRAZINESS;
U16 *ptr_return1(int a); U16 *ptr_return1(int a);
@@ -23,7 +23,8 @@
void var_args1(int a, ...); void var_args1(int a, ...);
void var_args2(int a, int b, ...); void var_args2(int a, int b, ...);
VOID_TYPE_CRAZINESS arg_list(int * a, int *b, int* c); VOID_TYPE_CRAZINESS void_type_craziness1(int * a, int *b, int* c);
void void_type_craziness2(VOID_TYPE_CRAZINESS);
char char
crazy_multiline( crazy_multiline(
@@ -35,7 +36,7 @@
unsigned int **ptr_ptr_return3(unsigned int **a); unsigned int **ptr_ptr_return3(unsigned int **a);
unsigned int ** ptr_ptr_return4(unsigned int ** a); unsigned int ** ptr_ptr_return4(unsigned int ** a);
unsigned long int incredible_descriptors(const unsigned short a); extern unsigned long int incredible_descriptors(register const unsigned short a);
:source: :source:
:header: | :header: |
@@ -64,7 +65,8 @@
void exercise_arglist_pointers(void) void exercise_arglist_pointers(void)
{ {
arg_list(&A, &B, &C); void_type_craziness1(&A, &B, &C);
void_type_craziness2();
} }
char exercise_multiline_declarations(int a, unsigned int b) char exercise_multiline_declarations(int a, unsigned int b)
@@ -93,7 +95,7 @@
extern int A, B, C; extern int A, B, C;
:units: :units:
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory return value check - compilation was the important part' :should: 'execute simple pointer return value check'
:code: | :code: |
test() test()
{ {
@@ -105,7 +107,7 @@
} }
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory var arg check - compilation was the important part' :should: 'ignore var args in expect prototype generation'
:code: | :code: |
test() test()
{ {
@@ -115,16 +117,17 @@
} }
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory argument list check - compilation was the important part' :should: "not process a typedef'd void as anything other than void"
:code: | :code: |
test() test()
{ {
arg_list_Expect(&A, &B, &C); void_type_craziness1_Expect(&A, &B, &C);
void_type_craziness2_Expect();
exercise_arglist_pointers(); exercise_arglist_pointers();
} }
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory return value check - compilation was the important part' :should: 'successfully mock crazy multline function prototypes'
:code: | :code: |
test() test()
{ {
@@ -133,7 +136,7 @@
} }
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory value check - compilation was the important part' :should: 'mock double pointers just fine'
:code: | :code: |
test() test()
{ {
@@ -145,7 +148,7 @@
} }
- :pass: TRUE - :pass: TRUE
:should: 'just do cursory return value check - compilation was the important part' :should: 'mock prototypes with long lists of return and parameter type descriptors'
:code: | :code: |
test() test()
{ {
@@ -131,12 +131,13 @@ class CMockFunctionPrototypeParserTest < Test::Unit::TestCase
parsed.get_arguments) parsed.get_arguments)
assert_nil(parsed.get_var_arg) assert_nil(parsed.get_var_arg)
parsed = @parser.parse("void foo_bar(signed char * abc, const unsigned long int xyz_123, unsigned int const abc_123)") parsed = @parser.parse("void foo_bar(signed char * abc, const unsigned long int xyz_123, unsigned int const abc_123, long long arm_of_the_law)")
assert_equal('signed char* abc, const unsigned long int xyz_123, unsigned int const abc_123', parsed.get_argument_list) assert_equal('signed char* abc, const unsigned long int xyz_123, unsigned int const abc_123, long long arm_of_the_law', parsed.get_argument_list)
assert_equal([ assert_equal([
{:type => 'signed char*', :name => 'abc'}, {:type => 'signed char*', :name => 'abc'},
{:type => 'const unsigned long int', :name => 'xyz_123'}, {:type => 'const unsigned long int', :name => 'xyz_123'},
{:type => 'unsigned int const', :name => 'abc_123'}], {:type => 'unsigned int const', :name => 'abc_123'},
{:type => 'long long', :name => 'arm_of_the_law'}],
parsed.get_arguments) parsed.get_arguments)
assert_nil(parsed.get_var_arg) assert_nil(parsed.get_var_arg)