1
0
mirror of https://github.com/ThrowTheSwitch/CMock synced 2025-05-19 02:09:33 -04:00

- drop cexception_include which is no longer needed

- correct which define needed to be long in cmock.c
- beefed up testing of unity TEST_IGNORE in relation to mocking

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@174 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord 2010-06-27 19:02:07 +00:00
parent 1f1c2a9ccf
commit 4a0df26994
8 changed files with 158 additions and 22 deletions

@ -15,7 +15,6 @@ class CMockConfig
:includes => [],
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
:enforce_strict_ordering => false,
:cexception_include => nil,
:unity_helper => false,
:treat_as => {},
:treat_as_void => [],

@ -13,12 +13,10 @@ class CMockGeneratorPluginCexception
@config = config
@utils = utils
@priority = 7
raise "'cexception_include' needs to be defined in config" unless @config.respond_to?(:cexception_include)
end
def include_files
return "#include \"#{@config.cexception_include || 'CException.h'}\"\n"
return "#include \"CException.h\"\n"
end
def instance_typedefs(function)

@ -256,11 +256,21 @@ module RakefileHelpers
tests.each_with_index do |test, index|
# compare test's intended pass/fail state with pass/fail state in actual results;
# if they don't match, the system test has failed
if ((test[:pass] and (test_results[index] =~ /:PASS/).nil?) or (!test[:pass] and (test_results[index] =~ /:FAIL/).nil?))
this_failed = case(test[:pass])
when :ignore
(test_results[index] =~ /:IGNORE/).nil?
when true
(test_results[index] =~ /:PASS/).nil?
when false
(test_results[index] =~ /:FAIL/).nil?
end
if (this_failed)
total_failures += 1
test_results[index] =~ /test#{index+1}:(.+)/
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}"
elsif (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/)
end
# some tests have additional requirements to check for (checking the actual output message)
if (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/)
total_failures += 1
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}'"
end

@ -19,12 +19,12 @@
//should be big enough to index full range of CMOCK_MEM_MAX
#ifndef CMOCK_MEM_INDEX_TYPE
#define CMOCK_MEM_INDEX_TYPE unsigned long
#define CMOCK_MEM_INDEX_TYPE unsigned int
#endif
//this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type
#ifndef CMOCK_MEM_PTR_AS_INT
#define CMOCK_MEM_PTR_AS_INT unsigned int
#define CMOCK_MEM_PTR_AS_INT unsigned long
#endif
//0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit

@ -0,0 +1,139 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 foo(UINT32 a);
void bar(void);
:source:
:header: |
UINT32 function_a(int a);
void function_b(void);
:code: |
UINT32 function_a(int a)
{
bar();
return foo((UINT32)a);
}
void function_b(void)
{
bar();
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: :ignore
:should: 'ignore incorrect expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore missing expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore no expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call even if it happens later'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(30);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are missing expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore if extra expects before the TEST_IGNORE because it ignored the rest of the test that might have made calls to it'
:code: |
test()
{
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
...

@ -20,7 +20,7 @@ class CMockConfigTest < Test::Unit::TestCase
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include)
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
end
should "replace only options specified in a hash" do
@ -31,16 +31,15 @@ class CMockConfigTest < Test::Unit::TestCase
assert_equal(test_includes, config.includes)
assert_equal(test_attributes, config.attributes)
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
assert_equal(CMockConfig::CMockDefaultOptions[:cexception_include], config.cexception_include)
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
end
should "replace only options specified in a yaml file" do
test_plugins = [:soda, :pizza]
test_include = 'MySillyException.h'
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
assert_equal(test_plugins, config.plugins)
assert_equal(test_include, config.cexception_include)
assert_equal(:include, config.treat_externs)
end
end

@ -2,4 +2,4 @@
:plugins:
- 'soda'
- 'pizza'
:cexception_include: 'MySillyException.h'
:treat_externs: :include

@ -10,7 +10,6 @@ require 'cmock_generator_plugin_cexception'
class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
def setup
create_mocks :config, :utils
@config.stubs!(:respond_to?).returns(true)
@cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
end
@ -25,14 +24,6 @@ class CMockGeneratorPluginCexceptionTest < Test::Unit::TestCase
should "include the cexception library" do
expected = "#include \"CException.h\"\n"
@config.expect.cexception_include.returns(nil)
returned = @cmock_generator_plugin_cexception.include_files
assert_equal(expected, returned)
end
should "include the cexception library with a custom path if specified" do
expected = "#include \"../cexception/lib/CException.h\"\n"
@config.expect.cexception_include.returns("../cexception/lib/CException.h")
returned = @cmock_generator_plugin_cexception.include_files
assert_equal(expected, returned)
end