mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
fixed white space
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
|
||||
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: 'src/'
|
||||
unit_tests_path: &unit_tests_path 'test/'
|
||||
build_path: &build_path 'build/'
|
||||
options:
|
||||
- -c
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
- __monitor
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.o'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: gcc
|
||||
options:
|
||||
- -lm
|
||||
includes:
|
||||
prefix: '-I'
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.exe'
|
||||
destination: *build_path
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
colour: true
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: 'src/'
|
||||
unit_tests_path: &unit_tests_path 'test/'
|
||||
build_path: &build_path 'build/'
|
||||
options:
|
||||
- -c
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
- __monitor
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.o'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: gcc
|
||||
options:
|
||||
- -lm
|
||||
includes:
|
||||
prefix: '-I'
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.exe'
|
||||
destination: *build_path
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0 Kickstart\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: 'src\'
|
||||
unit_tests_path: &unit_tests_path 'test\'
|
||||
build_path: &build_path 'build\'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\lib\dl4tptinl8n.h']
|
||||
- -z3
|
||||
- --no_cse
|
||||
- --no_unroll
|
||||
- --no_inline
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian little
|
||||
- --cpu ARM7TDMI
|
||||
- --stack_align 4
|
||||
- --interwork
|
||||
- -e
|
||||
- --silent
|
||||
- --warnings_are_errors
|
||||
- --fpu None
|
||||
- --diag_suppress Pa050
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: [*tools_root, 'common\bin\xlink.exe']
|
||||
options:
|
||||
- -rt
|
||||
- [*tools_root, 'arm\lib\dl4tptinl8n.r79']
|
||||
- -D_L_EXTMEM_START=0
|
||||
- -D_L_EXTMEM_SIZE=0
|
||||
- -D_L_HEAP_SIZE=120
|
||||
- -D_L_STACK_SIZE=32
|
||||
- -e_small_write=_formatted_write
|
||||
- -s
|
||||
- __program_start
|
||||
- -f
|
||||
- [*tools_root, '\arm\config\lnkarm.xcl']
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- [*tools_root, 'arm\config\']
|
||||
- [*tools_root, 'arm\lib\']
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.r79'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.d79'
|
||||
destination: *build_path
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
- --silent
|
||||
- [*tools_root, 'arm\bin\armproc.dll']
|
||||
- [*tools_root, 'arm\bin\armsim.dll']
|
||||
post_support:
|
||||
- --plugin
|
||||
- [*tools_root, 'arm\bin\armbat.dll']
|
||||
- --backend
|
||||
- -B
|
||||
- -p
|
||||
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0 Kickstart\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: 'src\'
|
||||
unit_tests_path: &unit_tests_path 'test\'
|
||||
build_path: &build_path 'build\'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\lib\dl4tptinl8n.h']
|
||||
- -z3
|
||||
- --no_cse
|
||||
- --no_unroll
|
||||
- --no_inline
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian little
|
||||
- --cpu ARM7TDMI
|
||||
- --stack_align 4
|
||||
- --interwork
|
||||
- -e
|
||||
- --silent
|
||||
- --warnings_are_errors
|
||||
- --fpu None
|
||||
- --diag_suppress Pa050
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: [*tools_root, 'common\bin\xlink.exe']
|
||||
options:
|
||||
- -rt
|
||||
- [*tools_root, 'arm\lib\dl4tptinl8n.r79']
|
||||
- -D_L_EXTMEM_START=0
|
||||
- -D_L_EXTMEM_SIZE=0
|
||||
- -D_L_HEAP_SIZE=120
|
||||
- -D_L_STACK_SIZE=32
|
||||
- -e_small_write=_formatted_write
|
||||
- -s
|
||||
- __program_start
|
||||
- -f
|
||||
- [*tools_root, '\arm\config\lnkarm.xcl']
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- [*tools_root, 'arm\config\']
|
||||
- [*tools_root, 'arm\lib\']
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.r79'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.d79'
|
||||
destination: *build_path
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
- --silent
|
||||
- [*tools_root, 'arm\bin\armproc.dll']
|
||||
- [*tools_root, 'arm\bin\armsim.dll']
|
||||
post_support:
|
||||
- --plugin
|
||||
- [*tools_root, 'arm\bin\armbat.dll']
|
||||
- --backend
|
||||
- -B
|
||||
- -p
|
||||
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: 'src\'
|
||||
unit_tests_path: &unit_tests_path 'test\'
|
||||
build_path: &build_path 'build\'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\inc\DLib_Config_Normal.h']
|
||||
- --no_cse
|
||||
- --no_unroll
|
||||
- --no_inline
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian=little
|
||||
- --cpu=ARM7TDMI
|
||||
- --interwork
|
||||
- --warnings_are_errors
|
||||
- --fpu=None
|
||||
- --diag_suppress=Pa050
|
||||
- --diag_suppress=Pe111
|
||||
- -e
|
||||
- -On
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: [*tools_root, 'arm\bin\ilinkarm.exe']
|
||||
options:
|
||||
- --redirect _Printf=_PrintfLarge
|
||||
- --redirect _Scanf=_ScanfSmall
|
||||
- --semihosting
|
||||
- --entry __iar_program_start
|
||||
- --config
|
||||
- [*tools_root, 'arm\config\generic.icf']
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.out'
|
||||
destination: *build_path
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
- --silent
|
||||
- [*tools_root, 'arm\bin\armproc.dll']
|
||||
- [*tools_root, 'arm\bin\armsim.dll']
|
||||
post_support:
|
||||
- --plugin
|
||||
- [*tools_root, 'arm\bin\armbat.dll']
|
||||
- --backend
|
||||
- -B
|
||||
- -p
|
||||
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
|
||||
compiler:
|
||||
path: [*tools_root, 'arm\bin\iccarm.exe']
|
||||
source_path: 'src\'
|
||||
unit_tests_path: &unit_tests_path 'test\'
|
||||
build_path: &build_path 'build\'
|
||||
options:
|
||||
- --dlib_config
|
||||
- [*tools_root, 'arm\inc\DLib_Config_Normal.h']
|
||||
- --no_cse
|
||||
- --no_unroll
|
||||
- --no_inline
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian=little
|
||||
- --cpu=ARM7TDMI
|
||||
- --interwork
|
||||
- --warnings_are_errors
|
||||
- --fpu=None
|
||||
- --diag_suppress=Pa050
|
||||
- --diag_suppress=Pe111
|
||||
- -e
|
||||
- -On
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: [*tools_root, 'arm\bin\ilinkarm.exe']
|
||||
options:
|
||||
- --redirect _Printf=_PrintfLarge
|
||||
- --redirect _Scanf=_ScanfSmall
|
||||
- --semihosting
|
||||
- --entry __iar_program_start
|
||||
- --config
|
||||
- [*tools_root, 'arm\config\generic.icf']
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.out'
|
||||
destination: *build_path
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
- --silent
|
||||
- [*tools_root, 'arm\bin\armproc.dll']
|
||||
- [*tools_root, 'arm\bin\armsim.dll']
|
||||
post_support:
|
||||
- --plugin
|
||||
- [*tools_root, 'arm\bin\armbat.dll']
|
||||
- --backend
|
||||
- -B
|
||||
- -p
|
||||
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
|
||||
- -d
|
||||
- sim
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
|
||||
|
||||
require 'rake'
|
||||
require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
require './rakefile_helper'
|
||||
|
||||
include RakefileHelpers
|
||||
|
||||
# Load default configuration, for now
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :unit do
|
||||
run_tests(get_unit_test_files)
|
||||
end
|
||||
|
||||
desc "Generate test summary"
|
||||
task :summary do
|
||||
report_summary
|
||||
end
|
||||
|
||||
desc "Build and test Unity"
|
||||
task :all => [:clean, :unit, :summary]
|
||||
task :default => [:clobber, :all]
|
||||
task :ci => [:default]
|
||||
task :cruise => [:default]
|
||||
|
||||
desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
configure_toolchain(args[:config_file])
|
||||
end
|
||||
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
|
||||
|
||||
require 'rake'
|
||||
require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
require './rakefile_helper'
|
||||
|
||||
include RakefileHelpers
|
||||
|
||||
# Load default configuration, for now
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
task :unit do
|
||||
run_tests(get_unit_test_files)
|
||||
end
|
||||
|
||||
desc "Generate test summary"
|
||||
task :summary do
|
||||
report_summary
|
||||
end
|
||||
|
||||
desc "Build and test Unity"
|
||||
task :all => [:clean, :unit, :summary]
|
||||
task :default => [:clobber, :all]
|
||||
task :ci => [:default]
|
||||
task :cruise => [:default]
|
||||
|
||||
desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
configure_toolchain(args[:config_file])
|
||||
end
|
||||
|
||||
@@ -1,270 +1,270 @@
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require '../vendor/unity/auto/unity_test_summary'
|
||||
require '../vendor/unity/auto/generate_test_runner'
|
||||
require '../vendor/unity/auto/colour_reporter'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
def load_configuration(config_file)
|
||||
$cfg_file = config_file
|
||||
$cfg = YAML.load(File.read($cfg_file))
|
||||
$colour_output = false unless $cfg['colour']
|
||||
end
|
||||
|
||||
def configure_clean
|
||||
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
|
||||
end
|
||||
|
||||
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
|
||||
config_file += '.yml' unless config_file =~ /\.yml$/
|
||||
load_configuration(config_file)
|
||||
configure_clean
|
||||
end
|
||||
|
||||
def get_unit_test_files
|
||||
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
|
||||
path.gsub!(/\\/, '/')
|
||||
FileList.new(path)
|
||||
end
|
||||
|
||||
def get_local_include_dirs
|
||||
include_dirs = $cfg['compiler']['includes']['items'].dup
|
||||
include_dirs.delete_if {|dir| dir.is_a?(Array)}
|
||||
return include_dirs
|
||||
end
|
||||
|
||||
def extract_headers(filename)
|
||||
includes = []
|
||||
lines = File.readlines(filename)
|
||||
lines.each do |line|
|
||||
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
|
||||
if not m.nil?
|
||||
includes << m[1]
|
||||
end
|
||||
end
|
||||
return includes
|
||||
end
|
||||
|
||||
def find_source_file(header, paths)
|
||||
paths.each do |dir|
|
||||
src_file = dir + header.ext(C_EXTENSION)
|
||||
if (File.exists?(src_file))
|
||||
return src_file
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def tackit(strings)
|
||||
case(strings)
|
||||
when Array
|
||||
"\"#{strings.join}\""
|
||||
when /^-/
|
||||
strings
|
||||
when /\s/
|
||||
"\"#{strings}\""
|
||||
else
|
||||
strings
|
||||
end
|
||||
end
|
||||
|
||||
def squash(prefix, items)
|
||||
result = ''
|
||||
items.each { |item| result += " #{prefix}#{tackit(item)}" }
|
||||
return result
|
||||
end
|
||||
|
||||
def build_compiler_fields
|
||||
command = tackit($cfg['compiler']['path'])
|
||||
if $cfg['compiler']['defines']['items'].nil?
|
||||
defines = ''
|
||||
else
|
||||
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
|
||||
end
|
||||
options = squash('', $cfg['compiler']['options'])
|
||||
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||
return {:command => command, :defines => defines, :options => options, :includes => includes}
|
||||
end
|
||||
|
||||
def compile(file, defines=[])
|
||||
compiler = build_compiler_fields
|
||||
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " +
|
||||
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
|
||||
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
|
||||
execute(cmd_str + obj_file)
|
||||
return obj_file
|
||||
end
|
||||
|
||||
def build_linker_fields
|
||||
command = tackit($cfg['linker']['path'])
|
||||
if $cfg['linker']['options'].nil?
|
||||
options = ''
|
||||
else
|
||||
options = squash('', $cfg['linker']['options'])
|
||||
end
|
||||
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
|
||||
includes = ''
|
||||
else
|
||||
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
||||
end
|
||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||
return {:command => command, :options => options, :includes => includes}
|
||||
end
|
||||
|
||||
def link_it(exe_name, obj_list)
|
||||
linker = build_linker_fields
|
||||
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
|
||||
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join +
|
||||
$cfg['linker']['bin_files']['prefix'] + ' ' +
|
||||
$cfg['linker']['bin_files']['destination'] +
|
||||
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
|
||||
execute(cmd_str)
|
||||
end
|
||||
|
||||
def build_simulator_fields
|
||||
return nil if $cfg['simulator'].nil?
|
||||
if $cfg['simulator']['path'].nil?
|
||||
command = ''
|
||||
else
|
||||
command = (tackit($cfg['simulator']['path']) + ' ')
|
||||
end
|
||||
if $cfg['simulator']['pre_support'].nil?
|
||||
pre_support = ''
|
||||
else
|
||||
pre_support = squash('', $cfg['simulator']['pre_support'])
|
||||
end
|
||||
if $cfg['simulator']['post_support'].nil?
|
||||
post_support = ''
|
||||
else
|
||||
post_support = squash('', $cfg['simulator']['post_support'])
|
||||
end
|
||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
||||
end
|
||||
|
||||
def execute(command_string, verbose=true)
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||
if $?.exitstatus != 0
|
||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(HERE)
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
report summary.run
|
||||
raise "There were failures" if (summary.failures > 0)
|
||||
end
|
||||
|
||||
def run_tests(test_files)
|
||||
|
||||
report 'Running system tests...'
|
||||
|
||||
# Tack on TEST define for compiling unit tests
|
||||
load_configuration($cfg_file)
|
||||
test_defines = ['TEST']
|
||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||
$cfg['compiler']['defines']['items'] << 'TEST'
|
||||
|
||||
include_dirs = get_local_include_dirs
|
||||
|
||||
# Build and execute each unit test
|
||||
test_files.each do |test|
|
||||
obj_list = []
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
header_list = extract_headers(test) + ['cmock.h']
|
||||
header_list.each do |header|
|
||||
|
||||
#create mocks if needed
|
||||
if (header =~ /Mock/)
|
||||
require "../lib/cmock.rb"
|
||||
@cmock ||= CMock.new($cfg_file)
|
||||
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#compile all mocks
|
||||
header_list.each do |header|
|
||||
#compile source file header if it exists
|
||||
src_file = find_source_file(header, include_dirs)
|
||||
if !src_file.nil?
|
||||
obj_list << compile(src_file, test_defines)
|
||||
end
|
||||
end
|
||||
|
||||
# Build the test runner (generate if configured to do so)
|
||||
test_base = File.basename(test, C_EXTENSION)
|
||||
runner_name = test_base + '_Runner.c'
|
||||
if $cfg['compiler']['runner_path'].nil?
|
||||
runner_path = $cfg['compiler']['build_path'] + runner_name
|
||||
test_gen = UnityTestRunnerGenerator.new($cfg_file)
|
||||
test_gen.run(test, runner_path)
|
||||
else
|
||||
runner_path = $cfg['compiler']['runner_path'] + runner_name
|
||||
end
|
||||
|
||||
obj_list << compile(runner_path, test_defines)
|
||||
|
||||
# Build the test module
|
||||
obj_list << compile(test, test_defines)
|
||||
|
||||
# Link the test executable
|
||||
link_it(test_base, obj_list)
|
||||
|
||||
# Execute unit test and generate results file
|
||||
simulator = build_simulator_fields
|
||||
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
|
||||
if simulator.nil?
|
||||
cmd_str = executable
|
||||
else
|
||||
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
||||
end
|
||||
output = execute(cmd_str)
|
||||
test_results = $cfg['compiler']['build_path'] + test_base
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
else
|
||||
test_results += '.testpass'
|
||||
end
|
||||
File.open(test_results, 'w') { |f| f.print output }
|
||||
end
|
||||
end
|
||||
|
||||
def build_application(main)
|
||||
|
||||
report "Building application..."
|
||||
|
||||
obj_list = []
|
||||
load_configuration($cfg_file)
|
||||
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
include_dirs = get_local_include_dirs
|
||||
extract_headers(main_path).each do |header|
|
||||
src_file = find_source_file(header, include_dirs)
|
||||
if !src_file.nil?
|
||||
obj_list << compile(src_file)
|
||||
end
|
||||
end
|
||||
|
||||
# Build the main source file
|
||||
main_base = File.basename(main_path, C_EXTENSION)
|
||||
obj_list << compile(main_path)
|
||||
|
||||
# Create the executable
|
||||
link_it(main_base, obj_list)
|
||||
end
|
||||
|
||||
end
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require '../vendor/unity/auto/unity_test_summary'
|
||||
require '../vendor/unity/auto/generate_test_runner'
|
||||
require '../vendor/unity/auto/colour_reporter'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
def load_configuration(config_file)
|
||||
$cfg_file = config_file
|
||||
$cfg = YAML.load(File.read($cfg_file))
|
||||
$colour_output = false unless $cfg['colour']
|
||||
end
|
||||
|
||||
def configure_clean
|
||||
CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil?
|
||||
end
|
||||
|
||||
def configure_toolchain(config_file=DEFAULT_CONFIG_FILE)
|
||||
config_file += '.yml' unless config_file =~ /\.yml$/
|
||||
load_configuration(config_file)
|
||||
configure_clean
|
||||
end
|
||||
|
||||
def get_unit_test_files
|
||||
path = $cfg['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION
|
||||
path.gsub!(/\\/, '/')
|
||||
FileList.new(path)
|
||||
end
|
||||
|
||||
def get_local_include_dirs
|
||||
include_dirs = $cfg['compiler']['includes']['items'].dup
|
||||
include_dirs.delete_if {|dir| dir.is_a?(Array)}
|
||||
return include_dirs
|
||||
end
|
||||
|
||||
def extract_headers(filename)
|
||||
includes = []
|
||||
lines = File.readlines(filename)
|
||||
lines.each do |line|
|
||||
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
|
||||
if not m.nil?
|
||||
includes << m[1]
|
||||
end
|
||||
end
|
||||
return includes
|
||||
end
|
||||
|
||||
def find_source_file(header, paths)
|
||||
paths.each do |dir|
|
||||
src_file = dir + header.ext(C_EXTENSION)
|
||||
if (File.exists?(src_file))
|
||||
return src_file
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def tackit(strings)
|
||||
case(strings)
|
||||
when Array
|
||||
"\"#{strings.join}\""
|
||||
when /^-/
|
||||
strings
|
||||
when /\s/
|
||||
"\"#{strings}\""
|
||||
else
|
||||
strings
|
||||
end
|
||||
end
|
||||
|
||||
def squash(prefix, items)
|
||||
result = ''
|
||||
items.each { |item| result += " #{prefix}#{tackit(item)}" }
|
||||
return result
|
||||
end
|
||||
|
||||
def build_compiler_fields
|
||||
command = tackit($cfg['compiler']['path'])
|
||||
if $cfg['compiler']['defines']['items'].nil?
|
||||
defines = ''
|
||||
else
|
||||
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
|
||||
end
|
||||
options = squash('', $cfg['compiler']['options'])
|
||||
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
|
||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||
return {:command => command, :defines => defines, :options => options, :includes => includes}
|
||||
end
|
||||
|
||||
def compile(file, defines=[])
|
||||
compiler = build_compiler_fields
|
||||
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " +
|
||||
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
|
||||
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
|
||||
execute(cmd_str + obj_file)
|
||||
return obj_file
|
||||
end
|
||||
|
||||
def build_linker_fields
|
||||
command = tackit($cfg['linker']['path'])
|
||||
if $cfg['linker']['options'].nil?
|
||||
options = ''
|
||||
else
|
||||
options = squash('', $cfg['linker']['options'])
|
||||
end
|
||||
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
|
||||
includes = ''
|
||||
else
|
||||
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
|
||||
end
|
||||
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
|
||||
return {:command => command, :options => options, :includes => includes}
|
||||
end
|
||||
|
||||
def link_it(exe_name, obj_list)
|
||||
linker = build_linker_fields
|
||||
cmd_str = "#{linker[:command]}#{linker[:includes]} " +
|
||||
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join +
|
||||
$cfg['linker']['bin_files']['prefix'] + ' ' +
|
||||
$cfg['linker']['bin_files']['destination'] +
|
||||
exe_name + $cfg['linker']['bin_files']['extension'] + " #{linker[:options]}"
|
||||
execute(cmd_str)
|
||||
end
|
||||
|
||||
def build_simulator_fields
|
||||
return nil if $cfg['simulator'].nil?
|
||||
if $cfg['simulator']['path'].nil?
|
||||
command = ''
|
||||
else
|
||||
command = (tackit($cfg['simulator']['path']) + ' ')
|
||||
end
|
||||
if $cfg['simulator']['pre_support'].nil?
|
||||
pre_support = ''
|
||||
else
|
||||
pre_support = squash('', $cfg['simulator']['pre_support'])
|
||||
end
|
||||
if $cfg['simulator']['post_support'].nil?
|
||||
post_support = ''
|
||||
else
|
||||
post_support = squash('', $cfg['simulator']['post_support'])
|
||||
end
|
||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
||||
end
|
||||
|
||||
def execute(command_string, verbose=true)
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||
if $?.exitstatus != 0
|
||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(HERE)
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
report summary.run
|
||||
raise "There were failures" if (summary.failures > 0)
|
||||
end
|
||||
|
||||
def run_tests(test_files)
|
||||
|
||||
report 'Running system tests...'
|
||||
|
||||
# Tack on TEST define for compiling unit tests
|
||||
load_configuration($cfg_file)
|
||||
test_defines = ['TEST']
|
||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||
$cfg['compiler']['defines']['items'] << 'TEST'
|
||||
|
||||
include_dirs = get_local_include_dirs
|
||||
|
||||
# Build and execute each unit test
|
||||
test_files.each do |test|
|
||||
obj_list = []
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
header_list = extract_headers(test) + ['cmock.h']
|
||||
header_list.each do |header|
|
||||
|
||||
#create mocks if needed
|
||||
if (header =~ /Mock/)
|
||||
require "../lib/cmock.rb"
|
||||
@cmock ||= CMock.new($cfg_file)
|
||||
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#compile all mocks
|
||||
header_list.each do |header|
|
||||
#compile source file header if it exists
|
||||
src_file = find_source_file(header, include_dirs)
|
||||
if !src_file.nil?
|
||||
obj_list << compile(src_file, test_defines)
|
||||
end
|
||||
end
|
||||
|
||||
# Build the test runner (generate if configured to do so)
|
||||
test_base = File.basename(test, C_EXTENSION)
|
||||
runner_name = test_base + '_Runner.c'
|
||||
if $cfg['compiler']['runner_path'].nil?
|
||||
runner_path = $cfg['compiler']['build_path'] + runner_name
|
||||
test_gen = UnityTestRunnerGenerator.new($cfg_file)
|
||||
test_gen.run(test, runner_path)
|
||||
else
|
||||
runner_path = $cfg['compiler']['runner_path'] + runner_name
|
||||
end
|
||||
|
||||
obj_list << compile(runner_path, test_defines)
|
||||
|
||||
# Build the test module
|
||||
obj_list << compile(test, test_defines)
|
||||
|
||||
# Link the test executable
|
||||
link_it(test_base, obj_list)
|
||||
|
||||
# Execute unit test and generate results file
|
||||
simulator = build_simulator_fields
|
||||
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
|
||||
if simulator.nil?
|
||||
cmd_str = executable
|
||||
else
|
||||
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
||||
end
|
||||
output = execute(cmd_str)
|
||||
test_results = $cfg['compiler']['build_path'] + test_base
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
else
|
||||
test_results += '.testpass'
|
||||
end
|
||||
File.open(test_results, 'w') { |f| f.print output }
|
||||
end
|
||||
end
|
||||
|
||||
def build_application(main)
|
||||
|
||||
report "Building application..."
|
||||
|
||||
obj_list = []
|
||||
load_configuration($cfg_file)
|
||||
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
|
||||
|
||||
# Detect dependencies and build required required modules
|
||||
include_dirs = get_local_include_dirs
|
||||
extract_headers(main_path).each do |header|
|
||||
src_file = find_source_file(header, include_dirs)
|
||||
if !src_file.nil?
|
||||
obj_list << compile(src_file)
|
||||
end
|
||||
end
|
||||
|
||||
# Build the main source file
|
||||
main_base = File.basename(main_path, C_EXTENSION)
|
||||
obj_list << compile(main_path)
|
||||
|
||||
# Create the executable
|
||||
link_it(main_base, obj_list)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+2556
-2556
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,42 @@
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "AdcModel.h"
|
||||
#include "AdcHardware.h"
|
||||
|
||||
void AdcConductor_Init(void)
|
||||
{
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void AdcConductor_Run(void)
|
||||
{
|
||||
if (AdcModel_DoGetSample() && AdcHardware_GetSampleComplete())
|
||||
{
|
||||
AdcModel_ProcessInput(AdcHardware_GetSample());
|
||||
AdcHardware_StartConversion();
|
||||
}
|
||||
}
|
||||
|
||||
bool AdcConductor_JustHereToTest(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T ExampleStruct;
|
||||
ExampleStruct.x = 5;
|
||||
ExampleStruct.y = 7;
|
||||
|
||||
return AdcModel_DoNothingExceptTestASpecialType(ExampleStruct);
|
||||
}
|
||||
|
||||
bool AdcConductor_AlsoHereToTest(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T example = AdcModel_DoNothingExceptReturnASpecialType();
|
||||
|
||||
return ((example.x == 99) && (example.y == 1));
|
||||
}
|
||||
|
||||
bool AdcConductor_YetAnotherTest(void)
|
||||
{
|
||||
uint32 example = 3;
|
||||
|
||||
return AdModel_DoNothingExceptTestPointers(&example);
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "AdcModel.h"
|
||||
#include "AdcHardware.h"
|
||||
|
||||
void AdcConductor_Init(void)
|
||||
{
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void AdcConductor_Run(void)
|
||||
{
|
||||
if (AdcModel_DoGetSample() && AdcHardware_GetSampleComplete())
|
||||
{
|
||||
AdcModel_ProcessInput(AdcHardware_GetSample());
|
||||
AdcHardware_StartConversion();
|
||||
}
|
||||
}
|
||||
|
||||
bool AdcConductor_JustHereToTest(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T ExampleStruct;
|
||||
ExampleStruct.x = 5;
|
||||
ExampleStruct.y = 7;
|
||||
|
||||
return AdcModel_DoNothingExceptTestASpecialType(ExampleStruct);
|
||||
}
|
||||
|
||||
bool AdcConductor_AlsoHereToTest(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T example = AdcModel_DoNothingExceptReturnASpecialType();
|
||||
|
||||
return ((example.x == 99) && (example.y == 1));
|
||||
}
|
||||
|
||||
bool AdcConductor_YetAnotherTest(void)
|
||||
{
|
||||
uint32 example = 3;
|
||||
|
||||
return AdModel_DoNothingExceptTestPointers(&example);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef _ADCCONDUCTOR_H
|
||||
#define _ADCCONDUCTOR_H
|
||||
|
||||
void AdcConductor_Init(void);
|
||||
void AdcConductor_Run(void);
|
||||
|
||||
bool AdcConductor_JustHereToTest(void);
|
||||
bool AdcConductor_AlsoHereToTest(void);
|
||||
bool AdcConductor_YetAnotherTest(void);
|
||||
|
||||
#endif // _ADCCONDUCTOR_H
|
||||
#ifndef _ADCCONDUCTOR_H
|
||||
#define _ADCCONDUCTOR_H
|
||||
|
||||
void AdcConductor_Init(void);
|
||||
void AdcConductor_Run(void);
|
||||
|
||||
bool AdcConductor_JustHereToTest(void);
|
||||
bool AdcConductor_AlsoHereToTest(void);
|
||||
bool AdcConductor_YetAnotherTest(void);
|
||||
|
||||
#endif // _ADCCONDUCTOR_H
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
|
||||
void AdcHardware_Init(void)
|
||||
{
|
||||
Adc_Reset();
|
||||
Adc_ConfigureMode();
|
||||
Adc_EnableTemperatureChannel();
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
}
|
||||
|
||||
void AdcHardware_StartConversion(void)
|
||||
{
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
}
|
||||
|
||||
bool AdcHardware_GetSampleComplete(void)
|
||||
{
|
||||
return Adc_TemperatureSensorSampleReady();
|
||||
}
|
||||
|
||||
uint16 AdcHardware_GetSample(void)
|
||||
{
|
||||
return Adc_ReadTemperatureSensor();
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
|
||||
void AdcHardware_Init(void)
|
||||
{
|
||||
Adc_Reset();
|
||||
Adc_ConfigureMode();
|
||||
Adc_EnableTemperatureChannel();
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
}
|
||||
|
||||
void AdcHardware_StartConversion(void)
|
||||
{
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
}
|
||||
|
||||
bool AdcHardware_GetSampleComplete(void)
|
||||
{
|
||||
return Adc_TemperatureSensorSampleReady();
|
||||
}
|
||||
|
||||
uint16 AdcHardware_GetSample(void)
|
||||
{
|
||||
return Adc_ReadTemperatureSensor();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _ADCHARDWARE_H
|
||||
#define _ADCHARDWARE_H
|
||||
|
||||
void AdcHardware_Init(void);
|
||||
void AdcHardware_StartConversion(void);
|
||||
bool AdcHardware_GetSampleComplete(void);
|
||||
uint16 AdcHardware_GetSample(void);
|
||||
|
||||
#endif // _ADCHARDWARE_H
|
||||
#ifndef _ADCHARDWARE_H
|
||||
#define _ADCHARDWARE_H
|
||||
|
||||
void AdcHardware_Init(void);
|
||||
void AdcHardware_StartConversion(void);
|
||||
bool AdcHardware_GetSampleComplete(void);
|
||||
uint16 AdcHardware_GetSample(void);
|
||||
|
||||
#endif // _ADCHARDWARE_H
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
void Adc_Reset(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
||||
}
|
||||
|
||||
void Adc_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_MR = (((uint32)11) << 8) | (((uint32)4) << 16);
|
||||
}
|
||||
|
||||
void Adc_EnableTemperatureChannel(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0x10;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
void Adc_Reset(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
||||
}
|
||||
|
||||
void Adc_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_MR = (((uint32)11) << 8) | (((uint32)4) << 16);
|
||||
}
|
||||
|
||||
void Adc_EnableTemperatureChannel(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0x10;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _ADCHARDWARECONFIGURATOR_H
|
||||
#define _ADCHARDWARECONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Adc_Reset(void);
|
||||
void Adc_ConfigureMode(void);
|
||||
void Adc_EnableTemperatureChannel(void);
|
||||
|
||||
#endif // _ADCHARDWARECONFIGURATOR_H
|
||||
#ifndef _ADCHARDWARECONFIGURATOR_H
|
||||
#define _ADCHARDWARECONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Adc_Reset(void);
|
||||
void Adc_ConfigureMode(void);
|
||||
void Adc_EnableTemperatureChannel(void);
|
||||
|
||||
#endif // _ADCHARDWARECONFIGURATOR_H
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "AdcModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
bool AdcModel_DoGetSample(void)
|
||||
{
|
||||
return TaskScheduler_DoAdc();
|
||||
}
|
||||
|
||||
void AdcModel_ProcessInput(uint16 millivolts)
|
||||
{
|
||||
TemperatureFilter_ProcessInput(TemperatureCalculator_Calculate(millivolts));
|
||||
}
|
||||
|
||||
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct)
|
||||
{
|
||||
//This doesn't really do anything. it's only here to make sure I can compare a struct.
|
||||
return FALSE;
|
||||
}
|
||||
bool AdModel_DoNothingExceptTestPointers(uint32* pExample)
|
||||
{
|
||||
//This doesn't really do anything. it's only here to make sure I can compare a pointer value.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T example; //again, this just is here to test that I can return a struct
|
||||
example.x = 99;
|
||||
example.y = 1;
|
||||
return example;
|
||||
}
|
||||
#include "AdcModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
bool AdcModel_DoGetSample(void)
|
||||
{
|
||||
return TaskScheduler_DoAdc();
|
||||
}
|
||||
|
||||
void AdcModel_ProcessInput(uint16 millivolts)
|
||||
{
|
||||
TemperatureFilter_ProcessInput(TemperatureCalculator_Calculate(millivolts));
|
||||
}
|
||||
|
||||
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct)
|
||||
{
|
||||
//This doesn't really do anything. it's only here to make sure I can compare a struct.
|
||||
return FALSE;
|
||||
}
|
||||
bool AdModel_DoNothingExceptTestPointers(uint32* pExample)
|
||||
{
|
||||
//This doesn't really do anything. it's only here to make sure I can compare a pointer value.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T example; //again, this just is here to test that I can return a struct
|
||||
example.x = 99;
|
||||
example.y = 1;
|
||||
return example;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _ADCMODEL_H
|
||||
#define _ADCMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
bool AdcModel_DoGetSample(void);
|
||||
void AdcModel_ProcessInput(uint16 millivolts);
|
||||
|
||||
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct);
|
||||
bool AdModel_DoNothingExceptTestPointers(uint32* pExample);
|
||||
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void);
|
||||
|
||||
#endif // _ADCMODEL_H
|
||||
#ifndef _ADCMODEL_H
|
||||
#define _ADCMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
bool AdcModel_DoGetSample(void);
|
||||
void AdcModel_ProcessInput(uint16 millivolts);
|
||||
|
||||
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct);
|
||||
bool AdModel_DoNothingExceptTestPointers(uint32* pExample);
|
||||
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void);
|
||||
|
||||
#endif // _ADCMODEL_H
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
|
||||
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts);
|
||||
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts);
|
||||
|
||||
//
|
||||
// PUBLIC METHODS
|
||||
//
|
||||
|
||||
void Adc_StartTemperatureSensorConversion(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
}
|
||||
|
||||
bool Adc_TemperatureSensorSampleReady(void)
|
||||
{
|
||||
return ((AT91C_BASE_ADC->ADC_SR & AT91C_ADC_EOC4) == AT91C_ADC_EOC4);
|
||||
}
|
||||
|
||||
uint16 Adc_ReadTemperatureSensor(void)
|
||||
{
|
||||
uint32 picovolts = ConvertAdcCountsToPicovolts(AT91C_BASE_ADC->ADC_CDR4);
|
||||
return ConvertPicovoltsToMillivolts(picovolts);
|
||||
}
|
||||
|
||||
//
|
||||
// PRIVATE HELPERS
|
||||
//
|
||||
|
||||
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts)
|
||||
{
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
uint32 picovoltsPerAdcCount = 2929688;
|
||||
|
||||
// Shift decimal point by 6 places to preserve accuracy in fixed-point math
|
||||
return counts * picovoltsPerAdcCount;
|
||||
}
|
||||
|
||||
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts)
|
||||
{
|
||||
const uint32 halfMillivoltInPicovolts = 500000;
|
||||
const uint32 picovoltsPerMillivolt = 1000000;
|
||||
|
||||
// Add 0.5 mV to result so that truncation yields properly rounded result
|
||||
picovolts += halfMillivoltInPicovolts;
|
||||
|
||||
// Divide appropriately to convert to millivolts
|
||||
return (uint16)(picovolts / picovoltsPerMillivolt);
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
|
||||
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts);
|
||||
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts);
|
||||
|
||||
//
|
||||
// PUBLIC METHODS
|
||||
//
|
||||
|
||||
void Adc_StartTemperatureSensorConversion(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
}
|
||||
|
||||
bool Adc_TemperatureSensorSampleReady(void)
|
||||
{
|
||||
return ((AT91C_BASE_ADC->ADC_SR & AT91C_ADC_EOC4) == AT91C_ADC_EOC4);
|
||||
}
|
||||
|
||||
uint16 Adc_ReadTemperatureSensor(void)
|
||||
{
|
||||
uint32 picovolts = ConvertAdcCountsToPicovolts(AT91C_BASE_ADC->ADC_CDR4);
|
||||
return ConvertPicovoltsToMillivolts(picovolts);
|
||||
}
|
||||
|
||||
//
|
||||
// PRIVATE HELPERS
|
||||
//
|
||||
|
||||
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts)
|
||||
{
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
uint32 picovoltsPerAdcCount = 2929688;
|
||||
|
||||
// Shift decimal point by 6 places to preserve accuracy in fixed-point math
|
||||
return counts * picovoltsPerAdcCount;
|
||||
}
|
||||
|
||||
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts)
|
||||
{
|
||||
const uint32 halfMillivoltInPicovolts = 500000;
|
||||
const uint32 picovoltsPerMillivolt = 1000000;
|
||||
|
||||
// Add 0.5 mV to result so that truncation yields properly rounded result
|
||||
picovolts += halfMillivoltInPicovolts;
|
||||
|
||||
// Divide appropriately to convert to millivolts
|
||||
return (uint16)(picovolts / picovoltsPerMillivolt);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _ADCTEMPERATURESENSOR_H
|
||||
#define _ADCTEMPERATURESENSOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Adc_StartTemperatureSensorConversion(void);
|
||||
bool Adc_TemperatureSensorSampleReady(void);
|
||||
uint16 Adc_ReadTemperatureSensor(void);
|
||||
|
||||
#endif // _ADCTEMPERATURESENSOR_H
|
||||
#ifndef _ADCTEMPERATURESENSOR_H
|
||||
#define _ADCTEMPERATURESENSOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Adc_StartTemperatureSensorConversion(void);
|
||||
bool Adc_TemperatureSensorSampleReady(void);
|
||||
uint16 Adc_ReadTemperatureSensor(void);
|
||||
|
||||
#endif // _ADCTEMPERATURESENSOR_H
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "Model.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "IntrinsicsWrapper.h"
|
||||
|
||||
|
||||
void Executor_Init(void)
|
||||
{
|
||||
Model_Init();
|
||||
UsartConductor_Init();
|
||||
AdcConductor_Init();
|
||||
TimerConductor_Init();
|
||||
Interrupt_Enable();
|
||||
}
|
||||
|
||||
bool Executor_Run(void)
|
||||
{
|
||||
UsartConductor_Run();
|
||||
TimerConductor_Run();
|
||||
AdcConductor_Run();
|
||||
return TRUE;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "Model.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "IntrinsicsWrapper.h"
|
||||
|
||||
|
||||
void Executor_Init(void)
|
||||
{
|
||||
Model_Init();
|
||||
UsartConductor_Init();
|
||||
AdcConductor_Init();
|
||||
TimerConductor_Init();
|
||||
Interrupt_Enable();
|
||||
}
|
||||
|
||||
bool Executor_Run(void)
|
||||
{
|
||||
UsartConductor_Run();
|
||||
TimerConductor_Run();
|
||||
AdcConductor_Run();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _EXECUTOR_H
|
||||
#define _EXECUTOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Executor_Init(void);
|
||||
bool Executor_Run(void);
|
||||
|
||||
#endif // _EXECUTOR_H
|
||||
#ifndef _EXECUTOR_H
|
||||
#define _EXECUTOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Executor_Init(void);
|
||||
bool Executor_Run(void);
|
||||
|
||||
#endif // _EXECUTOR_H
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "IntrinsicsWrapper.h"
|
||||
#ifdef __ICCARM__
|
||||
#include <intrinsics.h>
|
||||
#endif
|
||||
|
||||
void Interrupt_Enable(void)
|
||||
{
|
||||
#ifdef __ICCARM__
|
||||
__enable_interrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Interrupt_Disable(void)
|
||||
{
|
||||
#ifdef __ICCARM__
|
||||
__disable_interrupt();
|
||||
#endif
|
||||
}
|
||||
#include "IntrinsicsWrapper.h"
|
||||
#ifdef __ICCARM__
|
||||
#include <intrinsics.h>
|
||||
#endif
|
||||
|
||||
void Interrupt_Enable(void)
|
||||
{
|
||||
#ifdef __ICCARM__
|
||||
__enable_interrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Interrupt_Disable(void)
|
||||
{
|
||||
#ifdef __ICCARM__
|
||||
__disable_interrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _INTRINSICS_WRAPPER_H
|
||||
#define _INTRINSICS_WRAPPER_H
|
||||
|
||||
void Interrupt_Enable(void);
|
||||
void Interrupt_Disable(void);
|
||||
|
||||
#endif // _INTRINSICS_WRAPPER_H
|
||||
#ifndef _INTRINSICS_WRAPPER_H
|
||||
#define _INTRINSICS_WRAPPER_H
|
||||
|
||||
void Interrupt_Enable(void);
|
||||
void Interrupt_Disable(void);
|
||||
|
||||
#endif // _INTRINSICS_WRAPPER_H
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
#include "Types.h"
|
||||
|
||||
#include "IntrinsicsWrapper.h"
|
||||
#include "Executor.h"
|
||||
|
||||
#include "Model.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
#include "UsartConductor.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartConfigurator.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "UsartModel.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
#include "TimerConductor.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "TimerModel.h"
|
||||
|
||||
#include "AdcConductor.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AdcModel.h"
|
||||
|
||||
int AppMain(void)
|
||||
{
|
||||
Executor_Init();
|
||||
|
||||
while(Executor_Run());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef TEST
|
||||
int main(void)
|
||||
{
|
||||
return AppMain();
|
||||
}
|
||||
#endif // TEST
|
||||
#include "Types.h"
|
||||
|
||||
#include "IntrinsicsWrapper.h"
|
||||
#include "Executor.h"
|
||||
|
||||
#include "Model.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
#include "UsartConductor.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartConfigurator.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "UsartModel.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
#include "TimerConductor.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "TimerModel.h"
|
||||
|
||||
#include "AdcConductor.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AdcModel.h"
|
||||
|
||||
int AppMain(void)
|
||||
{
|
||||
Executor_Init();
|
||||
|
||||
while(Executor_Run());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef TEST
|
||||
int main(void)
|
||||
{
|
||||
return AppMain();
|
||||
}
|
||||
#endif // TEST
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
int AppMain(void);
|
||||
int main(void);
|
||||
|
||||
#endif // _MAIN_H_
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
int AppMain(void);
|
||||
int main(void);
|
||||
|
||||
#endif // _MAIN_H_
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "Model.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
void Model_Init(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
#include "Model.h"
|
||||
#include "TaskScheduler.h"
|
||||
#include "TemperatureFilter.h"
|
||||
|
||||
void Model_Init(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _MODEL_H
|
||||
#define _MODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Model_Init(void);
|
||||
|
||||
#endif // _MODEL_H
|
||||
#ifndef _MODEL_H
|
||||
#define _MODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Model_Init(void);
|
||||
|
||||
#endif // _MODEL_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _MODELCONFIG_H
|
||||
#define _MODELCONFIG_H
|
||||
|
||||
#define MASTER_CLOCK 48054857 // Master Clock
|
||||
#define USART0_BAUDRATE 115200 // USART Baudrate
|
||||
|
||||
#endif // _MODELCONFIG_H
|
||||
#ifndef _MODELCONFIG_H
|
||||
#define _MODELCONFIG_H
|
||||
|
||||
#define MASTER_CLOCK 48054857 // Master Clock
|
||||
#define USART0_BAUDRATE 115200 // USART Baudrate
|
||||
|
||||
#endif // _MODELCONFIG_H
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
typedef struct _Task
|
||||
{
|
||||
bool doIt;
|
||||
uint32 period;
|
||||
uint32 startTime;
|
||||
} Task;
|
||||
|
||||
typedef struct _TaskSchedulerInstance
|
||||
{
|
||||
Task usart;
|
||||
Task adc;
|
||||
} TaskSchedulerInstance;
|
||||
|
||||
static TaskSchedulerInstance this;
|
||||
|
||||
void TaskScheduler_Init(void)
|
||||
{
|
||||
this.usart.doIt = FALSE;
|
||||
this.usart.startTime = 0;
|
||||
|
||||
//The correct period
|
||||
this.usart.period = 1000;
|
||||
|
||||
this.adc.doIt = FALSE;
|
||||
this.adc.startTime = 0;
|
||||
this.adc.period = 100;
|
||||
}
|
||||
|
||||
void TaskScheduler_Update(uint32 time)
|
||||
{
|
||||
if ((time - this.usart.startTime) >= this.usart.period)
|
||||
{
|
||||
this.usart.doIt = TRUE;
|
||||
this.usart.startTime = time - (time % this.usart.period);
|
||||
}
|
||||
|
||||
if ((time - this.adc.startTime) >= this.adc.period)
|
||||
{
|
||||
this.adc.doIt = TRUE;
|
||||
this.adc.startTime = time - (time % this.adc.period);
|
||||
}
|
||||
}
|
||||
|
||||
bool TaskScheduler_DoUsart(void)
|
||||
{
|
||||
bool doIt = FALSE;
|
||||
|
||||
if (this.usart.doIt)
|
||||
{
|
||||
doIt = TRUE;
|
||||
this.usart.doIt = FALSE;
|
||||
}
|
||||
|
||||
return doIt;
|
||||
}
|
||||
|
||||
bool TaskScheduler_DoAdc(void)
|
||||
{
|
||||
bool doIt = FALSE;
|
||||
|
||||
if (this.adc.doIt)
|
||||
{
|
||||
doIt = TRUE;
|
||||
this.adc.doIt = FALSE;
|
||||
}
|
||||
|
||||
return doIt;
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
typedef struct _Task
|
||||
{
|
||||
bool doIt;
|
||||
uint32 period;
|
||||
uint32 startTime;
|
||||
} Task;
|
||||
|
||||
typedef struct _TaskSchedulerInstance
|
||||
{
|
||||
Task usart;
|
||||
Task adc;
|
||||
} TaskSchedulerInstance;
|
||||
|
||||
static TaskSchedulerInstance this;
|
||||
|
||||
void TaskScheduler_Init(void)
|
||||
{
|
||||
this.usart.doIt = FALSE;
|
||||
this.usart.startTime = 0;
|
||||
|
||||
//The correct period
|
||||
this.usart.period = 1000;
|
||||
|
||||
this.adc.doIt = FALSE;
|
||||
this.adc.startTime = 0;
|
||||
this.adc.period = 100;
|
||||
}
|
||||
|
||||
void TaskScheduler_Update(uint32 time)
|
||||
{
|
||||
if ((time - this.usart.startTime) >= this.usart.period)
|
||||
{
|
||||
this.usart.doIt = TRUE;
|
||||
this.usart.startTime = time - (time % this.usart.period);
|
||||
}
|
||||
|
||||
if ((time - this.adc.startTime) >= this.adc.period)
|
||||
{
|
||||
this.adc.doIt = TRUE;
|
||||
this.adc.startTime = time - (time % this.adc.period);
|
||||
}
|
||||
}
|
||||
|
||||
bool TaskScheduler_DoUsart(void)
|
||||
{
|
||||
bool doIt = FALSE;
|
||||
|
||||
if (this.usart.doIt)
|
||||
{
|
||||
doIt = TRUE;
|
||||
this.usart.doIt = FALSE;
|
||||
}
|
||||
|
||||
return doIt;
|
||||
}
|
||||
|
||||
bool TaskScheduler_DoAdc(void)
|
||||
{
|
||||
bool doIt = FALSE;
|
||||
|
||||
if (this.adc.doIt)
|
||||
{
|
||||
doIt = TRUE;
|
||||
this.adc.doIt = FALSE;
|
||||
}
|
||||
|
||||
return doIt;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef _TASKSCHEDULER_H
|
||||
#define _TASKSCHEDULER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TaskScheduler_Init(void);
|
||||
void TaskScheduler_Update(uint32 time);
|
||||
bool TaskScheduler_DoUsart(void);
|
||||
bool TaskScheduler_DoAdc(void);
|
||||
|
||||
#endif // _TASKSCHEDULER_H
|
||||
#ifndef _TASKSCHEDULER_H
|
||||
#define _TASKSCHEDULER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TaskScheduler_Init(void);
|
||||
void TaskScheduler_Update(uint32 time);
|
||||
bool TaskScheduler_DoUsart(void);
|
||||
bool TaskScheduler_DoAdc(void);
|
||||
|
||||
#endif // _TASKSCHEDULER_H
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef logl
|
||||
#define logl log
|
||||
#endif
|
||||
|
||||
float TemperatureCalculator_Calculate(uint16 millivolts)
|
||||
{
|
||||
const double supply_voltage = 3.0;
|
||||
const double series_resistance = 5000;
|
||||
const double coefficient_A = 316589.698;
|
||||
const double coefficient_B = -0.1382009;
|
||||
double sensor_voltage = ((double)millivolts / 1000);
|
||||
double resistance;
|
||||
|
||||
if (millivolts == 0)
|
||||
{
|
||||
return -INFINITY;
|
||||
}
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
resistance = ((supply_voltage * series_resistance) / sensor_voltage) - series_resistance;
|
||||
return (float)(logl(resistance / coefficient_A) / coefficient_B);
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef logl
|
||||
#define logl log
|
||||
#endif
|
||||
|
||||
float TemperatureCalculator_Calculate(uint16 millivolts)
|
||||
{
|
||||
const double supply_voltage = 3.0;
|
||||
const double series_resistance = 5000;
|
||||
const double coefficient_A = 316589.698;
|
||||
const double coefficient_B = -0.1382009;
|
||||
double sensor_voltage = ((double)millivolts / 1000);
|
||||
double resistance;
|
||||
|
||||
if (millivolts == 0)
|
||||
{
|
||||
return -INFINITY;
|
||||
}
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
resistance = ((supply_voltage * series_resistance) / sensor_voltage) - series_resistance;
|
||||
return (float)(logl(resistance / coefficient_A) / coefficient_B);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _TEMPERATURECALCULATOR_H
|
||||
#define _TEMPERATURECALCULATOR_H
|
||||
|
||||
float TemperatureCalculator_Calculate(uint16 millivolts);
|
||||
|
||||
#endif // _TEMPERATURECALCULATOR_H
|
||||
#ifndef _TEMPERATURECALCULATOR_H
|
||||
#define _TEMPERATURECALCULATOR_H
|
||||
|
||||
float TemperatureCalculator_Calculate(uint16 millivolts);
|
||||
|
||||
#endif // _TEMPERATURECALCULATOR_H
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
static bool initialized;
|
||||
static float temperatureInCelcius;
|
||||
|
||||
void TemperatureFilter_Init(void)
|
||||
{
|
||||
initialized = FALSE;
|
||||
temperatureInCelcius = -INFINITY;
|
||||
}
|
||||
|
||||
float TemperatureFilter_GetTemperatureInCelcius(void)
|
||||
{
|
||||
return temperatureInCelcius;
|
||||
}
|
||||
|
||||
void TemperatureFilter_ProcessInput(float temperature)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
temperatureInCelcius = temperature;
|
||||
initialized = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (temperature == +INFINITY ||
|
||||
temperature == -INFINITY ||
|
||||
temperature == +NAN ||
|
||||
temperature == -NAN)
|
||||
{
|
||||
initialized = FALSE;
|
||||
temperature = -INFINITY;
|
||||
}
|
||||
|
||||
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
|
||||
}
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
static bool initialized;
|
||||
static float temperatureInCelcius;
|
||||
|
||||
void TemperatureFilter_Init(void)
|
||||
{
|
||||
initialized = FALSE;
|
||||
temperatureInCelcius = -INFINITY;
|
||||
}
|
||||
|
||||
float TemperatureFilter_GetTemperatureInCelcius(void)
|
||||
{
|
||||
return temperatureInCelcius;
|
||||
}
|
||||
|
||||
void TemperatureFilter_ProcessInput(float temperature)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
temperatureInCelcius = temperature;
|
||||
initialized = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (temperature == +INFINITY ||
|
||||
temperature == -INFINITY ||
|
||||
temperature == +NAN ||
|
||||
temperature == -NAN)
|
||||
{
|
||||
initialized = FALSE;
|
||||
temperature = -INFINITY;
|
||||
}
|
||||
|
||||
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _TEMPERATUREFILTER_H
|
||||
#define _TEMPERATUREFILTER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TemperatureFilter_Init(void);
|
||||
float TemperatureFilter_GetTemperatureInCelcius(void);
|
||||
void TemperatureFilter_ProcessInput(float temperature);
|
||||
|
||||
#endif // _TEMPERATUREFILTER_H
|
||||
#ifndef _TEMPERATUREFILTER_H
|
||||
#define _TEMPERATUREFILTER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TemperatureFilter_Init(void);
|
||||
float TemperatureFilter_GetTemperatureInCelcius(void);
|
||||
void TemperatureFilter_ProcessInput(float temperature);
|
||||
|
||||
#endif // _TEMPERATUREFILTER_H
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "TimerModel.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
|
||||
void TimerConductor_Init(void)
|
||||
{
|
||||
TimerHardware_Init();
|
||||
}
|
||||
|
||||
void TimerConductor_Run(void)
|
||||
{
|
||||
TimerModel_UpdateTime(Timer_GetSystemTime());
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "TimerModel.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
|
||||
void TimerConductor_Init(void)
|
||||
{
|
||||
TimerHardware_Init();
|
||||
}
|
||||
|
||||
void TimerConductor_Run(void)
|
||||
{
|
||||
TimerModel_UpdateTime(Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _TIMERCONDUCTOR_H
|
||||
#define _TIMERCONDUCTOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerConductor_Init(void);
|
||||
void TimerConductor_Run(void);
|
||||
|
||||
#endif // _TIMERCONDUCTOR_H
|
||||
#ifndef _TIMERCONDUCTOR_H
|
||||
#define _TIMERCONDUCTOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerConductor_Init(void);
|
||||
void TimerConductor_Run(void);
|
||||
|
||||
#endif // _TIMERCONDUCTOR_H
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
|
||||
void Timer_EnablePeripheralClocks(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = TIMER0_CLOCK_ENABLE | PIOB_CLOCK_ENABLE;
|
||||
}
|
||||
|
||||
void Timer_Reset(void)
|
||||
{
|
||||
uint32 dummy;
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC0->TC_IDR = 0xffffffff;
|
||||
dummy = AT91C_BASE_TC0->TC_SR;
|
||||
dummy = dummy;
|
||||
}
|
||||
|
||||
void Timer_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0x000CC004; // ACPC=toggle TIOA on RC compare; mode=WAVE; WAVE_SEL=UP w/auto-trigger on RC compare; clock=MCK/1024
|
||||
}
|
||||
|
||||
void Timer_ConfigurePeriod(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 469; // 10ms period for timer clock source of MCK/1024 with MCK=48054857
|
||||
}
|
||||
|
||||
void Timer_EnableOutputPin(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = TIOA0_PIN_MASK;
|
||||
}
|
||||
|
||||
void Timer_Enable(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
|
||||
}
|
||||
|
||||
void Timer_ConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt();
|
||||
Timer_ResetSystemTime();
|
||||
Timer_ConfigureInterrupt();
|
||||
Timer_EnableInterrupt();
|
||||
}
|
||||
|
||||
void Timer_Start(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
|
||||
void Timer_EnablePeripheralClocks(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = TIMER0_CLOCK_ENABLE | PIOB_CLOCK_ENABLE;
|
||||
}
|
||||
|
||||
void Timer_Reset(void)
|
||||
{
|
||||
uint32 dummy;
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC0->TC_IDR = 0xffffffff;
|
||||
dummy = AT91C_BASE_TC0->TC_SR;
|
||||
dummy = dummy;
|
||||
}
|
||||
|
||||
void Timer_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0x000CC004; // ACPC=toggle TIOA on RC compare; mode=WAVE; WAVE_SEL=UP w/auto-trigger on RC compare; clock=MCK/1024
|
||||
}
|
||||
|
||||
void Timer_ConfigurePeriod(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 469; // 10ms period for timer clock source of MCK/1024 with MCK=48054857
|
||||
}
|
||||
|
||||
void Timer_EnableOutputPin(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = TIOA0_PIN_MASK;
|
||||
}
|
||||
|
||||
void Timer_Enable(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
|
||||
}
|
||||
|
||||
void Timer_ConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt();
|
||||
Timer_ResetSystemTime();
|
||||
Timer_ConfigureInterrupt();
|
||||
Timer_EnableInterrupt();
|
||||
}
|
||||
|
||||
void Timer_Start(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef _TIMERCONFIGURATOR_H
|
||||
#define _TIMERCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Timer_EnablePeripheralClocks(void);
|
||||
void Timer_Reset(void);
|
||||
void Timer_ConfigureMode(void);
|
||||
void Timer_ConfigurePeriod(void);
|
||||
void Timer_EnableOutputPin(void);
|
||||
void Timer_Enable(void);
|
||||
void Timer_ConfigureInterruptHandler(void);
|
||||
void Timer_Start(void);
|
||||
|
||||
#endif // _TIMERCONFIGURATOR_H
|
||||
#ifndef _TIMERCONFIGURATOR_H
|
||||
#define _TIMERCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Timer_EnablePeripheralClocks(void);
|
||||
void Timer_Reset(void);
|
||||
void Timer_ConfigureMode(void);
|
||||
void Timer_ConfigurePeriod(void);
|
||||
void Timer_EnableOutputPin(void);
|
||||
void Timer_Enable(void);
|
||||
void Timer_ConfigureInterruptHandler(void);
|
||||
void Timer_Start(void);
|
||||
|
||||
#endif // _TIMERCONFIGURATOR_H
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerConfigurator.h"
|
||||
|
||||
void TimerHardware_Init(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks();
|
||||
Timer_Reset();
|
||||
Timer_ConfigureMode();
|
||||
Timer_ConfigurePeriod();
|
||||
Timer_EnableOutputPin();
|
||||
Timer_Enable();
|
||||
Timer_ConfigureInterruptHandler();
|
||||
Timer_Start();
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "TimerConfigurator.h"
|
||||
|
||||
void TimerHardware_Init(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks();
|
||||
Timer_Reset();
|
||||
Timer_ConfigureMode();
|
||||
Timer_ConfigurePeriod();
|
||||
Timer_EnableOutputPin();
|
||||
Timer_Enable();
|
||||
Timer_ConfigureInterruptHandler();
|
||||
Timer_Start();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _TIMERHARDWARE_H
|
||||
#define _TIMERHARDWARE_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerHardware_Init(void);
|
||||
|
||||
#endif // _TIMERHARDWARE_H
|
||||
#ifndef _TIMERHARDWARE_H
|
||||
#define _TIMERHARDWARE_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerHardware_Init(void);
|
||||
|
||||
#endif // _TIMERHARDWARE_H
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
|
||||
static inline void SetInterruptHandler(void);
|
||||
static inline void ConfigureInterruptSourceModeRegister(void);
|
||||
static inline void ClearInterrupt(void);
|
||||
static inline void EnableCompareInterruptForRegisterC(void);
|
||||
|
||||
void Timer_DisableInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
void Timer_ResetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
}
|
||||
|
||||
void Timer_ConfigureInterrupt(void)
|
||||
{
|
||||
SetInterruptHandler();
|
||||
ConfigureInterruptSourceModeRegister();
|
||||
ClearInterrupt();
|
||||
EnableCompareInterruptForRegisterC();
|
||||
}
|
||||
|
||||
void Timer_EnableInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
||||
static inline void SetInterruptHandler(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)Timer_InterruptHandler;
|
||||
}
|
||||
|
||||
static inline void ConfigureInterruptSourceModeRegister(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 1;
|
||||
}
|
||||
|
||||
static inline void ClearInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
static inline void EnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
|
||||
static inline void SetInterruptHandler(void);
|
||||
static inline void ConfigureInterruptSourceModeRegister(void);
|
||||
static inline void ClearInterrupt(void);
|
||||
static inline void EnableCompareInterruptForRegisterC(void);
|
||||
|
||||
void Timer_DisableInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
void Timer_ResetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
}
|
||||
|
||||
void Timer_ConfigureInterrupt(void)
|
||||
{
|
||||
SetInterruptHandler();
|
||||
ConfigureInterruptSourceModeRegister();
|
||||
ClearInterrupt();
|
||||
EnableCompareInterruptForRegisterC();
|
||||
}
|
||||
|
||||
void Timer_EnableInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
||||
static inline void SetInterruptHandler(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)Timer_InterruptHandler;
|
||||
}
|
||||
|
||||
static inline void ConfigureInterruptSourceModeRegister(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 1;
|
||||
}
|
||||
|
||||
static inline void ClearInterrupt(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = TIMER0_ID_MASK;
|
||||
}
|
||||
|
||||
static inline void EnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
|
||||
#define _TIMERINTERRUPTCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#define TIMER0_ID_MASK (((uint32)0x1) << AT91C_ID_TC0)
|
||||
|
||||
void Timer_DisableInterrupt(void);
|
||||
void Timer_ResetSystemTime(void);
|
||||
void Timer_ConfigureInterrupt(void);
|
||||
void Timer_EnableInterrupt(void);
|
||||
|
||||
#endif // _TIMERINTERRUPTCONFIGURATOR_H
|
||||
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
|
||||
#define _TIMERINTERRUPTCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#define TIMER0_ID_MASK (((uint32)0x1) << AT91C_ID_TC0)
|
||||
|
||||
void Timer_DisableInterrupt(void);
|
||||
void Timer_ResetSystemTime(void);
|
||||
void Timer_ConfigureInterrupt(void);
|
||||
void Timer_EnableInterrupt(void);
|
||||
|
||||
#endif // _TIMERINTERRUPTCONFIGURATOR_H
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
|
||||
static uint32 systemTime;
|
||||
|
||||
void Timer_SetSystemTime(uint32 time)
|
||||
{
|
||||
systemTime = time;
|
||||
}
|
||||
|
||||
uint32 Timer_GetSystemTime(void)
|
||||
{
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
void Timer_InterruptHandler(void)
|
||||
{
|
||||
uint32 status = AT91C_BASE_TC0->TC_SR;
|
||||
if (status & AT91C_TC_CPCS)
|
||||
{
|
||||
systemTime += 10;
|
||||
}
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
|
||||
static uint32 systemTime;
|
||||
|
||||
void Timer_SetSystemTime(uint32 time)
|
||||
{
|
||||
systemTime = time;
|
||||
}
|
||||
|
||||
uint32 Timer_GetSystemTime(void)
|
||||
{
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
void Timer_InterruptHandler(void)
|
||||
{
|
||||
uint32 status = AT91C_BASE_TC0->TC_SR;
|
||||
if (status & AT91C_TC_CPCS)
|
||||
{
|
||||
systemTime += 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _TIMERINTERRUPTHANDLER_H
|
||||
#define _TIMERINTERRUPTHANDLER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Timer_SetSystemTime(uint32 time);
|
||||
uint32 Timer_GetSystemTime(void);
|
||||
void Timer_InterruptHandler(void);
|
||||
|
||||
#endif // _TIMERINTERRUPTHANDLER_H
|
||||
#ifndef _TIMERINTERRUPTHANDLER_H
|
||||
#define _TIMERINTERRUPTHANDLER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Timer_SetSystemTime(uint32 time);
|
||||
uint32 Timer_GetSystemTime(void);
|
||||
void Timer_InterruptHandler(void);
|
||||
|
||||
#endif // _TIMERINTERRUPTHANDLER_H
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void TimerModel_UpdateTime(uint32 systemTime)
|
||||
{
|
||||
TaskScheduler_Update(systemTime);
|
||||
}
|
||||
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void TimerModel_UpdateTime(uint32 systemTime)
|
||||
{
|
||||
TaskScheduler_Update(systemTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _TIMERMODEL_H
|
||||
#define _TIMERMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerModel_UpdateTime(uint32 systemTime);
|
||||
|
||||
#endif // _TIMERMODEL_H
|
||||
#ifndef _TIMERMODEL_H
|
||||
#define _TIMERMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void TimerModel_UpdateTime(uint32 systemTime);
|
||||
|
||||
#endif // _TIMERMODEL_H
|
||||
|
||||
+103
-103
@@ -1,103 +1,103 @@
|
||||
#ifndef _MYTYPES_H_
|
||||
#define _MYTYPES_H_
|
||||
|
||||
#include "AT91SAM7X256.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef __monitor
|
||||
#define __monitor
|
||||
#endif
|
||||
|
||||
// Peripheral Helper Definitions
|
||||
#define USART0_CLOCK_ENABLE (AT91C_ID_US0)
|
||||
#define USART0_TX_PIN (AT91C_PA1_TXD0)
|
||||
#define TIMER0_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_TC0)
|
||||
#define PIOA_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOA)
|
||||
#define PIOB_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOB)
|
||||
#define TIOA0_PIN_MASK (((uint32)0x1) << 23) // Timer/Counter Output Pin
|
||||
|
||||
// Application Type Definitions
|
||||
typedef unsigned int uint32;
|
||||
typedef int int32;
|
||||
typedef unsigned short uint16;
|
||||
typedef short int16;
|
||||
typedef unsigned char uint8;
|
||||
typedef char int8;
|
||||
typedef char bool;
|
||||
|
||||
// Application Special Value Definitions
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
#ifndef NULL
|
||||
#define NULL (0)
|
||||
#endif // NULL
|
||||
#define DONT_CARE (0)
|
||||
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (1.0 / 0.0)
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
#define NAN (0.0 / 0.0)
|
||||
#endif
|
||||
|
||||
// MIN/MAX Definitions for Standard Types
|
||||
#ifndef INT8_MAX
|
||||
#define INT8_MAX 127
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MIN
|
||||
#define INT8_MIN (-128)
|
||||
#endif
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
#define UINT8_MAX 0xFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT8_MIN
|
||||
#define UINT8_MIN 0x00U
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX 32767
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-32768)
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX 0xFFFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MIN
|
||||
#define UINT16_MIN 0x0000U
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-INT32_MAX - 1)
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xFFFFFFFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MIN
|
||||
#define UINT32_MIN 0x00000000U
|
||||
#endif
|
||||
|
||||
typedef struct _EXAMPLE_STRUCT_T
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} EXAMPLE_STRUCT_T;
|
||||
|
||||
#endif // _MYTYPES_H_
|
||||
#ifndef _MYTYPES_H_
|
||||
#define _MYTYPES_H_
|
||||
|
||||
#include "AT91SAM7X256.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef __monitor
|
||||
#define __monitor
|
||||
#endif
|
||||
|
||||
// Peripheral Helper Definitions
|
||||
#define USART0_CLOCK_ENABLE (AT91C_ID_US0)
|
||||
#define USART0_TX_PIN (AT91C_PA1_TXD0)
|
||||
#define TIMER0_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_TC0)
|
||||
#define PIOA_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOA)
|
||||
#define PIOB_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOB)
|
||||
#define TIOA0_PIN_MASK (((uint32)0x1) << 23) // Timer/Counter Output Pin
|
||||
|
||||
// Application Type Definitions
|
||||
typedef unsigned int uint32;
|
||||
typedef int int32;
|
||||
typedef unsigned short uint16;
|
||||
typedef short int16;
|
||||
typedef unsigned char uint8;
|
||||
typedef char int8;
|
||||
typedef char bool;
|
||||
|
||||
// Application Special Value Definitions
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
#ifndef NULL
|
||||
#define NULL (0)
|
||||
#endif // NULL
|
||||
#define DONT_CARE (0)
|
||||
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (1.0 / 0.0)
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
#define NAN (0.0 / 0.0)
|
||||
#endif
|
||||
|
||||
// MIN/MAX Definitions for Standard Types
|
||||
#ifndef INT8_MAX
|
||||
#define INT8_MAX 127
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MIN
|
||||
#define INT8_MIN (-128)
|
||||
#endif
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
#define UINT8_MAX 0xFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT8_MIN
|
||||
#define UINT8_MIN 0x00U
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX 32767
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-32768)
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX 0xFFFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MIN
|
||||
#define UINT16_MIN 0x0000U
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-INT32_MAX - 1)
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xFFFFFFFFU
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MIN
|
||||
#define UINT32_MIN 0x00000000U
|
||||
#endif
|
||||
|
||||
typedef struct _EXAMPLE_STRUCT_T
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} EXAMPLE_STRUCT_T;
|
||||
|
||||
#endif // _MYTYPES_H_
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate)
|
||||
{
|
||||
uint32 registerSetting = ((masterClock * 10) / (baudRate * 16));
|
||||
|
||||
if ((registerSetting % 10) >= 5)
|
||||
{
|
||||
registerSetting = (registerSetting / 10) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
registerSetting /= 10;
|
||||
}
|
||||
|
||||
return (uint8)registerSetting;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate)
|
||||
{
|
||||
uint32 registerSetting = ((masterClock * 10) / (baudRate * 16));
|
||||
|
||||
if ((registerSetting % 10) >= 5)
|
||||
{
|
||||
registerSetting = (registerSetting / 10) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
registerSetting /= 10;
|
||||
}
|
||||
|
||||
return (uint8)registerSetting;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
#define _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
|
||||
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate);
|
||||
|
||||
#endif // _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
#define _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
|
||||
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate);
|
||||
|
||||
#endif // _USARTBAUDRATEREGISTERCALCULATOR_H
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void UsartConductor_Init(void)
|
||||
{
|
||||
UsartHardware_Init(UsartModel_GetBaudRateRegisterSetting());
|
||||
UsartHardware_TransmitString(UsartModel_GetWakeupMessage());
|
||||
}
|
||||
|
||||
void UsartConductor_Run(void)
|
||||
{
|
||||
char* temp;
|
||||
if (TaskScheduler_DoUsart())
|
||||
{
|
||||
temp = UsartModel_GetFormattedTemperature();
|
||||
UsartHardware_TransmitString(temp);
|
||||
}
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartModel.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void UsartConductor_Init(void)
|
||||
{
|
||||
UsartHardware_Init(UsartModel_GetBaudRateRegisterSetting());
|
||||
UsartHardware_TransmitString(UsartModel_GetWakeupMessage());
|
||||
}
|
||||
|
||||
void UsartConductor_Run(void)
|
||||
{
|
||||
char* temp;
|
||||
if (TaskScheduler_DoUsart())
|
||||
{
|
||||
temp = UsartModel_GetFormattedTemperature();
|
||||
UsartHardware_TransmitString(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _USARTCONDUCTOR_H
|
||||
#define _USARTCONDUCTOR_H
|
||||
|
||||
void UsartConductor_Init(void);
|
||||
void UsartConductor_Run(void);
|
||||
|
||||
#endif // _USARTCONDUCTOR_H
|
||||
#ifndef _USARTCONDUCTOR_H
|
||||
#define _USARTCONDUCTOR_H
|
||||
|
||||
void UsartConductor_Init(void);
|
||||
void UsartConductor_Run(void);
|
||||
|
||||
#endif // _USARTCONDUCTOR_H
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
void Usart_ConfigureUsartIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = USART0_TX_PIN;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0;
|
||||
AT91C_BASE_PIOA->PIO_PDR = USART0_TX_PIN;
|
||||
}
|
||||
|
||||
void Usart_EnablePeripheralClock(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = ((uint32)1) << USART0_CLOCK_ENABLE;
|
||||
}
|
||||
|
||||
void Usart_Reset(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0xffffffff;
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
|
||||
}
|
||||
|
||||
void Usart_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK;
|
||||
}
|
||||
|
||||
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = baudRateRegisterSetting;
|
||||
}
|
||||
|
||||
void Usart_Enable(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_TXEN;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
void Usart_ConfigureUsartIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = USART0_TX_PIN;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0;
|
||||
AT91C_BASE_PIOA->PIO_PDR = USART0_TX_PIN;
|
||||
}
|
||||
|
||||
void Usart_EnablePeripheralClock(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = ((uint32)1) << USART0_CLOCK_ENABLE;
|
||||
}
|
||||
|
||||
void Usart_Reset(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0xffffffff;
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
|
||||
}
|
||||
|
||||
void Usart_ConfigureMode(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK;
|
||||
}
|
||||
|
||||
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = baudRateRegisterSetting;
|
||||
}
|
||||
|
||||
void Usart_Enable(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = AT91C_US_TXEN;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _USARTCONFIGURATOR_H
|
||||
#define _USARTCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Usart_ConfigureUsartIO(void);
|
||||
void Usart_EnablePeripheralClock(void);
|
||||
void Usart_Reset(void);
|
||||
void Usart_ConfigureMode(void);
|
||||
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting);
|
||||
void Usart_Enable(void);
|
||||
|
||||
#endif // _USARTCONFIGURATOR_H
|
||||
#ifndef _USARTCONFIGURATOR_H
|
||||
#define _USARTCONFIGURATOR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Usart_ConfigureUsartIO(void);
|
||||
void Usart_EnablePeripheralClock(void);
|
||||
void Usart_Reset(void);
|
||||
void Usart_ConfigureMode(void);
|
||||
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting);
|
||||
void Usart_Enable(void);
|
||||
|
||||
#endif // _USARTCONFIGURATOR_H
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartConfigurator.h"
|
||||
#include "UsartPutChar.h"
|
||||
|
||||
void UsartHardware_Init(uint8 baudRateRegisterSetting)
|
||||
{
|
||||
Usart_ConfigureUsartIO();
|
||||
Usart_EnablePeripheralClock();
|
||||
Usart_Reset();
|
||||
Usart_ConfigureMode();
|
||||
Usart_SetBaudRateRegister(baudRateRegisterSetting);
|
||||
Usart_Enable();
|
||||
}
|
||||
|
||||
void UsartHardware_TransmitString(char* data)
|
||||
{
|
||||
while(*data != NULL)
|
||||
{
|
||||
Usart_PutChar(*data++);
|
||||
}
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "UsartConfigurator.h"
|
||||
#include "UsartPutChar.h"
|
||||
|
||||
void UsartHardware_Init(uint8 baudRateRegisterSetting)
|
||||
{
|
||||
Usart_ConfigureUsartIO();
|
||||
Usart_EnablePeripheralClock();
|
||||
Usart_Reset();
|
||||
Usart_ConfigureMode();
|
||||
Usart_SetBaudRateRegister(baudRateRegisterSetting);
|
||||
Usart_Enable();
|
||||
}
|
||||
|
||||
void UsartHardware_TransmitString(char* data)
|
||||
{
|
||||
while(*data != NULL)
|
||||
{
|
||||
Usart_PutChar(*data++);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _USARTHARDWARE_H
|
||||
#define _USARTHARDWARE_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void UsartHardware_Init(uint8 baudRateRegisterSetting);
|
||||
void UsartHardware_TransmitString(char* data);
|
||||
|
||||
#endif // _USARTHARDWARE_H
|
||||
#ifndef _USARTHARDWARE_H
|
||||
#define _USARTHARDWARE_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void UsartHardware_Init(uint8 baudRateRegisterSetting);
|
||||
void UsartHardware_TransmitString(char* data);
|
||||
|
||||
#endif // _USARTHARDWARE_H
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
char formattedTemperature[32];
|
||||
char* wakeup = "It's Awesome Time!\n";
|
||||
|
||||
uint8 UsartModel_GetBaudRateRegisterSetting(void)
|
||||
{
|
||||
return UsartModel_CalculateBaudRateRegisterSetting(MASTER_CLOCK, USART0_BAUDRATE);
|
||||
}
|
||||
|
||||
char* UsartModel_GetFormattedTemperature(void)
|
||||
{
|
||||
float temperature = TemperatureFilter_GetTemperatureInCelcius();
|
||||
if (temperature == -INFINITY)
|
||||
{
|
||||
sprintf(formattedTemperature, "%s", "Temperature sensor failure!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(formattedTemperature, "%.1f C\n", temperature);
|
||||
}
|
||||
return formattedTemperature;
|
||||
}
|
||||
|
||||
char* UsartModel_GetWakeupMessage(void)
|
||||
{
|
||||
return wakeup;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
char formattedTemperature[32];
|
||||
char* wakeup = "It's Awesome Time!\n";
|
||||
|
||||
uint8 UsartModel_GetBaudRateRegisterSetting(void)
|
||||
{
|
||||
return UsartModel_CalculateBaudRateRegisterSetting(MASTER_CLOCK, USART0_BAUDRATE);
|
||||
}
|
||||
|
||||
char* UsartModel_GetFormattedTemperature(void)
|
||||
{
|
||||
float temperature = TemperatureFilter_GetTemperatureInCelcius();
|
||||
if (temperature == -INFINITY)
|
||||
{
|
||||
sprintf(formattedTemperature, "%s", "Temperature sensor failure!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(formattedTemperature, "%.1f C\n", temperature);
|
||||
}
|
||||
return formattedTemperature;
|
||||
}
|
||||
|
||||
char* UsartModel_GetWakeupMessage(void)
|
||||
{
|
||||
return wakeup;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _USARTMODEL_H
|
||||
#define _USARTMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
uint8 UsartModel_GetBaudRateRegisterSetting(void);
|
||||
char* UsartModel_GetFormattedTemperature(void);
|
||||
char* UsartModel_GetWakeupMessage(void);
|
||||
|
||||
#endif // _USARTMODEL_H
|
||||
#ifndef _USARTMODEL_H
|
||||
#define _USARTMODEL_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
uint8 UsartModel_GetBaudRateRegisterSetting(void);
|
||||
char* UsartModel_GetFormattedTemperature(void);
|
||||
char* UsartModel_GetWakeupMessage(void);
|
||||
|
||||
#endif // _USARTMODEL_H
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
#ifdef SIMULATE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
void Usart_PutChar(char data)
|
||||
{
|
||||
while(!Usart_ReadyToTransmit());
|
||||
#ifdef SIMULATE
|
||||
printf("%c", data);
|
||||
#else
|
||||
AT91C_BASE_US0->US_THR = data;
|
||||
#endif
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
#ifdef SIMULATE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
void Usart_PutChar(char data)
|
||||
{
|
||||
while(!Usart_ReadyToTransmit());
|
||||
#ifdef SIMULATE
|
||||
printf("%c", data);
|
||||
#else
|
||||
AT91C_BASE_US0->US_THR = data;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _USARTPUT_HAR_H
|
||||
#define _USARTPUT_HAR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Usart_PutChar(char data);
|
||||
|
||||
#endif // _USARTPUT_HAR_H
|
||||
#ifndef _USARTPUT_HAR_H
|
||||
#define _USARTPUT_HAR_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void Usart_PutChar(char data);
|
||||
|
||||
#endif // _USARTPUT_HAR_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
bool Usart_ReadyToTransmit(void)
|
||||
{
|
||||
return (AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) > 0;
|
||||
}
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
bool Usart_ReadyToTransmit(void)
|
||||
{
|
||||
return (AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) > 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _USARTTRANSMITBUFFERSTATUS_H
|
||||
#define _USARTTRANSMITBUFFERSTATUS_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
bool Usart_ReadyToTransmit(void);
|
||||
|
||||
#endif // _USARTTRANSMITBUFFERSTATUS_H
|
||||
#ifndef _USARTTRANSMITBUFFERSTATUS_H
|
||||
#define _USARTTRANSMITBUFFERSTATUS_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
bool Usart_ReadyToTransmit(void);
|
||||
|
||||
#endif // _USARTTRANSMITBUFFERSTATUS_H
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include "Types.h"
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "MockAdcModel.h"
|
||||
#include "MockAdcHardware.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
AdcHardware_Init_Expect();
|
||||
AdcConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfItIsNotTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSample_ExpectAndReturn(293U);
|
||||
AdcModel_ProcessInput_Expect(293U);
|
||||
AdcHardware_StartConversion_Expect();
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testJustHereToTest_Should_ProperlyPassAStructAndVerifyIt(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 5;
|
||||
TestStruct.y = 7;
|
||||
|
||||
AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
}
|
||||
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentXIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 6;
|
||||
// TestStruct.y = 7;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
//
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentYIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 5;
|
||||
// TestStruct.y = 8;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected1(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 99;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected2(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 98;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_FALSE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_YetAnotherTest_Should_VerifyThatPointersToStructsAreTestable(void)
|
||||
{
|
||||
uint32 TestNum = 3;
|
||||
|
||||
AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_YetAnotherTest());
|
||||
}
|
||||
|
||||
//void test_AdcConductor_YetAnotherTest_Should_FailIfYouUncommentThisTestBecauseTheValuePointedToIsWrong(void)
|
||||
//{
|
||||
// uint32 TestNum = 7;
|
||||
//
|
||||
// AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, FALSE);
|
||||
//
|
||||
// TEST_ASSERT_FALSE(AdcConductor_YetAnotherTest());
|
||||
//}
|
||||
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include "Types.h"
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "MockAdcModel.h"
|
||||
#include "MockAdcHardware.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
AdcHardware_Init_Expect();
|
||||
AdcConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfItIsNotTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSample_ExpectAndReturn(293U);
|
||||
AdcModel_ProcessInput_Expect(293U);
|
||||
AdcHardware_StartConversion_Expect();
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testJustHereToTest_Should_ProperlyPassAStructAndVerifyIt(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 5;
|
||||
TestStruct.y = 7;
|
||||
|
||||
AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
}
|
||||
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentXIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 6;
|
||||
// TestStruct.y = 7;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
//
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentYIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 5;
|
||||
// TestStruct.y = 8;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected1(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 99;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected2(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 98;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_FALSE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_YetAnotherTest_Should_VerifyThatPointersToStructsAreTestable(void)
|
||||
{
|
||||
uint32 TestNum = 3;
|
||||
|
||||
AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_YetAnotherTest());
|
||||
}
|
||||
|
||||
//void test_AdcConductor_YetAnotherTest_Should_FailIfYouUncommentThisTestBecauseTheValuePointedToIsWrong(void)
|
||||
//{
|
||||
// uint32 TestNum = 7;
|
||||
//
|
||||
// AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, FALSE);
|
||||
//
|
||||
// TEST_ASSERT_FALSE(AdcConductor_YetAnotherTest());
|
||||
//}
|
||||
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "MockAdcHardwareConfigurator.h"
|
||||
#include "MockAdcTemperatureSensor.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateToConfiguratorAndTemperatureSensor(void)
|
||||
{
|
||||
Adc_Reset_Expect();
|
||||
Adc_ConfigureMode_Expect();
|
||||
Adc_EnableTemperatureChannel_Expect();
|
||||
Adc_StartTemperatureSensorConversion_Expect();
|
||||
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_FALSE_WhenTemperatureSensorSampleReadyReturns_FALSE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT(!AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_TRUE_WhenTemperatureSensorSampleReadyReturns_TRUE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT(AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
|
||||
{
|
||||
uint16 sample;
|
||||
Adc_ReadTemperatureSensor_ExpectAndReturn(847);
|
||||
|
||||
sample = AdcHardware_GetSample();
|
||||
TEST_ASSERT_EQUAL(847, sample);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "MockAdcHardwareConfigurator.h"
|
||||
#include "MockAdcTemperatureSensor.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateToConfiguratorAndTemperatureSensor(void)
|
||||
{
|
||||
Adc_Reset_Expect();
|
||||
Adc_ConfigureMode_Expect();
|
||||
Adc_EnableTemperatureChannel_Expect();
|
||||
Adc_StartTemperatureSensorConversion_Expect();
|
||||
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_FALSE_WhenTemperatureSensorSampleReadyReturns_FALSE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT(!AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_TRUE_WhenTemperatureSensorSampleReadyReturns_TRUE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT(AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
|
||||
{
|
||||
uint16 sample;
|
||||
Adc_ReadTemperatureSensor_ExpectAndReturn(847);
|
||||
|
||||
sample = AdcHardware_GetSample();
|
||||
TEST_ASSERT_EQUAL(847, sample);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testResetShouldResetTheAdcConverterPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_SWRST, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetAdcModeRegisterAppropriately(void)
|
||||
{
|
||||
uint32 prescaler = (MASTER_CLOCK / (2 * 2000000)) - 1; // 5MHz ADC clock
|
||||
|
||||
AT91C_BASE_ADC->ADC_MR = 0;
|
||||
|
||||
Adc_ConfigureMode();
|
||||
|
||||
TEST_ASSERT_EQUAL(prescaler, (AT91C_BASE_ADC->ADC_MR & AT91C_ADC_PRESCAL) >> 8);
|
||||
}
|
||||
|
||||
void testEnableTemperatureChannelShouldEnableTheAppropriateAdcInput(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0;
|
||||
|
||||
Adc_EnableTemperatureChannel();
|
||||
|
||||
TEST_ASSERT_EQUAL(0x1 << 4, AT91C_BASE_ADC->ADC_CHER);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testResetShouldResetTheAdcConverterPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_SWRST, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetAdcModeRegisterAppropriately(void)
|
||||
{
|
||||
uint32 prescaler = (MASTER_CLOCK / (2 * 2000000)) - 1; // 5MHz ADC clock
|
||||
|
||||
AT91C_BASE_ADC->ADC_MR = 0;
|
||||
|
||||
Adc_ConfigureMode();
|
||||
|
||||
TEST_ASSERT_EQUAL(prescaler, (AT91C_BASE_ADC->ADC_MR & AT91C_ADC_PRESCAL) >> 8);
|
||||
}
|
||||
|
||||
void testEnableTemperatureChannelShouldEnableTheAppropriateAdcInput(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0;
|
||||
|
||||
Adc_EnableTemperatureChannel();
|
||||
|
||||
TEST_ASSERT_EQUAL(0x1 << 4, AT91C_BASE_ADC->ADC_CHER);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureCalculator.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
|
||||
{
|
||||
TemperatureCalculator_Calculate_ExpectAndReturn(21473, 23.5f);
|
||||
TemperatureFilter_ProcessInput_Expect(23.5f);
|
||||
AdcModel_ProcessInput(21473);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureCalculator.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
|
||||
{
|
||||
TemperatureCalculator_Calculate_ExpectAndReturn(21473, 23.5f);
|
||||
TemperatureFilter_ProcessInput_Expect(23.5f);
|
||||
AdcModel_ProcessInput(21473);
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldStartTemperatureSensorConversionWhenTriggered(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_START, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testTemperatureSensorSampleReadyShouldReturnChannelConversionCompletionStatus(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_SR = 0;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = ~AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = 0xffffffff;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
}
|
||||
|
||||
void testReadTemperatureSensorShouldFetchAndTranslateLatestReadingToMillivolts(void)
|
||||
{
|
||||
uint16 result;
|
||||
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 138;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(404, result);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 854;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(2502, result);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldStartTemperatureSensorConversionWhenTriggered(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_START, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testTemperatureSensorSampleReadyShouldReturnChannelConversionCompletionStatus(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_SR = 0;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = ~AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = 0xffffffff;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
}
|
||||
|
||||
void testReadTemperatureSensorShouldFetchAndTranslateLatestReadingToMillivolts(void)
|
||||
{
|
||||
uint16 result;
|
||||
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 138;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(404, result);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 854;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(2502, result);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "MockModel.h"
|
||||
#include "MockUsartConductor.h"
|
||||
#include "MockAdcConductor.h"
|
||||
#include "MockTimerConductor.h"
|
||||
#include "MockIntrinsicsWrapper.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallInitOfAllConductorsAndTheModel(void)
|
||||
{
|
||||
Model_Init_Expect();
|
||||
UsartConductor_Init_Expect();
|
||||
AdcConductor_Init_Expect();
|
||||
TimerConductor_Init_Expect();
|
||||
Interrupt_Enable_Expect();
|
||||
|
||||
Executor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
|
||||
{
|
||||
UsartConductor_Run_Expect();
|
||||
TimerConductor_Run_Expect();
|
||||
AdcConductor_Run_Expect();
|
||||
|
||||
TEST_ASSERT_EQUAL(TRUE, Executor_Run());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "MockModel.h"
|
||||
#include "MockUsartConductor.h"
|
||||
#include "MockAdcConductor.h"
|
||||
#include "MockTimerConductor.h"
|
||||
#include "MockIntrinsicsWrapper.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallInitOfAllConductorsAndTheModel(void)
|
||||
{
|
||||
Model_Init_Expect();
|
||||
UsartConductor_Init_Expect();
|
||||
AdcConductor_Init_Expect();
|
||||
TimerConductor_Init_Expect();
|
||||
Interrupt_Enable_Expect();
|
||||
|
||||
Executor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
|
||||
{
|
||||
UsartConductor_Run_Expect();
|
||||
TimerConductor_Run_Expect();
|
||||
AdcConductor_Run_Expect();
|
||||
|
||||
TEST_ASSERT_EQUAL(TRUE, Executor_Run());
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "MockExecutor.h"
|
||||
#include "Main.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void)
|
||||
{
|
||||
Executor_Init_Expect();
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(FALSE);
|
||||
|
||||
AppMain();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "MockExecutor.h"
|
||||
#include "Main.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void)
|
||||
{
|
||||
Executor_Init_Expect();
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(FALSE);
|
||||
|
||||
AppMain();
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Model.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallSchedulerAndTemperatureFilterInit(void)
|
||||
{
|
||||
TaskScheduler_Init_Expect();
|
||||
TemperatureFilter_Init_Expect();
|
||||
Model_Init();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Model.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallSchedulerAndTemperatureFilterInit(void)
|
||||
{
|
||||
TaskScheduler_Init_Expect();
|
||||
TemperatureFilter_Init_Expect();
|
||||
Model_Init();
|
||||
}
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskAfter1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldClearUsartDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskEvery1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1300);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(3100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1001);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskAfter100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(99);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldClearAdcDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskEvery100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(121);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(356);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(101);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(199);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskAfter1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldClearUsartDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskEvery1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1300);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(3100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1001);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskAfter100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(99);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldClearAdcDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskEvery100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(121);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(356);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(101);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(199);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testTemperatureCalculatorShouldCalculateTemperatureFromMillivolts(void)
|
||||
{
|
||||
float result;
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
result = TemperatureCalculator_Calculate(1000);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 25.0f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(2985);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 68.317f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(3);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, -19.96f, result);
|
||||
}
|
||||
|
||||
void testShouldReturnNegativeInfinityWhen_0_millivoltsInput(void)
|
||||
{
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0000001f, -INFINITY, TemperatureCalculator_Calculate(0));
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testTemperatureCalculatorShouldCalculateTemperatureFromMillivolts(void)
|
||||
{
|
||||
float result;
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
result = TemperatureCalculator_Calculate(1000);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 25.0f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(2985);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 68.317f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(3);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, -19.96f, result);
|
||||
}
|
||||
|
||||
void testShouldReturnNegativeInfinityWhen_0_millivoltsInput(void)
|
||||
{
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0000001f, -INFINITY, TemperatureCalculator_Calculate(0));
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeTemeratureToInvalidValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, -INFINITY, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void testShouldInitializeTemperatureAfterCallToInit(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(17.8f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 17.8f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(32.6f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 32.6f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void setValueAndVerifyResponse(float input, float response)
|
||||
{
|
||||
float actual;
|
||||
TemperatureFilter_ProcessInput(input);
|
||||
actual = TemperatureFilter_GetTemperatureInCelcius();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, response, actual);
|
||||
}
|
||||
|
||||
void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(0.0f, 0.0f);
|
||||
setValueAndVerifyResponse(10.0f, 2.5f);
|
||||
setValueAndVerifyResponse(10.0f, 4.375f);
|
||||
setValueAndVerifyResponse(10.0f, 5.78125f);
|
||||
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(0.0f, 75.0f);
|
||||
setValueAndVerifyResponse(0.0f, 56.25f);
|
||||
setValueAndVerifyResponse(0.0f, 42.1875f);
|
||||
}
|
||||
|
||||
void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(invalidTemperature, -INFINITY);
|
||||
setValueAndVerifyResponse(14.3f, 14.3f);
|
||||
}
|
||||
|
||||
void testShouldResetAverageIfPassedInfinityOrInvalidValue(void)
|
||||
{
|
||||
setInvalidTemperatureAndVerifyReinitialized(-INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+NAN);
|
||||
setInvalidTemperatureAndVerifyReinitialized(-NAN);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeTemeratureToInvalidValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, -INFINITY, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void testShouldInitializeTemperatureAfterCallToInit(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(17.8f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 17.8f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(32.6f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 32.6f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void setValueAndVerifyResponse(float input, float response)
|
||||
{
|
||||
float actual;
|
||||
TemperatureFilter_ProcessInput(input);
|
||||
actual = TemperatureFilter_GetTemperatureInCelcius();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, response, actual);
|
||||
}
|
||||
|
||||
void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(0.0f, 0.0f);
|
||||
setValueAndVerifyResponse(10.0f, 2.5f);
|
||||
setValueAndVerifyResponse(10.0f, 4.375f);
|
||||
setValueAndVerifyResponse(10.0f, 5.78125f);
|
||||
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(0.0f, 75.0f);
|
||||
setValueAndVerifyResponse(0.0f, 56.25f);
|
||||
setValueAndVerifyResponse(0.0f, 42.1875f);
|
||||
}
|
||||
|
||||
void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(invalidTemperature, -INFINITY);
|
||||
setValueAndVerifyResponse(14.3f, 14.3f);
|
||||
}
|
||||
|
||||
void testShouldResetAverageIfPassedInfinityOrInvalidValue(void)
|
||||
{
|
||||
setInvalidTemperatureAndVerifyReinitialized(-INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+NAN);
|
||||
setInvalidTemperatureAndVerifyReinitialized(-NAN);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "MockTimerHardware.h"
|
||||
#include "MockTimerModel.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
TimerHardware_Init_Expect();
|
||||
|
||||
TimerConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
|
||||
{
|
||||
Timer_GetSystemTime_ExpectAndReturn(1230);
|
||||
TimerModel_UpdateTime_Expect(1230);
|
||||
TimerConductor_Run();
|
||||
|
||||
Timer_GetSystemTime_ExpectAndReturn(837460);
|
||||
TimerModel_UpdateTime_Expect(837460);
|
||||
TimerConductor_Run();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "MockTimerHardware.h"
|
||||
#include "MockTimerModel.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
TimerHardware_Init_Expect();
|
||||
|
||||
TimerConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
|
||||
{
|
||||
Timer_GetSystemTime_ExpectAndReturn(1230);
|
||||
TimerModel_UpdateTime_Expect(1230);
|
||||
TimerConductor_Run();
|
||||
|
||||
Timer_GetSystemTime_ExpectAndReturn(837460);
|
||||
TimerModel_UpdateTime_Expect(837460);
|
||||
TimerConductor_Run();
|
||||
}
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockTimerInterruptConfigurator.h"
|
||||
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
AT91S_PIO PioBPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
TIMER0_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
PIOB_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
AT91C_BASE_TC0->TC_IDR = 0;
|
||||
AT91C_BASE_TC0->TC_SR = 0xFFFFFFFF;
|
||||
Timer_Reset();
|
||||
TEST_ASSERT_EQUAL(0x00000002, AT91C_BASE_TC0->TC_CCR);
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_TC0->TC_IDR);
|
||||
// CANNOT BE VERIFIED!! TEST_ASSERT_EQUAL(0X00000000, AT91C_BASE_TC0->TC_SR);
|
||||
}
|
||||
|
||||
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = 0;
|
||||
Timer_EnableOutputPin();
|
||||
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, AT91C_BASE_PIOB->PIO_PDR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00000004, AT91C_BASE_TC0->TC_CMR & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00008000, AT91C_BASE_TC0->TC_CMR & 0x00008000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00004000, AT91C_BASE_TC0->TC_CMR & 0x00006000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x000C0000, AT91C_BASE_TC0->TC_CMR & 0x000C0000);
|
||||
}
|
||||
|
||||
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 0;
|
||||
Timer_ConfigurePeriod();
|
||||
TEST_ASSERT_EQUAL(469, AT91C_BASE_TC0->TC_RC);
|
||||
}
|
||||
|
||||
void testEnableShouldSetEnableFlagForTimer0(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Enable();
|
||||
TEST_ASSERT_EQUAL_INT(1, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt_Expect();
|
||||
Timer_ResetSystemTime_Expect();
|
||||
Timer_ConfigureInterrupt_Expect();
|
||||
Timer_EnableInterrupt_Expect();
|
||||
|
||||
Timer_ConfigureInterruptHandler();
|
||||
}
|
||||
|
||||
void testStartShouldSetSoftwareTriggerFlag(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Start();
|
||||
TEST_ASSERT_EQUAL(0x04, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockTimerInterruptConfigurator.h"
|
||||
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
AT91S_PIO PioBPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
TIMER0_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
PIOB_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
AT91C_BASE_TC0->TC_IDR = 0;
|
||||
AT91C_BASE_TC0->TC_SR = 0xFFFFFFFF;
|
||||
Timer_Reset();
|
||||
TEST_ASSERT_EQUAL(0x00000002, AT91C_BASE_TC0->TC_CCR);
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_TC0->TC_IDR);
|
||||
// CANNOT BE VERIFIED!! TEST_ASSERT_EQUAL(0X00000000, AT91C_BASE_TC0->TC_SR);
|
||||
}
|
||||
|
||||
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = 0;
|
||||
Timer_EnableOutputPin();
|
||||
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, AT91C_BASE_PIOB->PIO_PDR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00000004, AT91C_BASE_TC0->TC_CMR & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00008000, AT91C_BASE_TC0->TC_CMR & 0x00008000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00004000, AT91C_BASE_TC0->TC_CMR & 0x00006000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x000C0000, AT91C_BASE_TC0->TC_CMR & 0x000C0000);
|
||||
}
|
||||
|
||||
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 0;
|
||||
Timer_ConfigurePeriod();
|
||||
TEST_ASSERT_EQUAL(469, AT91C_BASE_TC0->TC_RC);
|
||||
}
|
||||
|
||||
void testEnableShouldSetEnableFlagForTimer0(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Enable();
|
||||
TEST_ASSERT_EQUAL_INT(1, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt_Expect();
|
||||
Timer_ResetSystemTime_Expect();
|
||||
Timer_ConfigureInterrupt_Expect();
|
||||
Timer_EnableInterrupt_Expect();
|
||||
|
||||
Timer_ConfigureInterruptHandler();
|
||||
}
|
||||
|
||||
void testStartShouldSetSoftwareTriggerFlag(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Start();
|
||||
TEST_ASSERT_EQUAL(0x04, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "MockTimerConfigurator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateAppropriatelyToConfigurator(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks_Expect();
|
||||
Timer_Reset_Expect();
|
||||
Timer_ConfigureMode_Expect();
|
||||
Timer_ConfigurePeriod_Expect();
|
||||
Timer_EnableOutputPin_Expect();
|
||||
Timer_Enable_Expect();
|
||||
Timer_ConfigureInterruptHandler_Expect();
|
||||
Timer_Start_Expect();
|
||||
|
||||
TimerHardware_Init();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "MockTimerConfigurator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateAppropriatelyToConfigurator(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks_Expect();
|
||||
Timer_Reset_Expect();
|
||||
Timer_ConfigureMode_Expect();
|
||||
Timer_ConfigurePeriod_Expect();
|
||||
Timer_EnableOutputPin_Expect();
|
||||
Timer_Enable_Expect();
|
||||
Timer_ConfigureInterruptHandler_Expect();
|
||||
Timer_Start_Expect();
|
||||
|
||||
TimerHardware_Init();
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_AIC AicPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_TIMER0_ID_MASK_ShouldBeCorrect(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(((uint32)0x1) << AT91C_ID_TC0, TIMER0_ID_MASK);
|
||||
}
|
||||
|
||||
void testDisableInterruptDisablesTimer0InterruptInTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = 0;
|
||||
Timer_DisableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IDCR);
|
||||
}
|
||||
|
||||
void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
|
||||
{
|
||||
Timer_SetSystemTime_Expect(0);
|
||||
Timer_ResetSystemTime();
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)NULL;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(
|
||||
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000060);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptPriorityInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(1, AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldClearTimer0InterruptOnTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_ICCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldEnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(AT91C_TC_CPCS, AT91C_BASE_TC0->TC_IER);
|
||||
}
|
||||
|
||||
void testEnableInterruptShouldEnableTimer0InterruptsInInterruptCotroller(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = 0;
|
||||
Timer_EnableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IECR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_AIC AicPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_TIMER0_ID_MASK_ShouldBeCorrect(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(((uint32)0x1) << AT91C_ID_TC0, TIMER0_ID_MASK);
|
||||
}
|
||||
|
||||
void testDisableInterruptDisablesTimer0InterruptInTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = 0;
|
||||
Timer_DisableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IDCR);
|
||||
}
|
||||
|
||||
void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
|
||||
{
|
||||
Timer_SetSystemTime_Expect(0);
|
||||
Timer_ResetSystemTime();
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)NULL;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(
|
||||
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000060);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptPriorityInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(1, AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldClearTimer0InterruptOnTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_ICCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldEnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(AT91C_TC_CPCS, AT91C_BASE_TC0->TC_IER);
|
||||
}
|
||||
|
||||
void testEnableInterruptShouldEnableTimer0InterruptsInInterruptCotroller(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = 0;
|
||||
Timer_EnableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IECR);
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testSetAndGetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(129837);
|
||||
TEST_ASSERT_EQUAL(129837, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(UINT32_MAX);
|
||||
TEST_ASSERT_EQUAL(UINT32_MAX, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimeOnlyIfStatusHasCompareRegisterCOverflowBitSet(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = ~AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0xffffffff;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimerBy_10(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(10, Timer_GetSystemTime());
|
||||
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(20, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(39426857);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(39426867, Timer_GetSystemTime());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testSetAndGetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(129837);
|
||||
TEST_ASSERT_EQUAL(129837, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(UINT32_MAX);
|
||||
TEST_ASSERT_EQUAL(UINT32_MAX, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimeOnlyIfStatusHasCompareRegisterCOverflowBitSet(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = ~AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0xffffffff;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimerBy_10(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(10, Timer_GetSystemTime());
|
||||
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(20, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(39426857);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(39426867, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testUpdateTimeShouldDelegateToTaskScheduler(void)
|
||||
{
|
||||
TaskScheduler_Update_Expect(19387L);
|
||||
TimerModel_UpdateTime(19387L);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testUpdateTimeShouldDelegateToTaskScheduler(void)
|
||||
{
|
||||
TaskScheduler_Update_Expect(19387L);
|
||||
TimerModel_UpdateTime(19387L);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
|
||||
{
|
||||
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
|
||||
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
|
||||
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
|
||||
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
|
||||
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
|
||||
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
|
||||
{
|
||||
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
|
||||
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
|
||||
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
|
||||
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
|
||||
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
|
||||
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "MockUsartModel.h"
|
||||
#include "MockUsartHardware.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeHardwareWhenInitCalled(void)
|
||||
{
|
||||
UsartModel_GetBaudRateRegisterSetting_ExpectAndReturn(4);
|
||||
UsartModel_GetWakeupMessage_ExpectAndReturn("Hey there!");
|
||||
UsartHardware_TransmitString_Expect("Hey there!");
|
||||
UsartHardware_Init_Expect(4);
|
||||
|
||||
UsartConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetCurrentTemperatureAndTransmitIfSchedulerSaysItIsTime(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(TRUE);
|
||||
UsartModel_GetFormattedTemperature_ExpectAndReturn("hey there");
|
||||
UsartHardware_TransmitString_Expect("hey there");
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "MockUsartModel.h"
|
||||
#include "MockUsartHardware.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeHardwareWhenInitCalled(void)
|
||||
{
|
||||
UsartModel_GetBaudRateRegisterSetting_ExpectAndReturn(4);
|
||||
UsartModel_GetWakeupMessage_ExpectAndReturn("Hey there!");
|
||||
UsartHardware_TransmitString_Expect("Hey there!");
|
||||
UsartHardware_Init_Expect(4);
|
||||
|
||||
UsartConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetCurrentTemperatureAndTransmitIfSchedulerSaysItIsTime(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(TRUE);
|
||||
UsartModel_GetFormattedTemperature_ExpectAndReturn("hey there");
|
||||
UsartHardware_TransmitString_Expect("hey there");
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
AT91S_PIO PioAPeripheral;
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testConfigureUsartIOShouldConfigureUsartTxPinfForPeripheralIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = 0;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0xffffffff;
|
||||
AT91C_BASE_PIOA->PIO_PDR = 0;
|
||||
Usart_ConfigureUsartIO();
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_ASR);
|
||||
TEST_ASSERT_EQUAL(0, AT91C_BASE_PIOA->PIO_BSR);
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_PDR);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClockShouldEnableClockToUsartPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Usart_EnablePeripheralClock();
|
||||
TEST_ASSERT_EQUAL(((uint32)1) << USART0_CLOCK_ENABLE, AT91C_BASE_PMC->PMC_PCER);
|
||||
}
|
||||
|
||||
void testResetShouldDisableAllUsartInterrupts(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_US0->US_IDR);
|
||||
}
|
||||
|
||||
void testResetShouldResetUsartTransmitterAndReceiver(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetUsartModeToAsynchronous(void)
|
||||
{
|
||||
uint32 asyncMode = (AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK);
|
||||
|
||||
AT91C_BASE_US0->US_MR = ~asyncMode;
|
||||
Usart_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(asyncMode, AT91C_BASE_US0->US_MR);
|
||||
}
|
||||
|
||||
void testSetBaudRateRegisterShouldSetUsartBaudRateRegisterToValuePassedAsParameter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = 0;
|
||||
Usart_SetBaudRateRegister(3);
|
||||
TEST_ASSERT_EQUAL(3, AT91C_BASE_US0->US_BRGR);
|
||||
Usart_SetBaudRateRegister(251);
|
||||
TEST_ASSERT_EQUAL(251, AT91C_BASE_US0->US_BRGR);
|
||||
}
|
||||
|
||||
|
||||
void testEnableShouldEnableUsart0Transmitter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Enable();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_TXEN, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
AT91S_PIO PioAPeripheral;
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testConfigureUsartIOShouldConfigureUsartTxPinfForPeripheralIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = 0;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0xffffffff;
|
||||
AT91C_BASE_PIOA->PIO_PDR = 0;
|
||||
Usart_ConfigureUsartIO();
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_ASR);
|
||||
TEST_ASSERT_EQUAL(0, AT91C_BASE_PIOA->PIO_BSR);
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_PDR);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClockShouldEnableClockToUsartPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Usart_EnablePeripheralClock();
|
||||
TEST_ASSERT_EQUAL(((uint32)1) << USART0_CLOCK_ENABLE, AT91C_BASE_PMC->PMC_PCER);
|
||||
}
|
||||
|
||||
void testResetShouldDisableAllUsartInterrupts(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_US0->US_IDR);
|
||||
}
|
||||
|
||||
void testResetShouldResetUsartTransmitterAndReceiver(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetUsartModeToAsynchronous(void)
|
||||
{
|
||||
uint32 asyncMode = (AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK);
|
||||
|
||||
AT91C_BASE_US0->US_MR = ~asyncMode;
|
||||
Usart_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(asyncMode, AT91C_BASE_US0->US_MR);
|
||||
}
|
||||
|
||||
void testSetBaudRateRegisterShouldSetUsartBaudRateRegisterToValuePassedAsParameter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = 0;
|
||||
Usart_SetBaudRateRegister(3);
|
||||
TEST_ASSERT_EQUAL(3, AT91C_BASE_US0->US_BRGR);
|
||||
Usart_SetBaudRateRegister(251);
|
||||
TEST_ASSERT_EQUAL(251, AT91C_BASE_US0->US_BRGR);
|
||||
}
|
||||
|
||||
|
||||
void testEnableShouldEnableUsart0Transmitter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Enable();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_TXEN, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockUsartConfigurator.h"
|
||||
#include "MockUsartPutChar.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldConfigureUsartPeripheralByCallingConfiguratorAppropriately(void)
|
||||
{
|
||||
Usart_ConfigureUsartIO_Expect();
|
||||
Usart_EnablePeripheralClock_Expect();
|
||||
Usart_Reset_Expect();
|
||||
Usart_ConfigureMode_Expect();
|
||||
Usart_SetBaudRateRegister_Expect(73);
|
||||
Usart_Enable_Expect();
|
||||
|
||||
UsartHardware_Init(73);
|
||||
}
|
||||
|
||||
void testTransmitStringShouldSendDesiredStringOutUsingUsart(void)
|
||||
{
|
||||
Usart_PutChar_Expect('h');
|
||||
Usart_PutChar_Expect('e');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('o');
|
||||
|
||||
UsartHardware_TransmitString("hello");
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockUsartConfigurator.h"
|
||||
#include "MockUsartPutChar.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldConfigureUsartPeripheralByCallingConfiguratorAppropriately(void)
|
||||
{
|
||||
Usart_ConfigureUsartIO_Expect();
|
||||
Usart_EnablePeripheralClock_Expect();
|
||||
Usart_Reset_Expect();
|
||||
Usart_ConfigureMode_Expect();
|
||||
Usart_SetBaudRateRegister_Expect(73);
|
||||
Usart_Enable_Expect();
|
||||
|
||||
UsartHardware_Init(73);
|
||||
}
|
||||
|
||||
void testTransmitStringShouldSendDesiredStringOutUsingUsart(void)
|
||||
{
|
||||
Usart_PutChar_Expect('h');
|
||||
Usart_PutChar_Expect('e');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('o');
|
||||
|
||||
UsartHardware_TransmitString("hello");
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
#include "MockUsartBaudRateRegisterCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSetting(void)
|
||||
{
|
||||
uint8 dummyRegisterSetting = 17;
|
||||
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);
|
||||
|
||||
TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
|
||||
}
|
||||
|
||||
void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(25.0f);
|
||||
TEST_ASSERT_EQUAL_STRING("25.0 C\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnErrorMessageUponInvalidTemperatureValue(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(-INFINITY);
|
||||
TEST_ASSERT_EQUAL_STRING("Temperature sensor failure!\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
#include "MockUsartBaudRateRegisterCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSetting(void)
|
||||
{
|
||||
uint8 dummyRegisterSetting = 17;
|
||||
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);
|
||||
|
||||
TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
|
||||
}
|
||||
|
||||
void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(25.0f);
|
||||
TEST_ASSERT_EQUAL_STRING("25.0 C\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnErrorMessageUponInvalidTemperatureValue(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(-INFINITY);
|
||||
TEST_ASSERT_EQUAL_STRING("Temperature sensor failure!\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnWakeupMessage(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_STRING("It's Awesome Time!\n", UsartModel_GetWakeupMessage());
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "MockUsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testPutCharShouldWriteDesiredCharacterToUsartTransmitBuffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('1');
|
||||
TEST_ASSERT_EQUAL('1', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar(':');
|
||||
TEST_ASSERT_EQUAL(':', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
void testPutCharShouldWaitUntilReadyToTransmitBeforeLoadingTransmitBufffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "MockUsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testPutCharShouldWriteDesiredCharacterToUsartTransmitBuffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('1');
|
||||
TEST_ASSERT_EQUAL('1', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar(':');
|
||||
TEST_ASSERT_EQUAL(':', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
void testPutCharShouldWaitUntilReadyToTransmitBeforeLoadingTransmitBufffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testReadyToTransmitShouldReturnStatusPerTransmitBufferReadyStatus(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CSR = 0;
|
||||
TEST_ASSERT(!Usart_ReadyToTransmit());
|
||||
|
||||
AT91C_BASE_US0->US_CSR = AT91C_US_TXRDY;
|
||||
TEST_ASSERT(Usart_ReadyToTransmit());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testReadyToTransmitShouldReturnStatusPerTransmitBufferReadyStatus(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CSR = 0;
|
||||
TEST_ASSERT(!Usart_ReadyToTransmit());
|
||||
|
||||
AT91C_BASE_US0->US_CSR = AT91C_US_TXRDY;
|
||||
TEST_ASSERT(Usart_ReadyToTransmit());
|
||||
}
|
||||
|
||||
+134
-134
@@ -1,134 +1,134 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockConfig
|
||||
|
||||
CMockDefaultOptions =
|
||||
{
|
||||
:framework => :unity,
|
||||
:mock_path => 'mocks',
|
||||
:mock_prefix => 'Mock',
|
||||
:subdir => nil,
|
||||
:plugins => [],
|
||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
|
||||
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
|
||||
:enforce_strict_ordering => false,
|
||||
:unity_helper_path => false,
|
||||
:treat_as => {},
|
||||
: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
|
||||
:callback_include_count => true,
|
||||
:callback_after_arg_check => false,
|
||||
:includes => nil,
|
||||
:includes_h_pre_orig_header => nil,
|
||||
:includes_h_post_orig_header => nil,
|
||||
:includes_c_pre_header => nil,
|
||||
:includes_c_post_header => nil,
|
||||
:orig_header_include_fmt => "#include \"%s\"",
|
||||
}
|
||||
|
||||
def initialize(options=nil)
|
||||
case(options)
|
||||
when NilClass then options = CMockDefaultOptions.clone
|
||||
when String then options = CMockDefaultOptions.clone.merge(load_config_file_from_yaml(options))
|
||||
when Hash then options = CMockDefaultOptions.clone.merge(options)
|
||||
else raise "If you specify arguments, it should be a filename or a hash of options"
|
||||
end
|
||||
|
||||
#do some quick type verification
|
||||
[:plugins, :attributes, :treat_as_void].each do |opt|
|
||||
unless (options[opt].class == Array)
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
||||
end
|
||||
end
|
||||
[:includes, :includes_h_pre_orig_header, :includes_h_post_orig_header, :includes_c_pre_header, :includes_c_post_header].each do |opt|
|
||||
unless (options[opt].nil? or (options[opt].class == Array))
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
||||
end
|
||||
end
|
||||
options[:unity_helper_path] ||= options[:unity_helper]
|
||||
options[:plugins].compact!
|
||||
options[:plugins].map! {|p| p.to_sym}
|
||||
@options = options
|
||||
|
||||
treat_as_map = standard_treat_as_map()#.clone
|
||||
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") }
|
||||
end
|
||||
|
||||
def load_config_file_from_yaml yaml_filename
|
||||
self.class.load_config_file_from_yaml yaml_filename
|
||||
end
|
||||
|
||||
def self.load_config_file_from_yaml yaml_filename
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
YAML.load_file(yaml_filename)[:cmock]
|
||||
end
|
||||
|
||||
def set_path(path)
|
||||
@src_path = path
|
||||
end
|
||||
|
||||
def load_unity_helper
|
||||
return File.new(@options[:unity_helper_path]).read if (@options[:unity_helper_path])
|
||||
return nil
|
||||
end
|
||||
|
||||
def standard_treat_as_map
|
||||
{
|
||||
'int' => 'INT',
|
||||
'char' => 'INT8',
|
||||
'short' => 'INT16',
|
||||
'long' => 'INT',
|
||||
'int8' => 'INT8',
|
||||
'int16' => 'INT16',
|
||||
'int32' => 'INT',
|
||||
'int8_t' => 'INT8',
|
||||
'int16_t' => 'INT16',
|
||||
'int32_t' => 'INT',
|
||||
'INT8_T' => 'INT8',
|
||||
'INT16_T' => 'INT16',
|
||||
'INT32_T' => 'INT',
|
||||
'bool' => 'INT',
|
||||
'bool_t' => 'INT',
|
||||
'BOOL' => 'INT',
|
||||
'BOOL_T' => 'INT',
|
||||
'unsigned int' => 'HEX32',
|
||||
'unsigned long' => 'HEX32',
|
||||
'uint32' => 'HEX32',
|
||||
'uint32_t' => 'HEX32',
|
||||
'UINT32' => 'HEX32',
|
||||
'UINT32_T' => 'HEX32',
|
||||
'void*' => 'HEX8_ARRAY',
|
||||
'unsigned short' => 'HEX16',
|
||||
'uint16' => 'HEX16',
|
||||
'uint16_t' => 'HEX16',
|
||||
'UINT16' => 'HEX16',
|
||||
'UINT16_T' => 'HEX16',
|
||||
'unsigned char' => 'HEX8',
|
||||
'uint8' => 'HEX8',
|
||||
'uint8_t' => 'HEX8',
|
||||
'UINT8' => 'HEX8',
|
||||
'UINT8_T' => 'HEX8',
|
||||
'char*' => 'STRING',
|
||||
'pCHAR' => 'STRING',
|
||||
'cstring' => 'STRING',
|
||||
'CSTRING' => 'STRING',
|
||||
'float' => 'FLOAT',
|
||||
'double' => 'FLOAT'
|
||||
}
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockConfig
|
||||
|
||||
CMockDefaultOptions =
|
||||
{
|
||||
:framework => :unity,
|
||||
:mock_path => 'mocks',
|
||||
:mock_prefix => 'Mock',
|
||||
:subdir => nil,
|
||||
:plugins => [],
|
||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
|
||||
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
|
||||
:enforce_strict_ordering => false,
|
||||
:unity_helper_path => false,
|
||||
:treat_as => {},
|
||||
: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
|
||||
:callback_include_count => true,
|
||||
:callback_after_arg_check => false,
|
||||
:includes => nil,
|
||||
:includes_h_pre_orig_header => nil,
|
||||
:includes_h_post_orig_header => nil,
|
||||
:includes_c_pre_header => nil,
|
||||
:includes_c_post_header => nil,
|
||||
:orig_header_include_fmt => "#include \"%s\"",
|
||||
}
|
||||
|
||||
def initialize(options=nil)
|
||||
case(options)
|
||||
when NilClass then options = CMockDefaultOptions.clone
|
||||
when String then options = CMockDefaultOptions.clone.merge(load_config_file_from_yaml(options))
|
||||
when Hash then options = CMockDefaultOptions.clone.merge(options)
|
||||
else raise "If you specify arguments, it should be a filename or a hash of options"
|
||||
end
|
||||
|
||||
#do some quick type verification
|
||||
[:plugins, :attributes, :treat_as_void].each do |opt|
|
||||
unless (options[opt].class == Array)
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
||||
end
|
||||
end
|
||||
[:includes, :includes_h_pre_orig_header, :includes_h_post_orig_header, :includes_c_pre_header, :includes_c_post_header].each do |opt|
|
||||
unless (options[opt].nil? or (options[opt].class == Array))
|
||||
options[opt] = []
|
||||
puts "WARNING: :#{opt.to_s} should be an array." unless (options[:verbosity] < 1)
|
||||
end
|
||||
end
|
||||
options[:unity_helper_path] ||= options[:unity_helper]
|
||||
options[:plugins].compact!
|
||||
options[:plugins].map! {|p| p.to_sym}
|
||||
@options = options
|
||||
|
||||
treat_as_map = standard_treat_as_map()#.clone
|
||||
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") }
|
||||
end
|
||||
|
||||
def load_config_file_from_yaml yaml_filename
|
||||
self.class.load_config_file_from_yaml yaml_filename
|
||||
end
|
||||
|
||||
def self.load_config_file_from_yaml yaml_filename
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
YAML.load_file(yaml_filename)[:cmock]
|
||||
end
|
||||
|
||||
def set_path(path)
|
||||
@src_path = path
|
||||
end
|
||||
|
||||
def load_unity_helper
|
||||
return File.new(@options[:unity_helper_path]).read if (@options[:unity_helper_path])
|
||||
return nil
|
||||
end
|
||||
|
||||
def standard_treat_as_map
|
||||
{
|
||||
'int' => 'INT',
|
||||
'char' => 'INT8',
|
||||
'short' => 'INT16',
|
||||
'long' => 'INT',
|
||||
'int8' => 'INT8',
|
||||
'int16' => 'INT16',
|
||||
'int32' => 'INT',
|
||||
'int8_t' => 'INT8',
|
||||
'int16_t' => 'INT16',
|
||||
'int32_t' => 'INT',
|
||||
'INT8_T' => 'INT8',
|
||||
'INT16_T' => 'INT16',
|
||||
'INT32_T' => 'INT',
|
||||
'bool' => 'INT',
|
||||
'bool_t' => 'INT',
|
||||
'BOOL' => 'INT',
|
||||
'BOOL_T' => 'INT',
|
||||
'unsigned int' => 'HEX32',
|
||||
'unsigned long' => 'HEX32',
|
||||
'uint32' => 'HEX32',
|
||||
'uint32_t' => 'HEX32',
|
||||
'UINT32' => 'HEX32',
|
||||
'UINT32_T' => 'HEX32',
|
||||
'void*' => 'HEX8_ARRAY',
|
||||
'unsigned short' => 'HEX16',
|
||||
'uint16' => 'HEX16',
|
||||
'uint16_t' => 'HEX16',
|
||||
'UINT16' => 'HEX16',
|
||||
'UINT16_T' => 'HEX16',
|
||||
'unsigned char' => 'HEX8',
|
||||
'uint8' => 'HEX8',
|
||||
'uint8_t' => 'HEX8',
|
||||
'UINT8' => 'HEX8',
|
||||
'UINT8_T' => 'HEX8',
|
||||
'char*' => 'STRING',
|
||||
'pCHAR' => 'STRING',
|
||||
'cstring' => 'STRING',
|
||||
'CSTRING' => 'STRING',
|
||||
'float' => 'FLOAT',
|
||||
'double' => 'FLOAT'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
+40
-40
@@ -1,40 +1,40 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockFileWriter
|
||||
|
||||
attr_reader :config
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def create_subdir(subdir)
|
||||
if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}")
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}"
|
||||
end
|
||||
end
|
||||
|
||||
def create_file(filename, subdir)
|
||||
raise "Where's the block of data to create?" unless block_given?
|
||||
full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new"
|
||||
full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}"
|
||||
File.open(full_file_name_temp, 'w') do |file|
|
||||
yield(file, filename)
|
||||
end
|
||||
update_file(full_file_name_done, full_file_name_temp)
|
||||
end
|
||||
|
||||
private ###################################
|
||||
|
||||
def update_file(dest, src)
|
||||
require 'fileutils'
|
||||
FileUtils.rm(dest) if (File.exist?(dest))
|
||||
FileUtils.cp(src, dest)
|
||||
FileUtils.rm(src)
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockFileWriter
|
||||
|
||||
attr_reader :config
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def create_subdir(subdir)
|
||||
if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}")
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}"
|
||||
end
|
||||
end
|
||||
|
||||
def create_file(filename, subdir)
|
||||
raise "Where's the block of data to create?" unless block_given?
|
||||
full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new"
|
||||
full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}"
|
||||
File.open(full_file_name_temp, 'w') do |file|
|
||||
yield(file, filename)
|
||||
end
|
||||
update_file(full_file_name_done, full_file_name_temp)
|
||||
end
|
||||
|
||||
private ###################################
|
||||
|
||||
def update_file(dest, src)
|
||||
require 'fileutils'
|
||||
FileUtils.rm(dest) if (File.exist?(dest))
|
||||
FileUtils.cp(src, dest)
|
||||
FileUtils.rm(src)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginArray
|
||||
|
||||
attr_reader :priority
|
||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@ptr_handling = @config.when_ptr
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@utils = utils
|
||||
@unity_helper = @utils.helpers[:unity_helper]
|
||||
@priority = 8
|
||||
end
|
||||
|
||||
def instance_typedefs(function)
|
||||
function[:args].inject("") do |all, arg|
|
||||
(arg[:ptr?]) ? all + " int Expected_#{arg[:name]}_Depth;\n" : all
|
||||
end
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
||||
args_string = function[:args].map do |m|
|
||||
const_str = m[:const?] ? 'const ' : ''
|
||||
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||
end.join(', ')
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||
else
|
||||
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
lines = []
|
||||
func_name = function[:name]
|
||||
args_string = function[:args].map do |m|
|
||||
const_str = m[:const?] ? 'const ' : ''
|
||||
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||
end.join(', ')
|
||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
||||
else
|
||||
lines << "void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n"
|
||||
end
|
||||
lines << "{\n"
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n"
|
||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless (function[:return][:void?])
|
||||
lines << "}\n\n"
|
||||
end
|
||||
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginArray
|
||||
|
||||
attr_reader :priority
|
||||
attr_accessor :config, :utils, :unity_helper, :ordered
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@ptr_handling = @config.when_ptr
|
||||
@ordered = @config.enforce_strict_ordering
|
||||
@utils = utils
|
||||
@unity_helper = @utils.helpers[:unity_helper]
|
||||
@priority = 8
|
||||
end
|
||||
|
||||
def instance_typedefs(function)
|
||||
function[:args].inject("") do |all, arg|
|
||||
(arg[:ptr?]) ? all + " int Expected_#{arg[:name]}_Depth;\n" : all
|
||||
end
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
||||
args_string = function[:args].map do |m|
|
||||
const_str = m[:const?] ? 'const ' : ''
|
||||
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||
end.join(', ')
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||
else
|
||||
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n"
|
||||
end
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
return nil unless function[:contains_ptr?]
|
||||
lines = []
|
||||
func_name = function[:name]
|
||||
args_string = function[:args].map do |m|
|
||||
const_str = m[:const?] ? 'const ' : ''
|
||||
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||
end.join(', ')
|
||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
||||
else
|
||||
lines << "void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n"
|
||||
end
|
||||
lines << "{\n"
|
||||
lines << @utils.code_add_base_expectation(func_name)
|
||||
lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n"
|
||||
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless (function[:return][:void?])
|
||||
lines << "}\n\n"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginCallback
|
||||
|
||||
attr_accessor :include_count
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@utils = utils
|
||||
@priority = 6
|
||||
|
||||
@include_count = @config.callback_include_count
|
||||
if (@config.callback_after_arg_check)
|
||||
alias :mock_implementation :mock_implementation_for_callbacks
|
||||
alias :mock_implementation_precheck :nothing
|
||||
else
|
||||
alias :mock_implementation_precheck :mock_implementation_for_callbacks
|
||||
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}_CallbackCalls;\n"
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
func_name = function[:name]
|
||||
return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type]
|
||||
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"
|
||||
end
|
||||
|
||||
def mock_implementation_for_callbacks(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
|
||||
end
|
||||
|
||||
def nothing(function)
|
||||
return ""
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
func_name = function[:name]
|
||||
"void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" +
|
||||
" 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"
|
||||
end
|
||||
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginCallback
|
||||
|
||||
attr_accessor :include_count
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@utils = utils
|
||||
@priority = 6
|
||||
|
||||
@include_count = @config.callback_include_count
|
||||
if (@config.callback_after_arg_check)
|
||||
alias :mock_implementation :mock_implementation_for_callbacks
|
||||
alias :mock_implementation_precheck :nothing
|
||||
else
|
||||
alias :mock_implementation_precheck :mock_implementation_for_callbacks
|
||||
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}_CallbackCalls;\n"
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
func_name = function[:name]
|
||||
return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type]
|
||||
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"
|
||||
end
|
||||
|
||||
def mock_implementation_for_callbacks(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
|
||||
end
|
||||
|
||||
def nothing(function)
|
||||
return ""
|
||||
end
|
||||
|
||||
def mock_interfaces(function)
|
||||
func_name = function[:name]
|
||||
"void #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback)\n{\n" +
|
||||
" 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"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginExpectAnyArgs
|
||||
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@utils = utils
|
||||
@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"
|
||||
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"
|
||||
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_implementation(function)
|
||||
lines = " if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n {\n"
|
||||
if (function[:return][:void?])
|
||||
lines << " return;\n }\n"
|
||||
else
|
||||
retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} )
|
||||
lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?])
|
||||
return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '')
|
||||
lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n"
|
||||
end
|
||||
lines
|
||||
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"
|
||||
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"
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
class CMockGeneratorPluginExpectAnyArgs
|
||||
|
||||
attr_reader :priority
|
||||
attr_reader :config, :utils
|
||||
|
||||
def initialize(config, utils)
|
||||
@config = config
|
||||
@utils = utils
|
||||
@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"
|
||||
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"
|
||||
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_implementation(function)
|
||||
lines = " if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n {\n"
|
||||
if (function[:return][:void?])
|
||||
lines << " return;\n }\n"
|
||||
else
|
||||
retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} )
|
||||
lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?])
|
||||
return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '')
|
||||
lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n"
|
||||
end
|
||||
lines
|
||||
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"
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/* ==========================================
|
||||
CMock Project - Automatic Mock Generation for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include "cmock.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
|
||||
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
|
||||
extern void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void);
|
||||
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
|
||||
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
|
||||
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
|
||||
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UnityBegin("TestCMockDynamic.c");
|
||||
|
||||
RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 26);
|
||||
RUN_TEST(test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize, 35);
|
||||
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 45);
|
||||
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 59);
|
||||
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 70);
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 152);
|
||||
|
||||
UnityEnd();
|
||||
CMock_Guts_MemFreeFinal();
|
||||
return 0;
|
||||
}
|
||||
/* ==========================================
|
||||
CMock Project - Automatic Mock Generation for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include "cmock.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
|
||||
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
|
||||
extern void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void);
|
||||
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
|
||||
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
|
||||
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
|
||||
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UnityBegin("TestCMockDynamic.c");
|
||||
|
||||
RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 26);
|
||||
RUN_TEST(test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize, 35);
|
||||
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 45);
|
||||
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 59);
|
||||
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 70);
|
||||
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 152);
|
||||
|
||||
UnityEnd();
|
||||
CMock_Guts_MemFreeFinal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+39
-39
@@ -1,39 +1,39 @@
|
||||
/* ==========================================
|
||||
CMock Project - Automatic Mock Generation for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
|
||||
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
|
||||
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
|
||||
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
|
||||
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
|
||||
extern void test_MemEndOfChain(void);
|
||||
extern void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void);
|
||||
extern void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void);
|
||||
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Unity.TestFile = "TestCMock.c";
|
||||
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);
|
||||
|
||||
UnityEnd();
|
||||
return 0;
|
||||
}
|
||||
/* ==========================================
|
||||
CMock Project - Automatic Mock Generation for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
|
||||
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
|
||||
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
|
||||
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
|
||||
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
|
||||
extern void test_MemEndOfChain(void);
|
||||
extern void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void);
|
||||
extern void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void);
|
||||
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Unity.TestFile = "TestCMock.c";
|
||||
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);
|
||||
|
||||
UnityEnd();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+194
-194
@@ -1,194 +1,194 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require 'yaml'
|
||||
|
||||
SYS_TEST_GEN_ROOT = File.expand_path( File.dirname( __FILE__ ) ) + '/'
|
||||
GENERATED_PATH = SYS_TEST_GEN_ROOT + 'generated/'
|
||||
BUILD_PATH = SYS_TEST_GEN_ROOT + 'build/'
|
||||
CASES_PATH = SYS_TEST_GEN_ROOT + 'cases/'
|
||||
|
||||
TYPES_H = 'types.h'
|
||||
UNITY_H = 'unity.h'
|
||||
CMOCK_H = 'cmock.h'
|
||||
UNITY_HELPER_H = 'unity_helper.h'
|
||||
UNITY_HELPER_C = 'unity_helper.c'
|
||||
MOCKABLE_H = 'mockable.h'
|
||||
|
||||
YAML_EXTENSION = '.yml'
|
||||
TEST_PREFIX = 'test_'
|
||||
MOCK_PREFIX = 'mock_'
|
||||
H_EXTENSION = '.h'
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
|
||||
class SystemTestGenerator
|
||||
|
||||
def generate_files(test_cases)
|
||||
test_cases.each do |filename|
|
||||
yaml_hash = YAML.load_file(filename)
|
||||
|
||||
name = File.basename(filename, YAML_EXTENSION)
|
||||
namix = "#{name}_"
|
||||
|
||||
generate_cmock_config(yaml_hash, namix)
|
||||
generate_code(yaml_hash, namix, name)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_cmock_config(yaml_hash, namix)
|
||||
cmock_yaml = yaml_hash.clone
|
||||
cmock_yaml.delete(:systest)
|
||||
cmock = cmock_yaml[:cmock]
|
||||
|
||||
cmock[:mock_path] = GENERATED_PATH
|
||||
cmock[:includes] = (cmock[:includes] || []) + [namix + TYPES_H]
|
||||
cmock[:mock_prefix] = MOCK_PREFIX
|
||||
if not yaml_hash[:systest][:unity_helper].nil?
|
||||
cmock[:includes] << namix + UNITY_HELPER_H
|
||||
cmock[:unity_helper_path] = GENERATED_PATH + namix + UNITY_HELPER_H
|
||||
end
|
||||
|
||||
File.open(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION, 'w') do |out|
|
||||
YAML.dump(cmock_yaml, out)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_code(yaml_hash, namix, name)
|
||||
generate_types_file(yaml_hash, namix)
|
||||
generate_mockable_file(yaml_hash, namix)
|
||||
generate_unity_helper_files(yaml_hash, namix)
|
||||
|
||||
generate_test_file(yaml_hash, namix, name)
|
||||
generate_source_file(yaml_hash, namix, name)
|
||||
end
|
||||
|
||||
def generate_types_file(yaml_hash, namix)
|
||||
types = yaml_hash[:systest][:types]
|
||||
return if types.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + TYPES_H, namix.upcase + 'TYPES_H') do |out|
|
||||
out.puts(types)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_mockable_file(yaml_hash, namix)
|
||||
mockable = yaml_hash[:systest][:mockable]
|
||||
return if mockable.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + MOCKABLE_H, namix.upcase + 'MOCKABLE_H', [namix + TYPES_H]) do |out|
|
||||
out.puts(mockable)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_unity_helper_files(yaml_hash, namix)
|
||||
unity_helper = yaml_hash[:systest][:unity_helper]
|
||||
return if unity_helper.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + UNITY_HELPER_H, namix.upcase + 'UNITY_HELPER_H', [namix + TYPES_H]) do |out|
|
||||
out.puts(unity_helper[:header])
|
||||
end
|
||||
|
||||
write_source_file(GENERATED_PATH + namix + UNITY_HELPER_C, ["unity.h", namix + UNITY_HELPER_H]) do |out|
|
||||
out.puts(unity_helper[:code])
|
||||
end
|
||||
end
|
||||
|
||||
def generate_test_file(yaml_hash, namix, name)
|
||||
tests = yaml_hash[:systest][:tests]
|
||||
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]
|
||||
|
||||
write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(tests[:common])
|
||||
out.puts('')
|
||||
|
||||
tests[:units].each_with_index do |test, index|
|
||||
out.puts('// should ' + test[:should])
|
||||
out.puts(test[:code].gsub!(/test\(\)/, "void test#{index+1}(void)"))
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_source_file(yaml_hash, namix, name)
|
||||
source = yaml_hash[:systest][:source]
|
||||
return if source.nil?
|
||||
|
||||
header_file = name + H_EXTENSION
|
||||
|
||||
includes = yaml_hash[:systest][:types].nil? ? [] : [(namix + TYPES_H)]
|
||||
|
||||
write_header_file(GENERATED_PATH + header_file, name.upcase, includes) do |out|
|
||||
out.puts(source[:header])
|
||||
end
|
||||
|
||||
includes = []
|
||||
includes << (namix + TYPES_H) if not yaml_hash[:systest][:types].nil?
|
||||
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
|
||||
includes << header_file
|
||||
|
||||
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(source[:code])
|
||||
end
|
||||
end
|
||||
|
||||
def write_header_file(filename, upcase_name, include_list=[])
|
||||
File.open(filename, 'w') do |out|
|
||||
out.puts("#ifndef _#{upcase_name}")
|
||||
out.puts("#define _#{upcase_name}")
|
||||
out.puts('')
|
||||
include_list.each do |include|
|
||||
out.puts("#include \"#{include}\"")
|
||||
end
|
||||
out.puts('')
|
||||
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
|
||||
out.puts("#if !defined(__clang__)")
|
||||
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
|
||||
out.puts("#endif")
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
|
||||
out.puts("#endif")
|
||||
out.puts('')
|
||||
yield(out)
|
||||
out.puts('')
|
||||
out.puts("#endif // _#{upcase_name}")
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
|
||||
def write_source_file(filename, include_list=[])
|
||||
File.open(filename, 'w') do |out|
|
||||
include_list.each do |include|
|
||||
out.puts("#include \"#{include}\"")
|
||||
end
|
||||
out.puts('')
|
||||
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
|
||||
out.puts("#if !defined(__clang__)")
|
||||
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
|
||||
out.puts("#endif")
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
|
||||
out.puts("#endif")
|
||||
out.puts('')
|
||||
yield(out)
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if ($0 == __FILE__)
|
||||
SystemTestGenerator.new.generate_files(Dir[CASES_PATH + "*#{YAML_EXTENSION}"])
|
||||
end
|
||||
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require 'yaml'
|
||||
|
||||
SYS_TEST_GEN_ROOT = File.expand_path( File.dirname( __FILE__ ) ) + '/'
|
||||
GENERATED_PATH = SYS_TEST_GEN_ROOT + 'generated/'
|
||||
BUILD_PATH = SYS_TEST_GEN_ROOT + 'build/'
|
||||
CASES_PATH = SYS_TEST_GEN_ROOT + 'cases/'
|
||||
|
||||
TYPES_H = 'types.h'
|
||||
UNITY_H = 'unity.h'
|
||||
CMOCK_H = 'cmock.h'
|
||||
UNITY_HELPER_H = 'unity_helper.h'
|
||||
UNITY_HELPER_C = 'unity_helper.c'
|
||||
MOCKABLE_H = 'mockable.h'
|
||||
|
||||
YAML_EXTENSION = '.yml'
|
||||
TEST_PREFIX = 'test_'
|
||||
MOCK_PREFIX = 'mock_'
|
||||
H_EXTENSION = '.h'
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
|
||||
class SystemTestGenerator
|
||||
|
||||
def generate_files(test_cases)
|
||||
test_cases.each do |filename|
|
||||
yaml_hash = YAML.load_file(filename)
|
||||
|
||||
name = File.basename(filename, YAML_EXTENSION)
|
||||
namix = "#{name}_"
|
||||
|
||||
generate_cmock_config(yaml_hash, namix)
|
||||
generate_code(yaml_hash, namix, name)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_cmock_config(yaml_hash, namix)
|
||||
cmock_yaml = yaml_hash.clone
|
||||
cmock_yaml.delete(:systest)
|
||||
cmock = cmock_yaml[:cmock]
|
||||
|
||||
cmock[:mock_path] = GENERATED_PATH
|
||||
cmock[:includes] = (cmock[:includes] || []) + [namix + TYPES_H]
|
||||
cmock[:mock_prefix] = MOCK_PREFIX
|
||||
if not yaml_hash[:systest][:unity_helper].nil?
|
||||
cmock[:includes] << namix + UNITY_HELPER_H
|
||||
cmock[:unity_helper_path] = GENERATED_PATH + namix + UNITY_HELPER_H
|
||||
end
|
||||
|
||||
File.open(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION, 'w') do |out|
|
||||
YAML.dump(cmock_yaml, out)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_code(yaml_hash, namix, name)
|
||||
generate_types_file(yaml_hash, namix)
|
||||
generate_mockable_file(yaml_hash, namix)
|
||||
generate_unity_helper_files(yaml_hash, namix)
|
||||
|
||||
generate_test_file(yaml_hash, namix, name)
|
||||
generate_source_file(yaml_hash, namix, name)
|
||||
end
|
||||
|
||||
def generate_types_file(yaml_hash, namix)
|
||||
types = yaml_hash[:systest][:types]
|
||||
return if types.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + TYPES_H, namix.upcase + 'TYPES_H') do |out|
|
||||
out.puts(types)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_mockable_file(yaml_hash, namix)
|
||||
mockable = yaml_hash[:systest][:mockable]
|
||||
return if mockable.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + MOCKABLE_H, namix.upcase + 'MOCKABLE_H', [namix + TYPES_H]) do |out|
|
||||
out.puts(mockable)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_unity_helper_files(yaml_hash, namix)
|
||||
unity_helper = yaml_hash[:systest][:unity_helper]
|
||||
return if unity_helper.nil?
|
||||
|
||||
write_header_file(GENERATED_PATH + namix + UNITY_HELPER_H, namix.upcase + 'UNITY_HELPER_H', [namix + TYPES_H]) do |out|
|
||||
out.puts(unity_helper[:header])
|
||||
end
|
||||
|
||||
write_source_file(GENERATED_PATH + namix + UNITY_HELPER_C, ["unity.h", namix + UNITY_HELPER_H]) do |out|
|
||||
out.puts(unity_helper[:code])
|
||||
end
|
||||
end
|
||||
|
||||
def generate_test_file(yaml_hash, namix, name)
|
||||
tests = yaml_hash[:systest][:tests]
|
||||
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]
|
||||
|
||||
write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(tests[:common])
|
||||
out.puts('')
|
||||
|
||||
tests[:units].each_with_index do |test, index|
|
||||
out.puts('// should ' + test[:should])
|
||||
out.puts(test[:code].gsub!(/test\(\)/, "void test#{index+1}(void)"))
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_source_file(yaml_hash, namix, name)
|
||||
source = yaml_hash[:systest][:source]
|
||||
return if source.nil?
|
||||
|
||||
header_file = name + H_EXTENSION
|
||||
|
||||
includes = yaml_hash[:systest][:types].nil? ? [] : [(namix + TYPES_H)]
|
||||
|
||||
write_header_file(GENERATED_PATH + header_file, name.upcase, includes) do |out|
|
||||
out.puts(source[:header])
|
||||
end
|
||||
|
||||
includes = []
|
||||
includes << (namix + TYPES_H) if not yaml_hash[:systest][:types].nil?
|
||||
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
|
||||
includes << header_file
|
||||
|
||||
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
|
||||
out.puts(source[:code])
|
||||
end
|
||||
end
|
||||
|
||||
def write_header_file(filename, upcase_name, include_list=[])
|
||||
File.open(filename, 'w') do |out|
|
||||
out.puts("#ifndef _#{upcase_name}")
|
||||
out.puts("#define _#{upcase_name}")
|
||||
out.puts('')
|
||||
include_list.each do |include|
|
||||
out.puts("#include \"#{include}\"")
|
||||
end
|
||||
out.puts('')
|
||||
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
|
||||
out.puts("#if !defined(__clang__)")
|
||||
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
|
||||
out.puts("#endif")
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
|
||||
out.puts("#endif")
|
||||
out.puts('')
|
||||
yield(out)
|
||||
out.puts('')
|
||||
out.puts("#endif // _#{upcase_name}")
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
|
||||
def write_source_file(filename, include_list=[])
|
||||
File.open(filename, 'w') do |out|
|
||||
include_list.each do |include|
|
||||
out.puts("#include \"#{include}\"")
|
||||
end
|
||||
out.puts('')
|
||||
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
|
||||
out.puts("#if !defined(__clang__)")
|
||||
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
|
||||
out.puts("#endif")
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
|
||||
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
|
||||
out.puts("#endif")
|
||||
out.puts('')
|
||||
yield(out)
|
||||
out.puts('')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if ($0 == __FILE__)
|
||||
SystemTestGenerator.new.generate_files(Dir[CASES_PATH + "*#{YAML_EXTENSION}"])
|
||||
end
|
||||
|
||||
|
||||
+47
-47
@@ -1,47 +1,47 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
def create_mocks(*mocks)
|
||||
mocks.each do |mock|
|
||||
eval "@#{mock} = Minitest::Mock.new"
|
||||
end
|
||||
end
|
||||
|
||||
def create_stub(funcs)
|
||||
stub = Class.new
|
||||
#if (RUBY_VERSION.split('.')[0].to_i >= 2)
|
||||
# funcs.each_pair {|k,v| stub.define_singleton_method(k) {|*unused| return v } }
|
||||
#else
|
||||
blob = "class << stub\n"
|
||||
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
|
||||
blob += "end"
|
||||
eval blob
|
||||
#end
|
||||
stub
|
||||
end
|
||||
|
||||
def test_return
|
||||
{
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
}
|
||||
end
|
||||
|
||||
def test_arg
|
||||
{
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
|
||||
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
|
||||
}
|
||||
end
|
||||
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
def create_mocks(*mocks)
|
||||
mocks.each do |mock|
|
||||
eval "@#{mock} = Minitest::Mock.new"
|
||||
end
|
||||
end
|
||||
|
||||
def create_stub(funcs)
|
||||
stub = Class.new
|
||||
#if (RUBY_VERSION.split('.')[0].to_i >= 2)
|
||||
# funcs.each_pair {|k,v| stub.define_singleton_method(k) {|*unused| return v } }
|
||||
#else
|
||||
blob = "class << stub\n"
|
||||
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
|
||||
blob += "end"
|
||||
eval blob
|
||||
#end
|
||||
stub
|
||||
end
|
||||
|
||||
def test_return
|
||||
{
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
}
|
||||
end
|
||||
|
||||
def test_arg
|
||||
{
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
|
||||
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
+118
-118
@@ -1,118 +1,118 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_config'
|
||||
|
||||
|
||||
describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
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[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
it "replace only options specified in a hash" do
|
||||
test_includes = ['hello']
|
||||
test_attributes = ['blah', 'bleh']
|
||||
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(test_includes, config.includes)
|
||||
assert_equal(test_attributes, config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
it "replace only options specified in a yaml file" do
|
||||
test_plugins = [:soda, :pizza]
|
||||
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(:include, config.treat_externs)
|
||||
end
|
||||
|
||||
it "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do
|
||||
|
||||
user_treat_as1 = {
|
||||
'BOOL' => 'UINT8', # redefine standard default
|
||||
'unsigned long' => 'INT', # redefine standard default
|
||||
'U8' => 'UINT8', # custom value
|
||||
'U16' => 'UINT16' # custom value
|
||||
}
|
||||
user_treat_as2 = {
|
||||
'BOOL' => 'INT16', # redefine standard default
|
||||
'U16' => 'HEX16' # custom value
|
||||
}
|
||||
|
||||
config1 = CMockConfig.new({:treat_as => user_treat_as1})
|
||||
config2 = CMockConfig.new({:treat_as => user_treat_as2})
|
||||
|
||||
# ----- USER SET 1
|
||||
# standard defaults
|
||||
assert_equal('INT', config1.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config1.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config1.treat_as['void*'])
|
||||
assert_equal('STRING', config1.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config1.treat_as['char*'])
|
||||
assert_equal('HEX8', config1.treat_as['unsigned char'])
|
||||
assert_equal('INT', config1.treat_as['long'])
|
||||
assert_equal('INT16', config1.treat_as['short'])
|
||||
|
||||
# overrides
|
||||
assert_equal('UINT8', config1.treat_as['BOOL'])
|
||||
assert_equal('INT', config1.treat_as['unsigned long'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('UINT8', config1.treat_as['U8'])
|
||||
assert_equal('UINT16', config1.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config1.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config1.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config1.standard_treat_as_map['char*'])
|
||||
|
||||
# ----- USER SET 2
|
||||
# standard defaults
|
||||
assert_equal('INT', config2.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config2.treat_as['void*'])
|
||||
assert_equal('STRING', config2.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config2.treat_as['char*'])
|
||||
assert_equal('HEX8', config2.treat_as['unsigned char'])
|
||||
assert_equal('INT', config2.treat_as['long'])
|
||||
assert_equal('INT16', config2.treat_as['short'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned long'])
|
||||
|
||||
# overrides
|
||||
assert_equal('INT16', config2.treat_as['BOOL'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('HEX16', config2.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config2.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config2.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config2.standard_treat_as_map['char*'])
|
||||
end
|
||||
|
||||
it "standard treat_as map should be incorruptable" do
|
||||
config = CMockConfig.new({})
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
|
||||
local = config.standard_treat_as_map
|
||||
local['BOOL_T'] = "U8"
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
end
|
||||
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_config'
|
||||
|
||||
|
||||
describe CMockConfig, "Verify CMockConfig Module" do
|
||||
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
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[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
it "replace only options specified in a hash" do
|
||||
test_includes = ['hello']
|
||||
test_attributes = ['blah', 'bleh']
|
||||
config = CMockConfig.new(:includes => test_includes, :attributes => test_attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(test_includes, config.includes)
|
||||
assert_equal(test_attributes, config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
end
|
||||
|
||||
it "replace only options specified in a yaml file" do
|
||||
test_plugins = [:soda, :pizza]
|
||||
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(:include, config.treat_externs)
|
||||
end
|
||||
|
||||
it "populate treat_as map with internal standard_treat_as_map defaults, redefine defaults, and add custom values" do
|
||||
|
||||
user_treat_as1 = {
|
||||
'BOOL' => 'UINT8', # redefine standard default
|
||||
'unsigned long' => 'INT', # redefine standard default
|
||||
'U8' => 'UINT8', # custom value
|
||||
'U16' => 'UINT16' # custom value
|
||||
}
|
||||
user_treat_as2 = {
|
||||
'BOOL' => 'INT16', # redefine standard default
|
||||
'U16' => 'HEX16' # custom value
|
||||
}
|
||||
|
||||
config1 = CMockConfig.new({:treat_as => user_treat_as1})
|
||||
config2 = CMockConfig.new({:treat_as => user_treat_as2})
|
||||
|
||||
# ----- USER SET 1
|
||||
# standard defaults
|
||||
assert_equal('INT', config1.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config1.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config1.treat_as['void*'])
|
||||
assert_equal('STRING', config1.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config1.treat_as['char*'])
|
||||
assert_equal('HEX8', config1.treat_as['unsigned char'])
|
||||
assert_equal('INT', config1.treat_as['long'])
|
||||
assert_equal('INT16', config1.treat_as['short'])
|
||||
|
||||
# overrides
|
||||
assert_equal('UINT8', config1.treat_as['BOOL'])
|
||||
assert_equal('INT', config1.treat_as['unsigned long'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('UINT8', config1.treat_as['U8'])
|
||||
assert_equal('UINT16', config1.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config1.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config1.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config1.standard_treat_as_map['char*'])
|
||||
|
||||
# ----- USER SET 2
|
||||
# standard defaults
|
||||
assert_equal('INT', config2.treat_as['BOOL_T'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned int'])
|
||||
assert_equal('HEX8_ARRAY',config2.treat_as['void*'])
|
||||
assert_equal('STRING', config2.treat_as['CSTRING'])
|
||||
assert_equal('STRING', config2.treat_as['char*'])
|
||||
assert_equal('HEX8', config2.treat_as['unsigned char'])
|
||||
assert_equal('INT', config2.treat_as['long'])
|
||||
assert_equal('INT16', config2.treat_as['short'])
|
||||
assert_equal('HEX32', config2.treat_as['unsigned long'])
|
||||
|
||||
# overrides
|
||||
assert_equal('INT16', config2.treat_as['BOOL'])
|
||||
|
||||
# added custom values
|
||||
assert_equal('HEX16', config2.treat_as['U16'])
|
||||
|
||||
# standard_treat_as_map: unchanged
|
||||
assert_equal('INT', config2.standard_treat_as_map['BOOL'])
|
||||
assert_equal('HEX32', config2.standard_treat_as_map['unsigned long'])
|
||||
assert_equal('STRING', config2.standard_treat_as_map['char*'])
|
||||
end
|
||||
|
||||
it "standard treat_as map should be incorruptable" do
|
||||
config = CMockConfig.new({})
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
|
||||
local = config.standard_treat_as_map
|
||||
local['BOOL_T'] = "U8"
|
||||
|
||||
assert_equal('INT', config.standard_treat_as_map['BOOL_T'])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_file_writer'
|
||||
|
||||
describe CMockFileWriter, "Verify CMockFileWriter Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
@cmock_file_writer = CMockFileWriter.new(@config)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "complain if a block was not specified when calling create" do
|
||||
begin
|
||||
@cmock_file_writer.create_file("test.txt")
|
||||
assert false, "Should Have Thrown An Error When Calling Without A Block"
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_file_writer'
|
||||
|
||||
describe CMockFileWriter, "Verify CMockFileWriter Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
@cmock_file_writer = CMockFileWriter.new(@config)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "complain if a block was not specified when calling create" do
|
||||
begin
|
||||
@cmock_file_writer.create_file("test.txt")
|
||||
assert false, "Should Have Thrown An Error When Calling Without A Block"
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_array'
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
create_mocks :utils
|
||||
|
||||
#no strict ordering
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils = create_stub(
|
||||
:helpers => {},
|
||||
:code_add_base_expectation => "mock_retval_0"
|
||||
)
|
||||
|
||||
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(nil, @cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int", :ptr? => false}, { :name => "pork", :type => "int*", :ptr? => true}], :return => test_return[:void]}
|
||||
expected = " int Expected_pork_Depth;\n"
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not add an additional mock interface for functions not containing pointers" do
|
||||
function = {:name => "Maple", :args_string => "int blah", :return => test_return[:string], :contains_ptr? => false}
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'void func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not have a mock function implementation" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
it "not have a mock interfaces for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int* func(int* pescado, int pes)'" do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "int*", :name => "pescado", :ptr? => true}, { :type => "int", :name => "pes", :ptr? => false}],
|
||||
:args_string => "int* pescado, int pes",
|
||||
:return => test_return[:int_ptr],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = ["void Lemon_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
" CMockExpectParameters_Lemon(cmock_call_instance, pescado, pescado_Depth, pes);\n",
|
||||
" cmock_call_instance->ReturnVal = cmock_to_return;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function).join
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_array'
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
create_mocks :utils
|
||||
|
||||
#no strict ordering
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils = create_stub(
|
||||
:helpers => {},
|
||||
:code_add_base_expectation => "mock_retval_0"
|
||||
)
|
||||
|
||||
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(nil, @cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "not add to typedef structure for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal("", returned)
|
||||
end
|
||||
|
||||
it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
|
||||
function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int", :ptr? => false}, { :name => "pork", :type => "int*", :ptr? => true}], :return => test_return[:void]}
|
||||
expected = " int Expected_pork_Depth;\n"
|
||||
returned = @cmock_generator_plugin_array.instance_typedefs(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not add an additional mock interface for functions not containing pointers" do
|
||||
function = {:name => "Maple", :args_string => "int blah", :return => test_return[:string], :contains_ptr? => false}
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'void func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:void],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do
|
||||
function = {:name => "Pine",
|
||||
:args => [{ :type => "int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "not have a mock function implementation" do
|
||||
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
||||
end
|
||||
|
||||
it "not have a mock interfaces for functions of style 'int* func(void)'" do
|
||||
function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:int_ptr]}
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function)
|
||||
assert_nil(returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions of style 'int* func(int* pescado, int pes)'" do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "int*", :name => "pescado", :ptr? => true}, { :type => "int", :name => "pes", :ptr? => false}],
|
||||
:args_string => "int* pescado, int pes",
|
||||
:return => test_return[:int_ptr],
|
||||
:contains_ptr? => true }
|
||||
|
||||
expected = ["void Lemon_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* pescado, int pescado_Depth, int pes, int* cmock_to_return)\n",
|
||||
"{\n",
|
||||
"mock_retval_0",
|
||||
" CMockExpectParameters_Lemon(cmock_call_instance, pescado, pescado_Depth, pes);\n",
|
||||
" cmock_call_instance->ReturnVal = cmock_to_return;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_array.mock_interfaces(function).join
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,189 +1,189 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_callback'
|
||||
|
||||
describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config.expect :callback_include_count, true
|
||||
@config.expect :callback_after_arg_check, false
|
||||
|
||||
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(6, @cmock_generator_plugin_callback.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_callback.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
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" +
|
||||
" int Oak_CallbackCalls;\n"
|
||||
returned = @cmock_generator_plugin_callback.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions 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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)' when count turned off" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int16_t func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions " do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "char*", :name => "pescado"}],
|
||||
:args_string => "char* pescado",
|
||||
:return => test_return[:int]
|
||||
}
|
||||
|
||||
expected = ["void Lemon_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\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
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_callback'
|
||||
|
||||
describe CMockGeneratorPluginCallback, "Verify CMockGeneratorPluginCallback Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
|
||||
@config.expect :callback_include_count, true
|
||||
@config.expect :callback_after_arg_check, false
|
||||
|
||||
@cmock_generator_plugin_callback = CMockGeneratorPluginCallback.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(6, @cmock_generator_plugin_callback.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
assert(!@cmock_generator_plugin_callback.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
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" +
|
||||
" int Oak_CallbackCalls;\n"
|
||||
returned = @cmock_generator_plugin_callback.instance_structure(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
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
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions 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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer();\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int func(void)'" do
|
||||
function = {:name => "Apple", :args => [], :args_string => "void", :return => test_return[:int]}
|
||||
expected = [" if (Mock.Apple_CallbackFunctionPointer != NULL)\n",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'void func(int* steak, uint8_t flag)' when count turned off" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" Mock.Apple_CallbackFunctionPointer(steak, flag);\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
@cmock_generator_plugin_callback.include_count = false
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock function implementation for functions of style 'int16_t func(int* steak, uint8_t flag)'" do
|
||||
function = {:name => "Apple",
|
||||
:args => [ { :type => 'int*', :name => 'steak', :ptr? => true},
|
||||
{ :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",
|
||||
" {\n",
|
||||
" return Mock.Apple_CallbackFunctionPointer(steak, flag, Mock.Apple_CallbackCalls++);\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_callback.mock_implementation_precheck(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add mock interfaces for functions " do
|
||||
function = {:name => "Lemon",
|
||||
:args => [{ :type => "char*", :name => "pescado"}],
|
||||
:args_string => "char* pescado",
|
||||
:return => test_return[:int]
|
||||
}
|
||||
|
||||
expected = ["void Lemon_StubWithCallback(CMOCK_Lemon_CALLBACK Callback)\n",
|
||||
"{\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
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect_any_args.rb'
|
||||
|
||||
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority)
|
||||
end
|
||||
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :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]}
|
||||
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)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation with void function" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation with return functions" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:int]}
|
||||
retval = test_return[:int].merge({ :name => "cmock_call_instance->ReturnVal"})
|
||||
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
" mock_retval_0",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
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]}
|
||||
expected = ["void Slime_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", true]
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_generator_plugin_expect_any_args.rb'
|
||||
|
||||
describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAnyArgs Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config, :utils
|
||||
@config = create_stub(:respond_to? => true)
|
||||
@cmock_generator_plugin_expect_any_args = CMockGeneratorPluginExpectAnyArgs.new(@config, @utils)
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(3, @cmock_generator_plugin_expect_any_args.priority)
|
||||
end
|
||||
|
||||
it "not have any additional include file requirements" do
|
||||
assert(!@cmock_generator_plugin_expect_any_args.respond_to?(:include_files))
|
||||
end
|
||||
|
||||
it "handle function declarations for functions without return values" do
|
||||
function = {:name => "Mold", :args_string => "void", :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]}
|
||||
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)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation with void function" do
|
||||
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
" return;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "add required code to implementation with return functions" do
|
||||
function = {:name => "Fungus", :args_string => "void", :return => test_return[:int]}
|
||||
retval = test_return[:int].merge({ :name => "cmock_call_instance->ReturnVal"})
|
||||
@utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
|
||||
expected = [" if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n",
|
||||
" {\n",
|
||||
" mock_retval_0",
|
||||
" return cmock_call_instance->ReturnVal;\n",
|
||||
" }\n"
|
||||
].join
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_implementation(function)
|
||||
assert_equal(expected, returned)
|
||||
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]}
|
||||
expected = ["void Slime_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line)\n",
|
||||
"{\n",
|
||||
"mock_return_1",
|
||||
" cmock_call_instance->IgnoreMode = CMOCK_ARG_NONE;\n",
|
||||
"}\n\n"
|
||||
].join
|
||||
@utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", true]
|
||||
returned = @cmock_generator_plugin_expect_any_args.mock_interfaces(function)
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
end
|
||||
|
||||
+1381
-1381
File diff suppressed because it is too large
Load Diff
@@ -1,95 +1,95 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_plugin_manager'
|
||||
require 'cmock_generator_plugin_expect'
|
||||
require 'cmock_generator_plugin_ignore'
|
||||
require 'cmock_generator_plugin_cexception'
|
||||
|
||||
describe CMockPluginManager, "Verify CMockPluginManager Module" do
|
||||
|
||||
before do
|
||||
create_mocks :utils, :pluginA, :pluginB
|
||||
@config = create_stub(
|
||||
:respond_to => true,
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:ignore => :args_and_calls
|
||||
)
|
||||
|
||||
#if (RUBY_VERSION.split('.')[0].to_i >= 2)
|
||||
# @config.define_singleton_method( :plugins ){ @plugins || [] }
|
||||
# @config.define_singleton_method( :plugins= ){ |val| @plugins = val }
|
||||
#else
|
||||
eval "class << @config\ndef plugins\n@plugins||[]\nend\ndef plugins=(val)\n@plugins=val\nend\nend\n"
|
||||
#end
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "return all plugins by default" do
|
||||
@config.plugins = ['cexception','ignore']
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(true, contained[:ignore])
|
||||
assert_equal(true, contained[:cexception])
|
||||
end
|
||||
|
||||
it "return restricted plugins based on config" do
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(false,contained[:ignore])
|
||||
assert_equal(false,contained[:cexception])
|
||||
end
|
||||
|
||||
it "run a desired method over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method)
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "run a desired method and arg list over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method, "chickenpotpie")
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_plugin_manager'
|
||||
require 'cmock_generator_plugin_expect'
|
||||
require 'cmock_generator_plugin_ignore'
|
||||
require 'cmock_generator_plugin_cexception'
|
||||
|
||||
describe CMockPluginManager, "Verify CMockPluginManager Module" do
|
||||
|
||||
before do
|
||||
create_mocks :utils, :pluginA, :pluginB
|
||||
@config = create_stub(
|
||||
:respond_to => true,
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:ignore => :args_and_calls
|
||||
)
|
||||
|
||||
#if (RUBY_VERSION.split('.')[0].to_i >= 2)
|
||||
# @config.define_singleton_method( :plugins ){ @plugins || [] }
|
||||
# @config.define_singleton_method( :plugins= ){ |val| @plugins = val }
|
||||
#else
|
||||
eval "class << @config\ndef plugins\n@plugins||[]\nend\ndef plugins=(val)\n@plugins=val\nend\nend\n"
|
||||
#end
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "return all plugins by default" do
|
||||
@config.plugins = ['cexception','ignore']
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(true, contained[:ignore])
|
||||
assert_equal(true, contained[:cexception])
|
||||
end
|
||||
|
||||
it "return restricted plugins based on config" do
|
||||
@utils.expect :helpers, {}
|
||||
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
test_plugins = @cmock_plugins.plugins
|
||||
contained = { :expect => false, :ignore => false, :cexception => false }
|
||||
test_plugins.each do |plugin|
|
||||
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect)
|
||||
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore)
|
||||
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception)
|
||||
end
|
||||
assert_equal(true, contained[:expect])
|
||||
assert_equal(false,contained[:ignore])
|
||||
assert_equal(false,contained[:cexception])
|
||||
end
|
||||
|
||||
it "run a desired method over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method)
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
|
||||
it "run a desired method and arg list over each plugin requested and return the results" do
|
||||
@utils.expect :helpers, {}
|
||||
@cmock_plugins = CMockPluginManager.new(@config, @utils)
|
||||
|
||||
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"])
|
||||
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"])
|
||||
@cmock_plugins.plugins = [@pluginA, @pluginB]
|
||||
|
||||
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test"
|
||||
output = @cmock_plugins.run(:test_method, "chickenpotpie")
|
||||
assert_equal(expected, output)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,223 +1,223 @@
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_unityhelper_parser'
|
||||
|
||||
describe CMockUnityHelperParser, "Verify CMockUnityHelperParser Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "ignore lines that are commented out" do
|
||||
source =
|
||||
" abcd;\n" +
|
||||
"// #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"or maybe // #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "ignore stuff in block comments" do
|
||||
source =
|
||||
" abcd; /*\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n */\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers in the proper form and ignore others" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_T(a,b,line,msg) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL(a,b,c,d) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b,c,d) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS_T' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_T",
|
||||
'unsigned_funky_rabbits' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers that contain arrays" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS_ARRAY(a,b,c,d,e,f) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS*' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
'unsigned_funky_rabbits*' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the standard set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned long" => "HEX64",
|
||||
}
|
||||
expected = {
|
||||
"UINT" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"unsigned_long" => "UNITY_TEST_ASSERT_EQUAL_HEX64",
|
||||
"UINT*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
"unsigned_long*"=> "UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the user specified set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"char*" => "STRING",
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
expected = {
|
||||
"char*" => "UNITY_TEST_ASSERT_EQUAL_STRING",
|
||||
"unsigned_int" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"char**" => "UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY",
|
||||
"unsigned_int*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "be able to fetch helpers on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
'LONG_LONG' => "UNITY_TEST_ASSERT_EQUAL_LONG_LONG"
|
||||
}
|
||||
|
||||
[["UINT8","UINT8"],
|
||||
["UINT16*","UINT16_ARRAY"],
|
||||
["const SPINACH","SPINACH"],
|
||||
["LONG LONG","LONG_LONG"] ].each do |ctype, exptype|
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_#{exptype}",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory array comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [:array]
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32*","SPINACH_T*"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return the array handler if we cannot find the normal handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",'&'], @parser.get_helper("UINT16"))
|
||||
end
|
||||
|
||||
it "return the normal handler if we cannot find the array handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16' => "UNITY_TEST_ASSERT_EQUAL_UINT16",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT8",'*'], @parser.get_helper("UINT8*"))
|
||||
end
|
||||
|
||||
it "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@config.expect :memcmp_if_unknown, false
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT32*' => "UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_raises (RuntimeError) { @parser.get_helper("UINT16") }
|
||||
end
|
||||
end
|
||||
# ==========================================
|
||||
# CMock Project - Automatic Mock Generation for C
|
||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
# [Released under MIT License. Please refer to license.txt for details]
|
||||
# ==========================================
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require 'cmock_unityhelper_parser'
|
||||
|
||||
describe CMockUnityHelperParser, "Verify CMockUnityHelperParser Module" do
|
||||
|
||||
before do
|
||||
create_mocks :config
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it "ignore lines that are commented out" do
|
||||
source =
|
||||
" abcd;\n" +
|
||||
"// #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"or maybe // #define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "ignore stuff in block comments" do
|
||||
source =
|
||||
" abcd; /*\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_CHICKENS(a,b,line,msg) {...};\n */\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers in the proper form and ignore others" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_T(a,b,line,msg) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL(a,b,c,d) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits(a,b,c,d) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS_T' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_T",
|
||||
'unsigned_funky_rabbits' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "notice equal helpers that contain arrays" do
|
||||
source =
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_WRONG_NUM_ARGS_ARRAY(a,b,c,d,e,f) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_WRONG_NAME_EQUAL_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"#define UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY(a,b,c,d,e) {...};\n" +
|
||||
"abcd;\n"
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, source
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
expected = {
|
||||
'TURKEYS*' => "UNITY_TEST_ASSERT_EQUAL_TURKEYS_ARRAY",
|
||||
'unsigned_funky_rabbits*' => "UNITY_TEST_ASSERT_EQUAL_unsigned_funky_rabbits_ARRAY"
|
||||
}
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the standard set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"UINT" => "HEX32",
|
||||
"unsigned long" => "HEX64",
|
||||
}
|
||||
expected = {
|
||||
"UINT" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"unsigned_long" => "UNITY_TEST_ASSERT_EQUAL_HEX64",
|
||||
"UINT*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
"unsigned_long*"=> "UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "pull in the user specified set of helpers and add them to my list" do
|
||||
pairs = {
|
||||
"char*" => "STRING",
|
||||
"unsigned int" => "HEX32",
|
||||
}
|
||||
expected = {
|
||||
"char*" => "UNITY_TEST_ASSERT_EQUAL_STRING",
|
||||
"unsigned_int" => "UNITY_TEST_ASSERT_EQUAL_HEX32",
|
||||
"char**" => "UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY",
|
||||
"unsigned_int*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY",
|
||||
}
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, pairs
|
||||
@config.expect :load_unity_helper, nil
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
|
||||
assert_equal(expected, @parser.c_types)
|
||||
end
|
||||
|
||||
it "be able to fetch helpers on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
'LONG_LONG' => "UNITY_TEST_ASSERT_EQUAL_LONG_LONG"
|
||||
}
|
||||
|
||||
[["UINT8","UINT8"],
|
||||
["UINT16*","UINT16_ARRAY"],
|
||||
["const SPINACH","SPINACH"],
|
||||
["LONG LONG","LONG_LONG"] ].each do |ctype, exptype|
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_#{exptype}",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",'&'], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return memory array comparison when asked to fetch helper of types not on my list" do
|
||||
@config.expect :plugins, [:array]
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
["UINT32*","SPINACH_T*"].each do |ctype|
|
||||
@config.expect :memcmp_if_unknown, true
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype))
|
||||
end
|
||||
end
|
||||
|
||||
it "return the array handler if we cannot find the normal handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",'&'], @parser.get_helper("UINT16"))
|
||||
end
|
||||
|
||||
it "return the normal handler if we cannot find the array handler" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT16' => "UNITY_TEST_ASSERT_EQUAL_UINT16",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT8",'*'], @parser.get_helper("UINT8*"))
|
||||
end
|
||||
|
||||
it "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do
|
||||
@config.expect :plugins, [] #not :array
|
||||
@config.expect :treat_as, {}
|
||||
@config.expect :load_unity_helper, ""
|
||||
@config.expect :memcmp_if_unknown, false
|
||||
@parser = CMockUnityHelperParser.new(@config)
|
||||
@parser.c_types = {
|
||||
'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8",
|
||||
'UINT32*' => "UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY",
|
||||
'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH",
|
||||
}
|
||||
|
||||
assert_raises (RuntimeError) { @parser.get_helper("UINT16") }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user