Debian Codegraph @

test/unit/cmock_generator_plugin_cexception_test.rb

raw symbols SCIP
1 # ==========================================
2 # CMock Project - Automatic Mock Generation for C
3 # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4 # [Released under MIT License. Please refer to license.txt for details]
5 # ==========================================
6
7 require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
8 require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_cexception'
9
10 describe CMockGeneratorPluginCexception, "Verify CMockGeneratorPluginCexception Module" do
11
12 before do
13 create_mocks :config, :utils
14
15 @config.expect :exclude_setjmp_h, false
16
17 @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
18 end
19
20 after do
21 end
22
23 it "have set up internal priority" do
24 assert_equal(7, @cmock_generator_plugin_cexception.priority)
25 end
26
27 it "include the cexception library" do
28 expected = "#include \"CException.h\"\n"
29 returned = @cmock_generator_plugin_cexception.include_files
30 assert_equal(expected, returned)
31 end
32
33 it "add to typedef structure mock needs" do
34 function = { :name => "Oak", :args => [], :return => test_return[:void] }
35 expected = " CEXCEPTION_T ExceptionToThrow;\n"
36 returned = @cmock_generator_plugin_cexception.instance_typedefs(function)
37 assert_equal(expected, returned)
38 end
39
40 it "add mock function declarations for functions without arguments" do
41 function = { :name => "Spruce", :args_string => "void", :return => test_return[:void] }
42 expected = "#define Spruce_ExpectAndThrow(cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, cmock_to_throw)\n"+
43 "void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw);\n"
44 returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
45 assert_equal(expected, returned)
46 end
47
48 it "add mock function declarations for functions with arguments" do
49 function = { :name => "Spruce", :args_string => "const char* Petunia, uint32_t Lily", :args_call => "Petunia, Lily", :return => test_return[:void] }
50 expected = "#define Spruce_ExpectAndThrow(Petunia, Lily, cmock_to_throw) Spruce_CMockExpectAndThrow(__LINE__, Petunia, Lily, cmock_to_throw)\n" +
51 "void Spruce_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, const char* Petunia, uint32_t Lily, CEXCEPTION_T cmock_to_throw);\n"
52 returned = @cmock_generator_plugin_cexception.mock_function_declarations(function)
53 assert_equal(expected, returned)
54 end
55
56 it "add a mock implementation" do
57 function = {:name => "Cherry", :args => [], :return => test_return[:void]}
58 expected = " if (cmock_call_instance->ExceptionToThrow != CEXCEPTION_NONE)\n" +
59 " {\n" +
60 " UNITY_CLR_DETAILS();\n" +
61 " Throw(cmock_call_instance->ExceptionToThrow);\n" +
62 " }\n"
63 returned = @cmock_generator_plugin_cexception.mock_implementation(function)
64 assert_equal(expected, returned)
65 end
66
67 it "add mock interfaces for functions without arguments" do
68 function = {:name => "Pear", :args_string => "void", :args => [], :return => test_return[:void]}
69 @utils.expect :code_add_base_expectation, "mock_retval_0", ["Pear"]
70 @utils.expect :code_call_argument_loader, "", [function]
71
72 expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, CEXCEPTION_T cmock_to_throw)\n",
73 "{\n",
74 "mock_retval_0",
75 "",
76 " cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
77 "}\n\n"
78 ].join
79 returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
80 assert_equal(expected, returned)
81 end
82
83 it "add a mock interfaces for functions with arguments" do
84 function = {:name => "Pear", :args_string => "int blah", :args => [{ :type => "int", :name => "blah" }], :return => test_return[:void]}
85 @utils.expect :code_add_base_expectation, "mock_retval_0", ["Pear"]
86 @utils.expect :code_call_argument_loader, "mock_return_1", [function]
87
88 expected = ["void Pear_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, int blah, CEXCEPTION_T cmock_to_throw)\n",
89 "{\n",
90 "mock_retval_0",
91 "mock_return_1",
92 " cmock_call_instance->ExceptionToThrow = cmock_to_throw;\n",
93 "}\n\n"
94 ].join
95 returned = @cmock_generator_plugin_cexception.mock_interfaces(function)
96 assert_equal(expected, returned)
97 end
98
99 it "should throw an exception if we try to use this plugin when setjmp disabled" do
100
101 @config.expect :exclude_setjmp_h, true
102
103 assert_raises RuntimeError do
104 @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils)
105 end
106 end
107
108 end