Debian Codegraph @

test/unit/cmock_generator_plugin_expect_b_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_expect'
9
10 describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module with Global Ordering" do
11
12 before do
13 create_mocks :config, :utils
14
15 @config = create_stub(
16 :when_ptr => :compare_data,
17 :enforce_strict_ordering => true,
18 :respond_to? => true,
19 :plugins => [ :expect, :expect_any_args ] )
20
21 @utils.expect :helpers, {}
22 @cmock_generator_plugin_expect = CMockGeneratorPluginExpect.new(@config, @utils)
23 end
24
25 after do
26 end
27
28 it "have set up internal priority on init" do
29 assert_nil(@cmock_generator_plugin_expect.unity_helper)
30 assert_equal(5, @cmock_generator_plugin_expect.priority)
31 end
32
33 it "not include any additional include files" do
34 assert(!@cmock_generator_plugin_expect.respond_to?(:include_files))
35 end
36
37 it "add to typedef structure mock needs of functions of style 'void func(void)' and global ordering" do
38 function = {:name => "Oak", :args => [], :return => test_return[:void]}
39 expected = " int CallOrder;\n"
40 returned = @cmock_generator_plugin_expect.instance_typedefs(function)
41 assert_equal(expected, returned)
42 end
43
44 it "add to typedef structure mock needs of functions of style 'int func(void)'" do
45 function = {:name => "Elm", :args => [], :return => test_return[:int]}
46 expected = " int ReturnVal;\n int CallOrder;\n"
47 returned = @cmock_generator_plugin_expect.instance_typedefs(function)
48 assert_equal(expected, returned)
49 end
50
51 it "add to typedef structure mock needs of functions of style 'void func(int chicken, char* pork)'" do
52 function = {:name => "Cedar", :args => [{ :name => "chicken", :type => "int"}, { :name => "pork", :type => "char*"}], :return => test_return[:void]}
53 expected = " int CallOrder;\n int Expected_chicken;\n char* Expected_pork;\n"
54 returned = @cmock_generator_plugin_expect.instance_typedefs(function)
55 assert_equal(expected, returned)
56 end
57
58 it "add to typedef structure mock needs of functions of style 'int func(float beef)'" do
59 function = {:name => "Birch", :args => [{ :name => "beef", :type => "float"}], :return => test_return[:int]}
60 expected = " int ReturnVal;\n int CallOrder;\n float Expected_beef;\n"
61 returned = @cmock_generator_plugin_expect.instance_typedefs(function)
62 assert_equal(expected, returned)
63 end
64
65 it "add mock function declaration for functions of style 'void func(void)'" do
66 function = {:name => "Maple", :args => [], :return => test_return[:void]}
67 expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
68 "void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
69 returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
70 assert_equal(expected, returned)
71 end
72
73 it "add mock function declaration for functions of style 'int func(void)'" do
74 function = {:name => "Spruce", :args => [], :return => test_return[:int]}
75 expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
76 "void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
77 returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
78 assert_equal(expected, returned)
79 end
80
81 it "add mock function declaration for functions of style 'const char* func(int tofu)'" do
82 function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
83 expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
84 "void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
85 returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
86 assert_equal(expected, returned)
87 end
88
89 it "add mock function implementation for functions of style 'void func(void)'" do
90 function = {:name => "Apple", :args => [], :return => test_return[:void]}
91 expected = ""
92 returned = @cmock_generator_plugin_expect.mock_implementation(function)
93 assert_equal(expected, returned)
94 end
95
96 it "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do
97 function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return => test_return[:int]}
98
99 @utils.expect :code_verify_an_arg_expectation, "mocked_retval_1\n", [function, function[:args][0]]
100 @utils.expect :code_verify_an_arg_expectation, "mocked_retval_2\n", [function, function[:args][1]]
101 expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
102 " {\n" +
103 "mocked_retval_1\n" +
104 "mocked_retval_2\n" +
105 " }\n"
106 returned = @cmock_generator_plugin_expect.mock_implementation(function)
107 assert_equal(expected, returned)
108 end
109
110 it "add mock function implementation using ordering if needed" do
111 function = {:name => "Apple", :args => [], :return => test_return[:void]}
112 expected = ""
113 @cmock_generator_plugin_expect.ordered = true
114 returned = @cmock_generator_plugin_expect.mock_implementation(function)
115 assert_equal(expected, returned)
116 end
117
118 it "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do
119 function = {:name => "Apple", :args => [{ :type => "int", :name => "worm" }], :return => test_return[:void]}
120 @utils.expect :code_verify_an_arg_expectation, "mocked_retval_0\n", [function, function[:args][0]]
121 expected = " if (!cmock_call_instance->ExpectAnyArgsBool)\n" +
122 " {\n" +
123 "mocked_retval_0\n" +
124 " }\n"
125 @cmock_generator_plugin_expect.ordered = true
126 returned = @cmock_generator_plugin_expect.mock_implementation(function)
127 assert_equal(expected, returned)
128 end
129
130 it "add mock interfaces for functions of style 'void func(void)'" do
131 function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
132 @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"]
133 @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
134 expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
135 "{\n",
136 "mock_retval_0\n",
137 "mock_retval_1\n",
138 "}\n\n"
139 ].join
140 returned = @cmock_generator_plugin_expect.mock_interfaces(function)
141 assert_equal(expected, returned)
142 end
143
144 it "add mock interfaces for functions of style 'int func(void)'" do
145 function = {:name => "Orange", :args => [], :args_string => "void", :return => test_return[:int]}
146 @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Orange"]
147 @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
148 @utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]]
149 expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
150 "{\n",
151 "mock_retval_0\n",
152 "mock_retval_1\n",
153 "mock_retval_2\n",
154 "}\n\n"
155 ].join
156 returned = @cmock_generator_plugin_expect.mock_interfaces(function)
157 assert_equal(expected, returned)
158 end
159
160 it "add mock interfaces for functions of style 'int func(char* pescado)'" do
161 function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return => test_return[:int]}
162 @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Lemon"]
163 @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
164 @utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]]
165 expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n",
166 "{\n",
167 "mock_retval_0\n",
168 "mock_retval_1\n",
169 "mock_retval_2\n",
170 "}\n\n"
171 ].join
172 returned = @cmock_generator_plugin_expect.mock_interfaces(function)
173 assert_equal(expected, returned)
174 end
175
176 it "add mock interfaces for functions when using ordering" do
177 function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]}
178 @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"]
179 @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function]
180 expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n",
181 "{\n",
182 "mock_retval_0\n",
183 "mock_retval_1\n",
184 "}\n\n"
185 ].join
186 @cmock_generator_plugin_expect.ordered = true
187 returned = @cmock_generator_plugin_expect.mock_interfaces(function)
188 assert_equal(expected, returned)
189 end
190
191 it "add mock verify lines" do
192 function = {:name => "Banana" }
193 expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \
194 " {\n" \
195 " UNITY_SET_DETAIL(CMockString_Banana);\n" \
196 " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \
197 " }\n"
198 returned = @cmock_generator_plugin_expect.mock_verify(function)
199 assert_equal(expected, returned)
200 end
201 end