Debian Codegraph @

test/unit/cmock_generator_plugin_ignore_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'
9
10 describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module" do
11
12 before do
13 create_mocks :config, :utils
14 @config = create_stub(:respond_to? => true)
15 @cmock_generator_plugin_ignore = CMockGeneratorPluginIgnore.new(@config, @utils)
16 end
17
18 after do
19 end
20
21 it "have set up internal priority" do
22 assert_equal(2, @cmock_generator_plugin_ignore.priority)
23 end
24
25 it "not have any additional include file requirements" do
26 assert(!@cmock_generator_plugin_ignore.respond_to?(:include_files))
27 end
28
29 it "add a required variable to the instance structure" do
30 function = {:name => "Grass", :args => [], :return => test_return[:void]}
31 expected = " char Grass_IgnoreBool;\n"
32 returned = @cmock_generator_plugin_ignore.instance_structure(function)
33 assert_equal(expected, returned)
34 end
35
36 it "handle function declarations for functions without return values" do
37 function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
38 expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" +
39 "#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n"
40 returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
41 assert_equal(expected, returned)
42 end
43
44 it "handle function declarations for functions that returns something" do
45 function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
46 expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+
47 "void Fungus_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" +
48 "#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+
49 "void Fungus_CMockStopIgnore(void);\n"
50 returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
51 assert_equal(expected, returned)
52 end
53
54 it "add required code to implementation precheck with void function" do
55 function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
56 expected = [" if (Mock.Mold_IgnoreBool)\n",
57 " {\n",
58 " UNITY_CLR_DETAILS();\n",
59 " return;\n",
60 " }\n"
61 ].join
62 returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function)
63 assert_equal(expected, returned)
64 end
65
66 it "add required code to implementation precheck with return functions" do
67 function = {:name => "Fungus", :args_string => "void", :return => test_return[:int]}
68 retval = test_return[:int].merge({ :name => "cmock_call_instance->ReturnVal"})
69 @utils.expect :code_assign_argument_quickly, ' mock_retval_0', ["Mock.Fungus_FinalReturn", retval]
70 expected = [" if (Mock.Fungus_IgnoreBool)\n",
71 " {\n",
72 " UNITY_CLR_DETAILS();\n",
73 " if (cmock_call_instance == NULL)\n",
74 " return Mock.Fungus_FinalReturn;\n",
75 " mock_retval_0",
76 " return cmock_call_instance->ReturnVal;\n",
77 " }\n"
78 ].join
79 returned = @cmock_generator_plugin_ignore.mock_implementation_precheck(function)
80 assert_equal(expected, returned)
81 end
82
83 it "add a new mock interface for ignoring when function had no return value" do
84 function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:void]}
85 expected = ["void Slime_CMockIgnore(void)\n",
86 "{\n",
87 " Mock.Slime_IgnoreBool = (char)1;\n",
88 "}\n\n",
89
90 "void Slime_CMockStopIgnore(void)\n",
91 "{\n",
92 " Mock.Slime_IgnoreBool = (char)0;\n",
93 "}\n\n"
94 ].join
95 returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
96 assert_equal(expected, returned)
97 end
98
99 it "add a new mock interface for ignoring when function has return value" do
100 function = {:name => "Slime", :args => [], :args_string => "void", :return => test_return[:int]}
101 @utils.expect :code_add_base_expectation, "mock_return_1", ["Slime", false]
102 expected = ["void Slime_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n",
103 "{\n",
104 "mock_return_1",
105 " cmock_call_instance->ReturnVal = cmock_to_return;\n",
106 " Mock.Slime_IgnoreBool = (char)1;\n",
107 "}\n\n",
108
109 "void Slime_CMockStopIgnore(void)\n{\n",
110 " if(Mock.Slime_IgnoreBool)\n",
111 " Mock.Slime_CallInstance = CMock_Guts_MemNext(Mock.Slime_CallInstance);\n",
112 " Mock.Slime_IgnoreBool = (char)0;\n",
113 "}\n\n"
114 ].join
115 returned = @cmock_generator_plugin_ignore.mock_interfaces(function)
116 assert_equal(expected, returned)
117 end
118
119 end