| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
$ThisIsOnlyATest = true |
| 8 |
|
| 9 |
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 10 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator' |
| 11 |
|
| 12 |
class MockedPluginHelper |
| 13 |
def initialize return_this |
| 14 |
@return_this = return_this |
| 15 |
end |
| 16 |
|
| 17 |
def include_files |
| 18 |
return @return_this |
| 19 |
end |
| 20 |
|
| 21 |
def instance_structure( name, args, rettype ) |
| 22 |
return " #{@return_this}_#{name}(#{args}, #{rettype})" |
| 23 |
end |
| 24 |
|
| 25 |
def mock_verify( name ) |
| 26 |
return " #{@return_this}_#{name}" |
| 27 |
end |
| 28 |
|
| 29 |
def mock_destroy( name, args, rettype ) |
| 30 |
return " #{@return_this}_#{name}(#{args}, #{rettype})" |
| 31 |
end |
| 32 |
|
| 33 |
def mock_implementation(name, args) |
| 34 |
return " Mock#{name}#{@return_this}(#{args.join(", ")})" |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
describe CMockGenerator, "Verify CMockGenerator Module" do |
| 39 |
|
| 40 |
before do |
| 41 |
create_mocks :config, :file_writer, :utils, :plugins |
| 42 |
@module_name = "PoutPoutFish" |
| 43 |
|
| 44 |
|
| 45 |
@config.expect :mock_prefix, "Mock" |
| 46 |
@config.expect :mock_suffix, "" |
| 47 |
@config.expect :weak, "" |
| 48 |
@config.expect :enforce_strict_ordering, nil |
| 49 |
@config.expect :framework, :unity |
| 50 |
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"] |
| 51 |
@config.expect :includes_h_pre_orig_header, nil |
| 52 |
@config.expect :includes_h_post_orig_header, nil |
| 53 |
@config.expect :includes_c_pre_header, nil |
| 54 |
@config.expect :includes_c_post_header, nil |
| 55 |
@config.expect :subdir, nil |
| 56 |
@config.expect :fail_on_unexpected_calls, true |
| 57 |
@config.expect :treat_inlines, :exclude |
| 58 |
@config.expect :exclude_setjmp_h, false |
| 59 |
@cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins) |
| 60 |
@cmock_generator.module_name = @module_name |
| 61 |
@cmock_generator.module_ext = '.h' |
| 62 |
@cmock_generator.mock_name = "Mock#{@module_name}" |
| 63 |
@cmock_generator.clean_mock_name = "Mock#{@module_name}" |
| 64 |
|
| 65 |
|
| 66 |
@config.expect :mock_prefix, "Mock" |
| 67 |
@config.expect :mock_suffix, "" |
| 68 |
@config.expect :weak, "" |
| 69 |
@config.expect :enforce_strict_ordering, true |
| 70 |
@config.expect :framework, :unity |
| 71 |
@config.expect :includes, nil |
| 72 |
@config.expect :includes_h_pre_orig_header, nil |
| 73 |
@config.expect :includes_h_post_orig_header, nil |
| 74 |
@config.expect :includes_c_pre_header, nil |
| 75 |
@config.expect :includes_c_post_header, nil |
| 76 |
@config.expect :subdir, nil |
| 77 |
@config.expect :fail_on_unexpected_calls, true |
| 78 |
@config.expect :treat_inlines, :exclude |
| 79 |
@config.expect :exclude_setjmp_h, false |
| 80 |
@cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins) |
| 81 |
|
| 82 |
@test_project = { |
| 83 |
:module_name => @module_name, |
| 84 |
:module_ext => '.h', |
| 85 |
:mock_name => "Mock#{@module_name}", |
| 86 |
:clean_name => "Mock#{@module_name}", |
| 87 |
:folder => nil, |
| 88 |
:parsed_stuff => {}, |
| 89 |
:skeleton => false |
| 90 |
} |
| 91 |
end |
| 92 |
|
| 93 |
after do |
| 94 |
end |
| 95 |
|
| 96 |
def helper_create_header_top_with_opt_includes_form_config_and_plugin(ext) |
| 97 |
@config.expect :mock_prefix, "Mock" |
| 98 |
@config.expect :mock_suffix, "" |
| 99 |
@config.expect :weak, "" |
| 100 |
|
| 101 |
orig_filename = "PoutPoutFish#{ext}" |
| 102 |
define_name = "MOCKPOUTPOUTFISH_H" |
| 103 |
output = [] |
| 104 |
expected = [ |
| 105 |
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n", |
| 106 |
"#ifndef _#{define_name}\n", |
| 107 |
"#define _#{define_name}\n\n", |
| 108 |
"#include \"unity.h\"\n", |
| 109 |
"#include \"ConfigRequiredHeader1.h\"\n", |
| 110 |
"#include \"ConfigRequiredHeader2.h\"\n", |
| 111 |
"#include \"#{orig_filename}\"\n", |
| 112 |
"#include \"PluginRequiredHeader.h\"\n", |
| 113 |
"\n", |
| 114 |
"/* Ignore the following warnings, since we are copying code */\n", |
| 115 |
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n", |
| 116 |
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n", |
| 117 |
"#pragma GCC diagnostic push\n", |
| 118 |
"#endif\n", |
| 119 |
"#if !defined(__clang__)\n", |
| 120 |
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n", |
| 121 |
"#endif\n", |
| 122 |
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n", |
| 123 |
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n", |
| 124 |
"#endif\n", |
| 125 |
"\n", |
| 126 |
"#ifdef __cplusplus\n", |
| 127 |
"extern \"C\" {\n", |
| 128 |
"#endif\n", |
| 129 |
"\n", |
| 130 |
] |
| 131 |
|
| 132 |
@config.expect :orig_header_include_fmt, "#include \"%s\"" |
| 133 |
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files] |
| 134 |
|
| 135 |
|
| 136 |
test_project = @test_project.clone |
| 137 |
test_project[:module_ext] = ext |
| 138 |
|
| 139 |
@cmock_generator.create_mock_header_header(output, "Mock#{orig_filename}", test_project) |
| 140 |
|
| 141 |
assert_equal(expected, output) |
| 142 |
end |
| 143 |
|
| 144 |
it "create the top of a header file with optional include files from config and include file from plugin" do |
| 145 |
['.h','.hh','.hpp'].each do |ext| |
| 146 |
helper_create_header_top_with_opt_includes_form_config_and_plugin(ext) |
| 147 |
end |
| 148 |
end |
| 149 |
|
| 150 |
it "handle dashes and spaces in the module name" do |
| 151 |
@config.expect :mock_prefix, "Mock" |
| 152 |
@config.expect :mock_suffix, "" |
| 153 |
@config.expect :weak, "" |
| 154 |
|
| 155 |
orig_filename = "Pout-Pout Fish.h" |
| 156 |
define_name = "MOCKPOUT_POUT_FISH_H" |
| 157 |
output = [] |
| 158 |
expected = [ |
| 159 |
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n", |
| 160 |
"#ifndef _#{define_name}\n", |
| 161 |
"#define _#{define_name}\n\n", |
| 162 |
"#include \"unity.h\"\n", |
| 163 |
"#include \"ConfigRequiredHeader1.h\"\n", |
| 164 |
"#include \"ConfigRequiredHeader2.h\"\n", |
| 165 |
"#include \"#{orig_filename}\"\n", |
| 166 |
"#include \"PluginRequiredHeader.h\"\n", |
| 167 |
"\n", |
| 168 |
"/* Ignore the following warnings, since we are copying code */\n", |
| 169 |
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n", |
| 170 |
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n", |
| 171 |
"#pragma GCC diagnostic push\n", |
| 172 |
"#endif\n", |
| 173 |
"#if !defined(__clang__)\n", |
| 174 |
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n", |
| 175 |
"#endif\n", |
| 176 |
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n", |
| 177 |
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n", |
| 178 |
"#endif\n", |
| 179 |
"\n", |
| 180 |
"#ifdef __cplusplus\n", |
| 181 |
"extern \"C\" {\n", |
| 182 |
"#endif\n", |
| 183 |
"\n", |
| 184 |
] |
| 185 |
|
| 186 |
@config.expect :orig_header_include_fmt, "#include \"%s\"" |
| 187 |
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files] |
| 188 |
|
| 189 |
|
| 190 |
test_project = @test_project.clone |
| 191 |
test_project[:module_name] = "Pout-Pout Fish" |
| 192 |
test_project[:mock_name] = "MockPout-Pout Fish" |
| 193 |
test_project[:clean_name] = "MockPout_Pout_Fish" |
| 194 |
|
| 195 |
@cmock_generator.create_mock_header_header(output, "MockPout-Pout Fish.h", test_project) |
| 196 |
|
| 197 |
assert_equal(expected, output) |
| 198 |
end |
| 199 |
|
| 200 |
it "create the top of a header file with optional include files from config" do |
| 201 |
@config.expect :mock_prefix, "Mock" |
| 202 |
@config.expect :mock_suffix, "" |
| 203 |
@config.expect :weak, "" |
| 204 |
orig_filename = "PoutPoutFish.h" |
| 205 |
define_name = "MOCKPOUTPOUTFISH_H" |
| 206 |
output = [] |
| 207 |
expected = [ |
| 208 |
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n", |
| 209 |
"#ifndef _#{define_name}\n", |
| 210 |
"#define _#{define_name}\n\n", |
| 211 |
"#include \"unity.h\"\n", |
| 212 |
"#include \"ConfigRequiredHeader1.h\"\n", |
| 213 |
"#include \"ConfigRequiredHeader2.h\"\n", |
| 214 |
"#include \"#{orig_filename}\"\n", |
| 215 |
"\n", |
| 216 |
"/* Ignore the following warnings, since we are copying code */\n", |
| 217 |
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n", |
| 218 |
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n", |
| 219 |
"#pragma GCC diagnostic push\n", |
| 220 |
"#endif\n", |
| 221 |
"#if !defined(__clang__)\n", |
| 222 |
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n", |
| 223 |
"#endif\n", |
| 224 |
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n", |
| 225 |
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n", |
| 226 |
"#endif\n", |
| 227 |
"\n", |
| 228 |
"#ifdef __cplusplus\n", |
| 229 |
"extern \"C\" {\n", |
| 230 |
"#endif\n", |
| 231 |
"\n", |
| 232 |
] |
| 233 |
|
| 234 |
@config.expect :orig_header_include_fmt, "#include \"%s\"" |
| 235 |
@plugins.expect :run, '', [:include_files] |
| 236 |
|
| 237 |
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h", @test_project) |
| 238 |
|
| 239 |
assert_equal(expected, output) |
| 240 |
end |
| 241 |
|
| 242 |
it "create the top of a header file with include file from plugin" do |
| 243 |
@config.expect :mock_prefix, "Mock" |
| 244 |
@config.expect :mock_suffix, "" |
| 245 |
@config.expect :weak, "" |
| 246 |
orig_filename = "PoutPoutFish.h" |
| 247 |
define_name = "MOCKPOUTPOUTFISH_H" |
| 248 |
output = [] |
| 249 |
expected = [ |
| 250 |
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n", |
| 251 |
"#ifndef _#{define_name}\n", |
| 252 |
"#define _#{define_name}\n\n", |
| 253 |
"#include \"unity.h\"\n", |
| 254 |
"#include \"ConfigRequiredHeader1.h\"\n", |
| 255 |
"#include \"ConfigRequiredHeader2.h\"\n", |
| 256 |
"#include \"#{orig_filename}\"\n", |
| 257 |
"#include \"PluginRequiredHeader.h\"\n", |
| 258 |
"\n", |
| 259 |
"/* Ignore the following warnings, since we are copying code */\n", |
| 260 |
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n", |
| 261 |
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n", |
| 262 |
"#pragma GCC diagnostic push\n", |
| 263 |
"#endif\n", |
| 264 |
"#if !defined(__clang__)\n", |
| 265 |
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n", |
| 266 |
"#endif\n", |
| 267 |
"#pragma GCC diagnostic ignored \"-Wunknown-pragmas\"\n", |
| 268 |
"#pragma GCC diagnostic ignored \"-Wduplicate-decl-specifier\"\n", |
| 269 |
"#endif\n", |
| 270 |
"\n", |
| 271 |
"#ifdef __cplusplus\n", |
| 272 |
"extern \"C\" {\n", |
| 273 |
"#endif\n", |
| 274 |
"\n", |
| 275 |
] |
| 276 |
|
| 277 |
@config.expect :orig_header_include_fmt, "#include \"%s\"" |
| 278 |
@plugins.expect :run, "#include \"PluginRequiredHeader.h\"\n", [:include_files] |
| 279 |
|
| 280 |
@cmock_generator.create_mock_header_header(output, "MockPoutPoutFish.h", @test_project) |
| 281 |
|
| 282 |
assert_equal(expected, output) |
| 283 |
end |
| 284 |
|
| 285 |
it "write typedefs" do |
| 286 |
typedefs = [ 'typedef unsigned char U8;', |
| 287 |
'typedef char S8;', |
| 288 |
'typedef unsigned long U32;' |
| 289 |
] |
| 290 |
output = [] |
| 291 |
expected = [ "\n", |
| 292 |
"typedef unsigned char U8;\n", |
| 293 |
"typedef char S8;\n", |
| 294 |
"typedef unsigned long U32;\n", |
| 295 |
"\n\n" |
| 296 |
] |
| 297 |
|
| 298 |
@test_project[:parsed_stuff][:typedefs] = typedefs |
| 299 |
@cmock_generator.create_typedefs(output, @test_project) |
| 300 |
|
| 301 |
assert_equal(expected, output.flatten) |
| 302 |
end |
| 303 |
|
| 304 |
it "create the header file service call declarations" do |
| 305 |
mock_name = "MockPoutPoutFish" |
| 306 |
|
| 307 |
output = [] |
| 308 |
expected = [ "void #{mock_name}_Init(void);\n", |
| 309 |
"void #{mock_name}_Destroy(void);\n", |
| 310 |
"void #{mock_name}_Verify(void);\n\n" |
| 311 |
] |
| 312 |
|
| 313 |
@cmock_generator.create_mock_header_service_call_declarations(output, @test_project) |
| 314 |
|
| 315 |
assert_equal(expected, output) |
| 316 |
end |
| 317 |
|
| 318 |
it "append the proper footer to the header file" do |
| 319 |
output = [] |
| 320 |
expected = ["\n", |
| 321 |
"#ifdef __cplusplus\n", |
| 322 |
"}\n", |
| 323 |
"#endif\n", |
| 324 |
"\n", |
| 325 |
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n", |
| 326 |
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n", |
| 327 |
"#pragma GCC diagnostic pop\n", |
| 328 |
"#endif\n", |
| 329 |
"#endif\n", |
| 330 |
"\n", |
| 331 |
"#endif\n" |
| 332 |
] |
| 333 |
|
| 334 |
@cmock_generator.create_mock_header_footer(output) |
| 335 |
|
| 336 |
assert_equal(expected, output) |
| 337 |
end |
| 338 |
|
| 339 |
it "create a proper heading for a source file" do |
| 340 |
output = [] |
| 341 |
functions = [ { :name => "uno", :args => [ { :name => "arg1" }, { :name => "arg2" } ] }, |
| 342 |
{ :name => "dos", :args => [ { :name => "arg3" }, { :name => "arg2" } ] }, |
| 343 |
{ :name => "tres", :args => [] } |
| 344 |
] |
| 345 |
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", |
| 346 |
"#include <string.h>\n", |
| 347 |
"#include <stdlib.h>\n", |
| 348 |
"#include <setjmp.h>\n", |
| 349 |
"#include \"cmock.h\"\n", |
| 350 |
"#include \"MockPoutPoutFish.h\"\n", |
| 351 |
"\n", |
| 352 |
"static const char* CMockString_arg1 = \"arg1\";\n", |
| 353 |
"static const char* CMockString_arg2 = \"arg2\";\n", |
| 354 |
"static const char* CMockString_arg3 = \"arg3\";\n", |
| 355 |
"static const char* CMockString_dos = \"dos\";\n", |
| 356 |
"static const char* CMockString_tres = \"tres\";\n", |
| 357 |
"static const char* CMockString_uno = \"uno\";\n", |
| 358 |
"\n" |
| 359 |
] |
| 360 |
|
| 361 |
@test_project[:parsed_stuff][:functions] = functions |
| 362 |
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c", @test_project) |
| 363 |
|
| 364 |
assert_equal(expected, output) |
| 365 |
end |
| 366 |
|
| 367 |
it "create the instance structure where it is needed when no functions" do |
| 368 |
output = [] |
| 369 |
functions = [] |
| 370 |
expected = [ "static struct MockPoutPoutFishInstance\n", |
| 371 |
"{\n", |
| 372 |
" unsigned char placeHolder;\n", |
| 373 |
"} Mock;\n\n" |
| 374 |
].join |
| 375 |
|
| 376 |
@test_project[:parsed_stuff][:functions] = functions |
| 377 |
@cmock_generator.create_instance_structure(output, @test_project) |
| 378 |
|
| 379 |
assert_equal(expected, output.join) |
| 380 |
end |
| 381 |
|
| 382 |
it "create the instance structure where it is needed when functions required" do |
| 383 |
output = [] |
| 384 |
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] }, |
| 385 |
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] } |
| 386 |
] |
| 387 |
expected = [ "typedef struct _CMOCK_First_CALL_INSTANCE\n{\n", |
| 388 |
" UNITY_LINE_TYPE LineNumber;\n", |
| 389 |
" b1 b2", |
| 390 |
"\n} CMOCK_First_CALL_INSTANCE;\n\n", |
| 391 |
"typedef struct _CMOCK_Second_CALL_INSTANCE\n{\n", |
| 392 |
" UNITY_LINE_TYPE LineNumber;\n", |
| 393 |
"\n} CMOCK_Second_CALL_INSTANCE;\n\n", |
| 394 |
"static struct MockPoutPoutFishInstance\n{\n", |
| 395 |
" d1", |
| 396 |
" CMOCK_MEM_INDEX_TYPE First_CallInstance;\n", |
| 397 |
" e1 e2 e3", |
| 398 |
" CMOCK_MEM_INDEX_TYPE Second_CallInstance;\n", |
| 399 |
"} Mock;\n\n" |
| 400 |
].join |
| 401 |
@plugins.expect :run, [" b1"," b2"], [:instance_typedefs, functions[0]] |
| 402 |
@plugins.expect :run, [], [:instance_typedefs, functions[1]] |
| 403 |
|
| 404 |
@plugins.expect :run, [" d1"], [:instance_structure, functions[0]] |
| 405 |
@plugins.expect :run, [" e1"," e2"," e3"], [:instance_structure, functions[1]] |
| 406 |
|
| 407 |
@test_project[:parsed_stuff][:functions] = functions |
| 408 |
@cmock_generator.create_instance_structure(output, @test_project) |
| 409 |
|
| 410 |
assert_equal(expected, output.join) |
| 411 |
end |
| 412 |
|
| 413 |
it "create extern declarations for source file" do |
| 414 |
output = [] |
| 415 |
expected = [ "extern jmp_buf AbortFrame;\n", |
| 416 |
"\n" ] |
| 417 |
|
| 418 |
@cmock_generator.create_extern_declarations(output) |
| 419 |
|
| 420 |
assert_equal(expected, output.flatten) |
| 421 |
end |
| 422 |
|
| 423 |
it "create extern declarations for source file when using strict ordering" do |
| 424 |
output = [] |
| 425 |
expected = [ "extern jmp_buf AbortFrame;\n", |
| 426 |
"extern int GlobalExpectCount;\n", |
| 427 |
"extern int GlobalVerifyOrder;\n", |
| 428 |
"\n" ] |
| 429 |
|
| 430 |
@cmock_generator_strict.create_extern_declarations(output) |
| 431 |
|
| 432 |
assert_equal(expected, output.flatten) |
| 433 |
end |
| 434 |
|
| 435 |
it "create mock verify functions in source file when no functions specified" do |
| 436 |
functions = [] |
| 437 |
output = [] |
| 438 |
expected = "void MockPoutPoutFish_Verify(void)\n{\n}\n\n" |
| 439 |
|
| 440 |
@test_project[:parsed_stuff][:functions] = functions |
| 441 |
@cmock_generator.create_mock_verify_function(output, @test_project) |
| 442 |
|
| 443 |
assert_equal(expected, output.join) |
| 444 |
end |
| 445 |
|
| 446 |
it "create mock verify functions in source file when extra functions specified" do |
| 447 |
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] }, |
| 448 |
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] } |
| 449 |
] |
| 450 |
output = [] |
| 451 |
expected = [ "void MockPoutPoutFish_Verify(void)\n{\n", |
| 452 |
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", |
| 453 |
" CMOCK_MEM_INDEX_TYPE call_instance;\n", |
| 454 |
" call_instance = Mock.First_CallInstance;\n" + |
| 455 |
" Uno_First" + |
| 456 |
" Dos_First" + |
| 457 |
" call_instance = Mock.Second_CallInstance;\n" + |
| 458 |
" Uno_Second" + |
| 459 |
" Dos_Second", |
| 460 |
"}\n\n" |
| 461 |
] |
| 462 |
@plugins.expect :run, [" Uno_First"," Dos_First"], [:mock_verify, functions[0]] |
| 463 |
@plugins.expect :run, [" Uno_Second"," Dos_Second"], [:mock_verify, functions[1]] |
| 464 |
|
| 465 |
@cmock_generator.ordered = true |
| 466 |
@test_project[:parsed_stuff][:functions] = functions |
| 467 |
@cmock_generator.create_mock_verify_function(output, @test_project) |
| 468 |
|
| 469 |
assert_equal(expected, output.flatten) |
| 470 |
end |
| 471 |
|
| 472 |
it "create mock init functions in source file" do |
| 473 |
output = [] |
| 474 |
expected = [ "void MockPoutPoutFish_Init(void)\n{\n", |
| 475 |
" MockPoutPoutFish_Destroy();\n", |
| 476 |
"}\n\n" |
| 477 |
] |
| 478 |
|
| 479 |
@cmock_generator.create_mock_init_function(output, @test_project) |
| 480 |
|
| 481 |
assert_equal(expected.join, output.join) |
| 482 |
end |
| 483 |
|
| 484 |
it "create mock destroy functions in source file" do |
| 485 |
functions = [] |
| 486 |
output = [] |
| 487 |
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n", |
| 488 |
" CMock_Guts_MemFreeAll();\n", |
| 489 |
" memset(&Mock, 0, sizeof(Mock));\n", |
| 490 |
"}\n\n" |
| 491 |
] |
| 492 |
|
| 493 |
@test_project[:parsed_stuff][:functions] = functions |
| 494 |
@cmock_generator.create_mock_destroy_function(output, @test_project) |
| 495 |
|
| 496 |
assert_equal(expected.join, output.join) |
| 497 |
end |
| 498 |
|
| 499 |
it "create mock destroy functions in source file when specified with strict ordering" do |
| 500 |
functions = [ { :name => "First", :args => "int Candy", :return => test_return[:int] }, |
| 501 |
{ :name => "Second", :args => "bool Smarty", :return => test_return[:string] } |
| 502 |
] |
| 503 |
output = [] |
| 504 |
expected = [ "void MockPoutPoutFish_Destroy(void)\n{\n", |
| 505 |
" CMock_Guts_MemFreeAll();\n", |
| 506 |
" memset(&Mock, 0, sizeof(Mock));\n", |
| 507 |
" uno", |
| 508 |
" GlobalExpectCount = 0;\n", |
| 509 |
" GlobalVerifyOrder = 0;\n", |
| 510 |
"}\n\n" |
| 511 |
] |
| 512 |
@plugins.expect :run, [], [:mock_destroy, functions[0]] |
| 513 |
@plugins.expect :run, [" uno"], [:mock_destroy, functions[1]] |
| 514 |
|
| 515 |
@test_project[:parsed_stuff][:functions] = functions |
| 516 |
@cmock_generator_strict.create_mock_destroy_function(output, @test_project) |
| 517 |
|
| 518 |
assert_equal(expected.join, output.join) |
| 519 |
end |
| 520 |
|
| 521 |
it "create mock implementation functions in source file" do |
| 522 |
function = { :modifier => "static", |
| 523 |
:return => test_return[:int], |
| 524 |
:args_string => "uint32 sandwiches, const char* named", |
| 525 |
:args => ["uint32 sandwiches", "const char* named"], |
| 526 |
:var_arg => nil, |
| 527 |
:name => "SupaFunction", |
| 528 |
:unscoped_name => "SupaFunction", |
| 529 |
:namespace => [], |
| 530 |
:class => nil, |
| 531 |
:attributes => "__inline" |
| 532 |
} |
| 533 |
output = [] |
| 534 |
expected = [ "static int SupaFunction(uint32 sandwiches, const char* named)\n", |
| 535 |
"{\n", |
| 536 |
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", |
| 537 |
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n", |
| 538 |
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n", |
| 539 |
" cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n", |
| 540 |
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n", |
| 541 |
" uno", |
| 542 |
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n", |
| 543 |
" cmock_line = cmock_call_instance->LineNumber;\n", |
| 544 |
" dos", |
| 545 |
" tres", |
| 546 |
" UNITY_CLR_DETAILS();\n", |
| 547 |
" return cmock_call_instance->ReturnVal;\n", |
| 548 |
"}\n\n" |
| 549 |
] |
| 550 |
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function] |
| 551 |
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function] |
| 552 |
|
| 553 |
@cmock_generator.create_mock_implementation(output, function) |
| 554 |
|
| 555 |
assert_equal(expected.join, output.join) |
| 556 |
end |
| 557 |
|
| 558 |
it "create mock implementation functions in source file with different options" do |
| 559 |
function = { :modifier => "", |
| 560 |
:c_calling_convention => "__stdcall", |
| 561 |
:return => test_return[:int], |
| 562 |
:args_string => "uint32 sandwiches", |
| 563 |
:args => ["uint32 sandwiches"], |
| 564 |
:var_arg => "corn ...", |
| 565 |
:name => "SupaFunction", |
| 566 |
:unscoped_name => "SupaFunction", |
| 567 |
:namespace => [], |
| 568 |
:class => nil, |
| 569 |
:attributes => nil |
| 570 |
} |
| 571 |
output = [] |
| 572 |
expected = [ "int __stdcall SupaFunction(uint32 sandwiches, corn ...)\n", |
| 573 |
"{\n", |
| 574 |
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", |
| 575 |
" CMOCK_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n", |
| 576 |
" UNITY_SET_DETAIL(CMockString_SupaFunction);\n", |
| 577 |
" cmock_call_instance = (CMOCK_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaFunction_CallInstance);\n", |
| 578 |
" Mock.SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaFunction_CallInstance);\n", |
| 579 |
" uno", |
| 580 |
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n", |
| 581 |
" cmock_line = cmock_call_instance->LineNumber;\n", |
| 582 |
" dos", |
| 583 |
" tres", |
| 584 |
" UNITY_CLR_DETAILS();\n", |
| 585 |
" return cmock_call_instance->ReturnVal;\n", |
| 586 |
"}\n\n" |
| 587 |
] |
| 588 |
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function] |
| 589 |
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function] |
| 590 |
|
| 591 |
@cmock_generator.create_mock_implementation(output, function) |
| 592 |
|
| 593 |
assert_equal(expected.join, output.join) |
| 594 |
end |
| 595 |
|
| 596 |
it "create mock implementation function in source file for C++ static member" do |
| 597 |
function = { :modifier => "static", |
| 598 |
:return => test_return[:int], |
| 599 |
:args_string => "uint32 sandwiches, const char* named", |
| 600 |
:args => ["uint32 sandwiches", "const char* named"], |
| 601 |
:var_arg => nil, |
| 602 |
:unscoped_name => "SupaFunction", |
| 603 |
:namespace => ["ns1", "ns2"], |
| 604 |
:class => "SupaClass", |
| 605 |
:name => "ns1_ns2_SupaClass_SupaFunction", |
| 606 |
:attributes => nil |
| 607 |
} |
| 608 |
output = [] |
| 609 |
expected = [ "namespace ns1 {\n", |
| 610 |
"namespace ns2 {\n", |
| 611 |
"static int SupaClass::SupaFunction(uint32 sandwiches, const char* named)\n", |
| 612 |
"{\n", |
| 613 |
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", |
| 614 |
" CMOCK_ns1_ns2_SupaClass_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n", |
| 615 |
" UNITY_SET_DETAIL(CMockString_ns1_ns2_SupaClass_SupaFunction);\n", |
| 616 |
" cmock_call_instance = (CMOCK_ns1_ns2_SupaClass_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance);\n", |
| 617 |
" Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.ns1_ns2_SupaClass_SupaFunction_CallInstance);\n", |
| 618 |
" uno", |
| 619 |
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n", |
| 620 |
" cmock_line = cmock_call_instance->LineNumber;\n", |
| 621 |
" dos", |
| 622 |
" tres", |
| 623 |
" UNITY_CLR_DETAILS();\n", |
| 624 |
" return cmock_call_instance->ReturnVal;\n", |
| 625 |
"}\n", |
| 626 |
"}\n", |
| 627 |
"}\n\n", |
| 628 |
] |
| 629 |
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function] |
| 630 |
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function] |
| 631 |
|
| 632 |
@cmock_generator.create_mock_implementation(output, function) |
| 633 |
|
| 634 |
assert_equal(expected.join, output.join) |
| 635 |
end |
| 636 |
|
| 637 |
it "create mock implementation functions in source file with different options for C++ static member" do |
| 638 |
function = { :modifier => "static", |
| 639 |
:c_calling_convention => "__stdcall", |
| 640 |
:return => test_return[:int], |
| 641 |
:args_string => "uint32 sandwiches", |
| 642 |
:args => ["uint32 sandwiches"], |
| 643 |
:var_arg => "corn ...", |
| 644 |
:name => "SupaClass_SupaFunction", |
| 645 |
:unscoped_name => "SupaFunction", |
| 646 |
:namespace => [], |
| 647 |
:class => "SupaClass", |
| 648 |
:attributes => nil |
| 649 |
} |
| 650 |
output = [] |
| 651 |
expected = [ "static int __stdcall SupaClass::SupaFunction(uint32 sandwiches, corn ...)\n", |
| 652 |
"{\n", |
| 653 |
" UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n", |
| 654 |
" CMOCK_SupaClass_SupaFunction_CALL_INSTANCE* cmock_call_instance;\n", |
| 655 |
" UNITY_SET_DETAIL(CMockString_SupaClass_SupaFunction);\n", |
| 656 |
" cmock_call_instance = (CMOCK_SupaClass_SupaFunction_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.SupaClass_SupaFunction_CallInstance);\n", |
| 657 |
" Mock.SupaClass_SupaFunction_CallInstance = CMock_Guts_MemNext(Mock.SupaClass_SupaFunction_CallInstance);\n", |
| 658 |
" uno", |
| 659 |
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringCalledMore);\n", |
| 660 |
" cmock_line = cmock_call_instance->LineNumber;\n", |
| 661 |
" dos", |
| 662 |
" tres", |
| 663 |
" UNITY_CLR_DETAILS();\n", |
| 664 |
" return cmock_call_instance->ReturnVal;\n", |
| 665 |
"}\n\n" |
| 666 |
] |
| 667 |
@plugins.expect :run, [" uno"], [:mock_implementation_precheck, function] |
| 668 |
@plugins.expect :run, [" dos"," tres"], [:mock_implementation, function] |
| 669 |
|
| 670 |
@cmock_generator.create_mock_implementation(output, function) |
| 671 |
|
| 672 |
assert_equal(expected.join, output.join) |
| 673 |
end |
| 674 |
|
| 675 |
it "creates using statements for C++ static member in namespace" do |
| 676 |
function = { :modifier => "static", |
| 677 |
:return => test_return[:int], |
| 678 |
:args_string => "uint32 sandwiches", |
| 679 |
:args => ["uint32 sandwiches"], |
| 680 |
:var_arg => nil, |
| 681 |
:unscoped_name => "SupaFunction", |
| 682 |
:namespace => ["ns1"], |
| 683 |
:class => "SupaClass", |
| 684 |
:name => "ns1_SupaClass_SupaFunction", |
| 685 |
:attributes => nil |
| 686 |
} |
| 687 |
output = [] |
| 688 |
expected = "using namespace ns1;\n" |
| 689 |
|
| 690 |
@cmock_generator.create_using_statement(output, function) |
| 691 |
|
| 692 |
assert_equal(expected, output.join) |
| 693 |
end |
| 694 |
|
| 695 |
it "creates using statements for C++ static member in nested namespace" do |
| 696 |
function = { :modifier => "static", |
| 697 |
:return => test_return[:int], |
| 698 |
:args_string => "uint32 sandwiches", |
| 699 |
:args => ["uint32 sandwiches"], |
| 700 |
:var_arg => nil, |
| 701 |
:unscoped_name => "SupaFunction", |
| 702 |
:namespace => ["ns1", "ns2"], |
| 703 |
:class => "SupaClass", |
| 704 |
:name => "ns1_ns2_SupaClass_SupaFunction", |
| 705 |
:attributes => nil |
| 706 |
} |
| 707 |
output = [] |
| 708 |
expected = "using namespace ns1::ns2;\n" |
| 709 |
|
| 710 |
@cmock_generator.create_using_statement(output, function) |
| 711 |
|
| 712 |
assert_equal(expected, output.join) |
| 713 |
end |
| 714 |
end |