mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-27 04:27:26 +00:00
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:
@@ -913,6 +913,13 @@ module CMockFunctionPrototype
|
||||
end
|
||||
|
||||
module TypePrimitive2
|
||||
def space
|
||||
elements[1]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module TypePrimitive3
|
||||
def space
|
||||
elements[2]
|
||||
end
|
||||
@@ -1007,68 +1014,102 @@ module CMockFunctionPrototype
|
||||
if r8
|
||||
r7 = r8
|
||||
else
|
||||
i12, s12 = 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
|
||||
else
|
||||
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
|
||||
end
|
||||
if r12
|
||||
r7 = r12
|
||||
else
|
||||
if input.index('int', index) == index
|
||||
r13 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
||||
@index += 3
|
||||
if input.index('long', index) == index
|
||||
r16 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
||||
@index += 4
|
||||
else
|
||||
terminal_parse_failure('int')
|
||||
r13 = nil
|
||||
terminal_parse_failure('long')
|
||||
r16 = nil
|
||||
end
|
||||
if r13
|
||||
r7 = r13
|
||||
if r16
|
||||
r7 = r16
|
||||
else
|
||||
if input.index('short', index) == index
|
||||
r14 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
||||
@index += 5
|
||||
if input.index('int', index) == index
|
||||
r17 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
||||
@index += 3
|
||||
else
|
||||
terminal_parse_failure('short')
|
||||
r14 = nil
|
||||
terminal_parse_failure('int')
|
||||
r17 = nil
|
||||
end
|
||||
if r14
|
||||
r7 = r14
|
||||
if r17
|
||||
r7 = r17
|
||||
else
|
||||
if input.index('char', index) == index
|
||||
r15 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
||||
@index += 4
|
||||
if input.index('short', index) == index
|
||||
r18 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
||||
@index += 5
|
||||
else
|
||||
terminal_parse_failure('char')
|
||||
r15 = nil
|
||||
terminal_parse_failure('short')
|
||||
r18 = nil
|
||||
end
|
||||
if r15
|
||||
r7 = r15
|
||||
if r18
|
||||
r7 = r18
|
||||
else
|
||||
if input.index('float', index) == index
|
||||
r16 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
||||
@index += 5
|
||||
if input.index('char', index) == index
|
||||
r19 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
||||
@index += 4
|
||||
else
|
||||
terminal_parse_failure('float')
|
||||
r16 = nil
|
||||
terminal_parse_failure('char')
|
||||
r19 = nil
|
||||
end
|
||||
if r16
|
||||
r7 = r16
|
||||
if r19
|
||||
r7 = r19
|
||||
else
|
||||
if input.index('double', index) == index
|
||||
r17 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
||||
@index += 6
|
||||
if input.index('float', index) == index
|
||||
r20 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
||||
@index += 5
|
||||
else
|
||||
terminal_parse_failure('double')
|
||||
r17 = nil
|
||||
terminal_parse_failure('float')
|
||||
r20 = nil
|
||||
end
|
||||
if r17
|
||||
r7 = r17
|
||||
if r20
|
||||
r7 = r20
|
||||
else
|
||||
self.index = i7
|
||||
r7 = nil
|
||||
if input.index('double', index) == index
|
||||
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
|
||||
@@ -1078,22 +1119,22 @@ module CMockFunctionPrototype
|
||||
end
|
||||
s0 << r7
|
||||
if r7
|
||||
r18 = _nt_space
|
||||
s0 << r18
|
||||
if r18
|
||||
r20 = _nt_type_const_and_ptr_suffix
|
||||
if r20
|
||||
r19 = r20
|
||||
r22 = _nt_space
|
||||
s0 << r22
|
||||
if r22
|
||||
r24 = _nt_type_const_and_ptr_suffix
|
||||
if r24
|
||||
r23 = r24
|
||||
else
|
||||
r19 = instantiate_node(SyntaxNode,input, index...index)
|
||||
r23 = instantiate_node(SyntaxNode,input, index...index)
|
||||
end
|
||||
s0 << r19
|
||||
s0 << r23
|
||||
end
|
||||
end
|
||||
end
|
||||
if s0.last
|
||||
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
||||
r0.extend(TypePrimitive2)
|
||||
r0.extend(TypePrimitive3)
|
||||
else
|
||||
self.index = i0
|
||||
r0 = nil
|
||||
|
||||
@@ -88,7 +88,7 @@ grammar CMockFunctionPrototype
|
||||
# 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
|
||||
(('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?
|
||||
end
|
||||
|
||||
|
||||
+14
-11
@@ -13,7 +13,7 @@
|
||||
} POINT_T;
|
||||
|
||||
: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;
|
||||
|
||||
U16 *ptr_return1(int a);
|
||||
@@ -23,7 +23,8 @@
|
||||
void var_args1(int a, ...);
|
||||
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
|
||||
crazy_multiline(
|
||||
@@ -35,7 +36,7 @@
|
||||
unsigned int **ptr_ptr_return3(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:
|
||||
:header: |
|
||||
@@ -64,7 +65,8 @@
|
||||
|
||||
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)
|
||||
@@ -93,7 +95,7 @@
|
||||
extern int A, B, C;
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'just do cursory return value check - compilation was the important part'
|
||||
:should: 'execute simple pointer return value check'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -105,7 +107,7 @@
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'just do cursory var arg check - compilation was the important part'
|
||||
:should: 'ignore var args in expect prototype generation'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -115,16 +117,17 @@
|
||||
}
|
||||
|
||||
- :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: |
|
||||
test()
|
||||
{
|
||||
arg_list_Expect(&A, &B, &C);
|
||||
void_type_craziness1_Expect(&A, &B, &C);
|
||||
void_type_craziness2_Expect();
|
||||
exercise_arglist_pointers();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'just do cursory return value check - compilation was the important part'
|
||||
:should: 'successfully mock crazy multline function prototypes'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -133,7 +136,7 @@
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'just do cursory value check - compilation was the important part'
|
||||
:should: 'mock double pointers just fine'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -145,7 +148,7 @@
|
||||
}
|
||||
|
||||
- :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: |
|
||||
test()
|
||||
{
|
||||
@@ -131,12 +131,13 @@ class CMockFunctionPrototypeParserTest < Test::Unit::TestCase
|
||||
parsed.get_arguments)
|
||||
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)")
|
||||
assert_equal('signed char* abc, const unsigned long int xyz_123, unsigned int const abc_123', parsed.get_argument_list)
|
||||
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, long long arm_of_the_law', parsed.get_argument_list)
|
||||
assert_equal([
|
||||
{:type => 'signed char*', :name => 'abc'},
|
||||
{: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)
|
||||
assert_nil(parsed.get_var_arg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user