summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/lib/cmock_generator_plugin_cexception.rb
blob: a757669e69e0f8617d60c8ebac79d44df50d967e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# ==========================================
#   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 CMockGeneratorPluginCexception
  attr_reader :priority
  attr_reader :config, :utils

  def initialize(config, utils)
    @config = config
    @utils = utils
    @priority = 7
  end

  def include_files
    "#include \"CException.h\"\n"
  end

  def instance_typedefs(_function)
    "  CEXCEPTION_T ExceptionToThrow;\n"
  end

  def mock_function_declarations(function)
    if function[:args_string] == 'void'
      "#define #{function[:name]}_ExpectAndThrow(cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n" \
             "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
    else
      "#define #{function[:name]}_ExpectAndThrow(#{function[:args_call]}, cmock_to_throw) #{function[:name]}_CMockExpectAndThrow(__LINE__, #{function[:args_call]}, cmock_to_throw)\n" \
             "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, CEXCEPTION_T cmock_to_throw);\n"
    end
  end

  def mock_implementation(_function)
    "  if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n  {\n" \
      "    UNITY_CLR_DETAILS();\n" \
      "    Throw(cmock_call_instance->ExceptionToThrow);\n  }\n"
  end

  def mock_interfaces(function)
    arg_insert = function[:args_string] == 'void' ? '' : "#{function[:args_string]}, "
    ["void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
     @utils.code_add_base_expectation(function[:name]),
     @utils.code_call_argument_loader(function),
     "  cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
     "}\n\n"].join
  end
end