mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
- Added throwaway demo project
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@34 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ require "#{$here}/cmock_generator_utils"
|
||||
|
||||
class CMock
|
||||
|
||||
def initialize(mocks_path='mocks', includes=[], use_cexception=true, allow_ignore_mock=false)
|
||||
def initialize(mocks_path='mocks', includes=[], use_cexception=false, allow_ignore_mock=false)
|
||||
@mocks_path = mocks_path
|
||||
@includes = includes
|
||||
@use_cexception = use_cexception
|
||||
|
||||
+9
-2
@@ -15,12 +15,19 @@ COMPILER_CONFIGS = FileList.new('*.yml')
|
||||
CLEAN.include(SYSTEST_BUILD_DIR + '*.*')
|
||||
CLEAN.include(SYSTEST_MOCKS_DIR + '*.*')
|
||||
|
||||
task :default => [ :clobber, 'tests:all' ]
|
||||
task :default => [ :clobber, 'tests:all', :app ]
|
||||
|
||||
desc "Build and run application"
|
||||
task :app do
|
||||
COMPILER_CONFIGS.each do |cfg_file|
|
||||
build_and_run_application(yaml_read(cfg_file), 'MySwankApp')
|
||||
end
|
||||
end
|
||||
|
||||
namespace :tests do
|
||||
|
||||
desc "Run unit and system tests"
|
||||
task :all => [ 'units', 'system' ]
|
||||
task :all => ['units', 'system', 'app']
|
||||
|
||||
Rake::TestTask.new('units') do |t|
|
||||
t.pattern = 'test//unit/*_test.rb'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'yaml'
|
||||
require 'lib/cmock'
|
||||
|
||||
def Kernel.is_windows?
|
||||
processor, platform, *rest = RUBY_PLATFORM.split("-")
|
||||
@@ -103,6 +104,14 @@ module RakefileHelpers
|
||||
headers = extract_headers(test)
|
||||
|
||||
headers.each do |header|
|
||||
|
||||
if header =~ /^Mock(.*)\.h/i
|
||||
module_name = $1
|
||||
report "Generating mock for module #{module_name}..."
|
||||
cmock = CMock.new(mocks_path='test/system/mocks')
|
||||
cmock.setup_mocks("test/system/source/#{module_name}.h")
|
||||
end
|
||||
|
||||
compile(config, find_source_file(header))
|
||||
obj_list << header.ext(OBJ_EXTENSION)
|
||||
end
|
||||
@@ -116,5 +125,33 @@ module RakefileHelpers
|
||||
end
|
||||
end
|
||||
|
||||
def build_and_run_application(config, main)
|
||||
obj_list = []
|
||||
main_path = SYSTEST_SOURCE_DIR + main + '.c'
|
||||
executable_path = SYSTEST_BUILD_DIR + main + EXE_EXTENSION
|
||||
main_base = File.basename(main_path, C_EXTENSION)
|
||||
headers = extract_headers(main_path)
|
||||
|
||||
headers.each do |header|
|
||||
|
||||
if header =~ /^Mock(.*)\.h/i
|
||||
module_name = $1
|
||||
report "Generating mock for module #{module_name}..."
|
||||
cmock = CMock.new(mocks_path='test/system/mocks')
|
||||
cmock.setup_mocks("test/system/source/#{module_name}.h")
|
||||
end
|
||||
|
||||
compile(config, find_source_file(header))
|
||||
obj_list << header.ext(OBJ_EXTENSION)
|
||||
end
|
||||
|
||||
compile(config, main_path)
|
||||
obj_list << main_base.ext(OBJ_EXTENSION)
|
||||
|
||||
link(config, main_base, obj_list)
|
||||
|
||||
execute(SYSTEST_BUILD_DIR + main_base + EXE_EXTENSION)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include "Simple.h"
|
||||
#include "Stuff.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
Add(123, 456);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "Simple.h"
|
||||
#include "Stuff.h"
|
||||
|
||||
int Add(int a, int b)
|
||||
{
|
||||
return (a + b);
|
||||
int answer = a + b;
|
||||
ReportAnswer(answer);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void ReportAnswer(int answer)
|
||||
{
|
||||
printf("The answer is %d!\n", answer);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef _STUFF_H
|
||||
#define _STUFF_H
|
||||
|
||||
void ReportAnswer(int answer);
|
||||
|
||||
#endif // _STUFF_H
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "unity.h"
|
||||
#include "Simple.h"
|
||||
#include "MockStuff.h"
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
jmp_buf AbortFrame;
|
||||
|
||||
|
||||
@@ -17,23 +17,49 @@ void tearDown(void)
|
||||
|
||||
void test_Simple_Add_ShouldSumValues(void)
|
||||
{
|
||||
ReportAnswer_Expect(5);
|
||||
TEST_ASSERT_EQUAL( 5, Add( 2, 3));
|
||||
|
||||
ReportAnswer_Expect(5);
|
||||
TEST_ASSERT_EQUAL( 5, Add( 1, 4));
|
||||
|
||||
ReportAnswer_Expect(5);
|
||||
TEST_ASSERT_EQUAL( 5, Add( -2, 7));
|
||||
|
||||
ReportAnswer_Expect(100);
|
||||
TEST_ASSERT_EQUAL(100, Add( 25, 75));
|
||||
|
||||
ReportAnswer_Expect(-10);
|
||||
TEST_ASSERT_EQUAL(-10, Add(-90, 80));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// TEST SUPPORT
|
||||
|
||||
static void CMock_Init(void)
|
||||
{
|
||||
MockStuff_Init();
|
||||
}
|
||||
static void CMock_Verify(void)
|
||||
{
|
||||
MockStuff_Verify();
|
||||
}
|
||||
static void CMock_Destroy(void)
|
||||
{
|
||||
MockStuff_Destroy();
|
||||
}
|
||||
|
||||
static void runTest(UnityTestFunction test)
|
||||
{
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
CMock_Init();
|
||||
test();
|
||||
TEST_WRAP(CMock_Verify());
|
||||
CMock_Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Unity.TestFile = "SimpleTest.c";
|
||||
|
||||
Reference in New Issue
Block a user