mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-23 14:00:33 +00:00
Compare commits
120 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 543c230f33 | |||
| 968d3f6ec4 | |||
| 0c45d26a28 | |||
| 811b85e1b1 | |||
| 759d1826c8 | |||
| 60a1829acf | |||
| 8ba3ed99a1 | |||
| 0af0e20d15 | |||
| 2def6c4f21 | |||
| d403eb88c8 | |||
| 18b2deca85 | |||
| bd91eb4cca | |||
| fe829f2d8a | |||
| 5650b79dcd | |||
| 9908930bc5 | |||
| b256013c5e | |||
| 927ca1bec0 | |||
| e1c6851492 | |||
| e0a61d484e | |||
| 431c5c678a | |||
| 3a07201a3f | |||
| 11dfb9c668 | |||
| 27e89dd05e | |||
| 237c02dade | |||
| 5ee470d7e4 | |||
| 79ee5b8419 | |||
| fba3bc22a2 | |||
| 01536c4a67 | |||
| 7a32429bd2 | |||
| dbb2f4964c | |||
| 2817da62db | |||
| ee3ae84e64 | |||
| 0cdc742538 | |||
| c1b1ff6350 | |||
| 73afa2973b | |||
| db98427231 | |||
| 7615806e34 | |||
| 9a0bf38c76 | |||
| 277dc34fa1 | |||
| 9327cd7af1 | |||
| 71b4ec2088 | |||
| 639d4120d1 | |||
| 16900b4b7f | |||
| 14d57c2e93 | |||
| c787042e6d | |||
| ea71fb0e0e | |||
| 74fa13f6a0 | |||
| bb3e821eb2 | |||
| 4946aaac37 | |||
| cda809765e | |||
| 8f1156dddc | |||
| a210abdd12 | |||
| 10e8cc27eb | |||
| b2e312e434 | |||
| 741b1067a3 | |||
| b37b3cd86b | |||
| abec576fdb | |||
| b90706424a | |||
| 2ff29226e8 | |||
| bc8e20e88d | |||
| c5becef9fd | |||
| d2c5df2f5e | |||
| 0e9f8c54bc | |||
| b76d570d4a | |||
| c23c01266a | |||
| e17728fe4d | |||
| 37be90bd96 | |||
| 533ae7a7b1 | |||
| 582e0f87cf | |||
| 5e9264f993 | |||
| 6ae662f2e8 | |||
| e1f7c35f2e | |||
| b895a4575a | |||
| e17180b2ef | |||
| 23d2341c4c | |||
| 5f2ae0ee0f | |||
| c70cec0b19 | |||
| fbb0828ee0 | |||
| f8281e456d | |||
| 8b4deef12b | |||
| 9e5afe4255 | |||
| 4df532afcc | |||
| 12c74c0349 | |||
| 4c6fe35bbf | |||
| 4ab728b6d3 | |||
| 7761b3fb3f | |||
| 0b6118e410 | |||
| d5dffde17d | |||
| 347dfc181a | |||
| 4a6ee8680c | |||
| f909378a1d | |||
| 035141e2ab | |||
| 5eab75a078 | |||
| 99c2223a1d | |||
| 4b35cb2e43 | |||
| e417f323fc | |||
| af59c531f7 | |||
| a5616dc2df | |||
| 5716454e11 | |||
| 80454dc1f3 | |||
| 2b93dfdd1d | |||
| 727a5cc8a8 | |||
| c243b9a7a7 | |||
| b409ba6a1d | |||
| b2adf60b2f | |||
| cfa46d6440 | |||
| 789c5852b5 | |||
| 99fa519136 | |||
| 0706e8b355 | |||
| 8d16dca722 | |||
| e8c7ad9706 | |||
| 63527a3217 | |||
| 7cc41ddfdd | |||
| 407c2ef3b9 | |||
| 5edf07e87c | |||
| 7c6552bb2f | |||
| ab339721ae | |||
| 732556700d | |||
| c3a95e93be | |||
| 49bc3ebcce |
+5
-5
@@ -1,20 +1,20 @@
|
||||
language: ruby
|
||||
|
||||
os:
|
||||
- osx
|
||||
- linux
|
||||
|
||||
rvm:
|
||||
- "2.2.2"
|
||||
- "2.3"
|
||||
- "2.4"
|
||||
- "2.6"
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
|
||||
- sudo apt-get install --assume-yes --quiet gcc-multilib
|
||||
|
||||
install:
|
||||
- bundle install
|
||||
- gem install rspec
|
||||
- gem install rubocop
|
||||
- gem install rubocop -v 0.57.2
|
||||
|
||||
script:
|
||||
- cd test && rake ci
|
||||
|
||||
@@ -18,6 +18,7 @@ If you plan to help with the development of CMock (or just want to verify that i
|
||||
perform its self tests on your system) then you can enter the test directory and then
|
||||
ask it to test:
|
||||
|
||||
> cd test
|
||||
> rake # Run all CMock self tests
|
||||
|
||||
API Documentation
|
||||
|
||||
+109
-16
@@ -117,11 +117,11 @@ ExpectAnyArgs:
|
||||
This behaves just like the Expects calls, except that it doesn't really
|
||||
care what the arguments are that the mock gets called with. It still counts
|
||||
the number of times the mock is called and it still handles return values
|
||||
if there are some.
|
||||
if there are some. Note that an ExpectAnyArgs call is not generated for
|
||||
functions that have no arguments, because it would act exactly like the existing
|
||||
Expect and ExpectAndReturn calls.
|
||||
|
||||
* `void func(void)` => `void func_ExpectAnyArgs(void)`
|
||||
* `void func(params)` => `void func_ExpectAnyArgs(void)`
|
||||
* `retval func(void)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
|
||||
* `retval func(params)` => `void func_ExpectAnyArgsAndReturn(retval_to_return)`
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ only needs to be called once per test. It will then ignore any further calls to
|
||||
particular mock. The IgnoreAndReturn works similarly, except that it has the added
|
||||
benefit of knowing what to return when that call happens. If the mock is called more
|
||||
times than IgnoreAndReturn was called, it will keep returning the last value without
|
||||
complaint. If it's called less times, it will also ignore that. You SAID you didn't
|
||||
complaint. If it's called fewer times, it will also ignore that. You SAID you didn't
|
||||
care how many times it was called, right?
|
||||
|
||||
* `void func(void)` => `void func_Ignore(void)`
|
||||
@@ -168,9 +168,11 @@ Ignore Arg:
|
||||
Maybe you overall want to use Expect and its similar variations, but you don't care
|
||||
what is passed to a particular argument. This is particularly useful when that argument
|
||||
is a pointer to a value that is supposed to be filled in by the function. You don't want
|
||||
to use ExpectAnyArgs, because you still care about the other arguments. Instead, before
|
||||
any of your Expect calls are made, you can call this function. It tells CMock to ignore
|
||||
a particular argument for the rest of this test, for this mock function.
|
||||
to use ExpectAnyArgs, because you still care about the other arguments. Instead, after
|
||||
an Expect call is made, you can call this function. It tells CMock to ignore
|
||||
a particular argument for the rest of this test, for this mock function. You may call
|
||||
multiple instances of this to ignore multiple arguments after each expectation if
|
||||
desired.
|
||||
|
||||
* `void func(params)` => `void func_IgnoreArg_paramName(void)`
|
||||
|
||||
@@ -194,19 +196,30 @@ Callback:
|
||||
|
||||
If all those other options don't work, and you really need to do something custom, you
|
||||
still have a choice. As soon as you stub a callback in a test, it will call the callback
|
||||
whenever the mock is encountered and return the retval returned from the callback (if any)
|
||||
instead of performing the usual expect checks. It can be configured to check the arguments
|
||||
first (like expects) or just jump directly to the callback.
|
||||
whenever the mock is encountered and return the retval returned from the callback (if any).
|
||||
|
||||
* `void func(void)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
|
||||
* `void func(void)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
|
||||
where `CMOCK_func_CALLBACK` looks like: `void func(int NumCalls)`
|
||||
* `void func(params)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
|
||||
* `void func(params)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
|
||||
where `CMOCK_func_CALLBACK` looks like: `void func(params, int NumCalls)`
|
||||
* `retval func(void)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
|
||||
* `retval func(void)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
|
||||
where `CMOCK_func_CALLBACK` looks like: `retval func(int NumCalls)`
|
||||
* `retval func(params)` => `void func_StubWithCallback(CMOCK_func_CALLBACK callback)`
|
||||
* `retval func(params)` => `void func_[AddCallback,Stub](CMOCK_func_CALLBACK callback)`
|
||||
where `CMOCK_func_CALLBACK` looks like: `retval func(params, int NumCalls)`
|
||||
|
||||
You can choose from two options:
|
||||
|
||||
* `func_AddCallback` tells the mock to check its arguments and calling
|
||||
order (based on any Expects you've set up) before calling the callback.
|
||||
* `func_Stub` tells the mock to skip all the normal checks and jump directly
|
||||
to the callback instead. In this case, you are replacing the normal mock calls
|
||||
with your own custom stub function.
|
||||
|
||||
There is also an older name, `func_StubWithCallback`, which is just an alias
|
||||
for either `func_AddCallback` or `func_Stub` depending on setting of the
|
||||
`:callback_after_arg_check` toggle. This is deprecated and we recommend using
|
||||
the two options above.
|
||||
|
||||
|
||||
Cexception:
|
||||
-----------
|
||||
@@ -479,6 +492,18 @@ from the defaults. We've tried to specify what the defaults are below.
|
||||
* 'float': 'FLOAT'
|
||||
* 'double': 'FLOAT'
|
||||
|
||||
* `:treat_as_array`:
|
||||
A specialized sort of `:treat_as` to be used when you've created a
|
||||
typedef of an array type, such as `typedef int TenIntegers[10];`. This
|
||||
is a hash of typedef name to element type. For example:
|
||||
|
||||
{ "TenIntegers" => "int",
|
||||
"ArrayOfFloat" => "float" }
|
||||
|
||||
Telling CMock about these typedefs allows it to be more intelligent
|
||||
about parameters of such types, so that you can use features like
|
||||
ExpectWithArray and ReturnArrayThruPtr with them.
|
||||
|
||||
* `:treat_as_void`:
|
||||
We've seen "fun" legacy systems typedef 'void' with a custom type,
|
||||
like MY_VOID. Add any instances of those to this list to help CMock
|
||||
@@ -493,6 +518,14 @@ from the defaults. We've tried to specify what the defaults are below.
|
||||
* `:include` will mock externed functions
|
||||
* `:exclude` will ignore externed functions (default).
|
||||
|
||||
* `:treat_inlines`:
|
||||
This specifies how you want CMock to handle functions that have been
|
||||
marked as inline in the header file. Should it mock them?
|
||||
|
||||
* `:include` will mock inlined functions
|
||||
* `:exclude` will ignore inlined functions (default).
|
||||
|
||||
|
||||
* `:unity_helper_path`:
|
||||
If you have created a header with your own extensions to unity to
|
||||
handle your own types, you can set this argument to that path. CMock
|
||||
@@ -541,6 +574,53 @@ from the defaults. We've tried to specify what the defaults are below.
|
||||
|
||||
* default: :smart
|
||||
|
||||
* `:array_size_type`:
|
||||
* `:array_size_name`:
|
||||
When the `:array` plugin is disabled, these options do nothing.
|
||||
|
||||
When the `:array` plugin is enabled, these options allow CMock to recognize
|
||||
functions with parameters that might refer to an array, like the following,
|
||||
and treat them more intelligently:
|
||||
|
||||
* `void GoBananas(Banana * bananas, int num_bananas)`
|
||||
* `int write_data(int fd, const uint8_t * data, uint32_t size)`
|
||||
|
||||
To recognize functions like these, CMock looks for a parameter list
|
||||
containing a pointer (which could be an array) followed by something that
|
||||
could be an array size. "Something", by default, means an `int` or `size_t`
|
||||
parameter with a name containing "size" or "len".
|
||||
|
||||
`:array_size_type` is a list of additional types (besides `int` and `size_t`)
|
||||
that could be used for an array size parameter. For example, to get CMock to
|
||||
recognize that `uint32_t size` is an array size, you'd need to say:
|
||||
|
||||
cfg[:array_size_type] = ['uint32_t']
|
||||
|
||||
`:array_size_name` is a regular expression used to match an array size
|
||||
parameter by name. By default, it's 'size|len'. To get CMock to recognize a
|
||||
name like `num_bananas`, you could tell it to also accept names containing
|
||||
'num_' like this:
|
||||
|
||||
cfg[:array_size_name] = 'size|len|num_'
|
||||
|
||||
Parameters must match *both* `:array_size_type` and `:array_size_name` (and
|
||||
must come right after a pointer parameter) to be treated as an array size.
|
||||
|
||||
Once you've told it how to recognize your arrays, CMock will give you _Expect
|
||||
calls that work more like _ExpectWithArray, and compare an array of objects
|
||||
rather than just a single object.
|
||||
|
||||
For example, if you write the following, CMock will check that GoBananas is
|
||||
called and passed an array containing a green banana followed by a yellow
|
||||
banana:
|
||||
|
||||
Banana b[2] = {GreenBanana, YellowBanana};
|
||||
GoBananas_Expect(b, 2);
|
||||
|
||||
In other words, `GoBananas_Expect(b, 2)` now works just the same as:
|
||||
|
||||
GoBananas_ExpectWithArray(b, 2, 2);
|
||||
|
||||
* `:fail_on_unexpected_calls`:
|
||||
By default, CMock will fail a test if a mock is called without _Expect and _Ignore
|
||||
called first. While this forces test writers to be more explicit in their expectations,
|
||||
@@ -574,7 +654,7 @@ based on other settings, particularly Unity's settings.
|
||||
* `CMOCK_MEM_SIZE`
|
||||
In static mode this is the total amount of memory you are allocating
|
||||
to Cmock. In Dynamic mode this is the size of each chunk allocated
|
||||
at once (larger numbers grab more memory but require less mallocs).
|
||||
at once (larger numbers grab more memory but require fewer mallocs).
|
||||
|
||||
* `CMOCK_MEM_ALIGN`
|
||||
The way to align your data to. Not everything is as flexible as
|
||||
@@ -592,6 +672,20 @@ based on other settings, particularly Unity's settings.
|
||||
This needs to be something big enough to point anywhere in Cmock's
|
||||
memory space... usually it's an unsigned int.
|
||||
|
||||
Other Tips
|
||||
==========
|
||||
|
||||
resetTest
|
||||
---------
|
||||
|
||||
While this isn't strictly a CMock feature, often users of CMock are using
|
||||
either the test runner generator scripts in Unity or using Ceedling. In
|
||||
either case, there is a handy function called `resetTest` which gets
|
||||
generated with your runner. You can then use this handy function in your tests
|
||||
themselves. Call it during a test to have CMock validate everything to this point
|
||||
and start over clean. This is really useful when wanting to test a function in
|
||||
an iterative manner with different arguments.
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
@@ -600,4 +694,3 @@ you might tool CMock into your build process. You may also want to consider
|
||||
using [Ceedling](https://throwtheswitch.org/ceedling). Please note that
|
||||
these examples are meant to show how the build process works. They have
|
||||
failing tests ON PURPOSE to show what that would look like. Don't be alarmed. ;)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
CC ?= gcc
|
||||
BUILD_DIR ?= ./build
|
||||
SRC_DIR ?= ./src
|
||||
TEST_DIR ?= ./test
|
||||
TEST_BUILD_DIR ?= ${BUILD_DIR}/test
|
||||
export BUILD_DIR ?= ./build
|
||||
export SRC_DIR ?= ./src
|
||||
export TEST_DIR ?= ./test
|
||||
export TEST_BUILD_DIR ?= ${BUILD_DIR}/test
|
||||
TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport
|
||||
OBJ ?= ${BUILD_DIR}/obj
|
||||
OBJ_DIR = ${OBJ}
|
||||
|
||||
@@ -151,7 +151,7 @@ module RakefileHelpers
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||
unless $?.exitstatus.zero? || ok_to_fail
|
||||
unless (!$?.nil? && $?.exitstatus.zero?) || ok_to_fail
|
||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||
end
|
||||
return output
|
||||
@@ -185,7 +185,7 @@ module RakefileHelpers
|
||||
obj_list = []
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
header_list = extract_headers(test) + ['cmock.h']
|
||||
header_list = (extract_headers(test) + ['cmock.h'] + [ $cfg[:cmock][:unity_helper_path] ]).compact.uniq
|
||||
header_list.each do |header|
|
||||
|
||||
#create mocks if needed
|
||||
|
||||
+19
-1
@@ -22,12 +22,14 @@ class CMockConfig
|
||||
:fail_on_unexpected_calls => true,
|
||||
:unity_helper_path => false,
|
||||
:treat_as => {},
|
||||
:treat_as_array => {},
|
||||
:treat_as_void => [],
|
||||
:memcmp_if_unknown => true,
|
||||
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
|
||||
:when_ptr => :compare_data, #the options being :compare_ptr, :compare_data, or :smart
|
||||
:verbosity => 2, #the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
|
||||
:treat_externs => :exclude, #the options being :include or :exclude
|
||||
:treat_inlines => :exclude, #the options being :include or :exclude
|
||||
:callback_include_count => true,
|
||||
:callback_after_arg_check => false,
|
||||
:includes => nil,
|
||||
@@ -36,6 +38,8 @@ class CMockConfig
|
||||
:includes_c_pre_header => nil,
|
||||
:includes_c_post_header => nil,
|
||||
:orig_header_include_fmt => "#include \"%s\"",
|
||||
:array_size_type => [],
|
||||
:array_size_name => 'size|len',
|
||||
}
|
||||
|
||||
def initialize(options=nil)
|
||||
@@ -61,6 +65,16 @@ class CMockConfig
|
||||
end
|
||||
options[:unity_helper_path] ||= options[:unity_helper]
|
||||
options[:unity_helper_path] = [options[:unity_helper_path]] if options[:unity_helper_path].is_a? String
|
||||
|
||||
if options[:unity_helper_path]
|
||||
require 'pathname'
|
||||
includes1 = options[:includes_c_post_header] || []
|
||||
includes2 = options[:unity_helper_path].map do |path|
|
||||
Pathname(path).relative_path_from(Pathname(options[:mock_path])).to_s
|
||||
end
|
||||
options[:includes_c_post_header] = (includes1 + includes2).uniq
|
||||
end
|
||||
|
||||
options[:plugins].compact!
|
||||
options[:plugins].map! {|p| p.to_sym}
|
||||
@options = options
|
||||
@@ -69,7 +83,11 @@ class CMockConfig
|
||||
treat_as_map.merge!(@options[:treat_as])
|
||||
@options[:treat_as] = treat_as_map
|
||||
|
||||
@options.each_key { |key| eval("def #{key.to_s}() return @options[:#{key.to_s}] end") }
|
||||
@options.each_key do |key|
|
||||
unless methods.include?(key)
|
||||
eval("def #{key.to_s}() return @options[:#{key.to_s}] end")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def load_config_file_from_yaml yaml_filename
|
||||
|
||||
+18
-7
@@ -16,6 +16,7 @@ class CMockGenerator
|
||||
@prefix = @config.mock_prefix
|
||||
@suffix = @config.mock_suffix
|
||||
@weak = @config.weak
|
||||
@include_inline = @config.treat_inlines
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@framework = @config.framework.to_s
|
||||
@fail_on_unexpected_calls = @config.fail_on_unexpected_calls
|
||||
@@ -57,12 +58,16 @@ class CMockGenerator
|
||||
private if $ThisIsOnlyATest.nil? ##############################
|
||||
|
||||
def create_mock_subdir()
|
||||
if @subdir
|
||||
@file_writer.create_subdir(@subdir)
|
||||
end
|
||||
@file_writer.create_subdir(@subdir)
|
||||
end
|
||||
|
||||
def create_mock_header_file(parsed_stuff)
|
||||
if @include_inline == :include
|
||||
@file_writer.create_file(@module_name + ".h", @subdir) do |file, filename|
|
||||
file << parsed_stuff[:normalized_source]
|
||||
end
|
||||
end
|
||||
|
||||
@file_writer.create_file(@mock_name + ".h", @subdir) do |file, filename|
|
||||
create_mock_header_header(file, filename)
|
||||
create_mock_header_service_call_declarations(file)
|
||||
@@ -95,6 +100,7 @@ class CMockGenerator
|
||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
||||
file << "#ifndef _#{define_name}_H\n"
|
||||
file << "#define _#{define_name}_H\n\n"
|
||||
file << "#include \"#{@framework}.h\"\n"
|
||||
@includes_h_pre_orig_header.each {|inc| file << "#include #{inc}\n"}
|
||||
file << @config.orig_header_include_fmt.gsub(/%s/, "#{orig_filename}") + "\n"
|
||||
@includes_h_post_orig_header.each {|inc| file << "#include #{inc}\n"}
|
||||
@@ -144,7 +150,6 @@ class CMockGenerator
|
||||
file << "#include <string.h>\n"
|
||||
file << "#include <stdlib.h>\n"
|
||||
file << "#include <setjmp.h>\n"
|
||||
file << "#include \"#{@framework}.h\"\n"
|
||||
file << "#include \"cmock.h\"\n"
|
||||
@includes_c_pre_header.each {|inc| file << "#include #{inc}\n"}
|
||||
file << "#include \"#{header_file}\"\n"
|
||||
@@ -190,9 +195,15 @@ class CMockGenerator
|
||||
|
||||
def create_mock_verify_function(file, functions)
|
||||
file << "void #{@clean_mock_name}_Verify(void)\n{\n"
|
||||
verifications = functions.collect {|function| @plugins.run(:mock_verify, function)}.join
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n" unless verifications.empty?
|
||||
file << verifications
|
||||
verifications = functions.collect do |function|
|
||||
v = @plugins.run(:mock_verify, function)
|
||||
v.empty? ? v : [" call_instance = Mock.#{function[:name]}_CallInstance;\n", v]
|
||||
end.join
|
||||
unless verifications.empty?
|
||||
file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n"
|
||||
file << " CMOCK_MEM_INDEX_TYPE call_instance;\n"
|
||||
file << verifications
|
||||
end
|
||||
file << "}\n\n"
|
||||
end
|
||||
|
||||
|
||||
@@ -16,83 +16,73 @@ class CMockGeneratorPluginCallback
|
||||
@priority = 6
|
||||
|
||||
@include_count = @config.callback_include_count
|
||||
if (@config.callback_after_arg_check)
|
||||
alias :mock_implementation :mock_implementation_for_callbacks_after_arg_check
|
||||
alias :mock_implementation_precheck :nothing
|
||||
else
|
||||
alias :mock_implementation_precheck :mock_implementation_for_callbacks_without_arg_check
|
||||
alias :mock_implementation :nothing
|
||||
end
|
||||
end
|
||||
|
||||
def instance_structure(function)
|
||||
func_name = function[:name]
|
||||
" CMOCK_#{func_name}_CALLBACK #{func_name}_CallbackFunctionPointer;\n" +
|
||||
" int #{func_name}_CallbackBool;\n" \
|
||||
" CMOCK_#{func_name}_CALLBACK #{func_name}_CallbackFunctionPointer;\n" \
|
||||
" int #{func_name}_CallbackCalls;\n"
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
func_name = function[:name]
|
||||
return_type = function[:return][:type]
|
||||
action = @config.callback_after_arg_check ? 'AddCallback' : 'Stub'
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2)
|
||||
styles = [ "void", "int cmock_num_calls", function[:args_string], "#{function[:args_string]}, int cmock_num_calls" ]
|
||||
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\nvoid #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback);\n"
|
||||
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\n" \
|
||||
"void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
||||
"void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback);\n" \
|
||||
"#define #{func_name}_StubWithCallback #{func_name}_#{action}\n"
|
||||
end
|
||||
|
||||
def mock_implementation_for_callbacks_after_arg_check(function)
|
||||
func_name = function[:name]
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2) | (function[:return][:void?] ? 0 : 4)
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
case(style)
|
||||
when 0 then " Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 1 then " Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 2 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 3 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 4 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
end
|
||||
def generate_call(function)
|
||||
args = function[:args].map { |m| m[:name] }
|
||||
args << "Mock.#{function[:name]}_CallbackCalls++" if @include_count
|
||||
"Mock.#{function[:name]}_CallbackFunctionPointer(#{args.join(', ')})"
|
||||
end
|
||||
|
||||
def mock_implementation_for_callbacks_without_arg_check(function)
|
||||
func_name = function[:name]
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2) | (function[:return][:void?] ? 0 : 4)
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
case(style)
|
||||
when 0 then " Mock.#{func_name}_CallbackFunctionPointer();\n return;\n }\n"
|
||||
when 1 then " Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n return;\n }\n"
|
||||
when 2 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n return;\n }\n"
|
||||
when 3 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n return;\n }\n"
|
||||
when 4 then " return Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " return Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
end
|
||||
def mock_implementation(function)
|
||||
" if (Mock.#{function[:name]}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
if function[:return][:void?]
|
||||
" #{generate_call(function)};\n }\n"
|
||||
else
|
||||
" cmock_call_instance->ReturnVal = #{generate_call(function)};\n }\n"
|
||||
end
|
||||
end
|
||||
|
||||
def nothing(function)
|
||||
return ""
|
||||
def mock_implementation_precheck(function)
|
||||
" if (!Mock.#{function[:name]}_CallbackBool &&\n" \
|
||||
" Mock.#{function[:name]}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
if function[:return][:void?]
|
||||
" #{generate_call(function)};\n" \
|
||||
" UNITY_CLR_DETAILS();\n" \
|
||||
" return;\n }\n"
|
||||
else
|
||||
" #{function[:return][:type]} cmock_cb_ret = #{generate_call(function)};\n" \
|
||||
" UNITY_CLR_DETAILS();\n" \
|
||||
" return cmock_cb_ret;\n }\n"
|
||||
end
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
func_name = function[:name]
|
||||
has_ignore = @config.plugins.include? :ignore
|
||||
lines = ""
|
||||
lines << "void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
||||
if @config.plugins.include? :ignore
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n"
|
||||
end
|
||||
lines << "void #{func_name}_AddCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore
|
||||
lines << " Mock.#{func_name}_CallbackBool = (int)1;\n"
|
||||
lines << " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n"
|
||||
lines << "void #{func_name}_Stub(CMOCK_#{func_name}_CALLBACK Callback)\n{\n"
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if has_ignore
|
||||
lines << " Mock.#{func_name}_CallbackBool = (int)0;\n"
|
||||
lines << " Mock.#{func_name}_CallbackFunctionPointer = Callback;\n}\n\n"
|
||||
end
|
||||
|
||||
def mock_destroy(function)
|
||||
" Mock.#{function[:name]}_CallbackFunctionPointer = NULL;\n" +
|
||||
" Mock.#{function[:name]}_CallbackCalls = 0;\n"
|
||||
end
|
||||
|
||||
def mock_verify(function)
|
||||
func_name = function[:name]
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n Mock.#{func_name}_CallInstance = CMOCK_GUTS_NONE;\n"
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n call_instance = CMOCK_GUTS_NONE;\n"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ class CMockGeneratorPluginExpect
|
||||
|
||||
def mock_implementation_might_check_args(function)
|
||||
return "" if (function[:args].empty?)
|
||||
lines = " if (cmock_call_instance->IgnoreMode != CMOCK_ARG_NONE)\n {\n"
|
||||
lines = " if (!cmock_call_instance->ExpectAnyArgsBool)\n {\n"
|
||||
function[:args].each do |arg|
|
||||
lines << @utils.code_verify_an_arg_expectation(function, arg)
|
||||
end
|
||||
@@ -91,14 +91,13 @@ class CMockGeneratorPluginExpect
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
lines << @utils.code_call_argument_loader(function)
|
||||
lines << @utils.code_assign_argument_quickly("cmock_call_instance->ReturnVal", function[:return]) unless (function[:return][:void?])
|
||||
lines << " UNITY_CLR_DETAILS();\n"
|
||||
lines << "}\n\n"
|
||||
end
|
||||
|
||||
def mock_verify(function)
|
||||
func_name = function[:name]
|
||||
" UNITY_SET_DETAIL(CMockString_#{function[:name]});\n" +
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.#{func_name}_CallInstance, cmock_line, CMockStringCalledLess);\n"
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" +
|
||||
" UNITY_CLR_DETAILS();\n"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,40 +15,39 @@ class CMockGeneratorPluginExpectAnyArgs
|
||||
@priority = 3
|
||||
end
|
||||
|
||||
def instance_structure(function)
|
||||
if (function[:return][:void?]) || (@config.plugins.include? :ignore)
|
||||
""
|
||||
else
|
||||
" #{function[:return][:type]} #{function[:name]}_FinalReturn;\n"
|
||||
end
|
||||
end
|
||||
|
||||
def instance_typedefs(function)
|
||||
" CMOCK_ARG_MODE IgnoreMode;\n"
|
||||
" int ExpectAnyArgsBool;\n"
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" +
|
||||
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
unless (function[:args].empty?)
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" +
|
||||
"void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
return "#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
else
|
||||
return "#define #{function[:name]}_ExpectAnyArgsAndReturn(cmock_retval) #{function[:name]}_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
lines = ""
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||
else
|
||||
lines << "void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
unless (function[:args].empty?)
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n{\n"
|
||||
else
|
||||
lines << "void #{function[:name]}_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]})\n{\n"
|
||||
end
|
||||
lines << @utils.code_add_base_expectation(function[:name], true)
|
||||
unless (function[:return][:void?])
|
||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
||||
end
|
||||
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)1;\n"
|
||||
lines << "}\n\n"
|
||||
end
|
||||
lines << @utils.code_add_base_expectation(function[:name], true)
|
||||
unless (function[:return][:void?])
|
||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n"
|
||||
end
|
||||
lines << " cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n"
|
||||
lines << "}\n\n"
|
||||
return lines
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,6 +70,6 @@ class CMockGeneratorPluginIgnore
|
||||
|
||||
def mock_verify(function)
|
||||
func_name = function[:name]
|
||||
" if (Mock.#{func_name}_IgnoreBool)\n Mock.#{func_name}_CallInstance = CMOCK_GUTS_NONE;\n"
|
||||
" if (Mock.#{func_name}_IgnoreBool)\n call_instance = CMOCK_GUTS_NONE;\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,13 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
function[:args].each do |arg|
|
||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
||||
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||
# If the pointer type actually contains an asterisk, we can do sizeof the type (super safe), otherwise
|
||||
# we need to do a sizeof the dereferenced pointer (which could be a problem if give the wrong size
|
||||
if (arg[:type][-1] == '*')
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(#{arg[:type][0..-2]}))\n"
|
||||
else
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||
end
|
||||
lines << "#define #{function[:name]}_ReturnArrayThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_len)"
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, (int)(cmock_len * (int)sizeof(*#{arg[:name]})))\n"
|
||||
lines << "#define #{function[:name]}_ReturnMemThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_size)"
|
||||
|
||||
@@ -19,7 +19,7 @@ class CMockGeneratorUtils
|
||||
@ignore_arg = @config.plugins.include? :ignore_arg
|
||||
@ignore = @config.plugins.include? :ignore
|
||||
@treat_as = @config.treat_as
|
||||
@helpers = helpers
|
||||
@helpers = helpers
|
||||
end
|
||||
|
||||
def self.arg_type_with_const(arg)
|
||||
@@ -57,7 +57,7 @@ class CMockGeneratorUtils
|
||||
lines << " cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if (@ordered and global_ordering_supported)
|
||||
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if (@cexception)
|
||||
lines << " cmock_call_instance->IgnoreMode = CMOCK_ARG_ALL;\n" if (@expect_any)
|
||||
lines << " cmock_call_instance->ExpectAnyArgsBool = (int)0;\n" if (@expect_any)
|
||||
lines
|
||||
end
|
||||
|
||||
@@ -73,7 +73,10 @@ class CMockGeneratorUtils
|
||||
if (arg[:ptr?] or @treat_as.include?(arg[:type]))
|
||||
" #{dest} = #{arg[:name]};\n"
|
||||
else
|
||||
" memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n"
|
||||
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
|
||||
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
|
||||
" memcpy((void*)(&#{dest}), (void*)(&#{arg[:name]}),\n" +
|
||||
" sizeof(#{arg[:type]}[#{assert_expr}])); #{comment}\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -84,10 +87,12 @@ class CMockGeneratorUtils
|
||||
type = arg_type_with_const(m)
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string});\n" +
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
|
||||
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } +
|
||||
"}\n\n"
|
||||
else
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]});\n" +
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" +
|
||||
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg) } +
|
||||
"}\n\n"
|
||||
@@ -100,7 +105,13 @@ class CMockGeneratorUtils
|
||||
def code_call_argument_loader(function)
|
||||
if (function[:args_string] != "void")
|
||||
args = function[:args].map do |m|
|
||||
(@arrays and m[:ptr?]) ? "#{m[:name]}, 1" : m[:name]
|
||||
if (@arrays and m[:ptr?] and not m[:array_data?])
|
||||
"#{m[:name]}, 1"
|
||||
elsif (@arrays and m[:array_size?])
|
||||
"#{m[:name]}, #{m[:name]}"
|
||||
else
|
||||
m[:name]
|
||||
end
|
||||
end
|
||||
" CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n"
|
||||
else
|
||||
@@ -170,6 +181,7 @@ class CMockGeneratorUtils
|
||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||
lines << " {\n"
|
||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||
lines << " if (#{pre}#{expected} != #{pre}#{arg_name}) {\n"
|
||||
case(unity_func)
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
c_type_local = c_type.gsub(/\*$/,'')
|
||||
@@ -195,7 +207,7 @@ class CMockGeneratorUtils
|
||||
else
|
||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
||||
end
|
||||
lines << " }\n"
|
||||
lines << " }\n }\n"
|
||||
lines
|
||||
end
|
||||
|
||||
@@ -206,6 +218,7 @@ class CMockGeneratorUtils
|
||||
lines << " if (!#{ignore})\n" if @ignore_arg
|
||||
lines << " {\n"
|
||||
lines << " UNITY_SET_DETAILS(CMockString_#{function[:name]},CMockString_#{arg_name});\n"
|
||||
lines << " if (#{pre}#{expected} != #{pre}#{arg_name}) {\n"
|
||||
case(unity_func)
|
||||
when "UNITY_TEST_ASSERT_EQUAL_MEMORY"
|
||||
c_type_local = c_type.gsub(/\*$/,'')
|
||||
@@ -233,7 +246,7 @@ class CMockGeneratorUtils
|
||||
else
|
||||
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n"
|
||||
end
|
||||
lines << " }\n"
|
||||
lines << " }\n }\n"
|
||||
lines
|
||||
end
|
||||
|
||||
|
||||
+157
-20
@@ -6,7 +6,7 @@
|
||||
|
||||
class CMockHeaderParser
|
||||
|
||||
attr_accessor :funcs, :c_attr_noconst, :c_attributes, :treat_as_void, :treat_externs
|
||||
attr_accessor :funcs, :c_attr_noconst, :c_attributes, :treat_as_void, :treat_externs, :treat_inlines
|
||||
|
||||
def initialize(cfg)
|
||||
@funcs = []
|
||||
@@ -14,20 +14,26 @@ class CMockHeaderParser
|
||||
@c_attr_noconst = cfg.attributes.uniq - ['const']
|
||||
@c_attributes = ['const'] + c_attr_noconst
|
||||
@c_calling_conventions = cfg.c_calling_conventions.uniq
|
||||
@treat_as_array = cfg.treat_as_array
|
||||
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
|
||||
@declaration_parse_matcher = /([\d\w\s\*\(\),\[\]]+??)\(([\d\w\s\*\(\),\.\[\]+-]*)\)$/m
|
||||
@declaration_parse_matcher = /([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+-]*)\)$/m
|
||||
@standards = (['int','short','char','long','unsigned','signed'] + cfg.treat_as.keys).uniq
|
||||
@array_size_name = cfg.array_size_name
|
||||
@array_size_type = (['int', 'size_t'] + cfg.array_size_type).uniq
|
||||
@when_no_prototypes = cfg.when_no_prototypes
|
||||
@local_as_void = @treat_as_void
|
||||
@verbosity = cfg.verbosity
|
||||
@treat_externs = cfg.treat_externs
|
||||
@treat_inlines = cfg.treat_inlines
|
||||
@c_strippables += ['extern'] if (@treat_externs == :include) #we'll need to remove the attribute if we're allowing externs
|
||||
@c_strippables += ['inline'] if (@treat_inlines == :include) #we'll need to remove the attribute if we're allowing inlines
|
||||
end
|
||||
|
||||
def parse(name, source)
|
||||
@module_name = name.gsub(/\W/,'')
|
||||
@typedefs = []
|
||||
@funcs = []
|
||||
@normalized_source = nil
|
||||
function_names = []
|
||||
|
||||
parse_functions( import_source(source) ).map do |decl|
|
||||
@@ -38,14 +44,113 @@ class CMockHeaderParser
|
||||
end
|
||||
end
|
||||
|
||||
@normalized_source = if (@treat_inlines == :include)
|
||||
transform_inline_functions(source)
|
||||
else
|
||||
''
|
||||
end
|
||||
|
||||
{ :includes => nil,
|
||||
:functions => @funcs,
|
||||
:typedefs => @typedefs
|
||||
:typedefs => @typedefs,
|
||||
:normalized_source => @normalized_source
|
||||
}
|
||||
end
|
||||
|
||||
private if $ThisIsOnlyATest.nil? ################
|
||||
|
||||
def remove_nested_pairs_of_braces(source)
|
||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
||||
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
||||
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
||||
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
||||
source.gsub!(/#{r}/m, '{ }')
|
||||
else
|
||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||
end
|
||||
end
|
||||
|
||||
return source
|
||||
end
|
||||
|
||||
# Return the number of pairs of braces/square brackets in the function provided by the user
|
||||
# +source+:: String containing the function to be processed
|
||||
def count_number_of_pairs_of_braces_in_function(source)
|
||||
is_function_start_found = false
|
||||
curr_level = 0
|
||||
total_pairs = 0
|
||||
|
||||
source.each_char do |c|
|
||||
if ("{" == c)
|
||||
curr_level += 1
|
||||
total_pairs +=1
|
||||
is_function_start_found = true
|
||||
elsif ("}" == c)
|
||||
curr_level -=1
|
||||
end
|
||||
|
||||
break if is_function_start_found && curr_level == 0 # We reached the end of the inline function body
|
||||
end
|
||||
|
||||
if 0 != curr_level
|
||||
total_pairs = 0 # Something is fishy about this source, not enough closing braces?
|
||||
end
|
||||
|
||||
return total_pairs
|
||||
end
|
||||
|
||||
# Transform inline functions to regular functions in the source by the user
|
||||
# +source+:: String containing the source to be processed
|
||||
def transform_inline_functions(source)
|
||||
# Format to look for inline functions.
|
||||
# This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static")
|
||||
# There are several possibilities:
|
||||
# - sometimes they appear together, sometimes individually,
|
||||
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
|
||||
# so we check for word boundaries when searching for them
|
||||
# - We first remove "static inline" combinations and boil down to single inline or static statements
|
||||
inline_function_regex_formats = [
|
||||
/(static\s+inline|inline\s+static)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
|
||||
/(\bstatic\b|\binline\b)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
|
||||
]
|
||||
square_bracket_pair_regex_format = /\{[^\{\}]*\}/ # Regex to match one whole block enclosed by two square brackets
|
||||
|
||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
||||
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)
|
||||
|
||||
# - Just looking for static|inline in the gsub is a bit too aggressive (functions that are named like this, ...), so we try to be a bit smarter
|
||||
# Instead, look for "static inline" and parse it:
|
||||
# - Everything before the match should just be copied, we don't want
|
||||
# to touch anything but the inline functions.
|
||||
# - Remove the implementation of the inline function (this is enclosed
|
||||
# in square brackets) and replace it with ";" to complete the
|
||||
# transformation to normal/non-inline function.
|
||||
# To ensure proper removal of the function body, we count the number of square-bracket pairs
|
||||
# and remove the pairs one-by-one.
|
||||
# - Copy everything after the inline function implementation and start the parsing of the next inline function
|
||||
|
||||
inline_function_regex_formats.each do |format|
|
||||
loop do
|
||||
inline_function_match = source.match(/#{format}/) # Search for inline function declaration
|
||||
break if nil == inline_function_match # No inline functions so nothing to do
|
||||
|
||||
total_pairs_to_remove = count_number_of_pairs_of_braces_in_function(inline_function_match.post_match)
|
||||
|
||||
break if 0 == total_pairs_to_remove # Bad source?
|
||||
|
||||
inline_function_stripped = inline_function_match.post_match
|
||||
|
||||
total_pairs_to_remove.times do
|
||||
inline_function_stripped.sub!(/\s*#{square_bracket_pair_regex_format}/, ";") # Remove inline implementation (+ some whitespace because it's prettier)
|
||||
end
|
||||
|
||||
source = inline_function_match.pre_match + inline_function_stripped # Make new source with the inline function removed and move on to the next
|
||||
end
|
||||
end
|
||||
|
||||
return source
|
||||
end
|
||||
|
||||
def import_source(source)
|
||||
|
||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
||||
@@ -54,7 +159,7 @@ class CMockHeaderParser
|
||||
# void must be void for cmock _ExpectAndReturn calls to process properly, not some weird typedef which equates to void
|
||||
# to a certain extent, this action assumes we're chewing on pre-processed header files, otherwise we'll most likely just get stuff from @treat_as_void
|
||||
@local_as_void = @treat_as_void
|
||||
void_types = source.scan(/typedef\s+(?:\(\s*)?void(?:\s*\))?\s+([\w\d]+)\s*;/)
|
||||
void_types = source.scan(/typedef\s+(?:\(\s*)?void(?:\s*\))?\s+([\w]+)\s*;/)
|
||||
if void_types
|
||||
@local_as_void += void_types.flatten.uniq.compact
|
||||
end
|
||||
@@ -63,9 +168,9 @@ class CMockHeaderParser
|
||||
source.gsub!(/\s*\\\s*/m, ' ')
|
||||
|
||||
#remove comments (block and line, in three steps to ensure correct precedence)
|
||||
source.gsub!(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
|
||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||
source.gsub!(/(?<!\*)\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
|
||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||
|
||||
# remove assembler pragma sections
|
||||
source.gsub!(/^\s*#\s*pragma\s+asm\s+.*?#\s*pragma\s+endasm/m, '')
|
||||
@@ -87,6 +192,9 @@ class CMockHeaderParser
|
||||
source.gsub!(/\)(\w)/, ') \1') # add space between parenthese and alphanumeric
|
||||
source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/,'\1') unless @c_strippables.empty? # remove known attributes slated to be stripped
|
||||
|
||||
#scan standalone function pointers and remove them, because they can just be ignored
|
||||
source.gsub!(/\w+\s*\(\s*\*\s*\w+\s*\)\s*\([^)]*\)\s*;/,';')
|
||||
|
||||
#scan for functions which return function pointers, because they are a pain
|
||||
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |m|
|
||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||
@@ -94,16 +202,15 @@ class CMockHeaderParser
|
||||
"#{functype} #{$2.strip}(#{$3});"
|
||||
end
|
||||
|
||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
||||
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
||||
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
||||
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
||||
source.gsub!(/#{r}/m, '{ }')
|
||||
else
|
||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||
end
|
||||
source = remove_nested_pairs_of_braces(source)
|
||||
|
||||
if (@treat_inlines == :include)
|
||||
# Functions having "{ }" at this point are/were inline functions,
|
||||
# User wants them in so 'disguise' them as normal functions with the ";"
|
||||
source.gsub!("{ }", ";")
|
||||
end
|
||||
|
||||
|
||||
# remove function definitions by stripping off the arguments right now
|
||||
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ";")
|
||||
|
||||
@@ -118,11 +225,20 @@ class CMockHeaderParser
|
||||
src_lines = source.split(/\s*;\s*/).uniq
|
||||
src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
|
||||
src_lines.delete_if {|line| !(line =~ /[\w\s\*]+\(+\s*\*[\*\s]*[\w\s]+(?:\[[\w\s]*\]\s*)+\)+\s*\((?:[\w\s\*]*,?)*\s*\)/).nil?} #remove function pointer arrays
|
||||
if (@treat_externs == :include)
|
||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil?} # remove inline functions
|
||||
else
|
||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:extern|inline)\s+/).nil?} # remove inline and extern functions
|
||||
|
||||
unless (@treat_externs == :include)
|
||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:extern)\s+/).nil?} # remove extern functions
|
||||
end
|
||||
|
||||
if (@treat_inlines == :include)
|
||||
src_lines.each {
|
||||
|src_line|
|
||||
src_line.gsub!(/^inline/, "") # Remove "inline" so that they are 'normal' functions
|
||||
}
|
||||
else
|
||||
src_lines.delete_if {|line| !(line =~ /(?:^|\s+)(?:inline)\s+/).nil?} # remove inline functions
|
||||
end
|
||||
|
||||
src_lines.delete_if {|line| line.empty? } #drop empty lines
|
||||
end
|
||||
|
||||
@@ -184,8 +300,29 @@ class CMockHeaderParser
|
||||
arg_info = parse_type_and_name(arg)
|
||||
arg_info.delete(:modifier) # don't care about this
|
||||
arg_info.delete(:c_calling_convention) # don't care about this
|
||||
|
||||
# in C, array arguments implicitly degrade to pointers
|
||||
# make the translation explicit here to simplify later logic
|
||||
if @treat_as_array[arg_info[:type]] and not arg_info[:ptr?] then
|
||||
arg_info[:type] = "#{@treat_as_array[arg_info[:type]]}*"
|
||||
arg_info[:type] = "const #{arg_info[:type]}" if arg_info[:const?]
|
||||
arg_info[:ptr?] = true
|
||||
end
|
||||
|
||||
args << arg_info
|
||||
end
|
||||
|
||||
# Try to find array pair in parameters following this pattern : <type> * <name>, <@array_size_type> <@array_size_name>
|
||||
args.each_with_index {|val, index|
|
||||
next_index = index + 1
|
||||
if (args.length > next_index)
|
||||
if (val[:ptr?] == true and args[next_index][:name].match(@array_size_name) and @array_size_type.include?(args[next_index][:type]))
|
||||
val[:array_data?] = true
|
||||
args[next_index][:array_size?] = true
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
return args
|
||||
end
|
||||
|
||||
@@ -220,7 +357,7 @@ class CMockHeaderParser
|
||||
return 'void'
|
||||
else
|
||||
c=0
|
||||
arg_list.gsub!(/(\w+)(?:\s*\[\s*\(*[\s\d\w+-]*\)*\s*\])+/,'*\1') # magically turn brackets into asterisks, also match for parentheses that come from macros
|
||||
arg_list.gsub!(/(\w+)(?:\s*\[\s*\(*[\s\w+-]*\)*\s*\])+/,'*\1') # magically turn brackets into asterisks, also match for parentheses that come from macros
|
||||
arg_list.gsub!(/\s+\*/,'*') # remove space to place asterisks with type (where they belong)
|
||||
arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong)
|
||||
|
||||
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
###################################################################################
|
||||
# #
|
||||
# NAME: meson.build #
|
||||
# #
|
||||
# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. #
|
||||
# WRITTEN BY: Michael Brockus. #
|
||||
# #
|
||||
# License: MIT #
|
||||
# #
|
||||
###################################################################################
|
||||
|
||||
|
||||
project('cmock', 'c',
|
||||
license : 'MIT',
|
||||
meson_version : '>=0.52.0',
|
||||
subproject_dir : 'vendor',
|
||||
default_options: [
|
||||
'buildtype=minsize',
|
||||
'optimization=3',
|
||||
'warning_level=3',
|
||||
'werror=true',
|
||||
]
|
||||
)
|
||||
lang = 'c'
|
||||
cc = meson.get_compiler(lang)
|
||||
|
||||
|
||||
##
|
||||
#
|
||||
# Meson: Add compiler flags
|
||||
#
|
||||
##
|
||||
if cc.get_id() == 'clang'
|
||||
add_project_arguments(cc.get_supported_arguments(
|
||||
[
|
||||
'-Wweak-vtables', '-Wexit-time-destructors',
|
||||
'-Wglobal-constructors', '-Wmissing-noreturn'
|
||||
]
|
||||
), language: lang)
|
||||
endif
|
||||
|
||||
if cc.get_argument_syntax() == 'gcc'
|
||||
add_project_arguments(cc.get_supported_arguments(
|
||||
[
|
||||
'-Wformat', '-Waddress', '-Winit-self', '-Wno-multichar',
|
||||
'-Wpointer-arith' , '-Wwrite-strings' ,
|
||||
'-Wno-parentheses' , '-Wno-type-limits' ,
|
||||
'-Wformat-security' , '-Wunreachable-code' ,
|
||||
'-Waggregate-return' , '-Wformat-nonliteral' ,
|
||||
'-Wmissing-prototypes' , '-Wold-style-definition' ,
|
||||
'-Wmissing-declarations', '-Wmissing-include-dirs' ,
|
||||
'-Wno-unused-parameter' , '-Wdeclaration-after-statement'
|
||||
]
|
||||
), language: lang)
|
||||
endif
|
||||
|
||||
if cc.get_id() == 'msvc'
|
||||
add_project_arguments(cc.get_supported_arguments(
|
||||
[
|
||||
'/w44265', '/w44061', '/w44062',
|
||||
'/wd4018', '/wd4146', '/wd4244',
|
||||
'/wd4305',
|
||||
]
|
||||
), language: lang)
|
||||
endif
|
||||
|
||||
|
||||
unity_dep = dependency('unity', fallback: ['unity', 'unity_dep'])
|
||||
|
||||
subdir('src')
|
||||
|
||||
cmock_dep = declare_dependency(link_with: cmock_lib, include_directories: cmock_dir)
|
||||
@@ -1,2 +0,0 @@
|
||||
217
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
2.4.6
|
||||
|
||||
@@ -34,9 +34,9 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
|
||||
# Define make variables
|
||||
mkfile.puts "CC ?= gcc"
|
||||
mkfile.puts "BUILD_DIR ?= ./build"
|
||||
mkfile.puts "SRC_DIR ?= ./src"
|
||||
mkfile.puts "TEST_DIR ?= ./test"
|
||||
mkfile.puts "BUILD_DIR = #{BUILD_DIR}"
|
||||
mkfile.puts "SRC_DIR = #{SRC_DIR}"
|
||||
mkfile.puts "TEST_DIR = #{TEST_DIR}"
|
||||
mkfile.puts "TEST_CFLAGS ?= -DTEST"
|
||||
mkfile.puts "CMOCK_DIR ?= #{CMOCK_DIR}"
|
||||
mkfile.puts "UNITY_DIR ?= #{UNITY_DIR}"
|
||||
@@ -59,7 +59,21 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
test_sources = Dir["#{TEST_DIR}/**/test_*.c"]
|
||||
test_targets = []
|
||||
generator = UnityTestRunnerGenerator.new
|
||||
all_headers = Dir["#{SRC_DIR}/**/{[!#{MOCK_PREFIX}]}*{[!#{MOCK_SUFFIX}]}.h"] #headers that begin with prefix or end with suffix are not included
|
||||
|
||||
# headers that begin with prefix or end with suffix are not included
|
||||
all_headers = Dir["#{SRC_DIR}/**/*.h"]
|
||||
|
||||
def reject_mock_files(file)
|
||||
extn = File.extname file
|
||||
filename = File.basename file, extn
|
||||
if MOCK_SUFFIX.empty?
|
||||
return filename.start_with? MOCK_PREFIX
|
||||
end
|
||||
return (filename.start_with? MOCK_PREFIX or filename.end_with? MOCK_SUFFIX)
|
||||
end
|
||||
|
||||
all_headers = all_headers.reject { |f| reject_mock_files(f) }
|
||||
|
||||
makefile_targets = []
|
||||
|
||||
test_sources.each do |test|
|
||||
@@ -82,7 +96,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
if not makefile_targets.include? module_obj
|
||||
makefile_targets.push(module_obj)
|
||||
mkfile.puts "#{module_obj}: #{module_src}"
|
||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} ${INCLUDE_PATH}"
|
||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
||||
mkfile.puts ""
|
||||
end
|
||||
|
||||
@@ -98,7 +112,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
if not makefile_targets.include? linkonlymodule_obj
|
||||
makefile_targets.push(linkonlymodule_obj)
|
||||
mkfile.puts "#{linkonlymodule_obj}: #{linkonlymodule_src}"
|
||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} ${INCLUDE_PATH}"
|
||||
mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}"
|
||||
mkfile.puts ""
|
||||
end
|
||||
end
|
||||
|
||||
+11
-4
@@ -4,13 +4,12 @@
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include "cmock.h"
|
||||
|
||||
//public constants to be used by mocks
|
||||
const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more.";
|
||||
const char* CMockStringCalledMore = "Called more times than expected.";
|
||||
const char* CMockStringCalledLess = "Called less times than expected.";
|
||||
const char* CMockStringCalledLess = "Called fewer times than expected.";
|
||||
const char* CMockStringCalledEarly = "Called earlier than expected.";
|
||||
const char* CMockStringCalledLate = "Called later than expected.";
|
||||
const char* CMockStringCallOrder = "Called out of order.";
|
||||
@@ -24,11 +23,11 @@ const char* CMockStringMismatch = "Function called with unexpected argument v
|
||||
#ifdef CMOCK_MEM_DYNAMIC
|
||||
static unsigned char* CMock_Guts_Buffer = NULL;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_ALIGN_SIZE;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
|
||||
#else
|
||||
static unsigned char CMock_Guts_Buffer[CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE];
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
@@ -168,6 +167,14 @@ void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemBytesCapacity
|
||||
//-------------------------------------------------------
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void)
|
||||
{
|
||||
return (sizeof(CMock_Guts_Buffer) - CMOCK_MEM_ALIGN_SIZE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemBytesFree
|
||||
//-------------------------------------------------------
|
||||
|
||||
+6
-4
@@ -9,6 +9,11 @@
|
||||
|
||||
#include "cmock_internals.h"
|
||||
|
||||
#define CMOCK_VERSION_MAJOR 2
|
||||
#define CMOCK_VERSION_MINOR 5
|
||||
#define CMOCK_VERSION_BUILD 1
|
||||
#define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD)
|
||||
|
||||
//should be big enough to index full range of CMOCK_MEM_MAX
|
||||
#ifndef CMOCK_MEM_INDEX_TYPE
|
||||
#define CMOCK_MEM_INDEX_TYPE unsigned int
|
||||
@@ -16,10 +21,6 @@
|
||||
|
||||
#define CMOCK_GUTS_NONE (0)
|
||||
|
||||
#define CMOCK_ARG_MODE CMOCK_MEM_INDEX_TYPE
|
||||
#define CMOCK_ARG_ALL 0
|
||||
#define CMOCK_ARG_NONE ((CMOCK_MEM_INDEX_TYPE)(~0U))
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Memory API
|
||||
//-------------------------------------------------------
|
||||
@@ -30,6 +31,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index);
|
||||
|
||||
void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index);
|
||||
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void);
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void);
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void);
|
||||
void CMock_Guts_MemFreeAll(void);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#ifndef CMOCK_FRAMEWORK_INTERNALS_H
|
||||
#define CMOCK_FRAMEWORK_INTERNALS_H
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
//These are constants that the generated mocks have access to
|
||||
extern const char* CMockStringOutOfMemory;
|
||||
extern const char* CMockStringCalledMore;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
###################################################################################
|
||||
# #
|
||||
# NAME: meson.build #
|
||||
# #
|
||||
# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. #
|
||||
# WRITTEN BY: Michael Brockus. #
|
||||
# #
|
||||
# License: MIT #
|
||||
# #
|
||||
###################################################################################
|
||||
|
||||
cmock_dir = include_directories('.')
|
||||
|
||||
cmock_lib = static_library(meson.project_name(),
|
||||
sources: ['cmock.c'],
|
||||
dependencies: [unity_dep],
|
||||
include_directories: cmock_dir)
|
||||
+15
-5
@@ -25,8 +25,18 @@ void test_MemNewWillReturnNullIfGivenIllegalSizes(void)
|
||||
TEST_ASSERT_NULL( CMock_Guts_GetAddressFor(CMOCK_GUTS_NONE) );
|
||||
|
||||
//verify we're cleared still
|
||||
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
|
||||
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
|
||||
TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesCapacity());
|
||||
TEST_ASSERT_EQUAL_UINT32(0, CMock_Guts_MemBytesUsed());
|
||||
TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
|
||||
}
|
||||
|
||||
void test_MemShouldProtectAgainstMemoryOverflow(void)
|
||||
{
|
||||
(void)CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE);
|
||||
|
||||
//verify we've used all the memory
|
||||
TEST_ASSERT_LESS_OR_EQUAL_UINT32(TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesFree());
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed());
|
||||
}
|
||||
|
||||
void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void)
|
||||
@@ -258,11 +268,11 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
|
||||
}
|
||||
|
||||
//show that we can't ask for too much memory
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(12));
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(5));
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 8));
|
||||
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 1));
|
||||
|
||||
//but we CAN ask for something that will still fit
|
||||
next = CMock_Guts_MemNew(4);
|
||||
next = CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum - 4);
|
||||
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
|
||||
|
||||
first = CMock_Guts_MemChain(first, next);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
- 'TEST'
|
||||
- 'CMOCK_MEM_STATIC'
|
||||
- 'CMOCK_MEM_SIZE=128'
|
||||
#- 'CMOCK_MEM_SIZE=40000'
|
||||
- 'CMOCK_MEM_ALIGN=2'
|
||||
- 'CMOCK_MEM_INDEX_TYPE=int'
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
|
||||
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
|
||||
extern void test_MemShouldProtectAgainstMemoryOverflow(void);
|
||||
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
|
||||
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
|
||||
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
|
||||
@@ -26,13 +27,14 @@ int main(void)
|
||||
UnityBegin(Unity.TestFile);
|
||||
|
||||
RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 21);
|
||||
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 32);
|
||||
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 46);
|
||||
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 57);
|
||||
RUN_TEST(test_MemEndOfChain, 282);
|
||||
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory, 139);
|
||||
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd, 185);
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 233);
|
||||
RUN_TEST(test_MemShouldProtectAgainstMemoryOverflow, 33);
|
||||
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 42);
|
||||
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 56);
|
||||
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 67);
|
||||
RUN_TEST(test_MemEndOfChain, 149);
|
||||
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory, 195);
|
||||
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd, 244);
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 298);
|
||||
|
||||
UnityEnd();
|
||||
return 0;
|
||||
|
||||
@@ -50,6 +50,7 @@ module RakefileHelpers
|
||||
includes << m[1]
|
||||
end
|
||||
end
|
||||
includes << File.basename(filename,".c").slice(5,256) + "_unity_helper.h"
|
||||
return includes
|
||||
end
|
||||
|
||||
|
||||
@@ -104,7 +104,6 @@ class SystemTestGenerator
|
||||
return if tests.nil?
|
||||
|
||||
includes = [UNITY_H, CMOCK_H]
|
||||
includes << (namix + UNITY_HELPER_H) if not yaml_hash[:systest][:unity_helper].nil?
|
||||
includes << [MOCK_PREFIX + namix + MOCKABLE_H]
|
||||
includes << [name + H_EXTENSION]
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
:includes: []
|
||||
:mock_path: ./system/generated/
|
||||
:mock_prefix: mock_
|
||||
:treat_inlines: :include
|
||||
:treat_as_void:
|
||||
- OSEK_TASK
|
||||
- VOID_TYPE_CRAZINESS
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
static inline int dummy_func_0(void) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
inline static int dummy_func_1(int a) {
|
||||
int a = dummy_func_0();
|
||||
int b = 10;
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int inline static dummy_func_2(int a, char b, float c) {
|
||||
c += 3.14;
|
||||
b -= 32;
|
||||
return a + (int)(b) + (int)c;
|
||||
}
|
||||
|
||||
void dummy_normal_func(int a);
|
||||
|
||||
inline void dummy_func_3(void) {
|
||||
//NOP
|
||||
}
|
||||
Executable → Regular
@@ -50,3 +50,40 @@ extern unsigned long int incredible_descriptors(register const unsigned short a)
|
||||
int32_t example_c99_type(int32_t param1);
|
||||
|
||||
void I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
|
||||
|
||||
/* these are function pointers, not function declarations USING a function pointer, and so should NOT get mocked */
|
||||
int (* func_pointer)(void);
|
||||
extern int (*another_func_pointer)(unsigned int argument);
|
||||
struct struct_to_be_ignored {
|
||||
union {
|
||||
int i32;
|
||||
void *p;
|
||||
} variant;
|
||||
void (*a_function_pointer_in_a_struct)(void *);
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t a;
|
||||
struct
|
||||
{
|
||||
uint32_t bb;
|
||||
float bc;
|
||||
float bd;
|
||||
} b;
|
||||
int (*another_function_pointer_in_a_struct) (void);
|
||||
} another_thing_that_should_get_ignored;
|
||||
|
||||
inline int stuff(int num)
|
||||
{
|
||||
int reg = 0x12;
|
||||
if (num > 0)
|
||||
{
|
||||
reg |= (0x0Eu);
|
||||
}
|
||||
else
|
||||
{
|
||||
reg |= (0x07u);
|
||||
}
|
||||
return reg;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
:callback_after_arg_check: true
|
||||
:callback_include_count: false
|
||||
:treat_externs: :include
|
||||
:treat_inlines: :include
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'fail because bar() is called twice but is expected once'
|
||||
:verify_error: 'Called less times than expected'
|
||||
:verify_error: 'Called fewer times than expected'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
:plugins:
|
||||
- # none
|
||||
:memcmp_if_unknown: false
|
||||
:unity_helper_path: expect_and_return_custom_types_unity_helper.h
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
@@ -35,7 +36,6 @@
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
#include "expect_and_return_custom_types_unity_helper.h"
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'ignore foo() call details and notice if we called foo() less times than expected'
|
||||
:should: 'ignore foo() call details and notice if we called foo() fewer times than expected'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
void takes_const_function_ptr( unsigned int (* const)(int, char) );
|
||||
unsigned short (*returns_function_ptr( const char op_code ))( int, long int );
|
||||
|
||||
:source:
|
||||
:source:
|
||||
:header: |
|
||||
void exercise_function_pointer_param(void);
|
||||
unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int );
|
||||
|
||||
|
||||
// functions for function pointer tests
|
||||
unsigned int dummy_function1(int a, char b);
|
||||
unsigned short dummy_function2(int a, long int b);
|
||||
@@ -28,7 +28,7 @@
|
||||
/*
|
||||
* functions used in tests
|
||||
*/
|
||||
|
||||
|
||||
unsigned int dummy_function1(int a, char b)
|
||||
{
|
||||
// prevent compiler warnings by using everything
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
void bar(void);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
:header: |
|
||||
UINT32 function_a(int a);
|
||||
void function_b(void);
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
#The purpose of this test is to verify we handle void pointers as memory compares
|
||||
:cmock:
|
||||
:plugins:
|
||||
- :array
|
||||
:treat_as_array:
|
||||
VOID_PTR: unsigned char
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
#include "unity_internals.h"
|
||||
typedef void* VOID_PTR;
|
||||
|
||||
:mockable: |
|
||||
void* ret_v_ptr(void);
|
||||
void get_v_ptr(void* ptr);
|
||||
void get_v_ptr_typedefed(VOID_PTR ptr);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
|
||||
:code: |
|
||||
void function_a(void) {
|
||||
void* stuff = ret_v_ptr();
|
||||
get_v_ptr(stuff);
|
||||
get_v_ptr_typedefed((VOID_PTR)stuff);
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'handle passing working expects'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
char* a = "Hello";
|
||||
char* b = "Hello";
|
||||
ret_v_ptr_ExpectAndReturn(a);
|
||||
get_v_ptr_Expect(b);
|
||||
get_v_ptr_typedefed_Expect((VOID_PTR)b);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle passing array expects'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
char* a = "Hello";
|
||||
char* b = "Hello";
|
||||
ret_v_ptr_ExpectAndReturn(a);
|
||||
get_v_ptr_ExpectWithArray(b,5);
|
||||
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle failing expects'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
char* a = "Hello";
|
||||
char* b = "Jello";
|
||||
ret_v_ptr_ExpectAndReturn(a);
|
||||
get_v_ptr_Expect(b);
|
||||
get_v_ptr_typedefed_Expect((VOID_PTR)b);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle failing array expects'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
char* a = "Hello";
|
||||
char* b = "Hella";
|
||||
ret_v_ptr_ExpectAndReturn(a);
|
||||
get_v_ptr_ExpectWithArray(b,5);
|
||||
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
|
||||
|
||||
function_a();
|
||||
}
|
||||
...
|
||||
@@ -19,6 +19,7 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
||||
end
|
||||
|
||||
it "replace only options specified in a hash" do
|
||||
@@ -30,6 +31,7 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
assert_equal(test_attributes, config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_inlines], config.treat_inlines)
|
||||
end
|
||||
|
||||
it "replace only options specified in a yaml file" do
|
||||
@@ -40,6 +42,7 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
assert_nil(config.includes)
|
||||
assert_equal(test_plugins, config.plugins)
|
||||
assert_equal(:include, config.treat_externs)
|
||||
assert_equal(:include, config.treat_inlines)
|
||||
end
|
||||
|
||||
it "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
:plugins:
|
||||
- 'soda'
|
||||
- 'pizza'
|
||||
:treat_externs: :include
|
||||
:treat_externs: :include
|
||||
:treat_inlines: :include
|
||||
|
||||
@@ -54,6 +54,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator.module_name = @module_name
|
||||
@cmock_generator.mock_name = "Mock#{@module_name}"
|
||||
@@ -72,6 +73,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator_strict.module_name = @module_name
|
||||
@cmock_generator_strict.mock_name = "Mock#{@module_name}"
|
||||
@@ -92,6 +94,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
@@ -132,6 +135,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :includes_c_post_header, nil
|
||||
@config.expect :subdir, nil
|
||||
@config.expect :fail_on_unexpected_calls, true
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@cmock_generator2 = CMockGenerator.new(@config, @file_writer, @utils, @plugins)
|
||||
@cmock_generator2.module_name = "Pout-Pout Fish"
|
||||
@cmock_generator2.mock_name = "MockPout-Pout Fish"
|
||||
@@ -147,6 +151,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
@@ -185,6 +190,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
@@ -222,6 +228,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n",
|
||||
@@ -308,7 +315,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"#include <string.h>\n",
|
||||
"#include <stdlib.h>\n",
|
||||
"#include <setjmp.h>\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"cmock.h\"\n",
|
||||
"#include \"MockPoutPoutFish.h\"\n",
|
||||
"\n",
|
||||
@@ -409,8 +415,11 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
output = []
|
||||
expected = [ "void MockPoutPoutFish_Verify(void)\n{\n",
|
||||
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n",
|
||||
" CMOCK_MEM_INDEX_TYPE call_instance;\n",
|
||||
" call_instance = Mock.First_CallInstance;\n" +
|
||||
" Uno_First" +
|
||||
" Dos_First" +
|
||||
" call_instance = Mock.Second_CallInstance;\n" +
|
||||
" Uno_Second" +
|
||||
" Dos_Second",
|
||||
"}\n\n"
|
||||
|
||||
@@ -32,7 +32,8 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
|
||||
it "add to instance structure" do
|
||||
function = {:name => "Oak", :args => [:type => "int*", :name => "blah", :ptr? => true], :return => test_return[:int_ptr]}
|
||||
expected = " CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n" +
|
||||
expected = " int Oak_CallbackBool;\n" +
|
||||
" CMOCK_Oak_CALLBACK Oak_CallbackFunctionPointer;\n" +
|
||||
" int Oak_CallbackCalls;\n"
|
||||
returned = @cmock_generator_plugin_callback.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -41,7 +42,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
it "add mock function declaration for function without arguments" do
|
||||
function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int cmock_num_calls);\n",
|
||||
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -49,7 +52,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
it "add mock function declaration for function without arguments when count is also turned off" do
|
||||
function = {:name => "Maple", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(void);\n",
|
||||
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -58,7 +63,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
it "add mock function declaration for function with arguments" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:void]}
|
||||
expected = [ "typedef void (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n",
|
||||
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -66,7 +73,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
it "add mock function declaration for function with return values" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]}
|
||||
expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu, int cmock_num_calls);\n",
|
||||
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
@@ -74,7 +83,9 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
it "add mock function declaration for function with return values and count is turned off" do
|
||||
function = {:name => "Maple", :args_string => "int* tofu", :args => [1], :return => test_return[:string]}
|
||||
expected = [ "typedef const char* (* CMOCK_Maple_CALLBACK)(int* tofu);\n",
|
||||
"void Maple_StubWithCallback(CMOCK_Maple_CALLBACK Callback);\n" ].join
|
||||
"void Maple_AddCallback(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"void Maple_Stub(CMOCK_Maple_CALLBACK Callback);\n",
|
||||
"#define Maple_StubWithCallback Maple_Stub\n" ].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -87,7 +98,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -99,7 +110,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -110,7 +121,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" cmock_call_instance->ReturnVal = Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -125,7 +136,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -141,7 +152,7 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -156,31 +167,36 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
" cmock_call_instance->ReturnVal = Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_after_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'void func(void)' when count turned off" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer();\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_without_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions without arg check and of style 'int func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" int cmock_cb_ret = Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_cb_ret;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_without_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -190,13 +206,15 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_without_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -206,14 +224,16 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return=> test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_without_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -223,12 +243,15 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
{ :type => 'uint8_t', :name => 'flag', :ptr? => false} ],
|
||||
:args_string => "int* steak, uint8_t flag",
|
||||
:return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
expected = [" if (!Mock.Apple_CallbackBool &&\n",
|
||||
" Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" int cmock_cb_ret = Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
" return cmock_cb_ret;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_for_callbacks_without_arg_check(function)
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -239,21 +262,20 @@ describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Modu
|
||||
:return => test_return[:int]
|
||||
}
|
||||
|
||||
expected = ["void Lemon_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
expected = ["void Lemon_AddCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_IgnoreBool = (int)0;\n",
|
||||
" Mock.Lemon_CallbackBool = (int)1;\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
"}\n\n",
|
||||
"void Lemon_Stub(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\n",
|
||||
" Mock.Lemon_IgnoreBool = (int)0;\n",
|
||||
" Mock.Lemon_CallbackBool = (int)0;\n",
|
||||
" Mock.Lemon_CallbackFunctionPointer = Callback;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock destroy for functions" do
|
||||
function = {:name => "Peach", :args => [], :return => test_return[:void] }
|
||||
expected = " Mock.Peach_CallbackFunctionPointer = NULL;\n" +
|
||||
" Mock.Peach_CallbackCalls = 0;\n"
|
||||
returned = @cmock_generator_plugin_callback.mock_destroy(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,7 +119,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -136,7 +135,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"mock_retval_2",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -153,7 +151,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
"mock_retval_2",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -168,7 +165,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
"{\n",
|
||||
"mock_retval_0 ",
|
||||
"mock_retval_1 ",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
@@ -179,7 +175,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " UNITY_SET_DETAIL(CMockString_Banana);\n" +
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, CMockStringCalledLess);\n"
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" +
|
||||
" UNITY_CLR_DETAILS();\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -26,15 +26,22 @@ describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAn
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "ignore functions without arguments" do
|
||||
function = {:name => "Mold", :args_string => "void", :args => [], :return => test_return[:void]}
|
||||
expected = ""
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
function = {:name => "Mold", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]}
|
||||
expected = "#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\nvoid Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "handle function declarations for functions that returns something" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
|
||||
function = {:name => "Fungus", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:string]}
|
||||
expected = "#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+
|
||||
"void Fungus_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
|
||||
@@ -46,11 +53,11 @@ describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAn
|
||||
end
|
||||
|
||||
it "add a new mock interface for ignoring when function had no return value" do
|
||||
function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
function = {:name => "Slime", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]}
|
||||
expected = ["void Slime_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n",
|
||||
" cmock_call_instance->ExpectAnyArgsBool = (int)1;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", true]
|
||||
|
||||
@@ -98,7 +98,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_1\n", [function, function[:args][0]]
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_2\n", [function, function[:args][1]]
|
||||
expected = " if (cmock_call_instance->IgnoreMode != CMOCK_ARG_NONE)\n" +
|
||||
expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
|
||||
" {\n" +
|
||||
"mocked_retval_1\n" +
|
||||
"mocked_retval_2\n" +
|
||||
@@ -118,7 +118,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
it "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do
|
||||
function = {:name => "Apple", :args => [{ :type => "int", :name => "worm" }], :return => test_return[:void]}
|
||||
@utils.expect :code_verify_an_arg_expectation, "mocked_retval_0\n", [function, function[:args][0]]
|
||||
expected = " if (cmock_call_instance->IgnoreMode != CMOCK_ARG_NONE)\n" +
|
||||
expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
|
||||
" {\n" +
|
||||
"mocked_retval_0\n" +
|
||||
" }\n"
|
||||
@@ -135,7 +135,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -152,7 +151,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"mock_retval_2\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -169,7 +167,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
"mock_retval_2\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect.mock_interfaces(function)
|
||||
@@ -184,7 +181,6 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
"{\n",
|
||||
"mock_retval_0\n",
|
||||
"mock_retval_1\n",
|
||||
" UNITY_CLR_DETAILS();\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@cmock_generator_plugin_expect.ordered = true
|
||||
@@ -195,7 +191,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
it "add mock verify lines" do
|
||||
function = {:name => "Banana" }
|
||||
expected = " UNITY_SET_DETAIL(CMockString_Banana);\n" +
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == Mock.Banana_CallInstance, cmock_line, CMockStringCalledLess);\n"
|
||||
" UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" +
|
||||
" UNITY_CLR_DETAILS();\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_verify(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
|
||||
expected =
|
||||
"#define Pine_ReturnThruPtr_tofu(tofu)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(*tofu))\n" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(int))\n" +
|
||||
"#define Pine_ReturnArrayThruPtr_tofu(tofu, cmock_len)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (int)(cmock_len * (int)sizeof(*tofu)))\n" +
|
||||
"#define Pine_ReturnMemThruPtr_tofu(tofu, cmock_size)" +
|
||||
|
||||
@@ -106,7 +106,8 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n"
|
||||
|
||||
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
|
||||
expected4 = " memcpy(&cmock_call_instance->Expected_Lime, &Lime, sizeof(LIME_T));\n"
|
||||
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
|
||||
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n"
|
||||
|
||||
assert_equal(expected1, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg1))
|
||||
assert_equal(expected2, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg2))
|
||||
@@ -131,7 +132,8 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
" cmock_call_instance->ReturnThruPtr_Kiwi_Used = 0;\n"
|
||||
|
||||
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
|
||||
expected4 = " memcpy(&cmock_call_instance->Expected_Lime, &Lime, sizeof(LIME_T));\n" +
|
||||
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
|
||||
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->IgnoreArg_Lime = 0;\n"
|
||||
|
||||
assert_equal(expected1, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg1))
|
||||
@@ -151,9 +153,11 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff);\n" +
|
||||
"void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
|
||||
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
|
||||
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
|
||||
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
|
||||
@@ -164,12 +168,14 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr)\n{\n" +
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr);\n" +
|
||||
"void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyIntPtr = 0;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" +
|
||||
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
|
||||
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
|
||||
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyMyType = 0;\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyStr = 0;\n" +
|
||||
@@ -182,7 +188,8 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:const_ptr], test_arg[:double_ptr]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth)\n{\n" +
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth);\n" +
|
||||
"void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr = MyConstPtr;\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr_Depth = MyConstPtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyConstPtr = 0;\n" +
|
||||
@@ -294,7 +301,9 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
|
||||
" if (cmock_call_instance->Expected_MyInt != MyInt) {\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT',''], ['int']
|
||||
@@ -307,12 +316,14 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyIntPtr != MyIntPtr) {\n" +
|
||||
" if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''], ['int*']
|
||||
@@ -325,7 +336,9 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyStr != MyStr) {\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
|
||||
@@ -338,10 +351,12 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyType != MyMyType) {\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyType == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(cmock_call_instance->Expected_MyMyType), (void*)(MyMyType), sizeof(MY_TYPE), 1, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY', ''], ['MY_TYPE']
|
||||
@@ -354,7 +369,9 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyType != MyMyType) {\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE', ''], ['MY_TYPE']
|
||||
@@ -367,12 +384,14 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyTypePtr);\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyTypePtr != MyMyTypePtr) {\n" +
|
||||
" if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
|
||||
" { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, CMockStringExpNULL); }\n" +
|
||||
" else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, CMockStringMismatch); }\n" +
|
||||
" else\n" +
|
||||
" { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, CMockStringMismatch); }\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', ''], ['MY_TYPE*']
|
||||
@@ -385,7 +404,9 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
|
||||
" {\n" +
|
||||
" UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
|
||||
" if (&cmock_call_instance->Expected_MyMyType != &MyMyType) {\n" +
|
||||
" UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', '&'], ['MY_TYPE']
|
||||
|
||||
@@ -19,9 +19,13 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
@config.expect :c_calling_conventions, ['__stdcall']
|
||||
@config.expect :treat_as_void, ['MY_FUNKY_VOID']
|
||||
@config.expect :treat_as, { "BANJOS" => "INT", "TUBAS" => "HEX16"}
|
||||
@config.expect :treat_as_array, {"IntArray" => "int", "Book" => "Page"}
|
||||
@config.expect :when_no_prototypes, :error
|
||||
@config.expect :verbosity, 1
|
||||
@config.expect :treat_externs, :exclude
|
||||
@config.expect :treat_inlines, :exclude
|
||||
@config.expect :array_size_type, ['int', 'size_t']
|
||||
@config.expect :array_size_name, 'size|len'
|
||||
|
||||
@parser = CMockHeaderParser.new(@config)
|
||||
end
|
||||
@@ -450,6 +454,60 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
it "leave inline functions if inline to be included" do
|
||||
source =
|
||||
"extern uint32 foobar(unsigned int);\n" +
|
||||
"uint32 extern_name_func(unsigned int);\n" +
|
||||
"uint32 funcinline(unsigned int);\n" +
|
||||
"inline void inlineBar(unsigned int);\n" +
|
||||
"extern int extern_bar(void);\n" +
|
||||
"static inline void staticinlineBar(unsigned int);\n" +
|
||||
"static inline void bar(unsigned int);\n" +
|
||||
"static inline void bar(unsigned int)\n" +
|
||||
"{\n" +
|
||||
" // NOP\n" +
|
||||
"}\n"
|
||||
|
||||
expected =
|
||||
[ "uint32 extern_name_func(unsigned int)",
|
||||
"uint32 funcinline(unsigned int)",
|
||||
"void inlineBar(unsigned int)",
|
||||
"void staticinlineBar(unsigned int)",
|
||||
"void bar(unsigned int)"
|
||||
]
|
||||
|
||||
@parser.treat_inlines = :include
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
it "leave inline and extern functions if inline and extern to be included" do
|
||||
source =
|
||||
"extern uint32 foobar(unsigned int);\n" +
|
||||
"uint32 extern_name_func(unsigned int);\n" +
|
||||
"uint32 funcinline(unsigned int);\n" +
|
||||
"inline void inlineBar(unsigned int);\n" +
|
||||
"extern int extern_bar(void);\n" +
|
||||
"static inline void staticinlineBar(unsigned int);\n" +
|
||||
"static inline void bar(unsigned int);\n" +
|
||||
"static inline void bar(unsigned int)\n" +
|
||||
"{\n" +
|
||||
" // NOP\n" +
|
||||
"}\n"
|
||||
|
||||
expected =
|
||||
[ "extern uint32 foobar(unsigned int)",
|
||||
"uint32 extern_name_func(unsigned int)",
|
||||
"uint32 funcinline(unsigned int)",
|
||||
"void inlineBar(unsigned int)",
|
||||
"extern int extern_bar(void)",
|
||||
"void staticinlineBar(unsigned int)",
|
||||
"void bar(unsigned int)"
|
||||
]
|
||||
|
||||
@parser.treat_externs = :include
|
||||
@parser.treat_inlines = :include
|
||||
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})
|
||||
end
|
||||
|
||||
it "remove defines" do
|
||||
source =
|
||||
@@ -949,6 +1007,32 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
it "converts typedef'd array arguments to pointers" do
|
||||
|
||||
source = "Book AddToBook(Book book, const IntArray values);\n"
|
||||
|
||||
expected = [{ :name => "AddToBook",
|
||||
:modifier=>"",
|
||||
:return => { :type => "Book",
|
||||
:name => "cmock_to_return",
|
||||
:str => "Book cmock_to_return",
|
||||
:void? => false,
|
||||
:ptr? => false,
|
||||
:const? => false,
|
||||
:const_ptr? => false
|
||||
},
|
||||
:var_arg => nil,
|
||||
:args => [{ :type => "Page*", :name => "book", :ptr? => true, :const? => false, :const_ptr? => false },
|
||||
{ :type => "const int*", :name => "values", :ptr? => true, :const? => true, :const_ptr? => false }],
|
||||
:args_string => "Book book, const IntArray values",
|
||||
:args_call => "book, values",
|
||||
:contains_ptr? => true
|
||||
}]
|
||||
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
|
||||
end
|
||||
|
||||
it "properly detect typedef'd variants of void and use those" do
|
||||
|
||||
source = "typedef (void) FUNKY_VOID_T;\n" +
|
||||
@@ -1696,4 +1780,221 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
end
|
||||
end
|
||||
|
||||
it "Transform inline functions doesn't change a header with no inlines" do
|
||||
source =
|
||||
"#ifndef _NOINCLUDES\n" +
|
||||
"#define _NOINCLUDES\n" +
|
||||
"#include \"unity.h\"\n" +
|
||||
"#include \"cmock.h\"\n" +
|
||||
"#include \"YetAnotherHeader.h\"\n" +
|
||||
"\n" +
|
||||
"/* Ignore the following warnings since we are copying code */\n" +
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n" +
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n" +
|
||||
"#pragma GCC diagnostic push\n" +
|
||||
"#endif\n" +
|
||||
"#if !defined(__clang__)\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n" +
|
||||
"#endif\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n" +
|
||||
"#endif\n" +
|
||||
"\n" +
|
||||
"struct my_struct {\n" +
|
||||
"int a;\n" +
|
||||
"int b;\n" +
|
||||
"int b;\n" +
|
||||
"char c;\n" +
|
||||
"};\n" +
|
||||
"int my_function(int a);\n" +
|
||||
"int my_better_function(struct my_struct *s);\n" +
|
||||
"\n" +
|
||||
"#endif _NOINCLUDES\n"
|
||||
|
||||
assert_equal(source, @parser.transform_inline_functions(source))
|
||||
end
|
||||
|
||||
it "Transform inline functions changes inline functions to function declarations" do
|
||||
source =
|
||||
"#ifndef _NOINCLUDES\n" +
|
||||
"#define _NOINCLUDES\n" +
|
||||
"#include \"unity.h\"\n" +
|
||||
"#include \"cmock.h\"\n" +
|
||||
"#include \"YetAnotherHeader.h\"\n" +
|
||||
"\n" +
|
||||
"/* Ignore the following warnings since we are copying code */\n" +
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n" +
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n" +
|
||||
"#pragma GCC diagnostic push\n" +
|
||||
"#endif\n" +
|
||||
"#if !defined(__clang__)\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n" +
|
||||
"#endif\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n" +
|
||||
"#endif\n" +
|
||||
"\n" +
|
||||
"struct my_struct {\n" +
|
||||
"int a;\n" +
|
||||
"int b;\n" +
|
||||
"int b;\n" +
|
||||
"char c;\n" +
|
||||
"};\n" +
|
||||
"int my_function(int a);\n" +
|
||||
"int my_better_function(struct my_struct *s);\n" +
|
||||
"static inline int staticinlinebar(struct my_struct *s)\n" + # This is a function with a lot of indentation levels, we should be able to handle it
|
||||
"{\n" +
|
||||
"\t{\n" +
|
||||
"\t\t{\n" +
|
||||
"\t\t\treturn s->a;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t}\n" +
|
||||
"}\n" +
|
||||
"static inline int staticinlinefunc(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return s->a;\n" +
|
||||
"}\n" +
|
||||
"int bar(struct my_struct *s);\n" + # A normal function to screw with our parser
|
||||
"inline static int inlinestaticfunc(int a) {\n" +
|
||||
" return a + 42;\n" +
|
||||
"}\n" +
|
||||
"inline int StaticInlineFunc(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return get_member_a(s) + 42;\n" +
|
||||
"}\n" +
|
||||
"int inline StaticInlineBar(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return get_member_a(s) + 42;\n" +
|
||||
"}\n" +
|
||||
"struct staticinlinestruct {\n" + # Add a structure declaration between the inline functions, just to make sure we don't touch it!
|
||||
"int a;\n" +
|
||||
"};\n" +
|
||||
"\n" +
|
||||
"struct staticinlinestruct fubarstruct(struct my_struct *s);\n" + # Another normal function to screw with our parser
|
||||
"static inline struct staticinlinestruct inlinefubarfunction(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return (struct staticinlinestruct)*s;\n" +
|
||||
"}\n" +
|
||||
"int fubar(struct my_struct *s);\n" + # Another normal function to screw with our parser
|
||||
"inline int stuff(int num)" +
|
||||
"{" +
|
||||
" int reg = 0x12;" +
|
||||
" if (num > 0)" +
|
||||
" {" +
|
||||
" reg |= (0x0Eu);" +
|
||||
" }" +
|
||||
" else" +
|
||||
" {" +
|
||||
" reg |= (0x07u);" +
|
||||
" }" +
|
||||
" return reg;" +
|
||||
"}" +
|
||||
"\n" +
|
||||
"int inline static dummy_func_2(int a, char b, float c) {" + # This is a sneaky one, inline static is placed AFTER the return value
|
||||
" c += 3.14;" +
|
||||
" b -= 32;" +
|
||||
" return a + (int)(b) + (int)c;" +
|
||||
"}" +
|
||||
"#endif _NOINCLUDES\n"
|
||||
|
||||
expected =
|
||||
"#ifndef _NOINCLUDES\n" +
|
||||
"#define _NOINCLUDES\n" +
|
||||
"#include \"unity.h\"\n" +
|
||||
"#include \"cmock.h\"\n" +
|
||||
"#include \"YetAnotherHeader.h\"\n" +
|
||||
"\n" +
|
||||
"/* Ignore the following warnings since we are copying code */\n" +
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n" +
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n" +
|
||||
"#pragma GCC diagnostic push\n" +
|
||||
"#endif\n" +
|
||||
"#if !defined(__clang__)\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n" +
|
||||
"#endif\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n" +
|
||||
"#endif\n" +
|
||||
"\n" +
|
||||
"struct my_struct {\n" +
|
||||
"int a;\n" +
|
||||
"int b;\n" +
|
||||
"int b;\n" +
|
||||
"char c;\n" +
|
||||
"};\n" +
|
||||
"int my_function(int a);\n" +
|
||||
"int my_better_function(struct my_struct *s);\n" +
|
||||
"int staticinlinebar(struct my_struct *s);\n" +
|
||||
"int staticinlinefunc(struct my_struct *s);\n" +
|
||||
"int bar(struct my_struct *s);\n" +
|
||||
"int inlinestaticfunc(int a);\n" +
|
||||
"int StaticInlineFunc(struct my_struct *s);\n" +
|
||||
"int StaticInlineBar(struct my_struct *s);\n" +
|
||||
"struct staticinlinestruct {\n" +
|
||||
"int a;\n" +
|
||||
"};\n" +
|
||||
"\n" +
|
||||
"struct staticinlinestruct fubarstruct(struct my_struct *s);\n" +
|
||||
"struct staticinlinestruct inlinefubarfunction(struct my_struct *s);\n" +
|
||||
"int fubar(struct my_struct *s);\n" +
|
||||
"int stuff(int num);\n" +
|
||||
"int dummy_func_2(int a, char b, float c);" +
|
||||
"#endif _NOINCLUDES\n"
|
||||
|
||||
assert_equal(expected, @parser.transform_inline_functions(source))
|
||||
end
|
||||
|
||||
it "Count number of pairs of braces in function succesfully" do
|
||||
source =
|
||||
"int foo(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return get_member_a(s) + 42;\n" +
|
||||
"}\n"
|
||||
complex_source =
|
||||
"int bar(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
"\tint a = 6;\n" +
|
||||
"\tint res = foo(&(struct my_struct){.nr = a});\n" +
|
||||
"\t{\n" +
|
||||
"\t\tint a = 5;\n" +
|
||||
"\t\tint res = foo(&(struct my_struct){.nr = a});\n" +
|
||||
"\t\t{\n" +
|
||||
"\t\t\tstruct my_struct a = {.nr = 1};\n" +
|
||||
"\t\t}\n" +
|
||||
"\t}\n" +
|
||||
"\treturn 42;\n" +
|
||||
"}\n"
|
||||
|
||||
assert_equal(1, @parser.count_number_of_pairs_of_braces_in_function(source))
|
||||
assert_equal(6, @parser.count_number_of_pairs_of_braces_in_function(complex_source))
|
||||
end
|
||||
|
||||
it "Count number of pairs of braces returns 0 if bad source is supplied" do
|
||||
bad_source_0 =
|
||||
"int foo(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
" return get_member_a(s) + 42;\n" +
|
||||
"\n" # Missing closing brace
|
||||
bad_source_1 =
|
||||
"int bar(struct my_struct *s)\n" +
|
||||
"{\n" +
|
||||
"\tint a = 6;\n" +
|
||||
"\tint res = foo(&(struct my_struct){.nr = a});\n" +
|
||||
"\t{\n" +
|
||||
"\t\tint a = 5;\n" +
|
||||
"\t\tint res = foo(&(struct my_struct){.nr = a});\n" +
|
||||
"\t\t{\n" +
|
||||
"\t\t\n" + # Missing closing brace
|
||||
"\t}\n" +
|
||||
"\treturn 42;\n" +
|
||||
"}\n"
|
||||
bad_source_2 =
|
||||
"int foo(struct my_struct *s)\n" +
|
||||
"\n" # No braces in source
|
||||
|
||||
assert_equal(0, @parser.count_number_of_pairs_of_braces_in_function(bad_source_0))
|
||||
assert_equal(0, @parser.count_number_of_pairs_of_braces_in_function(bad_source_1))
|
||||
assert_equal(0, @parser.count_number_of_pairs_of_braces_in_function(bad_source_2))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -21,8 +21,17 @@ describe CMockPluginManager, "Verify CMockPluginManager Module" do
|
||||
:ignore => :args_and_calls
|
||||
)
|
||||
|
||||
eval "class << @config\ndef plugins\n@plugins||[]\nend\ndef plugins=(val)\n@plugins=val\nend\nend\n"
|
||||
def @config.plugins
|
||||
if instance_variable_defined?(:@plugins)
|
||||
@plugins || []
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def @config.plugins=(val)
|
||||
@plugins = val
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/c_exception updated: dce9e8b26f...e78c5aacc7
Vendored
+1
-1
Submodule vendor/unity updated: 287e076962...c3d7662a1e
Reference in New Issue
Block a user