Debian Codegraph @

test/unit/cmock_generator_plugin_ignore_arg_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_ignore_arg'
9
10 describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Module" do
11
12 before do
13 create_mocks :config, :utils
14
15 # int *Oak(void)"
16 @void_func = {:name => "Oak", :args => [], :return => test_return[:int_ptr]}
17
18 # void Pine(int chicken, const int beef, int *tofu)
19 @complex_func = {:name => "Pine",
20 :args => [{ :type => "int",
21 :name => "chicken",
22 :ptr? => false,
23 },
24 { :type => "const int*",
25 :name => "beef",
26 :ptr? => true,
27 :const? => true,
28 },
29 { :type => "int*",
30 :name => "tofu",
31 :ptr? => true,
32 }],
33 :return => test_return[:void],
34 :contains_ptr? => true }
35
36 #no strict ordering
37 @cmock_generator_plugin_ignore_arg = CMockGeneratorPluginIgnoreArg.new(@config, @utils)
38 end
39
40 after do
41 end
42
43 it "have set up internal priority correctly on init" do
44 assert_equal(10, @cmock_generator_plugin_ignore_arg.priority)
45 end
46
47 it "not include any additional include files" do
48 assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:include_files))
49 end
50
51 it "not add to typedef structure for functions with no args" do
52 returned = @cmock_generator_plugin_ignore_arg.instance_typedefs(@void_func)
53 assert_equal("", returned)
54 end
55
56 it "add to tyepdef structure mock needs of functions of style 'void func(int chicken, int* pork)'" do
57 expected = " char IgnoreArg_chicken;\n" +
58 " char IgnoreArg_beef;\n" +
59 " char IgnoreArg_tofu;\n"
60 returned = @cmock_generator_plugin_ignore_arg.instance_typedefs(@complex_func)
61 assert_equal(expected, returned)
62 end
63
64 it "add mock function declarations for all arguments" do
65 expected =
66 "#define Pine_IgnoreArg_chicken()" +
67 " Pine_CMockIgnoreArg_chicken(__LINE__)\n" +
68 "void Pine_CMockIgnoreArg_chicken(UNITY_LINE_TYPE cmock_line);\n" +
69
70 "#define Pine_IgnoreArg_beef()" +
71 " Pine_CMockIgnoreArg_beef(__LINE__)\n" +
72 "void Pine_CMockIgnoreArg_beef(UNITY_LINE_TYPE cmock_line);\n" +
73
74 "#define Pine_IgnoreArg_tofu()" +
75 " Pine_CMockIgnoreArg_tofu(__LINE__)\n" +
76 "void Pine_CMockIgnoreArg_tofu(UNITY_LINE_TYPE cmock_line);\n"
77
78 returned = @cmock_generator_plugin_ignore_arg.mock_function_declarations(@complex_func)
79 assert_equal(expected, returned)
80 end
81
82 it "add mock interfaces for all arguments" do
83 expected =
84 "void Pine_CMockIgnoreArg_chicken(UNITY_LINE_TYPE cmock_line)\n" +
85 "{\n" +
86 " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
87 "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
88 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
89 " cmock_call_instance->IgnoreArg_chicken = 1;\n" +
90 "}\n\n" +
91
92 "void Pine_CMockIgnoreArg_beef(UNITY_LINE_TYPE cmock_line)\n" +
93 "{\n" +
94 " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
95 "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
96 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
97 " cmock_call_instance->IgnoreArg_beef = 1;\n" +
98 "}\n\n" +
99
100 "void Pine_CMockIgnoreArg_tofu(UNITY_LINE_TYPE cmock_line)\n" +
101 "{\n" +
102 " CMOCK_Pine_CALL_INSTANCE* cmock_call_instance = " +
103 "(CMOCK_Pine_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.Pine_CallInstance));\n" +
104 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n" +
105 " cmock_call_instance->IgnoreArg_tofu = 1;\n" +
106 "}\n\n"
107
108 returned = @cmock_generator_plugin_ignore_arg.mock_interfaces(@complex_func).join("")
109 assert_equal(expected, returned)
110 end
111
112 it "not add a mock implementation" do
113 assert(!@cmock_generator_plugin_ignore_arg.respond_to?(:mock_implementation))
114 end
115
116 end